aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert Richter <robert.richter@amd.com>2009-06-19 10:45:34 -0400
committerRobert Richter <robert.richter@amd.com>2009-07-20 10:43:19 -0400
commita5659d17adb815fb35e11745e2f39c3f0bfd579f (patch)
tree5a7b151a9bbf0d9ec4c38e828e213ac9915f0483
parent16422a6e2d16a39861ae5b0b11d9b411a245ab83 (diff)
oprofile: Grouping multiplexing code in oprof.c
This patch moves multiplexing code to a single section of code. This reduces the use of #ifdefs especially within functions. Signed-off-by: Robert Richter <robert.richter@amd.com>
-rw-r--r--drivers/oprofile/oprof.c100
1 files changed, 49 insertions, 51 deletions
diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
index fa6cccd87cf8..a48294a8ebe8 100644
--- a/drivers/oprofile/oprof.c
+++ b/drivers/oprofile/oprof.c
@@ -29,13 +29,6 @@ unsigned long oprofile_backtrace_depth;
29static unsigned long is_setup; 29static unsigned long is_setup;
30static DEFINE_MUTEX(start_mutex); 30static DEFINE_MUTEX(start_mutex);
31 31
32#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
33
34static void switch_worker(struct work_struct *work);
35static DECLARE_DELAYED_WORK(switch_work, switch_worker);
36
37#endif
38
39/* timer 32/* timer
40 0 - use performance monitoring hardware if available 33 0 - use performance monitoring hardware if available
41 1 - use the timer int mechanism regardless 34 1 - use the timer int mechanism regardless
@@ -98,9 +91,18 @@ out:
98 91
99#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX 92#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
100 93
94static void switch_worker(struct work_struct *work);
95static DECLARE_DELAYED_WORK(switch_work, switch_worker);
96
101static void start_switch_worker(void) 97static void start_switch_worker(void)
102{ 98{
103 schedule_delayed_work(&switch_work, oprofile_time_slice); 99 if (oprofile_ops.switch_events)
100 schedule_delayed_work(&switch_work, oprofile_time_slice);
101}
102
103static void stop_switch_worker(void)
104{
105 cancel_delayed_work_sync(&switch_work);
104} 106}
105 107
106static void switch_worker(struct work_struct *work) 108static void switch_worker(struct work_struct *work)
@@ -109,6 +111,43 @@ static void switch_worker(struct work_struct *work)
109 start_switch_worker(); 111 start_switch_worker();
110} 112}
111 113
114/* User inputs in ms, converts to jiffies */
115int oprofile_set_timeout(unsigned long val_msec)
116{
117 int err = 0;
118 unsigned long time_slice;
119
120 mutex_lock(&start_mutex);
121
122 if (oprofile_started) {
123 err = -EBUSY;
124 goto out;
125 }
126
127 if (!oprofile_ops.switch_events) {
128 err = -EINVAL;
129 goto out;
130 }
131
132 time_slice = msecs_to_jiffies(val_msec);
133 if (time_slice == MAX_JIFFY_OFFSET) {
134 err = -EINVAL;
135 goto out;
136 }
137
138 oprofile_time_slice = time_slice;
139
140out:
141 mutex_unlock(&start_mutex);
142 return err;
143
144}
145
146#else
147
148static inline void start_switch_worker(void) { }
149static inline void stop_switch_worker(void) { }
150
112#endif 151#endif
113 152
114/* Actually start profiling (echo 1>/dev/oprofile/enable) */ 153/* Actually start profiling (echo 1>/dev/oprofile/enable) */
@@ -131,10 +170,7 @@ int oprofile_start(void)
131 if ((err = oprofile_ops.start())) 170 if ((err = oprofile_ops.start()))
132 goto out; 171 goto out;
133 172
134#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX 173 start_switch_worker();
135 if (oprofile_ops.switch_events)
136 start_switch_worker();
137#endif
138 174
139 oprofile_started = 1; 175 oprofile_started = 1;
140out: 176out:
@@ -152,9 +188,7 @@ void oprofile_stop(void)
152 oprofile_ops.stop(); 188 oprofile_ops.stop();
153 oprofile_started = 0; 189 oprofile_started = 0;
154 190
155#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX 191 stop_switch_worker();
156 cancel_delayed_work_sync(&switch_work);
157#endif
158 192
159 /* wake up the daemon to read what remains */ 193 /* wake up the daemon to read what remains */
160 wake_up_buffer_waiter(); 194 wake_up_buffer_waiter();
@@ -188,42 +222,6 @@ post_sync:
188 mutex_unlock(&start_mutex); 222 mutex_unlock(&start_mutex);
189} 223}
190 224
191#ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
192
193/* User inputs in ms, converts to jiffies */
194int oprofile_set_timeout(unsigned long val_msec)
195{
196 int err = 0;
197 unsigned long time_slice;
198
199 mutex_lock(&start_mutex);
200
201 if (oprofile_started) {
202 err = -EBUSY;
203 goto out;
204 }
205
206 if (!oprofile_ops.switch_events) {
207 err = -EINVAL;
208 goto out;
209 }
210
211 time_slice = msecs_to_jiffies(val_msec);
212 if (time_slice == MAX_JIFFY_OFFSET) {
213 err = -EINVAL;
214 goto out;
215 }
216
217 oprofile_time_slice = time_slice;
218
219out:
220 mutex_unlock(&start_mutex);
221 return err;
222
223}
224
225#endif
226
227int oprofile_set_backtrace(unsigned long val) 225int oprofile_set_backtrace(unsigned long val)
228{ 226{
229 int err = 0; 227 int err = 0;