blob: a7aae24f2889a4578ebd90dad52ae72aab916116 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/**
2 * @file cpu_buffer.c
3 *
Robert Richter2cc28b92008-12-25 17:26:07 +01004 * @remark Copyright 2002-2009 OProfile authors
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * @remark Read the file COPYING
6 *
7 * @author John Levon <levon@movementarian.org>
Barry Kasindorf345c2572008-07-22 21:08:54 +02008 * @author Barry Kasindorf <barry.kasindorf@amd.com>
Robert Richter2cc28b92008-12-25 17:26:07 +01009 * @author Robert Richter <robert.richter@amd.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * Each CPU has a local buffer that stores PC value/event
12 * pairs. We also log context switches when we notice them.
13 * Eventually each CPU's buffer is processed into the global
14 * event buffer by sync_buffer().
15 *
16 * We use a local buffer for two reasons: an NMI or similar
17 * interrupt cannot synchronise, and high sampling rates
18 * would lead to catastrophic global synchronisation if
19 * a global buffer was used.
20 */
21
22#include <linux/sched.h>
23#include <linux/oprofile.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070024#include <linux/errno.h>
Robert Richter6a180372008-10-16 15:01:40 +020025
Linus Torvalds1da177e2005-04-16 15:20:36 -070026#include "event_buffer.h"
27#include "cpu_buffer.h"
28#include "buffer_sync.h"
29#include "oprof.h"
30
Robert Richter6dad8282008-12-09 01:21:32 +010031#define OP_BUFFER_FLAGS 0
32
33/*
34 * Read and write access is using spin locking. Thus, writing to the
35 * buffer by NMI handler (x86) could occur also during critical
36 * sections when reading the buffer. To avoid this, there are 2
37 * buffers for independent read and write access. Read access is in
38 * process context only, write access only in the NMI handler. If the
39 * read buffer runs empty, both buffers are swapped atomically. There
40 * is potentially a small window during swapping where the buffers are
41 * disabled and samples could be lost.
42 *
43 * Using 2 buffers is a little bit overhead, but the solution is clear
44 * and does not require changes in the ring buffer implementation. It
45 * can be changed to a single buffer solution when the ring buffer
46 * access is implemented as non-locking atomic code.
47 */
Robert Richter99667182008-12-16 16:19:54 +010048static struct ring_buffer *op_ring_buffer_read;
49static struct ring_buffer *op_ring_buffer_write;
Eric Dumazet8b8b4982008-05-14 16:05:31 -070050DEFINE_PER_CPU(struct oprofile_cpu_buffer, cpu_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
David Howellsc4028952006-11-22 14:57:56 +000052static void wq_sync_buffer(struct work_struct *work);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54#define DEFAULT_TIMER_EXPIRE (HZ / 10)
55static int work_enabled;
56
Carl Lovea5598ca2008-10-14 23:37:01 +000057unsigned long oprofile_get_cpu_buffer_size(void)
58{
Robert Richterbd2172f2008-12-16 16:19:54 +010059 return oprofile_cpu_buffer_size;
Carl Lovea5598ca2008-10-14 23:37:01 +000060}
61
62void oprofile_cpu_buffer_inc_smpl_lost(void)
63{
64 struct oprofile_cpu_buffer *cpu_buf
65 = &__get_cpu_var(cpu_buffer);
66
67 cpu_buf->sample_lost_overflow++;
68}
69
Robert Richter30015772008-12-23 01:35:12 +010070void free_cpu_buffers(void)
71{
72 if (op_ring_buffer_read)
73 ring_buffer_free(op_ring_buffer_read);
74 op_ring_buffer_read = NULL;
75 if (op_ring_buffer_write)
76 ring_buffer_free(op_ring_buffer_write);
77 op_ring_buffer_write = NULL;
78}
79
Robert Richter54f2c842009-05-07 17:28:59 +020080#define RB_EVENT_HDR_SIZE 4
81
Linus Torvalds1da177e2005-04-16 15:20:36 -070082int alloc_cpu_buffers(void)
83{
84 int i;
Robert Richter6a180372008-10-16 15:01:40 +020085
Robert Richterbd2172f2008-12-16 16:19:54 +010086 unsigned long buffer_size = oprofile_cpu_buffer_size;
Robert Richter54f2c842009-05-07 17:28:59 +020087 unsigned long byte_size = buffer_size * (sizeof(struct op_sample) +
88 RB_EVENT_HDR_SIZE);
Robert Richter6a180372008-10-16 15:01:40 +020089
Robert Richter54f2c842009-05-07 17:28:59 +020090 op_ring_buffer_read = ring_buffer_alloc(byte_size, OP_BUFFER_FLAGS);
Robert Richter6dad8282008-12-09 01:21:32 +010091 if (!op_ring_buffer_read)
92 goto fail;
Robert Richter54f2c842009-05-07 17:28:59 +020093 op_ring_buffer_write = ring_buffer_alloc(byte_size, OP_BUFFER_FLAGS);
Robert Richter6dad8282008-12-09 01:21:32 +010094 if (!op_ring_buffer_write)
95 goto fail;
96
Chris J Arges4bd9b9d2008-10-15 11:03:39 -050097 for_each_possible_cpu(i) {
Mike Travis608dfdd2008-04-28 02:14:15 -070098 struct oprofile_cpu_buffer *b = &per_cpu(cpu_buffer, i);
Robert Richter6a180372008-10-16 15:01:40 +020099
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 b->last_task = NULL;
101 b->last_is_kernel = -1;
102 b->tracing = 0;
103 b->buffer_size = buffer_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 b->sample_received = 0;
105 b->sample_lost_overflow = 0;
Philippe Eliedf9d1772007-11-14 16:58:48 -0800106 b->backtrace_aborted = 0;
107 b->sample_invalid_eip = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 b->cpu = i;
David Howellsc4028952006-11-22 14:57:56 +0000109 INIT_DELAYED_WORK(&b->work, wq_sync_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 }
111 return 0;
112
113fail:
114 free_cpu_buffers();
115 return -ENOMEM;
116}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118void start_cpu_work(void)
119{
120 int i;
121
122 work_enabled = 1;
123
124 for_each_online_cpu(i) {
Mike Travis608dfdd2008-04-28 02:14:15 -0700125 struct oprofile_cpu_buffer *b = &per_cpu(cpu_buffer, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
127 /*
128 * Spread the work by 1 jiffy per cpu so they dont all
129 * fire at once.
130 */
131 schedule_delayed_work_on(i, &b->work, DEFAULT_TIMER_EXPIRE + i);
132 }
133}
134
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135void end_cpu_work(void)
136{
137 int i;
138
139 work_enabled = 0;
140
141 for_each_online_cpu(i) {
Mike Travis608dfdd2008-04-28 02:14:15 -0700142 struct oprofile_cpu_buffer *b = &per_cpu(cpu_buffer, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144 cancel_delayed_work(&b->work);
145 }
146
147 flush_scheduled_work();
148}
149
Robert Richter2cc28b92008-12-25 17:26:07 +0100150/*
151 * This function prepares the cpu buffer to write a sample.
152 *
153 * Struct op_entry is used during operations on the ring buffer while
154 * struct op_sample contains the data that is stored in the ring
155 * buffer. Struct entry can be uninitialized. The function reserves a
156 * data array that is specified by size. Use
157 * op_cpu_buffer_write_commit() after preparing the sample. In case of
158 * errors a null pointer is returned, otherwise the pointer to the
159 * sample.
160 *
161 */
162struct op_sample
163*op_cpu_buffer_write_reserve(struct op_entry *entry, unsigned long size)
Robert Richter99667182008-12-16 16:19:54 +0100164{
Robert Richter2cc28b92008-12-25 17:26:07 +0100165 entry->event = ring_buffer_lock_reserve
166 (op_ring_buffer_write, sizeof(struct op_sample) +
Ingo Molnar304cc6a2009-02-06 01:12:02 +0100167 size * sizeof(entry->sample->data[0]));
Robert Richter99667182008-12-16 16:19:54 +0100168 if (entry->event)
169 entry->sample = ring_buffer_event_data(entry->event);
170 else
171 entry->sample = NULL;
172
173 if (!entry->sample)
Robert Richter2cc28b92008-12-25 17:26:07 +0100174 return NULL;
Robert Richter99667182008-12-16 16:19:54 +0100175
Robert Richter2cc28b92008-12-25 17:26:07 +0100176 entry->size = size;
177 entry->data = entry->sample->data;
178
179 return entry->sample;
Robert Richter99667182008-12-16 16:19:54 +0100180}
181
182int op_cpu_buffer_write_commit(struct op_entry *entry)
183{
Ingo Molnar304cc6a2009-02-06 01:12:02 +0100184 return ring_buffer_unlock_commit(op_ring_buffer_write, entry->event);
Robert Richter99667182008-12-16 16:19:54 +0100185}
186
Robert Richter2d87b142008-12-30 04:10:46 +0100187struct op_sample *op_cpu_buffer_read_entry(struct op_entry *entry, int cpu)
Robert Richter99667182008-12-16 16:19:54 +0100188{
189 struct ring_buffer_event *e;
190 e = ring_buffer_consume(op_ring_buffer_read, cpu, NULL);
191 if (e)
Robert Richter2d87b142008-12-30 04:10:46 +0100192 goto event;
Robert Richter99667182008-12-16 16:19:54 +0100193 if (ring_buffer_swap_cpu(op_ring_buffer_read,
194 op_ring_buffer_write,
195 cpu))
196 return NULL;
197 e = ring_buffer_consume(op_ring_buffer_read, cpu, NULL);
198 if (e)
Robert Richter2d87b142008-12-30 04:10:46 +0100199 goto event;
Robert Richter99667182008-12-16 16:19:54 +0100200 return NULL;
Robert Richter2d87b142008-12-30 04:10:46 +0100201
202event:
203 entry->event = e;
204 entry->sample = ring_buffer_event_data(e);
205 entry->size = (ring_buffer_event_length(e) - sizeof(struct op_sample))
206 / sizeof(entry->sample->data[0]);
207 entry->data = entry->sample->data;
208 return entry->sample;
Robert Richter99667182008-12-16 16:19:54 +0100209}
210
211unsigned long op_cpu_buffer_entries(int cpu)
212{
213 return ring_buffer_entries_cpu(op_ring_buffer_read, cpu)
214 + ring_buffer_entries_cpu(op_ring_buffer_write, cpu);
215}
216
Robert Richterae735e92008-12-25 17:26:07 +0100217static int
218op_add_code(struct oprofile_cpu_buffer *cpu_buf, unsigned long backtrace,
219 int is_kernel, struct task_struct *task)
220{
221 struct op_entry entry;
222 struct op_sample *sample;
223 unsigned long flags;
224 int size;
225
226 flags = 0;
227
228 if (backtrace)
229 flags |= TRACE_BEGIN;
230
231 /* notice a switch from user->kernel or vice versa */
232 is_kernel = !!is_kernel;
233 if (cpu_buf->last_is_kernel != is_kernel) {
234 cpu_buf->last_is_kernel = is_kernel;
235 flags |= KERNEL_CTX_SWITCH;
236 if (is_kernel)
237 flags |= IS_KERNEL;
238 }
239
240 /* notice a task switch */
241 if (cpu_buf->last_task != task) {
242 cpu_buf->last_task = task;
243 flags |= USER_CTX_SWITCH;
244 }
245
246 if (!flags)
247 /* nothing to do */
248 return 0;
249
250 if (flags & USER_CTX_SWITCH)
251 size = 1;
252 else
253 size = 0;
254
255 sample = op_cpu_buffer_write_reserve(&entry, size);
256 if (!sample)
257 return -ENOMEM;
258
259 sample->eip = ESCAPE_CODE;
260 sample->event = flags;
261
262 if (size)
Robert Richterd9928c22008-12-25 17:26:07 +0100263 op_cpu_buffer_add_data(&entry, (unsigned long)task);
Robert Richterae735e92008-12-25 17:26:07 +0100264
265 op_cpu_buffer_write_commit(&entry);
266
267 return 0;
268}
269
Robert Richter211117f2008-12-09 02:13:25 +0100270static inline int
Robert Richterd0e23382008-12-23 04:03:05 +0100271op_add_sample(struct oprofile_cpu_buffer *cpu_buf,
272 unsigned long pc, unsigned long event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273{
Robert Richter6dad8282008-12-09 01:21:32 +0100274 struct op_entry entry;
Robert Richter2cc28b92008-12-25 17:26:07 +0100275 struct op_sample *sample;
Robert Richter6dad8282008-12-09 01:21:32 +0100276
Robert Richter2cc28b92008-12-25 17:26:07 +0100277 sample = op_cpu_buffer_write_reserve(&entry, 0);
278 if (!sample)
279 return -ENOMEM;
Robert Richter6dad8282008-12-09 01:21:32 +0100280
Robert Richter2cc28b92008-12-25 17:26:07 +0100281 sample->eip = pc;
282 sample->event = event;
Robert Richter6dad8282008-12-09 01:21:32 +0100283
Robert Richter3967e932008-12-30 05:10:58 +0100284 return op_cpu_buffer_write_commit(&entry);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285}
286
Robert Richterae735e92008-12-25 17:26:07 +0100287/*
288 * This must be safe from any context.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 *
290 * is_kernel is needed because on some architectures you cannot
291 * tell if you are in kernel or user space simply by looking at
292 * pc. We tag this in the buffer by generating kernel enter/exit
293 * events whenever is_kernel changes
294 */
Robert Richterae735e92008-12-25 17:26:07 +0100295static int
296log_sample(struct oprofile_cpu_buffer *cpu_buf, unsigned long pc,
297 unsigned long backtrace, int is_kernel, unsigned long event)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 cpu_buf->sample_received++;
300
Philippe Eliedf9d1772007-11-14 16:58:48 -0800301 if (pc == ESCAPE_CODE) {
302 cpu_buf->sample_invalid_eip++;
303 return 0;
304 }
305
Robert Richterae735e92008-12-25 17:26:07 +0100306 if (op_add_code(cpu_buf, backtrace, is_kernel, current))
307 goto fail;
Robert Richter6a180372008-10-16 15:01:40 +0200308
Robert Richterd0e23382008-12-23 04:03:05 +0100309 if (op_add_sample(cpu_buf, pc, event))
Robert Richter211117f2008-12-09 02:13:25 +0100310 goto fail;
311
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 return 1;
Robert Richter211117f2008-12-09 02:13:25 +0100313
314fail:
315 cpu_buf->sample_lost_overflow++;
316 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317}
318
Robert Richter6352d922008-12-18 22:09:13 +0100319static inline void oprofile_begin_trace(struct oprofile_cpu_buffer *cpu_buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 cpu_buf->tracing = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322}
323
Robert Richter6352d922008-12-18 22:09:13 +0100324static inline void oprofile_end_trace(struct oprofile_cpu_buffer *cpu_buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325{
326 cpu_buf->tracing = 0;
327}
328
Robert Richterd45d23b2008-12-16 12:00:10 +0100329static inline void
330__oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs,
331 unsigned long event, int is_kernel)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
Mike Travis608dfdd2008-04-28 02:14:15 -0700333 struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer);
Robert Richterae735e92008-12-25 17:26:07 +0100334 unsigned long backtrace = oprofile_backtrace_depth;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335
Robert Richterfd13f6c2008-10-19 21:00:09 +0200336 /*
337 * if log_sample() fail we can't backtrace since we lost the
338 * source of this event
339 */
Robert Richterae735e92008-12-25 17:26:07 +0100340 if (!log_sample(cpu_buf, pc, backtrace, is_kernel, event))
341 /* failed */
342 return;
Robert Richter6352d922008-12-18 22:09:13 +0100343
Robert Richterae735e92008-12-25 17:26:07 +0100344 if (!backtrace)
345 return;
346
347 oprofile_begin_trace(cpu_buf);
348 oprofile_ops.backtrace(regs, backtrace);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 oprofile_end_trace(cpu_buf);
350}
351
Robert Richterd45d23b2008-12-16 12:00:10 +0100352void oprofile_add_ext_sample(unsigned long pc, struct pt_regs * const regs,
353 unsigned long event, int is_kernel)
354{
355 __oprofile_add_ext_sample(pc, regs, event, is_kernel);
356}
357
Brian Rogan27357712006-03-28 01:56:20 -0800358void oprofile_add_sample(struct pt_regs * const regs, unsigned long event)
359{
360 int is_kernel = !user_mode(regs);
361 unsigned long pc = profile_pc(regs);
362
Robert Richterd45d23b2008-12-16 12:00:10 +0100363 __oprofile_add_ext_sample(pc, regs, event, is_kernel);
Brian Rogan27357712006-03-28 01:56:20 -0800364}
365
Robert Richter1acda872009-01-05 10:35:31 +0100366/*
367 * Add samples with data to the ring buffer.
368 *
Robert Richter14f0ca82009-01-07 21:50:22 +0100369 * Use oprofile_add_data(&entry, val) to add data and
370 * oprofile_write_commit(&entry) to commit the sample.
Robert Richter1acda872009-01-05 10:35:31 +0100371 */
Robert Richter14f0ca82009-01-07 21:50:22 +0100372void
373oprofile_write_reserve(struct op_entry *entry, struct pt_regs * const regs,
Robert Richter1acda872009-01-05 10:35:31 +0100374 unsigned long pc, int code, int size)
Barry Kasindorf345c2572008-07-22 21:08:54 +0200375{
Robert Richter1acda872009-01-05 10:35:31 +0100376 struct op_sample *sample;
Robert Richtere2fee272008-07-18 17:36:20 +0200377 int is_kernel = !user_mode(regs);
378 struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer);
Barry Kasindorf345c2572008-07-22 21:08:54 +0200379
380 cpu_buf->sample_received++;
381
Robert Richter1acda872009-01-05 10:35:31 +0100382 /* no backtraces for samples with data */
383 if (op_add_code(cpu_buf, 0, is_kernel, current))
384 goto fail;
Barry Kasindorf345c2572008-07-22 21:08:54 +0200385
Robert Richter1acda872009-01-05 10:35:31 +0100386 sample = op_cpu_buffer_write_reserve(entry, size + 2);
387 if (!sample)
388 goto fail;
389 sample->eip = ESCAPE_CODE;
390 sample->event = 0; /* no flags */
Barry Kasindorf345c2572008-07-22 21:08:54 +0200391
Robert Richter1acda872009-01-05 10:35:31 +0100392 op_cpu_buffer_add_data(entry, code);
393 op_cpu_buffer_add_data(entry, pc);
Barry Kasindorf345c2572008-07-22 21:08:54 +0200394
Robert Richter1acda872009-01-05 10:35:31 +0100395 return;
396
397fail:
Robert Richterfdb6a8f2009-01-17 17:13:27 +0100398 entry->event = NULL;
Robert Richter1acda872009-01-05 10:35:31 +0100399 cpu_buf->sample_lost_overflow++;
Barry Kasindorf345c2572008-07-22 21:08:54 +0200400}
401
Robert Richter14f0ca82009-01-07 21:50:22 +0100402int oprofile_add_data(struct op_entry *entry, unsigned long val)
403{
Robert Richterfdb6a8f2009-01-17 17:13:27 +0100404 if (!entry->event)
405 return 0;
Robert Richter14f0ca82009-01-07 21:50:22 +0100406 return op_cpu_buffer_add_data(entry, val);
407}
408
Robert Richter51563a02009-06-03 20:54:56 +0200409int oprofile_add_data64(struct op_entry *entry, u64 val)
410{
411 if (!entry->event)
412 return 0;
413 if (op_cpu_buffer_get_size(entry) < 2)
414 /*
415 * the function returns 0 to indicate a too small
416 * buffer, even if there is some space left
417 */
418 return 0;
419 if (!op_cpu_buffer_add_data(entry, (u32)val))
420 return 0;
421 return op_cpu_buffer_add_data(entry, (u32)(val >> 32));
422}
423
Robert Richter14f0ca82009-01-07 21:50:22 +0100424int oprofile_write_commit(struct op_entry *entry)
425{
Robert Richterfdb6a8f2009-01-17 17:13:27 +0100426 if (!entry->event)
427 return -EINVAL;
Robert Richter14f0ca82009-01-07 21:50:22 +0100428 return op_cpu_buffer_write_commit(entry);
429}
430
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431void oprofile_add_pc(unsigned long pc, int is_kernel, unsigned long event)
432{
Mike Travis608dfdd2008-04-28 02:14:15 -0700433 struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer);
Robert Richterae735e92008-12-25 17:26:07 +0100434 log_sample(cpu_buf, pc, 0, is_kernel, event);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435}
436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437void oprofile_add_trace(unsigned long pc)
438{
Mike Travis608dfdd2008-04-28 02:14:15 -0700439 struct oprofile_cpu_buffer *cpu_buf = &__get_cpu_var(cpu_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
441 if (!cpu_buf->tracing)
442 return;
443
Robert Richterfd13f6c2008-10-19 21:00:09 +0200444 /*
445 * broken frame can give an eip with the same value as an
446 * escape code, abort the trace if we get it
447 */
Robert Richter211117f2008-12-09 02:13:25 +0100448 if (pc == ESCAPE_CODE)
449 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
Robert Richterd0e23382008-12-23 04:03:05 +0100451 if (op_add_sample(cpu_buf, pc, 0))
Robert Richter211117f2008-12-09 02:13:25 +0100452 goto fail;
453
454 return;
455fail:
456 cpu_buf->tracing = 0;
457 cpu_buf->backtrace_aborted++;
458 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459}
460
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461/*
462 * This serves to avoid cpu buffer overflow, and makes sure
463 * the task mortuary progresses
464 *
465 * By using schedule_delayed_work_on and then schedule_delayed_work
466 * we guarantee this will stay on the correct cpu
467 */
David Howellsc4028952006-11-22 14:57:56 +0000468static void wq_sync_buffer(struct work_struct *work)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469{
Robert Richter25ad29132008-09-05 17:12:36 +0200470 struct oprofile_cpu_buffer *b =
David Howellsc4028952006-11-22 14:57:56 +0000471 container_of(work, struct oprofile_cpu_buffer, work.work);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 if (b->cpu != smp_processor_id()) {
Robert Richterbd17b622008-07-22 21:09:07 +0200473 printk(KERN_DEBUG "WQ on CPU%d, prefer CPU%d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 smp_processor_id(), b->cpu);
Chris J Arges4bd9b9d2008-10-15 11:03:39 -0500475
476 if (!cpu_online(b->cpu)) {
477 cancel_delayed_work(&b->work);
478 return;
479 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 }
481 sync_buffer(b->cpu);
482
483 /* don't re-add the work if we're shutting down */
484 if (work_enabled)
485 schedule_delayed_work(&b->work, DEFAULT_TIMER_EXPIRE);
486}