[PATCH 8/8] Call tick_check_idle before __irq_enter

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Venkatesh Pallipadi
Date: Monday, October 4, 2010 - 5:03 pm

When CPU is idle and on first interrupt, irq_enter calls tick_check_idle()
to notify interruption from idle. But, there is a problem if this call
is done after __irq_enter, as all routines in __irq_enter may find
stale time due to yet to be done tick_check_idle.

Specifically, trace calls in __irq_enter when they use global clock and also
account_system_vtime change in this patch as it wants to use sched_clock_cpu()
to do proper irq timing.

But, tick_check_idle was moved after __irq_enter intentionally to
prevent problem of unneeded ksoftirqd wakeups by the commit ee5f80a.
    irq: call __irq_enter() before calling the tick_idle_check
    Impact: avoid spurious ksoftirqd wakeups

Moving tick_check_idle() before __irq_enter and wrapping it with
local_bh_enable/disable would solve both the problems.

Signed-off-by: Venkatesh Pallipadi <venki@google.com>
---
 kernel/sched.c   |    2 +-
 kernel/softirq.c |   12 +++++++++---
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/kernel/sched.c b/kernel/sched.c
index 6487da4..442e151 100644
--- a/kernel/sched.c
+++ b/kernel/sched.c
@@ -1983,8 +1983,8 @@ void account_system_vtime(struct task_struct *curr)
 
 	local_irq_save(flags);
 
-	now = sched_clock();
 	cpu = smp_processor_id();
+	now = sched_clock_cpu(cpu);
 	delta = now - per_cpu(irq_start_time, cpu);
 	per_cpu(irq_start_time, cpu) = now;
 	/*
diff --git a/kernel/softirq.c b/kernel/softirq.c
index 267f7b7..6bb7e19 100644
--- a/kernel/softirq.c
+++ b/kernel/softirq.c
@@ -296,10 +296,16 @@ void irq_enter(void)
 
 	rcu_irq_enter();
 	if (idle_cpu(cpu) && !in_interrupt()) {
-		__irq_enter();
+		/*
+		 * Prevent raise_softirq from needlessly waking up ksoftirqd
+		 * here, as softirq will be serviced on return from interrupt.
+		 */
+		local_bh_disable();
 		tick_check_idle(cpu);
-	} else
-		__irq_enter();
+		local_bh_enable();
+	}
+
+	__irq_enter();
 }
 
 #ifdef __ARCH_IRQ_EXIT_IRQS_DISABLED
-- 
1.7.1

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Proper kernel irq time accounting -v4, Venkatesh Pallipadi, (Mon Oct 4, 5:03 pm)
[PATCH 1/8] si time accounting accounts bh_disable'd time ..., Venkatesh Pallipadi, (Mon Oct 4, 5:03 pm)
[PATCH 2/8] Consolidate account_system_vtime extern declar ..., Venkatesh Pallipadi, (Mon Oct 4, 5:03 pm)
[PATCH 3/8] Add a PF flag for ksoftirqd identification, Venkatesh Pallipadi, (Mon Oct 4, 5:03 pm)
[PATCH 4/8] Add IRQ_TIME_ACCOUNTING, finer accounting of i ..., Venkatesh Pallipadi, (Mon Oct 4, 5:03 pm)
[PATCH 5/8] x86: Add IRQ_TIME_ACCOUNTING in x86 -v4, Venkatesh Pallipadi, (Mon Oct 4, 5:03 pm)
[PATCH 6/8] sched: Do not account irq time to current task -v4, Venkatesh Pallipadi, (Mon Oct 4, 5:03 pm)
[PATCH 7/8] sched: Remove irq time from available CPU powe ..., Venkatesh Pallipadi, (Mon Oct 4, 5:03 pm)
[PATCH 8/8] Call tick_check_idle before __irq_enter, Venkatesh Pallipadi, (Mon Oct 4, 5:03 pm)
Re: Proper kernel irq time accounting -v4, Venkatesh Pallipadi, (Tue Oct 12, 12:00 pm)
Re: Proper kernel irq time accounting -v4, Shaun Ruffell, (Thu Oct 14, 9:12 am)
Re: Proper kernel irq time accounting -v4, Venkatesh Pallipadi, (Thu Oct 14, 11:19 am)
Re: Proper kernel irq time accounting -v4, Shaun Ruffell, (Thu Oct 14, 1:00 pm)
Re: [PATCH 3/8] Add a PF flag for ksoftirqd identification, Peter Zijlstra, (Fri Oct 15, 7:26 am)
Re: [PATCH 5/8] x86: Add IRQ_TIME_ACCOUNTING in x86 -v4, Peter Zijlstra, (Fri Oct 15, 7:38 am)
Re: Proper kernel irq time accounting -v4, Peter Zijlstra, (Fri Oct 15, 8:11 am)
Re: Proper kernel irq time accounting -v4, Peter Zijlstra, (Fri Oct 15, 8:27 am)
Re: Proper kernel irq time accounting -v4, Venkatesh Pallipadi, (Fri Oct 15, 10:13 am)
Re: Proper kernel irq time accounting -v4, Peter Zijlstra, (Fri Oct 15, 10:20 am)
Re: Proper kernel irq time accounting -v4, Yong Zhang, (Sun Oct 17, 2:11 am)
Re: [PATCH 8/8] Call tick_check_idle before __irq_enter, Peter Zijlstra, (Mon Oct 18, 2:15 am)
[tip:sched/core] sched: Fix softirq time accounting, tip-bot for Venkates ..., (Mon Oct 18, 12:24 pm)
[tip:sched/core] sched: Consolidate account_system_vtime e ..., tip-bot for Venkates ..., (Mon Oct 18, 12:24 pm)
[tip:sched/core] sched: Add a PF flag for ksoftirqd identi ..., tip-bot for Venkates ..., (Mon Oct 18, 12:25 pm)
[tip:sched/core] sched: Add IRQ_TIME_ACCOUNTING, finer acc ..., tip-bot for Venkates ..., (Mon Oct 18, 12:25 pm)
[tip:sched/core] x86: Add IRQ_TIME_ACCOUNTING, tip-bot for Venkates ..., (Mon Oct 18, 12:26 pm)
[tip:sched/core] sched: Do not account irq time to current ..., tip-bot for Venkates ..., (Mon Oct 18, 12:26 pm)
[tip:sched/core] sched: Remove irq time from available CPU ..., tip-bot for Venkates ..., (Mon Oct 18, 12:26 pm)
[tip:sched/core] sched: Call tick_check_idle before __irq_ ..., tip-bot for Venkates ..., (Mon Oct 18, 12:27 pm)
[tip:sched/core] sched: Export account_system_vtime(), tip-bot for Ingo Molnar, (Mon Oct 18, 12:27 pm)
Re: [tip:sched/core] sched: Do not account irq time to cur ..., Venkatesh Pallipadi, (Wed Dec 1, 11:55 am)