Skip to contentSkip to conversation

x86/nmi: improve NMI watchdog test

PATCH In review David Vrabel 4 participants 20 messages May 14, 2014 – May 15, 2014

lore
Share & tools
lore
#0 lore raw

cover x86/nmi: improve NMI watchdog test

Serial output (usually virtual serial like HP's iLO) occasional stops on the Testing NMI watchdog line. This series should fix this (see patch #2) and cleans-up a few other bits and pieces as well.

David

#11 lore raw

PATCH 3/4 x86/nmi: wait for all CPUs in check_nmi_watchdog()

The counting of a CPUs NMIs in check_nmi_watchdog() is only reliable if all CPUs have been spinning for 5 or more ticks. There may be delays in waking other CPUs from deep power states that can mean that when the counts are checked CPUs haven't run for long enough.

Fix this by waiting for all CPUs to have delayed in wait_for_nmis().

---
 xen/arch/x86/nmi.c |    4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
xen/arch/x86/nmi.c +1 -3
index 07488da..4f330d8 100644
@@ -136,9 +136,7 @@ int __init check_nmi_watchdog (void)
 
     /* Wait for 10 ticks.  Busy-wait on all CPUs: the LAPIC counter that
      * the NMI watchdog uses only runs while the core's not halted */
-    if ( nmi_watchdog == NMI_LOCAL_APIC )
-        smp_call_function(wait_for_nmis, NULL, 0);
-    wait_for_nmis(NULL);
+    on_selected_cpus(&cpu_online_map, wait_for_nmis, NULL, 1);
 
     for_each_online_cpu ( cpu )
     {
Signature · 1 line
1.7.10.4
#1 lore raw

PATCH 1/4 x86/nmi: remove spurious local_irq_enable from check_nmi_watchdog()

In reply to David Vrabel

All callers of check_nmi_watchdog() already have local irqs enabled so remove the unpaired local_irq_enable().

---
 xen/arch/x86/nmi.c |    1 -
 1 file changed, 1 deletion(-)
xen/arch/x86/nmi.c +0 -1
index 526020b..18d3820 100644
@@ -126,7 +126,6 @@ int __init check_nmi_watchdog (void)
 
     for_each_online_cpu ( cpu )
         prev_nmi_count[cpu] = nmi_count(cpu);
-    local_irq_enable();
 
     /* Wait for 10 ticks.  Busy-wait on all CPUs: the LAPIC counter that
      * the NMI watchdog uses only runs while the core's not halted */
Signature · 1 line
1.7.10.4
#6 lore raw

PATCH 2/4 x86/nmi: enable local irqs in wait_for_nmis()

In reply to David Vrabel

wait_for_nmis() runs for 10 ticks with local interrupts disabled, which is quite a long time.

We occasionally see serial output (particularly with virtual serial ports such as HP's iLO) stopping on the "Testing for NMIs" line. We think the long delay in handling the serial interrupt is the cause.

---
 xen/arch/x86/nmi.c |    7 +++++++
 1 file changed, 7 insertions(+)
xen/arch/x86/nmi.c +7 -0
index 18d3820..07488da 100644
@@ -111,7 +111,14 @@ int nmi_active;
 
 static void __init wait_for_nmis(void *p)
 {
+    unsigned long flags;
+
+    local_save_flags(flags);
+    local_irq_enable();
+
     mdelay((10*1000)/nmi_hz); /* wait 10 ticks */
+
+    local_irq_restore(flags);
 }
 
 int __init check_nmi_watchdog (void)
Signature · 1 line
1.7.10.4
#17 lore raw

PATCH 4/4 x86/nmi: be less verbose when testing the NMI watchdog

In reply to David Vrabel

There's no need to print all the CPUs that are ok, only the ones that got stuck.

The resulting output is either:

Testing NMI watchdog on all CPUs: 1 4 6 stuck

or

Testing NMI watchdog on all CPUs: ok

---
 xen/arch/x86/nmi.c |   14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
xen/arch/x86/nmi.c +8 -6
index 4f330d8..84c1a5e 100644
@@ -125,11 +125,12 @@ int __init check_nmi_watchdog (void)
 {
     static unsigned int __initdata prev_nmi_count[NR_CPUS];
     int cpu;
-    
+    bool_t ok = 1;
+
     if ( !nmi_watchdog )
         return 0;
 
-    printk("Testing NMI watchdog --- ");
+    printk("Testing NMI watchdog on all CPUs:");
 
     for_each_online_cpu ( cpu )
         prev_nmi_count[cpu] = nmi_count(cpu);
@@ -141,12 +142,13 @@ int __init check_nmi_watchdog (void)
     for_each_online_cpu ( cpu )
     {
         if ( nmi_count(cpu) - prev_nmi_count[cpu] <= 5 )
-            printk("CPU#%d stuck. ", cpu);
-        else
-            printk("CPU#%d okay. ", cpu);
+        {
+            printk(" %d", cpu);
+            ok = 0;
+        }
     }
 
-    printk("\n");
+    printk(" %s\n", ok ? "ok" : "stuck");
 
     /*
      * Now that we know it works we can reduce NMI frequency to
Signature · 1 line
1.7.10.4
#3 lore raw

Re: [PATCH 1/4] x86/nmi: remove spurious local_irq_enable from check_nmi_watchdog()

In reply to Jan Beulich
Quoted 15 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 14.05.14 at 14:58, <[email protected]> wrote:

All callers of check_nmi_watchdog() already have local irqs enabled so remove the unpaired local_irq_enable().

---
 xen/arch/x86/nmi.c |    1 -
 1 file changed, 1 deletion(-)
xen/arch/x86/nmi.c +0 -0
index 526020b..18d3820 100644
@@ -126,7 +126,6 @@ int __init check_nmi_watchdog (void)
 
Quoted 6 lines

xen/arch/x86/nmi.c int __init check_nmi_watchdog (void) · line 129

Quoted 3 lines
xen/arch/x86/nmi.c +0 -1
     for_each_online_cpu ( cpu )
         prev_nmi_count[cpu] = nmi_count(cpu);
-    local_irq_enable();

I guess this will want to be replaced by a suitable ASSERT(), to make sure eventual new callers adhere to the described rule.

smp_call_function() and on_selected_cpus() which is where this matters already has such an ASSERT() so I don't think another one needs to be added here.

David

#2 lore raw

Re: [PATCH 1/4] x86/nmi: remove spurious local_irq_enable from check_nmi_watchdog()

In reply to David Vrabel
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 14.05.14 at 14:58, <[email protected]> wrote:

All callers of check_nmi_watchdog() already have local irqs enabled so remove the unpaired local_irq_enable().

---
 xen/arch/x86/nmi.c |    1 -
 1 file changed, 1 deletion(-)
xen/arch/x86/nmi.c +0 -0
index 526020b..18d3820 100644

xen/arch/x86/nmi.c int __init check_nmi_watchdog (void) · line 129

Quoted 4 lines
xen/arch/x86/nmi.c +0 -1
@@ -126,7 +126,6 @@ int __init check_nmi_watchdog (void)
 
     for_each_online_cpu ( cpu )
         prev_nmi_count[cpu] = nmi_count(cpu);
-    local_irq_enable();

I guess this will want to be replaced by a suitable ASSERT(), to make sure eventual new callers adhere to the described rule.

Jan

#4 lore raw

Re: [PATCH 1/4] x86/nmi: remove spurious local_irq_enable from check_nmi_watchdog()

In reply to David Vrabel
Quoted 24 lines
Quoted 1 line
Quoted 1 line · On 14.05.14 at 15:31, <[email protected]> wrote:
Quoted 15 lines · Jan Beulich
Quoted 15 lines
Quoted 1 line
Quoted 1 line · On 14.05.14 at 14:58, <[email protected]> wrote:

All callers of check_nmi_watchdog() already have local irqs enabled so remove the unpaired local_irq_enable().

---
 xen/arch/x86/nmi.c |    1 -
 1 file changed, 1 deletion(-)
xen/arch/x86/nmi.c +0 -0
index 526020b..18d3820 100644
@@ -126,7 +126,6 @@ int __init check_nmi_watchdog (void)
 
Quoted 6 lines

xen/arch/x86/nmi.c int __init check_nmi_watchdog (void) · line 129

Quoted 3 lines
xen/arch/x86/nmi.c +0 -1
     for_each_online_cpu ( cpu )
         prev_nmi_count[cpu] = nmi_count(cpu);
-    local_irq_enable();

I guess this will want to be replaced by a suitable ASSERT(), to make sure eventual new callers adhere to the described rule.

Quoted 3 lines

smp_call_function() and on_selected_cpus() which is where this matters already has such an ASSERT() so I don't think another one needs to be added here.

Okay, that's true.

Jan

#7 lore raw

Re: [PATCH 2/4] x86/nmi: enable local irqs in wait_for_nmis()

In reply to David Vrabel
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 14.05.14 at 14:58, <[email protected]> wrote:
xen/arch/x86/nmi.c +0 -0
@@ -111,7 +111,14 @@ int nmi_active;
 
 static void __init wait_for_nmis(void *p)

xen/arch/x86/nmi.c int nmi_active; · line 122

Quoted 10 lines
xen/arch/x86/nmi.c +7 -0
 {
+    unsigned long flags;
+
+    local_save_flags(flags);
+    local_irq_enable();
+
     mdelay((10*1000)/nmi_hz); /* wait 10 ticks */
+
+    local_irq_restore(flags);
 }

This being the callback for on_selected_cpus(), i.e. called out of interrupt context, I don't think it is uniformly safe to enable interrupts here. The current behavior anyway is for the function to run with interrupts enabled on the boot CPU, and with interrupts disabled on the APs. So for this change to make a difference, the IRQ would need to be bound to one of the APs, and consequently the fix would be to force it onto the BP until boot progressed far enough.

Jan

#12 lore raw

Re: [PATCH 3/4] x86/nmi: wait for all CPUs in check_nmi_watchdog()

In reply to David Vrabel
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 14.05.14 at 14:58, <[email protected]> wrote:

The counting of a CPUs NMIs in check_nmi_watchdog() is only reliable if all CPUs have been spinning for 5 or more ticks. There may be delays in waking other CPUs from deep power states that can mean that when the counts are checked CPUs haven't run for long enough.

5 ticks ought to be a couple of orders of a magnitude longer than the worst possible wakeup time. I.e. I don't buy this argument without actual numbers to support it.

Jan

#13 lore raw

Re: [PATCH 3/4] x86/nmi: wait for all CPUs in check_nmi_watchdog()

Quoted 9 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 14.05.14 at 14:58, <[email protected]> wrote:

The counting of a CPUs NMIs in check_nmi_watchdog() is only reliable if all CPUs have been spinning for 5 or more ticks. There may be delays in waking other CPUs from deep power states that can mean that when the counts are checked CPUs haven't run for long enough.

5 ticks ought to be a couple of orders of a magnitude longer than the worst possible wakeup time. I.e. I don't buy this argument without actual numbers to support it.

This was a change Andrew asked for and the reasoning he used, but I agree that it seems highly implausible.

I think this is a worthwhile cleanup anyway so you can apply with the below commit message or drop it (your preference).

David

8<-------
x86/nmi: wait for all CPUs in check_nmi_watchdog()

The counting of a CPUs NMIs in check_nmi_watchdog() is only reliable if all CPUs have been spinning for 5 or more ticks. Whilst its highly implausible that this won't happen in practise, explicitly wait so it's clear that this is required.

#15 lore raw

Re: [PATCH 3/4] x86/nmi: wait for all CPUs in check_nmi_watchdog()

In reply to Jan Beulich
Quoted 10 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 14.05.14 at 14:58, <[email protected]> wrote:

The counting of a CPUs NMIs in check_nmi_watchdog() is only reliable if all CPUs have been spinning for 5 or more ticks. There may be delays in waking other CPUs from deep power states that can mean that when the counts are checked CPUs haven't run for long enough.

5 ticks ought to be a couple of orders of a magnitude longer than the worst possible wakeup time. I.e. I don't buy this argument without actual numbers to support it.

Jan

Its not necesserily the wakeup time, although on some systems that does appear to be a consideration. Simple A

We have a prototype 8 socket system where the cpus on the further sockets had progressively less nmi delta, and are mostly declared stuck as the BSP reads the delta before the APs have completed their busy loop.

~Andrew

#14 lore raw

Re: [PATCH 3/4] x86/nmi: wait for all CPUs in check_nmi_watchdog()

In reply to David Vrabel
Quoted 7 lines
Quoted 1 line
Quoted 1 line · On 14.05.14 at 16:09, <[email protected]> wrote:

x86/nmi: wait for all CPUs in check_nmi_watchdog()

The counting of a CPUs NMIs in check_nmi_watchdog() is only reliable if all CPUs have been spinning for 5 or more ticks. Whilst its highly implausible that this won't happen in practise, explicitly wait so it's clear that this is required.

The thing is that I actually consider the early continuation to be desirable - there's no need for the BP to actually wait for the APs to finish their wait loop, as long as they progressed far enough into it. If you added a flag telling the others to bail as soon as the master exited its waiting, that would look more acceptable to me.

Agreed we're not talking about big time differences here, but we shouldn't be making booting slower than it needs to be. Btw., did you check how modern Linux deals with the same issue (last I looked was many releases ago)?

Jan

#8 lore raw

Re: [PATCH 2/4] x86/nmi: enable local irqs in wait_for_nmis()

In reply to Jan Beulich
Quoted 17 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 14.05.14 at 14:58, <[email protected]> wrote:
xen/arch/x86/nmi.c +0 -0
@@ -111,7 +111,14 @@ int nmi_active;
 
 static void __init wait_for_nmis(void *p)

xen/arch/x86/nmi.c int nmi_active; · line 122

Quoted 10 lines
xen/arch/x86/nmi.c +7 -0
 {
+    unsigned long flags;
+
+    local_save_flags(flags);
+    local_irq_enable();
+
     mdelay((10*1000)/nmi_hz); /* wait 10 ticks */
+
+    local_irq_restore(flags);
 }
Quoted 8 lines

This being the callback for on_selected_cpus(), i.e. called out of interrupt context, I don't think it is uniformly safe to enable interrupts here. The current behavior anyway is for the function to run with interrupts enabled on the boot CPU, and with interrupts disabled on the APs. So for this change to make a difference, the IRQ would need to be bound to one of the APs, and consequently the fix would be to force it onto the BP until boot progressed far enough.

The call function IPIs are handled with a direct apic vector so skip the normal interrupt enabling path for irqs. I can't see anywhere where irqs are enabled in call_function_interrupt() (x86) and smp_call_function_interrupt() (common).

David

#9 lore raw

Re: [PATCH 2/4] x86/nmi: enable local irqs in wait_for_nmis()

Quoted 28 lines
Quoted 1 line
Quoted 1 line · On 14.05.14 at 16:38, <[email protected]> wrote:
Quoted 17 lines · Jan Beulich
Quoted 6 lines
Quoted 1 line
Quoted 1 line · On 14.05.14 at 14:58, <[email protected]> wrote:
xen/arch/x86/nmi.c +0 -0
@@ -111,7 +111,14 @@ int nmi_active;
 
 static void __init wait_for_nmis(void *p)

xen/arch/x86/nmi.c int nmi_active; · line 122

Quoted 10 lines
xen/arch/x86/nmi.c +7 -0
 {
+    unsigned long flags;
+
+    local_save_flags(flags);
+    local_irq_enable();
+
     mdelay((10*1000)/nmi_hz); /* wait 10 ticks */
+
+    local_irq_restore(flags);
 }
Quoted 8 lines

This being the callback for on_selected_cpus(), i.e. called out of interrupt context, I don't think it is uniformly safe to enable interrupts here. The current behavior anyway is for the function to run with interrupts enabled on the boot CPU, and with interrupts disabled on the APs. So for this change to make a difference, the IRQ would need to be bound to one of the APs, and consequently the fix would be to force it onto the BP until boot progressed far enough.

Quoted 4 lines

The call function IPIs are handled with a direct apic vector so skip the normal interrupt enabling path for irqs. I can't see anywhere where irqs are enabled in call_function_interrupt() (x86) and smp_call_function_interrupt() (common).

Exactly, they aren't, because it's not generally safe to do so. And if the generic code doesn't do so, you'll need a rather good reason to do this manually.

Jan

Reviewed-by on v1 3/4
#16 lore raw

Re: [PATCH 3/4] x86/nmi: wait for all CPUs in check_nmi_watchdog()

In reply to David Vrabel
Quoted 8 lines · David Vrabel

The counting of a CPUs NMIs in check_nmi_watchdog() is only reliable if all CPUs have been spinning for 5 or more ticks. There may be delays in waking other CPUs from deep power states that can mean that when the counts are checked CPUs haven't run for long enough.

Fix this by waiting for all CPUs to have delayed in wait_for_nmis().

I think we could separately address the boot time issue by having wait_for_nmis() exit after it's seen 5 NMIs _or_ counted 10 ticks.

Tim.

#10 lore raw

Re: [PATCH 2/4] x86/nmi: enable local irqs in wait_for_nmis()

In reply to Jan Beulich
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 14.05.14 at 14:58, <[email protected]> wrote:
xen/arch/x86/nmi.c +0 -0
@@ -111,7 +111,14 @@ int nmi_active;
 
Quoted 15 lines

xen/arch/x86/nmi.c int nmi_active; · line 122

Quoted 11 lines
xen/arch/x86/nmi.c +7 -0
 static void __init wait_for_nmis(void *p)
 {
+    unsigned long flags;
+
+    local_save_flags(flags);
+    local_irq_enable();
+
     mdelay((10*1000)/nmi_hz); /* wait 10 ticks */
+
+    local_irq_restore(flags);
 }

This being the callback for on_selected_cpus(), i.e. called out of interrupt context, I don't think it is uniformly safe to enable interrupts here.

Yes, I think if you really need this (and I don't see what the problem is with serial interrupts being delayed as long as they're not lost), you'll have to use some sort of softirq context to do this spinning.

Tim.