Skip to contentSkip to conversation

spinlock lockup on CPU#0

DISCUSSION Justin Mattock 6 participants 10 messages Apr 24, 2008 – Apr 28, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hello, I recorded a .mov of a spinlock, but cant seem to send it out, so I have to manually write it down:

BUG: spinlock lockup on CPU#0, swapper/0, c17fa6c0
Pid: 0. swapper Not tainted 2.6.25-03562-g3dc5063 #1
[<c0219fbb>]  _raw_spin_lock+0xd5/0xf9
[<c0377c6b>] _spin_lock+0x8/0xa
[<c011cdce>]  task_rq_lock+0x44/0x6b
[<c011cfb4>]   try_to_wake+0x2a/0x1c4
[<co11d159>]  default_wake_function+0xb/0xd
[<co118847>] __wake_up_common+0x2f/0x5a
[<c011bc11>] complete+0x2b/0x3e
[<c02ad79a>] usb_api_blocking_completion+0x13/0x15
[<c02abadc>] usb_hcd_giveback_urb+0x52/0x82
[<f88686c7>] ehci_urb_done+0x6f/0x7c [ehci_hcd]
[<f8869614>] qh_completions+0x2d7/0x348 [ehci_hcd]
[<f8869721>] ehci_work+0x9c [ehci_hcd]
[<c0107c35>] ? sched_clock+0xb/0x1c
[<c0119bec>] ? __update_rq_clock+0x94/0x15a
[<f886c827>] ehci_irq+0x138/0x15f [ehci_hcd]
[<c02abd9> ] usb_hcd_irq+0x23/0x51
[<c0151c43>] handle_IRQ_event+0x2a/0x5a
[<c0152d2c>] handle_fasteoi_irq+0x74/0xb6
[<c01058c5>] do_IRQ+0x71/0x8c
[<c01042f7>] common_interrupt+0x23/0x28
[<c011fb07>] ? sched_clock_idle_wakeup_event+0x5b/0x74
[<c02cc212>] acpi_idle_enter_bm+0x2a4/0x31f    [processor]
[<c02cc212>] cpuidle_idle_call+0x5c/0x8c
[<c02cc1b4>] ? cpuidle_idle_call+0x0/0x8c
[<c0102571>] cpu_idle+0xb1/0xd1
[<c036b371>] reset_init+0x49/0x4b
=====================================================

Hopefully the numbers are right, and hopefully this provides enough info to help the kernel out
regards;

Signature · 1 line
Justin P. Mattock
#1 lore raw
Quoted 34 lines · On Thu, 24 Apr 2008 01:41:32 +0000 "Justin Mattock" <[email protected]>…

Hello, I recorded a .mov of a spinlock, but cant seem to send it out, so I have to manually write it down:

BUG: spinlock lockup on CPU#0, swapper/0, c17fa6c0
Pid: 0. swapper Not tainted 2.6.25-03562-g3dc5063 #1
[<c0219fbb>]  _raw_spin_lock+0xd5/0xf9
[<c0377c6b>] _spin_lock+0x8/0xa
[<c011cdce>]  task_rq_lock+0x44/0x6b
[<c011cfb4>]   try_to_wake+0x2a/0x1c4
[<co11d159>]  default_wake_function+0xb/0xd
[<co118847>] __wake_up_common+0x2f/0x5a
[<c011bc11>] complete+0x2b/0x3e
[<c02ad79a>] usb_api_blocking_completion+0x13/0x15
[<c02abadc>] usb_hcd_giveback_urb+0x52/0x82
[<f88686c7>] ehci_urb_done+0x6f/0x7c [ehci_hcd]
[<f8869614>] qh_completions+0x2d7/0x348 [ehci_hcd]
[<f8869721>] ehci_work+0x9c [ehci_hcd]
[<c0107c35>] ? sched_clock+0xb/0x1c
[<c0119bec>] ? __update_rq_clock+0x94/0x15a
[<f886c827>] ehci_irq+0x138/0x15f [ehci_hcd]
[<c02abd9> ] usb_hcd_irq+0x23/0x51
[<c0151c43>] handle_IRQ_event+0x2a/0x5a
[<c0152d2c>] handle_fasteoi_irq+0x74/0xb6
[<c01058c5>] do_IRQ+0x71/0x8c
[<c01042f7>] common_interrupt+0x23/0x28
[<c011fb07>] ? sched_clock_idle_wakeup_event+0x5b/0x74
[<c02cc212>] acpi_idle_enter_bm+0x2a4/0x31f    [processor]
[<c02cc212>] cpuidle_idle_call+0x5c/0x8c
[<c02cc1b4>] ? cpuidle_idle_call+0x0/0x8c
[<c0102571>] cpu_idle+0xb1/0xd1
[<c036b371>] reset_init+0x49/0x4b
=====================================================
Quoted 2 lines

Hopefully the numbers are right, and hopefully this provides enough info to help the kernel out

Well that's cute. At a guess I'd say that acpi_processor_idle() managed to call sched_clock_idle_wakeup_event() with local interrupts enabled. We took an interrupt with rq->lock held and things went downhill from there.

Can you add this please, see if it triggers?

