tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: CPUs and processes not evenly assigned?!



christos%astron.com@localhost (Christos Zoulas) writes:

>>                 /* Average count of the threads */
>>-               ci_rq->r_avgcount = (ci_rq->r_avgcount + ci_rq->r_mcount) >> 1;


>I think that the code is wrong here; I think it should be using r_count...

>		u_int totcount = ci_rq->r_count + ci_rq->r_mcount;
>		ci_rq->r_avgcount = totcount >> 1;



r_count is the number of threads scheduled on that CPU, that includes
r_mcount. So you get number of migratable threads + half of number
of non-migratable threads. And the division again causes a rounding
error.


The balancer is supposed to base its decision on the average number
of migratable threads.

So

	r_avgcount = alpha * r_avgcount + (1 - alpha) * (float)r_mcount;

is what you would need to get a moving average over the number of
migratable threads with a coefficient 'alpha'. Assuming you could
use floating point.

Since we don't have floating point the computation should be done in
fixed point arithmetic, e.g.

	r_avgcount = (A * r_avgcount + B * INT2FIX(r_mcount)) / (A + B);

With the current A=B=1 you get alpha=0.5, but other values are thinkable
to make the balancer decide on the short term thread count or an even
longer term moving average.

Using one fractional bit for INT2FIX by multiplying by two might not
be enough.

-- 
-- 
                                Michael van Elst
Internet: mlelstv%serpens.de@localhost
                                "A potential Snark may lurk in every tree."


Home | Main Index | Thread Index | Old Index