First, let me give a background of what I am trying to achieve. I know how to isolate a particular CPU using boot param (isolcpu and nohz_full; the housekeeping subsystem setup).
But as per my requirement, I need to isolate the CPU after the system has booted up. So, as per many articles, I tried to isolate a particular CPU using cpuset
subsystem as follows:
I am using a hardware having 16 cpus. (0-15). So, I decided to isolate CPU 0.
$ cd /cpusets
$ mkdir housekeeping
$ mkdir isolate
$ echo 1-15 > housekeeping/cpus
$ echo 0 > mems
$ echo 0 > isolated/cpus
$ echo 0 > isolated/mens
$ echo 0 > cpuset.sched_load_balance
$ echo 0 > isolated/sched_load_balance
$ while read P ; do echo $P > housekeeping/tasks ; done < tasks
This isolates the processor 0
from all the other processors. But when I tried to assign a process to processor 0 using taskset
as follows:
/******loop.c**********/
int main(){
int i;
for(i=0;;i++);
return 0;
}
$ gcc -o loop.c loop
$ taskset -c 0 ./loop
taskset: failed to set pid 2755250's affinity: Invalid argument
Apart from echoing pid 2755250
to isolated/tasks, is it possible to set the affinity of a new process to the isolated CPU 0
?
Where am I making a mistake?
while(true){}
forfor(;;){}
are much more idiomatic. Your code usesi
uninitialized, and has undefined behaviour on signed-integer overflow. If you wanted to slow the loop down by introducing a data dependency through memory in a debug build, usefor (unsigned i=0; ; i++)
so wrap-around is well-defined. It doesn't actually matter in a debug build with a normal compiler for a normal ISA, though; the compiler will still make the same asm (except for actually initializing if you don't omit it), but it seems like a better habit.