cpuset and affinity implementation

From: Jeff Roberson <jroberson_at_chesapeake.net>
Date: Sun, 24 Feb 2008 17:38:37 -1000 (HST)
Hello,

I have implemented a new api similar to processors sets on solaris.  This 
allows you to assign processes to sets of cpus and dynamically change 
those sets.  This is useful for provisioning purposes to add and remove 
cpu resources for a particular process or group of processes.  This new 
facility also supports binding secific threads to specific cpus which some 
applications may want to do.  At some point in the future this will be 
integrated with jail so you can restrict the cpus any jail is allowed to 
use.

This api should not be considered final and the 'cpuset' tool is quite 
rough.  This also only works with ULE and is unfortunately intertwined 
with a big ULE patch I've been working on.  The set management code is 
generic but 4BSD doesn't contain the hooks to actually constrain threads.

Please see:
http://people.freebsd.org/~jeff/cpuset.diff

here's a couple of neat things to do with cpuset:

cpuset -l 0-4 /bin/sh

This creates a new group with a list (-l) of cpus 0-4 inclusive and runs sh in 
it.

cpuset -g -p <sh pid>

This will get (-g) the mask of cpus pid (-p) is allowed to run on.

cpuset -l 0,2 -p <sh pid>

This will restrict sh to running on cpus 0, 2 while its group is still allowed 
0-4.

cpuset -l 0,2 -c -p <sh pid>

This will modify the cpuset (-c) that the sh belongs to.

cpuset -l 0-3 -s 1

This will modify the set (-s) that all threads are in by default to contain the 
first 4 cpus leaving the rest idled.

cpuset -g -i -p <sh pid>

This will print the id of the set sh is in.

cpuset -s <set id> -p <pid>

This will move pid into the specified set so it may be managed with other 
pids in that set.

Feedback is appreciated.

Thanks,
Jeff
Received on Mon Feb 25 2008 - 02:37:10 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:39:28 UTC