I am using
cset shield to create a user shield with a set of cpus
cset shield --cpu 1,3,5,7 --kthread on
The idea behind this is to reserve these cpus for my application code, and push all other tasks plus the movable kernel threads onto the other cpus.
In my application I create 4 threads, and in the context of each thread, attempt to use
sched_setaffinity to pin each thread onto one of the reserved cpus.
int cpuNum = 1; // each thread gets one of the cpus pid_t threadId = static_cast<pid_t>(syscall(SYS_gettid)); cpu_set_t cpuSet; CPU_ZERO(&cpuSet); CPU_SET(cpuNum, &cpuSet); if (sched_setaffinity(threadId, sizeof(cpu_set_t), &cpuSet) == -1) perror("sched_setaffinity");
sched_setaffinity fails with
If I run my application using
cset shield --exec ./TestApp then the pinning works
How come the naked
sched_setaffinity call fails?