MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / arch / ia64 / oprofile / perfmon.c
blobbfc82ccf543281d9bb00e5842b0539a51677c613
1 /**
2 * @file perfmon.c
4 * @remark Copyright 2003 OProfile authors
5 * @remark Read the file COPYING
7 * @author John Levon <levon@movementarian.org>
8 */
10 #include <linux/kernel.h>
11 #include <linux/config.h>
12 #include <linux/oprofile.h>
13 #include <linux/sched.h>
14 #include <asm/perfmon.h>
15 #include <asm/ptrace.h>
16 #include <asm/errno.h>
18 static int allow_ints;
20 static int
21 perfmon_handler(struct task_struct *task, void *buf, pfm_ovfl_arg_t *arg,
22 struct pt_regs *regs, unsigned long stamp)
24 int cpu = smp_processor_id();
25 unsigned long eip = instruction_pointer(regs);
26 int event = arg->pmd_eventid;
28 arg->ovfl_ctrl.bits.reset_ovfl_pmds = 1;
30 /* the owner of the oprofile event buffer may have exited
31 * without perfmon being shutdown (e.g. SIGSEGV)
33 if (allow_ints)
34 oprofile_add_sample(eip, !user_mode(regs), event, cpu);
35 return 0;
39 static int perfmon_start(void)
41 allow_ints = 1;
42 return 0;
46 static void perfmon_stop(void)
48 allow_ints = 0;
52 #define OPROFILE_FMT_UUID { \
53 0x77, 0x7a, 0x6e, 0x61, 0x20, 0x65, 0x73, 0x69, 0x74, 0x6e, 0x72, 0x20, 0x61, 0x65, 0x0a, 0x6c }
55 static pfm_buffer_fmt_t oprofile_fmt = {
56 .fmt_name = "oprofile_format",
57 .fmt_uuid = OPROFILE_FMT_UUID,
58 .fmt_handler = perfmon_handler,
62 static char * get_cpu_type(void)
64 __u8 family = local_cpu_data->family;
66 switch (family) {
67 case 0x07:
68 return "ia64/itanium";
69 case 0x1f:
70 return "ia64/itanium2";
71 default:
72 return "ia64/ia64";
77 /* all the ops are handled via userspace for IA64 perfmon */
78 static struct oprofile_operations perfmon_ops = {
79 .start = perfmon_start,
80 .stop = perfmon_stop,
83 static int using_perfmon;
85 int perfmon_init(struct oprofile_operations ** ops)
87 int ret = pfm_register_buffer_fmt(&oprofile_fmt);
88 if (ret)
89 return -ENODEV;
91 perfmon_ops.cpu_type = get_cpu_type();
92 *ops = &perfmon_ops;
93 using_perfmon = 1;
94 printk(KERN_INFO "oprofile: using perfmon.\n");
95 return 0;
99 void perfmon_exit(void)
101 if (!using_perfmon)
102 return;
104 pfm_unregister_buffer_fmt(oprofile_fmt.fmt_uuid);