4 * @remark Copyright 2002 OProfile authors
5 * @remark Read the file COPYING
7 * @author John Levon <levon@movementarian.org>
9 * Modified by Aravind Menon for Xen
10 * These modifications are:
11 * Copyright (C) 2005 Hewlett-Packard Co.
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/oprofile.h>
18 #include <linux/moduleparam.h>
19 #include <asm/semaphore.h>
22 #include "event_buffer.h"
23 #include "cpu_buffer.h"
24 #include "buffer_sync.h"
25 #include "oprofile_stats.h"
27 struct oprofile_operations oprofile_ops;
29 unsigned long oprofile_started;
30 unsigned long backtrace_depth;
31 static unsigned long is_setup;
32 static DECLARE_MUTEX(start_sem);
35 0 - use performance monitoring hardware if available
36 1 - use the timer int mechanism regardless
41 int oprofile_set_active(int active_domains[], unsigned int adomains)
45 if (!oprofile_ops.set_active)
49 err = oprofile_ops.set_active(active_domains, adomains);
54 int oprofile_set_passive(int passive_domains[], unsigned int pdomains)
58 if (!oprofile_ops.set_passive)
62 err = oprofile_ops.set_passive(passive_domains, pdomains);
68 int oprofile_setup(void)
74 if ((err = alloc_cpu_buffers()))
77 if ((err = alloc_event_buffer()))
80 if (oprofile_ops.setup && (err = oprofile_ops.setup()))
83 /* Note even though this starts part of the
84 * profiling overhead, it's necessary to prevent
85 * us missing task deaths and eventually oopsing
86 * when trying to process the event buffer.
88 if ((err = sync_start()))
96 if (oprofile_ops.shutdown)
97 oprofile_ops.shutdown();
108 /* Actually start profiling (echo 1>/dev/oprofile/enable) */
109 int oprofile_start(void)
120 if (oprofile_started)
123 oprofile_reset_stats();
125 if ((err = oprofile_ops.start()))
128 oprofile_started = 1;
135 /* echo 0>/dev/oprofile/enable */
136 void oprofile_stop(void)
139 if (!oprofile_started)
142 oprofile_started = 0;
143 /* wake up the daemon to read what remains */
144 wake_up_buffer_waiter();
150 void oprofile_shutdown(void)
154 if (oprofile_ops.shutdown)
155 oprofile_ops.shutdown();
163 int oprofile_set_backtrace(unsigned long val)
169 if (oprofile_started) {
174 if (!oprofile_ops.backtrace) {
179 backtrace_depth = val;
186 static int __init oprofile_init(void)
190 err = oprofile_arch_init(&oprofile_ops);
192 if (err < 0 || timer) {
193 printk(KERN_INFO "oprofile: using timer interrupt.\n");
194 oprofile_timer_init(&oprofile_ops);
197 err = oprofilefs_register();
199 oprofile_arch_exit();
205 static void __exit oprofile_exit(void)
207 oprofilefs_unregister();
208 oprofile_arch_exit();
212 module_init(oprofile_init);
213 module_exit(oprofile_exit);
215 module_param_named(timer, timer, int, 0644);
216 MODULE_PARM_DESC(timer, "force use of timer interrupt");
218 MODULE_LICENSE("GPL");
219 MODULE_AUTHOR("John Levon <levon@movementarian.org>");
220 MODULE_DESCRIPTION("OProfile system profiler");