]>
Commit | Line | Data |
---|---|---|
b77e38aa SR |
1 | /* |
2 | * event tracer | |
3 | * | |
4 | * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> | |
5 | * | |
981d081e SR |
6 | * - Added format output of fields of the trace point. |
7 | * This was based off of work by Tom Zanussi <tzanussi@gmail.com>. | |
8 | * | |
b77e38aa SR |
9 | */ |
10 | ||
e6187007 SR |
11 | #include <linux/workqueue.h> |
12 | #include <linux/spinlock.h> | |
13 | #include <linux/kthread.h> | |
b77e38aa SR |
14 | #include <linux/debugfs.h> |
15 | #include <linux/uaccess.h> | |
16 | #include <linux/module.h> | |
17 | #include <linux/ctype.h> | |
5a0e3ad6 | 18 | #include <linux/slab.h> |
e6187007 | 19 | #include <linux/delay.h> |
b77e38aa | 20 | |
020e5f85 LZ |
21 | #include <asm/setup.h> |
22 | ||
91729ef9 | 23 | #include "trace_output.h" |
b77e38aa | 24 | |
4e5292ea | 25 | #undef TRACE_SYSTEM |
b628b3e6 SR |
26 | #define TRACE_SYSTEM "TRACE_SYSTEM" |
27 | ||
20c8928a | 28 | DEFINE_MUTEX(event_mutex); |
11a241a3 | 29 | |
04295780 SR |
30 | DEFINE_MUTEX(event_storage_mutex); |
31 | EXPORT_SYMBOL_GPL(event_storage_mutex); | |
32 | ||
33 | char event_storage[EVENT_STORAGE_SIZE]; | |
34 | EXPORT_SYMBOL_GPL(event_storage); | |
35 | ||
a59fd602 | 36 | LIST_HEAD(ftrace_events); |
b3a8c6fd | 37 | static LIST_HEAD(ftrace_common_fields); |
a59fd602 | 38 | |
d1a29143 SR |
39 | #define GFP_TRACE (GFP_KERNEL | __GFP_ZERO) |
40 | ||
41 | static struct kmem_cache *field_cachep; | |
42 | static struct kmem_cache *file_cachep; | |
43 | ||
6e94a780 SR |
44 | #define SYSTEM_FL_FREE_NAME (1 << 31) |
45 | ||
46 | static inline int system_refcount(struct event_subsystem *system) | |
47 | { | |
48 | return system->ref_count & ~SYSTEM_FL_FREE_NAME; | |
49 | } | |
50 | ||
51 | static int system_refcount_inc(struct event_subsystem *system) | |
52 | { | |
53 | return (system->ref_count++) & ~SYSTEM_FL_FREE_NAME; | |
54 | } | |
55 | ||
56 | static int system_refcount_dec(struct event_subsystem *system) | |
57 | { | |
58 | return (--system->ref_count) & ~SYSTEM_FL_FREE_NAME; | |
59 | } | |
60 | ||
ae63b31e SR |
61 | /* Double loops, do not use break, only goto's work */ |
62 | #define do_for_each_event_file(tr, file) \ | |
63 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { \ | |
64 | list_for_each_entry(file, &tr->events, list) | |
65 | ||
66 | #define do_for_each_event_file_safe(tr, file) \ | |
67 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { \ | |
68 | struct ftrace_event_file *___n; \ | |
69 | list_for_each_entry_safe(file, ___n, &tr->events, list) | |
70 | ||
71 | #define while_for_each_event_file() \ | |
72 | } | |
73 | ||
b3a8c6fd | 74 | static struct list_head * |
2e33af02 SR |
75 | trace_get_fields(struct ftrace_event_call *event_call) |
76 | { | |
77 | if (!event_call->class->get_fields) | |
78 | return &event_call->class->fields; | |
79 | return event_call->class->get_fields(event_call); | |
80 | } | |
81 | ||
b3a8c6fd J |
82 | static struct ftrace_event_field * |
83 | __find_event_field(struct list_head *head, char *name) | |
84 | { | |
85 | struct ftrace_event_field *field; | |
86 | ||
87 | list_for_each_entry(field, head, link) { | |
88 | if (!strcmp(field->name, name)) | |
89 | return field; | |
90 | } | |
91 | ||
92 | return NULL; | |
93 | } | |
94 | ||
95 | struct ftrace_event_field * | |
96 | trace_find_event_field(struct ftrace_event_call *call, char *name) | |
97 | { | |
98 | struct ftrace_event_field *field; | |
99 | struct list_head *head; | |
100 | ||
101 | field = __find_event_field(&ftrace_common_fields, name); | |
102 | if (field) | |
103 | return field; | |
104 | ||
105 | head = trace_get_fields(call); | |
106 | return __find_event_field(head, name); | |
107 | } | |
108 | ||
8728fe50 LZ |
109 | static int __trace_define_field(struct list_head *head, const char *type, |
110 | const char *name, int offset, int size, | |
111 | int is_signed, int filter_type) | |
cf027f64 TZ |
112 | { |
113 | struct ftrace_event_field *field; | |
114 | ||
d1a29143 | 115 | field = kmem_cache_alloc(field_cachep, GFP_TRACE); |
cf027f64 | 116 | if (!field) |
aaf6ac0f | 117 | return -ENOMEM; |
fe9f57f2 | 118 | |
92edca07 SR |
119 | field->name = name; |
120 | field->type = type; | |
fe9f57f2 | 121 | |
43b51ead LZ |
122 | if (filter_type == FILTER_OTHER) |
123 | field->filter_type = filter_assign_type(type); | |
124 | else | |
125 | field->filter_type = filter_type; | |
126 | ||
cf027f64 TZ |
127 | field->offset = offset; |
128 | field->size = size; | |
a118e4d1 | 129 | field->is_signed = is_signed; |
aa38e9fc | 130 | |
2e33af02 | 131 | list_add(&field->link, head); |
cf027f64 TZ |
132 | |
133 | return 0; | |
cf027f64 | 134 | } |
8728fe50 LZ |
135 | |
136 | int trace_define_field(struct ftrace_event_call *call, const char *type, | |
137 | const char *name, int offset, int size, int is_signed, | |
138 | int filter_type) | |
139 | { | |
140 | struct list_head *head; | |
141 | ||
142 | if (WARN_ON(!call->class)) | |
143 | return 0; | |
144 | ||
145 | head = trace_get_fields(call); | |
146 | return __trace_define_field(head, type, name, offset, size, | |
147 | is_signed, filter_type); | |
148 | } | |
17c873ec | 149 | EXPORT_SYMBOL_GPL(trace_define_field); |
cf027f64 | 150 | |
e647d6b3 | 151 | #define __common_field(type, item) \ |
8728fe50 LZ |
152 | ret = __trace_define_field(&ftrace_common_fields, #type, \ |
153 | "common_" #item, \ | |
154 | offsetof(typeof(ent), item), \ | |
155 | sizeof(ent.item), \ | |
156 | is_signed_type(type), FILTER_OTHER); \ | |
e647d6b3 LZ |
157 | if (ret) \ |
158 | return ret; | |
159 | ||
8728fe50 | 160 | static int trace_define_common_fields(void) |
e647d6b3 LZ |
161 | { |
162 | int ret; | |
163 | struct trace_entry ent; | |
164 | ||
165 | __common_field(unsigned short, type); | |
166 | __common_field(unsigned char, flags); | |
167 | __common_field(unsigned char, preempt_count); | |
168 | __common_field(int, pid); | |
e647d6b3 LZ |
169 | |
170 | return ret; | |
171 | } | |
172 | ||
ad7067ce | 173 | static void trace_destroy_fields(struct ftrace_event_call *call) |
2df75e41 LZ |
174 | { |
175 | struct ftrace_event_field *field, *next; | |
2e33af02 | 176 | struct list_head *head; |
2df75e41 | 177 | |
2e33af02 SR |
178 | head = trace_get_fields(call); |
179 | list_for_each_entry_safe(field, next, head, link) { | |
2df75e41 | 180 | list_del(&field->link); |
d1a29143 | 181 | kmem_cache_free(field_cachep, field); |
2df75e41 LZ |
182 | } |
183 | } | |
184 | ||
87d9b4e1 LZ |
185 | int trace_event_raw_init(struct ftrace_event_call *call) |
186 | { | |
187 | int id; | |
188 | ||
80decc70 | 189 | id = register_ftrace_event(&call->event); |
87d9b4e1 LZ |
190 | if (!id) |
191 | return -ENODEV; | |
87d9b4e1 LZ |
192 | |
193 | return 0; | |
194 | } | |
195 | EXPORT_SYMBOL_GPL(trace_event_raw_init); | |
196 | ||
ceec0b6f JO |
197 | int ftrace_event_reg(struct ftrace_event_call *call, |
198 | enum trace_reg type, void *data) | |
a1d0ce82 | 199 | { |
ae63b31e SR |
200 | struct ftrace_event_file *file = data; |
201 | ||
a1d0ce82 SR |
202 | switch (type) { |
203 | case TRACE_REG_REGISTER: | |
204 | return tracepoint_probe_register(call->name, | |
205 | call->class->probe, | |
ae63b31e | 206 | file); |
a1d0ce82 SR |
207 | case TRACE_REG_UNREGISTER: |
208 | tracepoint_probe_unregister(call->name, | |
209 | call->class->probe, | |
ae63b31e | 210 | file); |
a1d0ce82 SR |
211 | return 0; |
212 | ||
213 | #ifdef CONFIG_PERF_EVENTS | |
214 | case TRACE_REG_PERF_REGISTER: | |
215 | return tracepoint_probe_register(call->name, | |
216 | call->class->perf_probe, | |
217 | call); | |
218 | case TRACE_REG_PERF_UNREGISTER: | |
219 | tracepoint_probe_unregister(call->name, | |
220 | call->class->perf_probe, | |
221 | call); | |
222 | return 0; | |
ceec0b6f JO |
223 | case TRACE_REG_PERF_OPEN: |
224 | case TRACE_REG_PERF_CLOSE: | |
489c75c3 JO |
225 | case TRACE_REG_PERF_ADD: |
226 | case TRACE_REG_PERF_DEL: | |
ceec0b6f | 227 | return 0; |
a1d0ce82 SR |
228 | #endif |
229 | } | |
230 | return 0; | |
231 | } | |
232 | EXPORT_SYMBOL_GPL(ftrace_event_reg); | |
233 | ||
e870e9a1 LZ |
234 | void trace_event_enable_cmd_record(bool enable) |
235 | { | |
ae63b31e SR |
236 | struct ftrace_event_file *file; |
237 | struct trace_array *tr; | |
e870e9a1 LZ |
238 | |
239 | mutex_lock(&event_mutex); | |
ae63b31e SR |
240 | do_for_each_event_file(tr, file) { |
241 | ||
242 | if (!(file->flags & FTRACE_EVENT_FL_ENABLED)) | |
e870e9a1 LZ |
243 | continue; |
244 | ||
245 | if (enable) { | |
246 | tracing_start_cmdline_record(); | |
417944c4 | 247 | set_bit(FTRACE_EVENT_FL_RECORDED_CMD_BIT, &file->flags); |
e870e9a1 LZ |
248 | } else { |
249 | tracing_stop_cmdline_record(); | |
417944c4 | 250 | clear_bit(FTRACE_EVENT_FL_RECORDED_CMD_BIT, &file->flags); |
e870e9a1 | 251 | } |
ae63b31e | 252 | } while_for_each_event_file(); |
e870e9a1 LZ |
253 | mutex_unlock(&event_mutex); |
254 | } | |
255 | ||
417944c4 SRRH |
256 | static int __ftrace_event_enable_disable(struct ftrace_event_file *file, |
257 | int enable, int soft_disable) | |
fd994989 | 258 | { |
ae63b31e | 259 | struct ftrace_event_call *call = file->event_call; |
3b8e4273 | 260 | int ret = 0; |
417944c4 | 261 | int disable; |
3b8e4273 | 262 | |
fd994989 SR |
263 | switch (enable) { |
264 | case 0: | |
417944c4 | 265 | /* |
1cf4c073 MH |
266 | * When soft_disable is set and enable is cleared, the sm_ref |
267 | * reference counter is decremented. If it reaches 0, we want | |
417944c4 SRRH |
268 | * to clear the SOFT_DISABLED flag but leave the event in the |
269 | * state that it was. That is, if the event was enabled and | |
270 | * SOFT_DISABLED isn't set, then do nothing. But if SOFT_DISABLED | |
271 | * is set we do not want the event to be enabled before we | |
272 | * clear the bit. | |
273 | * | |
274 | * When soft_disable is not set but the SOFT_MODE flag is, | |
275 | * we do nothing. Do not disable the tracepoint, otherwise | |
276 | * "soft enable"s (clearing the SOFT_DISABLED bit) wont work. | |
277 | */ | |
278 | if (soft_disable) { | |
1cf4c073 MH |
279 | if (atomic_dec_return(&file->sm_ref) > 0) |
280 | break; | |
417944c4 SRRH |
281 | disable = file->flags & FTRACE_EVENT_FL_SOFT_DISABLED; |
282 | clear_bit(FTRACE_EVENT_FL_SOFT_MODE_BIT, &file->flags); | |
283 | } else | |
284 | disable = !(file->flags & FTRACE_EVENT_FL_SOFT_MODE); | |
285 | ||
286 | if (disable && (file->flags & FTRACE_EVENT_FL_ENABLED)) { | |
287 | clear_bit(FTRACE_EVENT_FL_ENABLED_BIT, &file->flags); | |
ae63b31e | 288 | if (file->flags & FTRACE_EVENT_FL_RECORDED_CMD) { |
e870e9a1 | 289 | tracing_stop_cmdline_record(); |
417944c4 | 290 | clear_bit(FTRACE_EVENT_FL_RECORDED_CMD_BIT, &file->flags); |
e870e9a1 | 291 | } |
ae63b31e | 292 | call->class->reg(call, TRACE_REG_UNREGISTER, file); |
fd994989 | 293 | } |
3baa5e4c | 294 | /* If in SOFT_MODE, just set the SOFT_DISABLE_BIT, else clear it */ |
417944c4 SRRH |
295 | if (file->flags & FTRACE_EVENT_FL_SOFT_MODE) |
296 | set_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &file->flags); | |
3baa5e4c TZ |
297 | else |
298 | clear_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &file->flags); | |
fd994989 SR |
299 | break; |
300 | case 1: | |
417944c4 SRRH |
301 | /* |
302 | * When soft_disable is set and enable is set, we want to | |
303 | * register the tracepoint for the event, but leave the event | |
304 | * as is. That means, if the event was already enabled, we do | |
305 | * nothing (but set SOFT_MODE). If the event is disabled, we | |
306 | * set SOFT_DISABLED before enabling the event tracepoint, so | |
307 | * it still seems to be disabled. | |
308 | */ | |
309 | if (!soft_disable) | |
310 | clear_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &file->flags); | |
1cf4c073 MH |
311 | else { |
312 | if (atomic_inc_return(&file->sm_ref) > 1) | |
313 | break; | |
417944c4 | 314 | set_bit(FTRACE_EVENT_FL_SOFT_MODE_BIT, &file->flags); |
1cf4c073 | 315 | } |
417944c4 | 316 | |
ae63b31e | 317 | if (!(file->flags & FTRACE_EVENT_FL_ENABLED)) { |
417944c4 SRRH |
318 | |
319 | /* Keep the event disabled, when going to SOFT_MODE. */ | |
320 | if (soft_disable) | |
321 | set_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &file->flags); | |
322 | ||
e870e9a1 LZ |
323 | if (trace_flags & TRACE_ITER_RECORD_CMD) { |
324 | tracing_start_cmdline_record(); | |
417944c4 | 325 | set_bit(FTRACE_EVENT_FL_RECORDED_CMD_BIT, &file->flags); |
e870e9a1 | 326 | } |
ae63b31e | 327 | ret = call->class->reg(call, TRACE_REG_REGISTER, file); |
3b8e4273 LZ |
328 | if (ret) { |
329 | tracing_stop_cmdline_record(); | |
330 | pr_info("event trace: Could not enable event " | |
331 | "%s\n", call->name); | |
332 | break; | |
333 | } | |
417944c4 | 334 | set_bit(FTRACE_EVENT_FL_ENABLED_BIT, &file->flags); |
575380da SRRH |
335 | |
336 | /* WAS_ENABLED gets set but never cleared. */ | |
337 | call->flags |= TRACE_EVENT_FL_WAS_ENABLED; | |
fd994989 | 338 | } |
fd994989 SR |
339 | break; |
340 | } | |
3b8e4273 LZ |
341 | |
342 | return ret; | |
fd994989 SR |
343 | } |
344 | ||
417944c4 SRRH |
345 | static int ftrace_event_enable_disable(struct ftrace_event_file *file, |
346 | int enable) | |
347 | { | |
348 | return __ftrace_event_enable_disable(file, enable, 0); | |
349 | } | |
350 | ||
ae63b31e | 351 | static void ftrace_clear_events(struct trace_array *tr) |
0e907c99 | 352 | { |
ae63b31e | 353 | struct ftrace_event_file *file; |
0e907c99 Z |
354 | |
355 | mutex_lock(&event_mutex); | |
ae63b31e SR |
356 | list_for_each_entry(file, &tr->events, list) { |
357 | ftrace_event_enable_disable(file, 0); | |
0e907c99 Z |
358 | } |
359 | mutex_unlock(&event_mutex); | |
360 | } | |
361 | ||
e9dbfae5 SR |
362 | static void __put_system(struct event_subsystem *system) |
363 | { | |
364 | struct event_filter *filter = system->filter; | |
365 | ||
6e94a780 SR |
366 | WARN_ON_ONCE(system_refcount(system) == 0); |
367 | if (system_refcount_dec(system)) | |
e9dbfae5 SR |
368 | return; |
369 | ||
ae63b31e SR |
370 | list_del(&system->list); |
371 | ||
e9dbfae5 SR |
372 | if (filter) { |
373 | kfree(filter->filter_string); | |
374 | kfree(filter); | |
375 | } | |
6e94a780 SR |
376 | if (system->ref_count & SYSTEM_FL_FREE_NAME) |
377 | kfree(system->name); | |
e9dbfae5 SR |
378 | kfree(system); |
379 | } | |
380 | ||
381 | static void __get_system(struct event_subsystem *system) | |
382 | { | |
6e94a780 SR |
383 | WARN_ON_ONCE(system_refcount(system) == 0); |
384 | system_refcount_inc(system); | |
e9dbfae5 SR |
385 | } |
386 | ||
ae63b31e SR |
387 | static void __get_system_dir(struct ftrace_subsystem_dir *dir) |
388 | { | |
389 | WARN_ON_ONCE(dir->ref_count == 0); | |
390 | dir->ref_count++; | |
391 | __get_system(dir->subsystem); | |
392 | } | |
393 | ||
394 | static void __put_system_dir(struct ftrace_subsystem_dir *dir) | |
395 | { | |
396 | WARN_ON_ONCE(dir->ref_count == 0); | |
397 | /* If the subsystem is about to be freed, the dir must be too */ | |
6e94a780 | 398 | WARN_ON_ONCE(system_refcount(dir->subsystem) == 1 && dir->ref_count != 1); |
ae63b31e SR |
399 | |
400 | __put_system(dir->subsystem); | |
401 | if (!--dir->ref_count) | |
402 | kfree(dir); | |
403 | } | |
404 | ||
405 | static void put_system(struct ftrace_subsystem_dir *dir) | |
e9dbfae5 SR |
406 | { |
407 | mutex_lock(&event_mutex); | |
ae63b31e | 408 | __put_system_dir(dir); |
e9dbfae5 SR |
409 | mutex_unlock(&event_mutex); |
410 | } | |
411 | ||
1a11126b ON |
412 | static void *event_file_data(struct file *filp) |
413 | { | |
414 | return ACCESS_ONCE(file_inode(filp)->i_private); | |
415 | } | |
416 | ||
8e2e2fa4 SRRH |
417 | /* |
418 | * Open and update trace_array ref count. | |
419 | * Must have the current trace_array passed to it. | |
420 | */ | |
421 | static int tracing_open_generic_file(struct inode *inode, struct file *filp) | |
422 | { | |
423 | struct ftrace_event_file *file = inode->i_private; | |
424 | struct trace_array *tr = file->tr; | |
425 | int ret; | |
426 | ||
427 | if (trace_array_get(tr) < 0) | |
428 | return -ENODEV; | |
429 | ||
430 | ret = tracing_open_generic(inode, filp); | |
431 | if (ret < 0) | |
432 | trace_array_put(tr); | |
433 | return ret; | |
434 | } | |
435 | ||
436 | static int tracing_release_generic_file(struct inode *inode, struct file *filp) | |
437 | { | |
438 | struct ftrace_event_file *file = inode->i_private; | |
439 | struct trace_array *tr = file->tr; | |
440 | ||
441 | trace_array_put(tr); | |
442 | ||
443 | return 0; | |
444 | } | |
445 | ||
8f31bfe5 LZ |
446 | /* |
447 | * __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events. | |
448 | */ | |
2a6c24af SRRH |
449 | static int |
450 | __ftrace_set_clr_event_nolock(struct trace_array *tr, const char *match, | |
451 | const char *sub, const char *event, int set) | |
b77e38aa | 452 | { |
ae63b31e | 453 | struct ftrace_event_file *file; |
a59fd602 | 454 | struct ftrace_event_call *call; |
29f93943 | 455 | int ret = -EINVAL; |
8f31bfe5 | 456 | |
ae63b31e SR |
457 | list_for_each_entry(file, &tr->events, list) { |
458 | ||
459 | call = file->event_call; | |
8f31bfe5 | 460 | |
a1d0ce82 | 461 | if (!call->name || !call->class || !call->class->reg) |
8f31bfe5 LZ |
462 | continue; |
463 | ||
9b63776f SR |
464 | if (call->flags & TRACE_EVENT_FL_IGNORE_ENABLE) |
465 | continue; | |
466 | ||
8f31bfe5 LZ |
467 | if (match && |
468 | strcmp(match, call->name) != 0 && | |
8f082018 | 469 | strcmp(match, call->class->system) != 0) |
8f31bfe5 LZ |
470 | continue; |
471 | ||
8f082018 | 472 | if (sub && strcmp(sub, call->class->system) != 0) |
8f31bfe5 LZ |
473 | continue; |
474 | ||
475 | if (event && strcmp(event, call->name) != 0) | |
476 | continue; | |
477 | ||
ae63b31e | 478 | ftrace_event_enable_disable(file, set); |
8f31bfe5 LZ |
479 | |
480 | ret = 0; | |
481 | } | |
2a6c24af SRRH |
482 | |
483 | return ret; | |
484 | } | |
485 | ||
486 | static int __ftrace_set_clr_event(struct trace_array *tr, const char *match, | |
487 | const char *sub, const char *event, int set) | |
488 | { | |
489 | int ret; | |
490 | ||
491 | mutex_lock(&event_mutex); | |
492 | ret = __ftrace_set_clr_event_nolock(tr, match, sub, event, set); | |
8f31bfe5 LZ |
493 | mutex_unlock(&event_mutex); |
494 | ||
495 | return ret; | |
496 | } | |
497 | ||
ae63b31e | 498 | static int ftrace_set_clr_event(struct trace_array *tr, char *buf, int set) |
8f31bfe5 | 499 | { |
b628b3e6 | 500 | char *event = NULL, *sub = NULL, *match; |
b628b3e6 SR |
501 | |
502 | /* | |
503 | * The buf format can be <subsystem>:<event-name> | |
504 | * *:<event-name> means any event by that name. | |
505 | * :<event-name> is the same. | |
506 | * | |
507 | * <subsystem>:* means all events in that subsystem | |
508 | * <subsystem>: means the same. | |
509 | * | |
510 | * <name> (no ':') means all events in a subsystem with | |
511 | * the name <name> or any event that matches <name> | |
512 | */ | |
513 | ||
514 | match = strsep(&buf, ":"); | |
515 | if (buf) { | |
516 | sub = match; | |
517 | event = buf; | |
518 | match = NULL; | |
519 | ||
520 | if (!strlen(sub) || strcmp(sub, "*") == 0) | |
521 | sub = NULL; | |
522 | if (!strlen(event) || strcmp(event, "*") == 0) | |
523 | event = NULL; | |
524 | } | |
b77e38aa | 525 | |
ae63b31e | 526 | return __ftrace_set_clr_event(tr, match, sub, event, set); |
b77e38aa SR |
527 | } |
528 | ||
4671c794 SR |
529 | /** |
530 | * trace_set_clr_event - enable or disable an event | |
531 | * @system: system name to match (NULL for any system) | |
532 | * @event: event name to match (NULL for all events, within system) | |
533 | * @set: 1 to enable, 0 to disable | |
534 | * | |
535 | * This is a way for other parts of the kernel to enable or disable | |
536 | * event recording. | |
537 | * | |
538 | * Returns 0 on success, -EINVAL if the parameters do not match any | |
539 | * registered events. | |
540 | */ | |
541 | int trace_set_clr_event(const char *system, const char *event, int set) | |
542 | { | |
ae63b31e SR |
543 | struct trace_array *tr = top_trace_array(); |
544 | ||
545 | return __ftrace_set_clr_event(tr, NULL, system, event, set); | |
4671c794 | 546 | } |
56355b83 | 547 | EXPORT_SYMBOL_GPL(trace_set_clr_event); |
4671c794 | 548 | |
b77e38aa SR |
549 | /* 128 should be much more than enough */ |
550 | #define EVENT_BUF_SIZE 127 | |
551 | ||
552 | static ssize_t | |
553 | ftrace_event_write(struct file *file, const char __user *ubuf, | |
554 | size_t cnt, loff_t *ppos) | |
555 | { | |
48966364 | 556 | struct trace_parser parser; |
ae63b31e SR |
557 | struct seq_file *m = file->private_data; |
558 | struct trace_array *tr = m->private; | |
4ba7978e | 559 | ssize_t read, ret; |
b77e38aa | 560 | |
4ba7978e | 561 | if (!cnt) |
b77e38aa SR |
562 | return 0; |
563 | ||
1852fcce SR |
564 | ret = tracing_update_buffers(); |
565 | if (ret < 0) | |
566 | return ret; | |
567 | ||
48966364 | 568 | if (trace_parser_get_init(&parser, EVENT_BUF_SIZE + 1)) |
b77e38aa SR |
569 | return -ENOMEM; |
570 | ||
48966364 | 571 | read = trace_get_user(&parser, ubuf, cnt, ppos); |
572 | ||
4ba7978e | 573 | if (read >= 0 && trace_parser_loaded((&parser))) { |
48966364 | 574 | int set = 1; |
b77e38aa | 575 | |
48966364 | 576 | if (*parser.buffer == '!') |
b77e38aa | 577 | set = 0; |
b77e38aa | 578 | |
48966364 | 579 | parser.buffer[parser.idx] = 0; |
580 | ||
ae63b31e | 581 | ret = ftrace_set_clr_event(tr, parser.buffer + !set, set); |
b77e38aa | 582 | if (ret) |
48966364 | 583 | goto out_put; |
b77e38aa | 584 | } |
b77e38aa SR |
585 | |
586 | ret = read; | |
587 | ||
48966364 | 588 | out_put: |
589 | trace_parser_put(&parser); | |
b77e38aa SR |
590 | |
591 | return ret; | |
592 | } | |
593 | ||
594 | static void * | |
595 | t_next(struct seq_file *m, void *v, loff_t *pos) | |
596 | { | |
ae63b31e SR |
597 | struct ftrace_event_file *file = v; |
598 | struct ftrace_event_call *call; | |
599 | struct trace_array *tr = m->private; | |
b77e38aa SR |
600 | |
601 | (*pos)++; | |
602 | ||
ae63b31e SR |
603 | list_for_each_entry_continue(file, &tr->events, list) { |
604 | call = file->event_call; | |
40e26815 SR |
605 | /* |
606 | * The ftrace subsystem is for showing formats only. | |
607 | * They can not be enabled or disabled via the event files. | |
608 | */ | |
a1d0ce82 | 609 | if (call->class && call->class->reg) |
ae63b31e | 610 | return file; |
40e26815 | 611 | } |
b77e38aa | 612 | |
30bd39cd | 613 | return NULL; |
b77e38aa SR |
614 | } |
615 | ||
616 | static void *t_start(struct seq_file *m, loff_t *pos) | |
617 | { | |
ae63b31e SR |
618 | struct ftrace_event_file *file; |
619 | struct trace_array *tr = m->private; | |
e1c7e2a6 LZ |
620 | loff_t l; |
621 | ||
20c8928a | 622 | mutex_lock(&event_mutex); |
e1c7e2a6 | 623 | |
ae63b31e | 624 | file = list_entry(&tr->events, struct ftrace_event_file, list); |
e1c7e2a6 | 625 | for (l = 0; l <= *pos; ) { |
ae63b31e SR |
626 | file = t_next(m, file, &l); |
627 | if (!file) | |
e1c7e2a6 LZ |
628 | break; |
629 | } | |
ae63b31e | 630 | return file; |
b77e38aa SR |
631 | } |
632 | ||
633 | static void * | |
634 | s_next(struct seq_file *m, void *v, loff_t *pos) | |
635 | { | |
ae63b31e SR |
636 | struct ftrace_event_file *file = v; |
637 | struct trace_array *tr = m->private; | |
b77e38aa SR |
638 | |
639 | (*pos)++; | |
640 | ||
ae63b31e SR |
641 | list_for_each_entry_continue(file, &tr->events, list) { |
642 | if (file->flags & FTRACE_EVENT_FL_ENABLED) | |
643 | return file; | |
b77e38aa SR |
644 | } |
645 | ||
30bd39cd | 646 | return NULL; |
b77e38aa SR |
647 | } |
648 | ||
649 | static void *s_start(struct seq_file *m, loff_t *pos) | |
650 | { | |
ae63b31e SR |
651 | struct ftrace_event_file *file; |
652 | struct trace_array *tr = m->private; | |
e1c7e2a6 LZ |
653 | loff_t l; |
654 | ||
20c8928a | 655 | mutex_lock(&event_mutex); |
e1c7e2a6 | 656 | |
ae63b31e | 657 | file = list_entry(&tr->events, struct ftrace_event_file, list); |
e1c7e2a6 | 658 | for (l = 0; l <= *pos; ) { |
ae63b31e SR |
659 | file = s_next(m, file, &l); |
660 | if (!file) | |
e1c7e2a6 LZ |
661 | break; |
662 | } | |
ae63b31e | 663 | return file; |
b77e38aa SR |
664 | } |
665 | ||
666 | static int t_show(struct seq_file *m, void *v) | |
667 | { | |
ae63b31e SR |
668 | struct ftrace_event_file *file = v; |
669 | struct ftrace_event_call *call = file->event_call; | |
b77e38aa | 670 | |
8f082018 SR |
671 | if (strcmp(call->class->system, TRACE_SYSTEM) != 0) |
672 | seq_printf(m, "%s:", call->class->system); | |
b77e38aa SR |
673 | seq_printf(m, "%s\n", call->name); |
674 | ||
675 | return 0; | |
676 | } | |
677 | ||
678 | static void t_stop(struct seq_file *m, void *p) | |
679 | { | |
20c8928a | 680 | mutex_unlock(&event_mutex); |
b77e38aa SR |
681 | } |
682 | ||
1473e441 SR |
683 | static ssize_t |
684 | event_enable_read(struct file *filp, char __user *ubuf, size_t cnt, | |
685 | loff_t *ppos) | |
686 | { | |
bc6f6b08 ON |
687 | struct ftrace_event_file *file; |
688 | unsigned long flags; | |
a4390596 TZ |
689 | char buf[4] = "0"; |
690 | ||
bc6f6b08 ON |
691 | mutex_lock(&event_mutex); |
692 | file = event_file_data(filp); | |
693 | if (likely(file)) | |
694 | flags = file->flags; | |
695 | mutex_unlock(&event_mutex); | |
696 | ||
697 | if (!file) | |
698 | return -ENODEV; | |
699 | ||
700 | if (flags & FTRACE_EVENT_FL_ENABLED && | |
701 | !(flags & FTRACE_EVENT_FL_SOFT_DISABLED)) | |
a4390596 TZ |
702 | strcpy(buf, "1"); |
703 | ||
bc6f6b08 ON |
704 | if (flags & FTRACE_EVENT_FL_SOFT_DISABLED || |
705 | flags & FTRACE_EVENT_FL_SOFT_MODE) | |
a4390596 TZ |
706 | strcat(buf, "*"); |
707 | ||
708 | strcat(buf, "\n"); | |
1473e441 | 709 | |
417944c4 | 710 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, strlen(buf)); |
1473e441 SR |
711 | } |
712 | ||
713 | static ssize_t | |
714 | event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt, | |
715 | loff_t *ppos) | |
716 | { | |
bc6f6b08 | 717 | struct ftrace_event_file *file; |
1473e441 SR |
718 | unsigned long val; |
719 | int ret; | |
720 | ||
22fe9b54 PH |
721 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
722 | if (ret) | |
1473e441 SR |
723 | return ret; |
724 | ||
1852fcce SR |
725 | ret = tracing_update_buffers(); |
726 | if (ret < 0) | |
727 | return ret; | |
728 | ||
1473e441 SR |
729 | switch (val) { |
730 | case 0: | |
1473e441 | 731 | case 1: |
bc6f6b08 | 732 | ret = -ENODEV; |
11a241a3 | 733 | mutex_lock(&event_mutex); |
bc6f6b08 ON |
734 | file = event_file_data(filp); |
735 | if (likely(file)) | |
736 | ret = ftrace_event_enable_disable(file, val); | |
11a241a3 | 737 | mutex_unlock(&event_mutex); |
1473e441 SR |
738 | break; |
739 | ||
740 | default: | |
741 | return -EINVAL; | |
742 | } | |
743 | ||
744 | *ppos += cnt; | |
745 | ||
3b8e4273 | 746 | return ret ? ret : cnt; |
1473e441 SR |
747 | } |
748 | ||
8ae79a13 SR |
749 | static ssize_t |
750 | system_enable_read(struct file *filp, char __user *ubuf, size_t cnt, | |
751 | loff_t *ppos) | |
752 | { | |
c142b15d | 753 | const char set_to_char[4] = { '?', '0', '1', 'X' }; |
ae63b31e SR |
754 | struct ftrace_subsystem_dir *dir = filp->private_data; |
755 | struct event_subsystem *system = dir->subsystem; | |
8ae79a13 | 756 | struct ftrace_event_call *call; |
ae63b31e SR |
757 | struct ftrace_event_file *file; |
758 | struct trace_array *tr = dir->tr; | |
8ae79a13 | 759 | char buf[2]; |
c142b15d | 760 | int set = 0; |
8ae79a13 SR |
761 | int ret; |
762 | ||
8ae79a13 | 763 | mutex_lock(&event_mutex); |
ae63b31e SR |
764 | list_for_each_entry(file, &tr->events, list) { |
765 | call = file->event_call; | |
a1d0ce82 | 766 | if (!call->name || !call->class || !call->class->reg) |
8ae79a13 SR |
767 | continue; |
768 | ||
40ee4dff | 769 | if (system && strcmp(call->class->system, system->name) != 0) |
8ae79a13 SR |
770 | continue; |
771 | ||
772 | /* | |
773 | * We need to find out if all the events are set | |
774 | * or if all events or cleared, or if we have | |
775 | * a mixture. | |
776 | */ | |
ae63b31e | 777 | set |= (1 << !!(file->flags & FTRACE_EVENT_FL_ENABLED)); |
c142b15d | 778 | |
8ae79a13 SR |
779 | /* |
780 | * If we have a mixture, no need to look further. | |
781 | */ | |
c142b15d | 782 | if (set == 3) |
8ae79a13 SR |
783 | break; |
784 | } | |
785 | mutex_unlock(&event_mutex); | |
786 | ||
c142b15d | 787 | buf[0] = set_to_char[set]; |
8ae79a13 | 788 | buf[1] = '\n'; |
8ae79a13 SR |
789 | |
790 | ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); | |
791 | ||
792 | return ret; | |
793 | } | |
794 | ||
795 | static ssize_t | |
796 | system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt, | |
797 | loff_t *ppos) | |
798 | { | |
ae63b31e SR |
799 | struct ftrace_subsystem_dir *dir = filp->private_data; |
800 | struct event_subsystem *system = dir->subsystem; | |
40ee4dff | 801 | const char *name = NULL; |
8ae79a13 | 802 | unsigned long val; |
8ae79a13 SR |
803 | ssize_t ret; |
804 | ||
22fe9b54 PH |
805 | ret = kstrtoul_from_user(ubuf, cnt, 10, &val); |
806 | if (ret) | |
8ae79a13 SR |
807 | return ret; |
808 | ||
809 | ret = tracing_update_buffers(); | |
810 | if (ret < 0) | |
811 | return ret; | |
812 | ||
8f31bfe5 | 813 | if (val != 0 && val != 1) |
8ae79a13 | 814 | return -EINVAL; |
8ae79a13 | 815 | |
40ee4dff SR |
816 | /* |
817 | * Opening of "enable" adds a ref count to system, | |
818 | * so the name is safe to use. | |
819 | */ | |
820 | if (system) | |
821 | name = system->name; | |
822 | ||
ae63b31e | 823 | ret = __ftrace_set_clr_event(dir->tr, NULL, name, NULL, val); |
8ae79a13 | 824 | if (ret) |
8f31bfe5 | 825 | goto out; |
8ae79a13 SR |
826 | |
827 | ret = cnt; | |
828 | ||
8f31bfe5 | 829 | out: |
8ae79a13 SR |
830 | *ppos += cnt; |
831 | ||
832 | return ret; | |
833 | } | |
834 | ||
2a37a3df SR |
835 | enum { |
836 | FORMAT_HEADER = 1, | |
86397dc3 LZ |
837 | FORMAT_FIELD_SEPERATOR = 2, |
838 | FORMAT_PRINTFMT = 3, | |
2a37a3df SR |
839 | }; |
840 | ||
841 | static void *f_next(struct seq_file *m, void *v, loff_t *pos) | |
981d081e | 842 | { |
2a37a3df | 843 | struct ftrace_event_call *call = m->private; |
86397dc3 LZ |
844 | struct list_head *common_head = &ftrace_common_fields; |
845 | struct list_head *head = trace_get_fields(call); | |
7710b639 | 846 | struct list_head *node = v; |
981d081e | 847 | |
2a37a3df | 848 | (*pos)++; |
5a65e956 | 849 | |
2a37a3df SR |
850 | switch ((unsigned long)v) { |
851 | case FORMAT_HEADER: | |
7710b639 ON |
852 | node = common_head; |
853 | break; | |
5a65e956 | 854 | |
86397dc3 | 855 | case FORMAT_FIELD_SEPERATOR: |
7710b639 ON |
856 | node = head; |
857 | break; | |
5a65e956 | 858 | |
2a37a3df SR |
859 | case FORMAT_PRINTFMT: |
860 | /* all done */ | |
861 | return NULL; | |
5a65e956 LJ |
862 | } |
863 | ||
7710b639 ON |
864 | node = node->prev; |
865 | if (node == common_head) | |
86397dc3 | 866 | return (void *)FORMAT_FIELD_SEPERATOR; |
7710b639 | 867 | else if (node == head) |
2a37a3df | 868 | return (void *)FORMAT_PRINTFMT; |
7710b639 ON |
869 | else |
870 | return node; | |
2a37a3df SR |
871 | } |
872 | ||
873 | static int f_show(struct seq_file *m, void *v) | |
874 | { | |
875 | struct ftrace_event_call *call = m->private; | |
876 | struct ftrace_event_field *field; | |
877 | const char *array_descriptor; | |
878 | ||
879 | switch ((unsigned long)v) { | |
880 | case FORMAT_HEADER: | |
881 | seq_printf(m, "name: %s\n", call->name); | |
882 | seq_printf(m, "ID: %d\n", call->event.type); | |
883 | seq_printf(m, "format:\n"); | |
8728fe50 | 884 | return 0; |
5a65e956 | 885 | |
86397dc3 LZ |
886 | case FORMAT_FIELD_SEPERATOR: |
887 | seq_putc(m, '\n'); | |
888 | return 0; | |
889 | ||
2a37a3df SR |
890 | case FORMAT_PRINTFMT: |
891 | seq_printf(m, "\nprint fmt: %s\n", | |
892 | call->print_fmt); | |
893 | return 0; | |
981d081e | 894 | } |
8728fe50 | 895 | |
7710b639 | 896 | field = list_entry(v, struct ftrace_event_field, link); |
2a37a3df SR |
897 | /* |
898 | * Smartly shows the array type(except dynamic array). | |
899 | * Normal: | |
900 | * field:TYPE VAR | |
901 | * If TYPE := TYPE[LEN], it is shown: | |
902 | * field:TYPE VAR[LEN] | |
903 | */ | |
904 | array_descriptor = strchr(field->type, '['); | |
8728fe50 | 905 | |
2a37a3df SR |
906 | if (!strncmp(field->type, "__data_loc", 10)) |
907 | array_descriptor = NULL; | |
8728fe50 | 908 | |
2a37a3df SR |
909 | if (!array_descriptor) |
910 | seq_printf(m, "\tfield:%s %s;\toffset:%u;\tsize:%u;\tsigned:%d;\n", | |
911 | field->type, field->name, field->offset, | |
912 | field->size, !!field->is_signed); | |
913 | else | |
914 | seq_printf(m, "\tfield:%.*s %s%s;\toffset:%u;\tsize:%u;\tsigned:%d;\n", | |
915 | (int)(array_descriptor - field->type), | |
916 | field->type, field->name, | |
917 | array_descriptor, field->offset, | |
918 | field->size, !!field->is_signed); | |
8728fe50 | 919 | |
2a37a3df SR |
920 | return 0; |
921 | } | |
5a65e956 | 922 | |
7710b639 ON |
923 | static void *f_start(struct seq_file *m, loff_t *pos) |
924 | { | |
925 | void *p = (void *)FORMAT_HEADER; | |
926 | loff_t l = 0; | |
927 | ||
928 | while (l < *pos && p) | |
929 | p = f_next(m, p, &l); | |
930 | ||
931 | return p; | |
932 | } | |
933 | ||
2a37a3df SR |
934 | static void f_stop(struct seq_file *m, void *p) |
935 | { | |
936 | } | |
981d081e | 937 | |
2a37a3df SR |
938 | static const struct seq_operations trace_format_seq_ops = { |
939 | .start = f_start, | |
940 | .next = f_next, | |
941 | .stop = f_stop, | |
942 | .show = f_show, | |
943 | }; | |
944 | ||
945 | static int trace_format_open(struct inode *inode, struct file *file) | |
946 | { | |
947 | struct ftrace_event_call *call = inode->i_private; | |
948 | struct seq_file *m; | |
949 | int ret; | |
950 | ||
951 | ret = seq_open(file, &trace_format_seq_ops); | |
952 | if (ret < 0) | |
953 | return ret; | |
954 | ||
955 | m = file->private_data; | |
956 | m->private = call; | |
957 | ||
958 | return 0; | |
981d081e SR |
959 | } |
960 | ||
23725aee PZ |
961 | static ssize_t |
962 | event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) | |
963 | { | |
1a11126b | 964 | int id = (long)event_file_data(filp); |
cd458ba9 ON |
965 | char buf[32]; |
966 | int len; | |
23725aee PZ |
967 | |
968 | if (*ppos) | |
969 | return 0; | |
970 | ||
1a11126b ON |
971 | if (unlikely(!id)) |
972 | return -ENODEV; | |
973 | ||
974 | len = sprintf(buf, "%d\n", id); | |
975 | ||
cd458ba9 | 976 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, len); |
23725aee PZ |
977 | } |
978 | ||
7ce7e424 TZ |
979 | static ssize_t |
980 | event_filter_read(struct file *filp, char __user *ubuf, size_t cnt, | |
981 | loff_t *ppos) | |
982 | { | |
983 | struct ftrace_event_call *call = filp->private_data; | |
984 | struct trace_seq *s; | |
985 | int r; | |
986 | ||
987 | if (*ppos) | |
988 | return 0; | |
989 | ||
990 | s = kmalloc(sizeof(*s), GFP_KERNEL); | |
991 | if (!s) | |
992 | return -ENOMEM; | |
993 | ||
994 | trace_seq_init(s); | |
995 | ||
8b372562 | 996 | print_event_filter(call, s); |
4bda2d51 | 997 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); |
7ce7e424 TZ |
998 | |
999 | kfree(s); | |
1000 | ||
1001 | return r; | |
1002 | } | |
1003 | ||
1004 | static ssize_t | |
1005 | event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, | |
1006 | loff_t *ppos) | |
1007 | { | |
1008 | struct ftrace_event_call *call = filp->private_data; | |
8b372562 | 1009 | char *buf; |
7ce7e424 TZ |
1010 | int err; |
1011 | ||
8b372562 | 1012 | if (cnt >= PAGE_SIZE) |
7ce7e424 TZ |
1013 | return -EINVAL; |
1014 | ||
8b372562 TZ |
1015 | buf = (char *)__get_free_page(GFP_TEMPORARY); |
1016 | if (!buf) | |
7ce7e424 TZ |
1017 | return -ENOMEM; |
1018 | ||
8b372562 TZ |
1019 | if (copy_from_user(buf, ubuf, cnt)) { |
1020 | free_page((unsigned long) buf); | |
1021 | return -EFAULT; | |
7ce7e424 | 1022 | } |
8b372562 | 1023 | buf[cnt] = '\0'; |
7ce7e424 | 1024 | |
8b372562 TZ |
1025 | err = apply_event_filter(call, buf); |
1026 | free_page((unsigned long) buf); | |
1027 | if (err < 0) | |
44e9c8b7 | 1028 | return err; |
0a19e53c | 1029 | |
7ce7e424 TZ |
1030 | *ppos += cnt; |
1031 | ||
1032 | return cnt; | |
1033 | } | |
1034 | ||
e9dbfae5 SR |
1035 | static LIST_HEAD(event_subsystems); |
1036 | ||
1037 | static int subsystem_open(struct inode *inode, struct file *filp) | |
1038 | { | |
1039 | struct event_subsystem *system = NULL; | |
ae63b31e SR |
1040 | struct ftrace_subsystem_dir *dir = NULL; /* Initialize for gcc */ |
1041 | struct trace_array *tr; | |
e9dbfae5 SR |
1042 | int ret; |
1043 | ||
1044 | /* Make sure the system still exists */ | |
a8227415 | 1045 | mutex_lock(&trace_types_lock); |
e9dbfae5 | 1046 | mutex_lock(&event_mutex); |
ae63b31e SR |
1047 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { |
1048 | list_for_each_entry(dir, &tr->systems, list) { | |
1049 | if (dir == inode->i_private) { | |
1050 | /* Don't open systems with no events */ | |
1051 | if (dir->nr_events) { | |
1052 | __get_system_dir(dir); | |
1053 | system = dir->subsystem; | |
1054 | } | |
1055 | goto exit_loop; | |
e9dbfae5 | 1056 | } |
e9dbfae5 SR |
1057 | } |
1058 | } | |
ae63b31e | 1059 | exit_loop: |
e9dbfae5 | 1060 | mutex_unlock(&event_mutex); |
a8227415 | 1061 | mutex_unlock(&trace_types_lock); |
e9dbfae5 | 1062 | |
ae63b31e | 1063 | if (!system) |
e9dbfae5 SR |
1064 | return -ENODEV; |
1065 | ||
ae63b31e SR |
1066 | /* Some versions of gcc think dir can be uninitialized here */ |
1067 | WARN_ON(!dir); | |
1068 | ||
8e2e2fa4 SRRH |
1069 | /* Still need to increment the ref count of the system */ |
1070 | if (trace_array_get(tr) < 0) { | |
1071 | put_system(dir); | |
1072 | return -ENODEV; | |
1073 | } | |
1074 | ||
e9dbfae5 | 1075 | ret = tracing_open_generic(inode, filp); |
8e2e2fa4 SRRH |
1076 | if (ret < 0) { |
1077 | trace_array_put(tr); | |
ae63b31e | 1078 | put_system(dir); |
8e2e2fa4 | 1079 | } |
ae63b31e SR |
1080 | |
1081 | return ret; | |
1082 | } | |
1083 | ||
1084 | static int system_tr_open(struct inode *inode, struct file *filp) | |
1085 | { | |
1086 | struct ftrace_subsystem_dir *dir; | |
1087 | struct trace_array *tr = inode->i_private; | |
1088 | int ret; | |
1089 | ||
8e2e2fa4 SRRH |
1090 | if (trace_array_get(tr) < 0) |
1091 | return -ENODEV; | |
1092 | ||
ae63b31e SR |
1093 | /* Make a temporary dir that has no system but points to tr */ |
1094 | dir = kzalloc(sizeof(*dir), GFP_KERNEL); | |
8e2e2fa4 SRRH |
1095 | if (!dir) { |
1096 | trace_array_put(tr); | |
ae63b31e | 1097 | return -ENOMEM; |
8e2e2fa4 | 1098 | } |
ae63b31e SR |
1099 | |
1100 | dir->tr = tr; | |
1101 | ||
1102 | ret = tracing_open_generic(inode, filp); | |
8e2e2fa4 SRRH |
1103 | if (ret < 0) { |
1104 | trace_array_put(tr); | |
ae63b31e | 1105 | kfree(dir); |
8e2e2fa4 | 1106 | } |
ae63b31e SR |
1107 | |
1108 | filp->private_data = dir; | |
e9dbfae5 SR |
1109 | |
1110 | return ret; | |
1111 | } | |
1112 | ||
1113 | static int subsystem_release(struct inode *inode, struct file *file) | |
1114 | { | |
ae63b31e | 1115 | struct ftrace_subsystem_dir *dir = file->private_data; |
e9dbfae5 | 1116 | |
8e2e2fa4 SRRH |
1117 | trace_array_put(dir->tr); |
1118 | ||
ae63b31e SR |
1119 | /* |
1120 | * If dir->subsystem is NULL, then this is a temporary | |
1121 | * descriptor that was made for a trace_array to enable | |
1122 | * all subsystems. | |
1123 | */ | |
1124 | if (dir->subsystem) | |
1125 | put_system(dir); | |
1126 | else | |
1127 | kfree(dir); | |
e9dbfae5 SR |
1128 | |
1129 | return 0; | |
1130 | } | |
1131 | ||
cfb180f3 TZ |
1132 | static ssize_t |
1133 | subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt, | |
1134 | loff_t *ppos) | |
1135 | { | |
ae63b31e SR |
1136 | struct ftrace_subsystem_dir *dir = filp->private_data; |
1137 | struct event_subsystem *system = dir->subsystem; | |
cfb180f3 TZ |
1138 | struct trace_seq *s; |
1139 | int r; | |
1140 | ||
1141 | if (*ppos) | |
1142 | return 0; | |
1143 | ||
1144 | s = kmalloc(sizeof(*s), GFP_KERNEL); | |
1145 | if (!s) | |
1146 | return -ENOMEM; | |
1147 | ||
1148 | trace_seq_init(s); | |
1149 | ||
8b372562 | 1150 | print_subsystem_event_filter(system, s); |
4bda2d51 | 1151 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); |
cfb180f3 TZ |
1152 | |
1153 | kfree(s); | |
1154 | ||
1155 | return r; | |
1156 | } | |
1157 | ||
1158 | static ssize_t | |
1159 | subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, | |
1160 | loff_t *ppos) | |
1161 | { | |
ae63b31e | 1162 | struct ftrace_subsystem_dir *dir = filp->private_data; |
8b372562 | 1163 | char *buf; |
cfb180f3 TZ |
1164 | int err; |
1165 | ||
8b372562 | 1166 | if (cnt >= PAGE_SIZE) |
cfb180f3 TZ |
1167 | return -EINVAL; |
1168 | ||
8b372562 TZ |
1169 | buf = (char *)__get_free_page(GFP_TEMPORARY); |
1170 | if (!buf) | |
cfb180f3 TZ |
1171 | return -ENOMEM; |
1172 | ||
8b372562 TZ |
1173 | if (copy_from_user(buf, ubuf, cnt)) { |
1174 | free_page((unsigned long) buf); | |
1175 | return -EFAULT; | |
cfb180f3 | 1176 | } |
8b372562 | 1177 | buf[cnt] = '\0'; |
cfb180f3 | 1178 | |
ae63b31e | 1179 | err = apply_subsystem_event_filter(dir, buf); |
8b372562 TZ |
1180 | free_page((unsigned long) buf); |
1181 | if (err < 0) | |
44e9c8b7 | 1182 | return err; |
cfb180f3 TZ |
1183 | |
1184 | *ppos += cnt; | |
1185 | ||
1186 | return cnt; | |
1187 | } | |
1188 | ||
d1b182a8 SR |
1189 | static ssize_t |
1190 | show_header(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) | |
1191 | { | |
1192 | int (*func)(struct trace_seq *s) = filp->private_data; | |
1193 | struct trace_seq *s; | |
1194 | int r; | |
1195 | ||
1196 | if (*ppos) | |
1197 | return 0; | |
1198 | ||
1199 | s = kmalloc(sizeof(*s), GFP_KERNEL); | |
1200 | if (!s) | |
1201 | return -ENOMEM; | |
1202 | ||
1203 | trace_seq_init(s); | |
1204 | ||
1205 | func(s); | |
1206 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); | |
1207 | ||
1208 | kfree(s); | |
1209 | ||
1210 | return r; | |
1211 | } | |
1212 | ||
15075cac SR |
1213 | static int ftrace_event_avail_open(struct inode *inode, struct file *file); |
1214 | static int ftrace_event_set_open(struct inode *inode, struct file *file); | |
f77d09a3 | 1215 | static int ftrace_event_release(struct inode *inode, struct file *file); |
15075cac | 1216 | |
b77e38aa SR |
1217 | static const struct seq_operations show_event_seq_ops = { |
1218 | .start = t_start, | |
1219 | .next = t_next, | |
1220 | .show = t_show, | |
1221 | .stop = t_stop, | |
1222 | }; | |
1223 | ||
1224 | static const struct seq_operations show_set_event_seq_ops = { | |
1225 | .start = s_start, | |
1226 | .next = s_next, | |
1227 | .show = t_show, | |
1228 | .stop = t_stop, | |
1229 | }; | |
1230 | ||
2314c4ae | 1231 | static const struct file_operations ftrace_avail_fops = { |
15075cac | 1232 | .open = ftrace_event_avail_open, |
2314c4ae SR |
1233 | .read = seq_read, |
1234 | .llseek = seq_lseek, | |
1235 | .release = seq_release, | |
1236 | }; | |
1237 | ||
b77e38aa | 1238 | static const struct file_operations ftrace_set_event_fops = { |
15075cac | 1239 | .open = ftrace_event_set_open, |
b77e38aa SR |
1240 | .read = seq_read, |
1241 | .write = ftrace_event_write, | |
1242 | .llseek = seq_lseek, | |
f77d09a3 | 1243 | .release = ftrace_event_release, |
b77e38aa SR |
1244 | }; |
1245 | ||
1473e441 | 1246 | static const struct file_operations ftrace_enable_fops = { |
8e2e2fa4 | 1247 | .open = tracing_open_generic_file, |
1473e441 SR |
1248 | .read = event_enable_read, |
1249 | .write = event_enable_write, | |
8e2e2fa4 | 1250 | .release = tracing_release_generic_file, |
6038f373 | 1251 | .llseek = default_llseek, |
1473e441 SR |
1252 | }; |
1253 | ||
981d081e | 1254 | static const struct file_operations ftrace_event_format_fops = { |
2a37a3df SR |
1255 | .open = trace_format_open, |
1256 | .read = seq_read, | |
1257 | .llseek = seq_lseek, | |
1258 | .release = seq_release, | |
981d081e SR |
1259 | }; |
1260 | ||
23725aee | 1261 | static const struct file_operations ftrace_event_id_fops = { |
23725aee | 1262 | .read = event_id_read, |
6038f373 | 1263 | .llseek = default_llseek, |
23725aee PZ |
1264 | }; |
1265 | ||
7ce7e424 TZ |
1266 | static const struct file_operations ftrace_event_filter_fops = { |
1267 | .open = tracing_open_generic, | |
1268 | .read = event_filter_read, | |
1269 | .write = event_filter_write, | |
6038f373 | 1270 | .llseek = default_llseek, |
7ce7e424 TZ |
1271 | }; |
1272 | ||
cfb180f3 | 1273 | static const struct file_operations ftrace_subsystem_filter_fops = { |
e9dbfae5 | 1274 | .open = subsystem_open, |
cfb180f3 TZ |
1275 | .read = subsystem_filter_read, |
1276 | .write = subsystem_filter_write, | |
6038f373 | 1277 | .llseek = default_llseek, |
e9dbfae5 | 1278 | .release = subsystem_release, |
cfb180f3 TZ |
1279 | }; |
1280 | ||
8ae79a13 | 1281 | static const struct file_operations ftrace_system_enable_fops = { |
40ee4dff | 1282 | .open = subsystem_open, |
8ae79a13 SR |
1283 | .read = system_enable_read, |
1284 | .write = system_enable_write, | |
6038f373 | 1285 | .llseek = default_llseek, |
40ee4dff | 1286 | .release = subsystem_release, |
8ae79a13 SR |
1287 | }; |
1288 | ||
ae63b31e SR |
1289 | static const struct file_operations ftrace_tr_enable_fops = { |
1290 | .open = system_tr_open, | |
1291 | .read = system_enable_read, | |
1292 | .write = system_enable_write, | |
1293 | .llseek = default_llseek, | |
1294 | .release = subsystem_release, | |
1295 | }; | |
1296 | ||
d1b182a8 SR |
1297 | static const struct file_operations ftrace_show_header_fops = { |
1298 | .open = tracing_open_generic, | |
1299 | .read = show_header, | |
6038f373 | 1300 | .llseek = default_llseek, |
d1b182a8 SR |
1301 | }; |
1302 | ||
ae63b31e SR |
1303 | static int |
1304 | ftrace_event_open(struct inode *inode, struct file *file, | |
1305 | const struct seq_operations *seq_ops) | |
1473e441 | 1306 | { |
ae63b31e SR |
1307 | struct seq_file *m; |
1308 | int ret; | |
1473e441 | 1309 | |
ae63b31e SR |
1310 | ret = seq_open(file, seq_ops); |
1311 | if (ret < 0) | |
1312 | return ret; | |
1313 | m = file->private_data; | |
1314 | /* copy tr over to seq ops */ | |
1315 | m->private = inode->i_private; | |
1473e441 | 1316 | |
ae63b31e | 1317 | return ret; |
1473e441 SR |
1318 | } |
1319 | ||
f77d09a3 AL |
1320 | static int ftrace_event_release(struct inode *inode, struct file *file) |
1321 | { | |
1322 | struct trace_array *tr = inode->i_private; | |
1323 | ||
1324 | trace_array_put(tr); | |
1325 | ||
1326 | return seq_release(inode, file); | |
1327 | } | |
1328 | ||
15075cac SR |
1329 | static int |
1330 | ftrace_event_avail_open(struct inode *inode, struct file *file) | |
1331 | { | |
1332 | const struct seq_operations *seq_ops = &show_event_seq_ops; | |
1333 | ||
ae63b31e | 1334 | return ftrace_event_open(inode, file, seq_ops); |
15075cac SR |
1335 | } |
1336 | ||
1337 | static int | |
1338 | ftrace_event_set_open(struct inode *inode, struct file *file) | |
1339 | { | |
1340 | const struct seq_operations *seq_ops = &show_set_event_seq_ops; | |
ae63b31e | 1341 | struct trace_array *tr = inode->i_private; |
f77d09a3 AL |
1342 | int ret; |
1343 | ||
1344 | if (trace_array_get(tr) < 0) | |
1345 | return -ENODEV; | |
15075cac SR |
1346 | |
1347 | if ((file->f_mode & FMODE_WRITE) && | |
1348 | (file->f_flags & O_TRUNC)) | |
ae63b31e | 1349 | ftrace_clear_events(tr); |
15075cac | 1350 | |
f77d09a3 AL |
1351 | ret = ftrace_event_open(inode, file, seq_ops); |
1352 | if (ret < 0) | |
1353 | trace_array_put(tr); | |
1354 | return ret; | |
ae63b31e SR |
1355 | } |
1356 | ||
1357 | static struct event_subsystem * | |
1358 | create_new_subsystem(const char *name) | |
1359 | { | |
1360 | struct event_subsystem *system; | |
1361 | ||
1362 | /* need to create new entry */ | |
1363 | system = kmalloc(sizeof(*system), GFP_KERNEL); | |
1364 | if (!system) | |
1365 | return NULL; | |
1366 | ||
1367 | system->ref_count = 1; | |
6e94a780 SR |
1368 | |
1369 | /* Only allocate if dynamic (kprobes and modules) */ | |
1370 | if (!core_kernel_data((unsigned long)name)) { | |
1371 | system->ref_count |= SYSTEM_FL_FREE_NAME; | |
1372 | system->name = kstrdup(name, GFP_KERNEL); | |
1373 | if (!system->name) | |
1374 | goto out_free; | |
1375 | } else | |
1376 | system->name = name; | |
ae63b31e SR |
1377 | |
1378 | system->filter = NULL; | |
1379 | ||
1380 | system->filter = kzalloc(sizeof(struct event_filter), GFP_KERNEL); | |
1381 | if (!system->filter) | |
1382 | goto out_free; | |
1383 | ||
1384 | list_add(&system->list, &event_subsystems); | |
1385 | ||
1386 | return system; | |
1387 | ||
1388 | out_free: | |
6e94a780 SR |
1389 | if (system->ref_count & SYSTEM_FL_FREE_NAME) |
1390 | kfree(system->name); | |
ae63b31e SR |
1391 | kfree(system); |
1392 | return NULL; | |
15075cac SR |
1393 | } |
1394 | ||
6ecc2d1c | 1395 | static struct dentry * |
ae63b31e SR |
1396 | event_subsystem_dir(struct trace_array *tr, const char *name, |
1397 | struct ftrace_event_file *file, struct dentry *parent) | |
6ecc2d1c | 1398 | { |
ae63b31e | 1399 | struct ftrace_subsystem_dir *dir; |
6ecc2d1c | 1400 | struct event_subsystem *system; |
e1112b4d | 1401 | struct dentry *entry; |
6ecc2d1c SR |
1402 | |
1403 | /* First see if we did not already create this dir */ | |
ae63b31e SR |
1404 | list_for_each_entry(dir, &tr->systems, list) { |
1405 | system = dir->subsystem; | |
dc82ec98 | 1406 | if (strcmp(system->name, name) == 0) { |
ae63b31e SR |
1407 | dir->nr_events++; |
1408 | file->system = dir; | |
1409 | return dir->entry; | |
dc82ec98 | 1410 | } |
6ecc2d1c SR |
1411 | } |
1412 | ||
ae63b31e SR |
1413 | /* Now see if the system itself exists. */ |
1414 | list_for_each_entry(system, &event_subsystems, list) { | |
1415 | if (strcmp(system->name, name) == 0) | |
1416 | break; | |
6ecc2d1c | 1417 | } |
ae63b31e SR |
1418 | /* Reset system variable when not found */ |
1419 | if (&system->list == &event_subsystems) | |
1420 | system = NULL; | |
6ecc2d1c | 1421 | |
ae63b31e SR |
1422 | dir = kmalloc(sizeof(*dir), GFP_KERNEL); |
1423 | if (!dir) | |
1424 | goto out_fail; | |
6ecc2d1c | 1425 | |
ae63b31e SR |
1426 | if (!system) { |
1427 | system = create_new_subsystem(name); | |
1428 | if (!system) | |
1429 | goto out_free; | |
1430 | } else | |
1431 | __get_system(system); | |
1432 | ||
1433 | dir->entry = debugfs_create_dir(name, parent); | |
1434 | if (!dir->entry) { | |
1435 | pr_warning("Failed to create system directory %s\n", name); | |
1436 | __put_system(system); | |
1437 | goto out_free; | |
6d723736 SR |
1438 | } |
1439 | ||
ae63b31e SR |
1440 | dir->tr = tr; |
1441 | dir->ref_count = 1; | |
1442 | dir->nr_events = 1; | |
1443 | dir->subsystem = system; | |
1444 | file->system = dir; | |
8b372562 | 1445 | |
ae63b31e | 1446 | entry = debugfs_create_file("filter", 0644, dir->entry, dir, |
e1112b4d | 1447 | &ftrace_subsystem_filter_fops); |
8b372562 TZ |
1448 | if (!entry) { |
1449 | kfree(system->filter); | |
1450 | system->filter = NULL; | |
ae63b31e | 1451 | pr_warning("Could not create debugfs '%s/filter' entry\n", name); |
8b372562 | 1452 | } |
e1112b4d | 1453 | |
ae63b31e | 1454 | trace_create_file("enable", 0644, dir->entry, dir, |
f3f3f009 | 1455 | &ftrace_system_enable_fops); |
8ae79a13 | 1456 | |
ae63b31e SR |
1457 | list_add(&dir->list, &tr->systems); |
1458 | ||
1459 | return dir->entry; | |
1460 | ||
1461 | out_free: | |
1462 | kfree(dir); | |
1463 | out_fail: | |
1464 | /* Only print this message if failed on memory allocation */ | |
1465 | if (!dir || !system) | |
1466 | pr_warning("No memory to create event subsystem %s\n", | |
1467 | name); | |
1468 | return NULL; | |
6ecc2d1c SR |
1469 | } |
1470 | ||
1473e441 | 1471 | static int |
ae63b31e SR |
1472 | event_create_dir(struct dentry *parent, |
1473 | struct ftrace_event_file *file, | |
701970b3 SR |
1474 | const struct file_operations *id, |
1475 | const struct file_operations *enable, | |
1476 | const struct file_operations *filter, | |
1477 | const struct file_operations *format) | |
1473e441 | 1478 | { |
ae63b31e SR |
1479 | struct ftrace_event_call *call = file->event_call; |
1480 | struct trace_array *tr = file->tr; | |
2e33af02 | 1481 | struct list_head *head; |
ae63b31e | 1482 | struct dentry *d_events; |
fd994989 | 1483 | int ret; |
1473e441 | 1484 | |
6ecc2d1c SR |
1485 | /* |
1486 | * If the trace point header did not define TRACE_SYSTEM | |
1487 | * then the system would be called "TRACE_SYSTEM". | |
1488 | */ | |
ae63b31e SR |
1489 | if (strcmp(call->class->system, TRACE_SYSTEM) != 0) { |
1490 | d_events = event_subsystem_dir(tr, call->class->system, file, parent); | |
1491 | if (!d_events) | |
1492 | return -ENOMEM; | |
1493 | } else | |
1494 | d_events = parent; | |
1495 | ||
1496 | file->dir = debugfs_create_dir(call->name, d_events); | |
1497 | if (!file->dir) { | |
1498 | pr_warning("Could not create debugfs '%s' directory\n", | |
1499 | call->name); | |
1473e441 SR |
1500 | return -1; |
1501 | } | |
1502 | ||
9b63776f | 1503 | if (call->class->reg && !(call->flags & TRACE_EVENT_FL_IGNORE_ENABLE)) |
ae63b31e | 1504 | trace_create_file("enable", 0644, file->dir, file, |
f3f3f009 | 1505 | enable); |
1473e441 | 1506 | |
2239291a | 1507 | #ifdef CONFIG_PERF_EVENTS |
a1d0ce82 | 1508 | if (call->event.type && call->class->reg) |
1a11126b ON |
1509 | trace_create_file("id", 0444, file->dir, |
1510 | (void *)(long)call->event.type, id); | |
2239291a | 1511 | #endif |
23725aee | 1512 | |
c9d932cf LZ |
1513 | /* |
1514 | * Other events may have the same class. Only update | |
1515 | * the fields if they are not already defined. | |
1516 | */ | |
1517 | head = trace_get_fields(call); | |
1518 | if (list_empty(head)) { | |
1519 | ret = call->class->define_fields(call); | |
1520 | if (ret < 0) { | |
1521 | pr_warning("Could not initialize trace point" | |
1522 | " events/%s\n", call->name); | |
ae63b31e | 1523 | return -1; |
cf027f64 TZ |
1524 | } |
1525 | } | |
ae63b31e | 1526 | trace_create_file("filter", 0644, file->dir, call, |
c9d932cf | 1527 | filter); |
cf027f64 | 1528 | |
ae63b31e | 1529 | trace_create_file("format", 0444, file->dir, call, |
f3f3f009 | 1530 | format); |
6d723736 SR |
1531 | |
1532 | return 0; | |
1533 | } | |
1534 | ||
ae63b31e SR |
1535 | static void remove_subsystem(struct ftrace_subsystem_dir *dir) |
1536 | { | |
1537 | if (!dir) | |
1538 | return; | |
1539 | ||
1540 | if (!--dir->nr_events) { | |
1541 | debugfs_remove_recursive(dir->entry); | |
1542 | list_del(&dir->list); | |
1543 | __put_system_dir(dir); | |
1544 | } | |
1545 | } | |
1546 | ||
1547 | static void remove_event_from_tracers(struct ftrace_event_call *call) | |
1548 | { | |
1549 | struct ftrace_event_file *file; | |
1550 | struct trace_array *tr; | |
1551 | ||
1552 | do_for_each_event_file_safe(tr, file) { | |
1553 | ||
1554 | if (file->event_call != call) | |
1555 | continue; | |
1556 | ||
1557 | list_del(&file->list); | |
1558 | debugfs_remove_recursive(file->dir); | |
1559 | remove_subsystem(file->system); | |
d1a29143 | 1560 | kmem_cache_free(file_cachep, file); |
ae63b31e SR |
1561 | |
1562 | /* | |
1563 | * The do_for_each_event_file_safe() is | |
1564 | * a double loop. After finding the call for this | |
1565 | * trace_array, we use break to jump to the next | |
1566 | * trace_array. | |
1567 | */ | |
1568 | break; | |
1569 | } while_for_each_event_file(); | |
1570 | } | |
1571 | ||
8781915a EG |
1572 | static void event_remove(struct ftrace_event_call *call) |
1573 | { | |
ae63b31e SR |
1574 | struct trace_array *tr; |
1575 | struct ftrace_event_file *file; | |
1576 | ||
1577 | do_for_each_event_file(tr, file) { | |
1578 | if (file->event_call != call) | |
1579 | continue; | |
1580 | ftrace_event_enable_disable(file, 0); | |
1581 | /* | |
1582 | * The do_for_each_event_file() is | |
1583 | * a double loop. After finding the call for this | |
1584 | * trace_array, we use break to jump to the next | |
1585 | * trace_array. | |
1586 | */ | |
1587 | break; | |
1588 | } while_for_each_event_file(); | |
1589 | ||
8781915a EG |
1590 | if (call->event.funcs) |
1591 | __unregister_ftrace_event(&call->event); | |
ae63b31e | 1592 | remove_event_from_tracers(call); |
8781915a EG |
1593 | list_del(&call->list); |
1594 | } | |
1595 | ||
1596 | static int event_init(struct ftrace_event_call *call) | |
1597 | { | |
1598 | int ret = 0; | |
1599 | ||
1600 | if (WARN_ON(!call->name)) | |
1601 | return -EINVAL; | |
1602 | ||
1603 | if (call->class->raw_init) { | |
1604 | ret = call->class->raw_init(call); | |
1605 | if (ret < 0 && ret != -ENOSYS) | |
1606 | pr_warn("Could not initialize trace events/%s\n", | |
1607 | call->name); | |
1608 | } | |
1609 | ||
1610 | return ret; | |
1611 | } | |
1612 | ||
67ead0a6 | 1613 | static int |
ae63b31e | 1614 | __register_event(struct ftrace_event_call *call, struct module *mod) |
bd1a5c84 | 1615 | { |
bd1a5c84 | 1616 | int ret; |
6d723736 | 1617 | |
8781915a EG |
1618 | ret = event_init(call); |
1619 | if (ret < 0) | |
1620 | return ret; | |
701970b3 | 1621 | |
ae63b31e | 1622 | list_add(&call->list, &ftrace_events); |
67ead0a6 | 1623 | call->mod = mod; |
88f70d75 | 1624 | |
ae63b31e | 1625 | return 0; |
bd1a5c84 MH |
1626 | } |
1627 | ||
da511bf3 SRRH |
1628 | static struct ftrace_event_file * |
1629 | trace_create_new_event(struct ftrace_event_call *call, | |
1630 | struct trace_array *tr) | |
1631 | { | |
1632 | struct ftrace_event_file *file; | |
1633 | ||
1634 | file = kmem_cache_alloc(file_cachep, GFP_TRACE); | |
1635 | if (!file) | |
1636 | return NULL; | |
1637 | ||
1638 | file->event_call = call; | |
1639 | file->tr = tr; | |
1640 | atomic_set(&file->sm_ref, 0); | |
1641 | list_add(&file->list, &tr->events); | |
1642 | ||
1643 | return file; | |
1644 | } | |
1645 | ||
ae63b31e SR |
1646 | /* Add an event to a trace directory */ |
1647 | static int | |
1648 | __trace_add_new_event(struct ftrace_event_call *call, | |
1649 | struct trace_array *tr, | |
1650 | const struct file_operations *id, | |
1651 | const struct file_operations *enable, | |
1652 | const struct file_operations *filter, | |
1653 | const struct file_operations *format) | |
1654 | { | |
1655 | struct ftrace_event_file *file; | |
1656 | ||
da511bf3 | 1657 | file = trace_create_new_event(call, tr); |
ae63b31e SR |
1658 | if (!file) |
1659 | return -ENOMEM; | |
1660 | ||
ae63b31e SR |
1661 | return event_create_dir(tr->event_dir, file, id, enable, filter, format); |
1662 | } | |
1663 | ||
77248221 SR |
1664 | /* |
1665 | * Just create a decriptor for early init. A descriptor is required | |
1666 | * for enabling events at boot. We want to enable events before | |
1667 | * the filesystem is initialized. | |
1668 | */ | |
1669 | static __init int | |
1670 | __trace_early_add_new_event(struct ftrace_event_call *call, | |
1671 | struct trace_array *tr) | |
1672 | { | |
1673 | struct ftrace_event_file *file; | |
1674 | ||
da511bf3 | 1675 | file = trace_create_new_event(call, tr); |
77248221 SR |
1676 | if (!file) |
1677 | return -ENOMEM; | |
1678 | ||
77248221 SR |
1679 | return 0; |
1680 | } | |
1681 | ||
ae63b31e SR |
1682 | struct ftrace_module_file_ops; |
1683 | static void __add_event_to_tracers(struct ftrace_event_call *call, | |
1684 | struct ftrace_module_file_ops *file_ops); | |
1685 | ||
bd1a5c84 MH |
1686 | /* Add an additional event_call dynamically */ |
1687 | int trace_add_event_call(struct ftrace_event_call *call) | |
1688 | { | |
1689 | int ret; | |
a8227415 | 1690 | mutex_lock(&trace_types_lock); |
bd1a5c84 | 1691 | mutex_lock(&event_mutex); |
701970b3 | 1692 | |
ae63b31e SR |
1693 | ret = __register_event(call, NULL); |
1694 | if (ret >= 0) | |
1695 | __add_event_to_tracers(call, NULL); | |
a2ca5e03 | 1696 | |
ae63b31e | 1697 | mutex_unlock(&event_mutex); |
a8227415 | 1698 | mutex_unlock(&trace_types_lock); |
ae63b31e | 1699 | return ret; |
a2ca5e03 FW |
1700 | } |
1701 | ||
4fead8e4 | 1702 | /* |
a8227415 AL |
1703 | * Must be called under locking of trace_types_lock, event_mutex and |
1704 | * trace_event_sem. | |
4fead8e4 | 1705 | */ |
bd1a5c84 MH |
1706 | static void __trace_remove_event_call(struct ftrace_event_call *call) |
1707 | { | |
8781915a | 1708 | event_remove(call); |
bd1a5c84 MH |
1709 | trace_destroy_fields(call); |
1710 | destroy_preds(call); | |
bd1a5c84 MH |
1711 | } |
1712 | ||
1713 | /* Remove an event_call */ | |
1714 | void trace_remove_event_call(struct ftrace_event_call *call) | |
1715 | { | |
a8227415 | 1716 | mutex_lock(&trace_types_lock); |
bd1a5c84 | 1717 | mutex_lock(&event_mutex); |
52f6ad6d | 1718 | down_write(&trace_event_sem); |
bd1a5c84 | 1719 | __trace_remove_event_call(call); |
52f6ad6d | 1720 | up_write(&trace_event_sem); |
bd1a5c84 | 1721 | mutex_unlock(&event_mutex); |
a8227415 | 1722 | mutex_unlock(&trace_types_lock); |
bd1a5c84 MH |
1723 | } |
1724 | ||
1725 | #define for_each_event(event, start, end) \ | |
1726 | for (event = start; \ | |
1727 | (unsigned long)event < (unsigned long)end; \ | |
1728 | event++) | |
1729 | ||
1730 | #ifdef CONFIG_MODULES | |
1731 | ||
1732 | static LIST_HEAD(ftrace_module_file_list); | |
1733 | ||
1734 | /* | |
1735 | * Modules must own their file_operations to keep up with | |
1736 | * reference counting. | |
1737 | */ | |
1738 | struct ftrace_module_file_ops { | |
1739 | struct list_head list; | |
1740 | struct module *mod; | |
1741 | struct file_operations id; | |
1742 | struct file_operations enable; | |
1743 | struct file_operations format; | |
1744 | struct file_operations filter; | |
1745 | }; | |
1746 | ||
315326c1 SRRH |
1747 | static struct ftrace_module_file_ops * |
1748 | find_ftrace_file_ops(struct ftrace_module_file_ops *file_ops, struct module *mod) | |
ae63b31e | 1749 | { |
315326c1 SRRH |
1750 | /* |
1751 | * As event_calls are added in groups by module, | |
1752 | * when we find one file_ops, we don't need to search for | |
1753 | * each call in that module, as the rest should be the | |
1754 | * same. Only search for a new one if the last one did | |
1755 | * not match. | |
1756 | */ | |
1757 | if (file_ops && mod == file_ops->mod) | |
1758 | return file_ops; | |
ae63b31e SR |
1759 | |
1760 | list_for_each_entry(file_ops, &ftrace_module_file_list, list) { | |
1761 | if (file_ops->mod == mod) | |
1762 | return file_ops; | |
1763 | } | |
1764 | return NULL; | |
1765 | } | |
1766 | ||
701970b3 SR |
1767 | static struct ftrace_module_file_ops * |
1768 | trace_create_file_ops(struct module *mod) | |
1769 | { | |
1770 | struct ftrace_module_file_ops *file_ops; | |
1771 | ||
1772 | /* | |
1773 | * This is a bit of a PITA. To allow for correct reference | |
1774 | * counting, modules must "own" their file_operations. | |
1775 | * To do this, we allocate the file operations that will be | |
1776 | * used in the event directory. | |
1777 | */ | |
1778 | ||
1779 | file_ops = kmalloc(sizeof(*file_ops), GFP_KERNEL); | |
1780 | if (!file_ops) | |
1781 | return NULL; | |
1782 | ||
1783 | file_ops->mod = mod; | |
1784 | ||
1785 | file_ops->id = ftrace_event_id_fops; | |
1786 | file_ops->id.owner = mod; | |
1787 | ||
1788 | file_ops->enable = ftrace_enable_fops; | |
1789 | file_ops->enable.owner = mod; | |
1790 | ||
1791 | file_ops->filter = ftrace_event_filter_fops; | |
1792 | file_ops->filter.owner = mod; | |
1793 | ||
1794 | file_ops->format = ftrace_event_format_fops; | |
1795 | file_ops->format.owner = mod; | |
1796 | ||
1797 | list_add(&file_ops->list, &ftrace_module_file_list); | |
1798 | ||
1799 | return file_ops; | |
1800 | } | |
1801 | ||
6d723736 SR |
1802 | static void trace_module_add_events(struct module *mod) |
1803 | { | |
701970b3 | 1804 | struct ftrace_module_file_ops *file_ops = NULL; |
e4a9ea5e | 1805 | struct ftrace_event_call **call, **start, **end; |
6d723736 SR |
1806 | |
1807 | start = mod->trace_events; | |
1808 | end = mod->trace_events + mod->num_trace_events; | |
1809 | ||
1810 | if (start == end) | |
1811 | return; | |
1812 | ||
67ead0a6 LZ |
1813 | file_ops = trace_create_file_ops(mod); |
1814 | if (!file_ops) | |
6d723736 SR |
1815 | return; |
1816 | ||
1817 | for_each_event(call, start, end) { | |
ae63b31e SR |
1818 | __register_event(*call, mod); |
1819 | __add_event_to_tracers(*call, file_ops); | |
6d723736 SR |
1820 | } |
1821 | } | |
1822 | ||
1823 | static void trace_module_remove_events(struct module *mod) | |
1824 | { | |
701970b3 | 1825 | struct ftrace_module_file_ops *file_ops; |
6d723736 | 1826 | struct ftrace_event_call *call, *p; |
575380da | 1827 | bool clear_trace = false; |
6d723736 | 1828 | |
52f6ad6d | 1829 | down_write(&trace_event_sem); |
6d723736 SR |
1830 | list_for_each_entry_safe(call, p, &ftrace_events, list) { |
1831 | if (call->mod == mod) { | |
575380da SRRH |
1832 | if (call->flags & TRACE_EVENT_FL_WAS_ENABLED) |
1833 | clear_trace = true; | |
bd1a5c84 | 1834 | __trace_remove_event_call(call); |
6d723736 SR |
1835 | } |
1836 | } | |
701970b3 SR |
1837 | |
1838 | /* Now free the file_operations */ | |
1839 | list_for_each_entry(file_ops, &ftrace_module_file_list, list) { | |
1840 | if (file_ops->mod == mod) | |
1841 | break; | |
1842 | } | |
1843 | if (&file_ops->list != &ftrace_module_file_list) { | |
1844 | list_del(&file_ops->list); | |
1845 | kfree(file_ops); | |
1846 | } | |
52f6ad6d | 1847 | up_write(&trace_event_sem); |
9456f0fa SR |
1848 | |
1849 | /* | |
1850 | * It is safest to reset the ring buffer if the module being unloaded | |
873c642f SRRH |
1851 | * registered any events that were used. The only worry is if |
1852 | * a new module gets loaded, and takes on the same id as the events | |
1853 | * of this module. When printing out the buffer, traced events left | |
1854 | * over from this module may be passed to the new module events and | |
1855 | * unexpected results may occur. | |
9456f0fa | 1856 | */ |
575380da | 1857 | if (clear_trace) |
873c642f | 1858 | tracing_reset_all_online_cpus(); |
6d723736 SR |
1859 | } |
1860 | ||
61f919a1 SR |
1861 | static int trace_module_notify(struct notifier_block *self, |
1862 | unsigned long val, void *data) | |
6d723736 SR |
1863 | { |
1864 | struct module *mod = data; | |
1865 | ||
a8227415 | 1866 | mutex_lock(&trace_types_lock); |
6d723736 SR |
1867 | mutex_lock(&event_mutex); |
1868 | switch (val) { | |
1869 | case MODULE_STATE_COMING: | |
1870 | trace_module_add_events(mod); | |
1871 | break; | |
1872 | case MODULE_STATE_GOING: | |
1873 | trace_module_remove_events(mod); | |
1874 | break; | |
1875 | } | |
1876 | mutex_unlock(&event_mutex); | |
a8227415 | 1877 | mutex_unlock(&trace_types_lock); |
fd994989 | 1878 | |
1473e441 SR |
1879 | return 0; |
1880 | } | |
315326c1 SRRH |
1881 | |
1882 | static int | |
1883 | __trace_add_new_mod_event(struct ftrace_event_call *call, | |
1884 | struct trace_array *tr, | |
1885 | struct ftrace_module_file_ops *file_ops) | |
1886 | { | |
1887 | return __trace_add_new_event(call, tr, | |
1888 | &file_ops->id, &file_ops->enable, | |
1889 | &file_ops->filter, &file_ops->format); | |
1890 | } | |
1891 | ||
61f919a1 | 1892 | #else |
315326c1 SRRH |
1893 | static inline struct ftrace_module_file_ops * |
1894 | find_ftrace_file_ops(struct ftrace_module_file_ops *file_ops, struct module *mod) | |
ae63b31e SR |
1895 | { |
1896 | return NULL; | |
1897 | } | |
315326c1 SRRH |
1898 | static inline int trace_module_notify(struct notifier_block *self, |
1899 | unsigned long val, void *data) | |
61f919a1 SR |
1900 | { |
1901 | return 0; | |
1902 | } | |
315326c1 SRRH |
1903 | static inline int |
1904 | __trace_add_new_mod_event(struct ftrace_event_call *call, | |
1905 | struct trace_array *tr, | |
1906 | struct ftrace_module_file_ops *file_ops) | |
1907 | { | |
1908 | return -ENODEV; | |
1909 | } | |
61f919a1 | 1910 | #endif /* CONFIG_MODULES */ |
1473e441 | 1911 | |
ae63b31e SR |
1912 | /* Create a new event directory structure for a trace directory. */ |
1913 | static void | |
1914 | __trace_add_event_dirs(struct trace_array *tr) | |
1915 | { | |
1916 | struct ftrace_module_file_ops *file_ops = NULL; | |
1917 | struct ftrace_event_call *call; | |
1918 | int ret; | |
1919 | ||
1920 | list_for_each_entry(call, &ftrace_events, list) { | |
1921 | if (call->mod) { | |
1922 | /* | |
1923 | * Directories for events by modules need to | |
1924 | * keep module ref counts when opened (as we don't | |
1925 | * want the module to disappear when reading one | |
1926 | * of these files). The file_ops keep account of | |
1927 | * the module ref count. | |
ae63b31e | 1928 | */ |
315326c1 | 1929 | file_ops = find_ftrace_file_ops(file_ops, call->mod); |
ae63b31e SR |
1930 | if (!file_ops) |
1931 | continue; /* Warn? */ | |
315326c1 | 1932 | ret = __trace_add_new_mod_event(call, tr, file_ops); |
ae63b31e SR |
1933 | if (ret < 0) |
1934 | pr_warning("Could not create directory for event %s\n", | |
1935 | call->name); | |
1936 | continue; | |
1937 | } | |
1938 | ret = __trace_add_new_event(call, tr, | |
1939 | &ftrace_event_id_fops, | |
1940 | &ftrace_enable_fops, | |
1941 | &ftrace_event_filter_fops, | |
1942 | &ftrace_event_format_fops); | |
1943 | if (ret < 0) | |
1944 | pr_warning("Could not create directory for event %s\n", | |
1945 | call->name); | |
1946 | } | |
1947 | } | |
1948 | ||
3cd715de SRRH |
1949 | #ifdef CONFIG_DYNAMIC_FTRACE |
1950 | ||
1951 | /* Avoid typos */ | |
1952 | #define ENABLE_EVENT_STR "enable_event" | |
1953 | #define DISABLE_EVENT_STR "disable_event" | |
1954 | ||
1955 | struct event_probe_data { | |
1956 | struct ftrace_event_file *file; | |
1957 | unsigned long count; | |
1958 | int ref; | |
1959 | bool enable; | |
1960 | }; | |
1961 | ||
1962 | static struct ftrace_event_file * | |
1963 | find_event_file(struct trace_array *tr, const char *system, const char *event) | |
1964 | { | |
1965 | struct ftrace_event_file *file; | |
1966 | struct ftrace_event_call *call; | |
1967 | ||
1968 | list_for_each_entry(file, &tr->events, list) { | |
1969 | ||
1970 | call = file->event_call; | |
1971 | ||
1972 | if (!call->name || !call->class || !call->class->reg) | |
1973 | continue; | |
1974 | ||
1975 | if (call->flags & TRACE_EVENT_FL_IGNORE_ENABLE) | |
1976 | continue; | |
1977 | ||
1978 | if (strcmp(event, call->name) == 0 && | |
1979 | strcmp(system, call->class->system) == 0) | |
1980 | return file; | |
1981 | } | |
1982 | return NULL; | |
1983 | } | |
1984 | ||
1985 | static void | |
1986 | event_enable_probe(unsigned long ip, unsigned long parent_ip, void **_data) | |
1987 | { | |
1988 | struct event_probe_data **pdata = (struct event_probe_data **)_data; | |
1989 | struct event_probe_data *data = *pdata; | |
1990 | ||
1991 | if (!data) | |
1992 | return; | |
1993 | ||
1994 | if (data->enable) | |
1995 | clear_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &data->file->flags); | |
1996 | else | |
1997 | set_bit(FTRACE_EVENT_FL_SOFT_DISABLED_BIT, &data->file->flags); | |
1998 | } | |
1999 | ||
2000 | static void | |
2001 | event_enable_count_probe(unsigned long ip, unsigned long parent_ip, void **_data) | |
2002 | { | |
2003 | struct event_probe_data **pdata = (struct event_probe_data **)_data; | |
2004 | struct event_probe_data *data = *pdata; | |
2005 | ||
2006 | if (!data) | |
2007 | return; | |
2008 | ||
2009 | if (!data->count) | |
2010 | return; | |
2011 | ||
2012 | /* Skip if the event is in a state we want to switch to */ | |
2013 | if (data->enable == !(data->file->flags & FTRACE_EVENT_FL_SOFT_DISABLED)) | |
2014 | return; | |
2015 | ||
2016 | if (data->count != -1) | |
2017 | (data->count)--; | |
2018 | ||
2019 | event_enable_probe(ip, parent_ip, _data); | |
2020 | } | |
2021 | ||
2022 | static int | |
2023 | event_enable_print(struct seq_file *m, unsigned long ip, | |
2024 | struct ftrace_probe_ops *ops, void *_data) | |
2025 | { | |
2026 | struct event_probe_data *data = _data; | |
2027 | ||
2028 | seq_printf(m, "%ps:", (void *)ip); | |
2029 | ||
2030 | seq_printf(m, "%s:%s:%s", | |
2031 | data->enable ? ENABLE_EVENT_STR : DISABLE_EVENT_STR, | |
2032 | data->file->event_call->class->system, | |
2033 | data->file->event_call->name); | |
2034 | ||
2035 | if (data->count == -1) | |
2036 | seq_printf(m, ":unlimited\n"); | |
2037 | else | |
2038 | seq_printf(m, ":count=%ld\n", data->count); | |
2039 | ||
2040 | return 0; | |
2041 | } | |
2042 | ||
2043 | static int | |
2044 | event_enable_init(struct ftrace_probe_ops *ops, unsigned long ip, | |
2045 | void **_data) | |
2046 | { | |
2047 | struct event_probe_data **pdata = (struct event_probe_data **)_data; | |
2048 | struct event_probe_data *data = *pdata; | |
2049 | ||
2050 | data->ref++; | |
2051 | return 0; | |
2052 | } | |
2053 | ||
2054 | static void | |
2055 | event_enable_free(struct ftrace_probe_ops *ops, unsigned long ip, | |
2056 | void **_data) | |
2057 | { | |
2058 | struct event_probe_data **pdata = (struct event_probe_data **)_data; | |
2059 | struct event_probe_data *data = *pdata; | |
2060 | ||
2061 | if (WARN_ON_ONCE(data->ref <= 0)) | |
2062 | return; | |
2063 | ||
2064 | data->ref--; | |
2065 | if (!data->ref) { | |
2066 | /* Remove the SOFT_MODE flag */ | |
2067 | __ftrace_event_enable_disable(data->file, 0, 1); | |
2068 | module_put(data->file->event_call->mod); | |
2069 | kfree(data); | |
2070 | } | |
2071 | *pdata = NULL; | |
2072 | } | |
2073 | ||
2074 | static struct ftrace_probe_ops event_enable_probe_ops = { | |
2075 | .func = event_enable_probe, | |
2076 | .print = event_enable_print, | |
2077 | .init = event_enable_init, | |
2078 | .free = event_enable_free, | |
2079 | }; | |
2080 | ||
2081 | static struct ftrace_probe_ops event_enable_count_probe_ops = { | |
2082 | .func = event_enable_count_probe, | |
2083 | .print = event_enable_print, | |
2084 | .init = event_enable_init, | |
2085 | .free = event_enable_free, | |
2086 | }; | |
2087 | ||
2088 | static struct ftrace_probe_ops event_disable_probe_ops = { | |
2089 | .func = event_enable_probe, | |
2090 | .print = event_enable_print, | |
2091 | .init = event_enable_init, | |
2092 | .free = event_enable_free, | |
2093 | }; | |
2094 | ||
2095 | static struct ftrace_probe_ops event_disable_count_probe_ops = { | |
2096 | .func = event_enable_count_probe, | |
2097 | .print = event_enable_print, | |
2098 | .init = event_enable_init, | |
2099 | .free = event_enable_free, | |
2100 | }; | |
2101 | ||
2102 | static int | |
2103 | event_enable_func(struct ftrace_hash *hash, | |
2104 | char *glob, char *cmd, char *param, int enabled) | |
2105 | { | |
2106 | struct trace_array *tr = top_trace_array(); | |
2107 | struct ftrace_event_file *file; | |
2108 | struct ftrace_probe_ops *ops; | |
2109 | struct event_probe_data *data; | |
2110 | const char *system; | |
2111 | const char *event; | |
2112 | char *number; | |
2113 | bool enable; | |
2114 | int ret; | |
2115 | ||
2116 | /* hash funcs only work with set_ftrace_filter */ | |
8092e808 | 2117 | if (!enabled || !param) |
3cd715de SRRH |
2118 | return -EINVAL; |
2119 | ||
2120 | system = strsep(¶m, ":"); | |
2121 | if (!param) | |
2122 | return -EINVAL; | |
2123 | ||
2124 | event = strsep(¶m, ":"); | |
2125 | ||
2126 | mutex_lock(&event_mutex); | |
2127 | ||
2128 | ret = -EINVAL; | |
2129 | file = find_event_file(tr, system, event); | |
2130 | if (!file) | |
2131 | goto out; | |
2132 | ||
2133 | enable = strcmp(cmd, ENABLE_EVENT_STR) == 0; | |
2134 | ||
2135 | if (enable) | |
2136 | ops = param ? &event_enable_count_probe_ops : &event_enable_probe_ops; | |
2137 | else | |
2138 | ops = param ? &event_disable_count_probe_ops : &event_disable_probe_ops; | |
2139 | ||
2140 | if (glob[0] == '!') { | |
2141 | unregister_ftrace_function_probe_func(glob+1, ops); | |
2142 | ret = 0; | |
2143 | goto out; | |
2144 | } | |
2145 | ||
2146 | ret = -ENOMEM; | |
2147 | data = kzalloc(sizeof(*data), GFP_KERNEL); | |
2148 | if (!data) | |
2149 | goto out; | |
2150 | ||
2151 | data->enable = enable; | |
2152 | data->count = -1; | |
2153 | data->file = file; | |
2154 | ||
2155 | if (!param) | |
2156 | goto out_reg; | |
2157 | ||
2158 | number = strsep(¶m, ":"); | |
2159 | ||
2160 | ret = -EINVAL; | |
2161 | if (!strlen(number)) | |
2162 | goto out_free; | |
2163 | ||
2164 | /* | |
2165 | * We use the callback data field (which is a pointer) | |
2166 | * as our counter. | |
2167 | */ | |
2168 | ret = kstrtoul(number, 0, &data->count); | |
2169 | if (ret) | |
2170 | goto out_free; | |
2171 | ||
2172 | out_reg: | |
2173 | /* Don't let event modules unload while probe registered */ | |
2174 | ret = try_module_get(file->event_call->mod); | |
6ed01066 MH |
2175 | if (!ret) { |
2176 | ret = -EBUSY; | |
3cd715de | 2177 | goto out_free; |
6ed01066 | 2178 | } |
3cd715de SRRH |
2179 | |
2180 | ret = __ftrace_event_enable_disable(file, 1, 1); | |
2181 | if (ret < 0) | |
2182 | goto out_put; | |
2183 | ret = register_ftrace_function_probe(glob, ops, data); | |
ff305ded SRRH |
2184 | /* |
2185 | * The above returns on success the # of functions enabled, | |
2186 | * but if it didn't find any functions it returns zero. | |
2187 | * Consider no functions a failure too. | |
2188 | */ | |
a5b85bd1 MH |
2189 | if (!ret) { |
2190 | ret = -ENOENT; | |
3cd715de | 2191 | goto out_disable; |
ff305ded SRRH |
2192 | } else if (ret < 0) |
2193 | goto out_disable; | |
2194 | /* Just return zero, not the number of enabled functions */ | |
2195 | ret = 0; | |
3cd715de SRRH |
2196 | out: |
2197 | mutex_unlock(&event_mutex); | |
2198 | return ret; | |
2199 | ||
2200 | out_disable: | |
2201 | __ftrace_event_enable_disable(file, 0, 1); | |
2202 | out_put: | |
2203 | module_put(file->event_call->mod); | |
2204 | out_free: | |
2205 | kfree(data); | |
2206 | goto out; | |
2207 | } | |
2208 | ||
2209 | static struct ftrace_func_command event_enable_cmd = { | |
2210 | .name = ENABLE_EVENT_STR, | |
2211 | .func = event_enable_func, | |
2212 | }; | |
2213 | ||
2214 | static struct ftrace_func_command event_disable_cmd = { | |
2215 | .name = DISABLE_EVENT_STR, | |
2216 | .func = event_enable_func, | |
2217 | }; | |
2218 | ||
2219 | static __init int register_event_cmds(void) | |
2220 | { | |
2221 | int ret; | |
2222 | ||
2223 | ret = register_ftrace_command(&event_enable_cmd); | |
2224 | if (WARN_ON(ret < 0)) | |
2225 | return ret; | |
2226 | ret = register_ftrace_command(&event_disable_cmd); | |
2227 | if (WARN_ON(ret < 0)) | |
2228 | unregister_ftrace_command(&event_enable_cmd); | |
2229 | return ret; | |
2230 | } | |
2231 | #else | |
2232 | static inline int register_event_cmds(void) { return 0; } | |
2233 | #endif /* CONFIG_DYNAMIC_FTRACE */ | |
2234 | ||
77248221 SR |
2235 | /* |
2236 | * The top level array has already had its ftrace_event_file | |
2237 | * descriptors created in order to allow for early events to | |
2238 | * be recorded. This function is called after the debugfs has been | |
2239 | * initialized, and we now have to create the files associated | |
2240 | * to the events. | |
2241 | */ | |
2242 | static __init void | |
2243 | __trace_early_add_event_dirs(struct trace_array *tr) | |
2244 | { | |
2245 | struct ftrace_event_file *file; | |
2246 | int ret; | |
2247 | ||
2248 | ||
2249 | list_for_each_entry(file, &tr->events, list) { | |
2250 | ret = event_create_dir(tr->event_dir, file, | |
2251 | &ftrace_event_id_fops, | |
2252 | &ftrace_enable_fops, | |
2253 | &ftrace_event_filter_fops, | |
2254 | &ftrace_event_format_fops); | |
2255 | if (ret < 0) | |
2256 | pr_warning("Could not create directory for event %s\n", | |
2257 | file->event_call->name); | |
2258 | } | |
2259 | } | |
2260 | ||
2261 | /* | |
2262 | * For early boot up, the top trace array requires to have | |
2263 | * a list of events that can be enabled. This must be done before | |
2264 | * the filesystem is set up in order to allow events to be traced | |
2265 | * early. | |
2266 | */ | |
2267 | static __init void | |
2268 | __trace_early_add_events(struct trace_array *tr) | |
2269 | { | |
2270 | struct ftrace_event_call *call; | |
2271 | int ret; | |
2272 | ||
2273 | list_for_each_entry(call, &ftrace_events, list) { | |
2274 | /* Early boot up should not have any modules loaded */ | |
2275 | if (WARN_ON_ONCE(call->mod)) | |
2276 | continue; | |
2277 | ||
2278 | ret = __trace_early_add_new_event(call, tr); | |
2279 | if (ret < 0) | |
2280 | pr_warning("Could not create early event %s\n", | |
2281 | call->name); | |
2282 | } | |
2283 | } | |
2284 | ||
0c8916c3 SR |
2285 | /* Remove the event directory structure for a trace directory. */ |
2286 | static void | |
2287 | __trace_remove_event_dirs(struct trace_array *tr) | |
2288 | { | |
2289 | struct ftrace_event_file *file, *next; | |
2290 | ||
2291 | list_for_each_entry_safe(file, next, &tr->events, list) { | |
2292 | list_del(&file->list); | |
2293 | debugfs_remove_recursive(file->dir); | |
2294 | remove_subsystem(file->system); | |
d1a29143 | 2295 | kmem_cache_free(file_cachep, file); |
0c8916c3 SR |
2296 | } |
2297 | } | |
2298 | ||
ae63b31e SR |
2299 | static void |
2300 | __add_event_to_tracers(struct ftrace_event_call *call, | |
2301 | struct ftrace_module_file_ops *file_ops) | |
2302 | { | |
2303 | struct trace_array *tr; | |
2304 | ||
2305 | list_for_each_entry(tr, &ftrace_trace_arrays, list) { | |
2306 | if (file_ops) | |
315326c1 | 2307 | __trace_add_new_mod_event(call, tr, file_ops); |
ae63b31e SR |
2308 | else |
2309 | __trace_add_new_event(call, tr, | |
2310 | &ftrace_event_id_fops, | |
2311 | &ftrace_enable_fops, | |
2312 | &ftrace_event_filter_fops, | |
2313 | &ftrace_event_format_fops); | |
2314 | } | |
2315 | } | |
2316 | ||
ec827c7e | 2317 | static struct notifier_block trace_module_nb = { |
6d723736 SR |
2318 | .notifier_call = trace_module_notify, |
2319 | .priority = 0, | |
2320 | }; | |
2321 | ||
e4a9ea5e SR |
2322 | extern struct ftrace_event_call *__start_ftrace_events[]; |
2323 | extern struct ftrace_event_call *__stop_ftrace_events[]; | |
a59fd602 | 2324 | |
020e5f85 LZ |
2325 | static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata; |
2326 | ||
2327 | static __init int setup_trace_event(char *str) | |
2328 | { | |
2329 | strlcpy(bootup_event_buf, str, COMMAND_LINE_SIZE); | |
55034cd6 SRRH |
2330 | ring_buffer_expanded = true; |
2331 | tracing_selftest_disabled = true; | |
020e5f85 LZ |
2332 | |
2333 | return 1; | |
2334 | } | |
2335 | __setup("trace_event=", setup_trace_event); | |
2336 | ||
77248221 SR |
2337 | /* Expects to have event_mutex held when called */ |
2338 | static int | |
2339 | create_event_toplevel_files(struct dentry *parent, struct trace_array *tr) | |
ae63b31e SR |
2340 | { |
2341 | struct dentry *d_events; | |
2342 | struct dentry *entry; | |
2343 | ||
2344 | entry = debugfs_create_file("set_event", 0644, parent, | |
2345 | tr, &ftrace_set_event_fops); | |
2346 | if (!entry) { | |
2347 | pr_warning("Could not create debugfs 'set_event' entry\n"); | |
2348 | return -ENOMEM; | |
2349 | } | |
2350 | ||
2351 | d_events = debugfs_create_dir("events", parent); | |
277ba044 | 2352 | if (!d_events) { |
ae63b31e | 2353 | pr_warning("Could not create debugfs 'events' directory\n"); |
277ba044 SR |
2354 | return -ENOMEM; |
2355 | } | |
ae63b31e SR |
2356 | |
2357 | /* ring buffer internal formats */ | |
2358 | trace_create_file("header_page", 0444, d_events, | |
2359 | ring_buffer_print_page_header, | |
2360 | &ftrace_show_header_fops); | |
2361 | ||
2362 | trace_create_file("header_event", 0444, d_events, | |
2363 | ring_buffer_print_entry_header, | |
2364 | &ftrace_show_header_fops); | |
2365 | ||
2366 | trace_create_file("enable", 0644, d_events, | |
2367 | tr, &ftrace_tr_enable_fops); | |
2368 | ||
2369 | tr->event_dir = d_events; | |
77248221 SR |
2370 | |
2371 | return 0; | |
2372 | } | |
2373 | ||
2374 | /** | |
2375 | * event_trace_add_tracer - add a instance of a trace_array to events | |
2376 | * @parent: The parent dentry to place the files/directories for events in | |
2377 | * @tr: The trace array associated with these events | |
2378 | * | |
2379 | * When a new instance is created, it needs to set up its events | |
2380 | * directory, as well as other files associated with events. It also | |
2381 | * creates the event hierachry in the @parent/events directory. | |
2382 | * | |
2383 | * Returns 0 on success. | |
2384 | */ | |
2385 | int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr) | |
2386 | { | |
2387 | int ret; | |
2388 | ||
2389 | mutex_lock(&event_mutex); | |
2390 | ||
2391 | ret = create_event_toplevel_files(parent, tr); | |
2392 | if (ret) | |
2393 | goto out_unlock; | |
2394 | ||
52f6ad6d | 2395 | down_write(&trace_event_sem); |
ae63b31e | 2396 | __trace_add_event_dirs(tr); |
52f6ad6d | 2397 | up_write(&trace_event_sem); |
277ba044 | 2398 | |
77248221 | 2399 | out_unlock: |
277ba044 | 2400 | mutex_unlock(&event_mutex); |
ae63b31e | 2401 | |
77248221 SR |
2402 | return ret; |
2403 | } | |
2404 | ||
2405 | /* | |
2406 | * The top trace array already had its file descriptors created. | |
2407 | * Now the files themselves need to be created. | |
2408 | */ | |
2409 | static __init int | |
2410 | early_event_add_tracer(struct dentry *parent, struct trace_array *tr) | |
2411 | { | |
2412 | int ret; | |
2413 | ||
2414 | mutex_lock(&event_mutex); | |
2415 | ||
2416 | ret = create_event_toplevel_files(parent, tr); | |
2417 | if (ret) | |
2418 | goto out_unlock; | |
2419 | ||
52f6ad6d | 2420 | down_write(&trace_event_sem); |
77248221 | 2421 | __trace_early_add_event_dirs(tr); |
52f6ad6d | 2422 | up_write(&trace_event_sem); |
77248221 SR |
2423 | |
2424 | out_unlock: | |
2425 | mutex_unlock(&event_mutex); | |
2426 | ||
2427 | return ret; | |
ae63b31e SR |
2428 | } |
2429 | ||
0c8916c3 SR |
2430 | int event_trace_del_tracer(struct trace_array *tr) |
2431 | { | |
0c8916c3 SR |
2432 | mutex_lock(&event_mutex); |
2433 | ||
2a6c24af SRRH |
2434 | /* Disable any running events */ |
2435 | __ftrace_set_clr_event_nolock(tr, NULL, NULL, NULL, 0); | |
2436 | ||
52f6ad6d | 2437 | down_write(&trace_event_sem); |
0c8916c3 SR |
2438 | __trace_remove_event_dirs(tr); |
2439 | debugfs_remove_recursive(tr->event_dir); | |
52f6ad6d | 2440 | up_write(&trace_event_sem); |
0c8916c3 SR |
2441 | |
2442 | tr->event_dir = NULL; | |
2443 | ||
2444 | mutex_unlock(&event_mutex); | |
2445 | ||
2446 | return 0; | |
2447 | } | |
2448 | ||
d1a29143 SR |
2449 | static __init int event_trace_memsetup(void) |
2450 | { | |
2451 | field_cachep = KMEM_CACHE(ftrace_event_field, SLAB_PANIC); | |
2452 | file_cachep = KMEM_CACHE(ftrace_event_file, SLAB_PANIC); | |
2453 | return 0; | |
2454 | } | |
2455 | ||
8781915a EG |
2456 | static __init int event_trace_enable(void) |
2457 | { | |
ae63b31e | 2458 | struct trace_array *tr = top_trace_array(); |
8781915a EG |
2459 | struct ftrace_event_call **iter, *call; |
2460 | char *buf = bootup_event_buf; | |
2461 | char *token; | |
2462 | int ret; | |
2463 | ||
2464 | for_each_event(iter, __start_ftrace_events, __stop_ftrace_events) { | |
2465 | ||
2466 | call = *iter; | |
2467 | ret = event_init(call); | |
2468 | if (!ret) | |
2469 | list_add(&call->list, &ftrace_events); | |
2470 | } | |
2471 | ||
77248221 SR |
2472 | /* |
2473 | * We need the top trace array to have a working set of trace | |
2474 | * points at early init, before the debug files and directories | |
2475 | * are created. Create the file entries now, and attach them | |
2476 | * to the actual file dentries later. | |
2477 | */ | |
2478 | __trace_early_add_events(tr); | |
2479 | ||
8781915a EG |
2480 | while (true) { |
2481 | token = strsep(&buf, ","); | |
2482 | ||
2483 | if (!token) | |
2484 | break; | |
2485 | if (!*token) | |
2486 | continue; | |
2487 | ||
ae63b31e | 2488 | ret = ftrace_set_clr_event(tr, token, 1); |
8781915a EG |
2489 | if (ret) |
2490 | pr_warn("Failed to enable trace event: %s\n", token); | |
2491 | } | |
81698831 SR |
2492 | |
2493 | trace_printk_start_comm(); | |
2494 | ||
3cd715de SRRH |
2495 | register_event_cmds(); |
2496 | ||
8781915a EG |
2497 | return 0; |
2498 | } | |
2499 | ||
b77e38aa SR |
2500 | static __init int event_trace_init(void) |
2501 | { | |
ae63b31e | 2502 | struct trace_array *tr; |
b77e38aa SR |
2503 | struct dentry *d_tracer; |
2504 | struct dentry *entry; | |
6d723736 | 2505 | int ret; |
b77e38aa | 2506 | |
ae63b31e SR |
2507 | tr = top_trace_array(); |
2508 | ||
b77e38aa SR |
2509 | d_tracer = tracing_init_dentry(); |
2510 | if (!d_tracer) | |
2511 | return 0; | |
2512 | ||
2314c4ae | 2513 | entry = debugfs_create_file("available_events", 0444, d_tracer, |
ae63b31e | 2514 | tr, &ftrace_avail_fops); |
2314c4ae SR |
2515 | if (!entry) |
2516 | pr_warning("Could not create debugfs " | |
2517 | "'available_events' entry\n"); | |
2518 | ||
8728fe50 LZ |
2519 | if (trace_define_common_fields()) |
2520 | pr_warning("tracing: Failed to allocate common fields"); | |
2521 | ||
77248221 | 2522 | ret = early_event_add_tracer(d_tracer, tr); |
ae63b31e SR |
2523 | if (ret) |
2524 | return ret; | |
020e5f85 | 2525 | |
6d723736 | 2526 | ret = register_module_notifier(&trace_module_nb); |
55379376 | 2527 | if (ret) |
6d723736 SR |
2528 | pr_warning("Failed to register trace events module notifier\n"); |
2529 | ||
b77e38aa SR |
2530 | return 0; |
2531 | } | |
d1a29143 | 2532 | early_initcall(event_trace_memsetup); |
8781915a | 2533 | core_initcall(event_trace_enable); |
b77e38aa | 2534 | fs_initcall(event_trace_init); |
e6187007 SR |
2535 | |
2536 | #ifdef CONFIG_FTRACE_STARTUP_TEST | |
2537 | ||
2538 | static DEFINE_SPINLOCK(test_spinlock); | |
2539 | static DEFINE_SPINLOCK(test_spinlock_irq); | |
2540 | static DEFINE_MUTEX(test_mutex); | |
2541 | ||
2542 | static __init void test_work(struct work_struct *dummy) | |
2543 | { | |
2544 | spin_lock(&test_spinlock); | |
2545 | spin_lock_irq(&test_spinlock_irq); | |
2546 | udelay(1); | |
2547 | spin_unlock_irq(&test_spinlock_irq); | |
2548 | spin_unlock(&test_spinlock); | |
2549 | ||
2550 | mutex_lock(&test_mutex); | |
2551 | msleep(1); | |
2552 | mutex_unlock(&test_mutex); | |
2553 | } | |
2554 | ||
2555 | static __init int event_test_thread(void *unused) | |
2556 | { | |
2557 | void *test_malloc; | |
2558 | ||
2559 | test_malloc = kmalloc(1234, GFP_KERNEL); | |
2560 | if (!test_malloc) | |
2561 | pr_info("failed to kmalloc\n"); | |
2562 | ||
2563 | schedule_on_each_cpu(test_work); | |
2564 | ||
2565 | kfree(test_malloc); | |
2566 | ||
2567 | set_current_state(TASK_INTERRUPTIBLE); | |
2568 | while (!kthread_should_stop()) | |
2569 | schedule(); | |
2570 | ||
2571 | return 0; | |
2572 | } | |
2573 | ||
2574 | /* | |
2575 | * Do various things that may trigger events. | |
2576 | */ | |
2577 | static __init void event_test_stuff(void) | |
2578 | { | |
2579 | struct task_struct *test_thread; | |
2580 | ||
2581 | test_thread = kthread_run(event_test_thread, NULL, "test-events"); | |
2582 | msleep(1); | |
2583 | kthread_stop(test_thread); | |
2584 | } | |
2585 | ||
2586 | /* | |
2587 | * For every trace event defined, we will test each trace point separately, | |
2588 | * and then by groups, and finally all trace points. | |
2589 | */ | |
9ea21c1e | 2590 | static __init void event_trace_self_tests(void) |
e6187007 | 2591 | { |
ae63b31e SR |
2592 | struct ftrace_subsystem_dir *dir; |
2593 | struct ftrace_event_file *file; | |
e6187007 SR |
2594 | struct ftrace_event_call *call; |
2595 | struct event_subsystem *system; | |
ae63b31e | 2596 | struct trace_array *tr; |
e6187007 SR |
2597 | int ret; |
2598 | ||
ae63b31e SR |
2599 | tr = top_trace_array(); |
2600 | ||
e6187007 SR |
2601 | pr_info("Running tests on trace events:\n"); |
2602 | ||
ae63b31e SR |
2603 | list_for_each_entry(file, &tr->events, list) { |
2604 | ||
2605 | call = file->event_call; | |
e6187007 | 2606 | |
2239291a SR |
2607 | /* Only test those that have a probe */ |
2608 | if (!call->class || !call->class->probe) | |
e6187007 SR |
2609 | continue; |
2610 | ||
1f5a6b45 SR |
2611 | /* |
2612 | * Testing syscall events here is pretty useless, but | |
2613 | * we still do it if configured. But this is time consuming. | |
2614 | * What we really need is a user thread to perform the | |
2615 | * syscalls as we test. | |
2616 | */ | |
2617 | #ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS | |
8f082018 SR |
2618 | if (call->class->system && |
2619 | strcmp(call->class->system, "syscalls") == 0) | |
1f5a6b45 SR |
2620 | continue; |
2621 | #endif | |
2622 | ||
e6187007 SR |
2623 | pr_info("Testing event %s: ", call->name); |
2624 | ||
2625 | /* | |
2626 | * If an event is already enabled, someone is using | |
2627 | * it and the self test should not be on. | |
2628 | */ | |
ae63b31e | 2629 | if (file->flags & FTRACE_EVENT_FL_ENABLED) { |
e6187007 SR |
2630 | pr_warning("Enabled event during self test!\n"); |
2631 | WARN_ON_ONCE(1); | |
2632 | continue; | |
2633 | } | |
2634 | ||
ae63b31e | 2635 | ftrace_event_enable_disable(file, 1); |
e6187007 | 2636 | event_test_stuff(); |
ae63b31e | 2637 | ftrace_event_enable_disable(file, 0); |
e6187007 SR |
2638 | |
2639 | pr_cont("OK\n"); | |
2640 | } | |
2641 | ||
2642 | /* Now test at the sub system level */ | |
2643 | ||
2644 | pr_info("Running tests on trace event systems:\n"); | |
2645 | ||
ae63b31e SR |
2646 | list_for_each_entry(dir, &tr->systems, list) { |
2647 | ||
2648 | system = dir->subsystem; | |
e6187007 SR |
2649 | |
2650 | /* the ftrace system is special, skip it */ | |
2651 | if (strcmp(system->name, "ftrace") == 0) | |
2652 | continue; | |
2653 | ||
2654 | pr_info("Testing event system %s: ", system->name); | |
2655 | ||
ae63b31e | 2656 | ret = __ftrace_set_clr_event(tr, NULL, system->name, NULL, 1); |
e6187007 SR |
2657 | if (WARN_ON_ONCE(ret)) { |
2658 | pr_warning("error enabling system %s\n", | |
2659 | system->name); | |
2660 | continue; | |
2661 | } | |
2662 | ||
2663 | event_test_stuff(); | |
2664 | ||
ae63b31e | 2665 | ret = __ftrace_set_clr_event(tr, NULL, system->name, NULL, 0); |
76bab1b7 | 2666 | if (WARN_ON_ONCE(ret)) { |
e6187007 SR |
2667 | pr_warning("error disabling system %s\n", |
2668 | system->name); | |
76bab1b7 YL |
2669 | continue; |
2670 | } | |
e6187007 SR |
2671 | |
2672 | pr_cont("OK\n"); | |
2673 | } | |
2674 | ||
2675 | /* Test with all events enabled */ | |
2676 | ||
2677 | pr_info("Running tests on all trace events:\n"); | |
2678 | pr_info("Testing all events: "); | |
2679 | ||
ae63b31e | 2680 | ret = __ftrace_set_clr_event(tr, NULL, NULL, NULL, 1); |
e6187007 | 2681 | if (WARN_ON_ONCE(ret)) { |
e6187007 | 2682 | pr_warning("error enabling all events\n"); |
9ea21c1e | 2683 | return; |
e6187007 SR |
2684 | } |
2685 | ||
2686 | event_test_stuff(); | |
2687 | ||
2688 | /* reset sysname */ | |
ae63b31e | 2689 | ret = __ftrace_set_clr_event(tr, NULL, NULL, NULL, 0); |
e6187007 SR |
2690 | if (WARN_ON_ONCE(ret)) { |
2691 | pr_warning("error disabling all events\n"); | |
9ea21c1e | 2692 | return; |
e6187007 SR |
2693 | } |
2694 | ||
2695 | pr_cont("OK\n"); | |
9ea21c1e SR |
2696 | } |
2697 | ||
2698 | #ifdef CONFIG_FUNCTION_TRACER | |
2699 | ||
245b2e70 | 2700 | static DEFINE_PER_CPU(atomic_t, ftrace_test_event_disable); |
9ea21c1e SR |
2701 | |
2702 | static void | |
2f5f6ad9 | 2703 | function_test_events_call(unsigned long ip, unsigned long parent_ip, |
a1e2e31d | 2704 | struct ftrace_ops *op, struct pt_regs *pt_regs) |
9ea21c1e SR |
2705 | { |
2706 | struct ring_buffer_event *event; | |
e77405ad | 2707 | struct ring_buffer *buffer; |
9ea21c1e SR |
2708 | struct ftrace_entry *entry; |
2709 | unsigned long flags; | |
2710 | long disabled; | |
9ea21c1e SR |
2711 | int cpu; |
2712 | int pc; | |
2713 | ||
2714 | pc = preempt_count(); | |
5168ae50 | 2715 | preempt_disable_notrace(); |
9ea21c1e | 2716 | cpu = raw_smp_processor_id(); |
245b2e70 | 2717 | disabled = atomic_inc_return(&per_cpu(ftrace_test_event_disable, cpu)); |
9ea21c1e SR |
2718 | |
2719 | if (disabled != 1) | |
2720 | goto out; | |
2721 | ||
2722 | local_save_flags(flags); | |
2723 | ||
e77405ad SR |
2724 | event = trace_current_buffer_lock_reserve(&buffer, |
2725 | TRACE_FN, sizeof(*entry), | |
9ea21c1e SR |
2726 | flags, pc); |
2727 | if (!event) | |
2728 | goto out; | |
2729 | entry = ring_buffer_event_data(event); | |
2730 | entry->ip = ip; | |
2731 | entry->parent_ip = parent_ip; | |
2732 | ||
0d5c6e1c | 2733 | trace_buffer_unlock_commit(buffer, event, flags, pc); |
9ea21c1e SR |
2734 | |
2735 | out: | |
245b2e70 | 2736 | atomic_dec(&per_cpu(ftrace_test_event_disable, cpu)); |
5168ae50 | 2737 | preempt_enable_notrace(); |
9ea21c1e SR |
2738 | } |
2739 | ||
2740 | static struct ftrace_ops trace_ops __initdata = | |
2741 | { | |
2742 | .func = function_test_events_call, | |
4740974a | 2743 | .flags = FTRACE_OPS_FL_RECURSION_SAFE, |
9ea21c1e SR |
2744 | }; |
2745 | ||
2746 | static __init void event_trace_self_test_with_function(void) | |
2747 | { | |
17bb615a SR |
2748 | int ret; |
2749 | ret = register_ftrace_function(&trace_ops); | |
2750 | if (WARN_ON(ret < 0)) { | |
2751 | pr_info("Failed to enable function tracer for event tests\n"); | |
2752 | return; | |
2753 | } | |
9ea21c1e SR |
2754 | pr_info("Running tests again, along with the function tracer\n"); |
2755 | event_trace_self_tests(); | |
2756 | unregister_ftrace_function(&trace_ops); | |
2757 | } | |
2758 | #else | |
2759 | static __init void event_trace_self_test_with_function(void) | |
2760 | { | |
2761 | } | |
2762 | #endif | |
2763 | ||
2764 | static __init int event_trace_self_tests_init(void) | |
2765 | { | |
020e5f85 LZ |
2766 | if (!tracing_selftest_disabled) { |
2767 | event_trace_self_tests(); | |
2768 | event_trace_self_test_with_function(); | |
2769 | } | |
e6187007 SR |
2770 | |
2771 | return 0; | |
2772 | } | |
2773 | ||
28d20e2d | 2774 | late_initcall(event_trace_self_tests_init); |
e6187007 SR |
2775 | |
2776 | #endif |