1

Is it possible to isolate a cpu from the linux scheduler in code, and to grant a user rights to do this so that he doesn't have to be root?

I can readily set a process/thread's cpu affinity:

// set thread affinity to core 1
cpu_set_t cpu_set;
CPU_ZERO(&cpu_set);
CPU_SET(1, &cpu_set);
sched_setaffinity(tid, sizeof(cpu_set_t), &cpu_set);

I would now like to isolate this cpu from all other processes in the system.

I know that I can do this on Redhat using tuna:

sudo tuna --cpus 1 --isolate
sudo tuna --cpus 3 --isolate

I read somewhere that it is possible to isolate as follows:

sudo echo 0 > /sys/devices/system/cpu/cpu1/online 
sudo echo 1 > /sys/devices/system/cpu/cpu1/isolated
sudo echo 1 > /sys/devices/system/cpu/cpu1/online 

However, attempts to create the isolated file fail with Permission denied

Finally, is there a way to grant a particular user rights to isolate a cpu (much like it is possible to increase certain limits in /etc/security/limits.conf)?

username              hard       memlock         unlimited
username              soft       memlock         unlimited
username              -          rtprio          99
Steve Lorimer
  • 27,059
  • 17
  • 118
  • 213
  • Is it acceptable to use `setfacl(1)` to add the correct capability (check `capabilities(7)` for details; probably `CAP_SYS_NICE`, `CAP_SYS_RESOURCE`, or `CAP_SYS_ADMIN`) to an executable? – sarnold Feb 29 '12 at 12:14

1 Answers1

0

The files in /sys that you mention are created and maintained automatically by the operating system - it is a virtual filesystem and not regular files on hard disk, so you can't create them yourself.

The subsystem responsible for the particular files you mention is called "CPU hotplug" and is described here. Apparently, you need a kernel which supports this functionality, so either look into what kernels are available for your distribution (this option is likely to be only in kernels set up for advanced server use) or compile your own and make sure "CPU hotplug" (CONFIG_HOTPLUG_CPU=y) is enabled.

Michał Kosmulski
  • 9,855
  • 1
  • 32
  • 51