1
2
3
4
5
6
7
8
9
10#include <linux/kernel.h>
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
17static int allow_ints;
18
19static int
20perfmon_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
28
29
30 if (allow_ints)
31 oprofile_add_sample(regs, event);
32 return 0;
33}
34
35
36static int perfmon_start(void)
37{
38 allow_ints = 1;
39 return 0;
40}
41
42
43static 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
52static 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
59static char *get_cpu_type(void)
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
75
76static int using_perfmon;
77
78int perfmon_init(struct oprofile_operations *ops)
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
93void perfmon_exit(void)
94{
95 if (!using_perfmon)
96 return;
97
98 pfm_unregister_buffer_fmt(oprofile_fmt.fmt_uuid);
99}
100