kernel/sched.c renamed from kernel/sched.c~a +2 -0
@@ -811,6 +811,7 @@ void sched_clock_idle_sleep_event(void)
 {
 	struct rq *rq = cpu_rq(smp_processor_id());
 
+	WARN_ON(!irqs_disabled());
 	spin_lock(&rq->lock);
 	__update_rq_clock(rq);
 	spin_unlock(&rq->lock);
@@ -826,6 +827,7 @@ void sched_clock_idle_wakeup_event(u64 d
 	struct rq *rq = cpu_rq(smp_processor_id());
 	u64 now = sched_clock();
 
+	WARN_ON(!irqs_disabled());
 	rq->idle_clock += delta_ns;
 	/*
 	 * Override the previous timestamp and ignore all

_

#2 lore raw
Quoted 61 lines · Andrew Morton
Quoted 34 lines · On Thu, 24 Apr 2008 01:41:32 +0000 "Justin Mattock" <[email protected]>…

Hello, I recorded a .mov of a spinlock, but cant seem to send it out, so I have to manually write it down:

BUG: spinlock lockup on CPU#0, swapper/0, c17fa6c0
Pid: 0. swapper Not tainted 2.6.25-03562-g3dc5063 #1
[<c0219fbb>]  _raw_spin_lock+0xd5/0xf9
[<c0377c6b>] _spin_lock+0x8/0xa
[<c011cdce>]  task_rq_lock+0x44/0x6b
[<c011cfb4>]   try_to_wake+0x2a/0x1c4
[<co11d159>]  default_wake_function+0xb/0xd
[<co118847>] __wake_up_common+0x2f/0x5a
[<c011bc11>] complete+0x2b/0x3e
[<c02ad79a>] usb_api_blocking_completion+0x13/0x15
[<c02abadc>] usb_hcd_giveback_urb+0x52/0x82
[<f88686c7>] ehci_urb_done+0x6f/0x7c [ehci_hcd]
[<f8869614>] qh_completions+0x2d7/0x348 [ehci_hcd]
[<f8869721>] ehci_work+0x9c [ehci_hcd]
[<c0107c35>] ? sched_clock+0xb/0x1c
[<c0119bec>] ? __update_rq_clock+0x94/0x15a
[<f886c827>] ehci_irq+0x138/0x15f [ehci_hcd]
[<c02abd9> ] usb_hcd_irq+0x23/0x51
[<c0151c43>] handle_IRQ_event+0x2a/0x5a
[<c0152d2c>] handle_fasteoi_irq+0x74/0xb6
[<c01058c5>] do_IRQ+0x71/0x8c
[<c01042f7>] common_interrupt+0x23/0x28
[<c011fb07>] ? sched_clock_idle_wakeup_event+0x5b/0x74
[<c02cc212>] acpi_idle_enter_bm+0x2a4/0x31f    [processor]
[<c02cc212>] cpuidle_idle_call+0x5c/0x8c
[<c02cc1b4>] ? cpuidle_idle_call+0x0/0x8c
[<c0102571>] cpu_idle+0xb1/0xd1
[<c036b371>] reset_init+0x49/0x4b
=====================================================
Quoted 2 lines

Hopefully the numbers are right, and hopefully this provides enough info to help the kernel out

Well that's cute. At a guess I'd say that acpi_processor_idle() managed to call sched_clock_idle_wakeup_event() with local interrupts enabled. We took an interrupt with rq->lock held and things went downhill from there.

Can you add this please, see if it triggers?

--- a/kernel/sched.c~a
+++ a/kernel/sched.c
@@ -811,6 +811,7 @@ void sched_clock_idle_sleep_event(void)

  {
        struct rq *rq = cpu_rq(smp_processor_id());
 +       WARN_ON(!irqs_disabled());
        spin_lock(&rq->lock);
        __update_rq_clock(rq);
        spin_unlock(&rq->lock);
 @@ -826,6 +827,7 @@ void sched_clock_idle_wakeup_event(u64 d
        struct rq *rq = cpu_rq(smp_processor_id());
        u64 now = sched_clock();
Quoted 7 lines
 +       WARN_ON(!irqs_disabled());
        rq->idle_clock += delta_ns;
        /*
         * Override the previous timestamp and ignore all

_

Yeah, I dont mind adding this to see what happens. regards

Signature · 1 line
Justin P. Mattock
#3 lore raw
In reply to Andrew Morton
Quoted 9 lines · Andrew Morton
Quoted 2 lines

Hopefully the numbers are right, and hopefully this provides enough info to help the kernel out

Well that's cute. At a guess I'd say that acpi_processor_idle() managed to call sched_clock_idle_wakeup_event() with local interrupts enabled. We took an interrupt with rq->lock held and things went downhill from there.

Can you add this please, see if it triggers?

there's fixes pending in this area. The main fix would be the one below.

Ingo

---------------->
Subject: idle (arch, acpi and apm) and lockdep
From: Peter Zijlstra <[email protected]>
Date: Fri, 25 Apr 2008 17:39:01 +0200

Quoted 51 lines · Peter Zijlstra
Quoted 38 lines · Justin Mattock
Quoted 37 lines · Peter Zijlstra
Quoted 35 lines · Justin Mattock
[   13.269763] =================================
[   13.270954] [ INFO: inconsistent lock state ]
[   13.271865] 2.6.25-04569-gb69d398 #3
[   13.272614] ---------------------------------
[   13.273521] inconsistent {in-hardirq-W} -> {hardirq-on-W} usage.
[   13.274745] swapper/0 [HC0[0]:SC0[0]:HE1:SE1] takes:
[   13.275787]  (&rq->rq_lock_key){++..}, at: [<c01208e9>] sched_clock_idle_wakeup_event+0x43/0x74
[   13.276859] {in-hardirq-W} state was registered at:
[   13.276859]   [<c01423d8>] __lock_acquire+0x419/0xb70
[   13.276859]   [<c0142bae>] lock_acquire+0x7f/0xa6
[   13.280188]   [<c0394132>] _spin_lock+0x1c/0x49
[   13.280188]   [<c0121c44>] scheduler_tick+0x43/0x1bd
[   13.280188]   [<c012d99f>] update_process_times+0x3d/0x49
[   13.283524]   [<c013daf6>] tick_periodic+0x66/0x72
[   13.283524]   [<c013db1b>] tick_handle_periodic+0x19/0x6a
[   13.283524]   [<c0105a87>] timer_interrupt+0x47/0x4e
[   13.286855]   [<c015cf64>] handle_IRQ_event+0x1a/0x4f
[   13.286855]   [<c015e3e9>] handle_level_irq+0x7f/0xca
[   13.286855]   [<c0105a27>] do_IRQ+0x71/0x8a
[   13.290190]   [<c01043fe>] common_interrupt+0x2e/0x34
[   13.290190]   [<c038bd6f>] calibrate_delay+0x8f/0x276
[   13.290190]   [<c04f0883>] start_kernel+0x27c/0x2f8
[   13.293520]   [<c04f0008>] __init_begin+0x8/0xa
[   13.293520]   [<ffffffff>] 0xffffffff
[   13.293520] irq event stamp: 253965
[   13.296856] hardirqs last  enabled at (253965): [<c0108069>] native_sched_clock+0xe7/0xff
[   13.296856] hardirqs last disabled at (253964): [<c0107fef>] native_sched_clock+0x6d/0xff
[   13.300190] softirqs last  enabled at (253958): [<c0129cea>] __do_softirq+0xf9/0xff
[   13.300190] softirqs last disabled at (253953): [<c0129d3d>] do_softirq+0x4d/0x79
[   13.303522]
[   13.303522] other info that might help us debug this:
[   13.303522] no locks held by swapper/0.
[   13.303522]
[   13.303522] stack backtrace:
[   13.306852] Pid: 0, comm: swapper Not tainted 2.6.25-04569-gb69d398 #3
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
[   13.336851]  [<c01409f9>] print_usage_bug+0x106/0x113
[   13.340185]  [<c0141823>] mark_lock+0x1ed/0x3a5
[   13.343519]  [<c014244d>] __lock_acquire+0x48e/0xb70
[   13.346852]  [<c0142bae>] lock_acquire+0x7f/0xa6
[   13.350185]  [<c01208e9>] ? sched_clock_idle_wakeup_event+0x43/0x74
[   13.353519]  [<c0394132>] _spin_lock+0x1c/0x49
[   13.360185]  [<c01208e9>] ? sched_clock_idle_wakeup_event+0x43/0x74
[   13.363518]  [<c01208e9>] sched_clock_idle_wakeup_event+0x43/0x74

Got it:

acpi_idle_do_entry()

Quoted 15 lines
    acpi_processor_ffh_cstate_enter()
      mwait_idle_with_hints() (32 bit)
        local_irq_enable()

sched_clock_idle_wakeup_event()

I think my recent idle patches should address this, no?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
[   13.366851]  [<f883919b>] acpi_idle_enter_bm+0x2b3/0x333 [processor]
[   13.370184]  [<c02e5ec1>] cpuidle_idle_call+0x63/0x92
[   13.373517]  [<c02e5e5e>] ? cpuidle_idle_call+0x0/0x92
[   13.380184]  [<c010257d>] cpu_idle+0xb6/0xd6
[   13.383517]  [<c0387071>] rest_init+0x49/0x4b
[   13.386850]  =======================

(I just found out I failed to copy LKML on the last discussion about these patches)

---
From: Peter Zijlstra <[email protected]>

OK, so 25-mm1 gave a lockdep error which made me look into this.

The first thing that I noticed was the horrible mess; the second thing I saw was hacks like: 71e93d15612c61c2e26a169567becf088e71b8ff

The problem is that arch idle routines are somewhat inconsitent with their IRQ state handling and instead of fixing _that_, we go paper over the problem.

So the thing I've tried to do is set a standard for idle routines and fix them all up to adhere to that. So the rules are:

idle routines are entered with IRQs disabled
idle routines will exit with IRQs enabled

Nearly all already did this in one form or another.

Merge the 32 and 64 bit bits so they no longer have different bugs.

As for the actual lockdep warning; __sti_mwait() did a plainly un-annotated irq-enable.

---
 arch/x86/kernel/apm_32.c      |    3 +
 arch/x86/kernel/process.c     |  117 +++++++++++++++++++++++++++++++++++++++
 arch/x86/kernel/process_32.c  |  118 +---------------------------------------
 arch/x86/kernel/process_64.c  |  123 +-----------------------------------------
 drivers/acpi/processor_idle.c |   19 +++---
 include/asm-x86/processor.h   |    1 
 6 files changed, 137 insertions(+), 244 deletions(-)
arch/x86/kernel/apm_32.c +3 -0
Index: linux/arch/x86/kernel/apm_32.c
===================================================================
@@ -904,6 +904,7 @@ recalc:
 			original_pm_idle();
 		else
 			default_idle();
+		local_irq_disable();
 		jiffies_since_last_check = jiffies - last_jiffies;
 		if (jiffies_since_last_check > idle_period)
 			goto recalc;
@@ -911,6 +912,8 @@ recalc:
 
 	if (apm_idle_done)
 		apm_do_busy();
+
+	local_irq_enable();
 }
 
 /**
arch/x86/kernel/process.c +117 -0

126 lines not on this page · raw message

arch/x86/kernel/process_32.c +4 -114

143 lines not on this page · raw message

arch/x86/kernel/process_64.c +3 -120

139 lines not on this page · raw message

drivers/acpi/processor_idle.c +9 -10
Index: linux/drivers/acpi/processor_idle.c
===================================================================
@@ -418,13 +418,12 @@ static void acpi_processor_idle(void)
 
 	cx = pr->power.state;
 	if (!cx || acpi_idle_suspend) {
-		if (pm_idle_save)
-			pm_idle_save();
-		else
+		if (pm_idle_save) {
+			pm_idle_save(); /* enables IRQs */
+		} else {
 			acpi_safe_halt();
-
-		if (irqs_disabled())
 			local_irq_enable();
+		}
 
 		return;
 	}
