[Toybox] patch: taskset-work-as-nice (was Re: new toy: taskset)

Elie De Brauwer eliedebrauwer at gmail.com
Fri Jul 20 00:51:26 PDT 2012


On 07/19/2012 03:41 AM, Rob Landley wrote:
>> Meaning to works as renice, rather than nice. I'm open to suggestions, I
>> can as well the 'work-as-nice' functionality,
>
> Is there more to it than:
>
>    if (opt.argc>2) xexec(toys.optargs+2);
>
> Well, taskset getpid() and then exec. And detect -p... ok there's a bit
> of work.
>
> I'd prefer if you could add the new work-as-nice stuff since you know
> what the UI should be like, and I'll hold off converting to the raw
> syscall until then. Sound good?
>

In attach a patch which makes taskset work as both nice (and renice, the 
existing behavior).

The following example which spawns four loops:

#include <pthread.h>

void * loop(void * ptr)
{
     while(1){}
}

int main()
{
     int i = 0;
     for (i=0; i< 4; i++)
     {
         pthread_t tid;
         pthread_create(&tid, NULL, loop, NULL);
     }
     sleep(100);
     return 0;
}

executed as follows:

edb at lapedb:~/edb-stuff/toybox/toybox$ sudo ./toybox taskset 55 ./a.out

on my poor little quad-core with hyperthreading gives the following top 
output:

top - 09:50:37 up  1:23, 14 users,  load average: 3.52, 1.49, 0.79
Tasks: 195 total,   1 running, 193 sleeping,   0 stopped,   1 zombie
%Cpu0  : 99.7 us,  0.0 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  0.3
%Cpu1  :  7.3 us,  2.7 sy,  0.0 ni, 90.0 id,  0.0 wa,  0.0 hi,  0.0
%Cpu2  :100.0 us,  0.0 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  0.0
%Cpu3  :  6.0 us,  4.0 sy,  0.0 ni, 90.0 id,  0.0 wa,  0.0 hi,  0.0
%Cpu4  :100.0 us,  0.0 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  0.0
%Cpu5  :  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0
%Cpu6  :100.0 us,  0.0 sy,  0.0 ni,  0.0 id,  0.0 wa,  0.0 hi,  0.0
%Cpu7  :  0.7 us,  0.0 sy,  0.0 ni, 99.3 id,  0.0 wa,  0.0 hi,  0.0

my 2 cents
E.

-- 
Elie De Brauwer

-------------- next part --------------
A non-text attachment was scrubbed...
Name: taskset_work_as_nice.patch
Type: text/x-patch
Size: 2868 bytes
Desc: not available
URL: <http://lists.landley.net/pipermail/toybox-landley.net/attachments/20120720/01676a5e/attachment-0007.bin>


More information about the Toybox mailing list