Log in



Isolating a CPU / core in Linux

Tuesday, February 24th, 2009 by Peter

For some measurement task, we needed to isolate one CPU core on an Intel Quad Core machine under Linux 2.6. With the background of SMP and NUMA system support, Linux provides the following options:

  • isolcpus=[]: This is an old kernel boot parameter, which allows the isolate one or more CPU’s from the scheduler. Processes can still be placed on this processors by explicit affinity system calls. Processors are still utilized for interrupt processing, since they are only taken away from the OS scheduler. Modern kernels implement this feature with the (anyway given) scheduling domain support, a part of the cpu sets functionality. The kernel boot option was therefore lately requested to be removed.
  • CPU sets:  CPU sets constrain the CPU and Memory placement of tasks to only the resources within a tasks current set. Specifically, the sched_setaffinity() and the mbind() system calls are accordingly intercepted. The scheduler has also support to partition the system CPU’s into a number of scheduling domains. By default, there is one scheduling domain covering all CPUs, except those marked with isolcpus (see above). After mounting the according device, you can create custom CPU sets and assign tasks and processors to it. In our experiments, it was not possible to remove a core from the default CPU set. Aquick check of the sources showed that this is intentional, even though the error code is misleading:

    mount -t cgroup -o cpuset cpuset /dev/cpuset
    root@intel:/dev/cpuset# cat cpuset.cpus
    0-3
    root@intel:/dev/cpuset# /bin/echo 0,1,2 > cpuset.cpus
    /bin/echo: Schreibfehler: Keine Berechtigung

  • CPU hotplug: The CPU hotplug implementation provides exhaustive support for CPU management within the SYSFS file system tree. The implementation also frees the CPU from interrupts and timers. A simple echo 0 > /sys/devices/system/cpu/cpuX/online puts the particular CPU off-line. With a very recent kernel, it also works for single cores in our system:

    root@intel:/sys/devices/system/cpu/cpu0# ls -l
    drwxr-xr-x 5 root root 0 24. Feb 18:59 cache
    drwxr-xr-x 4 root root 0 24. Feb 18:59 cpufreq
    drwxr-xr-x 2 root root 0 24. Feb 18:59 microcode
    drwxr-xr-x 2 root root 0 24. Feb 18:59 thermal_throttle
    drwxr-xr-x 2 root root 0 24. Feb 18:59 topology

If you want to check if your disabling activity was successful, check the output of /proc/interrupts.

Leave a Reply