| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /** | 
|  | 2 | * @file perfmon.c | 
|  | 3 | * | 
|  | 4 | * @remark Copyright 2003 OProfile authors | 
|  | 5 | * @remark Read the file COPYING | 
|  | 6 | * | 
|  | 7 | * @author John Levon <levon@movementarian.org> | 
|  | 8 | */ | 
|  | 9 |  | 
|  | 10 | #include <linux/kernel.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/oprofile.h> | 
|  | 12 | #include <linux/sched.h> | 
|  | 13 | #include <asm/perfmon.h> | 
|  | 14 | #include <asm/ptrace.h> | 
|  | 15 | #include <asm/errno.h> | 
|  | 16 |  | 
|  | 17 | static int allow_ints; | 
|  | 18 |  | 
|  | 19 | static int | 
|  | 20 | perfmon_handler(struct task_struct *task, void *buf, pfm_ovfl_arg_t *arg, | 
|  | 21 | struct pt_regs *regs, unsigned long stamp) | 
|  | 22 | { | 
|  | 23 | int event = arg->pmd_eventid; | 
|  | 24 |  | 
|  | 25 | arg->ovfl_ctrl.bits.reset_ovfl_pmds = 1; | 
|  | 26 |  | 
|  | 27 | /* the owner of the oprofile event buffer may have exited | 
|  | 28 | * without perfmon being shutdown (e.g. SIGSEGV) | 
|  | 29 | */ | 
|  | 30 | if (allow_ints) | 
|  | 31 | oprofile_add_sample(regs, event); | 
|  | 32 | return 0; | 
|  | 33 | } | 
|  | 34 |  | 
|  | 35 |  | 
|  | 36 | static int perfmon_start(void) | 
|  | 37 | { | 
|  | 38 | allow_ints = 1; | 
|  | 39 | return 0; | 
|  | 40 | } | 
|  | 41 |  | 
|  | 42 |  | 
|  | 43 | static void perfmon_stop(void) | 
|  | 44 | { | 
|  | 45 | allow_ints = 0; | 
|  | 46 | } | 
|  | 47 |  | 
|  | 48 |  | 
|  | 49 | #define OPROFILE_FMT_UUID { \ | 
|  | 50 | 0x77, 0x7a, 0x6e, 0x61, 0x20, 0x65, 0x73, 0x69, 0x74, 0x6e, 0x72, 0x20, 0x61, 0x65, 0x0a, 0x6c } | 
|  | 51 |  | 
|  | 52 | static pfm_buffer_fmt_t oprofile_fmt = { | 
|  | 53 | .fmt_name 	    = "oprofile_format", | 
|  | 54 | .fmt_uuid	    = OPROFILE_FMT_UUID, | 
|  | 55 | .fmt_handler	    = perfmon_handler, | 
|  | 56 | }; | 
|  | 57 |  | 
|  | 58 |  | 
| Robert Richter | 25ad291 | 2008-09-05 17:12:36 +0200 | [diff] [blame] | 59 | static char *get_cpu_type(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | { | 
|  | 61 | __u8 family = local_cpu_data->family; | 
|  | 62 |  | 
|  | 63 | switch (family) { | 
|  | 64 | case 0x07: | 
|  | 65 | return "ia64/itanium"; | 
|  | 66 | case 0x1f: | 
|  | 67 | return "ia64/itanium2"; | 
|  | 68 | default: | 
|  | 69 | return "ia64/ia64"; | 
|  | 70 | } | 
|  | 71 | } | 
|  | 72 |  | 
|  | 73 |  | 
|  | 74 | /* all the ops are handled via userspace for IA64 perfmon */ | 
|  | 75 |  | 
|  | 76 | static int using_perfmon; | 
|  | 77 |  | 
| Robert Richter | 25ad291 | 2008-09-05 17:12:36 +0200 | [diff] [blame] | 78 | int perfmon_init(struct oprofile_operations *ops) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { | 
|  | 80 | int ret = pfm_register_buffer_fmt(&oprofile_fmt); | 
|  | 81 | if (ret) | 
|  | 82 | return -ENODEV; | 
|  | 83 |  | 
|  | 84 | ops->cpu_type = get_cpu_type(); | 
|  | 85 | ops->start = perfmon_start; | 
|  | 86 | ops->stop = perfmon_stop; | 
|  | 87 | using_perfmon = 1; | 
|  | 88 | printk(KERN_INFO "oprofile: using perfmon.\n"); | 
|  | 89 | return 0; | 
|  | 90 | } | 
|  | 91 |  | 
|  | 92 |  | 
|  | 93 | void perfmon_exit(void) | 
|  | 94 | { | 
|  | 95 | if (!using_perfmon) | 
|  | 96 | return; | 
|  | 97 |  | 
|  | 98 | pfm_unregister_buffer_fmt(oprofile_fmt.fmt_uuid); | 
|  | 99 | } |