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/mutex.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 DEFINE_MUTEX(start_mutex);
35 0 - use performance monitoring hardware if available
36 1 - use the timer int mechanism regardless
40 int oprofile_set_active(int active_domains[], unsigned int adomains)
44 if (!oprofile_ops.set_active)
47 mutex_lock(&start_mutex);
48 err = oprofile_ops.set_active(active_domains, adomains);
49 mutex_unlock(&start_mutex);
53 int oprofile_set_passive(int passive_domains[], unsigned int pdomains)
57 if (!oprofile_ops.set_passive)
60 mutex_lock(&start_mutex);
61 err = oprofile_ops.set_passive(passive_domains, pdomains);
62 mutex_unlock(&start_mutex);
66 int oprofile_setup(void)
70 mutex_lock(&start_mutex);
72 if ((err = alloc_cpu_buffers()))
75 if ((err = alloc_event_buffer()))
78 if (oprofile_ops.setup && (err = oprofile_ops.setup()))
81 /* Note even though this starts part of the
82 * profiling overhead, it's necessary to prevent
83 * us missing task deaths and eventually oopsing
84 * when trying to process the event buffer.
86 if ((err = sync_start()))
90 mutex_unlock(&start_mutex);
94 if (oprofile_ops.shutdown)
95 oprofile_ops.shutdown();
101 mutex_unlock(&start_mutex);
106 /* Actually start profiling (echo 1>/dev/oprofile/enable) */
107 int oprofile_start(void)
111 mutex_lock(&start_mutex);
118 if (oprofile_started)
121 oprofile_reset_stats();
123 if ((err = oprofile_ops.start()))
126 oprofile_started = 1;
128 mutex_unlock(&start_mutex);
133 /* echo 0>/dev/oprofile/enable */
134 void oprofile_stop(void)
136 mutex_lock(&start_mutex);
137 if (!oprofile_started)
140 oprofile_started = 0;
141 /* wake up the daemon to read what remains */
142 wake_up_buffer_waiter();
144 mutex_unlock(&start_mutex);
148 void oprofile_shutdown(void)
150 mutex_lock(&start_mutex);
152 if (oprofile_ops.shutdown)
153 oprofile_ops.shutdown();
157 mutex_unlock(&start_mutex);
161 int oprofile_set_backtrace(unsigned long val)
165 mutex_lock(&start_mutex);
167 if (oprofile_started) {
172 if (!oprofile_ops.backtrace) {
177 backtrace_depth = val;
180 mutex_unlock(&start_mutex);
184 static int __init oprofile_init(void)
188 err = oprofile_arch_init(&oprofile_ops);
190 if (err < 0 || timer) {
191 printk(KERN_INFO "oprofile: using timer interrupt.\n");
192 oprofile_timer_init(&oprofile_ops);
195 err = oprofilefs_register();
197 oprofile_arch_exit();
203 static void __exit oprofile_exit(void)
205 oprofilefs_unregister();
206 oprofile_arch_exit();
210 module_init(oprofile_init);
211 module_exit(oprofile_exit);
213 module_param_named(timer, timer, int, 0644);
214 MODULE_PARM_DESC(timer, "force use of timer interrupt");
216 MODULE_LICENSE("GPL");
217 MODULE_AUTHOR("John Levon <levon@movementarian.org>");
218 MODULE_DESCRIPTION("OProfile system profiler");