From: Eric Dumazet <dada1@cosmosbay.com>
To: Andrew Morton <akpm@osdl.org>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: [PATCH] Optimize calc_load()
Date: Mon, 11 Dec 2006 14:50:07 +0100 [thread overview]
Message-ID: <200612111450.07722.dada1@cosmosbay.com> (raw)
In-Reply-To: <200612111152.56945.dada1@cosmosbay.com>
[-- Attachment #1: Type: text/plain, Size: 614 bytes --]
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 <dada1@cosmosbay.com>
[-- Attachment #2: calc_load.patch --]
[-- Type: text/plain, Size: 820 bytes --]
--- linux-2.6.19/kernel/timer.c 2006-12-11 12:27:28.000000000 +0100
+++ linux-2.6.19-ed/kernel/timer.c 2006-12-11 12:29:11.000000000 +0100
@@ -1008,11 +1008,15 @@ static inline void calc_load(unsigned lo
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);
}
}
next prev parent reply other threads:[~2006-12-11 13:49 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-12-11 8:27 [patch] pipe: Don't oops when pipe filesystem isn't mounted Chuck Ebbert
2006-12-11 8:55 ` Andrew Morton
2006-12-11 9:13 ` Andrew Morton
2006-12-11 9:21 ` Al Viro
2006-12-11 9:25 ` Andrew Morton
2006-12-11 9:33 ` Al Viro
2006-12-11 9:47 ` Andrew Morton
2006-12-11 10:03 ` Al Viro
2006-12-11 10:17 ` Andrew Morton
2006-12-11 10:22 ` Al Viro
2006-12-11 10:34 ` Andrew Morton
2006-12-11 10:47 ` Al Viro
2006-12-11 10:57 ` Jeff Garzik
2006-12-11 10:27 ` Andrew Morton
2006-12-11 10:45 ` Al Viro
2006-12-11 16:01 ` Linus Torvalds
2006-12-11 16:12 ` Al Viro
2006-12-11 16:40 ` Linus Torvalds
2006-12-12 0:33 ` Benjamin Herrenschmidt
2006-12-12 2:08 ` Andrew Morton
2006-12-12 2:17 ` Dominik Brodowski
2006-12-12 2:23 ` Linus Torvalds
2006-12-11 10:52 ` [PATCH] get rid of ARCH_HAVE_XTIME_LOCK Eric Dumazet
2006-12-11 13:50 ` Eric Dumazet [this message]
2006-12-11 19:04 ` [PATCH] constify pipe_buf_operations Eric Dumazet
2006-12-11 9:13 ` [patch] pipe: Don't oops when pipe filesystem isn't mounted Al Viro
2006-12-11 9:40 ` Michael Tokarev
2006-12-11 15:44 ` Linus Torvalds
2006-12-12 12:20 ` Michael Tokarev
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200612111450.07722.dada1@cosmosbay.com \
--to=dada1@cosmosbay.com \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.