blob: e8e6043f4d29efdc2f475842d43ca65a7652f7e5 [file] [log] [blame]
Steven Rostedtb77e38a2009-02-24 10:21:36 -05001/*
2 * event tracer
3 *
4 * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com>
5 *
Steven Rostedt981d0812009-03-02 13:53:59 -05006 * - Added format output of fields of the trace point.
7 * This was based off of work by Tom Zanussi <tzanussi@gmail.com>.
8 *
Steven Rostedtb77e38a2009-02-24 10:21:36 -05009 */
10
Steven Rostedte6187002009-04-15 13:36:40 -040011#include <linux/workqueue.h>
12#include <linux/spinlock.h>
13#include <linux/kthread.h>
Steven Rostedtb77e38a2009-02-24 10:21:36 -050014#include <linux/debugfs.h>
15#include <linux/uaccess.h>
16#include <linux/module.h>
17#include <linux/ctype.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090018#include <linux/slab.h>
Steven Rostedte6187002009-04-15 13:36:40 -040019#include <linux/delay.h>
Steven Rostedtb77e38a2009-02-24 10:21:36 -050020
Li Zefan020e5f82009-07-01 10:47:05 +080021#include <asm/setup.h>
22
Steven Rostedt91729ef2009-03-02 15:03:01 -050023#include "trace_output.h"
Steven Rostedtb77e38a2009-02-24 10:21:36 -050024
Steven Rostedt4e5292e2009-09-12 19:26:21 -040025#undef TRACE_SYSTEM
Steven Rostedtb628b3e2009-02-27 23:32:58 -050026#define TRACE_SYSTEM "TRACE_SYSTEM"
27
Li Zefan20c89282009-05-06 10:33:45 +080028DEFINE_MUTEX(event_mutex);
Steven Rostedt11a241a2009-03-02 11:49:04 -050029
Steven Rostedta59fd602009-04-10 13:52:20 -040030LIST_HEAD(ftrace_events);
Li Zefan8728fe52010-05-24 16:22:49 +080031LIST_HEAD(ftrace_common_fields);
Steven Rostedta59fd602009-04-10 13:52:20 -040032
Steven Rostedt2e33af02010-04-22 10:35:55 -040033struct list_head *
34trace_get_fields(struct ftrace_event_call *event_call)
35{
36 if (!event_call->class->get_fields)
37 return &event_call->class->fields;
38 return event_call->class->get_fields(event_call);
39}
40
Li Zefan8728fe52010-05-24 16:22:49 +080041static int __trace_define_field(struct list_head *head, const char *type,
42 const char *name, int offset, int size,
43 int is_signed, int filter_type)
Tom Zanussicf027f62009-03-22 03:30:39 -050044{
45 struct ftrace_event_field *field;
46
Ingo Molnarfe9f57f2009-03-22 18:41:59 +010047 field = kzalloc(sizeof(*field), GFP_KERNEL);
Tom Zanussicf027f62009-03-22 03:30:39 -050048 if (!field)
49 goto err;
Ingo Molnarfe9f57f2009-03-22 18:41:59 +010050
Tom Zanussicf027f62009-03-22 03:30:39 -050051 field->name = kstrdup(name, GFP_KERNEL);
52 if (!field->name)
53 goto err;
Ingo Molnarfe9f57f2009-03-22 18:41:59 +010054
Tom Zanussicf027f62009-03-22 03:30:39 -050055 field->type = kstrdup(type, GFP_KERNEL);
56 if (!field->type)
57 goto err;
Ingo Molnarfe9f57f2009-03-22 18:41:59 +010058
Li Zefan43b51ea2009-08-07 10:33:22 +080059 if (filter_type == FILTER_OTHER)
60 field->filter_type = filter_assign_type(type);
61 else
62 field->filter_type = filter_type;
63
Tom Zanussicf027f62009-03-22 03:30:39 -050064 field->offset = offset;
65 field->size = size;
Tom Zanussia118e4d2009-04-28 03:04:53 -050066 field->is_signed = is_signed;
Li Zefanaa38e9f2009-08-07 10:33:02 +080067
Steven Rostedt2e33af02010-04-22 10:35:55 -040068 list_add(&field->link, head);
Tom Zanussicf027f62009-03-22 03:30:39 -050069
70 return 0;
Ingo Molnarfe9f57f2009-03-22 18:41:59 +010071
Tom Zanussicf027f62009-03-22 03:30:39 -050072err:
Wenji Huang7b60997f2010-02-24 15:40:26 +080073 if (field)
Tom Zanussicf027f62009-03-22 03:30:39 -050074 kfree(field->name);
Tom Zanussicf027f62009-03-22 03:30:39 -050075 kfree(field);
Ingo Molnarfe9f57f2009-03-22 18:41:59 +010076
Tom Zanussicf027f62009-03-22 03:30:39 -050077 return -ENOMEM;
78}
Li Zefan8728fe52010-05-24 16:22:49 +080079
80int trace_define_field(struct ftrace_event_call *call, const char *type,
81 const char *name, int offset, int size, int is_signed,
82 int filter_type)
83{
84 struct list_head *head;
85
86 if (WARN_ON(!call->class))
87 return 0;
88
89 head = trace_get_fields(call);
90 return __trace_define_field(head, type, name, offset, size,
91 is_signed, filter_type);
92}
Steven Rostedt17c873e2009-04-10 18:12:50 -040093EXPORT_SYMBOL_GPL(trace_define_field);
Tom Zanussicf027f62009-03-22 03:30:39 -050094
Li Zefane647d6b2009-08-19 15:54:32 +080095#define __common_field(type, item) \
Li Zefan8728fe52010-05-24 16:22:49 +080096 ret = __trace_define_field(&ftrace_common_fields, #type, \
97 "common_" #item, \
98 offsetof(typeof(ent), item), \
99 sizeof(ent.item), \
100 is_signed_type(type), FILTER_OTHER); \
Li Zefane647d6b2009-08-19 15:54:32 +0800101 if (ret) \
102 return ret;
103
Li Zefan8728fe52010-05-24 16:22:49 +0800104static int trace_define_common_fields(void)
Li Zefane647d6b2009-08-19 15:54:32 +0800105{
106 int ret;
107 struct trace_entry ent;
108
109 __common_field(unsigned short, type);
110 __common_field(unsigned char, flags);
111 __common_field(unsigned char, preempt_count);
112 __common_field(int, pid);
Steven Rostedt637e7e82009-09-11 13:55:35 -0400113 __common_field(int, lock_depth);
Li Zefane647d6b2009-08-19 15:54:32 +0800114
115 return ret;
116}
117
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -0400118void trace_destroy_fields(struct ftrace_event_call *call)
Li Zefan2df75e42009-05-06 10:33:04 +0800119{
120 struct ftrace_event_field *field, *next;
Steven Rostedt2e33af02010-04-22 10:35:55 -0400121 struct list_head *head;
Li Zefan2df75e42009-05-06 10:33:04 +0800122
Steven Rostedt2e33af02010-04-22 10:35:55 -0400123 head = trace_get_fields(call);
124 list_for_each_entry_safe(field, next, head, link) {
Li Zefan2df75e42009-05-06 10:33:04 +0800125 list_del(&field->link);
126 kfree(field->type);
127 kfree(field->name);
128 kfree(field);
129 }
130}
131
Li Zefan87d9b4e2009-12-08 11:14:20 +0800132int trace_event_raw_init(struct ftrace_event_call *call)
133{
134 int id;
135
Steven Rostedt80decc72010-04-23 10:00:22 -0400136 id = register_ftrace_event(&call->event);
Li Zefan87d9b4e2009-12-08 11:14:20 +0800137 if (!id)
138 return -ENODEV;
Li Zefan87d9b4e2009-12-08 11:14:20 +0800139
140 return 0;
141}
142EXPORT_SYMBOL_GPL(trace_event_raw_init);
143
Steven Rostedta1d0ce82010-06-08 11:22:06 -0400144int ftrace_event_reg(struct ftrace_event_call *call, enum trace_reg type)
145{
146 switch (type) {
147 case TRACE_REG_REGISTER:
148 return tracepoint_probe_register(call->name,
149 call->class->probe,
150 call);
151 case TRACE_REG_UNREGISTER:
152 tracepoint_probe_unregister(call->name,
153 call->class->probe,
154 call);
155 return 0;
156
157#ifdef CONFIG_PERF_EVENTS
158 case TRACE_REG_PERF_REGISTER:
159 return tracepoint_probe_register(call->name,
160 call->class->perf_probe,
161 call);
162 case TRACE_REG_PERF_UNREGISTER:
163 tracepoint_probe_unregister(call->name,
164 call->class->perf_probe,
165 call);
166 return 0;
167#endif
168 }
169 return 0;
170}
171EXPORT_SYMBOL_GPL(ftrace_event_reg);
172
Li Zefan3b8e4272009-12-08 11:14:52 +0800173static int ftrace_event_enable_disable(struct ftrace_event_call *call,
Steven Rostedtfd994982009-02-28 02:41:25 -0500174 int enable)
175{
Li Zefan3b8e4272009-12-08 11:14:52 +0800176 int ret = 0;
177
Steven Rostedtfd994982009-02-28 02:41:25 -0500178 switch (enable) {
179 case 0:
Steven Rostedt553552c2010-04-23 11:12:36 -0400180 if (call->flags & TRACE_EVENT_FL_ENABLED) {
181 call->flags &= ~TRACE_EVENT_FL_ENABLED;
Zhaoleib11c53e2009-05-25 18:11:59 +0800182 tracing_stop_cmdline_record();
Steven Rostedta1d0ce82010-06-08 11:22:06 -0400183 call->class->reg(call, TRACE_REG_UNREGISTER);
Steven Rostedtfd994982009-02-28 02:41:25 -0500184 }
Steven Rostedtfd994982009-02-28 02:41:25 -0500185 break;
186 case 1:
Steven Rostedt553552c2010-04-23 11:12:36 -0400187 if (!(call->flags & TRACE_EVENT_FL_ENABLED)) {
Zhaoleib11c53e2009-05-25 18:11:59 +0800188 tracing_start_cmdline_record();
Steven Rostedta1d0ce82010-06-08 11:22:06 -0400189 ret = call->class->reg(call, TRACE_REG_REGISTER);
Li Zefan3b8e4272009-12-08 11:14:52 +0800190 if (ret) {
191 tracing_stop_cmdline_record();
192 pr_info("event trace: Could not enable event "
193 "%s\n", call->name);
194 break;
195 }
Steven Rostedt553552c2010-04-23 11:12:36 -0400196 call->flags |= TRACE_EVENT_FL_ENABLED;
Steven Rostedtfd994982009-02-28 02:41:25 -0500197 }
Steven Rostedtfd994982009-02-28 02:41:25 -0500198 break;
199 }
Li Zefan3b8e4272009-12-08 11:14:52 +0800200
201 return ret;
Steven Rostedtfd994982009-02-28 02:41:25 -0500202}
203
Zhaolei0e907c92009-05-25 18:13:59 +0800204static void ftrace_clear_events(void)
205{
206 struct ftrace_event_call *call;
207
208 mutex_lock(&event_mutex);
209 list_for_each_entry(call, &ftrace_events, list) {
210 ftrace_event_enable_disable(call, 0);
211 }
212 mutex_unlock(&event_mutex);
213}
214
Li Zefan8f31bfe2009-05-08 10:31:42 +0800215/*
216 * __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events.
217 */
218static int __ftrace_set_clr_event(const char *match, const char *sub,
219 const char *event, int set)
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500220{
Steven Rostedta59fd602009-04-10 13:52:20 -0400221 struct ftrace_event_call *call;
Steven Rostedt29f93942009-05-08 16:06:47 -0400222 int ret = -EINVAL;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500223
Steven Rostedt11a241a2009-03-02 11:49:04 -0500224 mutex_lock(&event_mutex);
Steven Rostedta59fd602009-04-10 13:52:20 -0400225 list_for_each_entry(call, &ftrace_events, list) {
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500226
Steven Rostedta1d0ce82010-06-08 11:22:06 -0400227 if (!call->name || !call->class || !call->class->reg)
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500228 continue;
Steven Rostedt1473e442009-02-24 14:15:08 -0500229
Steven Rostedtb628b3e2009-02-27 23:32:58 -0500230 if (match &&
231 strcmp(match, call->name) != 0 &&
Steven Rostedt8f082012010-04-20 10:47:33 -0400232 strcmp(match, call->class->system) != 0)
Steven Rostedtb628b3e2009-02-27 23:32:58 -0500233 continue;
234
Steven Rostedt8f082012010-04-20 10:47:33 -0400235 if (sub && strcmp(sub, call->class->system) != 0)
Steven Rostedtb628b3e2009-02-27 23:32:58 -0500236 continue;
237
238 if (event && strcmp(event, call->name) != 0)
Steven Rostedt1473e442009-02-24 14:15:08 -0500239 continue;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500240
Steven Rostedtfd994982009-02-28 02:41:25 -0500241 ftrace_event_enable_disable(call, set);
242
Steven Rostedtb628b3e2009-02-27 23:32:58 -0500243 ret = 0;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500244 }
Steven Rostedt11a241a2009-03-02 11:49:04 -0500245 mutex_unlock(&event_mutex);
246
Steven Rostedtb628b3e2009-02-27 23:32:58 -0500247 return ret;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500248}
249
Li Zefan8f31bfe2009-05-08 10:31:42 +0800250static int ftrace_set_clr_event(char *buf, int set)
251{
252 char *event = NULL, *sub = NULL, *match;
253
254 /*
255 * The buf format can be <subsystem>:<event-name>
256 * *:<event-name> means any event by that name.
257 * :<event-name> is the same.
258 *
259 * <subsystem>:* means all events in that subsystem
260 * <subsystem>: means the same.
261 *
262 * <name> (no ':') means all events in a subsystem with
263 * the name <name> or any event that matches <name>
264 */
265
266 match = strsep(&buf, ":");
267 if (buf) {
268 sub = match;
269 event = buf;
270 match = NULL;
271
272 if (!strlen(sub) || strcmp(sub, "*") == 0)
273 sub = NULL;
274 if (!strlen(event) || strcmp(event, "*") == 0)
275 event = NULL;
276 }
277
278 return __ftrace_set_clr_event(match, sub, event, set);
279}
280
Steven Rostedt4671c792009-05-08 16:27:41 -0400281/**
282 * trace_set_clr_event - enable or disable an event
283 * @system: system name to match (NULL for any system)
284 * @event: event name to match (NULL for all events, within system)
285 * @set: 1 to enable, 0 to disable
286 *
287 * This is a way for other parts of the kernel to enable or disable
288 * event recording.
289 *
290 * Returns 0 on success, -EINVAL if the parameters do not match any
291 * registered events.
292 */
293int trace_set_clr_event(const char *system, const char *event, int set)
294{
295 return __ftrace_set_clr_event(NULL, system, event, set);
296}
297
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500298/* 128 should be much more than enough */
299#define EVENT_BUF_SIZE 127
300
301static ssize_t
302ftrace_event_write(struct file *file, const char __user *ubuf,
303 size_t cnt, loff_t *ppos)
304{
jolsa@redhat.com48966362009-09-11 17:29:28 +0200305 struct trace_parser parser;
Li Zefan4ba79782009-09-22 13:52:20 +0800306 ssize_t read, ret;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500307
Li Zefan4ba79782009-09-22 13:52:20 +0800308 if (!cnt)
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500309 return 0;
310
Steven Rostedt1852fcc2009-03-11 14:33:00 -0400311 ret = tracing_update_buffers();
312 if (ret < 0)
313 return ret;
314
jolsa@redhat.com48966362009-09-11 17:29:28 +0200315 if (trace_parser_get_init(&parser, EVENT_BUF_SIZE + 1))
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500316 return -ENOMEM;
317
jolsa@redhat.com48966362009-09-11 17:29:28 +0200318 read = trace_get_user(&parser, ubuf, cnt, ppos);
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500319
Li Zefan4ba79782009-09-22 13:52:20 +0800320 if (read >= 0 && trace_parser_loaded((&parser))) {
jolsa@redhat.com48966362009-09-11 17:29:28 +0200321 int set = 1;
322
323 if (*parser.buffer == '!')
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500324 set = 0;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500325
jolsa@redhat.com48966362009-09-11 17:29:28 +0200326 parser.buffer[parser.idx] = 0;
327
328 ret = ftrace_set_clr_event(parser.buffer + !set, set);
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500329 if (ret)
jolsa@redhat.com48966362009-09-11 17:29:28 +0200330 goto out_put;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500331 }
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500332
333 ret = read;
334
jolsa@redhat.com48966362009-09-11 17:29:28 +0200335 out_put:
336 trace_parser_put(&parser);
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500337
338 return ret;
339}
340
341static void *
342t_next(struct seq_file *m, void *v, loff_t *pos)
343{
Li Zefan30bd39c2009-09-18 14:07:05 +0800344 struct ftrace_event_call *call = v;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500345
346 (*pos)++;
347
Li Zefan30bd39c2009-09-18 14:07:05 +0800348 list_for_each_entry_continue(call, &ftrace_events, list) {
Steven Rostedt40e26812009-03-10 11:32:40 -0400349 /*
350 * The ftrace subsystem is for showing formats only.
351 * They can not be enabled or disabled via the event files.
352 */
Steven Rostedta1d0ce82010-06-08 11:22:06 -0400353 if (call->class && call->class->reg)
Li Zefan30bd39c2009-09-18 14:07:05 +0800354 return call;
Steven Rostedt40e26812009-03-10 11:32:40 -0400355 }
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500356
Li Zefan30bd39c2009-09-18 14:07:05 +0800357 return NULL;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500358}
359
360static void *t_start(struct seq_file *m, loff_t *pos)
361{
Li Zefan30bd39c2009-09-18 14:07:05 +0800362 struct ftrace_event_call *call;
Li Zefane1c7e2a2009-06-24 09:52:29 +0800363 loff_t l;
364
Li Zefan20c89282009-05-06 10:33:45 +0800365 mutex_lock(&event_mutex);
Li Zefane1c7e2a2009-06-24 09:52:29 +0800366
Li Zefan30bd39c2009-09-18 14:07:05 +0800367 call = list_entry(&ftrace_events, struct ftrace_event_call, list);
Li Zefane1c7e2a2009-06-24 09:52:29 +0800368 for (l = 0; l <= *pos; ) {
Li Zefan30bd39c2009-09-18 14:07:05 +0800369 call = t_next(m, call, &l);
Li Zefane1c7e2a2009-06-24 09:52:29 +0800370 if (!call)
371 break;
372 }
373 return call;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500374}
375
376static void *
377s_next(struct seq_file *m, void *v, loff_t *pos)
378{
Li Zefan30bd39c2009-09-18 14:07:05 +0800379 struct ftrace_event_call *call = v;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500380
381 (*pos)++;
382
Li Zefan30bd39c2009-09-18 14:07:05 +0800383 list_for_each_entry_continue(call, &ftrace_events, list) {
Steven Rostedt553552c2010-04-23 11:12:36 -0400384 if (call->flags & TRACE_EVENT_FL_ENABLED)
Li Zefan30bd39c2009-09-18 14:07:05 +0800385 return call;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500386 }
387
Li Zefan30bd39c2009-09-18 14:07:05 +0800388 return NULL;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500389}
390
391static void *s_start(struct seq_file *m, loff_t *pos)
392{
Li Zefan30bd39c2009-09-18 14:07:05 +0800393 struct ftrace_event_call *call;
Li Zefane1c7e2a2009-06-24 09:52:29 +0800394 loff_t l;
395
Li Zefan20c89282009-05-06 10:33:45 +0800396 mutex_lock(&event_mutex);
Li Zefane1c7e2a2009-06-24 09:52:29 +0800397
Li Zefan30bd39c2009-09-18 14:07:05 +0800398 call = list_entry(&ftrace_events, struct ftrace_event_call, list);
Li Zefane1c7e2a2009-06-24 09:52:29 +0800399 for (l = 0; l <= *pos; ) {
Li Zefan30bd39c2009-09-18 14:07:05 +0800400 call = s_next(m, call, &l);
Li Zefane1c7e2a2009-06-24 09:52:29 +0800401 if (!call)
402 break;
403 }
404 return call;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500405}
406
407static int t_show(struct seq_file *m, void *v)
408{
409 struct ftrace_event_call *call = v;
410
Steven Rostedt8f082012010-04-20 10:47:33 -0400411 if (strcmp(call->class->system, TRACE_SYSTEM) != 0)
412 seq_printf(m, "%s:", call->class->system);
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500413 seq_printf(m, "%s\n", call->name);
414
415 return 0;
416}
417
418static void t_stop(struct seq_file *m, void *p)
419{
Li Zefan20c89282009-05-06 10:33:45 +0800420 mutex_unlock(&event_mutex);
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500421}
422
423static int
424ftrace_event_seq_open(struct inode *inode, struct file *file)
425{
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500426 const struct seq_operations *seq_ops;
427
428 if ((file->f_mode & FMODE_WRITE) &&
Steven Rostedt8650ae32009-07-22 23:29:30 -0400429 (file->f_flags & O_TRUNC))
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500430 ftrace_clear_events();
431
432 seq_ops = inode->i_private;
Li Zefan20c89282009-05-06 10:33:45 +0800433 return seq_open(file, seq_ops);
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500434}
435
Steven Rostedt1473e442009-02-24 14:15:08 -0500436static ssize_t
437event_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
438 loff_t *ppos)
439{
440 struct ftrace_event_call *call = filp->private_data;
441 char *buf;
442
Steven Rostedt553552c2010-04-23 11:12:36 -0400443 if (call->flags & TRACE_EVENT_FL_ENABLED)
Steven Rostedt1473e442009-02-24 14:15:08 -0500444 buf = "1\n";
445 else
446 buf = "0\n";
447
448 return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
449}
450
451static ssize_t
452event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
453 loff_t *ppos)
454{
455 struct ftrace_event_call *call = filp->private_data;
456 char buf[64];
457 unsigned long val;
458 int ret;
459
460 if (cnt >= sizeof(buf))
461 return -EINVAL;
462
463 if (copy_from_user(&buf, ubuf, cnt))
464 return -EFAULT;
465
466 buf[cnt] = 0;
467
468 ret = strict_strtoul(buf, 10, &val);
469 if (ret < 0)
470 return ret;
471
Steven Rostedt1852fcc2009-03-11 14:33:00 -0400472 ret = tracing_update_buffers();
473 if (ret < 0)
474 return ret;
475
Steven Rostedt1473e442009-02-24 14:15:08 -0500476 switch (val) {
477 case 0:
Steven Rostedt1473e442009-02-24 14:15:08 -0500478 case 1:
Steven Rostedt11a241a2009-03-02 11:49:04 -0500479 mutex_lock(&event_mutex);
Li Zefan3b8e4272009-12-08 11:14:52 +0800480 ret = ftrace_event_enable_disable(call, val);
Steven Rostedt11a241a2009-03-02 11:49:04 -0500481 mutex_unlock(&event_mutex);
Steven Rostedt1473e442009-02-24 14:15:08 -0500482 break;
483
484 default:
485 return -EINVAL;
486 }
487
488 *ppos += cnt;
489
Li Zefan3b8e4272009-12-08 11:14:52 +0800490 return ret ? ret : cnt;
Steven Rostedt1473e442009-02-24 14:15:08 -0500491}
492
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400493static ssize_t
494system_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
495 loff_t *ppos)
496{
Li Zefanc142b152009-05-08 10:32:05 +0800497 const char set_to_char[4] = { '?', '0', '1', 'X' };
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400498 const char *system = filp->private_data;
499 struct ftrace_event_call *call;
500 char buf[2];
Li Zefanc142b152009-05-08 10:32:05 +0800501 int set = 0;
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400502 int ret;
503
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400504 mutex_lock(&event_mutex);
505 list_for_each_entry(call, &ftrace_events, list) {
Steven Rostedta1d0ce82010-06-08 11:22:06 -0400506 if (!call->name || !call->class || !call->class->reg)
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400507 continue;
508
Steven Rostedt8f082012010-04-20 10:47:33 -0400509 if (system && strcmp(call->class->system, system) != 0)
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400510 continue;
511
512 /*
513 * We need to find out if all the events are set
514 * or if all events or cleared, or if we have
515 * a mixture.
516 */
Steven Rostedt553552c2010-04-23 11:12:36 -0400517 set |= (1 << !!(call->flags & TRACE_EVENT_FL_ENABLED));
Li Zefanc142b152009-05-08 10:32:05 +0800518
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400519 /*
520 * If we have a mixture, no need to look further.
521 */
Li Zefanc142b152009-05-08 10:32:05 +0800522 if (set == 3)
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400523 break;
524 }
525 mutex_unlock(&event_mutex);
526
Li Zefanc142b152009-05-08 10:32:05 +0800527 buf[0] = set_to_char[set];
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400528 buf[1] = '\n';
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400529
530 ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
531
532 return ret;
533}
534
535static ssize_t
536system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
537 loff_t *ppos)
538{
539 const char *system = filp->private_data;
540 unsigned long val;
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400541 char buf[64];
542 ssize_t ret;
543
544 if (cnt >= sizeof(buf))
545 return -EINVAL;
546
547 if (copy_from_user(&buf, ubuf, cnt))
548 return -EFAULT;
549
550 buf[cnt] = 0;
551
552 ret = strict_strtoul(buf, 10, &val);
553 if (ret < 0)
554 return ret;
555
556 ret = tracing_update_buffers();
557 if (ret < 0)
558 return ret;
559
Li Zefan8f31bfe2009-05-08 10:31:42 +0800560 if (val != 0 && val != 1)
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400561 return -EINVAL;
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400562
Li Zefan8f31bfe2009-05-08 10:31:42 +0800563 ret = __ftrace_set_clr_event(NULL, system, NULL, val);
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400564 if (ret)
Li Zefan8f31bfe2009-05-08 10:31:42 +0800565 goto out;
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400566
567 ret = cnt;
568
Li Zefan8f31bfe2009-05-08 10:31:42 +0800569out:
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400570 *ppos += cnt;
571
572 return ret;
573}
574
Li Zefan8728fe52010-05-24 16:22:49 +0800575static void print_event_fields(struct trace_seq *s, struct list_head *head)
Steven Rostedt981d0812009-03-02 13:53:59 -0500576{
Lai Jiangshan5a65e952009-12-15 15:39:53 +0800577 struct ftrace_event_field *field;
Steven Rostedt981d0812009-03-02 13:53:59 -0500578
Steven Rostedt2e33af02010-04-22 10:35:55 -0400579 list_for_each_entry_reverse(field, head, link) {
Lai Jiangshan5a65e952009-12-15 15:39:53 +0800580 /*
581 * Smartly shows the array type(except dynamic array).
582 * Normal:
583 * field:TYPE VAR
584 * If TYPE := TYPE[LEN], it is shown:
585 * field:TYPE VAR[LEN]
586 */
587 const char *array_descriptor = strchr(field->type, '[');
588
589 if (!strncmp(field->type, "__data_loc", 10))
590 array_descriptor = NULL;
591
592 if (!array_descriptor) {
Li Zefan8728fe52010-05-24 16:22:49 +0800593 trace_seq_printf(s, "\tfield:%s %s;\toffset:%u;"
Lai Jiangshan5a65e952009-12-15 15:39:53 +0800594 "\tsize:%u;\tsigned:%d;\n",
595 field->type, field->name, field->offset,
596 field->size, !!field->is_signed);
597 } else {
Li Zefan8728fe52010-05-24 16:22:49 +0800598 trace_seq_printf(s, "\tfield:%.*s %s%s;\toffset:%u;"
Lai Jiangshan5a65e952009-12-15 15:39:53 +0800599 "\tsize:%u;\tsigned:%d;\n",
600 (int)(array_descriptor - field->type),
601 field->type, field->name,
602 array_descriptor, field->offset,
603 field->size, !!field->is_signed);
604 }
Lai Jiangshan5a65e952009-12-15 15:39:53 +0800605 }
Li Zefan8728fe52010-05-24 16:22:49 +0800606}
Lai Jiangshan5a65e952009-12-15 15:39:53 +0800607
Li Zefan8728fe52010-05-24 16:22:49 +0800608static ssize_t
609event_format_read(struct file *filp, char __user *ubuf, size_t cnt,
610 loff_t *ppos)
611{
612 struct ftrace_event_call *call = filp->private_data;
613 struct list_head *head;
614 struct trace_seq *s;
615 char *buf;
616 int r;
617
618 if (*ppos)
619 return 0;
620
621 s = kmalloc(sizeof(*s), GFP_KERNEL);
622 if (!s)
623 return -ENOMEM;
624
625 trace_seq_init(s);
626
627 trace_seq_printf(s, "name: %s\n", call->name);
628 trace_seq_printf(s, "ID: %d\n", call->event.type);
629 trace_seq_printf(s, "format:\n");
630
631 /* print common fields */
632 print_event_fields(s, &ftrace_common_fields);
633
634 trace_seq_putc(s, '\n');
635
636 /* print event specific fields */
637 head = trace_get_fields(call);
638 print_event_fields(s, head);
639
640 r = trace_seq_printf(s, "\nprint fmt: %s\n", call->print_fmt);
Lai Jiangshan5a65e952009-12-15 15:39:53 +0800641
Steven Rostedt981d0812009-03-02 13:53:59 -0500642 if (!r) {
643 /*
644 * ug! The format output is bigger than a PAGE!!
645 */
646 buf = "FORMAT TOO BIG\n";
647 r = simple_read_from_buffer(ubuf, cnt, ppos,
648 buf, strlen(buf));
649 goto out;
650 }
651
652 r = simple_read_from_buffer(ubuf, cnt, ppos,
653 s->buffer, s->len);
654 out:
655 kfree(s);
656 return r;
657}
658
Peter Zijlstra23725ae2009-03-19 20:26:13 +0100659static ssize_t
660event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
661{
662 struct ftrace_event_call *call = filp->private_data;
663 struct trace_seq *s;
664 int r;
665
666 if (*ppos)
667 return 0;
668
669 s = kmalloc(sizeof(*s), GFP_KERNEL);
670 if (!s)
671 return -ENOMEM;
672
673 trace_seq_init(s);
Steven Rostedt32c0eda2010-04-23 10:38:03 -0400674 trace_seq_printf(s, "%d\n", call->event.type);
Peter Zijlstra23725ae2009-03-19 20:26:13 +0100675
676 r = simple_read_from_buffer(ubuf, cnt, ppos,
677 s->buffer, s->len);
678 kfree(s);
679 return r;
680}
681
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500682static ssize_t
683event_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
684 loff_t *ppos)
685{
686 struct ftrace_event_call *call = filp->private_data;
687 struct trace_seq *s;
688 int r;
689
690 if (*ppos)
691 return 0;
692
693 s = kmalloc(sizeof(*s), GFP_KERNEL);
694 if (!s)
695 return -ENOMEM;
696
697 trace_seq_init(s);
698
Tom Zanussi8b372562009-04-28 03:04:59 -0500699 print_event_filter(call, s);
Tom Zanussi4bda2d52009-03-24 02:14:31 -0500700 r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500701
702 kfree(s);
703
704 return r;
705}
706
707static ssize_t
708event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
709 loff_t *ppos)
710{
711 struct ftrace_event_call *call = filp->private_data;
Tom Zanussi8b372562009-04-28 03:04:59 -0500712 char *buf;
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500713 int err;
714
Tom Zanussi8b372562009-04-28 03:04:59 -0500715 if (cnt >= PAGE_SIZE)
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500716 return -EINVAL;
717
Tom Zanussi8b372562009-04-28 03:04:59 -0500718 buf = (char *)__get_free_page(GFP_TEMPORARY);
719 if (!buf)
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500720 return -ENOMEM;
721
Tom Zanussi8b372562009-04-28 03:04:59 -0500722 if (copy_from_user(buf, ubuf, cnt)) {
723 free_page((unsigned long) buf);
724 return -EFAULT;
725 }
726 buf[cnt] = '\0';
727
728 err = apply_event_filter(call, buf);
729 free_page((unsigned long) buf);
730 if (err < 0)
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500731 return err;
Tom Zanussi0a19e532009-04-13 03:17:50 -0500732
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500733 *ppos += cnt;
734
735 return cnt;
736}
737
Tom Zanussicfb180f2009-03-22 03:31:17 -0500738static ssize_t
739subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
740 loff_t *ppos)
741{
742 struct event_subsystem *system = filp->private_data;
743 struct trace_seq *s;
744 int r;
745
746 if (*ppos)
747 return 0;
748
749 s = kmalloc(sizeof(*s), GFP_KERNEL);
750 if (!s)
751 return -ENOMEM;
752
753 trace_seq_init(s);
754
Tom Zanussi8b372562009-04-28 03:04:59 -0500755 print_subsystem_event_filter(system, s);
Tom Zanussi4bda2d52009-03-24 02:14:31 -0500756 r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
Tom Zanussicfb180f2009-03-22 03:31:17 -0500757
758 kfree(s);
759
760 return r;
761}
762
763static ssize_t
764subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
765 loff_t *ppos)
766{
767 struct event_subsystem *system = filp->private_data;
Tom Zanussi8b372562009-04-28 03:04:59 -0500768 char *buf;
Tom Zanussicfb180f2009-03-22 03:31:17 -0500769 int err;
770
Tom Zanussi8b372562009-04-28 03:04:59 -0500771 if (cnt >= PAGE_SIZE)
Tom Zanussicfb180f2009-03-22 03:31:17 -0500772 return -EINVAL;
773
Tom Zanussi8b372562009-04-28 03:04:59 -0500774 buf = (char *)__get_free_page(GFP_TEMPORARY);
775 if (!buf)
Tom Zanussicfb180f2009-03-22 03:31:17 -0500776 return -ENOMEM;
777
Tom Zanussi8b372562009-04-28 03:04:59 -0500778 if (copy_from_user(buf, ubuf, cnt)) {
779 free_page((unsigned long) buf);
780 return -EFAULT;
Tom Zanussicfb180f2009-03-22 03:31:17 -0500781 }
Tom Zanussi8b372562009-04-28 03:04:59 -0500782 buf[cnt] = '\0';
Tom Zanussicfb180f2009-03-22 03:31:17 -0500783
Tom Zanussi8b372562009-04-28 03:04:59 -0500784 err = apply_subsystem_event_filter(system, buf);
785 free_page((unsigned long) buf);
786 if (err < 0)
Li Zefan44e9c8b2009-04-11 15:55:28 +0800787 return err;
Tom Zanussicfb180f2009-03-22 03:31:17 -0500788
789 *ppos += cnt;
790
791 return cnt;
792}
793
Steven Rostedtd1b182a2009-04-15 16:53:47 -0400794static ssize_t
795show_header(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
796{
797 int (*func)(struct trace_seq *s) = filp->private_data;
798 struct trace_seq *s;
799 int r;
800
801 if (*ppos)
802 return 0;
803
804 s = kmalloc(sizeof(*s), GFP_KERNEL);
805 if (!s)
806 return -ENOMEM;
807
808 trace_seq_init(s);
809
810 func(s);
811 r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
812
813 kfree(s);
814
815 return r;
816}
817
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500818static const struct seq_operations show_event_seq_ops = {
819 .start = t_start,
820 .next = t_next,
821 .show = t_show,
822 .stop = t_stop,
823};
824
825static const struct seq_operations show_set_event_seq_ops = {
826 .start = s_start,
827 .next = s_next,
828 .show = t_show,
829 .stop = t_stop,
830};
831
Steven Rostedt2314c4a2009-03-10 12:04:02 -0400832static const struct file_operations ftrace_avail_fops = {
833 .open = ftrace_event_seq_open,
834 .read = seq_read,
835 .llseek = seq_lseek,
836 .release = seq_release,
837};
838
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500839static const struct file_operations ftrace_set_event_fops = {
840 .open = ftrace_event_seq_open,
841 .read = seq_read,
842 .write = ftrace_event_write,
843 .llseek = seq_lseek,
844 .release = seq_release,
845};
846
Steven Rostedt1473e442009-02-24 14:15:08 -0500847static const struct file_operations ftrace_enable_fops = {
848 .open = tracing_open_generic,
849 .read = event_enable_read,
850 .write = event_enable_write,
851};
852
Steven Rostedt981d0812009-03-02 13:53:59 -0500853static const struct file_operations ftrace_event_format_fops = {
854 .open = tracing_open_generic,
855 .read = event_format_read,
856};
857
Peter Zijlstra23725ae2009-03-19 20:26:13 +0100858static const struct file_operations ftrace_event_id_fops = {
859 .open = tracing_open_generic,
860 .read = event_id_read,
861};
862
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500863static const struct file_operations ftrace_event_filter_fops = {
864 .open = tracing_open_generic,
865 .read = event_filter_read,
866 .write = event_filter_write,
867};
868
Tom Zanussicfb180f2009-03-22 03:31:17 -0500869static const struct file_operations ftrace_subsystem_filter_fops = {
870 .open = tracing_open_generic,
871 .read = subsystem_filter_read,
872 .write = subsystem_filter_write,
873};
874
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400875static const struct file_operations ftrace_system_enable_fops = {
876 .open = tracing_open_generic,
877 .read = system_enable_read,
878 .write = system_enable_write,
879};
880
Steven Rostedtd1b182a2009-04-15 16:53:47 -0400881static const struct file_operations ftrace_show_header_fops = {
882 .open = tracing_open_generic,
883 .read = show_header,
884};
885
Steven Rostedt1473e442009-02-24 14:15:08 -0500886static struct dentry *event_trace_events_dir(void)
887{
888 static struct dentry *d_tracer;
889 static struct dentry *d_events;
890
891 if (d_events)
892 return d_events;
893
894 d_tracer = tracing_init_dentry();
895 if (!d_tracer)
896 return NULL;
897
898 d_events = debugfs_create_dir("events", d_tracer);
899 if (!d_events)
900 pr_warning("Could not create debugfs "
901 "'events' directory\n");
902
903 return d_events;
904}
905
Steven Rostedt6ecc2d12009-02-27 21:33:02 -0500906static LIST_HEAD(event_subsystems);
907
908static struct dentry *
909event_subsystem_dir(const char *name, struct dentry *d_events)
910{
911 struct event_subsystem *system;
Tom Zanussie1112b42009-03-31 00:48:49 -0500912 struct dentry *entry;
Steven Rostedt6ecc2d12009-02-27 21:33:02 -0500913
914 /* First see if we did not already create this dir */
915 list_for_each_entry(system, &event_subsystems, list) {
Xiao Guangrongdc82ec98a2009-07-09 16:22:22 +0800916 if (strcmp(system->name, name) == 0) {
917 system->nr_events++;
Steven Rostedt6ecc2d12009-02-27 21:33:02 -0500918 return system->entry;
Xiao Guangrongdc82ec98a2009-07-09 16:22:22 +0800919 }
Steven Rostedt6ecc2d12009-02-27 21:33:02 -0500920 }
921
922 /* need to create new entry */
923 system = kmalloc(sizeof(*system), GFP_KERNEL);
924 if (!system) {
925 pr_warning("No memory to create event subsystem %s\n",
926 name);
927 return d_events;
928 }
929
930 system->entry = debugfs_create_dir(name, d_events);
931 if (!system->entry) {
932 pr_warning("Could not create event subsystem %s\n",
933 name);
934 kfree(system);
935 return d_events;
936 }
937
Xiao Guangrongdc82ec98a2009-07-09 16:22:22 +0800938 system->nr_events = 1;
Steven Rostedt6d723732009-04-10 14:53:50 -0400939 system->name = kstrdup(name, GFP_KERNEL);
940 if (!system->name) {
941 debugfs_remove(system->entry);
942 kfree(system);
943 return d_events;
944 }
945
Steven Rostedt6ecc2d12009-02-27 21:33:02 -0500946 list_add(&system->list, &event_subsystems);
947
Tom Zanussi30e673b2009-04-28 03:04:47 -0500948 system->filter = NULL;
Tom Zanussicfb180f2009-03-22 03:31:17 -0500949
Tom Zanussi8b372562009-04-28 03:04:59 -0500950 system->filter = kzalloc(sizeof(struct event_filter), GFP_KERNEL);
951 if (!system->filter) {
952 pr_warning("Could not allocate filter for subsystem "
953 "'%s'\n", name);
954 return system->entry;
955 }
956
Tom Zanussie1112b42009-03-31 00:48:49 -0500957 entry = debugfs_create_file("filter", 0644, system->entry, system,
958 &ftrace_subsystem_filter_fops);
Tom Zanussi8b372562009-04-28 03:04:59 -0500959 if (!entry) {
960 kfree(system->filter);
961 system->filter = NULL;
Tom Zanussie1112b42009-03-31 00:48:49 -0500962 pr_warning("Could not create debugfs "
963 "'%s/filter' entry\n", name);
Tom Zanussi8b372562009-04-28 03:04:59 -0500964 }
Tom Zanussie1112b42009-03-31 00:48:49 -0500965
Frederic Weisbeckerf3f3f002009-09-24 15:27:41 +0200966 trace_create_file("enable", 0644, system->entry,
967 (void *)system->name,
968 &ftrace_system_enable_fops);
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400969
Steven Rostedt6ecc2d12009-02-27 21:33:02 -0500970 return system->entry;
971}
972
Steven Rostedt1473e442009-02-24 14:15:08 -0500973static int
Steven Rostedt701970b2009-04-24 23:11:22 -0400974event_create_dir(struct ftrace_event_call *call, struct dentry *d_events,
975 const struct file_operations *id,
976 const struct file_operations *enable,
977 const struct file_operations *filter,
978 const struct file_operations *format)
Steven Rostedt1473e442009-02-24 14:15:08 -0500979{
Steven Rostedt2e33af02010-04-22 10:35:55 -0400980 struct list_head *head;
Steven Rostedtfd994982009-02-28 02:41:25 -0500981 int ret;
Steven Rostedt1473e442009-02-24 14:15:08 -0500982
Steven Rostedt6ecc2d12009-02-27 21:33:02 -0500983 /*
984 * If the trace point header did not define TRACE_SYSTEM
985 * then the system would be called "TRACE_SYSTEM".
986 */
Steven Rostedt8f082012010-04-20 10:47:33 -0400987 if (strcmp(call->class->system, TRACE_SYSTEM) != 0)
988 d_events = event_subsystem_dir(call->class->system, d_events);
Steven Rostedt6ecc2d12009-02-27 21:33:02 -0500989
Steven Rostedt1473e442009-02-24 14:15:08 -0500990 call->dir = debugfs_create_dir(call->name, d_events);
991 if (!call->dir) {
992 pr_warning("Could not create debugfs "
993 "'%s' directory\n", call->name);
994 return -1;
995 }
996
Steven Rostedta1d0ce82010-06-08 11:22:06 -0400997 if (call->class->reg)
Frederic Weisbeckerf3f3f002009-09-24 15:27:41 +0200998 trace_create_file("enable", 0644, call->dir, call,
999 enable);
Steven Rostedt1473e442009-02-24 14:15:08 -05001000
Steven Rostedt22392912010-04-21 12:27:06 -04001001#ifdef CONFIG_PERF_EVENTS
Steven Rostedta1d0ce82010-06-08 11:22:06 -04001002 if (call->event.type && call->class->reg)
Frederic Weisbeckerf3f3f002009-09-24 15:27:41 +02001003 trace_create_file("id", 0444, call->dir, call,
1004 id);
Steven Rostedt22392912010-04-21 12:27:06 -04001005#endif
Peter Zijlstra23725ae2009-03-19 20:26:13 +01001006
Li Zefanc9d932c2010-05-24 16:24:28 +08001007 /*
1008 * Other events may have the same class. Only update
1009 * the fields if they are not already defined.
1010 */
1011 head = trace_get_fields(call);
1012 if (list_empty(head)) {
1013 ret = call->class->define_fields(call);
1014 if (ret < 0) {
1015 pr_warning("Could not initialize trace point"
1016 " events/%s\n", call->name);
1017 return ret;
Tom Zanussicf027f62009-03-22 03:30:39 -05001018 }
1019 }
Li Zefanc9d932c2010-05-24 16:24:28 +08001020 trace_create_file("filter", 0644, call->dir, call,
1021 filter);
Tom Zanussicf027f62009-03-22 03:30:39 -05001022
Frederic Weisbeckerf3f3f002009-09-24 15:27:41 +02001023 trace_create_file("format", 0444, call->dir, call,
1024 format);
Steven Rostedtfd994982009-02-28 02:41:25 -05001025
Steven Rostedt1473e442009-02-24 14:15:08 -05001026 return 0;
1027}
1028
Li Zefan67ead0a2010-05-24 16:25:13 +08001029static int
1030__trace_add_event_call(struct ftrace_event_call *call, struct module *mod,
1031 const struct file_operations *id,
1032 const struct file_operations *enable,
1033 const struct file_operations *filter,
1034 const struct file_operations *format)
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001035{
1036 struct dentry *d_events;
1037 int ret;
Steven Rostedt6d723732009-04-10 14:53:50 -04001038
Li Zefan67ead0a2010-05-24 16:25:13 +08001039 /* The linker may leave blanks */
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001040 if (!call->name)
1041 return -EINVAL;
Steven Rostedt701970b2009-04-24 23:11:22 -04001042
Steven Rostedt0405ab82010-04-22 11:46:44 -04001043 if (call->class->raw_init) {
1044 ret = call->class->raw_init(call);
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001045 if (ret < 0) {
1046 if (ret != -ENOSYS)
Li Zefan67ead0a2010-05-24 16:25:13 +08001047 pr_warning("Could not initialize trace events/%s\n",
1048 call->name);
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001049 return ret;
1050 }
1051 }
Steven Rostedt701970b2009-04-24 23:11:22 -04001052
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001053 d_events = event_trace_events_dir();
1054 if (!d_events)
1055 return -ENOENT;
1056
Li Zefan67ead0a2010-05-24 16:25:13 +08001057 ret = event_create_dir(call, d_events, id, enable, filter, format);
Masami Hiramatsu88f70d72009-09-25 11:20:54 -07001058 if (!ret)
1059 list_add(&call->list, &ftrace_events);
Li Zefan67ead0a2010-05-24 16:25:13 +08001060 call->mod = mod;
Masami Hiramatsu88f70d72009-09-25 11:20:54 -07001061
Masami Hiramatsu588bebb2009-09-16 11:42:55 -04001062 return ret;
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001063}
1064
1065/* Add an additional event_call dynamically */
1066int trace_add_event_call(struct ftrace_event_call *call)
1067{
1068 int ret;
1069 mutex_lock(&event_mutex);
Li Zefan67ead0a2010-05-24 16:25:13 +08001070 ret = __trace_add_event_call(call, NULL, &ftrace_event_id_fops,
1071 &ftrace_enable_fops,
1072 &ftrace_event_filter_fops,
1073 &ftrace_event_format_fops);
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001074 mutex_unlock(&event_mutex);
1075 return ret;
1076}
Steven Rostedt701970b2009-04-24 23:11:22 -04001077
Frederic Weisbeckera2ca5e02009-08-06 07:32:21 +02001078static void remove_subsystem_dir(const char *name)
1079{
1080 struct event_subsystem *system;
1081
1082 if (strcmp(name, TRACE_SYSTEM) == 0)
1083 return;
1084
1085 list_for_each_entry(system, &event_subsystems, list) {
1086 if (strcmp(system->name, name) == 0) {
1087 if (!--system->nr_events) {
1088 struct event_filter *filter = system->filter;
1089
1090 debugfs_remove_recursive(system->entry);
1091 list_del(&system->list);
1092 if (filter) {
1093 kfree(filter->filter_string);
1094 kfree(filter);
1095 }
1096 kfree(system->name);
1097 kfree(system);
1098 }
1099 break;
1100 }
1101 }
1102}
1103
Masami Hiramatsu4fead8e2009-09-14 16:49:12 -04001104/*
1105 * Must be called under locking both of event_mutex and trace_event_mutex.
1106 */
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001107static void __trace_remove_event_call(struct ftrace_event_call *call)
1108{
1109 ftrace_event_enable_disable(call, 0);
Steven Rostedt80decc72010-04-23 10:00:22 -04001110 if (call->event.funcs)
1111 __unregister_ftrace_event(&call->event);
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001112 debugfs_remove_recursive(call->dir);
1113 list_del(&call->list);
1114 trace_destroy_fields(call);
1115 destroy_preds(call);
Steven Rostedt8f082012010-04-20 10:47:33 -04001116 remove_subsystem_dir(call->class->system);
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001117}
1118
1119/* Remove an event_call */
1120void trace_remove_event_call(struct ftrace_event_call *call)
1121{
1122 mutex_lock(&event_mutex);
Masami Hiramatsu4fead8e2009-09-14 16:49:12 -04001123 down_write(&trace_event_mutex);
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001124 __trace_remove_event_call(call);
Masami Hiramatsu4fead8e2009-09-14 16:49:12 -04001125 up_write(&trace_event_mutex);
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001126 mutex_unlock(&event_mutex);
1127}
1128
1129#define for_each_event(event, start, end) \
1130 for (event = start; \
1131 (unsigned long)event < (unsigned long)end; \
1132 event++)
1133
1134#ifdef CONFIG_MODULES
1135
1136static LIST_HEAD(ftrace_module_file_list);
1137
1138/*
1139 * Modules must own their file_operations to keep up with
1140 * reference counting.
1141 */
1142struct ftrace_module_file_ops {
1143 struct list_head list;
1144 struct module *mod;
1145 struct file_operations id;
1146 struct file_operations enable;
1147 struct file_operations format;
1148 struct file_operations filter;
1149};
1150
Steven Rostedt701970b2009-04-24 23:11:22 -04001151static struct ftrace_module_file_ops *
1152trace_create_file_ops(struct module *mod)
1153{
1154 struct ftrace_module_file_ops *file_ops;
1155
1156 /*
1157 * This is a bit of a PITA. To allow for correct reference
1158 * counting, modules must "own" their file_operations.
1159 * To do this, we allocate the file operations that will be
1160 * used in the event directory.
1161 */
1162
1163 file_ops = kmalloc(sizeof(*file_ops), GFP_KERNEL);
1164 if (!file_ops)
1165 return NULL;
1166
1167 file_ops->mod = mod;
1168
1169 file_ops->id = ftrace_event_id_fops;
1170 file_ops->id.owner = mod;
1171
1172 file_ops->enable = ftrace_enable_fops;
1173 file_ops->enable.owner = mod;
1174
1175 file_ops->filter = ftrace_event_filter_fops;
1176 file_ops->filter.owner = mod;
1177
1178 file_ops->format = ftrace_event_format_fops;
1179 file_ops->format.owner = mod;
1180
1181 list_add(&file_ops->list, &ftrace_module_file_list);
1182
1183 return file_ops;
1184}
1185
Steven Rostedt6d723732009-04-10 14:53:50 -04001186static void trace_module_add_events(struct module *mod)
1187{
Steven Rostedt701970b2009-04-24 23:11:22 -04001188 struct ftrace_module_file_ops *file_ops = NULL;
Steven Rostedt6d723732009-04-10 14:53:50 -04001189 struct ftrace_event_call *call, *start, *end;
Steven Rostedt6d723732009-04-10 14:53:50 -04001190
1191 start = mod->trace_events;
1192 end = mod->trace_events + mod->num_trace_events;
1193
1194 if (start == end)
1195 return;
1196
Li Zefan67ead0a2010-05-24 16:25:13 +08001197 file_ops = trace_create_file_ops(mod);
1198 if (!file_ops)
Steven Rostedt6d723732009-04-10 14:53:50 -04001199 return;
1200
1201 for_each_event(call, start, end) {
Li Zefan67ead0a2010-05-24 16:25:13 +08001202 __trace_add_event_call(call, mod,
Masami Hiramatsu88f70d72009-09-25 11:20:54 -07001203 &file_ops->id, &file_ops->enable,
1204 &file_ops->filter, &file_ops->format);
Steven Rostedt6d723732009-04-10 14:53:50 -04001205 }
1206}
1207
1208static void trace_module_remove_events(struct module *mod)
1209{
Steven Rostedt701970b2009-04-24 23:11:22 -04001210 struct ftrace_module_file_ops *file_ops;
Steven Rostedt6d723732009-04-10 14:53:50 -04001211 struct ftrace_event_call *call, *p;
Steven Rostedt9456f0f2009-05-06 21:54:09 -04001212 bool found = false;
Steven Rostedt6d723732009-04-10 14:53:50 -04001213
Steven Rostedt110bf2b2009-06-09 17:29:07 -04001214 down_write(&trace_event_mutex);
Steven Rostedt6d723732009-04-10 14:53:50 -04001215 list_for_each_entry_safe(call, p, &ftrace_events, list) {
1216 if (call->mod == mod) {
Steven Rostedt9456f0f2009-05-06 21:54:09 -04001217 found = true;
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001218 __trace_remove_event_call(call);
Steven Rostedt6d723732009-04-10 14:53:50 -04001219 }
1220 }
Steven Rostedt701970b2009-04-24 23:11:22 -04001221
1222 /* Now free the file_operations */
1223 list_for_each_entry(file_ops, &ftrace_module_file_list, list) {
1224 if (file_ops->mod == mod)
1225 break;
1226 }
1227 if (&file_ops->list != &ftrace_module_file_list) {
1228 list_del(&file_ops->list);
1229 kfree(file_ops);
1230 }
Steven Rostedt9456f0f2009-05-06 21:54:09 -04001231
1232 /*
1233 * It is safest to reset the ring buffer if the module being unloaded
1234 * registered any events.
1235 */
1236 if (found)
1237 tracing_reset_current_online_cpus();
Steven Rostedt110bf2b2009-06-09 17:29:07 -04001238 up_write(&trace_event_mutex);
Steven Rostedt6d723732009-04-10 14:53:50 -04001239}
1240
Steven Rostedt61f919a2009-04-14 18:22:32 -04001241static int trace_module_notify(struct notifier_block *self,
1242 unsigned long val, void *data)
Steven Rostedt6d723732009-04-10 14:53:50 -04001243{
1244 struct module *mod = data;
1245
1246 mutex_lock(&event_mutex);
1247 switch (val) {
1248 case MODULE_STATE_COMING:
1249 trace_module_add_events(mod);
1250 break;
1251 case MODULE_STATE_GOING:
1252 trace_module_remove_events(mod);
1253 break;
1254 }
1255 mutex_unlock(&event_mutex);
1256
1257 return 0;
1258}
Steven Rostedt61f919a2009-04-14 18:22:32 -04001259#else
1260static int trace_module_notify(struct notifier_block *self,
1261 unsigned long val, void *data)
1262{
1263 return 0;
1264}
1265#endif /* CONFIG_MODULES */
Steven Rostedt6d723732009-04-10 14:53:50 -04001266
Steven Rostedtec827c72009-09-14 10:50:23 -04001267static struct notifier_block trace_module_nb = {
Steven Rostedt6d723732009-04-10 14:53:50 -04001268 .notifier_call = trace_module_notify,
1269 .priority = 0,
1270};
1271
Steven Rostedta59fd602009-04-10 13:52:20 -04001272extern struct ftrace_event_call __start_ftrace_events[];
1273extern struct ftrace_event_call __stop_ftrace_events[];
1274
Li Zefan020e5f82009-07-01 10:47:05 +08001275static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata;
1276
1277static __init int setup_trace_event(char *str)
1278{
1279 strlcpy(bootup_event_buf, str, COMMAND_LINE_SIZE);
1280 ring_buffer_expanded = 1;
1281 tracing_selftest_disabled = 1;
1282
1283 return 1;
1284}
1285__setup("trace_event=", setup_trace_event);
1286
Steven Rostedtb77e38a2009-02-24 10:21:36 -05001287static __init int event_trace_init(void)
1288{
Steven Rostedta59fd602009-04-10 13:52:20 -04001289 struct ftrace_event_call *call;
Steven Rostedtb77e38a2009-02-24 10:21:36 -05001290 struct dentry *d_tracer;
1291 struct dentry *entry;
Steven Rostedt1473e442009-02-24 14:15:08 -05001292 struct dentry *d_events;
Steven Rostedt6d723732009-04-10 14:53:50 -04001293 int ret;
Li Zefan020e5f82009-07-01 10:47:05 +08001294 char *buf = bootup_event_buf;
1295 char *token;
Steven Rostedtb77e38a2009-02-24 10:21:36 -05001296
1297 d_tracer = tracing_init_dentry();
1298 if (!d_tracer)
1299 return 0;
1300
Steven Rostedt2314c4a2009-03-10 12:04:02 -04001301 entry = debugfs_create_file("available_events", 0444, d_tracer,
1302 (void *)&show_event_seq_ops,
1303 &ftrace_avail_fops);
1304 if (!entry)
1305 pr_warning("Could not create debugfs "
1306 "'available_events' entry\n");
1307
Steven Rostedtb77e38a2009-02-24 10:21:36 -05001308 entry = debugfs_create_file("set_event", 0644, d_tracer,
1309 (void *)&show_set_event_seq_ops,
1310 &ftrace_set_event_fops);
1311 if (!entry)
1312 pr_warning("Could not create debugfs "
1313 "'set_event' entry\n");
1314
Steven Rostedt1473e442009-02-24 14:15:08 -05001315 d_events = event_trace_events_dir();
1316 if (!d_events)
1317 return 0;
1318
Steven Rostedtd1b182a2009-04-15 16:53:47 -04001319 /* ring buffer internal formats */
1320 trace_create_file("header_page", 0444, d_events,
1321 ring_buffer_print_page_header,
1322 &ftrace_show_header_fops);
1323
1324 trace_create_file("header_event", 0444, d_events,
1325 ring_buffer_print_entry_header,
1326 &ftrace_show_header_fops);
1327
Steven Rostedt8ae79a12009-05-06 22:52:15 -04001328 trace_create_file("enable", 0644, d_events,
Li Zefan8f31bfe2009-05-08 10:31:42 +08001329 NULL, &ftrace_system_enable_fops);
Steven Rostedt8ae79a12009-05-06 22:52:15 -04001330
Li Zefan8728fe52010-05-24 16:22:49 +08001331 if (trace_define_common_fields())
1332 pr_warning("tracing: Failed to allocate common fields");
1333
Steven Rostedt6d723732009-04-10 14:53:50 -04001334 for_each_event(call, __start_ftrace_events, __stop_ftrace_events) {
Li Zefan67ead0a2010-05-24 16:25:13 +08001335 __trace_add_event_call(call, NULL, &ftrace_event_id_fops,
Masami Hiramatsu88f70d72009-09-25 11:20:54 -07001336 &ftrace_enable_fops,
1337 &ftrace_event_filter_fops,
1338 &ftrace_event_format_fops);
Steven Rostedt1473e442009-02-24 14:15:08 -05001339 }
1340
Li Zefan020e5f82009-07-01 10:47:05 +08001341 while (true) {
1342 token = strsep(&buf, ",");
1343
1344 if (!token)
1345 break;
1346 if (!*token)
1347 continue;
1348
1349 ret = ftrace_set_clr_event(token, 1);
1350 if (ret)
1351 pr_warning("Failed to enable trace event: %s\n", token);
1352 }
1353
Steven Rostedt6d723732009-04-10 14:53:50 -04001354 ret = register_module_notifier(&trace_module_nb);
Ming Lei55379372009-05-18 23:04:46 +08001355 if (ret)
Steven Rostedt6d723732009-04-10 14:53:50 -04001356 pr_warning("Failed to register trace events module notifier\n");
1357
Steven Rostedtb77e38a2009-02-24 10:21:36 -05001358 return 0;
1359}
1360fs_initcall(event_trace_init);
Steven Rostedte6187002009-04-15 13:36:40 -04001361
1362#ifdef CONFIG_FTRACE_STARTUP_TEST
1363
1364static DEFINE_SPINLOCK(test_spinlock);
1365static DEFINE_SPINLOCK(test_spinlock_irq);
1366static DEFINE_MUTEX(test_mutex);
1367
1368static __init void test_work(struct work_struct *dummy)
1369{
1370 spin_lock(&test_spinlock);
1371 spin_lock_irq(&test_spinlock_irq);
1372 udelay(1);
1373 spin_unlock_irq(&test_spinlock_irq);
1374 spin_unlock(&test_spinlock);
1375
1376 mutex_lock(&test_mutex);
1377 msleep(1);
1378 mutex_unlock(&test_mutex);
1379}
1380
1381static __init int event_test_thread(void *unused)
1382{
1383 void *test_malloc;
1384
1385 test_malloc = kmalloc(1234, GFP_KERNEL);
1386 if (!test_malloc)
1387 pr_info("failed to kmalloc\n");
1388
1389 schedule_on_each_cpu(test_work);
1390
1391 kfree(test_malloc);
1392
1393 set_current_state(TASK_INTERRUPTIBLE);
1394 while (!kthread_should_stop())
1395 schedule();
1396
1397 return 0;
1398}
1399
1400/*
1401 * Do various things that may trigger events.
1402 */
1403static __init void event_test_stuff(void)
1404{
1405 struct task_struct *test_thread;
1406
1407 test_thread = kthread_run(event_test_thread, NULL, "test-events");
1408 msleep(1);
1409 kthread_stop(test_thread);
1410}
1411
1412/*
1413 * For every trace event defined, we will test each trace point separately,
1414 * and then by groups, and finally all trace points.
1415 */
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001416static __init void event_trace_self_tests(void)
Steven Rostedte6187002009-04-15 13:36:40 -04001417{
1418 struct ftrace_event_call *call;
1419 struct event_subsystem *system;
Steven Rostedte6187002009-04-15 13:36:40 -04001420 int ret;
1421
1422 pr_info("Running tests on trace events:\n");
1423
1424 list_for_each_entry(call, &ftrace_events, list) {
1425
Steven Rostedt22392912010-04-21 12:27:06 -04001426 /* Only test those that have a probe */
1427 if (!call->class || !call->class->probe)
Steven Rostedte6187002009-04-15 13:36:40 -04001428 continue;
1429
Steven Rostedt1f5a6b42009-09-14 11:58:24 -04001430/*
1431 * Testing syscall events here is pretty useless, but
1432 * we still do it if configured. But this is time consuming.
1433 * What we really need is a user thread to perform the
1434 * syscalls as we test.
1435 */
1436#ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS
Steven Rostedt8f082012010-04-20 10:47:33 -04001437 if (call->class->system &&
1438 strcmp(call->class->system, "syscalls") == 0)
Steven Rostedt1f5a6b42009-09-14 11:58:24 -04001439 continue;
1440#endif
1441
Steven Rostedte6187002009-04-15 13:36:40 -04001442 pr_info("Testing event %s: ", call->name);
1443
1444 /*
1445 * If an event is already enabled, someone is using
1446 * it and the self test should not be on.
1447 */
Steven Rostedt553552c2010-04-23 11:12:36 -04001448 if (call->flags & TRACE_EVENT_FL_ENABLED) {
Steven Rostedte6187002009-04-15 13:36:40 -04001449 pr_warning("Enabled event during self test!\n");
1450 WARN_ON_ONCE(1);
1451 continue;
1452 }
1453
Zhaolei0e907c92009-05-25 18:13:59 +08001454 ftrace_event_enable_disable(call, 1);
Steven Rostedte6187002009-04-15 13:36:40 -04001455 event_test_stuff();
Zhaolei0e907c92009-05-25 18:13:59 +08001456 ftrace_event_enable_disable(call, 0);
Steven Rostedte6187002009-04-15 13:36:40 -04001457
1458 pr_cont("OK\n");
1459 }
1460
1461 /* Now test at the sub system level */
1462
1463 pr_info("Running tests on trace event systems:\n");
1464
1465 list_for_each_entry(system, &event_subsystems, list) {
1466
1467 /* the ftrace system is special, skip it */
1468 if (strcmp(system->name, "ftrace") == 0)
1469 continue;
1470
1471 pr_info("Testing event system %s: ", system->name);
1472
Li Zefan8f31bfe2009-05-08 10:31:42 +08001473 ret = __ftrace_set_clr_event(NULL, system->name, NULL, 1);
Steven Rostedte6187002009-04-15 13:36:40 -04001474 if (WARN_ON_ONCE(ret)) {
1475 pr_warning("error enabling system %s\n",
1476 system->name);
1477 continue;
1478 }
1479
1480 event_test_stuff();
1481
Li Zefan8f31bfe2009-05-08 10:31:42 +08001482 ret = __ftrace_set_clr_event(NULL, system->name, NULL, 0);
Steven Rostedte6187002009-04-15 13:36:40 -04001483 if (WARN_ON_ONCE(ret))
1484 pr_warning("error disabling system %s\n",
1485 system->name);
1486
1487 pr_cont("OK\n");
1488 }
1489
1490 /* Test with all events enabled */
1491
1492 pr_info("Running tests on all trace events:\n");
1493 pr_info("Testing all events: ");
1494
Li Zefan8f31bfe2009-05-08 10:31:42 +08001495 ret = __ftrace_set_clr_event(NULL, NULL, NULL, 1);
Steven Rostedte6187002009-04-15 13:36:40 -04001496 if (WARN_ON_ONCE(ret)) {
Steven Rostedte6187002009-04-15 13:36:40 -04001497 pr_warning("error enabling all events\n");
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001498 return;
Steven Rostedte6187002009-04-15 13:36:40 -04001499 }
1500
1501 event_test_stuff();
1502
1503 /* reset sysname */
Li Zefan8f31bfe2009-05-08 10:31:42 +08001504 ret = __ftrace_set_clr_event(NULL, NULL, NULL, 0);
Steven Rostedte6187002009-04-15 13:36:40 -04001505 if (WARN_ON_ONCE(ret)) {
1506 pr_warning("error disabling all events\n");
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001507 return;
Steven Rostedte6187002009-04-15 13:36:40 -04001508 }
1509
1510 pr_cont("OK\n");
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001511}
1512
1513#ifdef CONFIG_FUNCTION_TRACER
1514
Tejun Heo245b2e72009-06-24 15:13:48 +09001515static DEFINE_PER_CPU(atomic_t, ftrace_test_event_disable);
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001516
1517static void
1518function_test_events_call(unsigned long ip, unsigned long parent_ip)
1519{
1520 struct ring_buffer_event *event;
Steven Rostedte77405a2009-09-02 14:17:06 -04001521 struct ring_buffer *buffer;
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001522 struct ftrace_entry *entry;
1523 unsigned long flags;
1524 long disabled;
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001525 int cpu;
1526 int pc;
1527
1528 pc = preempt_count();
Steven Rostedt5168ae52010-06-03 09:36:50 -04001529 preempt_disable_notrace();
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001530 cpu = raw_smp_processor_id();
Tejun Heo245b2e72009-06-24 15:13:48 +09001531 disabled = atomic_inc_return(&per_cpu(ftrace_test_event_disable, cpu));
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001532
1533 if (disabled != 1)
1534 goto out;
1535
1536 local_save_flags(flags);
1537
Steven Rostedte77405a2009-09-02 14:17:06 -04001538 event = trace_current_buffer_lock_reserve(&buffer,
1539 TRACE_FN, sizeof(*entry),
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001540 flags, pc);
1541 if (!event)
1542 goto out;
1543 entry = ring_buffer_event_data(event);
1544 entry->ip = ip;
1545 entry->parent_ip = parent_ip;
1546
Steven Rostedte77405a2009-09-02 14:17:06 -04001547 trace_nowake_buffer_unlock_commit(buffer, event, flags, pc);
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001548
1549 out:
Tejun Heo245b2e72009-06-24 15:13:48 +09001550 atomic_dec(&per_cpu(ftrace_test_event_disable, cpu));
Steven Rostedt5168ae52010-06-03 09:36:50 -04001551 preempt_enable_notrace();
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001552}
1553
1554static struct ftrace_ops trace_ops __initdata =
1555{
1556 .func = function_test_events_call,
1557};
1558
1559static __init void event_trace_self_test_with_function(void)
1560{
1561 register_ftrace_function(&trace_ops);
1562 pr_info("Running tests again, along with the function tracer\n");
1563 event_trace_self_tests();
1564 unregister_ftrace_function(&trace_ops);
1565}
1566#else
1567static __init void event_trace_self_test_with_function(void)
1568{
1569}
1570#endif
1571
1572static __init int event_trace_self_tests_init(void)
1573{
Li Zefan020e5f82009-07-01 10:47:05 +08001574 if (!tracing_selftest_disabled) {
1575 event_trace_self_tests();
1576 event_trace_self_test_with_function();
1577 }
Steven Rostedte6187002009-04-15 13:36:40 -04001578
1579 return 0;
1580}
1581
Steven Rostedt28d20e22009-04-20 12:12:44 -04001582late_initcall(event_trace_self_tests_init);
Steven Rostedte6187002009-04-15 13:36:40 -04001583
1584#endif