@@ -520,10 +519,12 @@ static void acpi_processor_idle(void)
 		 * Use the appropriate idle routine, the one that would
 		 * be used without acpi C-states.
 		 */
-		if (pm_idle_save)
-			pm_idle_save();
-		else
+		if (pm_idle_save) {
+			pm_idle_save(); /* enables IRQs */
+		} else {
 			acpi_safe_halt();
+			local_irq_enable();
+		}
 
 		/*
 		 * TBD: Can't get time duration while in C1, as resumes
@@ -534,8 +535,6 @@ static void acpi_processor_idle(void)
 		 *       skew otherwise.
 		 */
 		sleep_ticks = 0xFFFFFFFF;
-		if (irqs_disabled())
-			local_irq_enable();
 
 		break;
 
include/asm-x86/processor.h +1 -0
Index: linux/include/asm-x86/processor.h
===================================================================
@@ -725,6 +725,7 @@ static inline void __mwait(unsigned long
 
 static inline void __sti_mwait(unsigned long eax, unsigned long ecx)
 {
+	trace_hardirqs_on();
 	/* "mwait %eax, %ecx;" */
 	asm volatile("sti; .byte 0x0f, 0x01, 0xc9;"
 		     :: "a" (eax), "c" (ecx));
#4 lore raw
Quoted 632 lines · Ingo Molnar
Quoted 9 lines · Andrew Morton
Quoted 2 lines

Hopefully the numbers are right, and hopefully this provides enough info to help the kernel out

Well that's cute. At a guess I'd say that acpi_processor_idle() managed to call sched_clock_idle_wakeup_event() with local interrupts enabled. We took an interrupt with rq->lock held and things went downhill from there.

Can you add this please, see if it triggers?

there's fixes pending in this area. The main fix would be the one below.

Ingo

---------------->
Subject: idle (arch, acpi and apm) and lockdep
From: Peter Zijlstra <[email protected]>
Date: Fri, 25 Apr 2008 17:39:01 +0200

Quoted 51 lines · Peter Zijlstra
Quoted 38 lines · Justin Mattock
Quoted 37 lines · Peter Zijlstra
Quoted 35 lines · Justin Mattock
[   13.269763] =================================
[   13.270954] [ INFO: inconsistent lock state ]
[   13.271865] 2.6.25-04569-gb69d398 #3
[   13.272614] ---------------------------------
[   13.273521] inconsistent {in-hardirq-W} -> {hardirq-on-W} usage.
[   13.274745] swapper/0 [HC0[0]:SC0[0]:HE1:SE1] takes:
[   13.275787]  (&rq->rq_lock_key){++..}, at: [<c01208e9>] sched_clock_idle_wakeup_event+0x43/0x74
[   13.276859] {in-hardirq-W} state was registered at:
[   13.276859]   [<c01423d8>] __lock_acquire+0x419/0xb70
[   13.276859]   [<c0142bae>] lock_acquire+0x7f/0xa6
[   13.280188]   [<c0394132>] _spin_lock+0x1c/0x49
[   13.280188]   [<c0121c44>] scheduler_tick+0x43/0x1bd
[   13.280188]   [<c012d99f>] update_process_times+0x3d/0x49
[   13.283524]   [<c013daf6>] tick_periodic+0x66/0x72
[   13.283524]   [<c013db1b>] tick_handle_periodic+0x19/0x6a
[   13.283524]   [<c0105a87>] timer_interrupt+0x47/0x4e
[   13.286855]   [<c015cf64>] handle_IRQ_event+0x1a/0x4f
[   13.286855]   [<c015e3e9>] handle_level_irq+0x7f/0xca
[   13.286855]   [<c0105a27>] do_IRQ+0x71/0x8a
[   13.290190]   [<c01043fe>] common_interrupt+0x2e/0x34
[   13.290190]   [<c038bd6f>] calibrate_delay+0x8f/0x276
[   13.290190]   [<c04f0883>] start_kernel+0x27c/0x2f8
[   13.293520]   [<c04f0008>] __init_begin+0x8/0xa
[   13.293520]   [<ffffffff>] 0xffffffff
[   13.293520] irq event stamp: 253965
[   13.296856] hardirqs last  enabled at (253965): [<c0108069>] native_sched_clock+0xe7/0xff
[   13.296856] hardirqs last disabled at (253964): [<c0107fef>] native_sched_clock+0x6d/0xff
[   13.300190] softirqs last  enabled at (253958): [<c0129cea>] __do_softirq+0xf9/0xff
[   13.300190] softirqs last disabled at (253953): [<c0129d3d>] do_softirq+0x4d/0x79
[   13.303522]
[   13.303522] other info that might help us debug this:
[   13.303522] no locks held by swapper/0.
[   13.303522]
[   13.303522] stack backtrace:
[   13.306852] Pid: 0, comm: swapper Not tainted 2.6.25-04569-gb69d398 #3
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
[   13.336851]  [<c01409f9>] print_usage_bug+0x106/0x113
[   13.340185]  [<c0141823>] mark_lock+0x1ed/0x3a5
[   13.343519]  [<c014244d>] __lock_acquire+0x48e/0xb70
[   13.346852]  [<c0142bae>] lock_acquire+0x7f/0xa6
[   13.350185]  [<c01208e9>] ? sched_clock_idle_wakeup_event+0x43/0x74
[   13.353519]  [<c0394132>] _spin_lock+0x1c/0x49
[   13.360185]  [<c01208e9>] ? sched_clock_idle_wakeup_event+0x43/0x74
[   13.363518]  [<c01208e9>] sched_clock_idle_wakeup_event+0x43/0x74

Got it:

acpi_idle_do_entry()

Quoted 15 lines
    acpi_processor_ffh_cstate_enter()
      mwait_idle_with_hints() (32 bit)
        local_irq_enable()

sched_clock_idle_wakeup_event()

I think my recent idle patches should address this, no?

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
[   13.366851]  [<f883919b>] acpi_idle_enter_bm+0x2b3/0x333 [processor]
[   13.370184]  [<c02e5ec1>] cpuidle_idle_call+0x63/0x92
[   13.373517]  [<c02e5e5e>] ? cpuidle_idle_call+0x0/0x92
[   13.380184]  [<c010257d>] cpu_idle+0xb6/0xd6
[   13.383517]  [<c0387071>] rest_init+0x49/0x4b
[   13.386850]  =======================

(I just found out I failed to copy LKML on the last discussion about these patches)

---
From: Peter Zijlstra <[email protected]>

OK, so 25-mm1 gave a lockdep error which made me look into this.

The first thing that I noticed was the horrible mess; the second thing I saw was hacks like: 71e93d15612c61c2e26a169567becf088e71b8ff

The problem is that arch idle routines are somewhat inconsitent with their IRQ state handling and instead of fixing _that_, we go paper over the problem.

So the thing I've tried to do is set a standard for idle routines and fix them all up to adhere to that. So the rules are:

idle routines are entered with IRQs disabled
idle routines will exit with IRQs enabled

Nearly all already did this in one form or another.

Merge the 32 and 64 bit bits so they no longer have different bugs.

As for the actual lockdep warning; __sti_mwait() did a plainly un-annotated irq-enable.

---

  arch/x86/kernel/apm_32.c      |    3 +
  arch/x86/kernel/process.c     |  117 +++++++++++++++++++++++++++++++++++++++
  arch/x86/kernel/process_32.c  |  118 +---------------------------------------
  arch/x86/kernel/process_64.c  |  123 +-----------------------------------------
  drivers/acpi/processor_idle.c |   19 +++---
  include/asm-x86/processor.h   |    1
  6 files changed, 137 insertions(+), 244 deletions(-)

Index: linux/arch/x86/kernel/apm_32.c
===================================================================
--- linux.orig/arch/x86/kernel/apm_32.c
+++ linux/arch/x86/kernel/apm_32.c
@@ -904,6 +904,7 @@ recalc:

                        original_pm_idle();
                else
                        default_idle();
 +               local_irq_disable();
                jiffies_since_last_check = jiffies - last_jiffies;
                if (jiffies_since_last_check > idle_period)
                        goto recalc;

@@ -911,6 +912,8 @@ recalc:

        if (apm_idle_done)
                apm_do_busy();

+
+ local_irq_enable();
}

/**
Index: linux/arch/x86/kernel/process.c
===================================================================
--- linux.orig/arch/x86/kernel/process.c
+++ linux/arch/x86/kernel/process.c
@@ -4,6 +4,8 @@
#include <linux/smp.h>
#include <linux/slab.h>
#include <linux/sched.h>
+#include <linux/module.h>
+#include <linux/pm.h>

struct kmem_cache *task_xstate_cachep;

@@ -42,3 +44,118 @@ void arch_task_cache_init(void)

                                  __alignof__(union thread_xstate),
                                  SLAB_PANIC | SLAB_NOTRACK, NULL);
  }
 +
 +static void do_nothing(void *unused)
 +{
 +}
 +
 +/*
 + * cpu_idle_wait - Used to ensure that all the CPUs discard old value of
 + * pm_idle and update to new pm_idle value. Required while changing pm_idle
 + * handler on SMP systems.
 + *
 + * Caller must have changed pm_idle to the new value before the call. Old
 + * pm_idle value will not be used by any CPU after the return of this function.
 + */
 +void cpu_idle_wait(void)
 +{
 +       smp_mb();
 +       /* kick all the CPUs so that they exit out of pm_idle */
 +       smp_call_function(do_nothing, NULL, 0, 1);
 +}
 +EXPORT_SYMBOL_GPL(cpu_idle_wait);
 +
 +/*
 + * This uses new MONITOR/MWAIT instructions on P4 processors with PNI,
 + * which can obviate IPI to trigger checking of need_resched.
 + * We execute MONITOR against need_resched and enter optimized wait state
 + * through MWAIT. Whenever someone changes need_resched, we would be woken
 + * up from MWAIT (without an IPI).
 + *
 + * New with Core Duo processors, MWAIT can take some hints based on CPU
 + * capability.
 + */
 +void mwait_idle_with_hints(unsigned long ax, unsigned long cx)
 +{
 +       if (!need_resched()) {
 +               __monitor((void *)&current_thread_info()->flags, 0, 0);
 +               smp_mb();
 +               if (!need_resched())
 +                       __mwait(ax, cx);
 +       }
 +}
 +
 +/* Default MONITOR/MWAIT with no hints, used for default C1 state */
 +static void mwait_idle(void)
 +{
 +       if (!need_resched()) {
 +               __monitor((void *)&current_thread_info()->flags, 0, 0);
 +               smp_mb();
 +               if (!need_resched())
 +                       __sti_mwait(0, 0);
 +               else
 +                       local_irq_enable();
 +       } else
 +               local_irq_enable();
 +}
 +
 +
 +static int __cpuinit mwait_usable(const struct cpuinfo_x86 *c)
 +{
 +       if (force_mwait)
 +               return 1;
 +       /* Any C1 states supported? */
 +       return c->cpuid_level >= 5 && ((cpuid_edx(5) >> 4) & 0xf) > 0;
 +}
 +
 +/*
 + * On SMP it's slightly faster (but much more power-consuming!)
 + * to poll the ->work.need_resched flag instead of waiting for the
 + * cross-CPU IPI to arrive. Use this option with caution.
 + */
 +static void poll_idle(void)
 +{
 +       local_irq_enable();
 +       cpu_relax();
 +}
 +
 +void __cpuinit select_idle_routine(const struct cpuinfo_x86 *c)
 +{
 +       static int selected;
 +
 +       if (selected)
 +               return;
 +#ifdef CONFIG_X86_SMP
 +       if (pm_idle == poll_idle && smp_num_siblings > 1) {
 +               printk(KERN_WARNING "WARNING: polling idle and HT enabled,"
 +                       " performance may degrade.\n");
 +       }
 +#endif
 +       if (cpu_has(c, X86_FEATURE_MWAIT) && mwait_usable(c)) {
 +               /*
 +                * Skip, if setup has overridden idle.
 +                * One CPU supports mwait => All CPUs supports mwait
 +                */
 +               if (!pm_idle) {
 +                       printk(KERN_INFO "using mwait in idle threads.\n");
 +                       pm_idle = mwait_idle;
 +               }
 +       }
 +       selected = 1;
 +}
 +
 +static int __init idle_setup(char *str)
 +{
 +       if (!strcmp(str, "poll")) {
 +               printk("using polling idle threads.\n");
 +               pm_idle = poll_idle;
 +       } else if (!strcmp(str, "mwait"))
 +               force_mwait = 1;
 +       else
 +               return -1;
 +
 +       boot_option_idle_override = 1;
 +       return 0;
 +}
 +early_param("idle", idle_setup);
 +
 Index: linux/arch/x86/kernel/process_32.c
 ===================================================================
 --- linux.orig/arch/x86/kernel/process_32.c
 +++ linux/arch/x86/kernel/process_32.c
 @@ -111,12 +111,10 @@ void default_idle(void)
                 */
                smp_mb();
 -               local_irq_disable();
 -               if (!need_resched()) {
 +               if (!need_resched())
                        safe_halt();    /* enables interrupts racelessly */
 -                       local_irq_disable();
 -               }
 -               local_irq_enable();
 +               else
 +                       local_irq_enable();
                current_thread_info()->status |= TS_POLLING;
        } else {
                local_irq_enable();

@@ -128,17 +126,6 @@ void default_idle(void)
EXPORT_SYMBOL(default_idle);
#endif

-/*
- * On SMP it's slightly faster (but much more power-consuming!)
- * to poll the ->work.need_resched flag instead of waiting for the
- * cross-CPU IPI to arrive. Use this option with caution.
- */
-static void poll_idle(void)
-{
- local_irq_enable();
- cpu_relax();
-}
-
#ifdef CONFIG_HOTPLUG_CPU
#include <asm/nmi.h>
/* We don't actually take CPU down, just spin without interrupts. */
@@ -196,6 +183,7 @@ void cpu_idle(void)

                        if (cpu_is_offline(cpu))
                                play_dead();
 +                       local_irq_disable();
                        __get_cpu_var(irq_stat).idle_timestamp = jiffies;
                        /* Don't trace irqs off for idle */
                        stop_critical_timings();
 @@ -209,104 +197,6 @@ void cpu_idle(void)
        }

}

