CPUSET Filesystem




Creating, modifying, using the cpusets can be done through the cpuset pseudo filesystem.

To mount it, type:
# mount -t cpuset none /dev/cpuset
Then under /dev/cpuset you can find a tree that corresponds to the tree of the cpusets in the system. For instance, /dev/cpuset/ is the cpuset that holds the whole system.

If you want to create a new cpuset under the top cpuset:
# cd /dev/cpuset/
# mkdir my_cpuset
Now you want to do something with this cpuset.
# cd my_cpuset
In this directory you can find several files:
# ls
cpu_exclusive  cpus  mem_exclusive  mems  notify_on_release  placement  tasks  virtualize
Reading them will give you information about the state of this cpuset: the CPUs it can use, the processes that are using it, its properties... And Writing to these files you can manipulate the cpuset.

Set some flags:
# echo 1 > notify_on_release
(Be sure to read this note about echo).
Add some cpus:
# echo 0-7 > cpus
Now attach your shell to this cpuset:
# echo $$ > tasks
You can also create cpusets inside your cpuset by using mkdir in this directory.
# mkdir my_sub_cs
To remove a cpuset, juste use rmdir:
# rmdir my_sub_cs
Note that this will fail is the cpuset is in use (has cpusets inside, or has processes attached).

Adding/removing cpus

Syntax for adding/removing cpus has been simplified. Now you just have to enter what you want to be the list of CPUs:
# echo 1-4 > cpus          -> set cpus list to cpus 1,2,3,4
# echo 1,2,3,4 > cpus      -> set cpus list to cpus 1,2,3,4

Setting flags

The syntax is very simple:
# echo 1 > cpu_exclusive       -> set flag 'cpu_exclusive'
# echo 0 > cpu_exclusive       -> unset flag 'cpu_exclusive'
# echo 1 > notify_on_release   -> set flag 'notify_on_release'

Attaching processes

To attach process with pid PID to this cpuset:
# echo PID > tasks
Note you can only attach ONE task at a time. If you have several tasks to attach, you have to do it one after another:
# echo PID1 > tasks
# echo PID2 > tasks
...
# echo PIDn > tasks



IMPORTANT NOTE:
Make sure you use a echo command that checks for errors. Some versions of /bin/echo ignore them. bash's builtin will return a non-zero error code but print no error message. You can use this macro:
echo()
{
	/bin/echo | cat
}
Thu Jan 8 15:36:43 CET 2004