x86: clean up nmi_32/64.c

clean up and make nmi_32/64.c more similar.
- white space and coding style clean up.
- nmi_cpu_busy is available on CONFIG_SMP.
- move functions __acpi_nmi_enable, acpi_nmi_enable,
  __acpi_nmi_disable and acpi_nmi_disable.
- make variables name more similar.

Signed-off-by: Hiroshi Shimamoto <h-shimamoto@ct.jp.nec.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
This commit is contained in:
Hiroshi Shimamoto 2008-01-30 13:30:33 +01:00 committed by Ingo Molnar
parent 6ea8bad1c0
commit 416b72182a
2 changed files with 55 additions and 54 deletions

View File

@ -51,13 +51,13 @@ static int unknown_nmi_panic_callback(struct pt_regs *regs, int cpu);
static int endflag __initdata = 0; static int endflag __initdata = 0;
#ifdef CONFIG_SMP
/* The performance counters used by NMI_LOCAL_APIC don't trigger when /* The performance counters used by NMI_LOCAL_APIC don't trigger when
* the CPU is idle. To make sure the NMI watchdog really ticks on all * the CPU is idle. To make sure the NMI watchdog really ticks on all
* CPUs during the test make them busy. * CPUs during the test make them busy.
*/ */
static __init void nmi_cpu_busy(void *data) static __init void nmi_cpu_busy(void *data)
{ {
#ifdef CONFIG_SMP
local_irq_enable_in_hardirq(); local_irq_enable_in_hardirq();
/* Intentionally don't use cpu_relax here. This is /* Intentionally don't use cpu_relax here. This is
to make sure that the performance counter really ticks, to make sure that the performance counter really ticks,
@ -67,8 +67,8 @@ static __init void nmi_cpu_busy(void *data)
care if they get somewhat less cycles. */ care if they get somewhat less cycles. */
while (endflag == 0) while (endflag == 0)
mb(); mb();
#endif
} }
#endif
static int __init check_nmi_watchdog(void) static int __init check_nmi_watchdog(void)
{ {
@ -87,11 +87,13 @@ static int __init check_nmi_watchdog(void)
printk(KERN_INFO "Testing NMI watchdog ... "); printk(KERN_INFO "Testing NMI watchdog ... ");
#ifdef CONFIG_SMP
if (nmi_watchdog == NMI_LOCAL_APIC) if (nmi_watchdog == NMI_LOCAL_APIC)
smp_call_function(nmi_cpu_busy, (void *)&endflag, 0, 0); smp_call_function(nmi_cpu_busy, (void *)&endflag, 0, 0);
#endif
for_each_possible_cpu(cpu) for_each_possible_cpu(cpu)
prev_nmi_count[cpu] = per_cpu(irq_stat, cpu).__nmi_count; prev_nmi_count[cpu] = nmi_count(cpu);
local_irq_enable(); local_irq_enable();
mdelay((20*1000)/nmi_hz); // wait 20 ticks mdelay((20*1000)/nmi_hz); // wait 20 ticks

View File

@ -80,7 +80,7 @@ static __init void nmi_cpu_busy(void *data)
int __init check_nmi_watchdog(void) int __init check_nmi_watchdog(void)
{ {
int *counts; int *prev_nmi_count;
int cpu; int cpu;
if ((nmi_watchdog == NMI_NONE) || (nmi_watchdog == NMI_DISABLED)) if ((nmi_watchdog == NMI_NONE) || (nmi_watchdog == NMI_DISABLED))
@ -89,11 +89,11 @@ int __init check_nmi_watchdog (void)
if (!atomic_read(&nmi_active)) if (!atomic_read(&nmi_active))
return 0; return 0;
counts = kmalloc(NR_CPUS * sizeof(int), GFP_KERNEL); prev_nmi_count = kmalloc(NR_CPUS * sizeof(int), GFP_KERNEL);
if (!counts) if (!prev_nmi_count)
return -1; return -1;
printk(KERN_INFO "testing NMI watchdog ... "); printk(KERN_INFO "Testing NMI watchdog ... ");
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
if (nmi_watchdog == NMI_LOCAL_APIC) if (nmi_watchdog == NMI_LOCAL_APIC)
@ -101,30 +101,29 @@ int __init check_nmi_watchdog (void)
#endif #endif
for (cpu = 0; cpu < NR_CPUS; cpu++) for (cpu = 0; cpu < NR_CPUS; cpu++)
counts[cpu] = cpu_pda(cpu)->__nmi_count; prev_nmi_count[cpu] = cpu_pda(cpu)->__nmi_count;
local_irq_enable(); local_irq_enable();
mdelay((20*1000)/nmi_hz); // wait 20 ticks mdelay((20*1000)/nmi_hz); // wait 20 ticks
for_each_online_cpu(cpu) { for_each_online_cpu(cpu) {
if (!per_cpu(wd_enabled, cpu)) if (!per_cpu(wd_enabled, cpu))
continue; continue;
if (cpu_pda(cpu)->__nmi_count - counts[cpu] <= 5) { if (cpu_pda(cpu)->__nmi_count - prev_nmi_count[cpu] <= 5) {
printk(KERN_WARNING "WARNING: CPU#%d: NMI " printk(KERN_WARNING "WARNING: CPU#%d: NMI "
"appears to be stuck (%d->%d)!\n", "appears to be stuck (%d->%d)!\n",
cpu, cpu,
counts[cpu], prev_nmi_count[cpu],
cpu_pda(cpu)->__nmi_count); cpu_pda(cpu)->__nmi_count);
per_cpu(wd_enabled, cpu) = 0; per_cpu(wd_enabled, cpu) = 0;
atomic_dec(&nmi_active); atomic_dec(&nmi_active);
} }
} }
if (!atomic_read(&nmi_active)) {
kfree(counts);
atomic_set(&nmi_active, -1);
endflag = 1; endflag = 1;
if (!atomic_read(&nmi_active)) {
kfree(prev_nmi_count);
atomic_set(&nmi_active, -1);
return -1; return -1;
} }
endflag = 1;
printk("OK.\n"); printk("OK.\n");
/* now that we know it works we can reduce NMI frequency to /* now that we know it works we can reduce NMI frequency to
@ -132,7 +131,7 @@ int __init check_nmi_watchdog (void)
if (nmi_watchdog == NMI_LOCAL_APIC) if (nmi_watchdog == NMI_LOCAL_APIC)
nmi_hz = lapic_adjust_nmi_hz(1); nmi_hz = lapic_adjust_nmi_hz(1);
kfree(counts); kfree(prev_nmi_count);
return 0; return 0;
} }
@ -159,34 +158,6 @@ static int __init setup_nmi_watchdog(char *str)
__setup("nmi_watchdog=", setup_nmi_watchdog); __setup("nmi_watchdog=", setup_nmi_watchdog);
static void __acpi_nmi_disable(void *__unused)
{
apic_write(APIC_LVT0, APIC_DM_NMI | APIC_LVT_MASKED);
}
/*
* Disable timer based NMIs on all CPUs:
*/
void acpi_nmi_disable(void)
{
if (atomic_read(&nmi_active) && nmi_watchdog == NMI_IO_APIC)
on_each_cpu(__acpi_nmi_disable, NULL, 0, 1);
}
static void __acpi_nmi_enable(void *__unused)
{
apic_write(APIC_LVT0, APIC_DM_NMI);
}
/*
* Enable timer based NMIs on all CPUs:
*/
void acpi_nmi_enable(void)
{
if (atomic_read(&nmi_active) && nmi_watchdog == NMI_IO_APIC)
on_each_cpu(__acpi_nmi_enable, NULL, 0, 1);
}
#ifdef CONFIG_PM #ifdef CONFIG_PM
static int nmi_pm_active; /* nmi_active before suspend */ static int nmi_pm_active; /* nmi_active before suspend */
@ -244,9 +215,37 @@ late_initcall(init_lapic_nmi_sysfs);
#endif /* CONFIG_PM */ #endif /* CONFIG_PM */
static void __acpi_nmi_enable(void *__unused)
{
apic_write(APIC_LVT0, APIC_DM_NMI);
}
/*
* Enable timer based NMIs on all CPUs:
*/
void acpi_nmi_enable(void)
{
if (atomic_read(&nmi_active) && nmi_watchdog == NMI_IO_APIC)
on_each_cpu(__acpi_nmi_enable, NULL, 0, 1);
}
static void __acpi_nmi_disable(void *__unused)
{
apic_write(APIC_LVT0, APIC_DM_NMI | APIC_LVT_MASKED);
}
/*
* Disable timer based NMIs on all CPUs:
*/
void acpi_nmi_disable(void)
{
if (atomic_read(&nmi_active) && nmi_watchdog == NMI_IO_APIC)
on_each_cpu(__acpi_nmi_disable, NULL, 0, 1);
}
void setup_apic_nmi_watchdog(void *unused) void setup_apic_nmi_watchdog(void *unused)
{ {
if (__get_cpu_var(wd_enabled) == 1) if (__get_cpu_var(wd_enabled))
return; return;
/* cheap hack to support suspend/resume */ /* cheap hack to support suspend/resume */
@ -313,6 +312,7 @@ void touch_nmi_watchdog(void)
touch_softlockup_watchdog(); touch_softlockup_watchdog();
} }
EXPORT_SYMBOL(touch_nmi_watchdog);
int __kprobes nmi_watchdog_tick(struct pt_regs * regs, unsigned reason) int __kprobes nmi_watchdog_tick(struct pt_regs * regs, unsigned reason)
{ {
@ -479,4 +479,3 @@ void __trigger_all_cpu_backtrace(void)
EXPORT_SYMBOL(nmi_active); EXPORT_SYMBOL(nmi_active);
EXPORT_SYMBOL(nmi_watchdog); EXPORT_SYMBOL(nmi_watchdog);
EXPORT_SYMBOL(touch_nmi_watchdog);