From 455b63cdcbb6fc2b1cbd4bd626fee356bd83c492 Mon Sep 17 00:00:00 2001 From: Hannes Diethelm Date: Sat, 24 Oct 2026 20:19:09 +0200 Subject: [PATCH] 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 --- src/rtapi/uspace_rtapi_app.cc | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/rtapi/uspace_rtapi_app.cc b/src/rtapi/uspace_rtapi_app.cc index 93e3e2014b8..8bfbedec1d2 100644 --- a/src/rtapi/uspace_rtapi_app.cc +++ b/src/rtapi/uspace_rtapi_app.cc @@ -258,8 +258,24 @@ int RtapiApp::find_rt_cpu_number() { top = i; } if (top == -1) { + //Fallback: If no isolated CPU's found + //use the highest CPU available + CPU_ZERO(&cpuset); + if (sched_getaffinity(0, sizeof(cpuset), &cpuset) == -1) { + rtapi_print_msg(RTAPI_MSG_ERR, "sched_getaffinity failed %m\n"); + top = 0; //Fallback, use CPU 0 + } else { + for (int i = 0; i < CPU_SETSIZE; i++) { + if (CPU_ISSET(i, &cpuset)) + top = i; + } + if (top == -1) { + top = 0; //Fallback, use CPU 0 + } + } rtapi_print_msg( - RTAPI_MSG_ERR, "No isolated CPU's found, expect some latency or set RTAPI_CPU_NUMBER to select CPU\n" + RTAPI_MSG_ERR, "No isolated CPU's found, expect some latency or set RTAPI_CPU_NUMBER to select CPU.\n" + " CPU %i selected as fallback.\n", top ); } return top;