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/mutex.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
;
25 unsigned long oprofile_started
;
26 unsigned long backtrace_depth
;
27 static unsigned long is_setup
;
28 static DEFINE_MUTEX(start_mutex
);
31 0 - use performance monitoring hardware if available
32 1 - use the timer int mechanism regardless
36 int oprofile_setup(void)
40 mutex_lock(&start_mutex
);
42 if ((err
= alloc_cpu_buffers()))
45 if ((err
= alloc_event_buffer()))
48 if (oprofile_ops
.setup
&& (err
= oprofile_ops
.setup()))
51 /* Note even though this starts part of the
52 * profiling overhead, it's necessary to prevent
53 * us missing task deaths and eventually oopsing
54 * when trying to process the event buffer.
56 if ((err
= sync_start()))
60 mutex_unlock(&start_mutex
);
64 if (oprofile_ops
.shutdown
)
65 oprofile_ops
.shutdown();
71 mutex_unlock(&start_mutex
);
76 /* Actually start profiling (echo 1>/dev/oprofile/enable) */
77 int oprofile_start(void)
81 mutex_lock(&start_mutex
);
91 oprofile_reset_stats();
93 if ((err
= oprofile_ops
.start()))
98 mutex_unlock(&start_mutex
);
103 /* echo 0>/dev/oprofile/enable */
104 void oprofile_stop(void)
106 mutex_lock(&start_mutex
);
107 if (!oprofile_started
)
110 oprofile_started
= 0;
111 /* wake up the daemon to read what remains */
112 wake_up_buffer_waiter();
114 mutex_unlock(&start_mutex
);
118 void oprofile_shutdown(void)
120 mutex_lock(&start_mutex
);
122 if (oprofile_ops
.shutdown
)
123 oprofile_ops
.shutdown();
127 mutex_unlock(&start_mutex
);
131 int oprofile_set_backtrace(unsigned long val
)
135 mutex_lock(&start_mutex
);
137 if (oprofile_started
) {
142 if (!oprofile_ops
.backtrace
) {
147 backtrace_depth
= val
;
150 mutex_unlock(&start_mutex
);
154 static int __init
oprofile_init(void)
158 err
= oprofile_arch_init(&oprofile_ops
);
160 if (err
< 0 || timer
) {
161 printk(KERN_INFO
"oprofile: using timer interrupt.\n");
162 oprofile_timer_init(&oprofile_ops
);
165 err
= oprofilefs_register();
167 oprofile_arch_exit();
173 static void __exit
oprofile_exit(void)
175 oprofilefs_unregister();
176 oprofile_arch_exit();
180 module_init(oprofile_init
);
181 module_exit(oprofile_exit
);
183 module_param_named(timer
, timer
, int, 0644);
184 MODULE_PARM_DESC(timer
, "force use of timer interrupt");
186 MODULE_LICENSE("GPL");
187 MODULE_AUTHOR("John Levon <levon@movementarian.org>");
188 MODULE_DESCRIPTION("OProfile system profiler");