xref: /OK3568_Linux_fs/kernel/arch/sparc/oprofile/init.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /**
2*4882a593Smuzhiyun  * @file init.c
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * @remark Copyright 2002 OProfile authors
5*4882a593Smuzhiyun  * @remark Read the file COPYING
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * @author John Levon <levon@movementarian.org>
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun #include <linux/kernel.h>
11*4882a593Smuzhiyun #include <linux/oprofile.h>
12*4882a593Smuzhiyun #include <linux/errno.h>
13*4882a593Smuzhiyun #include <linux/init.h>
14*4882a593Smuzhiyun #include <linux/param.h>	/* for HZ */
15*4882a593Smuzhiyun 
16*4882a593Smuzhiyun #ifdef CONFIG_SPARC64
17*4882a593Smuzhiyun #include <linux/notifier.h>
18*4882a593Smuzhiyun #include <linux/rcupdate.h>
19*4882a593Smuzhiyun #include <linux/kdebug.h>
20*4882a593Smuzhiyun #include <asm/nmi.h>
21*4882a593Smuzhiyun 
profile_timer_exceptions_notify(struct notifier_block * self,unsigned long val,void * data)22*4882a593Smuzhiyun static int profile_timer_exceptions_notify(struct notifier_block *self,
23*4882a593Smuzhiyun 					   unsigned long val, void *data)
24*4882a593Smuzhiyun {
25*4882a593Smuzhiyun 	struct die_args *args = data;
26*4882a593Smuzhiyun 	int ret = NOTIFY_DONE;
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun 	switch (val) {
29*4882a593Smuzhiyun 	case DIE_NMI:
30*4882a593Smuzhiyun 		oprofile_add_sample(args->regs, 0);
31*4882a593Smuzhiyun 		ret = NOTIFY_STOP;
32*4882a593Smuzhiyun 		break;
33*4882a593Smuzhiyun 	default:
34*4882a593Smuzhiyun 		break;
35*4882a593Smuzhiyun 	}
36*4882a593Smuzhiyun 	return ret;
37*4882a593Smuzhiyun }
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun static struct notifier_block profile_timer_exceptions_nb = {
40*4882a593Smuzhiyun 	.notifier_call	= profile_timer_exceptions_notify,
41*4882a593Smuzhiyun };
42*4882a593Smuzhiyun 
timer_start(void)43*4882a593Smuzhiyun static int timer_start(void)
44*4882a593Smuzhiyun {
45*4882a593Smuzhiyun 	if (register_die_notifier(&profile_timer_exceptions_nb))
46*4882a593Smuzhiyun 		return 1;
47*4882a593Smuzhiyun 	nmi_adjust_hz(HZ);
48*4882a593Smuzhiyun 	return 0;
49*4882a593Smuzhiyun }
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun 
timer_stop(void)52*4882a593Smuzhiyun static void timer_stop(void)
53*4882a593Smuzhiyun {
54*4882a593Smuzhiyun 	nmi_adjust_hz(1);
55*4882a593Smuzhiyun 	unregister_die_notifier(&profile_timer_exceptions_nb);
56*4882a593Smuzhiyun 	synchronize_rcu();  /* Allow already-started NMIs to complete. */
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun 
op_nmi_timer_init(struct oprofile_operations * ops)59*4882a593Smuzhiyun static int op_nmi_timer_init(struct oprofile_operations *ops)
60*4882a593Smuzhiyun {
61*4882a593Smuzhiyun 	if (atomic_read(&nmi_active) <= 0)
62*4882a593Smuzhiyun 		return -ENODEV;
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun 	ops->start = timer_start;
65*4882a593Smuzhiyun 	ops->stop = timer_stop;
66*4882a593Smuzhiyun 	ops->cpu_type = "timer";
67*4882a593Smuzhiyun 	printk(KERN_INFO "oprofile: Using perfctr NMI timer interrupt.\n");
68*4882a593Smuzhiyun 	return 0;
69*4882a593Smuzhiyun }
70*4882a593Smuzhiyun #endif
71*4882a593Smuzhiyun 
oprofile_arch_init(struct oprofile_operations * ops)72*4882a593Smuzhiyun int __init oprofile_arch_init(struct oprofile_operations *ops)
73*4882a593Smuzhiyun {
74*4882a593Smuzhiyun 	int ret = -ENODEV;
75*4882a593Smuzhiyun 
76*4882a593Smuzhiyun #ifdef CONFIG_SPARC64
77*4882a593Smuzhiyun 	ret = op_nmi_timer_init(ops);
78*4882a593Smuzhiyun 	if (!ret)
79*4882a593Smuzhiyun 		return ret;
80*4882a593Smuzhiyun #endif
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun 	return ret;
83*4882a593Smuzhiyun }
84*4882a593Smuzhiyun 
oprofile_arch_exit(void)85*4882a593Smuzhiyun void oprofile_arch_exit(void)
86*4882a593Smuzhiyun {
87*4882a593Smuzhiyun }
88