Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: uspace: Let the user choose the CPU affinity per hal thread #2514

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions src/rtapi/uspace_rtapi_app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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<PosixTask>(task_id);
Expand Down Expand Up @@ -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;
Expand Down