CPU shielding using /proc and /dev/cpuset
(Initial info) |
|||
Line 24: | Line 24: | ||
The kernel has an cpuset feature that allows you to create cpusets for real-time purposes. The kernel interface is proc filesystem based. It is described in {{path|/usr/src/kernel/Documentation/cpusets.txt}}. | The kernel has an cpuset feature that allows you to create cpusets for real-time purposes. The kernel interface is proc filesystem based. It is described in {{path|/usr/src/kernel/Documentation/cpusets.txt}}. | ||
+ | |||
+ | Here is a quick example of how to use cpuset to reserve one cpu for your real-time process on a 4 cpu machine: | ||
+ | |||
+ | {{cmdroot|mkdir /dev/cpuset/rt0}} | ||
+ | |||
+ | {{cmdroot|echo 0 > /dev/cpuset/rt0/cpus}} | ||
+ | |||
+ | {{cmdroot|echo 0 > /dev/cpuset/rt0/mems}} | ||
+ | |||
+ | {{cmdroot|echo 1 > /dev/cpuset/rt0/cpu_exclusive}} | ||
+ | |||
+ | {{cmdroot|echo $RT_PROC_PID > /dev/cpuset/rt0/tasks}} | ||
+ | |||
+ | {{cmdroot|mkdir /dev/cpuset/system}} | ||
+ | |||
+ | {{cmdroot|echo 1-3 > /dev/cpuset/system/cpus}} | ||
+ | |||
+ | {{cmdroot|echo 0 > /dev/cpuset/system/mems}} | ||
+ | |||
+ | {{cmdroot|echo 1 > /dev/cpuset/system/cpu_exclusive}} | ||
+ | |||
+ | {{cmdroot|for pid in $(cat /dev/cpuset/tasks); do /bin/echo $pid > /dev/cpuset/system/tasks; done}} |
Revision as of 13:34, 14 June 2007
Interrupt shielding
In order to shield CPUs from individual interrupts being serviced on them you have to make sure that the following kernel configuration parameter is set:
- CONFIG_IRQBALANCE
Then make sure that the interrupts are not automatically balanced by the irqbalance daemon. This daemon is started from the irqbalance init script. To disable once do:
# /etc/init.d/irqbalance stop
To disable after next reboot do:
# chkconfig irqbalance off
After this you can change the CPU affinity mask of each interrupt by doing:
# echo hex_mask > /proc/irq/irq_number/smp_affinity
More information can be found in /usr/src/kernel/Documentation/IRQ-affinity.txt
.
Process shielding
The kernel has an cpuset feature that allows you to create cpusets for real-time purposes. The kernel interface is proc filesystem based. It is described in /usr/src/kernel/Documentation/cpusets.txt
.
Here is a quick example of how to use cpuset to reserve one cpu for your real-time process on a 4 cpu machine:
# mkdir /dev/cpuset/rt0
# echo 0 > /dev/cpuset/rt0/cpus
# echo 0 > /dev/cpuset/rt0/mems
# echo 1 > /dev/cpuset/rt0/cpu_exclusive
# echo $RT_PROC_PID > /dev/cpuset/rt0/tasks
# mkdir /dev/cpuset/system
# echo 1-3 > /dev/cpuset/system/cpus
# echo 0 > /dev/cpuset/system/mems
# echo 1 > /dev/cpuset/system/cpu_exclusive
# for pid in $(cat /dev/cpuset/tasks); do /bin/echo $pid > /dev/cpuset/system/tasks; done