2009-01-30 13:22:47 +08:00
|
|
|
/* Pseudo NMI support on sparc64 systems.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 David S. Miller <davem@davemloft.net>
|
|
|
|
*
|
|
|
|
* The NMI watchdog support and infrastructure is based almost
|
|
|
|
* entirely upon the x86 NMI support code.
|
|
|
|
*/
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/param.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/percpu.h>
|
|
|
|
#include <linux/nmi.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kprobes.h>
|
|
|
|
#include <linux/kernel_stat.h>
|
2009-03-30 06:40:33 +08:00
|
|
|
#include <linux/reboot.h>
|
2009-01-30 13:22:47 +08:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/kdebug.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/smp.h>
|
|
|
|
|
perf: Do the big rename: Performance Counters -> Performance Events
Bye-bye Performance Counters, welcome Performance Events!
In the past few months the perfcounters subsystem has grown out its
initial role of counting hardware events, and has become (and is
becoming) a much broader generic event enumeration, reporting, logging,
monitoring, analysis facility.
Naming its core object 'perf_counter' and naming the subsystem
'perfcounters' has become more and more of a misnomer. With pending
code like hw-breakpoints support the 'counter' name is less and
less appropriate.
All in one, we've decided to rename the subsystem to 'performance
events' and to propagate this rename through all fields, variables
and API names. (in an ABI compatible fashion)
The word 'event' is also a bit shorter than 'counter' - which makes
it slightly more convenient to write/handle as well.
Thanks goes to Stephane Eranian who first observed this misnomer and
suggested a rename.
User-space tooling and ABI compatibility is not affected - this patch
should be function-invariant. (Also, defconfigs were not touched to
keep the size down.)
This patch has been generated via the following script:
FILES=$(find * -type f | grep -vE 'oprofile|[^K]config')
sed -i \
-e 's/PERF_EVENT_/PERF_RECORD_/g' \
-e 's/PERF_COUNTER/PERF_EVENT/g' \
-e 's/perf_counter/perf_event/g' \
-e 's/nb_counters/nb_events/g' \
-e 's/swcounter/swevent/g' \
-e 's/tpcounter_event/tp_event/g' \
$FILES
for N in $(find . -name perf_counter.[ch]); do
M=$(echo $N | sed 's/perf_counter/perf_event/g')
mv $N $M
done
FILES=$(find . -name perf_event.*)
sed -i \
-e 's/COUNTER_MASK/REG_MASK/g' \
-e 's/COUNTER/EVENT/g' \
-e 's/\<event\>/event_id/g' \
-e 's/counter/event/g' \
-e 's/Counter/Event/g' \
$FILES
... to keep it as correct as possible. This script can also be
used by anyone who has pending perfcounters patches - it converts
a Linux kernel tree over to the new naming. We tried to time this
change to the point in time where the amount of pending patches
is the smallest: the end of the merge window.
Namespace clashes were fixed up in a preparatory patch - and some
stylistic fallout will be fixed up in a subsequent patch.
( NOTE: 'counters' are still the proper terminology when we deal
with hardware registers - and these sed scripts are a bit
over-eager in renaming them. I've undone some of that, but
in case there's something left where 'counter' would be
better than 'event' we can undo that on an individual basis
instead of touching an otherwise nicely automated patch. )
Suggested-by: Stephane Eranian <eranian@google.com>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: Paul Mackerras <paulus@samba.org>
Reviewed-by: Arjan van de Ven <arjan@linux.intel.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: David Howells <dhowells@redhat.com>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: <linux-arch@vger.kernel.org>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-09-21 18:02:48 +08:00
|
|
|
#include <asm/perf_event.h>
|
2009-01-30 13:22:47 +08:00
|
|
|
#include <asm/ptrace.h>
|
|
|
|
#include <asm/pcr.h>
|
|
|
|
|
|
|
|
/* We don't have a real NMI on sparc64, but we can fake one
|
|
|
|
* up using profiling counter overflow interrupts and interrupt
|
|
|
|
* levels.
|
|
|
|
*
|
|
|
|
* The profile overflow interrupts at level 15, so we use
|
|
|
|
* level 14 as our IRQ off level.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int panic_on_timeout;
|
|
|
|
|
2009-09-09 14:16:06 +08:00
|
|
|
/* nmi_active:
|
|
|
|
* >0: the NMI watchdog is active, but can be disabled
|
|
|
|
* <0: the NMI watchdog has not been set up, and cannot be enabled
|
|
|
|
* 0: the NMI watchdog is disabled, but can be enabled
|
|
|
|
*/
|
|
|
|
atomic_t nmi_active = ATOMIC_INIT(0); /* oprofile uses this */
|
|
|
|
EXPORT_SYMBOL(nmi_active);
|
2009-01-30 13:22:47 +08:00
|
|
|
|
|
|
|
static unsigned int nmi_hz = HZ;
|
2009-09-09 14:16:06 +08:00
|
|
|
static DEFINE_PER_CPU(short, wd_enabled);
|
|
|
|
static int endflag __initdata;
|
2009-01-30 13:22:47 +08:00
|
|
|
|
|
|
|
static DEFINE_PER_CPU(unsigned int, last_irq_sum);
|
2009-10-08 07:04:29 +08:00
|
|
|
static DEFINE_PER_CPU(long, alert_counter);
|
2009-01-30 13:22:47 +08:00
|
|
|
static DEFINE_PER_CPU(int, nmi_touch);
|
|
|
|
|
|
|
|
void touch_nmi_watchdog(void)
|
|
|
|
{
|
2009-09-09 14:29:16 +08:00
|
|
|
if (atomic_read(&nmi_active)) {
|
2009-01-30 13:22:47 +08:00
|
|
|
int cpu;
|
|
|
|
|
|
|
|
for_each_present_cpu(cpu) {
|
|
|
|
if (per_cpu(nmi_touch, cpu) != 1)
|
|
|
|
per_cpu(nmi_touch, cpu) = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
touch_softlockup_watchdog();
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(touch_nmi_watchdog);
|
|
|
|
|
|
|
|
static void die_nmi(const char *str, struct pt_regs *regs, int do_panic)
|
|
|
|
{
|
|
|
|
if (notify_die(DIE_NMIWATCHDOG, str, regs, 0,
|
|
|
|
pt_regs_trap_type(regs), SIGINT) == NOTIFY_STOP)
|
|
|
|
return;
|
|
|
|
|
|
|
|
console_verbose();
|
|
|
|
bust_spinlocks(1);
|
|
|
|
|
|
|
|
printk(KERN_EMERG "%s", str);
|
|
|
|
printk(" on CPU%d, ip %08lx, registers:\n",
|
|
|
|
smp_processor_id(), regs->tpc);
|
|
|
|
show_regs(regs);
|
2009-02-05 05:48:11 +08:00
|
|
|
dump_stack();
|
2009-01-30 13:22:47 +08:00
|
|
|
|
|
|
|
bust_spinlocks(0);
|
|
|
|
|
|
|
|
if (do_panic || panic_on_oops)
|
|
|
|
panic("Non maskable interrupt");
|
|
|
|
|
2009-09-10 20:56:16 +08:00
|
|
|
nmi_exit();
|
2009-01-30 13:22:47 +08:00
|
|
|
local_irq_enable();
|
|
|
|
do_exit(SIGBUS);
|
|
|
|
}
|
|
|
|
|
|
|
|
notrace __kprobes void perfctr_irq(int irq, struct pt_regs *regs)
|
|
|
|
{
|
|
|
|
unsigned int sum, touched = 0;
|
|
|
|
int cpu = smp_processor_id();
|
|
|
|
|
|
|
|
clear_softint(1 << irq);
|
|
|
|
|
|
|
|
local_cpu_data().__nmi_count++;
|
|
|
|
|
2009-09-10 20:56:16 +08:00
|
|
|
nmi_enter();
|
|
|
|
|
2009-01-30 13:22:47 +08:00
|
|
|
if (notify_die(DIE_NMI, "nmi", regs, 0,
|
|
|
|
pt_regs_trap_type(regs), SIGINT) == NOTIFY_STOP)
|
|
|
|
touched = 1;
|
2010-01-05 07:37:04 +08:00
|
|
|
else
|
|
|
|
pcr_ops->write(PCR_PIC_PRIV);
|
2009-01-30 13:22:47 +08:00
|
|
|
|
2009-02-03 14:14:28 +08:00
|
|
|
sum = kstat_irqs_cpu(0, cpu);
|
2009-01-30 13:22:47 +08:00
|
|
|
if (__get_cpu_var(nmi_touch)) {
|
|
|
|
__get_cpu_var(nmi_touch) = 0;
|
|
|
|
touched = 1;
|
|
|
|
}
|
|
|
|
if (!touched && __get_cpu_var(last_irq_sum) == sum) {
|
2009-10-29 21:34:15 +08:00
|
|
|
__this_cpu_inc(alert_counter);
|
|
|
|
if (__this_cpu_read(alert_counter) == 30 * nmi_hz)
|
2009-01-30 13:22:47 +08:00
|
|
|
die_nmi("BUG: NMI Watchdog detected LOCKUP",
|
|
|
|
regs, panic_on_timeout);
|
|
|
|
} else {
|
|
|
|
__get_cpu_var(last_irq_sum) = sum;
|
2009-10-29 21:34:15 +08:00
|
|
|
__this_cpu_write(alert_counter, 0);
|
2009-01-30 13:22:47 +08:00
|
|
|
}
|
2009-09-09 14:16:06 +08:00
|
|
|
if (__get_cpu_var(wd_enabled)) {
|
2009-01-30 13:22:47 +08:00
|
|
|
write_pic(picl_value(nmi_hz));
|
|
|
|
pcr_ops->write(pcr_enable);
|
|
|
|
}
|
2009-09-10 20:56:16 +08:00
|
|
|
|
|
|
|
nmi_exit();
|
2009-01-30 13:22:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int get_nmi_count(int cpu)
|
|
|
|
{
|
|
|
|
return cpu_data(cpu).__nmi_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __init void nmi_cpu_busy(void *data)
|
|
|
|
{
|
|
|
|
local_irq_enable_in_hardirq();
|
|
|
|
while (endflag == 0)
|
|
|
|
mb();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void report_broken_nmi(int cpu, int *prev_nmi_count)
|
|
|
|
{
|
|
|
|
printk(KERN_CONT "\n");
|
|
|
|
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"WARNING: CPU#%d: NMI appears to be stuck (%d->%d)!\n",
|
|
|
|
cpu, prev_nmi_count[cpu], get_nmi_count(cpu));
|
|
|
|
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"Please report this to bugzilla.kernel.org,\n");
|
|
|
|
printk(KERN_WARNING
|
|
|
|
"and attach the output of the 'dmesg' command.\n");
|
|
|
|
|
2009-09-09 14:16:06 +08:00
|
|
|
per_cpu(wd_enabled, cpu) = 0;
|
|
|
|
atomic_dec(&nmi_active);
|
2009-01-30 13:22:47 +08:00
|
|
|
}
|
|
|
|
|
2009-09-10 21:28:20 +08:00
|
|
|
void stop_nmi_watchdog(void *unused)
|
2009-01-30 13:22:47 +08:00
|
|
|
{
|
|
|
|
pcr_ops->write(PCR_PIC_PRIV);
|
2009-09-09 14:16:06 +08:00
|
|
|
__get_cpu_var(wd_enabled) = 0;
|
|
|
|
atomic_dec(&nmi_active);
|
2009-01-30 13:22:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __init check_nmi_watchdog(void)
|
|
|
|
{
|
|
|
|
unsigned int *prev_nmi_count;
|
|
|
|
int cpu, err;
|
|
|
|
|
2009-09-09 14:16:06 +08:00
|
|
|
if (!atomic_read(&nmi_active))
|
|
|
|
return 0;
|
|
|
|
|
2009-01-30 13:22:47 +08:00
|
|
|
prev_nmi_count = kmalloc(nr_cpu_ids * sizeof(unsigned int), GFP_KERNEL);
|
|
|
|
if (!prev_nmi_count) {
|
|
|
|
err = -ENOMEM;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
printk(KERN_INFO "Testing NMI watchdog ... ");
|
|
|
|
|
|
|
|
smp_call_function(nmi_cpu_busy, (void *)&endflag, 0);
|
|
|
|
|
|
|
|
for_each_possible_cpu(cpu)
|
|
|
|
prev_nmi_count[cpu] = get_nmi_count(cpu);
|
|
|
|
local_irq_enable();
|
|
|
|
mdelay((20 * 1000) / nmi_hz); /* wait 20 ticks */
|
|
|
|
|
|
|
|
for_each_online_cpu(cpu) {
|
2009-09-09 14:16:06 +08:00
|
|
|
if (!per_cpu(wd_enabled, cpu))
|
|
|
|
continue;
|
2009-01-30 13:22:47 +08:00
|
|
|
if (get_nmi_count(cpu) - prev_nmi_count[cpu] <= 5)
|
|
|
|
report_broken_nmi(cpu, prev_nmi_count);
|
|
|
|
}
|
|
|
|
endflag = 1;
|
2009-09-09 14:16:06 +08:00
|
|
|
if (!atomic_read(&nmi_active)) {
|
2009-01-30 13:22:47 +08:00
|
|
|
kfree(prev_nmi_count);
|
2009-09-09 14:16:06 +08:00
|
|
|
atomic_set(&nmi_active, -1);
|
2009-01-30 13:22:47 +08:00
|
|
|
err = -ENODEV;
|
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
printk("OK.\n");
|
|
|
|
|
|
|
|
nmi_hz = 1;
|
|
|
|
|
|
|
|
kfree(prev_nmi_count);
|
|
|
|
return 0;
|
|
|
|
error:
|
2009-09-09 14:16:06 +08:00
|
|
|
on_each_cpu(stop_nmi_watchdog, NULL, 1);
|
2009-01-30 13:22:47 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2009-09-10 21:28:20 +08:00
|
|
|
void start_nmi_watchdog(void *unused)
|
2009-09-09 14:16:06 +08:00
|
|
|
{
|
|
|
|
__get_cpu_var(wd_enabled) = 1;
|
|
|
|
atomic_inc(&nmi_active);
|
|
|
|
|
|
|
|
pcr_ops->write(PCR_PIC_PRIV);
|
|
|
|
write_pic(picl_value(nmi_hz));
|
|
|
|
|
|
|
|
pcr_ops->write(pcr_enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void nmi_adjust_hz_one(void *unused)
|
2009-01-30 13:22:47 +08:00
|
|
|
{
|
2009-09-09 14:16:06 +08:00
|
|
|
if (!__get_cpu_var(wd_enabled))
|
|
|
|
return;
|
|
|
|
|
2009-01-30 13:22:47 +08:00
|
|
|
pcr_ops->write(PCR_PIC_PRIV);
|
|
|
|
write_pic(picl_value(nmi_hz));
|
|
|
|
|
|
|
|
pcr_ops->write(pcr_enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nmi_adjust_hz(unsigned int new_hz)
|
|
|
|
{
|
|
|
|
nmi_hz = new_hz;
|
2009-09-09 14:16:06 +08:00
|
|
|
on_each_cpu(nmi_adjust_hz_one, NULL, 1);
|
2009-01-30 13:22:47 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(nmi_adjust_hz);
|
|
|
|
|
2009-03-30 06:40:33 +08:00
|
|
|
static int nmi_shutdown(struct notifier_block *nb, unsigned long cmd, void *p)
|
|
|
|
{
|
2009-09-09 14:16:06 +08:00
|
|
|
on_each_cpu(stop_nmi_watchdog, NULL, 1);
|
2009-03-30 06:40:33 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct notifier_block nmi_reboot_notifier = {
|
|
|
|
.notifier_call = nmi_shutdown,
|
|
|
|
};
|
|
|
|
|
2009-01-30 13:22:47 +08:00
|
|
|
int __init nmi_init(void)
|
|
|
|
{
|
2009-03-30 06:40:33 +08:00
|
|
|
int err;
|
|
|
|
|
2009-09-09 14:16:06 +08:00
|
|
|
on_each_cpu(start_nmi_watchdog, NULL, 1);
|
2009-01-30 13:22:47 +08:00
|
|
|
|
2009-03-30 06:40:33 +08:00
|
|
|
err = check_nmi_watchdog();
|
|
|
|
if (!err) {
|
|
|
|
err = register_reboot_notifier(&nmi_reboot_notifier);
|
|
|
|
if (err) {
|
2009-09-09 14:16:06 +08:00
|
|
|
on_each_cpu(stop_nmi_watchdog, NULL, 1);
|
|
|
|
atomic_set(&nmi_active, -1);
|
2009-03-30 06:40:33 +08:00
|
|
|
}
|
|
|
|
}
|
2009-09-10 21:28:20 +08:00
|
|
|
if (!err)
|
perf: Do the big rename: Performance Counters -> Performance Events
Bye-bye Performance Counters, welcome Performance Events!
In the past few months the perfcounters subsystem has grown out its
initial role of counting hardware events, and has become (and is
becoming) a much broader generic event enumeration, reporting, logging,
monitoring, analysis facility.
Naming its core object 'perf_counter' and naming the subsystem
'perfcounters' has become more and more of a misnomer. With pending
code like hw-breakpoints support the 'counter' name is less and
less appropriate.
All in one, we've decided to rename the subsystem to 'performance
events' and to propagate this rename through all fields, variables
and API names. (in an ABI compatible fashion)
The word 'event' is also a bit shorter than 'counter' - which makes
it slightly more convenient to write/handle as well.
Thanks goes to Stephane Eranian who first observed this misnomer and
suggested a rename.
User-space tooling and ABI compatibility is not affected - this patch
should be function-invariant. (Also, defconfigs were not touched to
keep the size down.)
This patch has been generated via the following script:
FILES=$(find * -type f | grep -vE 'oprofile|[^K]config')
sed -i \
-e 's/PERF_EVENT_/PERF_RECORD_/g' \
-e 's/PERF_COUNTER/PERF_EVENT/g' \
-e 's/perf_counter/perf_event/g' \
-e 's/nb_counters/nb_events/g' \
-e 's/swcounter/swevent/g' \
-e 's/tpcounter_event/tp_event/g' \
$FILES
for N in $(find . -name perf_counter.[ch]); do
M=$(echo $N | sed 's/perf_counter/perf_event/g')
mv $N $M
done
FILES=$(find . -name perf_event.*)
sed -i \
-e 's/COUNTER_MASK/REG_MASK/g' \
-e 's/COUNTER/EVENT/g' \
-e 's/\<event\>/event_id/g' \
-e 's/counter/event/g' \
-e 's/Counter/Event/g' \
$FILES
... to keep it as correct as possible. This script can also be
used by anyone who has pending perfcounters patches - it converts
a Linux kernel tree over to the new naming. We tried to time this
change to the point in time where the amount of pending patches
is the smallest: the end of the merge window.
Namespace clashes were fixed up in a preparatory patch - and some
stylistic fallout will be fixed up in a subsequent patch.
( NOTE: 'counters' are still the proper terminology when we deal
with hardware registers - and these sed scripts are a bit
over-eager in renaming them. I've undone some of that, but
in case there's something left where 'counter' would be
better than 'event' we can undo that on an individual basis
instead of touching an otherwise nicely automated patch. )
Suggested-by: Stephane Eranian <eranian@google.com>
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
Acked-by: Paul Mackerras <paulus@samba.org>
Reviewed-by: Arjan van de Ven <arjan@linux.intel.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: David Howells <dhowells@redhat.com>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: <linux-arch@vger.kernel.org>
LKML-Reference: <new-submission>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-09-21 18:02:48 +08:00
|
|
|
init_hw_perf_events();
|
2009-09-10 21:28:20 +08:00
|
|
|
|
2009-03-30 06:40:33 +08:00
|
|
|
return err;
|
2009-01-30 13:22:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int __init setup_nmi_watchdog(char *str)
|
|
|
|
{
|
|
|
|
if (!strncmp(str, "panic", 5))
|
|
|
|
panic_on_timeout = 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
__setup("nmi_watchdog=", setup_nmi_watchdog);
|