-static void do_nothing(void *unused)
-{
-}
-
-/*
- * cpu_idle_wait - Used to ensure that all the CPUs discard old value of
- * pm_idle and update to new pm_idle value. Required while changing pm_idle
- * handler on SMP systems.
- *
- * Caller must have changed pm_idle to the new value before the call. Old
- * pm_idle value will not be used by any CPU after the return of this function.
- */
-void cpu_idle_wait(void)
-{

 -       smp_mb();
 -       /* kick all the CPUs so that they exit out of pm_idle */
 -       smp_call_function(do_nothing, NULL, 0, 1);
 -}
 -EXPORT_SYMBOL_GPL(cpu_idle_wait);
 -
 -/*
 - * This uses new MONITOR/MWAIT instructions on P4 processors with PNI,
 - * which can obviate IPI to trigger checking of need_resched.
 - * We execute MONITOR against need_resched and enter optimized wait state
 - * through MWAIT. Whenever someone changes need_resched, we would be woken
 - * up from MWAIT (without an IPI).
 - *
 - * New with Core Duo processors, MWAIT can take some hints based on CPU
 - * capability.
 - */
 -void mwait_idle_with_hints(unsigned long ax, unsigned long cx)
 -{
 -       if (!need_resched()) {
 -               __monitor((void *)&current_thread_info()->flags, 0, 0);
 -               smp_mb();
 -               if (!need_resched())
 -                       __sti_mwait(ax, cx);
 -               else
 -                       local_irq_enable();
 -       } else
 -               local_irq_enable();
 -}
 -
 -/* Default MONITOR/MWAIT with no hints, used for default C1 state */
 -static void mwait_idle(void)
 -{
 -       local_irq_enable();
 -       mwait_idle_with_hints(0, 0);
 -}
 -
 -static int __cpuinit mwait_usable(const struct cpuinfo_x86 *c)
 -{
 -       if (force_mwait)
 -               return 1;
 -       /* Any C1 states supported? */
 -       return c->cpuid_level >= 5 && ((cpuid_edx(5) >> 4) & 0xf) > 0;
 -}
 -
 -void __cpuinit select_idle_routine(const struct cpuinfo_x86 *c)
 -{
 -       static int selected;
 -
 -       if (selected)
 -               return;
 -#ifdef CONFIG_X86_SMP
 -       if (pm_idle == poll_idle && smp_num_siblings > 1) {
 -               printk(KERN_WARNING "WARNING: polling idle and HT enabled,"
 -                       " performance may degrade.\n");
 -       }
 -#endif
 -       if (cpu_has(c, X86_FEATURE_MWAIT) && mwait_usable(c)) {
 -               /*
 -                * Skip, if setup has overridden idle.
 -                * One CPU supports mwait => All CPUs supports mwait
 -                */
 -               if (!pm_idle) {
 -                       printk(KERN_INFO "using mwait in idle threads.\n");
 -                       pm_idle = mwait_idle;
 -               }
 -       }
 -       selected = 1;
 -}
 -
 -static int __init idle_setup(char *str)
 -{
 -       if (!strcmp(str, "poll")) {
 -               printk("using polling idle threads.\n");
 -               pm_idle = poll_idle;
 -       } else if (!strcmp(str, "mwait"))
 -               force_mwait = 1;
 -       else
 -               return -1;
 -
 -       boot_option_idle_override = 1;
 -       return 0;
 -}
 -early_param("idle", idle_setup);
 -
  void __show_regs(struct pt_regs *regs, int all)
  {
        unsigned long cr0 = 0L, cr2 = 0L, cr3 = 0L, cr4 = 0L;
 Index: linux/arch/x86/kernel/process_64.c
 ===================================================================
 --- linux.orig/arch/x86/kernel/process_64.c
 +++ linux/arch/x86/kernel/process_64.c
 @@ -107,26 +107,13 @@ void default_idle(void)
         * test NEED_RESCHED:
         */
        smp_mb();
 -       local_irq_disable();
 -       if (!need_resched()) {
 +       if (!need_resched())
                safe_halt();    /* enables interrupts racelessly */
 -               local_irq_disable();
 -       }
 -       local_irq_enable();
 +       else
 +               local_irq_enable();
        current_thread_info()->status |= TS_POLLING;

}

-/*
- * On SMP it's slightly faster (but much more power-consuming!)
- * to poll the ->need_resched flag instead of waiting for the
- * cross-CPU IPI to arrive. Use this option with caution.
- */
-static void poll_idle(void)
-{
- local_irq_enable();
- cpu_relax();
-}
-
#ifdef CONFIG_HOTPLUG_CPU
DECLARE_PER_CPU(int, cpu_state);

@@ -207,110 +194,6 @@ void cpu_idle(void)

        }

}

-static void do_nothing(void *unused)
-{
-}
-
-/*
- * cpu_idle_wait - Used to ensure that all the CPUs discard old value of
- * pm_idle and update to new pm_idle value. Required while changing pm_idle
- * handler on SMP systems.
- *
- * Caller must have changed pm_idle to the new value before the call. Old
- * pm_idle value will not be used by any CPU after the return of this function.
- */
-void cpu_idle_wait(void)
-{

 -       smp_mb();
 -       /* kick all the CPUs so that they exit out of pm_idle */
 -       smp_call_function(do_nothing, NULL, 0, 1);
 -}
 -EXPORT_SYMBOL_GPL(cpu_idle_wait);
 -
 -/*
 - * This uses new MONITOR/MWAIT instructions on P4 processors with PNI,
 - * which can obviate IPI to trigger checking of need_resched.
 - * We execute MONITOR against need_resched and enter optimized wait state
 - * through MWAIT. Whenever someone changes need_resched, we would be woken
 - * up from MWAIT (without an IPI).
 - *
 - * New with Core Duo processors, MWAIT can take some hints based on CPU
 - * capability.
 - */
 -void mwait_idle_with_hints(unsigned long ax, unsigned long cx)
 -{
 -       if (!need_resched()) {
 -               __monitor((void *)&current_thread_info()->flags, 0, 0);
 -               smp_mb();
 -               if (!need_resched())
 -                       __mwait(ax, cx);
 -       }
 -}
 -
 -/* Default MONITOR/MWAIT with no hints, used for default C1 state */
 -static void mwait_idle(void)
 -{
 -       if (!need_resched()) {
 -               __monitor((void *)&current_thread_info()->flags, 0, 0);
 -               smp_mb();
 -               if (!need_resched())
 -                       __sti_mwait(0, 0);
 -               else
 -                       local_irq_enable();
 -       } else {
 -               local_irq_enable();
 -       }
 -}
 -
 -
 -static int __cpuinit mwait_usable(const struct cpuinfo_x86 *c)
 -{
 -       if (force_mwait)
 -               return 1;
 -       /* Any C1 states supported? */
 -       return c->cpuid_level >= 5 && ((cpuid_edx(5) >> 4) & 0xf) > 0;
 -}
 -
 -void __cpuinit select_idle_routine(const struct cpuinfo_x86 *c)
 -{
 -       static int selected;
 -
 -       if (selected)
 -               return;
 -#ifdef CONFIG_X86_SMP
 -       if (pm_idle == poll_idle && smp_num_siblings > 1) {
 -               printk(KERN_WARNING "WARNING: polling idle and HT enabled,"
 -                       " performance may degrade.\n");
 -       }
 -#endif
 -       if (cpu_has(c, X86_FEATURE_MWAIT) && mwait_usable(c)) {
 -               /*
 -                * Skip, if setup has overridden idle.
 -                * One CPU supports mwait => All CPUs supports mwait
 -                */

- if (!pm_idle) {
- printk(KERN_INFO "using mwait in idle threads.\n");
- pm_idle = mwait_idle;
- }
- }
- selected = 1;
-}
-
-static int __init idle_setup(char *str)
-{
- if (!strcmp(str, "poll")) {
- printk("using polling idle threads.\n");
- pm_idle = poll_idle;
- } else if (!strcmp(str, "mwait"))
- force_mwait = 1;
- else
- return -1;
-
- boot_option_idle_override = 1;
- return 0;
-}
-early_param("idle", idle_setup);
-
/* Prints also some state that isn't saved in the pt_regs */ void __show_regs(struct pt_regs * regs, int all)
{
Index: linux/drivers/acpi/processor_idle.c
===================================================================
--- linux.orig/drivers/acpi/processor_idle.c
+++ linux/drivers/acpi/processor_idle.c
@@ -418,13 +418,12 @@ static void acpi_processor_idle(void)

        cx = pr->power.state;
        if (!cx || acpi_idle_suspend) {
 -               if (pm_idle_save)
 -                       pm_idle_save();
 -               else
 +               if (pm_idle_save) {
 +                       pm_idle_save(); /* enables IRQs */
 +               } else {
                        acpi_safe_halt();
 -
 -               if (irqs_disabled())
                        local_irq_enable();

+ }

                return;
        }
 @@ -520,10 +519,12 @@ static void acpi_processor_idle(void)
                 * Use the appropriate idle routine, the one that would
                 * be used without acpi C-states.
                 */
 -               if (pm_idle_save)
 -                       pm_idle_save();
 -               else
 +               if (pm_idle_save) {
 +                       pm_idle_save(); /* enables IRQs */
 +               } else {
                        acpi_safe_halt();

+ local_irq_enable();
+ }

/*
* TBD: Can't get time duration while in C1, as resumes
@@ -534,8 +535,6 @@ static void acpi_processor_idle(void)

                 *       skew otherwise.
                 */
                sleep_ticks = 0xFFFFFFFF;

- if (irqs_disabled())
- local_irq_enable();

                break;

Index: linux/include/asm-x86/processor.h
===================================================================
--- linux.orig/include/asm-x86/processor.h
+++ linux/include/asm-x86/processor.h
@@ -725,6 +725,7 @@ static inline void __mwait(unsigned long

Quoted 7 lines

static inline void __sti_mwait(unsigned long eax, unsigned long ecx) {

 +       trace_hardirqs_on();
        /* "mwait %eax, %ecx;" */
        asm volatile("sti; .byte 0x0f, 0x01, 0xc9;"
                     :: "a" (eax), "c" (ecx));

O.K.
I added WARN_ON(!irqs_disabled()); in kernel/sched.c
I'm not experiencing anything different, should I have done this with a fresh git that was'nt patched with the above?
The numbers were different for me they were at kernel/sched.c line 1123 and 1143 regards;

Signature · 1 line
Justin P. Mattock
#5 lore raw
In reply to Ingo Molnar
Quoted 8 lines · Ingo Molnar
Quoted 1 line

Can you add this please, see if it triggers?

there's fixes pending in this area. The main fix would be the one below.

Ingo

---------------->
Subject: idle (arch, acpi and apm) and lockdep

FWIW, I was seeing the same lockdep trace with eventual hangs, and this patch (applied with some fuzz) fixed the problem.

Signature · 1 line
Bob Copeland %% www.bobcopeland.com
#6 lore raw
Quoted 7 lines · Bob Copeland
Quoted 6 lines · Ingo Molnar
Quoted 1 line

Can you add this please, see if it triggers?

there's fixes pending in this area. The main fix would be the one below.

Ingo

Quoted 9 lines
Quoted 2 lines

---------------->
Subject: idle (arch, acpi and apm) and lockdep

FWIW, I was seeing the same lockdep trace with eventual hangs, and this patch (applied with some fuzz) fixed the problem.

--
Bob Copeland %% www.bobcopeland.com

Just out of curiosity I put the kernel back to it's original state, were the freezing occurs, then booted with nohz=off, then added WARN_ON(!irqs_disabled()); to sched.c only to the kernel, no other patches, upon rebooting
I received different results: The screen from what I could tell was spitting out the spinlock messages, but instead of printing that out, and going on to the next task it just keep't printing, from what I could tell something with ehci, uhci, agpgart, ieee1394 etc... too fast to really make anything out, the numbers on the left side keept moving upward, the fans started hauling ass, I waitied a few minuetes hopeing this would stop
so I can grab dmesg, but it would'nt. is there a way to use the boot param to write date to a file? so I could capture this event. regards

Signature · 1 line
Justin P. Mattock
#7 lore raw
Quoted 18 lines · Justin Mattock
Quoted 7 lines · Bob Copeland
Quoted 6 lines · Ingo Molnar
Quoted 1 line

Can you add this please, see if it triggers?

there's fixes pending in this area. The main fix would be the one below.

Ingo

Quoted 9 lines
Quoted 2 lines

---------------->
Subject: idle (arch, acpi and apm) and lockdep

FWIW, I was seeing the same lockdep trace with eventual hangs, and this patch (applied with some fuzz) fixed the problem.

--
Bob Copeland %% www.bobcopeland.com

Quoted 15 lines

Just out of curiosity I put the kernel back to it's original state, were the freezing occurs, then booted with nohz=off, then added WARN_ON(!irqs_disabled()); to sched.c only to the kernel, no other patches, upon rebooting
I received different results: The screen from what I could tell was spitting out the spinlock messages, but instead of printing that out, and going on to the next task it just keep't printing, from what I could tell something with ehci, uhci, agpgart, ieee1394 etc... too fast to really make anything out, the numbers on the left side keept moving upward, the fans started hauling ass, I waitied a few minuetes hopeing this would stop
so I can grab dmesg, but it would'nt. is there a way to use the boot param to write date to a file? so I could capture this event. regards

OK. Hunted this bug down to
commit 3b22ec7b13cb31e0d87fbc0aabe14caaaad309e8

which for some reason enables interrupt in mwait_idle_with_hints(), which eventually causes interrupts to be enabled in acpi idle call, resulting in sched_clock_idle_wakeup_event() with interrupts enabled. This bug was only in x86 32 bit version.

Peter's patch below which is already in git fixes this. So we don't need any additional fixes here...

Thanks,
Venki

#8 lore raw
Quoted 43 lines · Venki Pallipadi
Quoted 18 lines · Justin Mattock
Quoted 7 lines · Bob Copeland
Quoted 6 lines · Ingo Molnar
Quoted 1 line

Can you add this please, see if it triggers?

there's fixes pending in this area. The main fix would be the one below.

Ingo

Quoted 9 lines
Quoted 2 lines

---------------->
Subject: idle (arch, acpi and apm) and lockdep

FWIW, I was seeing the same lockdep trace with eventual hangs, and this patch (applied with some fuzz) fixed the problem.

--
Bob Copeland %% www.bobcopeland.com

Quoted 15 lines

Just out of curiosity I put the kernel back to it's original state, were the freezing occurs, then booted with nohz=off, then added WARN_ON(!irqs_disabled()); to sched.c only to the kernel, no other patches, upon rebooting
I received different results: The screen from what I could tell was spitting out the spinlock messages, but instead of printing that out, and going on to the next task it just keep't printing, from what I could tell something with ehci, uhci, agpgart, ieee1394 etc... too fast to really make anything out, the numbers on the left side keept moving upward, the fans started hauling ass, I waitied a few minuetes hopeing this would stop
so I can grab dmesg, but it would'nt. is there a way to use the boot param to write date to a file? so I could capture this event. regards

OK. Hunted this bug down to
commit 3b22ec7b13cb31e0d87fbc0aabe14caaaad309e8

which for some reason enables interrupt in mwait_idle_with_hints(), which eventually causes interrupts to be enabled in acpi idle call, resulting in sched_clock_idle_wakeup_event() with interrupts enabled. This bug was only in x86 32 bit version.

Quoted 7 lines

Peter's patch below which is already in git fixes this. So we don't need any additional fixes here...

Thanks,
Venki

Alright, I was concerned about having additional fixes. regards;

Signature · 1 line
Justin P. Mattock
#9 lore raw
In reply to Ingo Molnar
Quoted 12 lines · Ingo Molnar
Quoted 9 lines · Andrew Morton
Quoted 2 lines

Hopefully the numbers are right, and hopefully this provides enough info to help the kernel out

Well that's cute. At a guess I'd say that acpi_processor_idle() managed to call sched_clock_idle_wakeup_event() with local interrupts enabled. We took an interrupt with rq->lock held and things went downhill from there.

Can you add this please, see if it triggers?

Quoted 8 lines

there's fixes pending in this area. The main fix would be the one below.

Ingo

---------------->
Subject: idle (arch, acpi and apm) and lockdep
From: Peter Zijlstra <[email protected]>
Date: Fri, 25 Apr 2008 17:39:01 +0200

Oh good, thanks, I see you've just asked Linus to pull that idle fix.

Thanks to Peter for the fix, and to Justin for calling attention to it:
this freeze has been plaguing me on one x86_32 box since I put -git8 on, and I've just verified that it's the same as what's been plaguing me on that machine since 2.6.25-mm1 came out.

Andrew, here's a belated hotfix for 2.6.25-mm1, running nicely at last:

Peter Zijlstra's "idle (arch, acpi and apm) and lockdep" fix to recent x86 freezes - adapted to 2.6.25-mm1 by omitting merges from process_32.c and process_64.c into process.c.

---

 arch/x86/kernel/apm_32.c      |    3 +++
 arch/x86/kernel/process_32.c  |   27 +++++++++++++++------------
 arch/x86/kernel/process_64.c  |    8 +++-----
 drivers/acpi/processor_idle.c |   19 +++++++++----------
 include/asm-x86/processor.h   |    1 +
 5 files changed, 31 insertions(+), 27 deletions(-)
arch/x86/kernel/apm_32.c +3 -0
@@ -904,6 +904,7 @@ recalc:
 			original_pm_idle();
 		else
 			default_idle();
+		local_irq_disable();
 		jiffies_since_last_check = jiffies - last_jiffies;
 		if (jiffies_since_last_check > idle_period)
 			goto recalc;
@@ -911,6 +912,8 @@ recalc:
 
 	if (apm_idle_done)
 		apm_do_busy();
+
+	local_irq_enable();
 }
 
 /**
arch/x86/kernel/process_32.c +15 -12
@@ -111,12 +111,10 @@ void default_idle(void)
 		 */
 		smp_mb();
 
-		local_irq_disable();
-		if (!need_resched()) {
+		if (!need_resched())
 			safe_halt();	/* enables interrupts racelessly */
-			local_irq_disable();
-		}
-		local_irq_enable();
+		else
+			local_irq_enable();
 		current_thread_info()->status |= TS_POLLING;
 	} else {
 		local_irq_enable();
@@ -196,6 +194,7 @@ void cpu_idle(void)
 			if (cpu_is_offline(cpu))
 				play_dead();
 
+			local_irq_disable();
 			__get_cpu_var(irq_stat).idle_timestamp = jiffies;
 			/* Don't trace irqs off for idle */
 			stop_critical_timings();
@@ -245,18 +244,22 @@ void mwait_idle_with_hints(unsigned long
 		__monitor((void *)&current_thread_info()->flags, 0, 0);
 		smp_mb();
 		if (!need_resched())
-			__sti_mwait(ax, cx);
-		else
-			local_irq_enable();
-	} else
-		local_irq_enable();
+			__mwait(ax, cx);
+	}
 }
 
 /* Default MONITOR/MWAIT with no hints, used for default C1 state */
 static void mwait_idle(void)
 {
-	local_irq_enable();
-	mwait_idle_with_hints(0, 0);
+	if (!need_resched()) {
+		__monitor((void *)&current_thread_info()->flags, 0, 0);
+		smp_mb();
+		if (!need_resched())
+			__sti_mwait(0, 0);
+		else
+			local_irq_enable();
+	} else
+		local_irq_enable();
 }
 
 static int __cpuinit mwait_usable(const struct cpuinfo_x86 *c)
