public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [patch] sched: avoid div in rebalance_tick
@ 2007-01-12  6:02 Nick Piggin
  2007-01-12  9:59 ` Alan
  0 siblings, 1 reply; 4+ messages in thread
From: Nick Piggin @ 2007-01-12  6:02 UTC (permalink / raw)
  To: Andrew Morton, Ingo Molnar, Linux Kernel Mailing List

Just noticed this while looking at a bug.

--

Avoid an expensive integer divide 3 times per CPU per tick.

Signed-off-by: Nick Piggin <npiggin@suse.de>

Index: linux-2.6/kernel/sched.c
===================================================================
--- linux-2.6.orig/kernel/sched.c
+++ linux-2.6/kernel/sched.c
@@ -2887,13 +2887,14 @@ static void active_load_balance(struct r
 static void update_load(struct rq *this_rq)
 {
 	unsigned long this_load;
-	int i, scale;
+	int i;
 
 	this_load = this_rq->raw_weighted_load;
 
 	/* Update our load: */
-	for (i = 0, scale = 1; i < 3; i++, scale <<= 1) {
+	for (i = 0; i < 3; i++) {
 		unsigned long old_load, new_load;
+		int scale;
 
 		old_load = this_rq->cpu_load[i];
 		new_load = this_load;
@@ -2902,9 +2903,11 @@ static void update_load(struct rq *this_
 		 * prevents us from getting stuck on 9 if the load is 10, for
 		 * example.
 		 */
+		scale = 1 << i;
 		if (new_load > old_load)
 			new_load += scale-1;
-		this_rq->cpu_load[i] = (old_load*(scale-1) + new_load) / scale;
+		this_rq->cpu_load[i] = (old_load*(scale-1) + new_load)
+					>> i; /* (divide by 'scale') */
 	}
 }
 

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

end of thread, other threads:[~2007-01-13  6:46 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-01-12  6:02 [patch] sched: avoid div in rebalance_tick Nick Piggin
2007-01-12  9:59 ` Alan
2007-01-12 10:27   ` Nick Piggin
2007-01-13  6:46   ` Nick Piggin

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