Skip to content

Commit 7034385

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.
1 parent 3f0f6bf commit 7034385

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
@@ -257,8 +257,24 @@ int RtapiApp::find_rt_cpu_number() {
257257
top = i;
258258
}
259259
if (top == -1) {
260+
//Restore 2.9 behaviour: If no isolated CPU's found
261+
//get the highest CPU available
262+
CPU_ZERO(&cpuset);
263+
if (sched_getaffinity(0, sizeof(cpuset), &cpuset) == -1) {
264+
rtapi_print_msg(RTAPI_MSG_ERR, "sched_getaffinity failed %m\n");
265+
top = 0; //Fallback, use CPU 0
266+
} else {
267+
for (int i = 0; i < CPU_SETSIZE; i++) {
268+
if (CPU_ISSET(i, &cpuset))
269+
top = i;
270+
}
271+
if (top == -1) {
272+
top = 0; //Fallback, use CPU 0
273+
}
274+
}
260275
rtapi_print_msg(
261-
RTAPI_MSG_ERR, "No isolated CPU's found, expect some latency or set RTAPI_CPU_NUMBER to select CPU\n"
276+
RTAPI_MSG_ERR, "No isolated CPU's found, expect some latency or set RTAPI_CPU_NUMBER to select CPU.\n"
277+
" CPU %i selected as fallback.\n", top
262278
);
263279
}
264280
return top;

0 commit comments

Comments
 (0)