4 * @remark Copyright 2002 OProfile authors
5 * @remark Read the file COPYING
7 * @author John Levon <levon@movementarian.org>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/oprofile.h>
14 #include <linux/moduleparam.h>
15 #include <asm/semaphore.h>
18 #include "event_buffer.h"
19 #include "cpu_buffer.h"
20 #include "buffer_sync.h"
21 #include "oprofile_stats.h"
23 struct oprofile_operations * oprofile_ops;
24 unsigned long oprofile_started;
25 static unsigned long is_setup;
26 static DECLARE_MUTEX(start_sem);
29 0 - use performance monitoring hardware if available
30 1 - use the timer int mechanism regardless
34 int oprofile_setup(void)
40 if ((err = alloc_cpu_buffers()))
43 if ((err = alloc_event_buffer()))
46 if (oprofile_ops->setup && (err = oprofile_ops->setup()))
49 /* Note even though this starts part of the
50 * profiling overhead, it's necessary to prevent
51 * us missing task deaths and eventually oopsing
52 * when trying to process the event buffer.
54 if ((err = sync_start()))
62 if (oprofile_ops->shutdown)
63 oprofile_ops->shutdown();
74 /* Actually start profiling (echo 1>/dev/oprofile/enable) */
75 int oprofile_start(void)
89 oprofile_reset_stats();
91 if ((err = oprofile_ops->start()))
101 /* echo 0>/dev/oprofile/enable */
102 void oprofile_stop(void)
105 if (!oprofile_started)
107 oprofile_ops->stop();
108 oprofile_started = 0;
109 /* wake up the daemon to read what remains */
110 wake_up_buffer_waiter();
116 void oprofile_shutdown(void)
120 if (oprofile_ops->shutdown)
121 oprofile_ops->shutdown();
129 extern void timer_init(struct oprofile_operations ** ops);
132 static int __init oprofile_init(void)
134 /* Architecture must fill in the interrupt ops and the
135 * logical CPU type, or we can fall back to the timer
136 * interrupt profiler.
138 int err = oprofile_arch_init(&oprofile_ops);
140 if (err == -ENODEV || timer) {
141 timer_init(&oprofile_ops);
147 if (!oprofile_ops->cpu_type) {
148 printk(KERN_ERR "oprofile: cpu_type not set !\n");
151 err = oprofilefs_register();
159 oprofile_arch_exit();
164 static void __exit oprofile_exit(void)
166 oprofilefs_unregister();
167 oprofile_arch_exit();
171 module_init(oprofile_init);
172 module_exit(oprofile_exit);
174 module_param_named(timer, timer, int, 0644);
175 MODULE_PARM_DESC(timer, "force use of timer interrupt");
177 MODULE_LICENSE("GPL");
178 MODULE_AUTHOR("John Levon <levon@movementarian.org>");
179 MODULE_DESCRIPTION("OProfile system profiler");