2.6.34.7中让人费解的effective_load

来源:互联网 发布:手机聊天软件开发 编辑:程序博客网 时间:2024/05/12 09:43

2.6.34.7中计算effective_load的代码很不好理解,Peter Zijlstra 如是在2011年提了一个patch,运用了更清晰明了的实现和文字注释。

http://lkml.indiana.edu/hypermail/linux/kernel/1110.1/02082.html

Add a comment to effective_load() since its a pain

 

回头看了一下这个不好理解的代码,做了一下推导,其结果和新的实现是一样的。


effective load ==》

Calculate the effective load difference if @wl is added (subtracted) to @tg
 on this @cpu and results in a total addition (subtraction) of @wg to the
 total group weight.

目标是要计算进程组的某个CPU对应的运行队列中增加/减少某个进程后, 这个进程的有效weight改变量, s1指的是运行队列在计算之前的share值。

dw_s =( ( rw + wl ) / ( wg + g ) ) * S - s1

rw --> 本CPU对应的运行队列的weight

wl --> 进程的weight。

wg --> 进程组的weight值改变量。

g  --> 进程组的weight值。


下面代码的算法为:

  S = se->my_q->tg->shares;
  s = se->my_q->shares;
  rw = se->my_q->rq_weight;

  a = S*(rw + wl);
  b = S*rw + s*wg;

  wl = s*(a-b);

  if (likely(b))
   wl /= b;

 

s1*(a-b)/b = s1*(a/b) - s1 ==> s1 * ( S*(rw+wl) ) / ( S*rw + s1*wg ) ) - s1 

分子分母同除S ==> s1 * ( rw + wl ) / ( rw + s1/S*wg ) - s1

分子分母同乘S/s1 ==> S * ( rw + wl ) / ( rw * S/s1 + wg )  - s1  

rw* S/s1 = g 得出 ==> ( ( rw + wl ) / ( wg + g ) ) * S - s1


0 0