PDA

View Full Version : Binding processes to diffrent cpu's (for you dual core guys out there)


adoroar
02-26-2006, 12:01 PM
I got bored and decided to try this out today, here's how:

First your gona need a kernel with this option compiled in.
CONFIG_CPUSETS (Under General Setup --->)
I checked debian's smp kernel, and it doesn't have this option set, can't say about any other distro's.

All the documentation you'll need is in Documentation/cpusets.txt in your kernel source.

So let's go:
First mount cpuset
mkdir /dev/cpuset
mount -t cpuset none /dev/cpuset

Then create a profile for one of your cpu's
cd /dev/cpuset
mkdir cpu0
cd cpu0
echo 1 > cpu_exclusive
echo 0 > mems # check cat /dev/cpuset/mems for valid options, I atleast can't set tasks without specifying this.
echo 0 > cpus # 0 here is the first cpu


Now for the sake of this tutorial I'm gona use gnuchess as an example
start gnuchess, and then type go and press enter, then you'll see your cpu jump up to 100% straight away(gkrellm is a nice app to watch both cpu's)
Then do.

echo `pidof gnuchess` > tasks

And watch all the load on one cpu, now to get that load over to the other cpu.

cd /dev/cpuset
mkdir cpu1
cd cpu1
echo 1 > cpu_exclusive
echo 0 > mems
echo 1 > cpus # 1 here is the second cpu.

Then

echo `pidof gnuchess` > tasks

And watch the other one light up!

To add more than one process to the tasks file just do echo `pidof someapp` >> tasks
And to remove a profile use rmdir profilename instead of rm.

Fun eh? :w00t:

bigtrouble77
02-26-2006, 07:35 PM
So is this like the equivalent of setting the affinity? Your just telling the apps to run on a specific core? If so that's pretty nifty and probably have some uses for it. (like running a chrooted 32bit environment on a second core)