int init_litmus(void) { int ret, ret2; ret = mlockall(MCL_CURRENT | MCL_FUTURE); check("mlockall()"); ret2 = init_rt_thread(); return (ret == 0) && (ret2 == 0) ? 0 : -1; }
void* rt_thread(void *tcontext) { struct thread_context *ctx = (struct thread_context *) tcontext; struct rt_task param; /* set up litmus real-time task*/ be_migrate_to_domain(ctx->cpu); init_rt_task_param(¶m); param.priority = ctx->priority; param.cpu = ctx->cpu; param.exec_cost = ms2ns(3000); param.period = ms2ns(10000); param.relative_deadline = ms2ns(15000); param.budget_policy = NO_ENFORCEMENT; param.cls = RT_CLASS_HARD; param.enable_help = helping; param.non_preemption_after_migrate = non_preemption; init_rt_thread(); if (set_rt_task_param(gettid(), ¶m) != 0) printf("set_rt_task_param error. \n "); task_mode(LITMUS_RT_TASK); lock_1 = litmus_open_lock(7, 1, "b", init_prio_per_cpu(4, 10, 10, 10, 10)); do { lt_sleep(10); job(ctx); count_first++; if (count_first >= executions) exit_program = 1; } while (exit_program != 1); task_mode(BACKGROUND_TASK); return NULL; }
/* A real-time thread is very similar to the main function of a single-threaded * real-time app. Notice, that init_rt_thread() is called to initialized per-thread * data structures of the LITMUS^RT user space libary. */ void* rt_thread(void *tcontext) { int do_exit; struct thread_context *ctx = (struct thread_context *) tcontext; struct rt_task param; /* Set up task parameters */ memset(¶m, 0, sizeof(param)); param.exec_cost = EXEC_COST * NS_PER_MS; param.period = PERIOD * NS_PER_MS; param.relative_deadline = RELATIVE_DEADLINE * NS_PER_MS; /* What to do in the case of budget overruns? */ param.budget_policy = NO_ENFORCEMENT; /* The task class parameter is ignored by most plugins. */ param.cls = RT_CLASS_SOFT; /* The priority parameter is only used by fixed-priority plugins. */ param.priority = LITMUS_LOWEST_PRIORITY; /* Make presence visible. */ printf("RT Thread %d active.\n", ctx->id); /***** * 1) Initialize real-time settings. */ CALL( init_rt_thread() ); /* To specify a partition, do * * param.cpu = CPU; * be_migrate_to(CPU); * * where CPU ranges from 0 to "Number of CPUs" - 1 before calling * set_rt_task_param(). */ CALL( set_rt_task_param(gettid(), ¶m) ); /***** * 2) Transition to real-time mode. */ CALL( task_mode(LITMUS_RT_TASK) ); /* The task is now executing as a real-time task if the call didn't fail. */ /***** * 3) Invoke real-time jobs. */ do { /* Wait until the next job is released. */ sleep_next_period(); /* Invoke job. */ do_exit = job(); } while (!do_exit); /***** * 4) Transition to background mode. */ CALL( task_mode(BACKGROUND_TASK) ); return NULL; }