public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Strange interactivity behaviour
@ 2006-02-27 11:40 Martin Andersson
  2006-02-28 10:33 ` [Patch] task interactivity calculation (was Strange interactivity behaviour) Martin Andersson
  0 siblings, 1 reply; 5+ messages in thread
From: Martin Andersson @ 2006-02-27 11:40 UTC (permalink / raw)
  To: linux-kernel

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     0     0     0     0     0     0
  -4     1     1     1     1     1     0     0     0     0     0     0
  -3     1     1     1     1     0     0     0     0     0     0     0
  -2     1     1     1     1     0     0     0     0     0     0     0
  -1     1     1     1     1     0     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


Output of TASK_INTERACTIVE when using "floor"
nice    dynamic priorities
-20     1     1     1     1     1     1     1     1     1     0     0
-19     1     1     1     1     1     1     1     1     1     0     0
-18     1     1     1     1     1     1     1     1     1     0     0
-17     1     1     1     1     1     1     1     1     1     0     0
-16     1     1     1     1     1     1     1     1     0     0     0
-15     1     1     1     1     1     1     1     1     0     0     0
-14     1     1     1     1     1     1     1     1     0     0     0
-13     1     1     1     1     1     1     1     1     0     0     0
-12     1     1     1     1     1     1     1     0     0     0     0
-11     1     1     1     1     1     1     1     0     0     0     0
-10     1     1     1     1     1     1     1     0     0     0     0
  -9     1     1     1     1     1     1     1     0     0     0     0
  -8     1     1     1     1     1     1     0     0     0     0     0
  -7     1     1     1     1     1     1     0     0     0     0     0
  -6     1     1     1     1     1     1     0     0     0     0     0
  -5     1     1     1     1     1     1     0     0     0     0     0
  -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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Patch] task interactivity calculation (was Strange interactivity behaviour)
  2006-02-27 11:40 Strange interactivity behaviour Martin Andersson
@ 2006-02-28 10:33 ` Martin Andersson
  2006-02-28 14:07   ` Mike Galbraith
  0 siblings, 1 reply; 5+ messages in thread
From: Martin Andersson @ 2006-02-28 10:33 UTC (permalink / raw)
  To: linux-kernel; +Cc: torvalds

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

diff -uprN linux-2.6.15.4.orig/kernel/sched.c linux-2.6.15.4/kernel/sched.c
--- linux-2.6.15.4.orig/kernel/sched.c	2006-02-10 08:22:48.000000000 +0100
+++ linux-2.6.15.4/kernel/sched.c	2006-02-28 11:10:30.000000000 +0100
@@ -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))

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch] task interactivity calculation (was Strange interactivity behaviour)
  2006-02-28 10:33 ` [Patch] task interactivity calculation (was Strange interactivity behaviour) Martin Andersson
@ 2006-02-28 14:07   ` Mike Galbraith
  2006-02-28 15:05     ` Martin Andersson
  0 siblings, 1 reply; 5+ messages in thread
From: Mike Galbraith @ 2006-02-28 14:07 UTC (permalink / raw)
  To: Martin Andersson; +Cc: linux-kernel, torvalds, Ingo Molnar, Andrew Morton

On Tue, 2006-02-28 at 11:33 +0100, Martin Andersson wrote:
> 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...

Signed-off-by: Martin Andersson <martin.andersson@control.lth.se>

...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

> /Martin Andersson
> 
> diff -uprN linux-2.6.15.4.orig/kernel/sched.c linux-2.6.15.4/kernel/sched.c
> --- linux-2.6.15.4.orig/kernel/sched.c	2006-02-10 08:22:48.000000000 +0100
> +++ linux-2.6.15.4/kernel/sched.c	2006-02-28 11:10:30.000000000 +0100
> @@ -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 majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch] task interactivity calculation (was Strange interactivity behaviour)
  2006-02-28 14:07   ` Mike Galbraith
@ 2006-02-28 15:05     ` Martin Andersson
  2006-02-28 16:28       ` Mike Galbraith
  0 siblings, 1 reply; 5+ messages in thread
From: Martin Andersson @ 2006-02-28 15:05 UTC (permalink / raw)
  To: Mike Galbraith; +Cc: linux-kernel, torvalds, Ingo Molnar, Andrew Morton

 >On Tue, 2006-02-28 at 11:33 +0100, Martin Andersson wrote:
>>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

Signed-off-by: Martin Andersson <martin.andersson@control.lth.se>

diff -uprN linux-2.6.15.4.orig/kernel/sched.c linux-2.6.15.4/kernel/sched.c
--- linux-2.6.15.4.orig/kernel/sched.c	2006-02-10 08:22:48.000000000 +0100
+++ linux-2.6.15.4/kernel/sched.c	2006-02-28 15:49:12.000000000 +0100
@@ -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))

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Patch] task interactivity calculation (was Strange interactivity behaviour)
  2006-02-28 15:05     ` Martin Andersson
@ 2006-02-28 16:28       ` Mike Galbraith
  0 siblings, 0 replies; 5+ messages in thread
From: Mike Galbraith @ 2006-02-28 16:28 UTC (permalink / raw)
  To: Martin Andersson; +Cc: linux-kernel, torvalds, Ingo Molnar, Andrew Morton

On Tue, 2006-02-28 at 16:05 +0100, Martin Andersson wrote:
>  >On Tue, 2006-02-28 at 11:33 +0100, Martin Andersson wrote:
> >>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

> 
> /Martin
> 
> Signed-off-by: Martin Andersson <martin.andersson@control.lth.se>
> 
> diff -uprN linux-2.6.15.4.orig/kernel/sched.c linux-2.6.15.4/kernel/sched.c
> --- linux-2.6.15.4.orig/kernel/sched.c	2006-02-10 08:22:48.000000000 +0100
> +++ linux-2.6.15.4/kernel/sched.c	2006-02-28 15:49:12.000000000 +0100
> @@ -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))
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-02-28 16:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-27 11:40 Strange interactivity behaviour Martin Andersson
2006-02-28 10:33 ` [Patch] task interactivity calculation (was Strange interactivity behaviour) Martin Andersson
2006-02-28 14:07   ` Mike Galbraith
2006-02-28 15:05     ` Martin Andersson
2006-02-28 16:28       ` Mike Galbraith

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox