Linux-RT processor affinity cpusets

cset examples

It is very easy to assign tasks to a particular processor or processor set!!!

For proper permissions: sudo or su root or add yourself to the admin group or /etc/sudoers file.
Use /bin/echo or just echo worked on my Ubuntu instance.
Obviously you can omit the full paths and use relative paths below, commands are listed with full paths for clarity.

mount the cpuset filesystem, add it to /etc/fstab to make it permanent and create a script called at startup to perform the subsequent initialization
 mkdir /dev/cpuset
 mount -t cpuset cpuset /dev/cpuset

set the sched_load_balance flag to zero - at that point the scheduler is not moving tasks among processors anymore, you may immediate notice in the System Monitor variation in the processor load if they weren't balanced at the moment this command was executed
 cd /dev/cpuset
 echo 0 > sched_load_balance

create a sub cpuset for each processor or set of processor if you have more than 2
 mkdir /dev/cpuset/cpu0
 mkdir /dev/cpuset/cpu1 

assign cpus and memory to the mems for each cpuset - my config only has one so I set it the same for each
 echo 0 > /dev/cpuset/cpu0/mems
 echo 0 > /dev/cpuset/cpu0/cpus
 echo 0 > /dev/cpuset/cpu0/mems
 echo 1 > /dev/cpuset/cpu1/cpus

migrate all tasks to one cpuset
 while read i; do echo $i; done \
  < /dev/cpuset/tasks > /dev/cpuset/cpu0/tasks

migrate the critical task(s) to the dedicated cpuset
 echo <task pid> > /dev/cpuset/cpu1/tasks


References:

cpusets.txt extend existing affinity mechanisms

Excerpts from cpusets.txt:

For real-time the top cpuset flag "sched_load_balance" should be disabled

By default, there is one sched domain covering all CPUs, except those marked isolated using the kernel boot time "isolcpus=" argument.

mounting cpuset filesystem


man cpuset filesystem


pin process to different CPU cores (using numactl)
pin to different physically memory based on NUMA nodes

Java Affinity Library

http://java.dzone.com/articles/java-threads-steroids





  • CPUs were additionaly occupied by handling IRQs, so reconfiguring irq load balancing by using IRQBALANCE_BANNED_CPUS could render slightly better results
  • The exact number of context switches can be measured using SystemTap or by examiningctxt property value in /proc/stat
  • You can achieve better results by employing Linux cgroups to separate application workload from system tasks by assigning two separate resource pools to those two different groups



  • http://wiki.linuxcnc.org/cgi-bin/wiki.pl?The_Isolcpus_Boot_Parameter_And_GRUB2


    ps aux | awk '{print $2}' > pids

    while read i; do taskset -cp 0 $i; done < pids

    Comments

    Popular posts from this blog

    Sites, Newsletters, and Blogs

    Oracle JDBC ReadTimeout QueryTimeout