Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /** |
2 | * @file arch/alpha/oprofile/common.c | |
3 | * | |
4 | * @remark Copyright 2002 OProfile authors | |
5 | * @remark Read the file COPYING | |
6 | * | |
7 | * @author Richard Henderson <rth@twiddle.net> | |
8 | */ | |
9 | ||
10 | #include <linux/oprofile.h> | |
11 | #include <linux/init.h> | |
12 | #include <linux/smp.h> | |
13 | #include <linux/errno.h> | |
14 | #include <asm/ptrace.h> | |
1da177e4 LT |
15 | |
16 | #include "op_impl.h" | |
17 | ||
18 | extern struct op_axp_model op_model_ev4 __attribute__((weak)); | |
19 | extern struct op_axp_model op_model_ev5 __attribute__((weak)); | |
20 | extern struct op_axp_model op_model_pca56 __attribute__((weak)); | |
21 | extern struct op_axp_model op_model_ev6 __attribute__((weak)); | |
22 | extern struct op_axp_model op_model_ev67 __attribute__((weak)); | |
23 | ||
24 | static struct op_axp_model *model; | |
25 | ||
26 | extern void (*perf_irq)(unsigned long, struct pt_regs *); | |
27 | static void (*save_perf_irq)(unsigned long, struct pt_regs *); | |
28 | ||
29 | static struct op_counter_config ctr[20]; | |
30 | static struct op_system_config sys; | |
31 | static struct op_register_config reg; | |
32 | ||
33 | /* Called from do_entInt to handle the performance monitor interrupt. */ | |
34 | ||
35 | static void | |
36 | op_handle_interrupt(unsigned long which, struct pt_regs *regs) | |
37 | { | |
38 | model->handle_interrupt(which, regs, ctr); | |
39 | ||
40 | /* If the user has selected an interrupt frequency that is | |
41 | not exactly the width of the counter, write a new value | |
42 | into the counter such that it'll overflow after N more | |
43 | events. */ | |
44 | if ((reg.need_reset >> which) & 1) | |
45 | model->reset_ctr(®, which); | |
46 | } | |
47 | ||
48 | static int | |
49 | op_axp_setup(void) | |
50 | { | |
51 | unsigned long i, e; | |
52 | ||
53 | /* Install our interrupt handler into the existing hook. */ | |
54 | save_perf_irq = perf_irq; | |
55 | perf_irq = op_handle_interrupt; | |
56 | ||
57 | /* Compute the mask of enabled counters. */ | |
58 | for (i = e = 0; i < model->num_counters; ++i) | |
59 | if (ctr[i].enabled) | |
60 | e |= 1 << i; | |
61 | reg.enable = e; | |
62 | ||
63 | /* Pre-compute the values to stuff in the hardware registers. */ | |
64 | model->reg_setup(®, ctr, &sys); | |
65 | ||
66 | /* Configure the registers on all cpus. */ | |
8691e5a8 | 67 | (void)smp_call_function(model->cpu_setup, ®, 1); |
1da177e4 LT |
68 | model->cpu_setup(®); |
69 | return 0; | |
70 | } | |
71 | ||
72 | static void | |
73 | op_axp_shutdown(void) | |
74 | { | |
75 | /* Remove our interrupt handler. We may be removing this module. */ | |
76 | perf_irq = save_perf_irq; | |
77 | } | |
78 | ||
79 | static void | |
80 | op_axp_cpu_start(void *dummy) | |
81 | { | |
82 | wrperfmon(1, reg.enable); | |
83 | } | |
84 | ||
85 | static int | |
86 | op_axp_start(void) | |
87 | { | |
8691e5a8 | 88 | (void)smp_call_function(op_axp_cpu_start, NULL, 1); |
1da177e4 LT |
89 | op_axp_cpu_start(NULL); |
90 | return 0; | |
91 | } | |
92 | ||
93 | static inline void | |
94 | op_axp_cpu_stop(void *dummy) | |
95 | { | |
96 | /* Disable performance monitoring for all counters. */ | |
97 | wrperfmon(0, -1); | |
98 | } | |
99 | ||
100 | static void | |
101 | op_axp_stop(void) | |
102 | { | |
8691e5a8 | 103 | (void)smp_call_function(op_axp_cpu_stop, NULL, 1); |
1da177e4 LT |
104 | op_axp_cpu_stop(NULL); |
105 | } | |
106 | ||
107 | static int | |
25ad2913 | 108 | op_axp_create_files(struct super_block *sb, struct dentry *root) |
1da177e4 LT |
109 | { |
110 | int i; | |
111 | ||
112 | for (i = 0; i < model->num_counters; ++i) { | |
113 | struct dentry *dir; | |
0c6856f7 | 114 | char buf[4]; |
1da177e4 LT |
115 | |
116 | snprintf(buf, sizeof buf, "%d", i); | |
117 | dir = oprofilefs_mkdir(sb, root, buf); | |
118 | ||
119 | oprofilefs_create_ulong(sb, dir, "enabled", &ctr[i].enabled); | |
120 | oprofilefs_create_ulong(sb, dir, "event", &ctr[i].event); | |
121 | oprofilefs_create_ulong(sb, dir, "count", &ctr[i].count); | |
122 | /* Dummies. */ | |
123 | oprofilefs_create_ulong(sb, dir, "kernel", &ctr[i].kernel); | |
124 | oprofilefs_create_ulong(sb, dir, "user", &ctr[i].user); | |
125 | oprofilefs_create_ulong(sb, dir, "unit_mask", &ctr[i].unit_mask); | |
126 | } | |
127 | ||
128 | if (model->can_set_proc_mode) { | |
129 | oprofilefs_create_ulong(sb, root, "enable_pal", | |
130 | &sys.enable_pal); | |
131 | oprofilefs_create_ulong(sb, root, "enable_kernel", | |
132 | &sys.enable_kernel); | |
133 | oprofilefs_create_ulong(sb, root, "enable_user", | |
134 | &sys.enable_user); | |
135 | } | |
136 | ||
137 | return 0; | |
138 | } | |
139 | ||
140 | int __init | |
141 | oprofile_arch_init(struct oprofile_operations *ops) | |
142 | { | |
143 | struct op_axp_model *lmodel = NULL; | |
144 | ||
145 | switch (implver()) { | |
146 | case IMPLVER_EV4: | |
147 | lmodel = &op_model_ev4; | |
148 | break; | |
149 | case IMPLVER_EV5: | |
150 | /* 21164PC has a slightly different set of events. | |
151 | Recognize the chip by the presence of the MAX insns. */ | |
152 | if (!amask(AMASK_MAX)) | |
153 | lmodel = &op_model_pca56; | |
154 | else | |
155 | lmodel = &op_model_ev5; | |
156 | break; | |
157 | case IMPLVER_EV6: | |
158 | /* 21264A supports ProfileMe. | |
159 | Recognize the chip by the presence of the CIX insns. */ | |
160 | if (!amask(AMASK_CIX)) | |
161 | lmodel = &op_model_ev67; | |
162 | else | |
163 | lmodel = &op_model_ev6; | |
164 | break; | |
165 | } | |
166 | ||
167 | if (!lmodel) | |
168 | return -ENODEV; | |
169 | model = lmodel; | |
170 | ||
171 | ops->create_files = op_axp_create_files; | |
172 | ops->setup = op_axp_setup; | |
173 | ops->shutdown = op_axp_shutdown; | |
174 | ops->start = op_axp_start; | |
175 | ops->stop = op_axp_stop; | |
176 | ops->cpu_type = lmodel->cpu_type; | |
177 | ||
178 | printk(KERN_INFO "oprofile: using %s performance monitoring.\n", | |
179 | lmodel->cpu_type); | |
180 | ||
181 | return 0; | |
182 | } | |
183 | ||
184 | ||
185 | void | |
186 | oprofile_arch_exit(void) | |
187 | { | |
188 | } |