| Martin Habets | 9550e59 | 2006-10-17 19:21:48 -0700 | [diff] [blame] | 1 | /** | 
 | 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> | 
 | 14 |   | 
| David S. Miller | 422e23e | 2008-11-25 22:29:24 -0800 | [diff] [blame] | 15 | #ifdef CONFIG_SPARC64 | 
| David S. Miller | e5553a6 | 2009-01-29 21:22:47 -0800 | [diff] [blame] | 16 | #include <linux/notifier.h> | 
 | 17 | #include <linux/rcupdate.h> | 
 | 18 | #include <linux/kdebug.h> | 
 | 19 | #include <asm/nmi.h> | 
| David S. Miller | 422e23e | 2008-11-25 22:29:24 -0800 | [diff] [blame] | 20 |  | 
| David S. Miller | e5553a6 | 2009-01-29 21:22:47 -0800 | [diff] [blame] | 21 | static int profile_timer_exceptions_notify(struct notifier_block *self, | 
 | 22 | 					   unsigned long val, void *data) | 
| David S. Miller | 422e23e | 2008-11-25 22:29:24 -0800 | [diff] [blame] | 23 | { | 
| David S. Miller | e5553a6 | 2009-01-29 21:22:47 -0800 | [diff] [blame] | 24 | 	struct die_args *args = (struct die_args *)data; | 
 | 25 | 	int ret = NOTIFY_DONE; | 
| David S. Miller | 422e23e | 2008-11-25 22:29:24 -0800 | [diff] [blame] | 26 |  | 
| David S. Miller | e5553a6 | 2009-01-29 21:22:47 -0800 | [diff] [blame] | 27 | 	switch (val) { | 
 | 28 | 	case DIE_NMI: | 
 | 29 | 		oprofile_add_sample(args->regs, 0); | 
 | 30 | 		ret = NOTIFY_STOP; | 
| David S. Miller | 63ef348 | 2008-11-28 02:27:42 -0800 | [diff] [blame] | 31 | 		break; | 
| David S. Miller | 63ef348 | 2008-11-28 02:27:42 -0800 | [diff] [blame] | 32 | 	default: | 
| David S. Miller | e5553a6 | 2009-01-29 21:22:47 -0800 | [diff] [blame] | 33 | 		break; | 
| David S. Miller | 63ef348 | 2008-11-28 02:27:42 -0800 | [diff] [blame] | 34 | 	} | 
| David S. Miller | e5553a6 | 2009-01-29 21:22:47 -0800 | [diff] [blame] | 35 | 	return ret; | 
 | 36 | } | 
| David S. Miller | 422e23e | 2008-11-25 22:29:24 -0800 | [diff] [blame] | 37 |  | 
| David S. Miller | e5553a6 | 2009-01-29 21:22:47 -0800 | [diff] [blame] | 38 | static struct notifier_block profile_timer_exceptions_nb = { | 
 | 39 | 	.notifier_call	= profile_timer_exceptions_notify, | 
 | 40 | }; | 
 | 41 |  | 
 | 42 | static int timer_start(void) | 
 | 43 | { | 
 | 44 | 	if (register_die_notifier(&profile_timer_exceptions_nb)) | 
 | 45 | 		return 1; | 
 | 46 | 	nmi_adjust_hz(HZ); | 
 | 47 | 	return 0; | 
 | 48 | } | 
 | 49 |  | 
 | 50 |  | 
 | 51 | static void timer_stop(void) | 
 | 52 | { | 
 | 53 | 	nmi_adjust_hz(1); | 
 | 54 | 	unregister_die_notifier(&profile_timer_exceptions_nb); | 
 | 55 | 	synchronize_sched();  /* Allow already-started NMIs to complete. */ | 
 | 56 | } | 
 | 57 |  | 
 | 58 | static int op_nmi_timer_init(struct oprofile_operations *ops) | 
 | 59 | { | 
 | 60 | 	if (!nmi_usable) | 
 | 61 | 		return -ENODEV; | 
 | 62 |  | 
 | 63 | 	ops->start = timer_start; | 
 | 64 | 	ops->stop = timer_stop; | 
| David S. Miller | 422e23e | 2008-11-25 22:29:24 -0800 | [diff] [blame] | 65 | 	ops->cpu_type = "timer"; | 
| David S. Miller | e5553a6 | 2009-01-29 21:22:47 -0800 | [diff] [blame] | 66 | 	printk(KERN_INFO "oprofile: Using perfctr NMI timer interrupt.\n"); | 
| David S. Miller | 422e23e | 2008-11-25 22:29:24 -0800 | [diff] [blame] | 67 | 	return 0; | 
 | 68 | } | 
 | 69 | #endif | 
 | 70 |  | 
| Robert Richter | 25ad291 | 2008-09-05 17:12:36 +0200 | [diff] [blame] | 71 | int __init oprofile_arch_init(struct oprofile_operations *ops) | 
| Martin Habets | 9550e59 | 2006-10-17 19:21:48 -0700 | [diff] [blame] | 72 | { | 
| David S. Miller | 422e23e | 2008-11-25 22:29:24 -0800 | [diff] [blame] | 73 | 	int ret = -ENODEV; | 
 | 74 |  | 
 | 75 | #ifdef CONFIG_SPARC64 | 
| David S. Miller | e5553a6 | 2009-01-29 21:22:47 -0800 | [diff] [blame] | 76 | 	ret = op_nmi_timer_init(ops); | 
| David S. Miller | 422e23e | 2008-11-25 22:29:24 -0800 | [diff] [blame] | 77 | 	if (!ret) | 
 | 78 | 		return ret; | 
 | 79 | #endif | 
 | 80 |  | 
 | 81 | 	return ret; | 
| Martin Habets | 9550e59 | 2006-10-17 19:21:48 -0700 | [diff] [blame] | 82 | } | 
 | 83 |  | 
| Martin Habets | 9550e59 | 2006-10-17 19:21:48 -0700 | [diff] [blame] | 84 | void oprofile_arch_exit(void) | 
 | 85 | { | 
| Martin Habets | 9550e59 | 2006-10-17 19:21:48 -0700 | [diff] [blame] | 86 | } |