public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: john stultz <johnstul@us.ibm.com>, Torben Hohn <torbenh@gmx.de>,
	LKML <linux-kernel@vger.kernel.org>,
	hch@infradead.org, yong.zhang0@gmail.com
Subject: Re: [PATCH 01/18] move do_timer() from kernel/timer.c into kernel/time/timekeeping.c
Date: Tue, 25 Jan 2011 11:34:37 +0100	[thread overview]
Message-ID: <1295951677.28776.489.camel@laptop> (raw)
In-Reply-To: <1295946514.28776.476.camel@laptop>

On Tue, 2011-01-25 at 10:08 +0100, Peter Zijlstra wrote:
> On Mon, 2011-01-24 at 23:44 +0100, Thomas Gleixner wrote:
> > On Mon, 24 Jan 2011, Peter Zijlstra wrote:
> > 
> > > On Mon, 2011-01-24 at 23:10 +0100, Thomas Gleixner wrote:
> > > > The call to calc_global_load() is there for hysterical raisins and we
> > > > really should get rid of it sooner than later. I'm quite sure that it
> > > > could be run from a timer callback as well. Peter ?
> > > 
> > > calc_global_load() wants to be called on just one cpu, do we have a
> > > better place for that?
> > 
> > Well, we can call it from a timer from a single CPU.
> 
> Right that would work I guess.

Something like the (completely untested) below would do I guess:

---
Subject: sched: Move the calc_global_load() call into the scheduler
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
Date: Tue Jan 25 11:30:35 CET 2011

Remove the calc_global_load() call from the timekeeping code and make
it local to the scheduler.

Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
LKML-Reference: <new-submission>
---
 include/linux/sched.h |    2 --
 kernel/sched.c        |   22 ++++++++++++++++------
 kernel/timer.c        |    1 -
 3 files changed, 16 insertions(+), 9 deletions(-)

