Skip to content

Commit 455b63c

Browse files
committed
rtapi_app: Assign highest number CPU if no isolated CPU was found
If isolcpus is not used, not assigning a CPU to the thread resulted in higher latency and sporadic failures of tests/threads.0
1 parent 39b516a commit 455b63c

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

‎src/rtapi/uspace_rtapi_app.cc‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,24 @@ int RtapiApp::find_rt_cpu_number() {
258258
top = i;
259259
}
260260
if (top == -1) {
261+
//Fallback: If no isolated CPU's found
262+
//use the highest CPU available
263+
CPU_ZERO(&cpuset);
264+
if (sched_getaffinity(0, sizeof(cpuset), &cpuset) == -1) {
265+
rtapi_print_msg(RTAPI_MSG_ERR, "sched_getaffinity failed %m\n");
266+
top = 0; //Fallback, use CPU 0
267+
} else {
268+
for (int i = 0; i < CPU_SETSIZE; i++) {
269+
if (CPU_ISSET(i, &cpuset))
270+
top = i;
271+
}
272+
if (top == -1) {
273+
top = 0; //Fallback, use CPU 0
274+
}
275+
}
261276
rtapi_print_msg(
262-
RTAPI_MSG_ERR, "No isolated CPU's found, expect some latency or set RTAPI_CPU_NUMBER to select CPU\n"
277+
RTAPI_MSG_ERR, "No isolated CPU's found, expect some latency or set RTAPI_CPU_NUMBER to select CPU.\n"
278+
" CPU %i selected as fallback.\n", top
263279
);
264280
}
265281
return top;

0 commit comments

Comments
 (0)