blob: abf0ba52a6359fd8dc12c2cae9b4137dcca8d6e7 [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>
15
16
17#include <asm/nmi.h>
18#include <asm/apic.h>
19#include <asm/ptrace.h>
Don Zickus2fbe7b22006-09-26 10:52:27 +020020#include <asm/kdebug.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
Adrian Bunkc7c19f82006-09-26 10:52:27 +020022static int profile_timer_exceptions_notify(struct notifier_block *self,
23 unsigned long val, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -070024{
Don Zickus2fbe7b22006-09-26 10:52:27 +020025 struct die_args *args = (struct die_args *)data;
26 int ret = NOTIFY_DONE;
27
28 switch(val) {
29 case DIE_NMI:
30 oprofile_add_sample(args->regs, 0);
31 ret = NOTIFY_STOP;
32 break;
33 default:
34 break;
35 }
36 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037}
38
Don Zickus2fbe7b22006-09-26 10:52:27 +020039static struct notifier_block profile_timer_exceptions_nb = {
40 .notifier_call = profile_timer_exceptions_notify,
41 .next = NULL,
42 .priority = 0
43};
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045static int timer_start(void)
46{
Don Zickus2fbe7b22006-09-26 10:52:27 +020047 if (register_die_notifier(&profile_timer_exceptions_nb))
48 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 return 0;
50}
51
52
53static void timer_stop(void)
54{
Don Zickus2fbe7b22006-09-26 10:52:27 +020055 unregister_die_notifier(&profile_timer_exceptions_nb);
Paul E. McKenneyfbd568a3e2005-05-01 08:59:04 -070056 synchronize_sched(); /* Allow already-started NMIs to complete. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070057}
58
59
David Gibson96d08212005-09-06 15:17:26 -070060int __init op_nmi_timer_init(struct oprofile_operations * ops)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
Don Zickus2fbe7b22006-09-26 10:52:27 +020062 if ((nmi_watchdog != NMI_IO_APIC) || (atomic_read(&nmi_active) <= 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -070063 return -ENODEV;
64
65 ops->start = timer_start;
66 ops->stop = timer_stop;
67 ops->cpu_type = "timer";
68 printk(KERN_INFO "oprofile: using NMI timer interrupt.\n");
69 return 0;
70}