blob: 5bad9cbbf974d987c7c4781aa6df3914939f79ce [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 Rostedt91729ef92009-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
Li Zefan3b8e4272009-12-08 11:14:52 +0800144static int ftrace_event_enable_disable(struct ftrace_event_call *call,
Steven Rostedtfd994982009-02-28 02:41:25 -0500145 int enable)
146{
Li Zefan3b8e4272009-12-08 11:14:52 +0800147 int ret = 0;
148
Steven Rostedtfd994982009-02-28 02:41:25 -0500149 switch (enable) {
150 case 0:
Steven Rostedt553552c2010-04-23 11:12:36 -0400151 if (call->flags & TRACE_EVENT_FL_ENABLED) {
152 call->flags &= ~TRACE_EVENT_FL_ENABLED;
Zhaoleib11c53e2009-05-25 18:11:59 +0800153 tracing_stop_cmdline_record();
Steven Rostedt22392912010-04-21 12:27:06 -0400154 if (call->class->reg)
155 call->class->reg(call, TRACE_REG_UNREGISTER);
156 else
157 tracepoint_probe_unregister(call->name,
158 call->class->probe,
159 call);
Steven Rostedtfd994982009-02-28 02:41:25 -0500160 }
Steven Rostedtfd994982009-02-28 02:41:25 -0500161 break;
162 case 1:
Steven Rostedt553552c2010-04-23 11:12:36 -0400163 if (!(call->flags & TRACE_EVENT_FL_ENABLED)) {
Zhaoleib11c53e2009-05-25 18:11:59 +0800164 tracing_start_cmdline_record();
Steven Rostedt22392912010-04-21 12:27:06 -0400165 if (call->class->reg)
166 ret = call->class->reg(call, TRACE_REG_REGISTER);
167 else
168 ret = tracepoint_probe_register(call->name,
169 call->class->probe,
170 call);
Li Zefan3b8e4272009-12-08 11:14:52 +0800171 if (ret) {
172 tracing_stop_cmdline_record();
173 pr_info("event trace: Could not enable event "
174 "%s\n", call->name);
175 break;
176 }
Steven Rostedt553552c2010-04-23 11:12:36 -0400177 call->flags |= TRACE_EVENT_FL_ENABLED;
Steven Rostedtfd994982009-02-28 02:41:25 -0500178 }
Steven Rostedtfd994982009-02-28 02:41:25 -0500179 break;
180 }
Li Zefan3b8e4272009-12-08 11:14:52 +0800181
182 return ret;
Steven Rostedtfd994982009-02-28 02:41:25 -0500183}
184
Zhaolei0e907c92009-05-25 18:13:59 +0800185static void ftrace_clear_events(void)
186{
187 struct ftrace_event_call *call;
188
189 mutex_lock(&event_mutex);
190 list_for_each_entry(call, &ftrace_events, list) {
191 ftrace_event_enable_disable(call, 0);
192 }
193 mutex_unlock(&event_mutex);
194}
195
Li Zefan8f31bfe2009-05-08 10:31:42 +0800196/*
197 * __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events.
198 */
199static int __ftrace_set_clr_event(const char *match, const char *sub,
200 const char *event, int set)
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500201{
Steven Rostedta59fd602009-04-10 13:52:20 -0400202 struct ftrace_event_call *call;
Steven Rostedt29f93942009-05-08 16:06:47 -0400203 int ret = -EINVAL;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500204
Steven Rostedt11a241a2009-03-02 11:49:04 -0500205 mutex_lock(&event_mutex);
Steven Rostedta59fd602009-04-10 13:52:20 -0400206 list_for_each_entry(call, &ftrace_events, list) {
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500207
Steven Rostedt22392912010-04-21 12:27:06 -0400208 if (!call->name || !call->class ||
209 (!call->class->probe && !call->class->reg))
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500210 continue;
Steven Rostedt1473e442009-02-24 14:15:08 -0500211
Steven Rostedtb628b3e2009-02-27 23:32:58 -0500212 if (match &&
213 strcmp(match, call->name) != 0 &&
Steven Rostedt8f082012010-04-20 10:47:33 -0400214 strcmp(match, call->class->system) != 0)
Steven Rostedtb628b3e2009-02-27 23:32:58 -0500215 continue;
216
Steven Rostedt8f082012010-04-20 10:47:33 -0400217 if (sub && strcmp(sub, call->class->system) != 0)
Steven Rostedtb628b3e2009-02-27 23:32:58 -0500218 continue;
219
220 if (event && strcmp(event, call->name) != 0)
Steven Rostedt1473e442009-02-24 14:15:08 -0500221 continue;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500222
Steven Rostedtfd994982009-02-28 02:41:25 -0500223 ftrace_event_enable_disable(call, set);
224
Steven Rostedtb628b3e2009-02-27 23:32:58 -0500225 ret = 0;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500226 }
Steven Rostedt11a241a2009-03-02 11:49:04 -0500227 mutex_unlock(&event_mutex);
228
Steven Rostedtb628b3e2009-02-27 23:32:58 -0500229 return ret;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500230}
231
Li Zefan8f31bfe2009-05-08 10:31:42 +0800232static int ftrace_set_clr_event(char *buf, int set)
233{
234 char *event = NULL, *sub = NULL, *match;
235
236 /*
237 * The buf format can be <subsystem>:<event-name>
238 * *:<event-name> means any event by that name.
239 * :<event-name> is the same.
240 *
241 * <subsystem>:* means all events in that subsystem
242 * <subsystem>: means the same.
243 *
244 * <name> (no ':') means all events in a subsystem with
245 * the name <name> or any event that matches <name>
246 */
247
248 match = strsep(&buf, ":");
249 if (buf) {
250 sub = match;
251 event = buf;
252 match = NULL;
253
254 if (!strlen(sub) || strcmp(sub, "*") == 0)
255 sub = NULL;
256 if (!strlen(event) || strcmp(event, "*") == 0)
257 event = NULL;
258 }
259
260 return __ftrace_set_clr_event(match, sub, event, set);
261}
262
Steven Rostedt4671c792009-05-08 16:27:41 -0400263/**
264 * trace_set_clr_event - enable or disable an event
265 * @system: system name to match (NULL for any system)
266 * @event: event name to match (NULL for all events, within system)
267 * @set: 1 to enable, 0 to disable
268 *
269 * This is a way for other parts of the kernel to enable or disable
270 * event recording.
271 *
272 * Returns 0 on success, -EINVAL if the parameters do not match any
273 * registered events.
274 */
275int trace_set_clr_event(const char *system, const char *event, int set)
276{
277 return __ftrace_set_clr_event(NULL, system, event, set);
278}
279
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500280/* 128 should be much more than enough */
281#define EVENT_BUF_SIZE 127
282
283static ssize_t
284ftrace_event_write(struct file *file, const char __user *ubuf,
285 size_t cnt, loff_t *ppos)
286{
jolsa@redhat.com48966362009-09-11 17:29:28 +0200287 struct trace_parser parser;
Li Zefan4ba79782009-09-22 13:52:20 +0800288 ssize_t read, ret;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500289
Li Zefan4ba79782009-09-22 13:52:20 +0800290 if (!cnt)
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500291 return 0;
292
Steven Rostedt1852fcc2009-03-11 14:33:00 -0400293 ret = tracing_update_buffers();
294 if (ret < 0)
295 return ret;
296
jolsa@redhat.com48966362009-09-11 17:29:28 +0200297 if (trace_parser_get_init(&parser, EVENT_BUF_SIZE + 1))
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500298 return -ENOMEM;
299
jolsa@redhat.com48966362009-09-11 17:29:28 +0200300 read = trace_get_user(&parser, ubuf, cnt, ppos);
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500301
Li Zefan4ba79782009-09-22 13:52:20 +0800302 if (read >= 0 && trace_parser_loaded((&parser))) {
jolsa@redhat.com48966362009-09-11 17:29:28 +0200303 int set = 1;
304
305 if (*parser.buffer == '!')
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500306 set = 0;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500307
jolsa@redhat.com48966362009-09-11 17:29:28 +0200308 parser.buffer[parser.idx] = 0;
309
310 ret = ftrace_set_clr_event(parser.buffer + !set, set);
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500311 if (ret)
jolsa@redhat.com48966362009-09-11 17:29:28 +0200312 goto out_put;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500313 }
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500314
315 ret = read;
316
jolsa@redhat.com48966362009-09-11 17:29:28 +0200317 out_put:
318 trace_parser_put(&parser);
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500319
320 return ret;
321}
322
323static void *
324t_next(struct seq_file *m, void *v, loff_t *pos)
325{
Li Zefan30bd39c2009-09-18 14:07:05 +0800326 struct ftrace_event_call *call = v;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500327
328 (*pos)++;
329
Li Zefan30bd39c2009-09-18 14:07:05 +0800330 list_for_each_entry_continue(call, &ftrace_events, list) {
Steven Rostedt40e26812009-03-10 11:32:40 -0400331 /*
332 * The ftrace subsystem is for showing formats only.
333 * They can not be enabled or disabled via the event files.
334 */
Steven Rostedt22392912010-04-21 12:27:06 -0400335 if (call->class && (call->class->probe || call->class->reg))
Li Zefan30bd39c2009-09-18 14:07:05 +0800336 return call;
Steven Rostedt40e26812009-03-10 11:32:40 -0400337 }
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500338
Li Zefan30bd39c2009-09-18 14:07:05 +0800339 return NULL;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500340}
341
342static void *t_start(struct seq_file *m, loff_t *pos)
343{
Li Zefan30bd39c2009-09-18 14:07:05 +0800344 struct ftrace_event_call *call;
Li Zefane1c7e2a2009-06-24 09:52:29 +0800345 loff_t l;
346
Li Zefan20c89282009-05-06 10:33:45 +0800347 mutex_lock(&event_mutex);
Li Zefane1c7e2a2009-06-24 09:52:29 +0800348
Li Zefan30bd39c2009-09-18 14:07:05 +0800349 call = list_entry(&ftrace_events, struct ftrace_event_call, list);
Li Zefane1c7e2a2009-06-24 09:52:29 +0800350 for (l = 0; l <= *pos; ) {
Li Zefan30bd39c2009-09-18 14:07:05 +0800351 call = t_next(m, call, &l);
Li Zefane1c7e2a2009-06-24 09:52:29 +0800352 if (!call)
353 break;
354 }
355 return call;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500356}
357
358static void *
359s_next(struct seq_file *m, void *v, loff_t *pos)
360{
Li Zefan30bd39c2009-09-18 14:07:05 +0800361 struct ftrace_event_call *call = v;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500362
363 (*pos)++;
364
Li Zefan30bd39c2009-09-18 14:07:05 +0800365 list_for_each_entry_continue(call, &ftrace_events, list) {
Steven Rostedt553552c2010-04-23 11:12:36 -0400366 if (call->flags & TRACE_EVENT_FL_ENABLED)
Li Zefan30bd39c2009-09-18 14:07:05 +0800367 return call;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500368 }
369
Li Zefan30bd39c2009-09-18 14:07:05 +0800370 return NULL;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500371}
372
373static void *s_start(struct seq_file *m, loff_t *pos)
374{
Li Zefan30bd39c2009-09-18 14:07:05 +0800375 struct ftrace_event_call *call;
Li Zefane1c7e2a2009-06-24 09:52:29 +0800376 loff_t l;
377
Li Zefan20c89282009-05-06 10:33:45 +0800378 mutex_lock(&event_mutex);
Li Zefane1c7e2a2009-06-24 09:52:29 +0800379
Li Zefan30bd39c2009-09-18 14:07:05 +0800380 call = list_entry(&ftrace_events, struct ftrace_event_call, list);
Li Zefane1c7e2a2009-06-24 09:52:29 +0800381 for (l = 0; l <= *pos; ) {
Li Zefan30bd39c2009-09-18 14:07:05 +0800382 call = s_next(m, call, &l);
Li Zefane1c7e2a2009-06-24 09:52:29 +0800383 if (!call)
384 break;
385 }
386 return call;
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500387}
388
389static int t_show(struct seq_file *m, void *v)
390{
391 struct ftrace_event_call *call = v;
392
Steven Rostedt8f082012010-04-20 10:47:33 -0400393 if (strcmp(call->class->system, TRACE_SYSTEM) != 0)
394 seq_printf(m, "%s:", call->class->system);
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500395 seq_printf(m, "%s\n", call->name);
396
397 return 0;
398}
399
400static void t_stop(struct seq_file *m, void *p)
401{
Li Zefan20c89282009-05-06 10:33:45 +0800402 mutex_unlock(&event_mutex);
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500403}
404
405static int
406ftrace_event_seq_open(struct inode *inode, struct file *file)
407{
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500408 const struct seq_operations *seq_ops;
409
410 if ((file->f_mode & FMODE_WRITE) &&
Steven Rostedt8650ae32009-07-22 23:29:30 -0400411 (file->f_flags & O_TRUNC))
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500412 ftrace_clear_events();
413
414 seq_ops = inode->i_private;
Li Zefan20c89282009-05-06 10:33:45 +0800415 return seq_open(file, seq_ops);
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500416}
417
Steven Rostedt1473e442009-02-24 14:15:08 -0500418static ssize_t
419event_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
420 loff_t *ppos)
421{
422 struct ftrace_event_call *call = filp->private_data;
423 char *buf;
424
Steven Rostedt553552c2010-04-23 11:12:36 -0400425 if (call->flags & TRACE_EVENT_FL_ENABLED)
Steven Rostedt1473e442009-02-24 14:15:08 -0500426 buf = "1\n";
427 else
428 buf = "0\n";
429
430 return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
431}
432
433static ssize_t
434event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
435 loff_t *ppos)
436{
437 struct ftrace_event_call *call = filp->private_data;
438 char buf[64];
439 unsigned long val;
440 int ret;
441
442 if (cnt >= sizeof(buf))
443 return -EINVAL;
444
445 if (copy_from_user(&buf, ubuf, cnt))
446 return -EFAULT;
447
448 buf[cnt] = 0;
449
450 ret = strict_strtoul(buf, 10, &val);
451 if (ret < 0)
452 return ret;
453
Steven Rostedt1852fcc2009-03-11 14:33:00 -0400454 ret = tracing_update_buffers();
455 if (ret < 0)
456 return ret;
457
Steven Rostedt1473e442009-02-24 14:15:08 -0500458 switch (val) {
459 case 0:
Steven Rostedt1473e442009-02-24 14:15:08 -0500460 case 1:
Steven Rostedt11a241a2009-03-02 11:49:04 -0500461 mutex_lock(&event_mutex);
Li Zefan3b8e4272009-12-08 11:14:52 +0800462 ret = ftrace_event_enable_disable(call, val);
Steven Rostedt11a241a2009-03-02 11:49:04 -0500463 mutex_unlock(&event_mutex);
Steven Rostedt1473e442009-02-24 14:15:08 -0500464 break;
465
466 default:
467 return -EINVAL;
468 }
469
470 *ppos += cnt;
471
Li Zefan3b8e4272009-12-08 11:14:52 +0800472 return ret ? ret : cnt;
Steven Rostedt1473e442009-02-24 14:15:08 -0500473}
474
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400475static ssize_t
476system_enable_read(struct file *filp, char __user *ubuf, size_t cnt,
477 loff_t *ppos)
478{
Li Zefanc142b152009-05-08 10:32:05 +0800479 const char set_to_char[4] = { '?', '0', '1', 'X' };
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400480 const char *system = filp->private_data;
481 struct ftrace_event_call *call;
482 char buf[2];
Li Zefanc142b152009-05-08 10:32:05 +0800483 int set = 0;
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400484 int ret;
485
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400486 mutex_lock(&event_mutex);
487 list_for_each_entry(call, &ftrace_events, list) {
Steven Rostedt22392912010-04-21 12:27:06 -0400488 if (!call->name || !call->class ||
489 (!call->class->probe && !call->class->reg))
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400490 continue;
491
Steven Rostedt8f082012010-04-20 10:47:33 -0400492 if (system && strcmp(call->class->system, system) != 0)
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400493 continue;
494
495 /*
496 * We need to find out if all the events are set
497 * or if all events or cleared, or if we have
498 * a mixture.
499 */
Steven Rostedt553552c2010-04-23 11:12:36 -0400500 set |= (1 << !!(call->flags & TRACE_EVENT_FL_ENABLED));
Li Zefanc142b152009-05-08 10:32:05 +0800501
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400502 /*
503 * If we have a mixture, no need to look further.
504 */
Li Zefanc142b152009-05-08 10:32:05 +0800505 if (set == 3)
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400506 break;
507 }
508 mutex_unlock(&event_mutex);
509
Li Zefanc142b152009-05-08 10:32:05 +0800510 buf[0] = set_to_char[set];
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400511 buf[1] = '\n';
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400512
513 ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, 2);
514
515 return ret;
516}
517
518static ssize_t
519system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt,
520 loff_t *ppos)
521{
522 const char *system = filp->private_data;
523 unsigned long val;
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400524 char buf[64];
525 ssize_t ret;
526
527 if (cnt >= sizeof(buf))
528 return -EINVAL;
529
530 if (copy_from_user(&buf, ubuf, cnt))
531 return -EFAULT;
532
533 buf[cnt] = 0;
534
535 ret = strict_strtoul(buf, 10, &val);
536 if (ret < 0)
537 return ret;
538
539 ret = tracing_update_buffers();
540 if (ret < 0)
541 return ret;
542
Li Zefan8f31bfe2009-05-08 10:31:42 +0800543 if (val != 0 && val != 1)
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400544 return -EINVAL;
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400545
Li Zefan8f31bfe2009-05-08 10:31:42 +0800546 ret = __ftrace_set_clr_event(NULL, system, NULL, val);
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400547 if (ret)
Li Zefan8f31bfe2009-05-08 10:31:42 +0800548 goto out;
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400549
550 ret = cnt;
551
Li Zefan8f31bfe2009-05-08 10:31:42 +0800552out:
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400553 *ppos += cnt;
554
555 return ret;
556}
557
Li Zefan8728fe52010-05-24 16:22:49 +0800558static void print_event_fields(struct trace_seq *s, struct list_head *head)
Steven Rostedt981d0812009-03-02 13:53:59 -0500559{
Lai Jiangshan5a65e952009-12-15 15:39:53 +0800560 struct ftrace_event_field *field;
Steven Rostedt981d0812009-03-02 13:53:59 -0500561
Steven Rostedt2e33af02010-04-22 10:35:55 -0400562 list_for_each_entry_reverse(field, head, link) {
Lai Jiangshan5a65e952009-12-15 15:39:53 +0800563 /*
564 * Smartly shows the array type(except dynamic array).
565 * Normal:
566 * field:TYPE VAR
567 * If TYPE := TYPE[LEN], it is shown:
568 * field:TYPE VAR[LEN]
569 */
570 const char *array_descriptor = strchr(field->type, '[');
571
572 if (!strncmp(field->type, "__data_loc", 10))
573 array_descriptor = NULL;
574
575 if (!array_descriptor) {
Li Zefan8728fe52010-05-24 16:22:49 +0800576 trace_seq_printf(s, "\tfield:%s %s;\toffset:%u;"
Lai Jiangshan5a65e952009-12-15 15:39:53 +0800577 "\tsize:%u;\tsigned:%d;\n",
578 field->type, field->name, field->offset,
579 field->size, !!field->is_signed);
580 } else {
Li Zefan8728fe52010-05-24 16:22:49 +0800581 trace_seq_printf(s, "\tfield:%.*s %s%s;\toffset:%u;"
Lai Jiangshan5a65e952009-12-15 15:39:53 +0800582 "\tsize:%u;\tsigned:%d;\n",
583 (int)(array_descriptor - field->type),
584 field->type, field->name,
585 array_descriptor, field->offset,
586 field->size, !!field->is_signed);
587 }
Lai Jiangshan5a65e952009-12-15 15:39:53 +0800588 }
Li Zefan8728fe52010-05-24 16:22:49 +0800589}
Lai Jiangshan5a65e952009-12-15 15:39:53 +0800590
Li Zefan8728fe52010-05-24 16:22:49 +0800591static ssize_t
592event_format_read(struct file *filp, char __user *ubuf, size_t cnt,
593 loff_t *ppos)
594{
595 struct ftrace_event_call *call = filp->private_data;
596 struct list_head *head;
597 struct trace_seq *s;
598 char *buf;
599 int r;
600
601 if (*ppos)
602 return 0;
603
604 s = kmalloc(sizeof(*s), GFP_KERNEL);
605 if (!s)
606 return -ENOMEM;
607
608 trace_seq_init(s);
609
610 trace_seq_printf(s, "name: %s\n", call->name);
611 trace_seq_printf(s, "ID: %d\n", call->event.type);
612 trace_seq_printf(s, "format:\n");
613
614 /* print common fields */
615 print_event_fields(s, &ftrace_common_fields);
616
617 trace_seq_putc(s, '\n');
618
619 /* print event specific fields */
620 head = trace_get_fields(call);
621 print_event_fields(s, head);
622
623 r = trace_seq_printf(s, "\nprint fmt: %s\n", call->print_fmt);
Lai Jiangshan5a65e952009-12-15 15:39:53 +0800624
Steven Rostedt981d0812009-03-02 13:53:59 -0500625 if (!r) {
626 /*
627 * ug! The format output is bigger than a PAGE!!
628 */
629 buf = "FORMAT TOO BIG\n";
630 r = simple_read_from_buffer(ubuf, cnt, ppos,
631 buf, strlen(buf));
632 goto out;
633 }
634
635 r = simple_read_from_buffer(ubuf, cnt, ppos,
636 s->buffer, s->len);
637 out:
638 kfree(s);
639 return r;
640}
641
Peter Zijlstra23725ae2009-03-19 20:26:13 +0100642static ssize_t
643event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
644{
645 struct ftrace_event_call *call = filp->private_data;
646 struct trace_seq *s;
647 int r;
648
649 if (*ppos)
650 return 0;
651
652 s = kmalloc(sizeof(*s), GFP_KERNEL);
653 if (!s)
654 return -ENOMEM;
655
656 trace_seq_init(s);
Steven Rostedt32c0eda2010-04-23 10:38:03 -0400657 trace_seq_printf(s, "%d\n", call->event.type);
Peter Zijlstra23725ae2009-03-19 20:26:13 +0100658
659 r = simple_read_from_buffer(ubuf, cnt, ppos,
660 s->buffer, s->len);
661 kfree(s);
662 return r;
663}
664
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500665static ssize_t
666event_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
667 loff_t *ppos)
668{
669 struct ftrace_event_call *call = filp->private_data;
670 struct trace_seq *s;
671 int r;
672
673 if (*ppos)
674 return 0;
675
676 s = kmalloc(sizeof(*s), GFP_KERNEL);
677 if (!s)
678 return -ENOMEM;
679
680 trace_seq_init(s);
681
Tom Zanussi8b372562009-04-28 03:04:59 -0500682 print_event_filter(call, s);
Tom Zanussi4bda2d52009-03-24 02:14:31 -0500683 r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500684
685 kfree(s);
686
687 return r;
688}
689
690static ssize_t
691event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
692 loff_t *ppos)
693{
694 struct ftrace_event_call *call = filp->private_data;
Tom Zanussi8b372562009-04-28 03:04:59 -0500695 char *buf;
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500696 int err;
697
Tom Zanussi8b372562009-04-28 03:04:59 -0500698 if (cnt >= PAGE_SIZE)
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500699 return -EINVAL;
700
Tom Zanussi8b372562009-04-28 03:04:59 -0500701 buf = (char *)__get_free_page(GFP_TEMPORARY);
702 if (!buf)
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500703 return -ENOMEM;
704
Tom Zanussi8b372562009-04-28 03:04:59 -0500705 if (copy_from_user(buf, ubuf, cnt)) {
706 free_page((unsigned long) buf);
707 return -EFAULT;
708 }
709 buf[cnt] = '\0';
710
711 err = apply_event_filter(call, buf);
712 free_page((unsigned long) buf);
713 if (err < 0)
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500714 return err;
Tom Zanussi0a19e532009-04-13 03:17:50 -0500715
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500716 *ppos += cnt;
717
718 return cnt;
719}
720
Tom Zanussicfb180f2009-03-22 03:31:17 -0500721static ssize_t
722subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt,
723 loff_t *ppos)
724{
725 struct event_subsystem *system = filp->private_data;
726 struct trace_seq *s;
727 int r;
728
729 if (*ppos)
730 return 0;
731
732 s = kmalloc(sizeof(*s), GFP_KERNEL);
733 if (!s)
734 return -ENOMEM;
735
736 trace_seq_init(s);
737
Tom Zanussi8b372562009-04-28 03:04:59 -0500738 print_subsystem_event_filter(system, s);
Tom Zanussi4bda2d52009-03-24 02:14:31 -0500739 r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
Tom Zanussicfb180f2009-03-22 03:31:17 -0500740
741 kfree(s);
742
743 return r;
744}
745
746static ssize_t
747subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt,
748 loff_t *ppos)
749{
750 struct event_subsystem *system = filp->private_data;
Tom Zanussi8b372562009-04-28 03:04:59 -0500751 char *buf;
Tom Zanussicfb180f2009-03-22 03:31:17 -0500752 int err;
753
Tom Zanussi8b372562009-04-28 03:04:59 -0500754 if (cnt >= PAGE_SIZE)
Tom Zanussicfb180f2009-03-22 03:31:17 -0500755 return -EINVAL;
756
Tom Zanussi8b372562009-04-28 03:04:59 -0500757 buf = (char *)__get_free_page(GFP_TEMPORARY);
758 if (!buf)
Tom Zanussicfb180f2009-03-22 03:31:17 -0500759 return -ENOMEM;
760
Tom Zanussi8b372562009-04-28 03:04:59 -0500761 if (copy_from_user(buf, ubuf, cnt)) {
762 free_page((unsigned long) buf);
763 return -EFAULT;
Tom Zanussicfb180f2009-03-22 03:31:17 -0500764 }
Tom Zanussi8b372562009-04-28 03:04:59 -0500765 buf[cnt] = '\0';
Tom Zanussicfb180f2009-03-22 03:31:17 -0500766
Tom Zanussi8b372562009-04-28 03:04:59 -0500767 err = apply_subsystem_event_filter(system, buf);
768 free_page((unsigned long) buf);
769 if (err < 0)
Li Zefan44e9c8b2009-04-11 15:55:28 +0800770 return err;
Tom Zanussicfb180f2009-03-22 03:31:17 -0500771
772 *ppos += cnt;
773
774 return cnt;
775}
776
Steven Rostedtd1b182a2009-04-15 16:53:47 -0400777static ssize_t
778show_header(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
779{
780 int (*func)(struct trace_seq *s) = filp->private_data;
781 struct trace_seq *s;
782 int r;
783
784 if (*ppos)
785 return 0;
786
787 s = kmalloc(sizeof(*s), GFP_KERNEL);
788 if (!s)
789 return -ENOMEM;
790
791 trace_seq_init(s);
792
793 func(s);
794 r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len);
795
796 kfree(s);
797
798 return r;
799}
800
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500801static const struct seq_operations show_event_seq_ops = {
802 .start = t_start,
803 .next = t_next,
804 .show = t_show,
805 .stop = t_stop,
806};
807
808static const struct seq_operations show_set_event_seq_ops = {
809 .start = s_start,
810 .next = s_next,
811 .show = t_show,
812 .stop = t_stop,
813};
814
Steven Rostedt2314c4a2009-03-10 12:04:02 -0400815static const struct file_operations ftrace_avail_fops = {
816 .open = ftrace_event_seq_open,
817 .read = seq_read,
818 .llseek = seq_lseek,
819 .release = seq_release,
820};
821
Steven Rostedtb77e38a2009-02-24 10:21:36 -0500822static const struct file_operations ftrace_set_event_fops = {
823 .open = ftrace_event_seq_open,
824 .read = seq_read,
825 .write = ftrace_event_write,
826 .llseek = seq_lseek,
827 .release = seq_release,
828};
829
Steven Rostedt1473e442009-02-24 14:15:08 -0500830static const struct file_operations ftrace_enable_fops = {
831 .open = tracing_open_generic,
832 .read = event_enable_read,
833 .write = event_enable_write,
834};
835
Steven Rostedt981d0812009-03-02 13:53:59 -0500836static const struct file_operations ftrace_event_format_fops = {
837 .open = tracing_open_generic,
838 .read = event_format_read,
839};
840
Peter Zijlstra23725ae2009-03-19 20:26:13 +0100841static const struct file_operations ftrace_event_id_fops = {
842 .open = tracing_open_generic,
843 .read = event_id_read,
844};
845
Tom Zanussi7ce7e422009-03-22 03:31:04 -0500846static const struct file_operations ftrace_event_filter_fops = {
847 .open = tracing_open_generic,
848 .read = event_filter_read,
849 .write = event_filter_write,
850};
851
Tom Zanussicfb180f2009-03-22 03:31:17 -0500852static const struct file_operations ftrace_subsystem_filter_fops = {
853 .open = tracing_open_generic,
854 .read = subsystem_filter_read,
855 .write = subsystem_filter_write,
856};
857
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400858static const struct file_operations ftrace_system_enable_fops = {
859 .open = tracing_open_generic,
860 .read = system_enable_read,
861 .write = system_enable_write,
862};
863
Steven Rostedtd1b182a2009-04-15 16:53:47 -0400864static const struct file_operations ftrace_show_header_fops = {
865 .open = tracing_open_generic,
866 .read = show_header,
867};
868
Steven Rostedt1473e442009-02-24 14:15:08 -0500869static struct dentry *event_trace_events_dir(void)
870{
871 static struct dentry *d_tracer;
872 static struct dentry *d_events;
873
874 if (d_events)
875 return d_events;
876
877 d_tracer = tracing_init_dentry();
878 if (!d_tracer)
879 return NULL;
880
881 d_events = debugfs_create_dir("events", d_tracer);
882 if (!d_events)
883 pr_warning("Could not create debugfs "
884 "'events' directory\n");
885
886 return d_events;
887}
888
Steven Rostedt6ecc2d12009-02-27 21:33:02 -0500889static LIST_HEAD(event_subsystems);
890
891static struct dentry *
892event_subsystem_dir(const char *name, struct dentry *d_events)
893{
894 struct event_subsystem *system;
Tom Zanussie1112b42009-03-31 00:48:49 -0500895 struct dentry *entry;
Steven Rostedt6ecc2d12009-02-27 21:33:02 -0500896
897 /* First see if we did not already create this dir */
898 list_for_each_entry(system, &event_subsystems, list) {
Xiao Guangrongdc82ec98a2009-07-09 16:22:22 +0800899 if (strcmp(system->name, name) == 0) {
900 system->nr_events++;
Steven Rostedt6ecc2d12009-02-27 21:33:02 -0500901 return system->entry;
Xiao Guangrongdc82ec98a2009-07-09 16:22:22 +0800902 }
Steven Rostedt6ecc2d12009-02-27 21:33:02 -0500903 }
904
905 /* need to create new entry */
906 system = kmalloc(sizeof(*system), GFP_KERNEL);
907 if (!system) {
908 pr_warning("No memory to create event subsystem %s\n",
909 name);
910 return d_events;
911 }
912
913 system->entry = debugfs_create_dir(name, d_events);
914 if (!system->entry) {
915 pr_warning("Could not create event subsystem %s\n",
916 name);
917 kfree(system);
918 return d_events;
919 }
920
Xiao Guangrongdc82ec98a2009-07-09 16:22:22 +0800921 system->nr_events = 1;
Steven Rostedt6d723732009-04-10 14:53:50 -0400922 system->name = kstrdup(name, GFP_KERNEL);
923 if (!system->name) {
924 debugfs_remove(system->entry);
925 kfree(system);
926 return d_events;
927 }
928
Steven Rostedt6ecc2d12009-02-27 21:33:02 -0500929 list_add(&system->list, &event_subsystems);
930
Tom Zanussi30e673b2009-04-28 03:04:47 -0500931 system->filter = NULL;
Tom Zanussicfb180f2009-03-22 03:31:17 -0500932
Tom Zanussi8b372562009-04-28 03:04:59 -0500933 system->filter = kzalloc(sizeof(struct event_filter), GFP_KERNEL);
934 if (!system->filter) {
935 pr_warning("Could not allocate filter for subsystem "
936 "'%s'\n", name);
937 return system->entry;
938 }
939
Tom Zanussie1112b42009-03-31 00:48:49 -0500940 entry = debugfs_create_file("filter", 0644, system->entry, system,
941 &ftrace_subsystem_filter_fops);
Tom Zanussi8b372562009-04-28 03:04:59 -0500942 if (!entry) {
943 kfree(system->filter);
944 system->filter = NULL;
Tom Zanussie1112b42009-03-31 00:48:49 -0500945 pr_warning("Could not create debugfs "
946 "'%s/filter' entry\n", name);
Tom Zanussi8b372562009-04-28 03:04:59 -0500947 }
Tom Zanussie1112b42009-03-31 00:48:49 -0500948
Frederic Weisbeckerf3f3f002009-09-24 15:27:41 +0200949 trace_create_file("enable", 0644, system->entry,
950 (void *)system->name,
951 &ftrace_system_enable_fops);
Steven Rostedt8ae79a12009-05-06 22:52:15 -0400952
Steven Rostedt6ecc2d12009-02-27 21:33:02 -0500953 return system->entry;
954}
955
Steven Rostedt1473e442009-02-24 14:15:08 -0500956static int
Steven Rostedt701970b2009-04-24 23:11:22 -0400957event_create_dir(struct ftrace_event_call *call, struct dentry *d_events,
958 const struct file_operations *id,
959 const struct file_operations *enable,
960 const struct file_operations *filter,
961 const struct file_operations *format)
Steven Rostedt1473e442009-02-24 14:15:08 -0500962{
Steven Rostedt2e33af02010-04-22 10:35:55 -0400963 struct list_head *head;
Steven Rostedtfd994982009-02-28 02:41:25 -0500964 int ret;
Steven Rostedt1473e442009-02-24 14:15:08 -0500965
Steven Rostedt6ecc2d12009-02-27 21:33:02 -0500966 /*
967 * If the trace point header did not define TRACE_SYSTEM
968 * then the system would be called "TRACE_SYSTEM".
969 */
Steven Rostedt8f082012010-04-20 10:47:33 -0400970 if (strcmp(call->class->system, TRACE_SYSTEM) != 0)
971 d_events = event_subsystem_dir(call->class->system, d_events);
Steven Rostedt6ecc2d12009-02-27 21:33:02 -0500972
Steven Rostedt1473e442009-02-24 14:15:08 -0500973 call->dir = debugfs_create_dir(call->name, d_events);
974 if (!call->dir) {
975 pr_warning("Could not create debugfs "
976 "'%s' directory\n", call->name);
977 return -1;
978 }
979
Steven Rostedt22392912010-04-21 12:27:06 -0400980 if (call->class->probe || call->class->reg)
Frederic Weisbeckerf3f3f002009-09-24 15:27:41 +0200981 trace_create_file("enable", 0644, call->dir, call,
982 enable);
Steven Rostedt1473e442009-02-24 14:15:08 -0500983
Steven Rostedt22392912010-04-21 12:27:06 -0400984#ifdef CONFIG_PERF_EVENTS
Steven Rostedt32c0eda2010-04-23 10:38:03 -0400985 if (call->event.type && (call->class->perf_probe || call->class->reg))
Frederic Weisbeckerf3f3f002009-09-24 15:27:41 +0200986 trace_create_file("id", 0444, call->dir, call,
987 id);
Steven Rostedt22392912010-04-21 12:27:06 -0400988#endif
Peter Zijlstra23725ae2009-03-19 20:26:13 +0100989
Li Zefanc9d932c2010-05-24 16:24:28 +0800990 /*
991 * Other events may have the same class. Only update
992 * the fields if they are not already defined.
993 */
994 head = trace_get_fields(call);
995 if (list_empty(head)) {
996 ret = call->class->define_fields(call);
997 if (ret < 0) {
998 pr_warning("Could not initialize trace point"
999 " events/%s\n", call->name);
1000 return ret;
Tom Zanussicf027f62009-03-22 03:30:39 -05001001 }
1002 }
Li Zefanc9d932c2010-05-24 16:24:28 +08001003 trace_create_file("filter", 0644, call->dir, call,
1004 filter);
Tom Zanussicf027f62009-03-22 03:30:39 -05001005
Frederic Weisbeckerf3f3f002009-09-24 15:27:41 +02001006 trace_create_file("format", 0444, call->dir, call,
1007 format);
Steven Rostedtfd994982009-02-28 02:41:25 -05001008
Steven Rostedt1473e442009-02-24 14:15:08 -05001009 return 0;
1010}
1011
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001012static int __trace_add_event_call(struct ftrace_event_call *call)
1013{
1014 struct dentry *d_events;
1015 int ret;
Steven Rostedt6d723732009-04-10 14:53:50 -04001016
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001017 if (!call->name)
1018 return -EINVAL;
Steven Rostedt701970b2009-04-24 23:11:22 -04001019
Steven Rostedt0405ab82010-04-22 11:46:44 -04001020 if (call->class->raw_init) {
1021 ret = call->class->raw_init(call);
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001022 if (ret < 0) {
1023 if (ret != -ENOSYS)
1024 pr_warning("Could not initialize trace "
1025 "events/%s\n", call->name);
1026 return ret;
1027 }
1028 }
Steven Rostedt701970b2009-04-24 23:11:22 -04001029
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001030 d_events = event_trace_events_dir();
1031 if (!d_events)
1032 return -ENOENT;
1033
Masami Hiramatsu588bebb2009-09-16 11:42:55 -04001034 ret = event_create_dir(call, d_events, &ftrace_event_id_fops,
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001035 &ftrace_enable_fops, &ftrace_event_filter_fops,
1036 &ftrace_event_format_fops);
Masami Hiramatsu88f70d72009-09-25 11:20:54 -07001037 if (!ret)
1038 list_add(&call->list, &ftrace_events);
1039
Masami Hiramatsu588bebb2009-09-16 11:42:55 -04001040 return ret;
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001041}
1042
1043/* Add an additional event_call dynamically */
1044int trace_add_event_call(struct ftrace_event_call *call)
1045{
1046 int ret;
1047 mutex_lock(&event_mutex);
1048 ret = __trace_add_event_call(call);
1049 mutex_unlock(&event_mutex);
1050 return ret;
1051}
Steven Rostedt701970b2009-04-24 23:11:22 -04001052
Frederic Weisbeckera2ca5e02009-08-06 07:32:21 +02001053static void remove_subsystem_dir(const char *name)
1054{
1055 struct event_subsystem *system;
1056
1057 if (strcmp(name, TRACE_SYSTEM) == 0)
1058 return;
1059
1060 list_for_each_entry(system, &event_subsystems, list) {
1061 if (strcmp(system->name, name) == 0) {
1062 if (!--system->nr_events) {
1063 struct event_filter *filter = system->filter;
1064
1065 debugfs_remove_recursive(system->entry);
1066 list_del(&system->list);
1067 if (filter) {
1068 kfree(filter->filter_string);
1069 kfree(filter);
1070 }
1071 kfree(system->name);
1072 kfree(system);
1073 }
1074 break;
1075 }
1076 }
1077}
1078
Masami Hiramatsu4fead8e2009-09-14 16:49:12 -04001079/*
1080 * Must be called under locking both of event_mutex and trace_event_mutex.
1081 */
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001082static void __trace_remove_event_call(struct ftrace_event_call *call)
1083{
1084 ftrace_event_enable_disable(call, 0);
Steven Rostedt80decc72010-04-23 10:00:22 -04001085 if (call->event.funcs)
1086 __unregister_ftrace_event(&call->event);
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001087 debugfs_remove_recursive(call->dir);
1088 list_del(&call->list);
1089 trace_destroy_fields(call);
1090 destroy_preds(call);
Steven Rostedt8f082012010-04-20 10:47:33 -04001091 remove_subsystem_dir(call->class->system);
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001092}
1093
1094/* Remove an event_call */
1095void trace_remove_event_call(struct ftrace_event_call *call)
1096{
1097 mutex_lock(&event_mutex);
Masami Hiramatsu4fead8e2009-09-14 16:49:12 -04001098 down_write(&trace_event_mutex);
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001099 __trace_remove_event_call(call);
Masami Hiramatsu4fead8e2009-09-14 16:49:12 -04001100 up_write(&trace_event_mutex);
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001101 mutex_unlock(&event_mutex);
1102}
1103
1104#define for_each_event(event, start, end) \
1105 for (event = start; \
1106 (unsigned long)event < (unsigned long)end; \
1107 event++)
1108
1109#ifdef CONFIG_MODULES
1110
1111static LIST_HEAD(ftrace_module_file_list);
1112
1113/*
1114 * Modules must own their file_operations to keep up with
1115 * reference counting.
1116 */
1117struct ftrace_module_file_ops {
1118 struct list_head list;
1119 struct module *mod;
1120 struct file_operations id;
1121 struct file_operations enable;
1122 struct file_operations format;
1123 struct file_operations filter;
1124};
1125
Steven Rostedt701970b2009-04-24 23:11:22 -04001126static struct ftrace_module_file_ops *
1127trace_create_file_ops(struct module *mod)
1128{
1129 struct ftrace_module_file_ops *file_ops;
1130
1131 /*
1132 * This is a bit of a PITA. To allow for correct reference
1133 * counting, modules must "own" their file_operations.
1134 * To do this, we allocate the file operations that will be
1135 * used in the event directory.
1136 */
1137
1138 file_ops = kmalloc(sizeof(*file_ops), GFP_KERNEL);
1139 if (!file_ops)
1140 return NULL;
1141
1142 file_ops->mod = mod;
1143
1144 file_ops->id = ftrace_event_id_fops;
1145 file_ops->id.owner = mod;
1146
1147 file_ops->enable = ftrace_enable_fops;
1148 file_ops->enable.owner = mod;
1149
1150 file_ops->filter = ftrace_event_filter_fops;
1151 file_ops->filter.owner = mod;
1152
1153 file_ops->format = ftrace_event_format_fops;
1154 file_ops->format.owner = mod;
1155
1156 list_add(&file_ops->list, &ftrace_module_file_list);
1157
1158 return file_ops;
1159}
1160
Steven Rostedt6d723732009-04-10 14:53:50 -04001161static void trace_module_add_events(struct module *mod)
1162{
Steven Rostedt701970b2009-04-24 23:11:22 -04001163 struct ftrace_module_file_ops *file_ops = NULL;
Steven Rostedt6d723732009-04-10 14:53:50 -04001164 struct ftrace_event_call *call, *start, *end;
1165 struct dentry *d_events;
Jason Baronf744bd52009-08-10 16:52:39 -04001166 int ret;
Steven Rostedt6d723732009-04-10 14:53:50 -04001167
1168 start = mod->trace_events;
1169 end = mod->trace_events + mod->num_trace_events;
1170
1171 if (start == end)
1172 return;
1173
1174 d_events = event_trace_events_dir();
1175 if (!d_events)
1176 return;
1177
1178 for_each_event(call, start, end) {
1179 /* The linker may leave blanks */
1180 if (!call->name)
1181 continue;
Steven Rostedt0405ab82010-04-22 11:46:44 -04001182 if (call->class->raw_init) {
1183 ret = call->class->raw_init(call);
Jason Baronf744bd52009-08-10 16:52:39 -04001184 if (ret < 0) {
1185 if (ret != -ENOSYS)
1186 pr_warning("Could not initialize trace "
1187 "point events/%s\n", call->name);
1188 continue;
1189 }
1190 }
Steven Rostedt701970b2009-04-24 23:11:22 -04001191 /*
1192 * This module has events, create file ops for this module
1193 * if not already done.
1194 */
1195 if (!file_ops) {
1196 file_ops = trace_create_file_ops(mod);
1197 if (!file_ops)
1198 return;
1199 }
Steven Rostedt6d723732009-04-10 14:53:50 -04001200 call->mod = mod;
Masami Hiramatsu88f70d72009-09-25 11:20:54 -07001201 ret = event_create_dir(call, d_events,
1202 &file_ops->id, &file_ops->enable,
1203 &file_ops->filter, &file_ops->format);
1204 if (!ret)
1205 list_add(&call->list, &ftrace_events);
Steven Rostedt6d723732009-04-10 14:53:50 -04001206 }
1207}
1208
1209static void trace_module_remove_events(struct module *mod)
1210{
Steven Rostedt701970b2009-04-24 23:11:22 -04001211 struct ftrace_module_file_ops *file_ops;
Steven Rostedt6d723732009-04-10 14:53:50 -04001212 struct ftrace_event_call *call, *p;
Steven Rostedt9456f0f2009-05-06 21:54:09 -04001213 bool found = false;
Steven Rostedt6d723732009-04-10 14:53:50 -04001214
Steven Rostedt110bf2b2009-06-09 17:29:07 -04001215 down_write(&trace_event_mutex);
Steven Rostedt6d723732009-04-10 14:53:50 -04001216 list_for_each_entry_safe(call, p, &ftrace_events, list) {
1217 if (call->mod == mod) {
Steven Rostedt9456f0f2009-05-06 21:54:09 -04001218 found = true;
Masami Hiramatsubd1a5c82009-08-13 16:34:53 -04001219 __trace_remove_event_call(call);
Steven Rostedt6d723732009-04-10 14:53:50 -04001220 }
1221 }
Steven Rostedt701970b2009-04-24 23:11:22 -04001222
1223 /* Now free the file_operations */
1224 list_for_each_entry(file_ops, &ftrace_module_file_list, list) {
1225 if (file_ops->mod == mod)
1226 break;
1227 }
1228 if (&file_ops->list != &ftrace_module_file_list) {
1229 list_del(&file_ops->list);
1230 kfree(file_ops);
1231 }
Steven Rostedt9456f0f2009-05-06 21:54:09 -04001232
1233 /*
1234 * It is safest to reset the ring buffer if the module being unloaded
1235 * registered any events.
1236 */
1237 if (found)
1238 tracing_reset_current_online_cpus();
Steven Rostedt110bf2b2009-06-09 17:29:07 -04001239 up_write(&trace_event_mutex);
Steven Rostedt6d723732009-04-10 14:53:50 -04001240}
1241
Steven Rostedt61f919a2009-04-14 18:22:32 -04001242static int trace_module_notify(struct notifier_block *self,
1243 unsigned long val, void *data)
Steven Rostedt6d723732009-04-10 14:53:50 -04001244{
1245 struct module *mod = data;
1246
1247 mutex_lock(&event_mutex);
1248 switch (val) {
1249 case MODULE_STATE_COMING:
1250 trace_module_add_events(mod);
1251 break;
1252 case MODULE_STATE_GOING:
1253 trace_module_remove_events(mod);
1254 break;
1255 }
1256 mutex_unlock(&event_mutex);
1257
1258 return 0;
1259}
Steven Rostedt61f919a2009-04-14 18:22:32 -04001260#else
1261static int trace_module_notify(struct notifier_block *self,
1262 unsigned long val, void *data)
1263{
1264 return 0;
1265}
1266#endif /* CONFIG_MODULES */
Steven Rostedt6d723732009-04-10 14:53:50 -04001267
Steven Rostedtec827c72009-09-14 10:50:23 -04001268static struct notifier_block trace_module_nb = {
Steven Rostedt6d723732009-04-10 14:53:50 -04001269 .notifier_call = trace_module_notify,
1270 .priority = 0,
1271};
1272
Steven Rostedta59fd602009-04-10 13:52:20 -04001273extern struct ftrace_event_call __start_ftrace_events[];
1274extern struct ftrace_event_call __stop_ftrace_events[];
1275
Li Zefan020e5f82009-07-01 10:47:05 +08001276static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata;
1277
1278static __init int setup_trace_event(char *str)
1279{
1280 strlcpy(bootup_event_buf, str, COMMAND_LINE_SIZE);
1281 ring_buffer_expanded = 1;
1282 tracing_selftest_disabled = 1;
1283
1284 return 1;
1285}
1286__setup("trace_event=", setup_trace_event);
1287
Steven Rostedtb77e38a2009-02-24 10:21:36 -05001288static __init int event_trace_init(void)
1289{
Steven Rostedta59fd602009-04-10 13:52:20 -04001290 struct ftrace_event_call *call;
Steven Rostedtb77e38a2009-02-24 10:21:36 -05001291 struct dentry *d_tracer;
1292 struct dentry *entry;
Steven Rostedt1473e442009-02-24 14:15:08 -05001293 struct dentry *d_events;
Steven Rostedt6d723732009-04-10 14:53:50 -04001294 int ret;
Li Zefan020e5f82009-07-01 10:47:05 +08001295 char *buf = bootup_event_buf;
1296 char *token;
Steven Rostedtb77e38a2009-02-24 10:21:36 -05001297
1298 d_tracer = tracing_init_dentry();
1299 if (!d_tracer)
1300 return 0;
1301
Steven Rostedt2314c4a2009-03-10 12:04:02 -04001302 entry = debugfs_create_file("available_events", 0444, d_tracer,
1303 (void *)&show_event_seq_ops,
1304 &ftrace_avail_fops);
1305 if (!entry)
1306 pr_warning("Could not create debugfs "
1307 "'available_events' entry\n");
1308
Steven Rostedtb77e38a2009-02-24 10:21:36 -05001309 entry = debugfs_create_file("set_event", 0644, d_tracer,
1310 (void *)&show_set_event_seq_ops,
1311 &ftrace_set_event_fops);
1312 if (!entry)
1313 pr_warning("Could not create debugfs "
1314 "'set_event' entry\n");
1315
Steven Rostedt1473e442009-02-24 14:15:08 -05001316 d_events = event_trace_events_dir();
1317 if (!d_events)
1318 return 0;
1319
Steven Rostedtd1b182a2009-04-15 16:53:47 -04001320 /* ring buffer internal formats */
1321 trace_create_file("header_page", 0444, d_events,
1322 ring_buffer_print_page_header,
1323 &ftrace_show_header_fops);
1324
1325 trace_create_file("header_event", 0444, d_events,
1326 ring_buffer_print_entry_header,
1327 &ftrace_show_header_fops);
1328
Steven Rostedt8ae79a12009-05-06 22:52:15 -04001329 trace_create_file("enable", 0644, d_events,
Li Zefan8f31bfe2009-05-08 10:31:42 +08001330 NULL, &ftrace_system_enable_fops);
Steven Rostedt8ae79a12009-05-06 22:52:15 -04001331
Li Zefan8728fe52010-05-24 16:22:49 +08001332 if (trace_define_common_fields())
1333 pr_warning("tracing: Failed to allocate common fields");
1334
Steven Rostedt6d723732009-04-10 14:53:50 -04001335 for_each_event(call, __start_ftrace_events, __stop_ftrace_events) {
Steven Rostedt1473e442009-02-24 14:15:08 -05001336 /* The linker may leave blanks */
1337 if (!call->name)
1338 continue;
Steven Rostedt0405ab82010-04-22 11:46:44 -04001339 if (call->class->raw_init) {
1340 ret = call->class->raw_init(call);
Jason Baronf744bd52009-08-10 16:52:39 -04001341 if (ret < 0) {
1342 if (ret != -ENOSYS)
1343 pr_warning("Could not initialize trace "
1344 "point events/%s\n", call->name);
1345 continue;
1346 }
1347 }
Masami Hiramatsu88f70d72009-09-25 11:20:54 -07001348 ret = event_create_dir(call, d_events, &ftrace_event_id_fops,
1349 &ftrace_enable_fops,
1350 &ftrace_event_filter_fops,
1351 &ftrace_event_format_fops);
1352 if (!ret)
1353 list_add(&call->list, &ftrace_events);
Steven Rostedt1473e442009-02-24 14:15:08 -05001354 }
1355
Li Zefan020e5f82009-07-01 10:47:05 +08001356 while (true) {
1357 token = strsep(&buf, ",");
1358
1359 if (!token)
1360 break;
1361 if (!*token)
1362 continue;
1363
1364 ret = ftrace_set_clr_event(token, 1);
1365 if (ret)
1366 pr_warning("Failed to enable trace event: %s\n", token);
1367 }
1368
Steven Rostedt6d723732009-04-10 14:53:50 -04001369 ret = register_module_notifier(&trace_module_nb);
Ming Lei55379372009-05-18 23:04:46 +08001370 if (ret)
Steven Rostedt6d723732009-04-10 14:53:50 -04001371 pr_warning("Failed to register trace events module notifier\n");
1372
Steven Rostedtb77e38a2009-02-24 10:21:36 -05001373 return 0;
1374}
1375fs_initcall(event_trace_init);
Steven Rostedte6187002009-04-15 13:36:40 -04001376
1377#ifdef CONFIG_FTRACE_STARTUP_TEST
1378
1379static DEFINE_SPINLOCK(test_spinlock);
1380static DEFINE_SPINLOCK(test_spinlock_irq);
1381static DEFINE_MUTEX(test_mutex);
1382
1383static __init void test_work(struct work_struct *dummy)
1384{
1385 spin_lock(&test_spinlock);
1386 spin_lock_irq(&test_spinlock_irq);
1387 udelay(1);
1388 spin_unlock_irq(&test_spinlock_irq);
1389 spin_unlock(&test_spinlock);
1390
1391 mutex_lock(&test_mutex);
1392 msleep(1);
1393 mutex_unlock(&test_mutex);
1394}
1395
1396static __init int event_test_thread(void *unused)
1397{
1398 void *test_malloc;
1399
1400 test_malloc = kmalloc(1234, GFP_KERNEL);
1401 if (!test_malloc)
1402 pr_info("failed to kmalloc\n");
1403
1404 schedule_on_each_cpu(test_work);
1405
1406 kfree(test_malloc);
1407
1408 set_current_state(TASK_INTERRUPTIBLE);
1409 while (!kthread_should_stop())
1410 schedule();
1411
1412 return 0;
1413}
1414
1415/*
1416 * Do various things that may trigger events.
1417 */
1418static __init void event_test_stuff(void)
1419{
1420 struct task_struct *test_thread;
1421
1422 test_thread = kthread_run(event_test_thread, NULL, "test-events");
1423 msleep(1);
1424 kthread_stop(test_thread);
1425}
1426
1427/*
1428 * For every trace event defined, we will test each trace point separately,
1429 * and then by groups, and finally all trace points.
1430 */
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001431static __init void event_trace_self_tests(void)
Steven Rostedte6187002009-04-15 13:36:40 -04001432{
1433 struct ftrace_event_call *call;
1434 struct event_subsystem *system;
Steven Rostedte6187002009-04-15 13:36:40 -04001435 int ret;
1436
1437 pr_info("Running tests on trace events:\n");
1438
1439 list_for_each_entry(call, &ftrace_events, list) {
1440
Steven Rostedt22392912010-04-21 12:27:06 -04001441 /* Only test those that have a probe */
1442 if (!call->class || !call->class->probe)
Steven Rostedte6187002009-04-15 13:36:40 -04001443 continue;
1444
Steven Rostedt1f5a6b42009-09-14 11:58:24 -04001445/*
1446 * Testing syscall events here is pretty useless, but
1447 * we still do it if configured. But this is time consuming.
1448 * What we really need is a user thread to perform the
1449 * syscalls as we test.
1450 */
1451#ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS
Steven Rostedt8f082012010-04-20 10:47:33 -04001452 if (call->class->system &&
1453 strcmp(call->class->system, "syscalls") == 0)
Steven Rostedt1f5a6b42009-09-14 11:58:24 -04001454 continue;
1455#endif
1456
Steven Rostedte6187002009-04-15 13:36:40 -04001457 pr_info("Testing event %s: ", call->name);
1458
1459 /*
1460 * If an event is already enabled, someone is using
1461 * it and the self test should not be on.
1462 */
Steven Rostedt553552c2010-04-23 11:12:36 -04001463 if (call->flags & TRACE_EVENT_FL_ENABLED) {
Steven Rostedte6187002009-04-15 13:36:40 -04001464 pr_warning("Enabled event during self test!\n");
1465 WARN_ON_ONCE(1);
1466 continue;
1467 }
1468
Zhaolei0e907c92009-05-25 18:13:59 +08001469 ftrace_event_enable_disable(call, 1);
Steven Rostedte6187002009-04-15 13:36:40 -04001470 event_test_stuff();
Zhaolei0e907c92009-05-25 18:13:59 +08001471 ftrace_event_enable_disable(call, 0);
Steven Rostedte6187002009-04-15 13:36:40 -04001472
1473 pr_cont("OK\n");
1474 }
1475
1476 /* Now test at the sub system level */
1477
1478 pr_info("Running tests on trace event systems:\n");
1479
1480 list_for_each_entry(system, &event_subsystems, list) {
1481
1482 /* the ftrace system is special, skip it */
1483 if (strcmp(system->name, "ftrace") == 0)
1484 continue;
1485
1486 pr_info("Testing event system %s: ", system->name);
1487
Li Zefan8f31bfe2009-05-08 10:31:42 +08001488 ret = __ftrace_set_clr_event(NULL, system->name, NULL, 1);
Steven Rostedte6187002009-04-15 13:36:40 -04001489 if (WARN_ON_ONCE(ret)) {
1490 pr_warning("error enabling system %s\n",
1491 system->name);
1492 continue;
1493 }
1494
1495 event_test_stuff();
1496
Li Zefan8f31bfe2009-05-08 10:31:42 +08001497 ret = __ftrace_set_clr_event(NULL, system->name, NULL, 0);
Steven Rostedte6187002009-04-15 13:36:40 -04001498 if (WARN_ON_ONCE(ret))
1499 pr_warning("error disabling system %s\n",
1500 system->name);
1501
1502 pr_cont("OK\n");
1503 }
1504
1505 /* Test with all events enabled */
1506
1507 pr_info("Running tests on all trace events:\n");
1508 pr_info("Testing all events: ");
1509
Li Zefan8f31bfe2009-05-08 10:31:42 +08001510 ret = __ftrace_set_clr_event(NULL, NULL, NULL, 1);
Steven Rostedte6187002009-04-15 13:36:40 -04001511 if (WARN_ON_ONCE(ret)) {
Steven Rostedte6187002009-04-15 13:36:40 -04001512 pr_warning("error enabling all events\n");
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001513 return;
Steven Rostedte6187002009-04-15 13:36:40 -04001514 }
1515
1516 event_test_stuff();
1517
1518 /* reset sysname */
Li Zefan8f31bfe2009-05-08 10:31:42 +08001519 ret = __ftrace_set_clr_event(NULL, NULL, NULL, 0);
Steven Rostedte6187002009-04-15 13:36:40 -04001520 if (WARN_ON_ONCE(ret)) {
1521 pr_warning("error disabling all events\n");
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001522 return;
Steven Rostedte6187002009-04-15 13:36:40 -04001523 }
1524
1525 pr_cont("OK\n");
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001526}
1527
1528#ifdef CONFIG_FUNCTION_TRACER
1529
Tejun Heo245b2e72009-06-24 15:13:48 +09001530static DEFINE_PER_CPU(atomic_t, ftrace_test_event_disable);
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001531
1532static void
1533function_test_events_call(unsigned long ip, unsigned long parent_ip)
1534{
1535 struct ring_buffer_event *event;
Steven Rostedte77405a2009-09-02 14:17:06 -04001536 struct ring_buffer *buffer;
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001537 struct ftrace_entry *entry;
1538 unsigned long flags;
1539 long disabled;
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001540 int cpu;
1541 int pc;
1542
1543 pc = preempt_count();
Steven Rostedt5168ae52010-06-03 09:36:50 -04001544 preempt_disable_notrace();
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001545 cpu = raw_smp_processor_id();
Tejun Heo245b2e72009-06-24 15:13:48 +09001546 disabled = atomic_inc_return(&per_cpu(ftrace_test_event_disable, cpu));
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001547
1548 if (disabled != 1)
1549 goto out;
1550
1551 local_save_flags(flags);
1552
Steven Rostedte77405a2009-09-02 14:17:06 -04001553 event = trace_current_buffer_lock_reserve(&buffer,
1554 TRACE_FN, sizeof(*entry),
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001555 flags, pc);
1556 if (!event)
1557 goto out;
1558 entry = ring_buffer_event_data(event);
1559 entry->ip = ip;
1560 entry->parent_ip = parent_ip;
1561
Steven Rostedte77405a2009-09-02 14:17:06 -04001562 trace_nowake_buffer_unlock_commit(buffer, event, flags, pc);
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001563
1564 out:
Tejun Heo245b2e72009-06-24 15:13:48 +09001565 atomic_dec(&per_cpu(ftrace_test_event_disable, cpu));
Steven Rostedt5168ae52010-06-03 09:36:50 -04001566 preempt_enable_notrace();
Steven Rostedt9ea21c12009-04-16 12:15:44 -04001567}
1568
1569static struct ftrace_ops trace_ops __initdata =
1570{
1571 .func = function_test_events_call,
1572};
1573
1574static __init void event_trace_self_test_with_function(void)
1575{
1576 register_ftrace_function(&trace_ops);
1577 pr_info("Running tests again, along with the function tracer\n");
1578 event_trace_self_tests();
1579 unregister_ftrace_function(&trace_ops);
1580}
1581#else
1582static __init void event_trace_self_test_with_function(void)
1583{
1584}
1585#endif
1586
1587static __init int event_trace_self_tests_init(void)
1588{
Li Zefan020e5f82009-07-01 10:47:05 +08001589 if (!tracing_selftest_disabled) {
1590 event_trace_self_tests();
1591 event_trace_self_test_with_function();
1592 }
Steven Rostedte6187002009-04-15 13:36:40 -04001593
1594 return 0;
1595}
1596
Steven Rostedt28d20e22009-04-20 12:12:44 -04001597late_initcall(event_trace_self_tests_init);
Steven Rostedte6187002009-04-15 13:36:40 -04001598
1599#endif