7 #include <linux/perf_event.h>
10 #include <linux/slab.h>
25 static int oprofile_perf_enabled;
30 static int num_counters;
41 for (
id = 0;
id < num_counters; ++
id)
42 if (
per_cpu(perf_events, cpu)[
id] == event)
45 if (
id != num_counters)
48 pr_warning(
"oprofile: ignoring spurious overflow "
57 static void op_perf_setup(
void)
63 for (i = 0; i < num_counters; ++
i) {
64 attr = &counter_config[
i].
attr;
74 static int op_create_counter(
int cpu,
int event)
78 if (!counter_config[event].
enabled ||
per_cpu(perf_events, cpu)[event])
83 op_overflow_handler,
NULL);
86 return PTR_ERR(pevent);
90 pr_warning(
"oprofile: failed to enable event %d "
91 "on CPU %d\n", event, cpu);
100 static void op_destroy_counter(
int cpu,
int event)
114 static int op_perf_start(
void)
119 for (event = 0;
event < num_counters; ++
event) {
120 ret = op_create_counter(cpu, event);
132 static void op_perf_stop(
void)
137 for (event = 0; event < num_counters; ++event)
138 op_destroy_counter(cpu, event);
145 for (i = 0; i < num_counters; i++) {
162 static int oprofile_perf_setup(
void)
170 static int oprofile_perf_start(
void)
175 if (!oprofile_perf_enabled) {
178 oprofile_perf_enabled = 1;
184 static void oprofile_perf_stop(
void)
187 if (oprofile_perf_enabled)
189 oprofile_perf_enabled = 0;
198 if (oprofile_perf_enabled)
207 if (oprofile_perf_enabled && op_perf_start())
208 oprofile_perf_enabled = 0;
215 .name =
"oprofile-perf",
217 .resume = oprofile_perf_resume,
218 .suspend = oprofile_perf_suspend,
223 static int __init init_driverfs(
void)
231 oprofile_pdev = platform_device_register_simple(
233 if (IS_ERR(oprofile_pdev)) {
234 ret = PTR_ERR(oprofile_pdev);
241 static void exit_driverfs(
void)
249 static inline int init_driverfs(
void) {
return 0; }
250 static inline void exit_driverfs(
void) { }
260 for (
id = 0;
id < num_counters; ++
id) {
269 kfree(counter_config);
277 ret = init_driverfs();
282 if (num_counters <= 0) {
283 pr_info(
"oprofile: no performance counters\n");
288 counter_config = kcalloc(num_counters,
291 if (!counter_config) {
292 pr_info(
"oprofile: failed to allocate %d "
293 "counters\n", num_counters);
300 per_cpu(perf_events, cpu) = kcalloc(num_counters,
302 if (!
per_cpu(perf_events, cpu)) {
303 pr_info(
"oprofile: failed to allocate %d perf events "
304 "for cpu %d\n", num_counters, cpu);
311 ops->
setup = oprofile_perf_setup;
312 ops->
start = oprofile_perf_start;
313 ops->
stop = oprofile_perf_stop;
315 ops->
cpu_type = op_name_from_perf_id();