Gitweb:     
http://git.kernel.org/git/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=cd7175edf963a92b2c3cd491d3e34afd357e7284
Commit:     cd7175edf963a92b2c3cd491d3e34afd357e7284
Parent:     f988443a84528bd30c2f474efa5e2c511959f19b
Author:     Eric Dumazet <[EMAIL PROTECTED]>
AuthorDate: Wed Dec 13 00:35:45 2006 -0800
Committer:  Linus Torvalds <[EMAIL PROTECTED]>
CommitDate: Wed Dec 13 09:05:55 2006 -0800

    [PATCH] Optimize calc_load()
    
    calc_load() is called by timer interrupt to update avenrun[].  It currently
    calls nr_active() at each timer tick (HZ per second), while the update of
    avenrun[] is done only once every 5 seconds.  (LOAD_FREQ=5 Hz)
    
    nr_active() is quite expensive on SMP machines, since it has to sum up
    nr_running and nr_uninterruptible of all online CPUS, bringing foreign
    dirty cache lines.
    
    This patch is an optimization of calc_load() so that nr_active() is called
    only if we need it.
    
    The use of unlikely() is welcome since the condition is true only once every
    5*HZ time.
    
    Signed-off-by: Eric Dumazet <[EMAIL PROTECTED]>
    Cc: Ingo Molnar <[EMAIL PROTECTED]>
    Acked-by: "Siddha, Suresh B" <[EMAIL PROTECTED]>
    Cc: Nick Piggin <[EMAIL PROTECTED]>
    Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
    Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>
---
 kernel/timer.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/kernel/timer.c b/kernel/timer.c
index 0256ab4..feddf81 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -1146,11 +1146,15 @@ static inline void calc_load(unsigned long ticks)
        unsigned long active_tasks; /* fixed-point */
        static int count = LOAD_FREQ;
 
-       active_tasks = count_active_tasks();
-       for (count -= ticks; count < 0; count += LOAD_FREQ) {
-               CALC_LOAD(avenrun[0], EXP_1, active_tasks);
-               CALC_LOAD(avenrun[1], EXP_5, active_tasks);
-               CALC_LOAD(avenrun[2], EXP_15, active_tasks);
+       count -= ticks;
+       if (unlikely(count < 0)) {
+               active_tasks = count_active_tasks();
+               do {
+                       CALC_LOAD(avenrun[0], EXP_1, active_tasks);
+                       CALC_LOAD(avenrun[1], EXP_5, active_tasks);
+                       CALC_LOAD(avenrun[2], EXP_15, active_tasks);
+                       count += LOAD_FREQ;
+               } while (count < 0);
        }
 }
 
-
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