All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/2] sched: 64bit: fix overflow(was: fix divide by zero)
@ 2008-06-12  8:43 Lai Jiangshan
  2008-06-12  8:50 ` Peter Zijlstra
  0 siblings, 1 reply; 2+ messages in thread
From: Lai Jiangshan @ 2008-06-12  8:43 UTC (permalink / raw)
  To: mingo; +Cc: peterz, Linux Kernel Mailing List

(overflow means weight >= 2^32 here, because inv_weigh = 2^32/weight)

A weight of a cfs_rq is the sum of weights of which entities
are queued on this cfs_rq, so it will be overflow when entities
are too many. 

Although, overflow is very hardly occurred, but it break fairness when
it is occurred. And 64bits system have more memory than 32bits system
and 64bits system can create more process usually, so overflow many be
occurred more.

This patch guarantee fairness when overflow in 64bits system.
Thanks to the optimization of compiler, it change nothing in 32bits system.


Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
diff --git a/kernel/sched.c b/kernel/sched.c
index bfb8ad8..e277533 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -1337,8 +1337,13 @@ calc_delta_mine(unsigned long delta_exec, unsigned long weight,
 {
 	u64 tmp;
 
-	if (!lw->inv_weight)
-		lw->inv_weight = 1 + (WMULT_CONST-lw->weight/2)/(lw->weight+1);
+	if (!lw->inv_weight) {
+		if (BITS_PER_LONG > 32 && unlikely(lw->weight >= WMULT_CONST))
+			lw->inv_weight = 1;
+		else
+			lw->inv_weight = 1 + (WMULT_CONST-lw->weight/2)
+				/ (lw->weight+1);
+	}
 
 	tmp = (u64)delta_exec * weight;
 	/*





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

* Re: [PATCH 2/2] sched: 64bit: fix overflow(was: fix divide by zero)
  2008-06-12  8:43 [PATCH 2/2] sched: 64bit: fix overflow(was: fix divide by zero) Lai Jiangshan
@ 2008-06-12  8:50 ` Peter Zijlstra
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Zijlstra @ 2008-06-12  8:50 UTC (permalink / raw)
  To: Lai Jiangshan; +Cc: mingo, Linux Kernel Mailing List

On Thu, 2008-06-12 at 16:43 +0800, Lai Jiangshan wrote:
> (overflow means weight >= 2^32 here, because inv_weigh = 2^32/weight)
> 
> A weight of a cfs_rq is the sum of weights of which entities
> are queued on this cfs_rq, so it will be overflow when entities
> are too many. 
> 
> Although, overflow is very hardly occurred, but it break fairness when
> it is occurred. And 64bits system have more memory than 32bits system
> and 64bits system can create more process usually, so overflow many be
> occurred more.
> 
> This patch guarantee fairness when overflow in 64bits system.
> Thanks to the optimization of compiler, it change nothing in 32bits system.

Yeah,. bit sad for that one branch extra on 64-bit, but I get the
unlikely is as good as we can get it.

Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>

> Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
> ---
> diff --git a/kernel/sched.c b/kernel/sched.c
> index bfb8ad8..e277533 100644
> --- a/kernel/sched.c
> +++ b/kernel/sched.c
> @@ -1337,8 +1337,13 @@ calc_delta_mine(unsigned long delta_exec, unsigned long weight,
>  {
>  	u64 tmp;
>  
> -	if (!lw->inv_weight)
> -		lw->inv_weight = 1 + (WMULT_CONST-lw->weight/2)/(lw->weight+1);
> +	if (!lw->inv_weight) {
> +		if (BITS_PER_LONG > 32 && unlikely(lw->weight >= WMULT_CONST))
> +			lw->inv_weight = 1;
> +		else
> +			lw->inv_weight = 1 + (WMULT_CONST-lw->weight/2)
> +				/ (lw->weight+1);
> +	}
>  
>  	tmp = (u64)delta_exec * weight;
>  	/*
> 
> 
> 
> 


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

end of thread, other threads:[~2008-06-12  8:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-06-12  8:43 [PATCH 2/2] sched: 64bit: fix overflow(was: fix divide by zero) Lai Jiangshan
2008-06-12  8:50 ` Peter Zijlstra

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.