From: Thomas Gleixner <tglx@linutronix.de>
To: Valdis.Kletnieks@vt.edu
Cc: Andrew Morton <akpm@osdl.org>,
LKML <linux-kernel@vger.kernel.org>, Ingo Molnar <mingo@elte.hu>,
Jim Gettys <jg@laptop.org>, John Stultz <johnstul@us.ibm.com>,
David Woodhouse <dwmw2@infradead.org>,
Arjan van de Ven <arjan@infradead.org>,
Dave Jones <davej@redhat.com>
Subject: [patch] dynticks core: Fix idle time accounting
Date: Mon, 02 Oct 2006 20:43:26 +0200 [thread overview]
Message-ID: <1159814606.1386.52.camel@localhost.localdomain> (raw)
In-Reply-To: <200610021825.k92IPSnd008215@turing-police.cc.vt.edu>
On Mon, 2006-10-02 at 14:25 -0400, Valdis.Kletnieks@vt.edu wrote:
> > > I'm also seeing gkrellm reporting about 25% CPU use when "near-idle" (X is up
> > > but not much is going on) when that's usually down around 5-6%. I need to
> > > collect some oprofile numbers and investigate that as well.
> >
> > I look into the accounting fixups again.
> I still need to get oprofile runs of this and see what's going on.
The patch below fixes the accounting weirdness.
tglx
----------------->
Subject: dynticks core: Fix idle time accounting
From: Thomas Gleixner <tglx@linutronix,de>
The extended sleeps during idle must be accounted to the idle thread.
The original accounting fixup was too naive. The time must be accounted
when the idle thread is interrupted and the jiffies update code has
forwarded jiffies. Otherwise the accounting is done on random targets.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
--
kernel/hrtimer.c | 34 +++++++++++++++++++---------------
1 file changed, 19 insertions(+), 15 deletions(-)
Index: linux-2.6.18-mm2/kernel/hrtimer.c
===================================================================
--- linux-2.6.18-mm2.orig/kernel/hrtimer.c 2006-10-02 19:22:14.000000000 +0200
+++ linux-2.6.18-mm2/kernel/hrtimer.c 2006-10-02 19:22:14.000000000 +0200
@@ -44,6 +44,7 @@
#include <linux/profile.h>
#include <linux/seq_file.h>
#include <linux/err.h>
+#include <linux/kernel_stat.h>
#include <asm/uaccess.h>
@@ -447,10 +448,11 @@ static const ktime_t nsec_per_hz = { .tv
* want to wake up a complete idle cpu just to update jiffies, so we need
* something more intellegent than a mere "do this only on CPUx".
*/
-static void update_jiffies64(ktime_t now)
+static unsigned long update_jiffies64(ktime_t now)
{
unsigned long seq;
ktime_t delta;
+ unsigned long ticks = 0;
/* Preevaluate to avoid lock contention */
do {
@@ -459,14 +461,13 @@ static void update_jiffies64(ktime_t now
} while (read_seqretry(&xtime_lock, seq));
if (delta.tv64 < nsec_per_hz.tv64)
- return;
+ return 0;
/* Reevalute with xtime_lock held */
write_seqlock(&xtime_lock);
delta = ktime_sub(now, last_jiffies_update);
if (delta.tv64 >= nsec_per_hz.tv64) {
- unsigned long ticks = 1;
delta = ktime_sub(delta, nsec_per_hz);
last_jiffies_update = ktime_add(last_jiffies_update,
@@ -480,11 +481,13 @@ static void update_jiffies64(ktime_t now
last_jiffies_update = ktime_add_ns(last_jiffies_update,
incr * ticks);
- ticks++;
}
+ ticks++;
do_timer(ticks);
}
write_sequnlock(&xtime_lock);
+
+ return ticks;
}
#ifdef CONFIG_NO_HZ
@@ -500,7 +503,7 @@ static void update_jiffies64(ktime_t now
void hrtimer_update_jiffies(void)
{
struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
- unsigned long flags;
+ unsigned long flags, ticks;
ktime_t now;
if (!cpu_base->tick_stopped || !cpu_base->hres_active)
@@ -509,7 +512,17 @@ void hrtimer_update_jiffies(void)
now = ktime_get();
local_irq_save(flags);
- update_jiffies64(now);
+ ticks = update_jiffies64(now);
+ if (ticks) {
+ /*
+ * We stopped the tick in idle and this function got called to
+ * update jiffies. Update process times would randomly account
+ * the time we slept to whatever the context of the next sched
+ * tick is. Enforce that this is accounted to idle !
+ */
+ account_system_time(current, HARDIRQ_OFFSET,
+ jiffies_to_cputime(ticks));
+ }
local_irq_restore(flags);
}
@@ -604,15 +617,6 @@ void hrtimer_restart_sched_tick(void)
local_irq_disable();
update_jiffies64(now);
- /*
- * Update process times would randomly account the time we slept to
- * whatever the context of the next sched tick is. Enforce that this
- * is accounted to idle !
- */
- add_preempt_count(HARDIRQ_OFFSET);
- update_process_times(0);
- sub_preempt_count(HARDIRQ_OFFSET);
-
/* Account the idle time */
delta = ktime_sub(now, cpu_base->idle_entrytime);
cpu_base->idle_sleeptime = ktime_add(cpu_base->idle_sleeptime, delta);
next prev parent reply other threads:[~2006-10-02 18:41 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-01 22:59 [patch 00/21] high resolution timers / dynamic ticks - V2 Thomas Gleixner
2006-10-01 22:59 ` [patch 01/21] GTOD: exponential update_wall_time Thomas Gleixner
2006-10-01 23:00 ` [patch 02/21] GTOD: persistent clock support, core Thomas Gleixner
2006-10-01 23:00 ` [patch 03/21] GTOD: persistent clock support, i386 Thomas Gleixner
2006-10-01 23:00 ` [patch 04/21] time: uninline jiffies.h Thomas Gleixner
2006-10-01 23:00 ` [patch 05/21] time: fix msecs_to_jiffies() bug Thomas Gleixner
2006-10-01 23:00 ` [patch 06/21] time: fix timeout overflow Thomas Gleixner
2006-10-01 23:00 ` [patch 07/21] cleanup: uninline irq_enter() and move it into a function Thomas Gleixner
2006-10-01 23:00 ` [patch 08/21] dynticks: extend next_timer_interrupt() to use a reference jiffie Thomas Gleixner
2006-10-01 23:00 ` [patch 09/21] hrtimers: namespace and enum cleanup Thomas Gleixner
2006-10-01 23:00 ` [patch 10/21] hrtimers: clean up locking Thomas Gleixner
2006-10-01 23:00 ` [patch 11/21] hrtimers: state tracking Thomas Gleixner
2006-10-01 23:00 ` [patch 12/21] hrtimers: clean up callback tracking Thomas Gleixner
2006-10-01 23:01 ` [patch 13/21] hrtimers: Move and add documentation Thomas Gleixner
2006-10-01 23:01 ` [patch 14/21] clockevents: core Thomas Gleixner
2006-10-01 23:01 ` [patch 15/21] clockevents: drivers for i386 Thomas Gleixner
2006-10-01 23:01 ` [patch 16/21] high-res timers: core Thomas Gleixner
2006-10-02 11:50 ` Paulo Marques
2006-10-01 23:01 ` [patch 17/21] dynticks: core Thomas Gleixner
2006-10-02 6:41 ` [patch] dynticks: core, NMI watchdog fix Ingo Molnar
2006-10-02 8:54 ` [patch] dynticks: core, NMI watchdog fix, #2 Ingo Molnar
2006-10-01 23:01 ` [patch 18/21] dyntick: add nohz stats to /proc/stat Thomas Gleixner
2006-10-01 23:01 ` [patch 19/21] dynticks: i386 arch code Thomas Gleixner
2006-10-01 23:01 ` [patch 20/21] high-res timers, dynticks: enable i386 support Thomas Gleixner
2006-10-01 23:01 ` [patch 21/21] debugging feature: timer stats Thomas Gleixner
2006-10-02 5:11 ` [patch 00/21] high resolution timers / dynamic ticks - V2 Valdis.Kletnieks
2006-10-02 13:02 ` Valdis.Kletnieks
2006-10-02 13:43 ` Thomas Gleixner
2006-10-02 18:25 ` Valdis.Kletnieks
2006-10-02 18:38 ` john stultz
2006-10-02 19:08 ` Valdis.Kletnieks
2006-10-02 19:23 ` john stultz
2006-10-02 18:43 ` Thomas Gleixner [this message]
2006-10-02 20:17 ` [patch] dynticks core: Fix idle time accounting Valdis.Kletnieks
2006-10-02 21:22 ` Thomas Gleixner
2006-10-02 21:35 ` Valdis.Kletnieks
2006-10-03 20:02 ` Thomas Gleixner
2006-10-03 21:05 ` Thomas Gleixner
2006-10-04 2:33 ` Valdis.Kletnieks
2006-10-04 7:56 ` Ingo Molnar
2006-10-04 9:58 ` Valdis.Kletnieks
2006-10-03 3:23 ` [patch 00/21] high resolution timers / dynamic ticks - V2 Andrew Morton
2006-10-03 4:00 ` Andrew Morton
2006-10-03 8:38 ` Thomas Gleixner
2006-10-03 8:47 ` Ingo Molnar
2006-10-03 10:35 ` [patch] clockevents: drivers for i386, fix #2 Ingo Molnar
2006-10-04 3:36 ` Andrew Morton
2006-10-04 6:46 ` Ingo Molnar
2006-10-04 7:32 ` Andrew Morton
2006-10-04 7:41 ` Ingo Molnar
2006-10-04 8:01 ` Andrew Morton
2006-10-04 7:55 ` Ingo Molnar
2006-10-04 8:15 ` Andrew Morton
2006-10-04 10:53 ` Ingo Molnar
2006-10-04 11:19 ` Thomas Gleixner
2006-10-04 16:02 ` Andrew Morton
2006-10-04 16:20 ` Thomas Gleixner
2006-10-04 16:35 ` Ingo Molnar
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=1159814606.1386.52.camel@localhost.localdomain \
--to=tglx@linutronix.de \
--cc=Valdis.Kletnieks@vt.edu \
--cc=akpm@osdl.org \
--cc=arjan@infradead.org \
--cc=davej@redhat.com \
--cc=dwmw2@infradead.org \
--cc=jg@laptop.org \
--cc=johnstul@us.ibm.com \
--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