Skip to content

Commit

Permalink
sched: round a bit better
Browse files Browse the repository at this point in the history
round a tiny bit better in high-frequency rescheduling scenarios,
by rounding around zero instead of rounding down.

(this is pretty theoretical though)

Signed-off-by: Ingo Molnar <mingo@elte.hu>
  • Loading branch information
Ingo Molnar committed Aug 9, 2007
1 parent 254753d commit 194081e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions kernel/sched.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,25 +638,29 @@ static u64 div64_likely32(u64 divident, unsigned long divisor)

#define WMULT_SHIFT 32

/*
* Shift right and round:
*/
#define RSR(x, y) (((x) + (1UL << ((y) - 1))) >> (y))

static unsigned long
calc_delta_mine(unsigned long delta_exec, unsigned long weight,
struct load_weight *lw)
{
u64 tmp;

if (unlikely(!lw->inv_weight))
lw->inv_weight = WMULT_CONST / lw->weight;
lw->inv_weight = (WMULT_CONST - lw->weight/2) / lw->weight + 1;

tmp = (u64)delta_exec * weight;
/*
* Check whether we'd overflow the 64-bit multiplication:
*/
if (unlikely(tmp > WMULT_CONST)) {
tmp = ((tmp >> WMULT_SHIFT/2) * lw->inv_weight)
>> (WMULT_SHIFT/2);
} else {
tmp = (tmp * lw->inv_weight) >> WMULT_SHIFT;
}
if (unlikely(tmp > WMULT_CONST))
tmp = RSR(RSR(tmp, WMULT_SHIFT/2) * lw->inv_weight,
WMULT_SHIFT/2);
else
tmp = RSR(tmp * lw->inv_weight, WMULT_SHIFT);

return (unsigned long)min(tmp, (u64)(unsigned long)LONG_MAX);
}
Expand Down

0 comments on commit 194081e

Please sign in to comment.