Skip to content

Commit a761e75

Browse files
Hannes Diethelmhdiethelm
authored andcommitted
LXRT: Fix cpu selection
1 parent ea6e61f commit a761e75

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

src/rtapi/uspace_rtai.cc

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,15 +81,18 @@ struct RtaiApp : RtapiApp {
8181
static void *wrapper(void *arg) {
8282
auto task = reinterpret_cast<RtaiTask*>(arg);
8383
pthread_setspecific(key, arg);
84-
task->rt_task = rt_task_init(task->id, task->prio, 0, 0);
85-
rt_set_periodic_mode();
86-
start_rt_timer(nano2count(task->period));
87-
if(task->uses_fp) rt_task_use_fpu(task->rt_task, 1);
84+
85+
int nprocs = sysconf( _SC_NPROCESSORS_ONLN );
86+
int cpus_allowed = 1 << (nprocs-1); //Use last CPU as default
8887
const static int rt_cpu_number = find_rt_cpu_number();
8988
if(rt_cpu_number != -1) {
9089
rtapi_print_msg(RTAPI_MSG_INFO, "rt_cpu_number = %i\n", rt_cpu_number);
91-
rt_set_runnable_on_cpus(task->rt_task, 1u << rt_cpu_number);
90+
cpus_allowed = 1 << rt_cpu_number;
9291
}
92+
task->rt_task = rt_task_init_schmod(task->id, task->prio, 0, 0, SCHED_FIFO, cpus_allowed);
93+
rt_set_periodic_mode();
94+
start_rt_timer(nano2count(task->period));
95+
if(task->uses_fp) rt_task_use_fpu(task->rt_task, 1);
9396
rt_make_hard_real_time();
9497
rt_task_make_periodic_relative_ns(task->rt_task, task->period, task->period);
9598
(task->taskcode) (task->arg);

src/rtapi/uspace_rtapi_app.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ int find_rt_cpu_number() {
10871087
if(CPU_ISSET(i, &cpuset)) top = i;
10881088
}
10891089
if(top == -1){
1090-
rtapi_print_msg(RTAPI_MSG_ERR, "No isolated CPU's found, expect some latency!");
1090+
rtapi_print_msg(RTAPI_MSG_ERR, "No isolated CPU's found, expect some latency or set RTAPI_CPU_NUMBER to select CPU\n");
10911091
}
10921092
return top;
10931093
#else

0 commit comments

Comments
 (0)