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