CPU shielding using /proc and /dev/cpuset

From RTwiki
(Difference between revisions)
Jump to: navigation, search
m (Protected "CPU shielding using /proc and /dev/cpuset": This page has been migrated to the Linux Foundation RT wiki. (‎[edit=sysop] (indefinite) ‎[move=sysop] (indefinite)))
 
Line 1: Line 1:
== Interrupt shielding ==
 
  
=== Kernel Space ===
+
<div style="margin:0; margin-top:10px; margin-right:10px; border:1px solid #dfdfdf; padding:0 1em 1em 1em; background-color:#f9e9e9; align:right;">
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:
+
<b>This wiki is being migrated to the Linux Foundation Real-Time Linux Project hosted wiki. The new pages are available at: https://wiki.linuxfoundation.org/realtime/documentation/howto/tools/cpu-partitioning/cpusets and https://wiki.linuxfoundation.org/realtime/documentation/howto/tools/cpu-partitioning/irqbalanced. This page is now deprecated.</b>
 
+
</div>
*CONFIG_IRQBALANCE
+
 
+
 
+
=== User Space ===
+
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:
+
 
+
{{cmdroot|/etc/init.d/irqbalance stop}}
+
 
+
To disable after next reboot do:
+
 
+
{{cmdroot|chkconfig irqbalance off}}
+
 
+
After this you can change the CPU affinity mask of each interrupt by doing:
+
 
+
{{cmdroot|echo ''hex_mask'' > /proc/irq/''<irq_number>''/smp_affinity}}
+
 
+
To check that the affinity mask has been set you can check the contents of the smp_affinity file. {{NOTE|The mask is updated the next time an interrupt is serviced. So you may not see the change immediately.}}
+
 
+
More information can be found in {{path|/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 {{path|/usr/src/kernel/Documentation/cgroups/cpusets.txt}}.
+
 
+
Each cpuset is represented by a directory in the cgroup file system
+
containing (on top of the standard cgroup files) the following
+
files describing that cpuset:
+
 
+
<pre>
+
  - cpus: list of CPUs in that cpuset
+
  - mems: list of Memory Nodes in that cpuset
+
  - memory_migrate flag: if set, move pages to cpusets nodes
+
  - cpu_exclusive flag: is cpu placement exclusive?
+
  - mem_exclusive flag: is memory placement exclusive?
+
  - mem_hardwall flag:  is memory allocation hardwalled
+
  - memory_pressure: measure of how much paging pressure in cpuset
+
  - memory_spread_page flag: if set, spread page cache evenly on allowed nodes
+
  - memory_spread_slab flag: if set, spread slab cache evenly on allowed nodes
+
  - sched_load_balance flag: if set, load balance within CPUs on that cpuset
+
  - sched_relax_domain_level: the searching range when migrating tasks
+
</pre>
+
 
+
In addition, the root cpuset only has the following file:
+
<pre>
+
  - memory_pressure_enabled flag: compute memory_pressure?
+
</pre>
+
 
+
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}}
+

Latest revision as of 09:57, 21 December 2017

This wiki is being migrated to the Linux Foundation Real-Time Linux Project hosted wiki. The new pages are available at: https://wiki.linuxfoundation.org/realtime/documentation/howto/tools/cpu-partitioning/cpusets and https://wiki.linuxfoundation.org/realtime/documentation/howto/tools/cpu-partitioning/irqbalanced. This page is now deprecated.

Personal tools