aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/oprofile/oprof.c
diff options
context:
space:
mode:
authorJason Yeh <jason.yeh@amd.com>2008-07-23 17:05:53 -0400
committerIngo Molnar <mingo@elte.hu>2008-07-26 05:48:16 -0400
commit1a960b402a51d80abf54e3f8e4972374ffe5f22d (patch)
tree108222afe94df145e7a71f44bb077067c35f0131 /drivers/oprofile/oprof.c
parent6852fd9b86d05063c6ef49d2e12e061cc7f6a105 (diff)
Oprofile Multiplexing Patch
This patch introduces multiplexing support for the Oprofile kernel module. It basically adds a new function pointer in oprofile_operator allowing each architecture to supply its callback to switch between different sets of event when the timer expires. Userspace tools can modify the time slice through /dev/oprofile/time_slice. It also modifies the number of counters exposed to the userspace through /dev/oprofile. For example, the number of counters for AMD CPUs are changed to 32 and multiplexed in the sets of 4. Signed-off-by: Jason Yeh <jason.yeh@amd.com> Signed-off-by: Robert Richter <robert.richter@amd.com> Cc: oprofile-list <oprofile-list@lists.sourceforge.net> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'drivers/oprofile/oprof.c')
-rw-r--r--drivers/oprofile/oprof.c58
1 files changed, 55 insertions, 3 deletions
diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
index 2c645170f06e..b2fa5df64a62 100644
--- a/drivers/oprofile/oprof.c
+++ b/drivers/oprofile/oprof.c
@@ -12,6 +12,8 @@
12#include <linux/init.h> 12#include <linux/init.h>
13#include <linux/oprofile.h> 13#include <linux/oprofile.h>
14#include <linux/moduleparam.h> 14#include <linux/moduleparam.h>
15#include <linux/workqueue.h>
16#include <linux/time.h>
15#include <asm/mutex.h> 17#include <asm/mutex.h>
16 18
17#include "oprof.h" 19#include "oprof.h"
@@ -19,13 +21,18 @@
19#include "cpu_buffer.h" 21#include "cpu_buffer.h"
20#include "buffer_sync.h" 22#include "buffer_sync.h"
21#include "oprofile_stats.h" 23#include "oprofile_stats.h"
24
25static unsigned long is_setup;
26static void switch_worker(struct work_struct *work);
27static DECLARE_DELAYED_WORK(switch_work, switch_worker);
28static DEFINE_MUTEX(start_mutex);
22 29
23struct oprofile_operations oprofile_ops; 30struct oprofile_operations oprofile_ops;
24 31
32unsigned long timeout_jiffies;
25unsigned long oprofile_started; 33unsigned long oprofile_started;
26unsigned long backtrace_depth; 34unsigned long backtrace_depth;
27static unsigned long is_setup; 35/* Multiplexing defaults at 1 msec*/
28static DEFINE_MUTEX(start_mutex);
29 36
30/* timer 37/* timer
31 0 - use performance monitoring hardware if available 38 0 - use performance monitoring hardware if available
@@ -87,6 +94,16 @@ out:
87 return err; 94 return err;
88} 95}
89 96
97static void start_switch_worker(void)
98{
99 schedule_delayed_work(&switch_work, timeout_jiffies);
100}
101
102static void switch_worker(struct work_struct *work)
103{
104 if (!oprofile_ops.switch_events())
105 start_switch_worker();
106}
90 107
91/* Actually start profiling (echo 1>/dev/oprofile/enable) */ 108/* Actually start profiling (echo 1>/dev/oprofile/enable) */
92int oprofile_start(void) 109int oprofile_start(void)
@@ -94,7 +111,6 @@ int oprofile_start(void)
94 int err = -EINVAL; 111 int err = -EINVAL;
95 112
96 mutex_lock(&start_mutex); 113 mutex_lock(&start_mutex);
97
98 if (!is_setup) 114 if (!is_setup)
99 goto out; 115 goto out;
100 116
@@ -108,6 +124,9 @@ int oprofile_start(void)
108 if ((err = oprofile_ops.start())) 124 if ((err = oprofile_ops.start()))
109 goto out; 125 goto out;
110 126
127 if (oprofile_ops.switch_events)
128 start_switch_worker();
129
111 oprofile_started = 1; 130 oprofile_started = 1;
112out: 131out:
113 mutex_unlock(&start_mutex); 132 mutex_unlock(&start_mutex);
@@ -123,6 +142,7 @@ void oprofile_stop(void)
123 goto out; 142 goto out;
124 oprofile_ops.stop(); 143 oprofile_ops.stop();
125 oprofile_started = 0; 144 oprofile_started = 0;
145 cancel_delayed_work_sync(&switch_work);
126 /* wake up the daemon to read what remains */ 146 /* wake up the daemon to read what remains */
127 wake_up_buffer_waiter(); 147 wake_up_buffer_waiter();
128out: 148out:
@@ -155,6 +175,32 @@ post_sync:
155 mutex_unlock(&start_mutex); 175 mutex_unlock(&start_mutex);
156} 176}
157 177
178/* User inputs in ms, converts to jiffies */
179int oprofile_set_timeout(unsigned long val_msec)
180{
181 int err = 0;
182
183 mutex_lock(&start_mutex);
184
185 if (oprofile_started) {
186 err = -EBUSY;
187 goto out;
188 }
189
190 if (!oprofile_ops.switch_events) {
191 err = -EINVAL;
192 goto out;
193 }
194
195 timeout_jiffies = msecs_to_jiffies(val_msec);
196 if (timeout_jiffies == MAX_JIFFY_OFFSET)
197 timeout_jiffies = msecs_to_jiffies(1);
198
199out:
200 mutex_unlock(&start_mutex);
201 return err;
202
203}
158 204
159int oprofile_set_backtrace(unsigned long val) 205int oprofile_set_backtrace(unsigned long val)
160{ 206{
@@ -179,10 +225,16 @@ out:
179 return err; 225 return err;
180} 226}
181 227
228static void __init oprofile_switch_timer_init(void)
229{
230 timeout_jiffies = msecs_to_jiffies(1);
231}
232
182static int __init oprofile_init(void) 233static int __init oprofile_init(void)
183{ 234{
184 int err; 235 int err;
185 236
237 oprofile_switch_timer_init();
186 err = oprofile_arch_init(&oprofile_ops); 238 err = oprofile_arch_init(&oprofile_ops);
187 239
188 if (err < 0 || timer) { 240 if (err < 0 || timer) {