Commit 438612ea authored by John Levon's avatar John Levon Committed by Linus Torvalds

[PATCH] OProfile: IO-APIC based NMI delivery

Use the IO-APIC NMI delivery when the local APIC performance counter delivery is
not available. By Zwane Mwaikambo.
parent 991cae79
......@@ -23,17 +23,27 @@
#include <linux/mc146818rtc.h>
#include <linux/kernel_stat.h>
#include <linux/module.h>
#include <linux/nmi.h>
#include <linux/sysdev.h>
#include <asm/smp.h>
#include <asm/mtrr.h>
#include <asm/mpspec.h>
#include <asm/nmi.h>
unsigned int nmi_watchdog = NMI_NONE;
static unsigned int nmi_hz = HZ;
unsigned int nmi_perfctr_msr; /* the MSR to reset in NMI handler */
extern void show_registers(struct pt_regs *regs);
/* nmi_active:
* +1: the lapic NMI watchdog is active, but can be disabled
* 0: the lapic NMI watchdog has not been set up, and cannot
* be enabled
* -1: the lapic NMI watchdog is disabled, but can be enabled
*/
static int nmi_active;
#define K7_EVNTSEL_ENABLE (1 << 22)
#define K7_EVNTSEL_INT (1 << 20)
#define K7_EVNTSEL_OS (1 << 17)
......@@ -91,6 +101,7 @@ int __init check_nmi_watchdog (void)
continue;
if (nmi_count(cpu) - prev_nmi_count[cpu] <= 5) {
printk("CPU#%d: NMI appears to be stuck!\n", cpu);
nmi_active = 0;
return -1;
}
}
......@@ -131,21 +142,15 @@ static int __init setup_nmi_watchdog(char *str)
* We can enable the IO-APIC watchdog
* unconditionally.
*/
if (nmi == NMI_IO_APIC)
if (nmi == NMI_IO_APIC) {
nmi_active = 1;
nmi_watchdog = nmi;
}
return 1;
}
__setup("nmi_watchdog=", setup_nmi_watchdog);
/* nmi_active:
* +1: the lapic NMI watchdog is active, but can be disabled
* 0: the lapic NMI watchdog has not been set up, and cannot
* be enabled
* -1: the lapic NMI watchdog is disabled, but can be enabled
*/
static int nmi_active;
void disable_lapic_nmi_watchdog(void)
{
if (nmi_active <= 0)
......@@ -179,6 +184,27 @@ void enable_lapic_nmi_watchdog(void)
}
}
void disable_timer_nmi_watchdog(void)
{
if ((nmi_watchdog != NMI_IO_APIC) || (nmi_active <= 0))
return;
disable_irq(0);
unset_nmi_callback();
nmi_active = -1;
nmi_watchdog = NMI_NONE;
}
void enable_timer_nmi_watchdog(void)
{
if (nmi_active < 0) {
nmi_watchdog = NMI_IO_APIC;
touch_nmi_watchdog();
nmi_active = 1;
enable_irq(0);
}
}
#ifdef CONFIG_PM
static int nmi_pm_active; /* nmi_active before suspend */
......@@ -429,3 +455,5 @@ void nmi_watchdog_tick (struct pt_regs * regs)
EXPORT_SYMBOL(nmi_watchdog);
EXPORT_SYMBOL(disable_lapic_nmi_watchdog);
EXPORT_SYMBOL(enable_lapic_nmi_watchdog);
EXPORT_SYMBOL(disable_timer_nmi_watchdog);
EXPORT_SYMBOL(enable_timer_nmi_watchdog);
......@@ -9,3 +9,4 @@ DRIVER_OBJS = $(addprefix ../../../drivers/oprofile/, \
oprofile-y := $(DRIVER_OBJS) init.o
oprofile-$(CONFIG_X86_LOCAL_APIC) += nmi_int.o op_model_athlon.o \
op_model_ppro.o op_model_p4.o
oprofile-$(CONFIG_X86_IO_APIC) += nmi_timer_int.o
......@@ -16,15 +16,21 @@
*/
extern int nmi_init(struct oprofile_operations ** ops);
extern int nmi_timer_init(struct oprofile_operations **ops);
extern void nmi_exit(void);
int __init oprofile_arch_init(struct oprofile_operations ** ops)
{
int ret = -ENODEV;
#ifdef CONFIG_X86_LOCAL_APIC
return nmi_init(ops);
#else
return -ENODEV;
ret = nmi_init(ops);
#endif
#ifdef CONFIG_X86_IO_APIC
if (ret < 0)
ret = nmi_timer_init(ops);
#endif
return ret;
}
......
/**
* @file nmi_timer_int.c
*
* @remark Copyright 2003 OProfile authors
* @remark Read the file COPYING
*
* @author Zwane Mwaikambo <zwane@linuxpower.ca>
*/
#include <linux/init.h>
#include <linux/smp.h>
#include <linux/irq.h>
#include <linux/oprofile.h>
#include <linux/rcupdate.h>
#include <asm/nmi.h>
#include <asm/apic.h>
#include <asm/ptrace.h>
static int nmi_timer_callback(struct pt_regs * regs, int cpu)
{
unsigned long eip = instruction_pointer(regs);
oprofile_add_sample(eip, !user_mode(regs), 0, cpu);
return 1;
}
static int timer_start(void)
{
disable_timer_nmi_watchdog();
set_nmi_callback(nmi_timer_callback);
return 0;
}
static void timer_stop(void)
{
enable_timer_nmi_watchdog();
unset_nmi_callback();
synchronize_kernel();
}
static struct oprofile_operations nmi_timer_ops = {
.start = timer_start,
.stop = timer_stop,
.cpu_type = "timer"
};
int __init nmi_timer_init(struct oprofile_operations ** ops)
{
*ops = &nmi_timer_ops;
printk(KERN_INFO "oprofile: using NMI timer interrupt.\n");
return 0;
}
......@@ -81,6 +81,8 @@ extern void setup_secondary_APIC_clock (void);
extern void setup_apic_nmi_watchdog (void);
extern void disable_lapic_nmi_watchdog(void);
extern void enable_lapic_nmi_watchdog(void);
extern void disable_timer_nmi_watchdog(void);
extern void enable_timer_nmi_watchdog(void);
extern inline void nmi_watchdog_tick (struct pt_regs * regs);
extern int APIC_init_uniprocessor (void);
extern void disable_APIC_timer(void);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment