diff --git a/src/rtapi/uspace_rtapi_app.cc b/src/rtapi/uspace_rtapi_app.cc index 440727b17cb..1b149492c21 100644 --- a/src/rtapi/uspace_rtapi_app.cc +++ b/src/rtapi/uspace_rtapi_app.cc @@ -960,9 +960,7 @@ int Posix::task_delete(int id) return 0; } -static int find_rt_cpu_number() { - if(getenv("RTAPI_CPU_NUMBER")) return atoi(getenv("RTAPI_CPU_NUMBER")); - +static int probe_rt_cpu_number() { #ifdef __linux__ cpu_set_t cpuset_orig; int r = sched_getaffinity(getpid(), sizeof(cpuset_orig), &cpuset_orig); @@ -1008,6 +1006,24 @@ static int find_rt_cpu_number() { #endif } +static int find_rt_cpu_number(int prio) { + static const int probed_cpu_number = probe_rt_cpu_number(); + + char cpu_env[64]; + const char *minus = ""; + if (prio < 0) { + prio = -prio; + minus = "m"; + } + snprintf(cpu_env, sizeof(cpu_env), "RTAPI_CPU_NUMBER_PRIO%s%d", minus, prio); + if(getenv(cpu_env)) + return atoi(getenv(cpu_env)); + if(getenv("RTAPI_CPU_NUMBER")) + return atoi(getenv("RTAPI_CPU_NUMBER")); + + return probed_cpu_number; +} + int Posix::task_start(int task_id, unsigned long int period_nsec) { auto task = ::rtapi_get_task(task_id); @@ -1039,7 +1055,7 @@ int Posix::task_start(int task_id, unsigned long int period_nsec) if(pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) < 0) return -errno; if(nprocs > 1) { - const static int rt_cpu_number = find_rt_cpu_number(); + int rt_cpu_number = find_rt_cpu_number(task->prio); if(rt_cpu_number != -1) { #ifdef __FreeBSD__ cpuset_t cpuset;