40 #define OROBLD_OS_INTERNAL 43 #include "../fosi_internal_interface.hpp" 47 #include "../../Logger.hpp" 59 nentries = backtrace(bt,
sizeof(bt) /
sizeof(bt[0]));
60 backtrace_symbols_fd(bt,nentries,fileno(stderr));
71 if ( geteuid() != 0 ) {
72 #if ((CONFIG_XENO_VERSION_MAJOR*1000)+(CONFIG_XENO_VERSION_MINOR*100)+CONFIG_XENO_REVISION_LEVEL) >= 2302 73 printf(
"WARNING: You are not root. This program *may* require that you are root.\n");
76 printf(
"You are not root. This program requires that you are root.\n");
82 int rv = mlockall(MCL_CURRENT | MCL_FUTURE);
84 perror(
"rtos_task_create_main: Could not lock memory using mlockall" );
88 struct sched_param param;
92 if (param.sched_priority != -1 )
95 const char* mt_name =
"MainThread";
97 main->
name = strncpy( (
char*)malloc( (strlen(mt_name)+1)*
sizeof(
char) ), mt_name, strlen(mt_name)+1 );
102 if ( (ret = rt_task_shadow( &(main->
xenotask),mt_name, 0, 0)) != 0 ) {
103 if ( ret == -ENOMEM ) {
105 printf(
"Cannot rt_task_create() MainThread: Out of memory.\n");
108 if ( ret == -EBUSY ) {
110 log(
Info) <<
"MainThread already a Xenomai task." <<
endlog();
113 if ( ret == -EEXIST ) {
118 if ( ret == -EPERM ) {
120 printf(
"Can not rt_task_create() MainThread: No permission.\n");
124 printf(
"Can not rt_task_create() MainThread: Error %d.\n",ret);
131 log(
Warning) <<
"'MainThread' name was already in use. Registered empty name with Xenomai.\n" <<
endlog();
135 main->
xenoptr = rt_task_self();
137 #ifdef OROSEM_OS_XENO_PERIODIC 138 # if CONFIG_XENO_VERSION_MAJOR == 2 && CONFIG_XENO_VERSION_MINOR == 0 140 rt_timer_start( ORODAT_OS_XENO_PERIODIC_TICK*1000*1000*1000 );
141 Logger::In in(
"Scheduler");
144 Logger::In in(
"Scheduler");
148 # if CONFIG_XENO_VERSION_MAJOR == 2 && CONFIG_XENO_VERSION_MINOR == 0 149 rt_timer_start( TM_ONESHOT );
152 # if CONFIG_XENO_OPT_TIMING_PERIODIC 163 sigemptyset( &sa.sa_mask );
165 sigaction(SIGXCPU, &sa, 0);
174 free (main_task->
name);
175 main_task->
name = NULL;
183 void* (*wrapper)(
void*);
190 task->
xenoptr = rt_task_self();
200 unsigned cpu_affinity,
204 void * (*start_routine)(
void *),
210 xcookie->
wrapper = start_routine;
211 if ( name == 0 || strlen(name) == 0)
213 task->
name = strncpy( (
char*)malloc( (strlen(name)+1)*
sizeof(
char) ), name, strlen(name)+1 );
217 unsigned int aff = 0;
218 if ( cpu_affinity != 0 ) {
220 for(
unsigned i = 0; i < 8*
sizeof(cpu_affinity); i++) {
221 if(cpu_affinity & (1 << i)) {
224 const unsigned int all_cpus = ~0;
225 if ( cpu_affinity != all_cpus )
226 log(
Warning) <<
"rtos_task_create: ignoring cpu_affinity for "<< name <<
" on CPU " << i <<
" since it's larger than RTHAL_NR_CPUS - 1 (="<< 7 <<
")"<<
endlog();
234 if (stack_size == 0) {
235 log(
Debug) <<
"Raizing default stack size to 128kb for Xenomai threads in Orocos." <<
endlog();
242 if ( rv == -EEXIST ) {
244 task->
name = strncpy( (
char*)malloc( (strlen(name)+2)*
sizeof(
char) ), name, strlen(name)+1 );
245 task->
name[ strlen(name) ] =
'0';
246 task->
name[ strlen(name)+1 ] = 0;
247 while ( rv == -EEXIST && task->
name[ strlen(name) ] !=
'9') {
248 task->
name[ strlen(name) ] += 1;
252 if ( rv == -EEXIST ) {
253 log(
Warning) << name <<
": an object with that name is already existing in Xenomai." <<
endlog();
257 log(
Error) << name <<
" : CANNOT INIT Xeno TASK " << task->
name <<
" error code: "<< rv <<
endlog();
270 RT_TASK*
self = rt_task_self();
271 if (
self == 0 || task == 0)
273 #if ((CONFIG_XENO_VERSION_MAJOR*1000)+(CONFIG_XENO_VERSION_MINOR*100)+CONFIG_XENO_REVISION_LEVEL) >= 2500 274 if ( rt_task_same(
self, task->
xenoptr ) != 0 )
303 #if ((CONFIG_XENO_VERSION_MAJOR*10000)+(CONFIG_XENO_VERSION_MINOR*100)+CONFIG_XENO_REVISION_LEVEL) >= 20500 304 const int minprio = 0;
306 const int minprio = 1;
308 if (*priority < minprio){
309 log(
Warning) <<
"Forcing priority ("<<*priority<<
") of thread to " << minprio <<
"." <<
endlog();
314 log(
Warning) <<
"Forcing priority ("<<*priority<<
") of thread to 99." <<
endlog();
325 if (t->
xenoptr != rt_task_self() ) {
332 #if ((CONFIG_XENO_VERSION_MAJOR*1000)+(CONFIG_XENO_VERSION_MINOR*100)+CONFIG_XENO_REVISION_LEVEL) < 2600 334 if ( rt_task_set_mode( 0, T_PRIMARY, 0 ) == 0 ) {
343 if (rt_task_set_mode( T_PRIMARY, 0, 0 ) == 0 ) {
365 if ( rt_task_inquire( tt, &info) == 0 )
366 if ( info.status & XNRELAX )
379 rt_task_set_periodic( &(mytask->
xenotask), TM_NOW, TM_INFINITE);
382 rt_task_set_periodic( &(mytask->
xenotask), TM_NOW, rt_timer_ns2ticks(nanosecs) );
400 #if CONFIG_XENO_VERSION_MAJOR == 2 && CONFIG_XENO_VERSION_MINOR == 0 401 if ( rt_task_wait_period() == -ETIMEDOUT)
403 #else // 2.1, 2.2, 2.3, 2.4,... 404 long unsigned int overrun = 0;
405 rt_task_wait_period(&overrun);
407 #if ((CONFIG_XENO_VERSION_MAJOR*1000)+(CONFIG_XENO_VERSION_MINOR*100)+CONFIG_XENO_REVISION_LEVEL) < 2600 410 rt_task_set_mode(T_PRIMARY, 0, 0 );
421 log(
Error) <<
"rtos_task_set_cpu_affinity: Xenomai tasks don't allow to migrate to another CPU once created." <<
endlog();
431 return mytask->
name ? mytask->
name :
"(destroyed)";
444 if ( rt_task_inquire ( tt, &info) == 0 )
450 if ( rt_task_join(&(mytask->
xenotask)) != 0 ) {
453 rt_task_delete(&(mytask->
xenotask));
463 return rt_task_set_priority( tt, priority);
int rtos_task_is_self(const RTOS_TASK *task)
int rtos_task_get_priority(const RTOS_TASK *task)
INTERNAL_QUAL void rtos_task_make_periodic(RTOS_TASK *mytask, NANO_TIME nanosecs)
#define SCHED_XENOMAI_HARD
unsigned int rtos_task_get_pid(const RTOS_TASK *task)
INTERNAL_QUAL int rtos_task_delete_main(RTOS_TASK *main_task)
int rtos_task_set_scheduler(RTOS_TASK *t, int sched_type)
int rtos_task_set_cpu_affinity(RTOS_TASK *task, unsigned cpu_affinity)
unsigned rtos_task_get_cpu_affinity(const RTOS_TASK *task)
INTERNAL_QUAL int rtos_task_check_priority(int *scheduler, int *priority)
void rtos_task_set_wait_period_policy(RTOS_TASK *task, int policy)
void rtos_task_delete(RTOS_TASK *mytask)
INTERNAL_QUAL void rtos_task_yield(RTOS_TASK *)
int rtos_task_set_priority(RTOS_TASK *task, int priority)
static std::ostream & endl(std::ostream &__os)
const char * rtos_task_get_name(const RTOS_TASK *task)
int rtos_task_check_scheduler(int *sched_type)
void *(* wrapper)(void *)
int rtos_task_wait_period(RTOS_TASK *task)
#define SCHED_XENOMAI_SOFT
INTERNAL_QUAL void rtos_xeno_thread_wrapper(void *cookie)
Contains TaskContext, Activity, OperationCaller, Operation, Property, InputPort, OutputPort, Attribute.
INTERNAL_QUAL int rtos_task_create_main(RTOS_TASK *main_task)
void rtos_task_set_period(RTOS_TASK *mytask, NANO_TIME nanosecs)
static Logger::LogFunction endlog()
void warn_upon_switch(int)
INTERNAL_QUAL int rtos_task_create(RTOS_TASK *task, int priority, unsigned cpu_affinity, const char *name, int sched_type, size_t stack_size, void *(*start_routine)(void *), ThreadInterface *obj)
int main(int argc, char **argv)
int rtos_task_get_scheduler(const RTOS_TASK *t)