blob: e3ecb71b5790228073d5eb089f4a4fc9303ab09a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/**
2 * @file nmi_timer_int.c
3 *
4 * @remark Copyright 2003 OProfile authors
5 * @remark Read the file COPYING
6 *
7 * @author Zwane Mwaikambo <zwane@linuxpower.ca>
8 */
9
10#include <linux/init.h>
11#include <linux/smp.h>
Al Viroce3a1612005-09-26 05:49:44 +010012#include <linux/errno.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013#include <linux/oprofile.h>
14#include <linux/rcupdate.h>
Christoph Hellwig1eeb66a2007-05-08 00:27:03 -070015#include <linux/kdebug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17#include <asm/nmi.h>
18#include <asm/apic.h>
19#include <asm/ptrace.h>
Paolo Ciarrocchi0fb90292008-02-22 23:11:34 +010020
Adrian Bunkc7c19f82006-09-26 10:52:27 +020021static int profile_timer_exceptions_notify(struct notifier_block *self,
22 unsigned long val, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070023{
Don Zickus2fbe7b22006-09-26 10:52:27 +020024 struct die_args *args = (struct die_args *)data;
25 int ret = NOTIFY_DONE;
26
Paolo Ciarrocchi0fb90292008-02-22 23:11:34 +010027 switch (val) {
Don Zickus2fbe7b22006-09-26 10:52:27 +020028 case DIE_NMI:
29 oprofile_add_sample(args->regs, 0);
30 ret = NOTIFY_STOP;
31 break;
32 default:
33 break;
34 }
35 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036}
37
Don Zickus2fbe7b22006-09-26 10:52:27 +020038static struct notifier_block profile_timer_exceptions_nb = {
39 .notifier_call = profile_timer_exceptions_notify,
40 .next = NULL,
41 .priority = 0
42};
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044static int timer_start(void)
45{
Don Zickus2fbe7b22006-09-26 10:52:27 +020046 if (register_die_notifier(&profile_timer_exceptions_nb))
47 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048 return 0;
49}
50
51
52static void timer_stop(void)
53{
Don Zickus2fbe7b22006-09-26 10:52:27 +020054 unregister_die_notifier(&profile_timer_exceptions_nb);
Paul E. McKenneyfbd568a3e2005-05-01 08:59:04 -070055 synchronize_sched(); /* Allow already-started NMIs to complete. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070056}
57
58
Paolo Ciarrocchi0fb90292008-02-22 23:11:34 +010059int __init op_nmi_timer_init(struct oprofile_operations *ops)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
Don Zickus2fbe7b22006-09-26 10:52:27 +020061 if ((nmi_watchdog != NMI_IO_APIC) || (atomic_read(&nmi_active) <= 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 return -ENODEV;
63
64 ops->start = timer_start;
65 ops->stop = timer_stop;
66 ops->cpu_type = "timer";
67 printk(KERN_INFO "oprofile: using NMI timer interrupt.\n");
68 return 0;
69}