arch/x86/kernel/process_64.c +3 -5
@@ -106,12 +106,10 @@ void default_idle(void)
 	 * test NEED_RESCHED:
 	 */
 	smp_mb();
-	local_irq_disable();
-	if (!need_resched()) {
+	if (!need_resched())
 		safe_halt();	/* enables interrupts racelessly */
-		local_irq_disable();
-	}
-	local_irq_enable();
+	else
+		local_irq_enable();
 	current_thread_info()->status |= TS_POLLING;
 }
 
drivers/acpi/processor_idle.c +9 -10
@@ -436,13 +436,12 @@ static void acpi_processor_idle(void)
 
 	cx = pr->power.state;
 	if (!cx || acpi_idle_suspend) {
-		if (pm_idle_save)
-			pm_idle_save();
-		else
+		if (pm_idle_save) {
+			pm_idle_save(); /* enables IRQs */
+		} else {
 			acpi_safe_halt();
-
-		if (irqs_disabled())
 			local_irq_enable();
+		}
 
 		return;
 	}
@@ -538,10 +537,12 @@ static void acpi_processor_idle(void)
 		 * Use the appropriate idle routine, the one that would
 		 * be used without acpi C-states.
 		 */
-		if (pm_idle_save)
-			pm_idle_save();
-		else
+		if (pm_idle_save) {
+			pm_idle_save(); /* enables IRQs */
+		} else {
 			acpi_safe_halt();
+			local_irq_enable();
+		}
 
 		/*
 		 * TBD: Can't get time duration while in C1, as resumes
@@ -552,8 +553,6 @@ static void acpi_processor_idle(void)
 		 *       skew otherwise.
 		 */
 		sleep_ticks = 0xFFFFFFFF;
-		if (irqs_disabled())
-			local_irq_enable();
 
 		break;
 
include/asm-x86/processor.h +1 -0
@@ -726,6 +726,7 @@ static inline void __mwait(unsigned long
 
 static inline void __sti_mwait(unsigned long eax, unsigned long ecx)
 {
+	trace_hardirqs_on();
 	/* "mwait %eax, %ecx;" */
 	asm volatile("sti; .byte 0x0f, 0x01, 0xc9;"
 		     :: "a" (eax), "c" (ecx));