[Toybox] new toy: taskset

Elie De Brauwer eliedebrauwer at gmail.com
Sun Jul 15 04:34:43 PDT 2012


Hello all,

In attach you can find an initial version of 'taskset'. It allows 
setting the cpu affinity of a given PID (or all tasks related with a 
given PID/TID). cpu affinity should be entered in hex, when no affinity 
is given the affinity for the process or the group of tasks is displayed.

I tested it (a.o.) with a yes > /dev/null and a top which shows the cpu 
load per core, and then you can see yes jump around

edb at lapedb:~/edb-stuff/toybox/toybox$ sudo ./toybox taskset 0x1 20941
pid 20941's current affinity mask: ff
pid 20941's new affinity mask: 1
edb at lapedb:~/edb-stuff/toybox/toybox$ sudo ./toybox taskset 0x2 20941
pid 20941's current affinity mask: 1
pid 20941's new affinity mask: 2
edb at lapedb:~/edb-stuff/toybox/toybox$ sudo ./toybox taskset 0x4 20941
pid 20941's current affinity mask: 2
pid 20941's new affinity mask: 4
edb at lapedb:~/edb-stuff/toybox/toybox$ sudo ./toybox taskset 0x8 20941
pid 20941's current affinity mask: 4
pid 20941's new affinity mask: 8
edb at lapedb:~/edb-stuff/toybox/toybox$ sudo ./toybox taskset 0x10 20941
pid 20941's current affinity mask: 8
pid 20941's new affinity mask: 10
edb at lapedb:~/edb-stuff/toybox/toybox$ sudo ./toybox taskset 0x20 20941
pid 20941's current affinity mask: 10
pid 20941's new affinity mask: 20
edb at lapedb:~/edb-stuff/toybox/toybox$ sudo ./toybox taskset 0x30 20941
pid 20941's current affinity mask: 20
pid 20941's new affinity mask: 30
edb at lapedb:~/edb-stuff/toybox/toybox$ sudo ./toybox taskset 0x40 20941
pid 20941's current affinity mask: 30
pid 20941's new affinity mask: 40
edb at lapedb:~/edb-stuff/toybox/toybox$ sudo ./toybox taskset 0x80 20941
pid 20941's current affinity mask: 40
pid 20941's new affinity mask: 80

One comment, I added sched.h into the toys.h include, but I also needed 
a #define _GNU_SOURCE or I'd run into troubles because it failed to find 
the CPU_SET* macro's. So this was added in taskset.c but I'm not sure if 
this is the correct way to go.

my 2 cents
E.


-- 
Elie De Brauwer

-------------- next part --------------
A non-text attachment was scrubbed...
Name: taskset.patch
Type: text/x-patch
Size: 3691 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20120715/f8dda953/attachment-0006.bin>


More information about the Toybox mailing list