blob: 09b4fa6e4d3be8b83758c48a529d01a6f18010da [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 Zefane870e9a2010-07-02 11:07:32 +0800173void trace_event_enable_cmd_record(bool enable)
174{
175 struct ftrace_event_call *call;
176
177 mutex_lock(&event_mutex);
178 list_for_each_entry(call, &ftrace_events, list) {
179 if (!(call->flags & TRACE_EVENT_FL_ENABLED))
180 continue;
181
182 if (enable) {
183 tracing_start_cmdline_record();
184 call->flags |= TRACE_EVENT_FL_RECORDED_CMD;
185 } else {
186 tracing_stop_cmdline_record();
187 call->flags &= ~TRACE_EVENT_FL_RECORDED_CMD;
188 }
189 }
190 mutex_unlock(&event_mutex);
191}
192
Li Zefan3b8e4272009-12-08 11:14:52 +0800193static int ftrace_event_enable_disable(struct ftrace_event_call *call,
Steven Rostedtfd994982009-02-28 02:41:25 -0500194 int enable)
195{
Li Zefan3b8e4272009-12-08 11:14:52 +0800196 int ret = 0;
197
Steven Rostedtfd994982009-02-28 02:41:25 -0500198 switch (enable) {
199 case 0:
Steven Rostedt553552c2010-04-23 11:12:36 -0400200 if (call->flags & TRACE_EVENT_FL_ENABLED) {
201 call->flags &= ~TRACE_EVENT_FL_ENABLED;
Li Zefane870e9a2010-07-02 11:07:32 +0800202 if (call->flags & TRACE_EVENT_FL_RECORDED_CMD) {
203 tracing_stop_cmdline_record();
204 call->flags &= ~TRACE_EVENT_FL_RECORDED_CMD;
205 }
Steven Rostedta1d0ce82010-06-08 11:22:06 -0400206 call->class->reg(call, TRACE_REG_UNREGISTER);
Steven Rostedtfd994982009-02-28 02:41:25 -0500207 }
Steven Rostedtfd994982009-02-28 02:41:25 -0500208 break;
209 case 1:
Steven Rostedt553552c2010-04-23 11:12:36 -0400210 if (!(call->flags & TRACE_EVENT_FL_ENABLED)) {
Li Zefane870e9a2010-07-02 11:07:32 +0800211 if (trace_flags & TRACE_ITER_RECORD_CMD) {
212 tracing_start_cmdline_record();
213 call->flags |= TRACE_EVENT_FL_RECORDED_CMD;
214 }
Steven Rostedta1d0ce82010-06-08 11:22:06 -0400215 ret = call->class->reg(call, TRACE_REG_REGISTER);
Li Zefan3b8e4272009-12-08 11:14:52 +0800216 if (ret) {
217 tracing_stop_cmdline_record();
218 pr_info("event trace: Could not enable event "
219 "%s\n", call->name);
220 break;
221 }
Steven Rostedt553552c2010-04-23 11:12:36 -0400222 call->flags |= TRACE_EVENT_FL_ENABLED;
Steven Rostedtfd994982009-02-28 02:41:25 -0500223 }
Steven Rostedtfd994982009-02-28 02:41:25 -0500224 break;
225 }
Li Zefan3b8e4272009-12-08 11:14:52 +0800226
227 return ret;
Steven Rostedtfd994982009-02-28 02:41:25 -0500228}
229
Zhaolei0e907c92009-05-25 18:13:59 +0800230static void ftrace_clear_events(void)
231{
232 struct ftrace_event_call *call;
233
234 mutex_lock(&event_mutex);
235 list_for_each_entry(call, &ftrace_events, list) {
236 ftrace_event_enable_disable(call, 0);
237 }
238 mutex_unlock(&event_mutex);
239}
240
Li Zefan8f31bfe2009-05-08 10:31:42 +0800241/*
242 * __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events.
243 */
244static int __ftrace_set_clr_event(const char *match, const char *sub,
245 const char *event, int set)
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500246{
Steven Rostedta59fd602009-04-10 13:52:20 -0400247 struct ftrace_event_call *call;
Steven Rostedt29f93942009-05-08 16:06:47 -0400248 int ret = -EINVAL;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500249
Steven Rostedt11a241a2009-03-02 11:49:04 -0500250 mutex_lock(&event_mutex);
Steven Rostedta59fd602009-04-10 13:52:20 -0400251 list_for_each_entry(call, &ftrace_events, list) {
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500252
Steven Rostedta1d0ce82010-06-08 11:22:06 -0400253 if (!call->name || !call->class || !call->class->reg)
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500254 continue;
Steven Rostedt1473e442009-02-24 14:15:08 -0500255
Steven Rostedtb628b3e2009-02-27 23:32:58 -0500256 if (match &&
257 strcmp(match, call->name) != 0 &&
Steven Rostedt8f082012010-04-20 10:47:33 -0400258 strcmp(match, call->class->system) != 0)
Steven Rostedtb628b3e2009-02-27 23:32:58 -0500259 continue;
260
Steven Rostedt8f082012010-04-20 10:47:33 -0400261 if (sub && strcmp(sub, call->class->system) != 0)
Steven Rostedtb628b3e2009-02-27 23:32:58 -0500262 continue;
263
264 if (event && strcmp(event, call->name) != 0)
Steven Rostedt1473e442009-02-24 14:15:08 -0500265 continue;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500266
Steven Rostedtfd994982009-02-28 02:41:25 -0500267 ftrace_event_enable_disable(call, set);
268
Steven Rostedtb628b3e2009-02-27 23:32:58 -0500269 ret = 0;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500270 }
Steven Rostedt11a241a2009-03-02 11:49:04 -0500271 mutex_unlock(&event_mutex);
272
Steven Rostedtb628b3e2009-02-27 23:32:58 -0500273 return ret;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500274}
275
Li Zefan8f31bfe2009-05-08 10:31:42 +0800276static int ftrace_set_clr_event(char *buf, int set)
277{
278 char *event = NULL, *sub = NULL, *match;
279
280 /*
281 * The buf format can be <subsystem>:<event-name>
282 * *:<event-name> means any event by that name.
283 * :<event-name> is the same.
284 *
285 * <subsystem>:* means all events in that subsystem
286 * <subsystem>: means the same.
287 *
288 * <name> (no ':') means all events in a subsystem with
289 * the name <name> or any event that matches <name>
290 */
291
292 match = strsep(&buf, ":");
293 if (buf) {
294 sub = match;
295 event = buf;
296 match = NULL;
297
298 if (!strlen(sub) || strcmp(sub, "*") == 0)
299 sub = NULL;
300 if (!strlen(event) || strcmp(event, "*") == 0)
301 event = NULL;
302 }
303
304 return __ftrace_set_clr_event(match, sub, event, set);
305}
306
Steven Rostedt4671c792009-05-08 16:27:41 -0400307/**
308 * trace_set_clr_event - enable or disable an event
309 * @system: system name to match (NULL for any system)
310 * @event: event name to match (NULL for all events, within system)
311 * @set: 1 to enable, 0 to disable
312 *
313 * This is a way for other parts of the kernel to enable or disable
314 * event recording.
315 *
316 * Returns 0 on success, -EINVAL if the parameters do not match any
317 * registered events.
318 */
319int trace_set_clr_event(const char *system, const char *event, int set)
320{
321 return __ftrace_set_clr_event(NULL, system, event, set);
322}
323
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500324/* 128 should be much more than enough */
325#define EVENT_BUF_SIZE 127
326
327static ssize_t
328ftrace_event_write(struct file *file, const char __user *ubuf,
329 size_t cnt, loff_t *ppos)
330{
jolsa@redhat.com48966362009-09-11 17:29:28 +0200331 struct trace_parser parser;
Li Zefan4ba79782009-09-22 13:52:20 +0800332 ssize_t read, ret;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500333
Li Zefan4ba79782009-09-22 13:52:20 +0800334 if (!cnt)
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500335 return 0;
336
Steven Rostedt1852fcc2009-03-11 14:33:00 -0400337 ret = tracing_update_buffers();
338 if (ret < 0)
339 return ret;
340
jolsa@redhat.com48966362009-09-11 17:29:28 +0200341 if (trace_parser_get_init(&parser, EVENT_BUF_SIZE + 1))
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500342 return -ENOMEM;
343
jolsa@redhat.com48966362009-09-11 17:29:28 +0200344 read = trace_get_user(&parser, ubuf, cnt, ppos);
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500345
Li Zefan4ba79782009-09-22 13:52:20 +0800346 if (read >= 0 && trace_parser_loaded((&parser))) {
jolsa@redhat.com48966362009-09-11 17:29:28 +0200347 int set = 1;
348
349 if (*parser.buffer == '!')
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500350 set = 0;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500351
jolsa@redhat.com48966362009-09-11 17:29:28 +0200352 parser.buffer[parser.idx] = 0;
353
354 ret = ftrace_set_clr_event(parser.buffer + !set, set);
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500355 if (ret)
jolsa@redhat.com48966362009-09-11 17:29:28 +0200356 goto out_put;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500357 }
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500358
359 ret = read;
360
jolsa@redhat.com48966362009-09-11 17:29:28 +0200361 out_put:
362 trace_parser_put(&parser);
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500363
364 return ret;
365}
366
367static void *
368t_next(struct seq_file *m, void *v, loff_t *pos)
369{
Li Zefan30bd39c2009-09-18 14:07:05 +0800370 struct ftrace_event_call *call = v;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500371
372 (*pos)++;
373
Li Zefan30bd39c2009-09-18 14:07:05 +0800374 list_for_each_entry_continue(call, &ftrace_events, list) {
Steven Rostedt40e26812009-03-10 11:32:40 -0400375 /*
376 * The ftrace subsystem is for showing formats only.
377 * They can not be enabled or disabled via the event files.
378 */
Steven Rostedta1d0ce82010-06-08 11:22:06 -0400379 if (call->class && call->class->reg)
Li Zefan30bd39c2009-09-18 14:07:05 +0800380 return call;
Steven Rostedt40e26812009-03-10 11:32:40 -0400381 }
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500382
Li Zefan30bd39c2009-09-18 14:07:05 +0800383 return NULL;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500384}
385
386static void *t_start(struct seq_file *m, loff_t *pos)
387{
Li Zefan30bd39c2009-09-18 14:07:05 +0800388 struct ftrace_event_call *call;
Li Zefane1c7e2a2009-06-24 09:52:29 +0800389 loff_t l;
390
Li Zefan20c89282009-05-06 10:33:45 +0800391 mutex_lock(&event_mutex);
Li Zefane1c7e2a2009-06-24 09:52:29 +0800392
Li Zefan30bd39c2009-09-18 14:07:05 +0800393 call = list_entry(&ftrace_events, struct ftrace_event_call, list);
Li Zefane1c7e2a2009-06-24 09:52:29 +0800394 for (l = 0; l <= *pos; ) {
Li Zefan30bd39c2009-09-18 14:07:05 +0800395 call = t_next(m, call, &l);
Li Zefane1c7e2a2009-06-24 09:52:29 +0800396 if (!call)
397 break;
398 }
399 return call;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500400}
401
402static void *
403s_next(struct seq_file *m, void *v, loff_t *pos)
404{
Li Zefan30bd39c2009-09-18 14:07:05 +0800405 struct ftrace_event_call *call = v;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500406
407 (*pos)++;
408
Li Zefan30bd39c2009-09-18 14:07:05 +0800409 list_for_each_entry_continue(call, &ftrace_events, list) {
Steven Rostedt553552c2010-04-23 11:12:36 -0400410 if (call->flags & TRACE_EVENT_FL_ENABLED)
Li Zefan30bd39c2009-09-18 14:07:05 +0800411 return call;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500412 }
413
Li Zefan30bd39c2009-09-18 14:07:05 +0800414 return NULL;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500415}
416
417static void *s_start(struct seq_file *m, loff_t *pos)
418{
Li Zefan30bd39c2009-09-18 14:07:05 +0800419 struct ftrace_event_call *call;
Li Zefane1c7e2a2009-06-24 09:52:29 +0800420 loff_t l;
421
Li Zefan20c89282009-05-06 10:33:45 +0800422 mutex_lock(&event_mutex);
Li Zefane1c7e2a2009-06-24 09:52:29 +0800423
Li Zefan30bd39c2009-09-18 14:07:05 +0800424 call = list_entry(&ftrace_events, struct ftrace_event_call, list);
Li Zefane1c7e2a2009-06-24 09:52:29 +0800425 for (l = 0; l <= *pos; ) {
Li Zefan30bd39c2009-09-18 14:07:05 +0800426 call = s_next(m, call, &l);
Li Zefane1c7e2a2009-06-24 09:52:29 +0800427 if (!call)
428 break;
429 }
430 return call;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500431}
432
433static int t_show(struct seq_file *m, void *v)
434{
435 struct ftrace_event_call *call = v;
436
Steven Rostedt8f082012010-04-20 10:47:33 -0400437 if (strcmp(call->class->system, TRACE_SYSTEM) != 0)
438 seq_printf(m, "%s:", call->class->system);
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500439 seq_printf(m, "%s\n", call->name);
440
441 return 0;
442}
443
444static void t_stop(struct seq_file *m, void *p)
445{
Li Zefan20c89282009-05-06 10:33:45 +0800446 mutex_unlock(&event_mutex);
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500447}
448
449static int
450ftrace_event_seq_open(struct inode *inode, struct file *file)
451{
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500452 const struct seq_operations *seq_ops;
453
454 if ((file->f_mode & FMODE_WRITE) &&
Steven Rostedt8650ae32009-07-22 23:29:30 -0400455 (file->f_flags & O_TRUNC))
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500456 ftrace_clear_events();
457
458 seq_ops = inode->i_private;
Li Zefan20c89282009-05-06 10:33:45 +0800459 return seq_open(file, seq_ops);
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500460}
461
Steven Rostedt1473e442009-02-24 14:15:08 -0500462static ssize_t
463event_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
464 loff_t *ppos)
465{
466 struct ftrace_event_call *call = filp->private_data;
467 char *buf;
468
Steven Rostedt553552c2010-04-23 11:12:36 -0400469 if (call->flags & TRACE_EVENT_FL_ENABLED)
Steven Rostedt1473e442009-02-24 14:15:08 -0500470 buf = "1\n";
471 else
472 buf = "0\n";
473
474 return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
475}
476
477static ssize_t
478event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
479 loff_t *ppos)
480{
481 struct ftrace_event_call *call = filp->private_data;
482 char buf[64];
483 unsigned long val;
484 int ret;
485
486 if (cnt >= sizeof(buf))
487 return -EINVAL;
488
489 if (copy_from_user(&buf, ubuf, cnt))
490 return -EFAULT;
491
492 buf[cnt] = 0;
493
494 ret = strict_strtoul(buf, 10, &val);
495 if (ret < 0)
496 return ret;
497
Steven Rostedt1852fcc2009-03-11 14:33:00 -0400498 ret = tracing_update_buffers();
499 if (ret < 0)
500 return ret;
501
Steven Rostedt1473e442009-02-24 14:15:08 -0500502 switch (val) {
503 case 0:
Steven Rostedt1473e442009-02-24 14:15:08 -0500504 case 1:
Steven Rostedt11a241a2009-03-02 11:49:04 -0500505 mutex_lock(&event_mutex);
Li Zefan3b8e4272009-12-08 11:14:52 +0800506 ret = ftrace_event_enable_disable(call, val);
Steven Rostedt11a241a2009-03-02 11:49:04 -0500507 mutex_unlock(&event_mutex);
Steven Rostedt1473e442009-02-24 14:15:08 -0500508 break;
509
510 default:
511 return -EINVAL;
512 }
513
514 *ppos += cnt;
515
Li Zefan3b8e4272009-12-08 11:14:52 +0800516 return ret ? ret : cnt;
Steven Rostedt1473e442009-02-24 14:15:08 -0500517}
518
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400519static ssize_t
520system_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
521 loff_t *ppos)
522{
Li Zefanc142b152009-05-08 10:32:05 +0800523 const char set_to_char[4] = { '?', '0', '1', 'X' };
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400524 const char *system = filp->private_data;
525 struct ftrace_event_call *call;
526 char buf[2];
Li Zefanc142b152009-05-08 10:32:05 +0800527 int set = 0;
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400528 int ret;
529
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400530 mutex_lock(&event_mutex);
531 list_for_each_entry(call, &ftrace_events, list) {
Steven Rostedta1d0ce82010-06-08 11:22:06 -0400532 if (!call->name || !call->class || !call->class->reg)
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400533 continue;
534
Steven Rostedt8f082012010-04-20 10:47:33 -0400535 if (system && strcmp(call->class->system, system) != 0)
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400536 continue;
537
538 /*
539 * We need to find out if all the events are set
540 * or if all events or cleared, or if we have
541 * a mixture.
542 */
Steven Rostedt553552c2010-04-23 11:12:36 -0400543 set |= (1 << !!(call->flags & TRACE_EVENT_FL_ENABLED));
Li Zefanc142b152009-05-08 10:32:05 +0800544
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400545 /*
546 * If we have a mixture, no need to look further.
547 */
Li Zefanc142b152009-05-08 10:32:05 +0800548 if (set == 3)
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400549 break;
550 }
551 mutex_unlock(&event_mutex);
552
Li Zefanc142b152009-05-08 10:32:05 +0800553 buf[0] = set_to_char[set];
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400554 buf[1] = '\n';
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400555
556 ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
557
558 return ret;
559}
560
561static ssize_t
562system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
563 loff_t *ppos)
564{
565 const char *system = filp->private_data;
566 unsigned long val;
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400567 char buf[64];
568 ssize_t ret;
569
570 if (cnt >= sizeof(buf))
571 return -EINVAL;
572
573 if (copy_from_user(&buf, ubuf, cnt))
574 return -EFAULT;
575
576 buf[cnt] = 0;
577
578 ret = strict_strtoul(buf, 10, &val);
579 if (ret < 0)
580 return ret;
581
582 ret = tracing_update_buffers();
583 if (ret < 0)
584 return ret;
585
Li Zefan8f31bfe2009-05-08 10:31:42 +0800586 if (val != 0 && val != 1)
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400587 return -EINVAL;
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400588
Li Zefan8f31bfe2009-05-08 10:31:42 +0800589 ret = __ftrace_set_clr_event(NULL, system, NULL, val);
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400590 if (ret)
Li Zefan8f31bfe2009-05-08 10:31:42 +0800591 goto out;
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400592
593 ret = cnt;
594
Li Zefan8f31bfe2009-05-08 10:31:42 +0800595out:
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400596 *ppos += cnt;
597
598 return ret;
599}
600
Li Zefan8728fe52010-05-24 16:22:49 +0800601static void print_event_fields(struct trace_seq *s, struct list_head *head)
Steven Rostedt981d0812009-03-02 13:53:59 -0500602{
Lai Jiangshan5a65e952009-12-15 15:39:53 +0800603 struct ftrace_event_field *field;
Steven Rostedt981d0812009-03-02 13:53:59 -0500604
Steven Rostedt2e33af02010-04-22 10:35:55 -0400605 list_for_each_entry_reverse(field, head, link) {
Lai Jiangshan5a65e952009-12-15 15:39:53 +0800606 /*
607 * Smartly shows the array type(except dynamic array).
608 * Normal:
609 * field:TYPE VAR
610 * If TYPE := TYPE[LEN], it is shown:
611 * field:TYPE VAR[LEN]
612 */
613 const char *array_descriptor = strchr(field->type, '[');
614
615 if (!strncmp(field->type, "__data_loc", 10))
616 array_descriptor = NULL;
617
618 if (!array_descriptor) {
Li Zefan8728fe52010-05-24 16:22:49 +0800619 trace_seq_printf(s, "\tfield:%s %s;\toffset:%u;"
Lai Jiangshan5a65e952009-12-15 15:39:53 +0800620 "\tsize:%u;\tsigned:%d;\n",
621 field->type, field->name, field->offset,
622 field->size, !!field->is_signed);
623 } else {
Li Zefan8728fe52010-05-24 16:22:49 +0800624 trace_seq_printf(s, "\tfield:%.*s %s%s;\toffset:%u;"
Lai Jiangshan5a65e952009-12-15 15:39:53 +0800625 "\tsize:%u;\tsigned:%d;\n",
626 (int)(array_descriptor - field->type),
627 field->type, field->name,
628 array_descriptor, field->offset,
629 field->size, !!field->is_signed);
630 }
Lai Jiangshan5a65e952009-12-15 15:39:53 +0800631 }
Li Zefan8728fe52010-05-24 16:22:49 +0800632}
Lai Jiangshan5a65e952009-12-15 15:39:53 +0800633
Li Zefan8728fe52010-05-24 16:22:49 +0800634static ssize_t
635event_format_read(struct file *filp, char __user *ubuf, size_t cnt,
636 loff_t *ppos)
637{
638 struct ftrace_event_call *call = filp->private_data;
639 struct list_head *head;
640 struct trace_seq *s;
641 char *buf;
642 int r;
643
644 if (*ppos)
645 return 0;
646
647 s = kmalloc(sizeof(*s), GFP_KERNEL);
648 if (!s)
649 return -ENOMEM;
650
651 trace_seq_init(s);
652
653 trace_seq_printf(s, "name: %s\n", call->name);
654 trace_seq_printf(s, "ID: %d\n", call->event.type);
655 trace_seq_printf(s, "format:\n");
656
657 /* print common fields */
658 print_event_fields(s, &ftrace_common_fields);
659
660 trace_seq_putc(s, '\n');
661
662 /* print event specific fields */
663 head = trace_get_fields(call);
664 print_event_fields(s, head);
665
666 r = trace_seq_printf(s, "\nprint fmt: %s\n", call->print_fmt);
Lai Jiangshan5a65e952009-12-15 15:39:53 +0800667
Steven Rostedt981d0812009-03-02 13:53:59 -0500668 if (!r) {
669 /*
670 * ug! The format output is bigger than a PAGE!!
671 */
672 buf = "FORMAT TOO BIG\n";
673 r = simple_read_from_buffer(ubuf, cnt, ppos,
674 buf, strlen(buf));
675 goto out;
676 }
677
678 r = simple_read_from_buffer(ubuf, cnt, ppos,
679 s->buffer, s->len);
680 out:
681 kfree(s);
682 return r;
683}
684
Peter Zijlstra23725ae2009-03-19 20:26:13 +0100685static ssize_t
686event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
687{
688 struct ftrace_event_call *call = filp->private_data;
689 struct trace_seq *s;
690 int r;
691
692 if (*ppos)
693 return 0;
694
695 s = kmalloc(sizeof(*s), GFP_KERNEL);
696 if (!s)
697 return -ENOMEM;
698
699 trace_seq_init(s);
Steven Rostedt32c0eda2010-04-23 10:38:03 -0400700 trace_seq_printf(s, "%d\n", call->event.type);
Peter Zijlstra23725ae2009-03-19 20:26:13 +0100701
702 r = simple_read_from_buffer(ubuf, cnt, ppos,
703 s->buffer, s->len);
704 kfree(s);
705 return r;
706}
707
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500708static ssize_t
709event_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
710 loff_t *ppos)
711{
712 struct ftrace_event_call *call = filp->private_data;
713 struct trace_seq *s;
714 int r;
715
716 if (*ppos)
717 return 0;
718
719 s = kmalloc(sizeof(*s), GFP_KERNEL);
720 if (!s)
721 return -ENOMEM;
722
723 trace_seq_init(s);
724
Tom Zanussi8b372562009-04-28 03:04:59 -0500725 print_event_filter(call, s);
Tom Zanussi4bda2d52009-03-24 02:14:31 -0500726 r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500727
728 kfree(s);
729
730 return r;
731}
732
733static ssize_t
734event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
735 loff_t *ppos)
736{
737 struct ftrace_event_call *call = filp->private_data;
Tom Zanussi8b372562009-04-28 03:04:59 -0500738 char *buf;
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500739 int err;
740
Tom Zanussi8b372562009-04-28 03:04:59 -0500741 if (cnt >= PAGE_SIZE)
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500742 return -EINVAL;
743
Tom Zanussi8b372562009-04-28 03:04:59 -0500744 buf = (char *)__get_free_page(GFP_TEMPORARY);
745 if (!buf)
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500746 return -ENOMEM;
747
Tom Zanussi8b372562009-04-28 03:04:59 -0500748 if (copy_from_user(buf, ubuf, cnt)) {
749 free_page((unsigned long) buf);
750 return -EFAULT;
751 }
752 buf[cnt] = '\0';
753
754 err = apply_event_filter(call, buf);
755 free_page((unsigned long) buf);
756 if (err < 0)
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500757 return err;
Tom Zanussi0a19e532009-04-13 03:17:50 -0500758
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500759 *ppos += cnt;
760
761 return cnt;
762}
763
Tom Zanussicfb180f2009-03-22 03:31:17 -0500764static ssize_t
765subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
766 loff_t *ppos)
767{
768 struct event_subsystem *system = filp->private_data;
769 struct trace_seq *s;
770 int r;
771
772 if (*ppos)
773 return 0;
774
775 s = kmalloc(sizeof(*s), GFP_KERNEL);
776 if (!s)
777 return -ENOMEM;
778
779 trace_seq_init(s);
780
Tom Zanussi8b372562009-04-28 03:04:59 -0500781 print_subsystem_event_filter(system, s);
Tom Zanussi4bda2d52009-03-24 02:14:31 -0500782 r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
Tom Zanussicfb180f2009-03-22 03:31:17 -0500783
784 kfree(s);
785
786 return r;
787}
788
789static ssize_t
790subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
791 loff_t *ppos)
792{
793 struct event_subsystem *system = filp->private_data;
Tom Zanussi8b372562009-04-28 03:04:59 -0500794 char *buf;
Tom Zanussicfb180f2009-03-22 03:31:17 -0500795 int err;
796
Tom Zanussi8b372562009-04-28 03:04:59 -0500797 if (cnt >= PAGE_SIZE)
Tom Zanussicfb180f2009-03-22 03:31:17 -0500798 return -EINVAL;
799
Tom Zanussi8b372562009-04-28 03:04:59 -0500800 buf = (char *)__get_free_page(GFP_TEMPORARY);
801 if (!buf)
Tom Zanussicfb180f2009-03-22 03:31:17 -0500802 return -ENOMEM;
803
Tom Zanussi8b372562009-04-28 03:04:59 -0500804 if (copy_from_user(buf, ubuf, cnt)) {
805 free_page((unsigned long) buf);
806 return -EFAULT;
Tom Zanussicfb180f2009-03-22 03:31:17 -0500807 }
Tom Zanussi8b372562009-04-28 03:04:59 -0500808 buf[cnt] = '\0';
Tom Zanussicfb180f2009-03-22 03:31:17 -0500809
Tom Zanussi8b372562009-04-28 03:04:59 -0500810 err = apply_subsystem_event_filter(system, buf);
811 free_page((unsigned long) buf);
812 if (err < 0)
Li Zefan44e9c8b2009-04-11 15:55:28 +0800813 return err;
Tom Zanussicfb180f2009-03-22 03:31:17 -0500814
815 *ppos += cnt;
816
817 return cnt;
818}
819
Steven Rostedtd1b182a2009-04-15 16:53:47 -0400820static ssize_t
821show_header(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
822{
823 int (*func)(struct trace_seq *s) = filp->private_data;
824 struct trace_seq *s;
825 int r;
826
827 if (*ppos)
828 return 0;
829
830 s = kmalloc(sizeof(*s), GFP_KERNEL);
831 if (!s)
832 return -ENOMEM;
833
834 trace_seq_init(s);
835
836 func(s);
837 r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
838
839 kfree(s);
840
841 return r;
842}
843
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500844static const struct seq_operations show_event_seq_ops = {
845 .start = t_start,
846 .next = t_next,
847 .show = t_show,
848 .stop = t_stop,
849};
850
851static const struct seq_operations show_set_event_seq_ops = {
852 .start = s_start,
853 .next = s_next,
854 .show = t_show,
855 .stop = t_stop,
856};
857
Steven Rostedt2314c4a2009-03-10 12:04:02 -0400858static const struct file_operations ftrace_avail_fops = {
859 .open = ftrace_event_seq_open,
860 .read = seq_read,
861 .llseek = seq_lseek,
862 .release = seq_release,
863};
864
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500865static const struct file_operations ftrace_set_event_fops = {
866 .open = ftrace_event_seq_open,
867 .read = seq_read,
868 .write = ftrace_event_write,
869 .llseek = seq_lseek,
870 .release = seq_release,
871};
872
Steven Rostedt1473e442009-02-24 14:15:08 -0500873static const struct file_operations ftrace_enable_fops = {
874 .open = tracing_open_generic,
875 .read = event_enable_read,
876 .write = event_enable_write,
877};
878
Steven Rostedt981d0812009-03-02 13:53:59 -0500879static const struct file_operations ftrace_event_format_fops = {
880 .open = tracing_open_generic,
881 .read = event_format_read,
882};
883
Peter Zijlstra23725ae2009-03-19 20:26:13 +0100884static const struct file_operations ftrace_event_id_fops = {
885 .open = tracing_open_generic,
886 .read = event_id_read,
887};
888
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500889static const struct file_operations ftrace_event_filter_fops = {
890 .open = tracing_open_generic,
891 .read = event_filter_read,
892 .write = event_filter_write,
893};
894
Tom Zanussicfb180f2009-03-22 03:31:17 -0500895static const struct file_operations ftrace_subsystem_filter_fops = {
896 .open = tracing_open_generic,
897 .read = subsystem_filter_read,
898 .write = subsystem_filter_write,
899};
900
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400901static const struct file_operations ftrace_system_enable_fops = {
902 .open = tracing_open_generic,
903 .read = system_enable_read,
904 .write = system_enable_write,
905};
906
Steven Rostedtd1b182a2009-04-15 16:53:47 -0400907static const struct file_operations ftrace_show_header_fops = {
908 .open = tracing_open_generic,
909 .read = show_header,
910};
911
Steven Rostedt1473e442009-02-24 14:15:08 -0500912static struct dentry *event_trace_events_dir(void)
913{
914 static struct dentry *d_tracer;
915 static struct dentry *d_events;
916
917 if (d_events)
918 return d_events;
919
920 d_tracer = tracing_init_dentry();
921 if (!d_tracer)
922 return NULL;
923
924 d_events = debugfs_create_dir("events", d_tracer);
925 if (!d_events)
926 pr_warning("Could not create debugfs "
927 "'events' directory\n");
928
929 return d_events;
930}
931
Steven Rostedt6ecc2d12009-02-27 21:33:02 -0500932static LIST_HEAD(event_subsystems);
933
934static struct dentry *
935event_subsystem_dir(const char *name, struct dentry *d_events)
936{
937 struct event_subsystem *system;
Tom Zanussie1112b42009-03-31 00:48:49 -0500938 struct dentry *entry;
Steven Rostedt6ecc2d12009-02-27 21:33:02 -0500939
940 /* First see if we did not already create this dir */
941 list_for_each_entry(system, &event_subsystems, list) {
Xiao Guangrongdc82ec98a2009-07-09 16:22:22 +0800942 if (strcmp(system->name, name) == 0) {
943 system->nr_events++;
Steven Rostedt6ecc2d12009-02-27 21:33:02 -0500944 return system->entry;
Xiao Guangrongdc82ec98a2009-07-09 16:22:22 +0800945 }
Steven Rostedt6ecc2d12009-02-27 21:33:02 -0500946 }
947
948 /* need to create new entry */
949 system = kmalloc(sizeof(*system), GFP_KERNEL);
950 if (!system) {
951 pr_warning("No memory to create event subsystem %s\n",
952 name);
953 return d_events;
954 }
955
956 system->entry = debugfs_create_dir(name, d_events);
957 if (!system->entry) {
958 pr_warning("Could not create event subsystem %s\n",
959 name);
960 kfree(system);
961 return d_events;
962 }
963
Xiao Guangrongdc82ec98a2009-07-09 16:22:22 +0800964 system->nr_events = 1;
Steven Rostedt6d723732009-04-10 14:53:50 -0400965 system->name = kstrdup(name, GFP_KERNEL);
966 if (!system->name) {
967 debugfs_remove(system->entry);
968 kfree(system);
969 return d_events;
970 }
971
Steven Rostedt6ecc2d12009-02-27 21:33:02 -0500972 list_add(&system->list, &event_subsystems);
973
Tom Zanussi30e673b2009-04-28 03:04:47 -0500974 system->filter = NULL;
Tom Zanussicfb180f2009-03-22 03:31:17 -0500975
Tom Zanussi8b372562009-04-28 03:04:59 -0500976 system->filter = kzalloc(sizeof(struct event_filter), GFP_KERNEL);
977 if (!system->filter) {
978 pr_warning("Could not allocate filter for subsystem "
979 "'%s'\n", name);
980 return system->entry;
981 }
982
Tom Zanussie1112b42009-03-31 00:48:49 -0500983 entry = debugfs_create_file("filter", 0644, system->entry, system,
984 &ftrace_subsystem_filter_fops);
Tom Zanussi8b372562009-04-28 03:04:59 -0500985 if (!entry) {
986 kfree(system->filter);
987 system->filter = NULL;
Tom Zanussie1112b42009-03-31 00:48:49 -0500988 pr_warning("Could not create debugfs "
989 "'%s/filter' entry\n", name);
Tom Zanussi8b372562009-04-28 03:04:59 -0500990 }
Tom Zanussie1112b42009-03-31 00:48:49 -0500991
Frederic Weisbeckerf3f3f002009-09-24 15:27:41 +0200992 trace_create_file("enable", 0644, system->entry,
993 (void *)system->name,
994 &ftrace_system_enable_fops);
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400995
Steven Rostedt6ecc2d12009-02-27 21:33:02 -0500996 return system->entry;
997}
998
Steven Rostedt1473e442009-02-24 14:15:08 -0500999static int
Steven Rostedt701970b2009-04-24 23:11:22 -04001000event_create_dir(struct ftrace_event_call *call, struct dentry *d_events,
1001 const struct file_operations *id,
1002 const struct file_operations *enable,
1003 const struct file_operations *filter,
1004 const struct file_operations *format)
Steven Rostedt1473e442009-02-24 14:15:08 -05001005{
Steven Rostedt2e33af02010-04-22 10:35:55 -04001006 struct list_head *head;
Steven Rostedtfd994982009-02-28 02:41:25 -05001007 int ret;
Steven Rostedt1473e442009-02-24 14:15:08 -05001008
Steven Rostedt6ecc2d12009-02-27 21:33:02 -05001009 /*
1010 * If the trace point header did not define TRACE_SYSTEM
1011 * then the system would be called "TRACE_SYSTEM".
1012 */
Steven Rostedt8f082012010-04-20 10:47:33 -04001013 if (strcmp(call->class->system, TRACE_SYSTEM) != 0)
1014 d_events = event_subsystem_dir(call->class->system, d_events);
Steven Rostedt6ecc2d12009-02-27 21:33:02 -05001015
Steven Rostedt1473e442009-02-24 14:15:08 -05001016 call->dir = debugfs_create_dir(call->name, d_events);
1017 if (!call->dir) {
1018 pr_warning("Could not create debugfs "
1019 "'%s' directory\n", call->name);
1020 return -1;
1021 }
1022
Steven Rostedta1d0ce82010-06-08 11:22:06 -04001023 if (call->class->reg)
Frederic Weisbeckerf3f3f002009-09-24 15:27:41 +02001024 trace_create_file("enable", 0644, call->dir, call,
1025 enable);
Steven Rostedt1473e442009-02-24 14:15:08 -05001026
Steven Rostedt22392912010-04-21 12:27:06 -04001027#ifdef CONFIG_PERF_EVENTS
Steven Rostedta1d0ce82010-06-08 11:22:06 -04001028 if (call->event.type && call->class->reg)
Frederic Weisbeckerf3f3f002009-09-24 15:27:41 +02001029 trace_create_file("id", 0444, call->dir, call,
1030 id);
Steven Rostedt22392912010-04-21 12:27:06 -04001031#endif
Peter Zijlstra23725ae2009-03-19 20:26:13 +01001032
Li Zefanc9d932c2010-05-24 16:24:28 +08001033 /*
1034 * Other events may have the same class. Only update
1035 * the fields if they are not already defined.
1036 */
1037 head = trace_get_fields(call);
1038 if (list_empty(head)) {
1039 ret = call->class->define_fields(call);
1040 if (ret < 0) {
1041 pr_warning("Could not initialize trace point"
1042 " events/%s\n", call->name);
1043 return ret;
Tom Zanussicf027f62009-03-22 03:30:39 -05001044 }
1045 }
Li Zefanc9d932c2010-05-24 16:24:28 +08001046 trace_create_file("filter", 0644, call->dir, call,
1047 filter);
Tom Zanussicf027f62009-03-22 03:30:39 -05001048
Frederic Weisbeckerf3f3f002009-09-24 15:27:41 +02001049 trace_create_file("format", 0444, call->dir, call,
1050 format);
Steven Rostedtfd994982009-02-28 02:41:25 -05001051
Steven Rostedt1473e442009-02-24 14:15:08 -05001052 return 0;
1053}
1054
Li Zefan67ead0a2010-05-24 16:25:13 +08001055static int
1056__trace_add_event_call(struct ftrace_event_call *call, struct module *mod,
1057 const struct file_operations *id,
1058 const struct file_operations *enable,
1059 const struct file_operations *filter,
1060 const struct file_operations *format)
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001061{
1062 struct dentry *d_events;
1063 int ret;
Steven Rostedt6d723732009-04-10 14:53:50 -04001064
Li Zefan67ead0a2010-05-24 16:25:13 +08001065 /* The linker may leave blanks */
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001066 if (!call->name)
1067 return -EINVAL;
Steven Rostedt701970b2009-04-24 23:11:22 -04001068
Steven Rostedt0405ab82010-04-22 11:46:44 -04001069 if (call->class->raw_init) {
1070 ret = call->class->raw_init(call);
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001071 if (ret < 0) {
1072 if (ret != -ENOSYS)
Li Zefan67ead0a2010-05-24 16:25:13 +08001073 pr_warning("Could not initialize trace events/%s\n",
1074 call->name);
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001075 return ret;
1076 }
1077 }
Steven Rostedt701970b2009-04-24 23:11:22 -04001078
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001079 d_events = event_trace_events_dir();
1080 if (!d_events)
1081 return -ENOENT;
1082
Li Zefan67ead0a2010-05-24 16:25:13 +08001083 ret = event_create_dir(call, d_events, id, enable, filter, format);
Masami Hiramatsu88f70d72009-09-25 11:20:54 -07001084 if (!ret)
1085 list_add(&call->list, &ftrace_events);
Li Zefan67ead0a2010-05-24 16:25:13 +08001086 call->mod = mod;
Masami Hiramatsu88f70d72009-09-25 11:20:54 -07001087
Masami Hiramatsu588bebb2009-09-16 11:42:55 -04001088 return ret;
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001089}
1090
1091/* Add an additional event_call dynamically */
1092int trace_add_event_call(struct ftrace_event_call *call)
1093{
1094 int ret;
1095 mutex_lock(&event_mutex);
Li Zefan67ead0a2010-05-24 16:25:13 +08001096 ret = __trace_add_event_call(call, NULL, &ftrace_event_id_fops,
1097 &ftrace_enable_fops,
1098 &ftrace_event_filter_fops,
1099 &ftrace_event_format_fops);
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001100 mutex_unlock(&event_mutex);
1101 return ret;
1102}
Steven Rostedt701970b2009-04-24 23:11:22 -04001103
Frederic Weisbeckera2ca5e02009-08-06 07:32:21 +02001104static void remove_subsystem_dir(const char *name)
1105{
1106 struct event_subsystem *system;
1107
1108 if (strcmp(name, TRACE_SYSTEM) == 0)
1109 return;
1110
1111 list_for_each_entry(system, &event_subsystems, list) {
1112 if (strcmp(system->name, name) == 0) {
1113 if (!--system->nr_events) {
1114 struct event_filter *filter = system->filter;
1115
1116 debugfs_remove_recursive(system->entry);
1117 list_del(&system->list);
1118 if (filter) {
1119 kfree(filter->filter_string);
1120 kfree(filter);
1121 }
1122 kfree(system->name);
1123 kfree(system);
1124 }
1125 break;
1126 }
1127 }
1128}
1129
Masami Hiramatsu4fead8e2009-09-14 16:49:12 -04001130/*
1131 * Must be called under locking both of event_mutex and trace_event_mutex.
1132 */
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001133static void __trace_remove_event_call(struct ftrace_event_call *call)
1134{
1135 ftrace_event_enable_disable(call, 0);
Steven Rostedt80decc72010-04-23 10:00:22 -04001136 if (call->event.funcs)
1137 __unregister_ftrace_event(&call->event);
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001138 debugfs_remove_recursive(call->dir);
1139 list_del(&call->list);
1140 trace_destroy_fields(call);
1141 destroy_preds(call);
Steven Rostedt8f082012010-04-20 10:47:33 -04001142 remove_subsystem_dir(call->class->system);
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001143}
1144
1145/* Remove an event_call */
1146void trace_remove_event_call(struct ftrace_event_call *call)
1147{
1148 mutex_lock(&event_mutex);
Masami Hiramatsu4fead8e2009-09-14 16:49:12 -04001149 down_write(&trace_event_mutex);
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001150 __trace_remove_event_call(call);
Masami Hiramatsu4fead8e2009-09-14 16:49:12 -04001151 up_write(&trace_event_mutex);
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001152 mutex_unlock(&event_mutex);
1153}
1154
1155#define for_each_event(event, start, end) \
1156 for (event = start; \
1157 (unsigned long)event < (unsigned long)end; \
1158 event++)
1159
1160#ifdef CONFIG_MODULES
1161
1162static LIST_HEAD(ftrace_module_file_list);
1163
1164/*
1165 * Modules must own their file_operations to keep up with
1166 * reference counting.
1167 */
1168struct ftrace_module_file_ops {
1169 struct list_head list;
1170 struct module *mod;
1171 struct file_operations id;
1172 struct file_operations enable;
1173 struct file_operations format;
1174 struct file_operations filter;
1175};
1176
Steven Rostedt701970b2009-04-24 23:11:22 -04001177static struct ftrace_module_file_ops *
1178trace_create_file_ops(struct module *mod)
1179{
1180 struct ftrace_module_file_ops *file_ops;
1181
1182 /*
1183 * This is a bit of a PITA. To allow for correct reference
1184 * counting, modules must "own" their file_operations.
1185 * To do this, we allocate the file operations that will be
1186 * used in the event directory.
1187 */
1188
1189 file_ops = kmalloc(sizeof(*file_ops), GFP_KERNEL);
1190 if (!file_ops)
1191 return NULL;
1192
1193 file_ops->mod = mod;
1194
1195 file_ops->id = ftrace_event_id_fops;
1196 file_ops->id.owner = mod;
1197
1198 file_ops->enable = ftrace_enable_fops;
1199 file_ops->enable.owner = mod;
1200
1201 file_ops->filter = ftrace_event_filter_fops;
1202 file_ops->filter.owner = mod;
1203
1204 file_ops->format = ftrace_event_format_fops;
1205 file_ops->format.owner = mod;
1206
1207 list_add(&file_ops->list, &ftrace_module_file_list);
1208
1209 return file_ops;
1210}
1211
Steven Rostedt6d723732009-04-10 14:53:50 -04001212static void trace_module_add_events(struct module *mod)
1213{
Steven Rostedt701970b2009-04-24 23:11:22 -04001214 struct ftrace_module_file_ops *file_ops = NULL;
Steven Rostedt6d723732009-04-10 14:53:50 -04001215 struct ftrace_event_call *call, *start, *end;
Steven Rostedt6d723732009-04-10 14:53:50 -04001216
1217 start = mod->trace_events;
1218 end = mod->trace_events + mod->num_trace_events;
1219
1220 if (start == end)
1221 return;
1222
Li Zefan67ead0a2010-05-24 16:25:13 +08001223 file_ops = trace_create_file_ops(mod);
1224 if (!file_ops)
Steven Rostedt6d723732009-04-10 14:53:50 -04001225 return;
1226
1227 for_each_event(call, start, end) {
Li Zefan67ead0a2010-05-24 16:25:13 +08001228 __trace_add_event_call(call, mod,
Masami Hiramatsu88f70d72009-09-25 11:20:54 -07001229 &file_ops->id, &file_ops->enable,
1230 &file_ops->filter, &file_ops->format);
Steven Rostedt6d723732009-04-10 14:53:50 -04001231 }
1232}
1233
1234static void trace_module_remove_events(struct module *mod)
1235{
Steven Rostedt701970b2009-04-24 23:11:22 -04001236 struct ftrace_module_file_ops *file_ops;
Steven Rostedt6d723732009-04-10 14:53:50 -04001237 struct ftrace_event_call *call, *p;
Steven Rostedt9456f0f2009-05-06 21:54:09 -04001238 bool found = false;
Steven Rostedt6d723732009-04-10 14:53:50 -04001239
Steven Rostedt110bf2b2009-06-09 17:29:07 -04001240 down_write(&trace_event_mutex);
Steven Rostedt6d723732009-04-10 14:53:50 -04001241 list_for_each_entry_safe(call, p, &ftrace_events, list) {
1242 if (call->mod == mod) {
Steven Rostedt9456f0f2009-05-06 21:54:09 -04001243 found = true;
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001244 __trace_remove_event_call(call);
Steven Rostedt6d723732009-04-10 14:53:50 -04001245 }
1246 }
Steven Rostedt701970b2009-04-24 23:11:22 -04001247
1248 /* Now free the file_operations */
1249 list_for_each_entry(file_ops, &ftrace_module_file_list, list) {
1250 if (file_ops->mod == mod)
1251 break;
1252 }
1253 if (&file_ops->list != &ftrace_module_file_list) {
1254 list_del(&file_ops->list);
1255 kfree(file_ops);
1256 }
Steven Rostedt9456f0f2009-05-06 21:54:09 -04001257
1258 /*
1259 * It is safest to reset the ring buffer if the module being unloaded
1260 * registered any events.
1261 */
1262 if (found)
1263 tracing_reset_current_online_cpus();
Steven Rostedt110bf2b2009-06-09 17:29:07 -04001264 up_write(&trace_event_mutex);
Steven Rostedt6d723732009-04-10 14:53:50 -04001265}
1266
Steven Rostedt61f919a2009-04-14 18:22:32 -04001267static int trace_module_notify(struct notifier_block *self,
1268 unsigned long val, void *data)
Steven Rostedt6d723732009-04-10 14:53:50 -04001269{
1270 struct module *mod = data;
1271
1272 mutex_lock(&event_mutex);
1273 switch (val) {
1274 case MODULE_STATE_COMING:
1275 trace_module_add_events(mod);
1276 break;
1277 case MODULE_STATE_GOING:
1278 trace_module_remove_events(mod);
1279 break;
1280 }
1281 mutex_unlock(&event_mutex);
1282
1283 return 0;
1284}
Steven Rostedt61f919a2009-04-14 18:22:32 -04001285#else
1286static int trace_module_notify(struct notifier_block *self,
1287 unsigned long val, void *data)
1288{
1289 return 0;
1290}
1291#endif /* CONFIG_MODULES */
Steven Rostedt6d723732009-04-10 14:53:50 -04001292
Steven Rostedtec827c72009-09-14 10:50:23 -04001293static struct notifier_block trace_module_nb = {
Steven Rostedt6d723732009-04-10 14:53:50 -04001294 .notifier_call = trace_module_notify,
1295 .priority = 0,
1296};
1297
Steven Rostedta59fd602009-04-10 13:52:20 -04001298extern struct ftrace_event_call __start_ftrace_events[];
1299extern struct ftrace_event_call __stop_ftrace_events[];
1300
Li Zefan020e5f82009-07-01 10:47:05 +08001301static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata;
1302
1303static __init int setup_trace_event(char *str)
1304{
1305 strlcpy(bootup_event_buf, str, COMMAND_LINE_SIZE);
1306 ring_buffer_expanded = 1;
1307 tracing_selftest_disabled = 1;
1308
1309 return 1;
1310}
1311__setup("trace_event=", setup_trace_event);
1312
Steven Rostedtb77e38a2009-02-24 10:21:36 -05001313static __init int event_trace_init(void)
1314{
Steven Rostedta59fd602009-04-10 13:52:20 -04001315 struct ftrace_event_call *call;
Steven Rostedtb77e38a2009-02-24 10:21:36 -05001316 struct dentry *d_tracer;
1317 struct dentry *entry;
Steven Rostedt1473e442009-02-24 14:15:08 -05001318 struct dentry *d_events;
Steven Rostedt6d723732009-04-10 14:53:50 -04001319 int ret;
Li Zefan020e5f82009-07-01 10:47:05 +08001320 char *buf = bootup_event_buf;
1321 char *token;
Steven Rostedtb77e38a2009-02-24 10:21:36 -05001322
1323 d_tracer = tracing_init_dentry();
1324 if (!d_tracer)
1325 return 0;
1326
Steven Rostedt2314c4a2009-03-10 12:04:02 -04001327 entry = debugfs_create_file("available_events", 0444, d_tracer,
1328 (void *)&show_event_seq_ops,
1329 &ftrace_avail_fops);
1330 if (!entry)
1331 pr_warning("Could not create debugfs "
1332 "'available_events' entry\n");
1333
Steven Rostedtb77e38a2009-02-24 10:21:36 -05001334 entry = debugfs_create_file("set_event", 0644, d_tracer,
1335 (void *)&show_set_event_seq_ops,
1336 &ftrace_set_event_fops);
1337 if (!entry)
1338 pr_warning("Could not create debugfs "
1339 "'set_event' entry\n");
1340
Steven Rostedt1473e442009-02-24 14:15:08 -05001341 d_events = event_trace_events_dir();
1342 if (!d_events)
1343 return 0;
1344
Steven Rostedtd1b182a2009-04-15 16:53:47 -04001345 /* ring buffer internal formats */
1346 trace_create_file("header_page", 0444, d_events,
1347 ring_buffer_print_page_header,
1348 &ftrace_show_header_fops);
1349
1350 trace_create_file("header_event", 0444, d_events,
1351 ring_buffer_print_entry_header,
1352 &ftrace_show_header_fops);
1353
Steven Rostedt8ae79a12009-05-06 22:52:15 -04001354 trace_create_file("enable", 0644, d_events,
Li Zefan8f31bfe2009-05-08 10:31:42 +08001355 NULL, &ftrace_system_enable_fops);
Steven Rostedt8ae79a12009-05-06 22:52:15 -04001356
Li Zefan8728fe52010-05-24 16:22:49 +08001357 if (trace_define_common_fields())
1358 pr_warning("tracing: Failed to allocate common fields");
1359
Steven Rostedt6d723732009-04-10 14:53:50 -04001360 for_each_event(call, __start_ftrace_events, __stop_ftrace_events) {
Li Zefan67ead0a2010-05-24 16:25:13 +08001361 __trace_add_event_call(call, NULL, &ftrace_event_id_fops,
Masami Hiramatsu88f70d72009-09-25 11:20:54 -07001362 &ftrace_enable_fops,
1363 &ftrace_event_filter_fops,
1364 &ftrace_event_format_fops);
Steven Rostedt1473e442009-02-24 14:15:08 -05001365 }
1366
Li Zefan020e5f82009-07-01 10:47:05 +08001367 while (true) {
1368 token = strsep(&buf, ",");
1369
1370 if (!token)
1371 break;
1372 if (!*token)
1373 continue;
1374
1375 ret = ftrace_set_clr_event(token, 1);
1376 if (ret)
1377 pr_warning("Failed to enable trace event: %s\n", token);
1378 }
1379
Steven Rostedt6d723732009-04-10 14:53:50 -04001380 ret = register_module_notifier(&trace_module_nb);
Ming Lei55379372009-05-18 23:04:46 +08001381 if (ret)
Steven Rostedt6d723732009-04-10 14:53:50 -04001382 pr_warning("Failed to register trace events module notifier\n");
1383
Steven Rostedtb77e38a2009-02-24 10:21:36 -05001384 return 0;
1385}
1386fs_initcall(event_trace_init);
Steven Rostedte6187002009-04-15 13:36:40 -04001387
1388#ifdef CONFIG_FTRACE_STARTUP_TEST
1389
1390static DEFINE_SPINLOCK(test_spinlock);
1391static DEFINE_SPINLOCK(test_spinlock_irq);
1392static DEFINE_MUTEX(test_mutex);
1393
1394static __init void test_work(struct work_struct *dummy)
1395{
1396 spin_lock(&test_spinlock);
1397 spin_lock_irq(&test_spinlock_irq);
1398 udelay(1);
1399 spin_unlock_irq(&test_spinlock_irq);
1400 spin_unlock(&test_spinlock);
1401
1402 mutex_lock(&test_mutex);
1403 msleep(1);
1404 mutex_unlock(&test_mutex);
1405}
1406
1407static __init int event_test_thread(void *unused)
1408{
1409 void *test_malloc;
1410
1411 test_malloc = kmalloc(1234, GFP_KERNEL);
1412 if (!test_malloc)
1413 pr_info("failed to kmalloc\n");
1414
1415 schedule_on_each_cpu(test_work);
1416
1417 kfree(test_malloc);
1418
1419 set_current_state(TASK_INTERRUPTIBLE);
1420 while (!kthread_should_stop())
1421 schedule();
1422
1423 return 0;
1424}
1425
1426/*
1427 * Do various things that may trigger events.
1428 */
1429static __init void event_test_stuff(void)
1430{
1431 struct task_struct *test_thread;
1432
1433 test_thread = kthread_run(event_test_thread, NULL, "test-events");
1434 msleep(1);
1435 kthread_stop(test_thread);
1436}
1437
1438/*
1439 * For every trace event defined, we will test each trace point separately,
1440 * and then by groups, and finally all trace points.
1441 */
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001442static __init void event_trace_self_tests(void)
Steven Rostedte6187002009-04-15 13:36:40 -04001443{
1444 struct ftrace_event_call *call;
1445 struct event_subsystem *system;
Steven Rostedte6187002009-04-15 13:36:40 -04001446 int ret;
1447
1448 pr_info("Running tests on trace events:\n");
1449
1450 list_for_each_entry(call, &ftrace_events, list) {
1451
Steven Rostedt22392912010-04-21 12:27:06 -04001452 /* Only test those that have a probe */
1453 if (!call->class || !call->class->probe)
Steven Rostedte6187002009-04-15 13:36:40 -04001454 continue;
1455
Steven Rostedt1f5a6b42009-09-14 11:58:24 -04001456/*
1457 * Testing syscall events here is pretty useless, but
1458 * we still do it if configured. But this is time consuming.
1459 * What we really need is a user thread to perform the
1460 * syscalls as we test.
1461 */
1462#ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS
Steven Rostedt8f082012010-04-20 10:47:33 -04001463 if (call->class->system &&
1464 strcmp(call->class->system, "syscalls") == 0)
Steven Rostedt1f5a6b42009-09-14 11:58:24 -04001465 continue;
1466#endif
1467
Steven Rostedte6187002009-04-15 13:36:40 -04001468 pr_info("Testing event %s: ", call->name);
1469
1470 /*
1471 * If an event is already enabled, someone is using
1472 * it and the self test should not be on.
1473 */
Steven Rostedt553552c2010-04-23 11:12:36 -04001474 if (call->flags & TRACE_EVENT_FL_ENABLED) {
Steven Rostedte6187002009-04-15 13:36:40 -04001475 pr_warning("Enabled event during self test!\n");
1476 WARN_ON_ONCE(1);
1477 continue;
1478 }
1479
Zhaolei0e907c92009-05-25 18:13:59 +08001480 ftrace_event_enable_disable(call, 1);
Steven Rostedte6187002009-04-15 13:36:40 -04001481 event_test_stuff();
Zhaolei0e907c92009-05-25 18:13:59 +08001482 ftrace_event_enable_disable(call, 0);
Steven Rostedte6187002009-04-15 13:36:40 -04001483
1484 pr_cont("OK\n");
1485 }
1486
1487 /* Now test at the sub system level */
1488
1489 pr_info("Running tests on trace event systems:\n");
1490
1491 list_for_each_entry(system, &event_subsystems, list) {
1492
1493 /* the ftrace system is special, skip it */
1494 if (strcmp(system->name, "ftrace") == 0)
1495 continue;
1496
1497 pr_info("Testing event system %s: ", system->name);
1498
Li Zefan8f31bfe2009-05-08 10:31:42 +08001499 ret = __ftrace_set_clr_event(NULL, system->name, NULL, 1);
Steven Rostedte6187002009-04-15 13:36:40 -04001500 if (WARN_ON_ONCE(ret)) {
1501 pr_warning("error enabling system %s\n",
1502 system->name);
1503 continue;
1504 }
1505
1506 event_test_stuff();
1507
Li Zefan8f31bfe2009-05-08 10:31:42 +08001508 ret = __ftrace_set_clr_event(NULL, system->name, NULL, 0);
Steven Rostedte6187002009-04-15 13:36:40 -04001509 if (WARN_ON_ONCE(ret))
1510 pr_warning("error disabling system %s\n",
1511 system->name);
1512
1513 pr_cont("OK\n");
1514 }
1515
1516 /* Test with all events enabled */
1517
1518 pr_info("Running tests on all trace events:\n");
1519 pr_info("Testing all events: ");
1520
Li Zefan8f31bfe2009-05-08 10:31:42 +08001521 ret = __ftrace_set_clr_event(NULL, NULL, NULL, 1);
Steven Rostedte6187002009-04-15 13:36:40 -04001522 if (WARN_ON_ONCE(ret)) {
Steven Rostedte6187002009-04-15 13:36:40 -04001523 pr_warning("error enabling all events\n");
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001524 return;
Steven Rostedte6187002009-04-15 13:36:40 -04001525 }
1526
1527 event_test_stuff();
1528
1529 /* reset sysname */
Li Zefan8f31bfe2009-05-08 10:31:42 +08001530 ret = __ftrace_set_clr_event(NULL, NULL, NULL, 0);
Steven Rostedte6187002009-04-15 13:36:40 -04001531 if (WARN_ON_ONCE(ret)) {
1532 pr_warning("error disabling all events\n");
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001533 return;
Steven Rostedte6187002009-04-15 13:36:40 -04001534 }
1535
1536 pr_cont("OK\n");
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001537}
1538
1539#ifdef CONFIG_FUNCTION_TRACER
1540
Tejun Heo245b2e72009-06-24 15:13:48 +09001541static DEFINE_PER_CPU(atomic_t, ftrace_test_event_disable);
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001542
1543static void
1544function_test_events_call(unsigned long ip, unsigned long parent_ip)
1545{
1546 struct ring_buffer_event *event;
Steven Rostedte77405a2009-09-02 14:17:06 -04001547 struct ring_buffer *buffer;
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001548 struct ftrace_entry *entry;
1549 unsigned long flags;
1550 long disabled;
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001551 int cpu;
1552 int pc;
1553
1554 pc = preempt_count();
Steven Rostedt5168ae52010-06-03 09:36:50 -04001555 preempt_disable_notrace();
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001556 cpu = raw_smp_processor_id();
Tejun Heo245b2e72009-06-24 15:13:48 +09001557 disabled = atomic_inc_return(&per_cpu(ftrace_test_event_disable, cpu));
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001558
1559 if (disabled != 1)
1560 goto out;
1561
1562 local_save_flags(flags);
1563
Steven Rostedte77405a2009-09-02 14:17:06 -04001564 event = trace_current_buffer_lock_reserve(&buffer,
1565 TRACE_FN, sizeof(*entry),
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001566 flags, pc);
1567 if (!event)
1568 goto out;
1569 entry = ring_buffer_event_data(event);
1570 entry->ip = ip;
1571 entry->parent_ip = parent_ip;
1572
Steven Rostedte77405a2009-09-02 14:17:06 -04001573 trace_nowake_buffer_unlock_commit(buffer, event, flags, pc);
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001574
1575 out:
Tejun Heo245b2e72009-06-24 15:13:48 +09001576 atomic_dec(&per_cpu(ftrace_test_event_disable, cpu));
Steven Rostedt5168ae52010-06-03 09:36:50 -04001577 preempt_enable_notrace();
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001578}
1579
1580static struct ftrace_ops trace_ops __initdata =
1581{
1582 .func = function_test_events_call,
1583};
1584
1585static __init void event_trace_self_test_with_function(void)
1586{
1587 register_ftrace_function(&trace_ops);
1588 pr_info("Running tests again, along with the function tracer\n");
1589 event_trace_self_tests();
1590 unregister_ftrace_function(&trace_ops);
1591}
1592#else
1593static __init void event_trace_self_test_with_function(void)
1594{
1595}
1596#endif
1597
1598static __init int event_trace_self_tests_init(void)
1599{
Li Zefan020e5f82009-07-01 10:47:05 +08001600 if (!tracing_selftest_disabled) {
1601 event_trace_self_tests();
1602 event_trace_self_test_with_function();
1603 }
Steven Rostedte6187002009-04-15 13:36:40 -04001604
1605 return 0;
1606}
1607
Steven Rostedt28d20e22009-04-20 12:12:44 -04001608late_initcall(event_trace_self_tests_init);
Steven Rostedte6187002009-04-15 13:36:40 -04001609
1610#endif