public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jack Steiner <steiner@sgi.com>
To: Ingo Molnar <mingo@elte.hu>
Cc: akpm@osdl.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] - Reduce overhead of calc_load
Date: Fri, 17 Mar 2006 09:26:11 -0600	[thread overview]
Message-ID: <20060317152611.GA4449@sgi.com> (raw)
In-Reply-To: <20060317145912.GA13207@elte.hu>

Currently, count_active_tasks() calls both nr_running() & nr_interruptible().
Each of these functions does a "for_each_cpu" & reads values from the
runqueue of each cpu. Although this is not a lot of instructions, each
runqueue may be located on different node. Depending on the architecture,
a unique TLB entry may be required to access each runqueue. 

Since there may be more runqueues than cpu TLB entries, a scan of all runqueues 
can trash the TLB. Each memory reference incurs a TLB miss & refill.

In addition, the runqueue cacheline that contains nr_running & 
nr_uninterruptible may be evicted from the cache between the two passes.
This causes unnecessary cache misses.

Combining nr_running() & nr_interruptible() into a single function
substantially reduces the TLB & cache misses on large systems. This should 
have no measureable effect on smaller systems.

On a 128p IA64 system running a memory stress workload, the new function reduced
the overhead of calc_load() from 605 usec/call to 324 usec/call. 

(Same as previous patch except reorder extern as requested by Ingo)


	Signed-off-by: Jack Steiner <steiner@sgi.com>
	Acked-by: Ingo Molnar <mingo@elte.hu>

 include/linux/sched.h |    1 +
 kernel/sched.c        |   16 ++++++++++++++++
 kernel/timer.c        |    8 +++++++-
 3 files changed, 24 insertions(+), 1 deletion(-)



Index: linux/include/linux/sched.h
===================================================================
--- linux.orig/include/linux/sched.h	2006-03-16 16:17:55.982340489 -0600
+++ linux/include/linux/sched.h	2006-03-17 09:23:44.847612520 -0600
@@ -99,6 +99,7 @@ DECLARE_PER_CPU(unsigned long, process_c
 extern int nr_processes(void);
 extern unsigned long nr_running(void);
 extern unsigned long nr_uninterruptible(void);
+extern unsigned long nr_active(void);
 extern unsigned long nr_iowait(void);
 
 #include <linux/time.h>
Index: linux/kernel/sched.c
===================================================================
--- linux.orig/kernel/sched.c	2006-03-16 16:17:56.376832371 -0600
+++ linux/kernel/sched.c	2006-03-16 16:26:01.141002841 -0600
@@ -1655,6 +1655,22 @@ unsigned long nr_iowait(void)
 	return sum;
 }
 
+unsigned long nr_active(void)
+{
+	unsigned long i, running = 0, uninterruptible = 0;
+
+	for_each_online_cpu(i) {
+		running += cpu_rq(i)->nr_running;
+		uninterruptible += cpu_rq(i)->nr_uninterruptible;
+	}
+
+	if (unlikely((long)uninterruptible < 0))
+		uninterruptible = 0;
+
+	return running + uninterruptible;
+}
+
+
 #ifdef CONFIG_SMP
 
 /*
Index: linux/kernel/timer.c
===================================================================
--- linux.orig/kernel/timer.c	2006-03-16 16:17:56.385620556 -0600
+++ linux/kernel/timer.c	2006-03-16 16:26:01.141979306 -0600
@@ -849,7 +849,7 @@ void update_process_times(int user_tick)
  */
 static unsigned long count_active_tasks(void)
 {
-	return (nr_running() + nr_uninterruptible()) * FIXED_1;
+	return nr_active() * FIXED_1;
 }
 
 /*

  reply	other threads:[~2006-03-17 15:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-03-17 14:57 [PATCH] - Reduce overhead of calc_load Jack Steiner
2006-03-17 14:59 ` Ingo Molnar
2006-03-17 15:26   ` Jack Steiner [this message]
2006-03-18  1:15     ` Andrew Morton
2006-03-18  2:09       ` Nick Piggin
2006-03-18  2:37         ` Andrew Morton
2006-03-18  2:46           ` Nick Piggin
2006-03-18  5:13             ` Andrew Morton
2006-03-18  5:38               ` Nick Piggin
2006-03-18  6:10                 ` Nick Piggin

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=20060317152611.GA4449@sgi.com \
    --to=steiner@sgi.com \
    --cc=akpm@osdl.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox