Exemplo n.º 1
0
int rt_task_create(RT_TASK *task, const char *name,
                   int stksize, int prio, int mode)
{
    int ret, susp, cpus, cpu;
    cpu_set_t cpuset;

    susp = mode & T_SUSP;
    cpus = mode & T_CPUMASK;
    ret = __CURRENT(rt_task_create(task, name, stksize, prio,
                                   mode & ~(T_SUSP|T_CPUMASK|T_LOCK)));
    if (ret)
        return ret;

    if (cpus) {
        CPU_ZERO(&cpuset);
        for (cpu = 0, cpus >>= 24;
                cpus && cpu < 8; cpu++, cpus >>= 1) {
            if (cpus & 1)
                CPU_SET(cpu, &cpuset);
        }
        ret = rt_task_set_affinity(task, &cpuset);
        if (ret) {
            rt_task_delete(task);
            return ret;
        }
    }

    return susp ? rt_task_suspend(task) : 0;
}
Exemplo n.º 2
0
int _rtapi_task_start_hook(task_data *task, int task_id) {
    int which_cpu = 0;
    int uses_fpu = 0;
    int retval;

#ifdef XENOMAI_V2
    // seems to work for me
    // not sure T_CPU(n) is possible - see:
    // http://www.xenomai.org/pipermail/xenomai-help/2010-09/msg00081.html

    if (task->cpu > -1)  // explicitly set by threads, motmod
	which_cpu = T_CPU(task->cpu);

    // http://www.xenomai.org/documentation/trunk/html/api/group__task.html#ga03387550693c21d0223f739570ccd992
    // Passing T_FPU|T_CPU(1) in the mode parameter thus creates a
    // task with FPU support enabled and which will be affine to CPU #1
    // the task will start out dormant; execution begins with rt_task_start()

    // since this is a usermode RT task, it will be FP anyway
    if (task->uses_fp)
	uses_fpu = T_FPU;
#endif

    // optionally start as relaxed thread - meaning defacto a standard Linux thread
    // without RT features
    // see https://xenomai.org/pipermail/xenomai/2015-July/034745.html and
    // https://github.com/machinekit/machinekit/issues/237#issuecomment-126590880

    int prio = (task->flags & TF_NONRT) ? 0 :task->prio;

    if ((retval = rt_task_create (&ostask_array[task_id], task->name, 
				  task->stacksize, prio,
				  uses_fpu | which_cpu | T_JOINABLE)
	 ) != 0) {
	rtapi_print_msg(RTAPI_MSG_ERR,
			"rt_task_create failed: %d %s\n",
			retval, strerror(-retval));
	return -ENOMEM;
    }

#ifndef XENOMAI_V2
    // Xenomai-3 CPU affinity
    cpu_set_t cpus;
    CPU_SET(task->cpu, &cpus);
    rt_task_set_affinity (&ostask_array[task_id], &cpus);
#endif

    if ((retval = rt_task_start( &ostask_array[task_id],
				 _rtapi_task_wrapper, (void *)(long)task_id))) {
	rtapi_print_msg(RTAPI_MSG_INFO,
			"rt_task_start failed: %d %s\n",
			retval, strerror(-retval));
	return -ENOMEM;
    }
    return 0;
}