aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephan Baerwolf <stephan.baerwolf@tu-ilmenau.de>2011-05-11 12:03:29 -0400
committerIngo Molnar <mingo@elte.hu>2011-05-16 05:01:18 -0400
commitdb670dac49b5423b39b5e523d28fe32045d71b10 (patch)
tree194220c83cb097504ddf7bcccc7ce93d6a23eac3
parentdb44fc017d5989302713ab4e7f9e922b648f4b59 (diff)
sched: Fix and optimise calculation of the weight-inverse
If the inverse loadweight should be zero, function "calc_delta_mine" calculates the inverse of "lw->weight" (in 32bit integer ops). This calculation is actually a little bit impure (because it is inverting something around "lw-weight"+1), especially when "lw->weight" becomes smaller. The correct inverse would be 1/lw->weight multiplied by "WMULT_CONST" for fixcomma-scaling it into integers. (So WMULT_CONST/lw->weight ...) The old, impure algorithm took two divisions for inverting lw->weight, the new, more exact one only takes one and an additional unlikely-if. Signed-off-by: Stephan Baerwolf <stephan.baerwolf@tu-ilmenau.de> Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl> Cc: Linus Torvalds <torvalds@linux-foundation.org> Link: http://lkml.kernel.org/n/tip-0pz0wnyalr4tk4ln11xwumdx@git.kernel.org [ This could explain some aritmetical issues for small shares but nothing concrete has been reported yet so we are not confident enough to queue this up in sched/urgent and for -stable backport. But if anyone finds this commit and sees it to fix some badness then we can certainly change our mind! ] Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r--kernel/sched.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/kernel/sched.c b/kernel/sched.c
index 70bec4f1edbb..c62acf45d3b9 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -1330,15 +1330,15 @@ calc_delta_mine(unsigned long delta_exec, unsigned long weight,
1330{ 1330{
1331 u64 tmp; 1331 u64 tmp;
1332 1332
1333 tmp = (u64)delta_exec * weight;
1334
1333 if (!lw->inv_weight) { 1335 if (!lw->inv_weight) {
1334 if (BITS_PER_LONG > 32 && unlikely(lw->weight >= WMULT_CONST)) 1336 if (BITS_PER_LONG > 32 && unlikely(lw->weight >= WMULT_CONST))
1335 lw->inv_weight = 1; 1337 lw->inv_weight = 1;
1336 else 1338 else
1337 lw->inv_weight = 1 + (WMULT_CONST-lw->weight/2) 1339 lw->inv_weight = WMULT_CONST / lw->weight;
1338 / (lw->weight+1);
1339 } 1340 }
1340 1341
1341 tmp = (u64)delta_exec * weight;
1342 /* 1342 /*
1343 * Check whether we'd overflow the 64-bit multiplication: 1343 * Check whether we'd overflow the 64-bit multiplication:
1344 */ 1344 */