Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=ff91691bccdb741efb2df0489058a4961fa79598
Commit:     ff91691bccdb741efb2df0489058a4961fa79598
Parent:     0a9ac38246b11892ad20a1eb9deb67adf8c0db2f
Author:     Nick Piggin <[EMAIL PROTECTED]>
AuthorDate: Mon Feb 12 00:53:51 2007 -0800
Committer:  Linus Torvalds <[EMAIL PROTECTED]>
CommitDate: Mon Feb 12 09:48:37 2007 -0800

    [PATCH] sched: avoid div in rebalance_tick
    
    Avoid expensive integer divide 3 times per CPU per tick.
    
    A userspace test of this loop went from 26ns, down to 19ns on a G5; and
    from 123ns down to 28ns on a P3.
    
    (Also avoid a variable bit shift, as suggested by Alan. The effect
    of this wasn't noticable on the CPUs I tested with).
    
    Signed-off-by: Nick Piggin <[EMAIL PROTECTED]>
    Cc: Ingo Molnar <[EMAIL PROTECTED]>
    Cc: Alan Cox <[EMAIL PROTECTED]>
    Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
    Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>
---
 kernel/sched.c |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/kernel/sched.c b/kernel/sched.c
index 1fd67e1..08f8617 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -2897,14 +2897,16 @@ static void active_load_balance(struct rq *busiest_rq, 
int busiest_cpu)
 static void update_load(struct rq *this_rq)
 {
        unsigned long this_load;
-       int i, scale;
+       unsigned int i, scale;
 
        this_load = this_rq->raw_weighted_load;
 
        /* Update our load: */
-       for (i = 0, scale = 1; i < 3; i++, scale <<= 1) {
+       for (i = 0, scale = 1; i < 3; i++, scale += scale) {
                unsigned long old_load, new_load;
 
+               /* scale is effectively 1 << i now, and >> i divides by scale */
+
                old_load = this_rq->cpu_load[i];
                new_load = this_load;
                /*
@@ -2914,7 +2916,7 @@ static void update_load(struct rq *this_rq)
                 */
                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;
        }
 }
 
-
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to