Commit b2a0e913 authored by Ingo Molnar's avatar Ingo Molnar Committed by Linus Torvalds

[PATCH] sched: fix timeslice calculations for HZ=1000.

The main benefit is that with the default HZ=1000 nice +19 tasks now get 5
msecs of timeslices, so the ratio of CPU use is linear.  (nice 0 task gets
20 times more CPU time than a nice 19 task.  Prior this change the ratio
was 1:10)

another effect is that nice 0 tasks now get a round 100 msecs of timeslices
(as intended), instead of 102 msecs.

here's a table of old/new timeslice values, for HZ=1000 and 100:

                      HZ=1000         (   HZ=100   )
                    old    new        ( old    new )

        nice -20:   200    200        ( 200    200 )
        nice -19:   195    195        ( 190    190 )
        ...
        nice 0:     102    100        ( 100    100 )
        nice 1:      97     95        (  90     90 )
        nice 2:      92     90        (  90     90 )
        ...
        nice 17:     19     15        (  10     10 )
        nice 18:     14     10        (  10     10 )
        nice 19:     10      5        (  10     10 )

i've tested the patch on x86.
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarAndrew Morton <akpm@osdl.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 5a528e75
......@@ -79,11 +79,11 @@
/*
* These are the 'tuning knobs' of the scheduler:
*
* Minimum timeslice is 10 msecs, default timeslice is 100 msecs,
* maximum timeslice is 200 msecs. Timeslices get refilled after
* they expire.
* Minimum timeslice is 5 msecs (or 1 jiffy, whichever is larger),
* default timeslice is 100 msecs, maximum timeslice is 200 msecs.
* Timeslices get refilled after they expire.
*/
#define MIN_TIMESLICE ( 10 * HZ / 1000)
#define MIN_TIMESLICE max(5 * HZ / 1000, 1)
#define MAX_TIMESLICE (200 * HZ / 1000)
#define ON_RUNQUEUE_WEIGHT 30
#define CHILD_PENALTY 95
......@@ -171,9 +171,9 @@
* task_timeslice() is the interface that is used by the scheduler.
*/
#define BASE_TIMESLICE(p) (MIN_TIMESLICE + \
((MAX_TIMESLICE - MIN_TIMESLICE) * \
(MAX_PRIO-1 - (p)->static_prio) / (MAX_USER_PRIO-1)))
#define BASE_TIMESLICE(p) \
max(MAX_TIMESLICE * (MAX_PRIO - (p)->static_prio) / (MAX_USER_PRIO), \
MIN_TIMESLICE)
static unsigned int task_timeslice(task_t *p)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment