Strange interactivity behaviour
Possible Problem:
There may be a truncation error in kernel/sched.c triggered when the nice value is negative. The affected code is used in the TASK_INTERACTIVE macro.
The code is:
#define SCALE(v1,v1_max,v2_max) \ (v1) * (v2_max) / (v1_max)
which is used in this way:SCALE(TASK_NICE(p), 40, MAX_BONUS)
Comments in the code says:
* This part scales the interactivity limit depending on niceness. *
* We scale it linearly, offset by the INTERACTIVE_DELTA delta.
* Here are a few examples of different nice levels:
*
* TASK_INTERACTIVE(-20): [1,1,1,1,1,1,1,1,1,0,0] * TASK_INTERACTIVE(-10): [1,1,1,1,1,1,1,0,0,0,0] * TASK_INTERACTIVE( 0): [1,1,1,1,0,0,0,0,0,0,0] * TASK_INTERACTIVE( 10): [1,1,0,0,0,0,0,0,0,0,0] * TASK_INTERACTIVE( 19): [0,0,0,0,0,0,0,0,0,0,0]
*
* (the X axis represents the possible -5 ... 0 ... +5 dynamic
* priority range a task can explore, a value of '1' means the
* task is rated interactive.)
However, the current code does not scale it linearly and the result differs from the given examples. If the mathematical function "floor" is used when the nice value is negative instead of the truncation one gets when using integer division, the result conforms to the documentation.
I belive that this is a bug. Is this correct or have i misunderstood something?
/Martin Andersson
---
Output of TASK_INTERACTIVE when using the kernel code:
nice dynamic priorities -20 1 1 1 1 1 1 1 1 1 0 0 -19 1 1 1 1 1 1 1 1 0 0 0 -18 1 1 1 1 1 1 1 1 0 0 0 -17 1 1 1 1 1 1 1 1 0 0 0 -16 1 1 1 1 1 1 1 1 0 0 0 -15 1 1 1 1 1 1 1 0 0 0 0 -14 1 1 1 1 1 1 1 0 0 0 0 -13 1 1 1 1 1 1 1 0 0 0 0 -12 1 1 1 1 1 1 1 0 0 0 0 -11 1 1 1 1 1 1 0 0 0 0 0 -10 1 1 1 1 1 1 0 0 0 0 0 -9 1 1 1 1 1 1 0 0 0 0 0 -8 1 1 1 1 1 1 0 0 0 0 0 -7 1 1 1 1 1 0 0 0 0 0 0 -6 1 1 1 1 1 0 0 0 0 0 0 -5 1 1 1 1 1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-4 1 1 1 1 1 0 0 0 0 0 0 -3 1 1 1 1 1 0 0 0 0 0 0 -2 1 1 1 1 1 0 0 0 0 0 0 -1 1 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 2 1 1 1 1 0 0 0 0 0 0 0 3 1 1 1 1 0 0 0 0 0 0 0 4 1 1 1 0 0 0 0 0 0 0 0 5 1 1 1 0 0 0 0 0 0 0 0 6 1 1 1 0 0 0 0 0 0 0 0 7 1 1 1 0 0 0 0 0 0 0 0 8 1 1 0 0 0 0 0 0 0 0 0 9 1 1 0 0 0 0 0 0 0 0 0 10 1 1 0 0 0 0 0 0 0 0 0 11 1 1 0 0 0 0 0 0 0 0 0 12 1 0 0 0 0 0 0 0 0 0 0 13 1 0 0 0 0 0 0 0 0 0 0 14 1 0 0 0 0 0 0 0 0 0 0 15 1 0 0 0 0 0 0 0 0 0 0 16 0 0 0 0 0 0 0 0 0 0 0 17 0 0 0 0 0 0 0 0 0 0 0 18 0 0 0 0 0 0 0 0 0 0 0 19 0 0 0 0 0 0 0 0 0 0 0
PATCH 1/1 task interactivity calculation (was Strange interactivity behaviour)
The appended patch fixes the problem mentioned in http://lkml.org/lkml/2006/2/27/104
regarding wrong truncations in the calculation of task interactivity when the nice value is negative. The problem causes the interactivity to scale nonlinearly and differ from examples in the code.
/Martin Andersson
kernel/sched.c +1 -1
@@ -142,7 +142,7 @@ (v1) * (v2_max) / (v1_max)#define DELTA (p) \ - (SCALE(TASK_NICE(p), 40, MAX_BONUS) + INTERACTIVE_DELTA) + (SCALE(TASK_NICE(p)+20,40, MAX_BONUS)-20*MAX_BONUS/40+INTERACTIVE_DELTA)#define TASK_INTERACTIVE (p) \ ((p)->prio <= (p)->static_prio - DELTA(p))
Re: [Patch] task interactivity calculation (was Strange interactivity behaviour)
Quoted 6 lines · Martin Andersson
The appended patch fixes the problem mentioned in
http://lkml.org/lkml/2006/2/27/104
regarding wrong truncations in the calculation of task interactivity when the nice value is negative. The problem causes the interactivity to scale nonlinearly and differ from examples in the code.
Hi (again) Martin,
Patches are required to have a credit/blame line these days ala...
...and should be sent with a cc to the subsystem maintainer In this case, Ingo Molnar. Things tend to go into mainline through Andrew Morton after being acked, so I've taken the liberty of adding him as well.
Wrt the fix itself, rather than scrunch to fit 80 columns, I'd just...
#define DELTA(p) \ (SCALE(TASK_NICE(p) + 20, 40, MAX_BONUS) - 20 * MAX_BONUS / 40 + \ INTERACTIVE_DELTA)
...wrap at the nearest readable spot.
(hmm. just re-packaging the thing would have wasted fewer electrons;)
-Mike
Quoted 20 lines
/Martin Andersson
diff -uprN
linux-2.6.15.4.orig/kernel/sched.clinux-2.6.15.4/kernel/sched.ckernel/sched.c +1
-2@@ -142,7 +142,7 @@ (v1) * (v2_max) / (v1_max)#define DELTA (p) \ - (SCALE(TASK_NICE(p), 40, MAX_BONUS) + INTERACTIVE_DELTA) + (SCALE(TASK_NICE(p)+20,40, MAX_BONUS)-20*MAX_BONUS/40+INTERACTIVE_DELTA)#define TASK_INTERACTIVE (p) \ ((p)->prio <= (p)->static_prio - DELTA(p)) -To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Re: [Patch] task interactivity calculation (was Strange interactivity behaviour)
Quoted 3 lines · Martin Andersson
Quoted 2 lines
The appended patch fixes the problem mentioned in http://lkml.org/lkml/2006/2/27/104
regarding wrong truncations in the calculation of task interactivity when the nice value is negative. The problem causes the interactivity to scale nonlinearly and differ from examples in the code.
Hi Mike,
Point taken. Is it correct now?
/Martin
kernel/sched.c +2 -1
@@ -142,7 +142,8 @@ (v1) * (v2_max) / (v1_max)#define DELTA (p) \ - (SCALE(TASK_NICE(p), 40, MAX_BONUS) + INTERACTIVE_DELTA) + (SCALE(TASK_NICE(p) + 20, 40, MAX_BONUS) - 20 * MAX_BONUS / 40 + \ + INTERACTIVE_DELTA)#define TASK_INTERACTIVE (p) \ ((p)->prio <= (p)->static_prio - DELTA(p))
Re: [Patch] task interactivity calculation (was Strange interactivity behaviour)
Quoted 10 lines · Martin Andersson
Quoted 6 lines · Martin Andersson
Quoted 5 lines
The appended patch fixes the problem mentioned in
http://lkml.org/lkml/2006/2/27/104
regarding wrong truncations in the calculation of task interactivity when the nice value is negative. The problem causes the interactivity to scale nonlinearly and differ from examples in the code.Hi Mike,
Point taken. Is it correct now?
Looks perfect to me.
-Mike
Quoted 19 lines
/Martin
Signed-off-by Martin Andersson <[email protected]>diff -uprN
linux-2.6.15.4.orig/kernel/sched.clinux-2.6.15.4/kernel/sched.ckernel/sched.c +2
-1@@ -142,7 +142,8 @@ (v1) * (v2_max) / (v1_max)#define DELTA (p) \ - (SCALE(TASK_NICE(p), 40, MAX_BONUS) + INTERACTIVE_DELTA) + (SCALE(TASK_NICE(p) + 20, 40, MAX_BONUS) - 20 * MAX_BONUS / 40 + \ + INTERACTIVE_DELTA)#define TASK_INTERACTIVE (p) \ ((p)->prio <= (p)->static_prio - DELTA(p))