blob: f9024bccff163f06fcca11054865b885086dc8c0 [file] [log] [blame]
Martin Habets9550e592006-10-17 19:21:48 -07001/**
2 * @file init.c
3 *
4 * @remark Copyright 2002 OProfile authors
5 * @remark Read the file COPYING
6 *
7 * @author John Levon <levon@movementarian.org>
8 */
9
10#include <linux/kernel.h>
11#include <linux/oprofile.h>
12#include <linux/errno.h>
13#include <linux/init.h>
Stephen Rothwellc4a57432009-10-05 00:46:08 -070014#include <linux/param.h> /* for HZ */
Martin Habets9550e592006-10-17 19:21:48 -070015
David S. Miller422e23e2008-11-25 22:29:24 -080016#ifdef CONFIG_SPARC64
David S. Millere5553a62009-01-29 21:22:47 -080017#include <linux/notifier.h>
18#include <linux/rcupdate.h>
19#include <linux/kdebug.h>
20#include <asm/nmi.h>
David S. Miller422e23e2008-11-25 22:29:24 -080021
David S. Millere5553a62009-01-29 21:22:47 -080022static int profile_timer_exceptions_notify(struct notifier_block *self,
23 unsigned long val, void *data)
David S. Miller422e23e2008-11-25 22:29:24 -080024{
David S. Miller4e85f592009-09-08 23:20:39 -070025 struct die_args *args = data;
David S. Millere5553a62009-01-29 21:22:47 -080026 int ret = NOTIFY_DONE;
David S. Miller422e23e2008-11-25 22:29:24 -080027
David S. Millere5553a62009-01-29 21:22:47 -080028 switch (val) {
29 case DIE_NMI:
30 oprofile_add_sample(args->regs, 0);
31 ret = NOTIFY_STOP;
David S. Miller63ef3482008-11-28 02:27:42 -080032 break;
David S. Miller63ef3482008-11-28 02:27:42 -080033 default:
David S. Millere5553a62009-01-29 21:22:47 -080034 break;
David S. Miller63ef3482008-11-28 02:27:42 -080035 }
David S. Millere5553a62009-01-29 21:22:47 -080036 return ret;
37}
David S. Miller422e23e2008-11-25 22:29:24 -080038
David S. Millere5553a62009-01-29 21:22:47 -080039static struct notifier_block profile_timer_exceptions_nb = {
40 .notifier_call = profile_timer_exceptions_notify,
41};
42
43static int timer_start(void)
44{
45 if (register_die_notifier(&profile_timer_exceptions_nb))
46 return 1;
47 nmi_adjust_hz(HZ);
48 return 0;
49}
50
51
52static void timer_stop(void)
53{
54 nmi_adjust_hz(1);
55 unregister_die_notifier(&profile_timer_exceptions_nb);
56 synchronize_sched(); /* Allow already-started NMIs to complete. */
57}
58
59static int op_nmi_timer_init(struct oprofile_operations *ops)
60{
David S. Millera8f22262009-09-08 23:16:06 -070061 if (atomic_read(&nmi_active) <= 0)
David S. Millere5553a62009-01-29 21:22:47 -080062 return -ENODEV;
63
64 ops->start = timer_start;
65 ops->stop = timer_stop;
David S. Miller422e23e2008-11-25 22:29:24 -080066 ops->cpu_type = "timer";
David S. Millere5553a62009-01-29 21:22:47 -080067 printk(KERN_INFO "oprofile: Using perfctr NMI timer interrupt.\n");
David S. Miller422e23e2008-11-25 22:29:24 -080068 return 0;
69}
70#endif
71
Robert Richter25ad2912008-09-05 17:12:36 +020072int __init oprofile_arch_init(struct oprofile_operations *ops)
Martin Habets9550e592006-10-17 19:21:48 -070073{
David S. Miller422e23e2008-11-25 22:29:24 -080074 int ret = -ENODEV;
75
76#ifdef CONFIG_SPARC64
David S. Millere5553a62009-01-29 21:22:47 -080077 ret = op_nmi_timer_init(ops);
David S. Miller422e23e2008-11-25 22:29:24 -080078 if (!ret)
79 return ret;
80#endif
81
82 return ret;
Martin Habets9550e592006-10-17 19:21:48 -070083}
84
Martin Habets9550e592006-10-17 19:21:48 -070085void oprofile_arch_exit(void)
86{
Martin Habets9550e592006-10-17 19:21:48 -070087}