2009-06-03 15:24:23

by Martin Schwidefsky

[permalink] [raw]
Subject: [patch 1/2] idle profile hits with NOHZ

From: Martin Schwidefsky <[email protected]>

On a NOHZ system the generic clock events code reports a maximum
of 1 tick to the kernel profiler. If the system slept for more than
a single tick or has not been woken by a timer interrupt the number
of ticks reported will be incorrect. This skewes the percentages in
the profile. A good place to report the profile ticks is in
tick_nohz_restart_sched_tick. We calculate the number of ticks for
the cpu accounting anyway. The only obstacle is that we need an
instruction address for the profile ticks. In order to get one
extend the tick_sched structure by an idle_pc field and set it in
tick_nohz_stop_idle which is called from tick_check_idle.
Note: this does not solve the same problem in oprofile.

Signed-off-by: Martin Schwidefsky <[email protected]>
---

include/linux/tick.h | 1 +
kernel/time/tick-sched.c | 14 +++++++++-----
2 files changed, 10 insertions(+), 5 deletions(-)

Index: quilt-2.6/include/linux/tick.h
===================================================================
--- quilt-2.6.orig/include/linux/tick.h
+++ quilt-2.6/include/linux/tick.h
@@ -64,6 +64,7 @@ struct tick_sched {
unsigned long last_jiffies;
unsigned long next_jiffies;
ktime_t idle_expires;
+ unsigned long idle_pc;
};

extern void __init tick_init(void);
Index: quilt-2.6/kernel/time/tick-sched.c
===================================================================
--- quilt-2.6.orig/kernel/time/tick-sched.c
+++ quilt-2.6/kernel/time/tick-sched.c
@@ -166,6 +166,8 @@ static void tick_nohz_stop_idle(int cpu)
ts->idle_lastupdate = now;
ts->idle_sleeptime = ktime_add(ts->idle_sleeptime, delta);
ts->idle_active = 0;
+ if (in_interrupt())
+ ts->idle_pc = profile_pc(get_irq_regs());

sched_clock_idle_wakeup_event(0);
}
@@ -419,9 +421,7 @@ void tick_nohz_restart_sched_tick(void)
{
int cpu = smp_processor_id();
struct tick_sched *ts = &per_cpu(tick_cpu_sched, cpu);
-#ifndef CONFIG_VIRT_CPU_ACCOUNTING
unsigned long ticks;
-#endif
ktime_t now;

local_irq_disable();
@@ -443,19 +443,23 @@ void tick_nohz_restart_sched_tick(void)
tick_do_update_jiffies64(now);
cpumask_clear_cpu(cpu, nohz_cpu_mask);

+ ticks = jiffies - ts->idle_jiffies;
#ifndef CONFIG_VIRT_CPU_ACCOUNTING
/*
* We stopped the tick in idle. Update process times would miss the
* time we slept as update_process_times does only a 1 tick
* accounting. Enforce that this is accounted to idle !
- */
- ticks = jiffies - ts->idle_jiffies;
- /*
+ *
* We might be one off. Do not randomly account a huge number of ticks!
*/
if (ticks && ticks < LONG_MAX)
account_idle_ticks(ticks);
#endif
+#ifdef CONFIG_PROFILING
+ /* Create profile hits for all ticks we slept in idle. */
+ if (ticks && ticks < LONG_MAX)
+ profile_hits(CPU_PROFILING, (void *) ts->idle_pc, ticks);
+#endif

touch_softlockup_watchdog();
/*

--
blue skies,
Martin.

"Reality continues to ruin my life." - Calvin.