Index: linux-2.6/include/linux/sched.h
===================================================================
--- linux-2.6.orig/include/linux/sched.h
+++ linux-2.6/include/linux/sched.h
@@ -142,8 +142,6 @@ extern unsigned long nr_iowait_cpu(int c
 extern unsigned long this_cpu_load(void);
 
 
-extern void calc_global_load(unsigned long ticks);
-
 extern unsigned long get_parent_ip(unsigned long addr);
 
 struct seq_file;
Index: linux-2.6/kernel/sched.c
===================================================================
--- linux-2.6.orig/kernel/sched.c
+++ linux-2.6/kernel/sched.c
@@ -3192,7 +3192,7 @@ calc_load_n(unsigned long load, unsigned
  * Once we've updated the global active value, we need to apply the exponential
  * weights adjusted to the number of cycles missed.
  */
-static void calc_global_nohz(unsigned long ticks)
+static void calc_global_nohz(void)
 {
 	long delta, active, n;
 
@@ -3209,11 +3209,13 @@ static void calc_global_nohz(unsigned lo
 	if (delta)
 		atomic_long_add(delta, &calc_load_tasks);
 
+
 	/*
 	 * If we were idle for multiple load cycles, apply them.
 	 */
-	if (ticks >= LOAD_FREQ) {
-		n = ticks / LOAD_FREQ;
+	delta = jiffies - calc_load_update - 10;
+	if (delta >= LOAD_FREQ) {
+		n = delta / LOAD_FREQ;
 
 		active = atomic_long_read(&calc_load_tasks);
 		active = active > 0 ? active * FIXED_1 : 0;
@@ -3246,7 +3248,7 @@ static inline long calc_load_fold_idle(v
 	return 0;
 }
 
-static void calc_global_nohz(unsigned long ticks)
+static void calc_global_nohz(void)
 {
 }
 #endif
@@ -3266,15 +3268,20 @@ void get_avenrun(unsigned long *loads, u
 	loads[2] = (avenrun[2] + offset) << shift;
 }
 
+static void calc_global_load(unsigned long __data);
+
+static struct timer_list global_load_timer =
+	TIMER_DEFERRED_INITIALIZER(calc_global_load, 0, 0);
+
 /*
  * calc_load - update the avenrun load estimates 10 ticks after the
  * CPUs have updated calc_load_tasks.
  */
-void calc_global_load(unsigned long ticks)
+static void calc_global_load(unsigned long __data)
 {
 	long active;
 
-	calc_global_nohz(ticks);
+	calc_global_nohz();
 
 	if (time_before(jiffies, calc_load_update + 10))
 		return;
@@ -3287,6 +3294,7 @@ void calc_global_load(unsigned long tick
 	avenrun[2] = calc_load(avenrun[2], EXP_15, active);
 
 	calc_load_update += LOAD_FREQ;
+	mod_timer(&global_load_timer, calc_load_update + 10);
 }
 
 /*
@@ -8172,6 +8180,8 @@ void __init sched_init(void)
 	init_idle(current, smp_processor_id());
 
 	calc_load_update = jiffies + LOAD_FREQ;
+	global_load_timer.slack = 0;
+	mod_timer(&global_load_timer, calc_load_update + 10);
 
 	/*
 	 * During early bootup we pretend to be a normal task:
Index: linux-2.6/kernel/timer.c
===================================================================
--- linux-2.6.orig/kernel/timer.c
+++ linux-2.6/kernel/timer.c
@@ -1303,7 +1303,6 @@ void do_timer(unsigned long ticks)
 {
 	jiffies_64 += ticks;
 	update_wall_time();
-	calc_global_load(ticks);
 }
 
 #ifdef __ARCH_WANT_SYS_ALARM


  reply	other threads:[~2011-01-25 10:33 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-21 23:06 make arch code use xtime_update() instead of do_timer() Torben Hohn
2011-01-21 23:06 ` [PATCH 01/18] move do_timer() from kernel/timer.c into kernel/time/timekeeping.c Torben Hohn
2011-01-22  9:45   ` Thomas Gleixner
2011-01-24 20:32   ` john stultz
2011-01-24 22:10     ` Thomas Gleixner
2011-01-24 22:21       ` Peter Zijlstra
2011-01-24 22:44         ` Thomas Gleixner
2011-01-25  9:08           ` Peter Zijlstra
2011-01-25 10:34             ` Peter Zijlstra [this message]
2011-01-25 16:51               ` Peter Zijlstra
2011-01-26  5:56                 ` Yong Zhang
2011-01-26  6:49                   ` Yong Zhang
2011-01-26 10:03                   ` Peter Zijlstra
2011-01-26 11:11                     ` Yong Zhang
2011-01-21 23:06 ` [PATCH 02/18] provide xtime_update() which does not require holding xtime_lock like do_timer() Torben Hohn
2011-01-22 10:36   ` Thomas Gleixner
2011-01-21 23:06 ` [PATCH 03/18] alpha: change do_timer() to xtime_update() Torben Hohn
2011-01-21 23:06 ` [PATCH 04/18] arm: switch from " Torben Hohn
2011-01-21 23:06 ` [PATCH 05/18] arm/mach-clps711x: switch " Torben Hohn
2011-01-21 23:06 ` [PATCH 06/18] blackfin: switch from " Torben Hohn
2011-01-21 23:06 ` [PATCH 07/18] cris/arch-v10: switch " Torben Hohn
2011-01-21 23:06 ` [PATCH 08/18] cris/arch-v32: " Torben Hohn
2011-01-21 23:06 ` [PATCH 09/18] frv: " Torben Hohn
2011-01-22 10:01   ` Thomas Gleixner
2011-01-24 12:51     ` torbenh
2011-01-24 13:09       ` Thomas Gleixner
2011-01-21 23:06 ` [PATCH 10/18] h8300: " Torben Hohn
2011-01-21 23:06 ` [PATCH 11/18] ia64: " Torben Hohn
2011-01-21 23:06 ` [PATCH 12/18] m32r: switch from " Torben Hohn
2011-01-21 23:06 ` [PATCH 13/18] m68k: switch " Torben Hohn
2011-01-21 23:07 ` [PATCH 14/18] mn10300: switch do_timer() to xtimer_update() Torben Hohn
2011-01-21 23:07 ` [PATCH 15/18] parisc: switch do_timer() to xtime_update() Torben Hohn
2011-01-21 23:07 ` [PATCH 16/18] sparc: " Torben Hohn
2011-01-22  0:51   ` David Miller
2011-01-21 23:07 ` [PATCH 17/18] xtensa: " Torben Hohn
2011-01-21 23:07 ` [PATCH 18/18] make do_timer() and xtime_lock private to the timer code Torben Hohn
2011-01-22 10:14 ` make arch code use xtime_update() instead of do_timer() Thomas Gleixner

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=1295951677.28776.489.camel@laptop \
    --to=peterz@infradead.org \
    --cc=hch@infradead.org \
    --cc=johnstul@us.ibm.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=torbenh@gmx.de \
    --cc=yong.zhang0@gmail.com \
    /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