Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1 | /* |
| 2 | * event tracer |
| 3 | * |
| 4 | * Copyright (C) 2008 Red Hat Inc, Steven Rostedt <srostedt@redhat.com> |
| 5 | * |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 6 | * - Added format output of fields of the trace point. |
| 7 | * This was based off of work by Tom Zanussi <tzanussi@gmail.com>. |
| 8 | * |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 9 | */ |
| 10 | |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 11 | #include <linux/workqueue.h> |
| 12 | #include <linux/spinlock.h> |
| 13 | #include <linux/kthread.h> |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 14 | #include <linux/debugfs.h> |
| 15 | #include <linux/uaccess.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/ctype.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 18 | #include <linux/slab.h> |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 19 | #include <linux/delay.h> |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 20 | |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 21 | #include <asm/setup.h> |
| 22 | |
Steven Rostedt | 91729ef9 | 2009-03-02 15:03:01 -0500 | [diff] [blame] | 23 | #include "trace_output.h" |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 24 | |
Steven Rostedt | 4e5292e | 2009-09-12 19:26:21 -0400 | [diff] [blame] | 25 | #undef TRACE_SYSTEM |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 26 | #define TRACE_SYSTEM "TRACE_SYSTEM" |
| 27 | |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 28 | DEFINE_MUTEX(event_mutex); |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 29 | |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 30 | LIST_HEAD(ftrace_events); |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 31 | LIST_HEAD(ftrace_common_fields); |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 32 | |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 33 | struct list_head * |
| 34 | trace_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 Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 41 | static 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 Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 44 | { |
| 45 | struct ftrace_event_field *field; |
| 46 | |
Ingo Molnar | fe9f57f2 | 2009-03-22 18:41:59 +0100 | [diff] [blame] | 47 | field = kzalloc(sizeof(*field), GFP_KERNEL); |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 48 | if (!field) |
| 49 | goto err; |
Ingo Molnar | fe9f57f2 | 2009-03-22 18:41:59 +0100 | [diff] [blame] | 50 | |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 51 | field->name = kstrdup(name, GFP_KERNEL); |
| 52 | if (!field->name) |
| 53 | goto err; |
Ingo Molnar | fe9f57f2 | 2009-03-22 18:41:59 +0100 | [diff] [blame] | 54 | |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 55 | field->type = kstrdup(type, GFP_KERNEL); |
| 56 | if (!field->type) |
| 57 | goto err; |
Ingo Molnar | fe9f57f2 | 2009-03-22 18:41:59 +0100 | [diff] [blame] | 58 | |
Li Zefan | 43b51ea | 2009-08-07 10:33:22 +0800 | [diff] [blame] | 59 | if (filter_type == FILTER_OTHER) |
| 60 | field->filter_type = filter_assign_type(type); |
| 61 | else |
| 62 | field->filter_type = filter_type; |
| 63 | |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 64 | field->offset = offset; |
| 65 | field->size = size; |
Tom Zanussi | a118e4d | 2009-04-28 03:04:53 -0500 | [diff] [blame] | 66 | field->is_signed = is_signed; |
Li Zefan | aa38e9f | 2009-08-07 10:33:02 +0800 | [diff] [blame] | 67 | |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 68 | list_add(&field->link, head); |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 69 | |
| 70 | return 0; |
Ingo Molnar | fe9f57f2 | 2009-03-22 18:41:59 +0100 | [diff] [blame] | 71 | |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 72 | err: |
Wenji Huang | 7b60997f | 2010-02-24 15:40:26 +0800 | [diff] [blame] | 73 | if (field) |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 74 | kfree(field->name); |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 75 | kfree(field); |
Ingo Molnar | fe9f57f2 | 2009-03-22 18:41:59 +0100 | [diff] [blame] | 76 | |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 77 | return -ENOMEM; |
| 78 | } |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 79 | |
| 80 | int 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 Rostedt | 17c873e | 2009-04-10 18:12:50 -0400 | [diff] [blame] | 93 | EXPORT_SYMBOL_GPL(trace_define_field); |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 94 | |
Li Zefan | e647d6b | 2009-08-19 15:54:32 +0800 | [diff] [blame] | 95 | #define __common_field(type, item) \ |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 96 | 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 Zefan | e647d6b | 2009-08-19 15:54:32 +0800 | [diff] [blame] | 101 | if (ret) \ |
| 102 | return ret; |
| 103 | |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 104 | static int trace_define_common_fields(void) |
Li Zefan | e647d6b | 2009-08-19 15:54:32 +0800 | [diff] [blame] | 105 | { |
| 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 Rostedt | 637e7e8 | 2009-09-11 13:55:35 -0400 | [diff] [blame] | 113 | __common_field(int, lock_depth); |
Li Zefan | e647d6b | 2009-08-19 15:54:32 +0800 | [diff] [blame] | 114 | |
| 115 | return ret; |
| 116 | } |
| 117 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 118 | void trace_destroy_fields(struct ftrace_event_call *call) |
Li Zefan | 2df75e4 | 2009-05-06 10:33:04 +0800 | [diff] [blame] | 119 | { |
| 120 | struct ftrace_event_field *field, *next; |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 121 | struct list_head *head; |
Li Zefan | 2df75e4 | 2009-05-06 10:33:04 +0800 | [diff] [blame] | 122 | |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 123 | head = trace_get_fields(call); |
| 124 | list_for_each_entry_safe(field, next, head, link) { |
Li Zefan | 2df75e4 | 2009-05-06 10:33:04 +0800 | [diff] [blame] | 125 | list_del(&field->link); |
| 126 | kfree(field->type); |
| 127 | kfree(field->name); |
| 128 | kfree(field); |
| 129 | } |
| 130 | } |
| 131 | |
Li Zefan | 87d9b4e | 2009-12-08 11:14:20 +0800 | [diff] [blame] | 132 | int trace_event_raw_init(struct ftrace_event_call *call) |
| 133 | { |
| 134 | int id; |
| 135 | |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame] | 136 | id = register_ftrace_event(&call->event); |
Li Zefan | 87d9b4e | 2009-12-08 11:14:20 +0800 | [diff] [blame] | 137 | if (!id) |
| 138 | return -ENODEV; |
Li Zefan | 87d9b4e | 2009-12-08 11:14:20 +0800 | [diff] [blame] | 139 | |
| 140 | return 0; |
| 141 | } |
| 142 | EXPORT_SYMBOL_GPL(trace_event_raw_init); |
| 143 | |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 144 | int 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 | } |
| 171 | EXPORT_SYMBOL_GPL(ftrace_event_reg); |
| 172 | |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 173 | void 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 Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 193 | static int ftrace_event_enable_disable(struct ftrace_event_call *call, |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 194 | int enable) |
| 195 | { |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 196 | int ret = 0; |
| 197 | |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 198 | switch (enable) { |
| 199 | case 0: |
Steven Rostedt | 553552c | 2010-04-23 11:12:36 -0400 | [diff] [blame] | 200 | if (call->flags & TRACE_EVENT_FL_ENABLED) { |
| 201 | call->flags &= ~TRACE_EVENT_FL_ENABLED; |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 202 | if (call->flags & TRACE_EVENT_FL_RECORDED_CMD) { |
| 203 | tracing_stop_cmdline_record(); |
| 204 | call->flags &= ~TRACE_EVENT_FL_RECORDED_CMD; |
| 205 | } |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 206 | call->class->reg(call, TRACE_REG_UNREGISTER); |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 207 | } |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 208 | break; |
| 209 | case 1: |
Steven Rostedt | 553552c | 2010-04-23 11:12:36 -0400 | [diff] [blame] | 210 | if (!(call->flags & TRACE_EVENT_FL_ENABLED)) { |
Li Zefan | e870e9a | 2010-07-02 11:07:32 +0800 | [diff] [blame] | 211 | if (trace_flags & TRACE_ITER_RECORD_CMD) { |
| 212 | tracing_start_cmdline_record(); |
| 213 | call->flags |= TRACE_EVENT_FL_RECORDED_CMD; |
| 214 | } |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 215 | ret = call->class->reg(call, TRACE_REG_REGISTER); |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 216 | 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 Rostedt | 553552c | 2010-04-23 11:12:36 -0400 | [diff] [blame] | 222 | call->flags |= TRACE_EVENT_FL_ENABLED; |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 223 | } |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 224 | break; |
| 225 | } |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 226 | |
| 227 | return ret; |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 228 | } |
| 229 | |
Zhaolei | 0e907c9 | 2009-05-25 18:13:59 +0800 | [diff] [blame] | 230 | static 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 Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 241 | /* |
| 242 | * __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events. |
| 243 | */ |
| 244 | static int __ftrace_set_clr_event(const char *match, const char *sub, |
| 245 | const char *event, int set) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 246 | { |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 247 | struct ftrace_event_call *call; |
Steven Rostedt | 29f9394 | 2009-05-08 16:06:47 -0400 | [diff] [blame] | 248 | int ret = -EINVAL; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 249 | |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 250 | mutex_lock(&event_mutex); |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 251 | list_for_each_entry(call, &ftrace_events, list) { |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 252 | |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 253 | if (!call->name || !call->class || !call->class->reg) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 254 | continue; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 255 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 256 | if (match && |
| 257 | strcmp(match, call->name) != 0 && |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 258 | strcmp(match, call->class->system) != 0) |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 259 | continue; |
| 260 | |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 261 | if (sub && strcmp(sub, call->class->system) != 0) |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 262 | continue; |
| 263 | |
| 264 | if (event && strcmp(event, call->name) != 0) |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 265 | continue; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 266 | |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 267 | ftrace_event_enable_disable(call, set); |
| 268 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 269 | ret = 0; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 270 | } |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 271 | mutex_unlock(&event_mutex); |
| 272 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 273 | return ret; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 274 | } |
| 275 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 276 | static 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 Rostedt | 4671c79 | 2009-05-08 16:27:41 -0400 | [diff] [blame] | 307 | /** |
| 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 | */ |
| 319 | int 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 Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 324 | /* 128 should be much more than enough */ |
| 325 | #define EVENT_BUF_SIZE 127 |
| 326 | |
| 327 | static ssize_t |
| 328 | ftrace_event_write(struct file *file, const char __user *ubuf, |
| 329 | size_t cnt, loff_t *ppos) |
| 330 | { |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 331 | struct trace_parser parser; |
Li Zefan | 4ba7978 | 2009-09-22 13:52:20 +0800 | [diff] [blame] | 332 | ssize_t read, ret; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 333 | |
Li Zefan | 4ba7978 | 2009-09-22 13:52:20 +0800 | [diff] [blame] | 334 | if (!cnt) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 335 | return 0; |
| 336 | |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 337 | ret = tracing_update_buffers(); |
| 338 | if (ret < 0) |
| 339 | return ret; |
| 340 | |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 341 | if (trace_parser_get_init(&parser, EVENT_BUF_SIZE + 1)) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 342 | return -ENOMEM; |
| 343 | |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 344 | read = trace_get_user(&parser, ubuf, cnt, ppos); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 345 | |
Li Zefan | 4ba7978 | 2009-09-22 13:52:20 +0800 | [diff] [blame] | 346 | if (read >= 0 && trace_parser_loaded((&parser))) { |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 347 | int set = 1; |
| 348 | |
| 349 | if (*parser.buffer == '!') |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 350 | set = 0; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 351 | |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 352 | parser.buffer[parser.idx] = 0; |
| 353 | |
| 354 | ret = ftrace_set_clr_event(parser.buffer + !set, set); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 355 | if (ret) |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 356 | goto out_put; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 357 | } |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 358 | |
| 359 | ret = read; |
| 360 | |
jolsa@redhat.com | 4896636 | 2009-09-11 17:29:28 +0200 | [diff] [blame] | 361 | out_put: |
| 362 | trace_parser_put(&parser); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 363 | |
| 364 | return ret; |
| 365 | } |
| 366 | |
| 367 | static void * |
| 368 | t_next(struct seq_file *m, void *v, loff_t *pos) |
| 369 | { |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 370 | struct ftrace_event_call *call = v; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 371 | |
| 372 | (*pos)++; |
| 373 | |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 374 | list_for_each_entry_continue(call, &ftrace_events, list) { |
Steven Rostedt | 40e2681 | 2009-03-10 11:32:40 -0400 | [diff] [blame] | 375 | /* |
| 376 | * The ftrace subsystem is for showing formats only. |
| 377 | * They can not be enabled or disabled via the event files. |
| 378 | */ |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 379 | if (call->class && call->class->reg) |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 380 | return call; |
Steven Rostedt | 40e2681 | 2009-03-10 11:32:40 -0400 | [diff] [blame] | 381 | } |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 382 | |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 383 | return NULL; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 384 | } |
| 385 | |
| 386 | static void *t_start(struct seq_file *m, loff_t *pos) |
| 387 | { |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 388 | struct ftrace_event_call *call; |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 389 | loff_t l; |
| 390 | |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 391 | mutex_lock(&event_mutex); |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 392 | |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 393 | call = list_entry(&ftrace_events, struct ftrace_event_call, list); |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 394 | for (l = 0; l <= *pos; ) { |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 395 | call = t_next(m, call, &l); |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 396 | if (!call) |
| 397 | break; |
| 398 | } |
| 399 | return call; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | static void * |
| 403 | s_next(struct seq_file *m, void *v, loff_t *pos) |
| 404 | { |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 405 | struct ftrace_event_call *call = v; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 406 | |
| 407 | (*pos)++; |
| 408 | |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 409 | list_for_each_entry_continue(call, &ftrace_events, list) { |
Steven Rostedt | 553552c | 2010-04-23 11:12:36 -0400 | [diff] [blame] | 410 | if (call->flags & TRACE_EVENT_FL_ENABLED) |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 411 | return call; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 412 | } |
| 413 | |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 414 | return NULL; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 415 | } |
| 416 | |
| 417 | static void *s_start(struct seq_file *m, loff_t *pos) |
| 418 | { |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 419 | struct ftrace_event_call *call; |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 420 | loff_t l; |
| 421 | |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 422 | mutex_lock(&event_mutex); |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 423 | |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 424 | call = list_entry(&ftrace_events, struct ftrace_event_call, list); |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 425 | for (l = 0; l <= *pos; ) { |
Li Zefan | 30bd39c | 2009-09-18 14:07:05 +0800 | [diff] [blame] | 426 | call = s_next(m, call, &l); |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 427 | if (!call) |
| 428 | break; |
| 429 | } |
| 430 | return call; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | static int t_show(struct seq_file *m, void *v) |
| 434 | { |
| 435 | struct ftrace_event_call *call = v; |
| 436 | |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 437 | if (strcmp(call->class->system, TRACE_SYSTEM) != 0) |
| 438 | seq_printf(m, "%s:", call->class->system); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 439 | seq_printf(m, "%s\n", call->name); |
| 440 | |
| 441 | return 0; |
| 442 | } |
| 443 | |
| 444 | static void t_stop(struct seq_file *m, void *p) |
| 445 | { |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 446 | mutex_unlock(&event_mutex); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | static int |
| 450 | ftrace_event_seq_open(struct inode *inode, struct file *file) |
| 451 | { |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 452 | const struct seq_operations *seq_ops; |
| 453 | |
| 454 | if ((file->f_mode & FMODE_WRITE) && |
Steven Rostedt | 8650ae3 | 2009-07-22 23:29:30 -0400 | [diff] [blame] | 455 | (file->f_flags & O_TRUNC)) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 456 | ftrace_clear_events(); |
| 457 | |
| 458 | seq_ops = inode->i_private; |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 459 | return seq_open(file, seq_ops); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 460 | } |
| 461 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 462 | static ssize_t |
| 463 | event_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 Rostedt | 553552c | 2010-04-23 11:12:36 -0400 | [diff] [blame] | 469 | if (call->flags & TRACE_EVENT_FL_ENABLED) |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 470 | buf = "1\n"; |
| 471 | else |
| 472 | buf = "0\n"; |
| 473 | |
| 474 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 475 | } |
| 476 | |
| 477 | static ssize_t |
| 478 | event_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 Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 498 | ret = tracing_update_buffers(); |
| 499 | if (ret < 0) |
| 500 | return ret; |
| 501 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 502 | switch (val) { |
| 503 | case 0: |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 504 | case 1: |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 505 | mutex_lock(&event_mutex); |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 506 | ret = ftrace_event_enable_disable(call, val); |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 507 | mutex_unlock(&event_mutex); |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 508 | break; |
| 509 | |
| 510 | default: |
| 511 | return -EINVAL; |
| 512 | } |
| 513 | |
| 514 | *ppos += cnt; |
| 515 | |
Li Zefan | 3b8e427 | 2009-12-08 11:14:52 +0800 | [diff] [blame] | 516 | return ret ? ret : cnt; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 517 | } |
| 518 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 519 | static ssize_t |
| 520 | system_enable_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 521 | loff_t *ppos) |
| 522 | { |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 523 | const char set_to_char[4] = { '?', '0', '1', 'X' }; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 524 | const char *system = filp->private_data; |
| 525 | struct ftrace_event_call *call; |
| 526 | char buf[2]; |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 527 | int set = 0; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 528 | int ret; |
| 529 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 530 | mutex_lock(&event_mutex); |
| 531 | list_for_each_entry(call, &ftrace_events, list) { |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 532 | if (!call->name || !call->class || !call->class->reg) |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 533 | continue; |
| 534 | |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 535 | if (system && strcmp(call->class->system, system) != 0) |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 536 | 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 Rostedt | 553552c | 2010-04-23 11:12:36 -0400 | [diff] [blame] | 543 | set |= (1 << !!(call->flags & TRACE_EVENT_FL_ENABLED)); |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 544 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 545 | /* |
| 546 | * If we have a mixture, no need to look further. |
| 547 | */ |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 548 | if (set == 3) |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 549 | break; |
| 550 | } |
| 551 | mutex_unlock(&event_mutex); |
| 552 | |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 553 | buf[0] = set_to_char[set]; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 554 | buf[1] = '\n'; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 555 | |
| 556 | ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 557 | |
| 558 | return ret; |
| 559 | } |
| 560 | |
| 561 | static ssize_t |
| 562 | system_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 Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 567 | 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 Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 586 | if (val != 0 && val != 1) |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 587 | return -EINVAL; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 588 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 589 | ret = __ftrace_set_clr_event(NULL, system, NULL, val); |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 590 | if (ret) |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 591 | goto out; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 592 | |
| 593 | ret = cnt; |
| 594 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 595 | out: |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 596 | *ppos += cnt; |
| 597 | |
| 598 | return ret; |
| 599 | } |
| 600 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 601 | enum { |
| 602 | FORMAT_HEADER = 1, |
Li Zefan | 86397dc | 2010-08-17 13:53:06 +0800 | [diff] [blame^] | 603 | FORMAT_FIELD_SEPERATOR = 2, |
| 604 | FORMAT_PRINTFMT = 3, |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 605 | }; |
| 606 | |
| 607 | static void *f_next(struct seq_file *m, void *v, loff_t *pos) |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 608 | { |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 609 | struct ftrace_event_call *call = m->private; |
Lai Jiangshan | 5a65e95 | 2009-12-15 15:39:53 +0800 | [diff] [blame] | 610 | struct ftrace_event_field *field; |
Li Zefan | 86397dc | 2010-08-17 13:53:06 +0800 | [diff] [blame^] | 611 | struct list_head *common_head = &ftrace_common_fields; |
| 612 | struct list_head *head = trace_get_fields(call); |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 613 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 614 | (*pos)++; |
Lai Jiangshan | 5a65e95 | 2009-12-15 15:39:53 +0800 | [diff] [blame] | 615 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 616 | switch ((unsigned long)v) { |
| 617 | case FORMAT_HEADER: |
Li Zefan | 86397dc | 2010-08-17 13:53:06 +0800 | [diff] [blame^] | 618 | if (unlikely(list_empty(common_head))) |
| 619 | return NULL; |
Lai Jiangshan | 5a65e95 | 2009-12-15 15:39:53 +0800 | [diff] [blame] | 620 | |
Li Zefan | 86397dc | 2010-08-17 13:53:06 +0800 | [diff] [blame^] | 621 | field = list_entry(common_head->prev, |
| 622 | struct ftrace_event_field, link); |
| 623 | return field; |
| 624 | |
| 625 | case FORMAT_FIELD_SEPERATOR: |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 626 | if (unlikely(list_empty(head))) |
| 627 | return NULL; |
Lai Jiangshan | 5a65e95 | 2009-12-15 15:39:53 +0800 | [diff] [blame] | 628 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 629 | field = list_entry(head->prev, struct ftrace_event_field, link); |
| 630 | return field; |
Lai Jiangshan | 5a65e95 | 2009-12-15 15:39:53 +0800 | [diff] [blame] | 631 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 632 | case FORMAT_PRINTFMT: |
| 633 | /* all done */ |
| 634 | return NULL; |
Lai Jiangshan | 5a65e95 | 2009-12-15 15:39:53 +0800 | [diff] [blame] | 635 | } |
| 636 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 637 | field = v; |
Li Zefan | 86397dc | 2010-08-17 13:53:06 +0800 | [diff] [blame^] | 638 | if (field->link.prev == common_head) |
| 639 | return (void *)FORMAT_FIELD_SEPERATOR; |
| 640 | else if (field->link.prev == head) |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 641 | return (void *)FORMAT_PRINTFMT; |
| 642 | |
| 643 | field = list_entry(field->link.prev, struct ftrace_event_field, link); |
| 644 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 645 | return field; |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 646 | } |
Lai Jiangshan | 5a65e95 | 2009-12-15 15:39:53 +0800 | [diff] [blame] | 647 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 648 | static void *f_start(struct seq_file *m, loff_t *pos) |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 649 | { |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 650 | loff_t l = 0; |
| 651 | void *p; |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 652 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 653 | /* Start by showing the header */ |
| 654 | if (!*pos) |
| 655 | return (void *)FORMAT_HEADER; |
| 656 | |
| 657 | p = (void *)FORMAT_HEADER; |
| 658 | do { |
| 659 | p = f_next(m, p, &l); |
| 660 | } while (p && l < *pos); |
| 661 | |
| 662 | return p; |
| 663 | } |
| 664 | |
| 665 | static int f_show(struct seq_file *m, void *v) |
| 666 | { |
| 667 | struct ftrace_event_call *call = m->private; |
| 668 | struct ftrace_event_field *field; |
| 669 | const char *array_descriptor; |
| 670 | |
| 671 | switch ((unsigned long)v) { |
| 672 | case FORMAT_HEADER: |
| 673 | seq_printf(m, "name: %s\n", call->name); |
| 674 | seq_printf(m, "ID: %d\n", call->event.type); |
| 675 | seq_printf(m, "format:\n"); |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 676 | return 0; |
| 677 | |
Li Zefan | 86397dc | 2010-08-17 13:53:06 +0800 | [diff] [blame^] | 678 | case FORMAT_FIELD_SEPERATOR: |
| 679 | seq_putc(m, '\n'); |
| 680 | return 0; |
| 681 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 682 | case FORMAT_PRINTFMT: |
| 683 | seq_printf(m, "\nprint fmt: %s\n", |
| 684 | call->print_fmt); |
| 685 | return 0; |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 686 | } |
| 687 | |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 688 | field = v; |
| 689 | |
| 690 | /* |
| 691 | * Smartly shows the array type(except dynamic array). |
| 692 | * Normal: |
| 693 | * field:TYPE VAR |
| 694 | * If TYPE := TYPE[LEN], it is shown: |
| 695 | * field:TYPE VAR[LEN] |
| 696 | */ |
| 697 | array_descriptor = strchr(field->type, '['); |
| 698 | |
| 699 | if (!strncmp(field->type, "__data_loc", 10)) |
| 700 | array_descriptor = NULL; |
| 701 | |
| 702 | if (!array_descriptor) |
| 703 | seq_printf(m, "\tfield:%s %s;\toffset:%u;\tsize:%u;\tsigned:%d;\n", |
| 704 | field->type, field->name, field->offset, |
| 705 | field->size, !!field->is_signed); |
| 706 | else |
| 707 | seq_printf(m, "\tfield:%.*s %s%s;\toffset:%u;\tsize:%u;\tsigned:%d;\n", |
| 708 | (int)(array_descriptor - field->type), |
| 709 | field->type, field->name, |
| 710 | array_descriptor, field->offset, |
| 711 | field->size, !!field->is_signed); |
| 712 | |
| 713 | return 0; |
| 714 | } |
| 715 | |
| 716 | static void f_stop(struct seq_file *m, void *p) |
| 717 | { |
| 718 | } |
| 719 | |
| 720 | static const struct seq_operations trace_format_seq_ops = { |
| 721 | .start = f_start, |
| 722 | .next = f_next, |
| 723 | .stop = f_stop, |
| 724 | .show = f_show, |
| 725 | }; |
| 726 | |
| 727 | static int trace_format_open(struct inode *inode, struct file *file) |
| 728 | { |
| 729 | struct ftrace_event_call *call = inode->i_private; |
| 730 | struct seq_file *m; |
| 731 | int ret; |
| 732 | |
| 733 | ret = seq_open(file, &trace_format_seq_ops); |
| 734 | if (ret < 0) |
| 735 | return ret; |
| 736 | |
| 737 | m = file->private_data; |
| 738 | m->private = call; |
| 739 | |
| 740 | return 0; |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 741 | } |
| 742 | |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 743 | static ssize_t |
| 744 | event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) |
| 745 | { |
| 746 | struct ftrace_event_call *call = filp->private_data; |
| 747 | struct trace_seq *s; |
| 748 | int r; |
| 749 | |
| 750 | if (*ppos) |
| 751 | return 0; |
| 752 | |
| 753 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 754 | if (!s) |
| 755 | return -ENOMEM; |
| 756 | |
| 757 | trace_seq_init(s); |
Steven Rostedt | 32c0eda | 2010-04-23 10:38:03 -0400 | [diff] [blame] | 758 | trace_seq_printf(s, "%d\n", call->event.type); |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 759 | |
| 760 | r = simple_read_from_buffer(ubuf, cnt, ppos, |
| 761 | s->buffer, s->len); |
| 762 | kfree(s); |
| 763 | return r; |
| 764 | } |
| 765 | |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 766 | static ssize_t |
| 767 | event_filter_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 768 | loff_t *ppos) |
| 769 | { |
| 770 | struct ftrace_event_call *call = filp->private_data; |
| 771 | struct trace_seq *s; |
| 772 | int r; |
| 773 | |
| 774 | if (*ppos) |
| 775 | return 0; |
| 776 | |
| 777 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 778 | if (!s) |
| 779 | return -ENOMEM; |
| 780 | |
| 781 | trace_seq_init(s); |
| 782 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 783 | print_event_filter(call, s); |
Tom Zanussi | 4bda2d5 | 2009-03-24 02:14:31 -0500 | [diff] [blame] | 784 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 785 | |
| 786 | kfree(s); |
| 787 | |
| 788 | return r; |
| 789 | } |
| 790 | |
| 791 | static ssize_t |
| 792 | event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 793 | loff_t *ppos) |
| 794 | { |
| 795 | struct ftrace_event_call *call = filp->private_data; |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 796 | char *buf; |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 797 | int err; |
| 798 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 799 | if (cnt >= PAGE_SIZE) |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 800 | return -EINVAL; |
| 801 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 802 | buf = (char *)__get_free_page(GFP_TEMPORARY); |
| 803 | if (!buf) |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 804 | return -ENOMEM; |
| 805 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 806 | if (copy_from_user(buf, ubuf, cnt)) { |
| 807 | free_page((unsigned long) buf); |
| 808 | return -EFAULT; |
| 809 | } |
| 810 | buf[cnt] = '\0'; |
| 811 | |
| 812 | err = apply_event_filter(call, buf); |
| 813 | free_page((unsigned long) buf); |
| 814 | if (err < 0) |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 815 | return err; |
Tom Zanussi | 0a19e53 | 2009-04-13 03:17:50 -0500 | [diff] [blame] | 816 | |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 817 | *ppos += cnt; |
| 818 | |
| 819 | return cnt; |
| 820 | } |
| 821 | |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 822 | static ssize_t |
| 823 | subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 824 | loff_t *ppos) |
| 825 | { |
| 826 | struct event_subsystem *system = filp->private_data; |
| 827 | struct trace_seq *s; |
| 828 | int r; |
| 829 | |
| 830 | if (*ppos) |
| 831 | return 0; |
| 832 | |
| 833 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 834 | if (!s) |
| 835 | return -ENOMEM; |
| 836 | |
| 837 | trace_seq_init(s); |
| 838 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 839 | print_subsystem_event_filter(system, s); |
Tom Zanussi | 4bda2d5 | 2009-03-24 02:14:31 -0500 | [diff] [blame] | 840 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 841 | |
| 842 | kfree(s); |
| 843 | |
| 844 | return r; |
| 845 | } |
| 846 | |
| 847 | static ssize_t |
| 848 | subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 849 | loff_t *ppos) |
| 850 | { |
| 851 | struct event_subsystem *system = filp->private_data; |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 852 | char *buf; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 853 | int err; |
| 854 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 855 | if (cnt >= PAGE_SIZE) |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 856 | return -EINVAL; |
| 857 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 858 | buf = (char *)__get_free_page(GFP_TEMPORARY); |
| 859 | if (!buf) |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 860 | return -ENOMEM; |
| 861 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 862 | if (copy_from_user(buf, ubuf, cnt)) { |
| 863 | free_page((unsigned long) buf); |
| 864 | return -EFAULT; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 865 | } |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 866 | buf[cnt] = '\0'; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 867 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 868 | err = apply_subsystem_event_filter(system, buf); |
| 869 | free_page((unsigned long) buf); |
| 870 | if (err < 0) |
Li Zefan | 44e9c8b | 2009-04-11 15:55:28 +0800 | [diff] [blame] | 871 | return err; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 872 | |
| 873 | *ppos += cnt; |
| 874 | |
| 875 | return cnt; |
| 876 | } |
| 877 | |
Steven Rostedt | d1b182a | 2009-04-15 16:53:47 -0400 | [diff] [blame] | 878 | static ssize_t |
| 879 | show_header(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) |
| 880 | { |
| 881 | int (*func)(struct trace_seq *s) = filp->private_data; |
| 882 | struct trace_seq *s; |
| 883 | int r; |
| 884 | |
| 885 | if (*ppos) |
| 886 | return 0; |
| 887 | |
| 888 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 889 | if (!s) |
| 890 | return -ENOMEM; |
| 891 | |
| 892 | trace_seq_init(s); |
| 893 | |
| 894 | func(s); |
| 895 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); |
| 896 | |
| 897 | kfree(s); |
| 898 | |
| 899 | return r; |
| 900 | } |
| 901 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 902 | static const struct seq_operations show_event_seq_ops = { |
| 903 | .start = t_start, |
| 904 | .next = t_next, |
| 905 | .show = t_show, |
| 906 | .stop = t_stop, |
| 907 | }; |
| 908 | |
| 909 | static const struct seq_operations show_set_event_seq_ops = { |
| 910 | .start = s_start, |
| 911 | .next = s_next, |
| 912 | .show = t_show, |
| 913 | .stop = t_stop, |
| 914 | }; |
| 915 | |
Steven Rostedt | 2314c4a | 2009-03-10 12:04:02 -0400 | [diff] [blame] | 916 | static const struct file_operations ftrace_avail_fops = { |
| 917 | .open = ftrace_event_seq_open, |
| 918 | .read = seq_read, |
| 919 | .llseek = seq_lseek, |
| 920 | .release = seq_release, |
| 921 | }; |
| 922 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 923 | static const struct file_operations ftrace_set_event_fops = { |
| 924 | .open = ftrace_event_seq_open, |
| 925 | .read = seq_read, |
| 926 | .write = ftrace_event_write, |
| 927 | .llseek = seq_lseek, |
| 928 | .release = seq_release, |
| 929 | }; |
| 930 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 931 | static const struct file_operations ftrace_enable_fops = { |
| 932 | .open = tracing_open_generic, |
| 933 | .read = event_enable_read, |
| 934 | .write = event_enable_write, |
| 935 | }; |
| 936 | |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 937 | static const struct file_operations ftrace_event_format_fops = { |
Steven Rostedt | 2a37a3d | 2010-06-03 15:21:34 -0400 | [diff] [blame] | 938 | .open = trace_format_open, |
| 939 | .read = seq_read, |
| 940 | .llseek = seq_lseek, |
| 941 | .release = seq_release, |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 942 | }; |
| 943 | |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 944 | static const struct file_operations ftrace_event_id_fops = { |
| 945 | .open = tracing_open_generic, |
| 946 | .read = event_id_read, |
| 947 | }; |
| 948 | |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 949 | static const struct file_operations ftrace_event_filter_fops = { |
| 950 | .open = tracing_open_generic, |
| 951 | .read = event_filter_read, |
| 952 | .write = event_filter_write, |
| 953 | }; |
| 954 | |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 955 | static const struct file_operations ftrace_subsystem_filter_fops = { |
| 956 | .open = tracing_open_generic, |
| 957 | .read = subsystem_filter_read, |
| 958 | .write = subsystem_filter_write, |
| 959 | }; |
| 960 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 961 | static const struct file_operations ftrace_system_enable_fops = { |
| 962 | .open = tracing_open_generic, |
| 963 | .read = system_enable_read, |
| 964 | .write = system_enable_write, |
| 965 | }; |
| 966 | |
Steven Rostedt | d1b182a | 2009-04-15 16:53:47 -0400 | [diff] [blame] | 967 | static const struct file_operations ftrace_show_header_fops = { |
| 968 | .open = tracing_open_generic, |
| 969 | .read = show_header, |
| 970 | }; |
| 971 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 972 | static struct dentry *event_trace_events_dir(void) |
| 973 | { |
| 974 | static struct dentry *d_tracer; |
| 975 | static struct dentry *d_events; |
| 976 | |
| 977 | if (d_events) |
| 978 | return d_events; |
| 979 | |
| 980 | d_tracer = tracing_init_dentry(); |
| 981 | if (!d_tracer) |
| 982 | return NULL; |
| 983 | |
| 984 | d_events = debugfs_create_dir("events", d_tracer); |
| 985 | if (!d_events) |
| 986 | pr_warning("Could not create debugfs " |
| 987 | "'events' directory\n"); |
| 988 | |
| 989 | return d_events; |
| 990 | } |
| 991 | |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 992 | static LIST_HEAD(event_subsystems); |
| 993 | |
| 994 | static struct dentry * |
| 995 | event_subsystem_dir(const char *name, struct dentry *d_events) |
| 996 | { |
| 997 | struct event_subsystem *system; |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 998 | struct dentry *entry; |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 999 | |
| 1000 | /* First see if we did not already create this dir */ |
| 1001 | list_for_each_entry(system, &event_subsystems, list) { |
Xiao Guangrong | dc82ec98a | 2009-07-09 16:22:22 +0800 | [diff] [blame] | 1002 | if (strcmp(system->name, name) == 0) { |
| 1003 | system->nr_events++; |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 1004 | return system->entry; |
Xiao Guangrong | dc82ec98a | 2009-07-09 16:22:22 +0800 | [diff] [blame] | 1005 | } |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | /* need to create new entry */ |
| 1009 | system = kmalloc(sizeof(*system), GFP_KERNEL); |
| 1010 | if (!system) { |
| 1011 | pr_warning("No memory to create event subsystem %s\n", |
| 1012 | name); |
| 1013 | return d_events; |
| 1014 | } |
| 1015 | |
| 1016 | system->entry = debugfs_create_dir(name, d_events); |
| 1017 | if (!system->entry) { |
| 1018 | pr_warning("Could not create event subsystem %s\n", |
| 1019 | name); |
| 1020 | kfree(system); |
| 1021 | return d_events; |
| 1022 | } |
| 1023 | |
Xiao Guangrong | dc82ec98a | 2009-07-09 16:22:22 +0800 | [diff] [blame] | 1024 | system->nr_events = 1; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1025 | system->name = kstrdup(name, GFP_KERNEL); |
| 1026 | if (!system->name) { |
| 1027 | debugfs_remove(system->entry); |
| 1028 | kfree(system); |
| 1029 | return d_events; |
| 1030 | } |
| 1031 | |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 1032 | list_add(&system->list, &event_subsystems); |
| 1033 | |
Tom Zanussi | 30e673b | 2009-04-28 03:04:47 -0500 | [diff] [blame] | 1034 | system->filter = NULL; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 1035 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1036 | system->filter = kzalloc(sizeof(struct event_filter), GFP_KERNEL); |
| 1037 | if (!system->filter) { |
| 1038 | pr_warning("Could not allocate filter for subsystem " |
| 1039 | "'%s'\n", name); |
| 1040 | return system->entry; |
| 1041 | } |
| 1042 | |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1043 | entry = debugfs_create_file("filter", 0644, system->entry, system, |
| 1044 | &ftrace_subsystem_filter_fops); |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1045 | if (!entry) { |
| 1046 | kfree(system->filter); |
| 1047 | system->filter = NULL; |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1048 | pr_warning("Could not create debugfs " |
| 1049 | "'%s/filter' entry\n", name); |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 1050 | } |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 1051 | |
Frederic Weisbecker | f3f3f00 | 2009-09-24 15:27:41 +0200 | [diff] [blame] | 1052 | trace_create_file("enable", 0644, system->entry, |
| 1053 | (void *)system->name, |
| 1054 | &ftrace_system_enable_fops); |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1055 | |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 1056 | return system->entry; |
| 1057 | } |
| 1058 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1059 | static int |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1060 | event_create_dir(struct ftrace_event_call *call, struct dentry *d_events, |
| 1061 | const struct file_operations *id, |
| 1062 | const struct file_operations *enable, |
| 1063 | const struct file_operations *filter, |
| 1064 | const struct file_operations *format) |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1065 | { |
Steven Rostedt | 2e33af0 | 2010-04-22 10:35:55 -0400 | [diff] [blame] | 1066 | struct list_head *head; |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 1067 | int ret; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1068 | |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 1069 | /* |
| 1070 | * If the trace point header did not define TRACE_SYSTEM |
| 1071 | * then the system would be called "TRACE_SYSTEM". |
| 1072 | */ |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 1073 | if (strcmp(call->class->system, TRACE_SYSTEM) != 0) |
| 1074 | d_events = event_subsystem_dir(call->class->system, d_events); |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 1075 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1076 | call->dir = debugfs_create_dir(call->name, d_events); |
| 1077 | if (!call->dir) { |
| 1078 | pr_warning("Could not create debugfs " |
| 1079 | "'%s' directory\n", call->name); |
| 1080 | return -1; |
| 1081 | } |
| 1082 | |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 1083 | if (call->class->reg) |
Frederic Weisbecker | f3f3f00 | 2009-09-24 15:27:41 +0200 | [diff] [blame] | 1084 | trace_create_file("enable", 0644, call->dir, call, |
| 1085 | enable); |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1086 | |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 1087 | #ifdef CONFIG_PERF_EVENTS |
Steven Rostedt | a1d0ce8 | 2010-06-08 11:22:06 -0400 | [diff] [blame] | 1088 | if (call->event.type && call->class->reg) |
Frederic Weisbecker | f3f3f00 | 2009-09-24 15:27:41 +0200 | [diff] [blame] | 1089 | trace_create_file("id", 0444, call->dir, call, |
| 1090 | id); |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 1091 | #endif |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 1092 | |
Li Zefan | c9d932c | 2010-05-24 16:24:28 +0800 | [diff] [blame] | 1093 | /* |
| 1094 | * Other events may have the same class. Only update |
| 1095 | * the fields if they are not already defined. |
| 1096 | */ |
| 1097 | head = trace_get_fields(call); |
| 1098 | if (list_empty(head)) { |
| 1099 | ret = call->class->define_fields(call); |
| 1100 | if (ret < 0) { |
| 1101 | pr_warning("Could not initialize trace point" |
| 1102 | " events/%s\n", call->name); |
| 1103 | return ret; |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 1104 | } |
| 1105 | } |
Li Zefan | c9d932c | 2010-05-24 16:24:28 +0800 | [diff] [blame] | 1106 | trace_create_file("filter", 0644, call->dir, call, |
| 1107 | filter); |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 1108 | |
Frederic Weisbecker | f3f3f00 | 2009-09-24 15:27:41 +0200 | [diff] [blame] | 1109 | trace_create_file("format", 0444, call->dir, call, |
| 1110 | format); |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 1111 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1112 | return 0; |
| 1113 | } |
| 1114 | |
Li Zefan | 67ead0a | 2010-05-24 16:25:13 +0800 | [diff] [blame] | 1115 | static int |
| 1116 | __trace_add_event_call(struct ftrace_event_call *call, struct module *mod, |
| 1117 | const struct file_operations *id, |
| 1118 | const struct file_operations *enable, |
| 1119 | const struct file_operations *filter, |
| 1120 | const struct file_operations *format) |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1121 | { |
| 1122 | struct dentry *d_events; |
| 1123 | int ret; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1124 | |
Li Zefan | 67ead0a | 2010-05-24 16:25:13 +0800 | [diff] [blame] | 1125 | /* The linker may leave blanks */ |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1126 | if (!call->name) |
| 1127 | return -EINVAL; |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1128 | |
Steven Rostedt | 0405ab8 | 2010-04-22 11:46:44 -0400 | [diff] [blame] | 1129 | if (call->class->raw_init) { |
| 1130 | ret = call->class->raw_init(call); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1131 | if (ret < 0) { |
| 1132 | if (ret != -ENOSYS) |
Li Zefan | 67ead0a | 2010-05-24 16:25:13 +0800 | [diff] [blame] | 1133 | pr_warning("Could not initialize trace events/%s\n", |
| 1134 | call->name); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1135 | return ret; |
| 1136 | } |
| 1137 | } |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1138 | |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1139 | d_events = event_trace_events_dir(); |
| 1140 | if (!d_events) |
| 1141 | return -ENOENT; |
| 1142 | |
Li Zefan | 67ead0a | 2010-05-24 16:25:13 +0800 | [diff] [blame] | 1143 | ret = event_create_dir(call, d_events, id, enable, filter, format); |
Masami Hiramatsu | 88f70d7 | 2009-09-25 11:20:54 -0700 | [diff] [blame] | 1144 | if (!ret) |
| 1145 | list_add(&call->list, &ftrace_events); |
Li Zefan | 67ead0a | 2010-05-24 16:25:13 +0800 | [diff] [blame] | 1146 | call->mod = mod; |
Masami Hiramatsu | 88f70d7 | 2009-09-25 11:20:54 -0700 | [diff] [blame] | 1147 | |
Masami Hiramatsu | 588bebb | 2009-09-16 11:42:55 -0400 | [diff] [blame] | 1148 | return ret; |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1149 | } |
| 1150 | |
| 1151 | /* Add an additional event_call dynamically */ |
| 1152 | int trace_add_event_call(struct ftrace_event_call *call) |
| 1153 | { |
| 1154 | int ret; |
| 1155 | mutex_lock(&event_mutex); |
Li Zefan | 67ead0a | 2010-05-24 16:25:13 +0800 | [diff] [blame] | 1156 | ret = __trace_add_event_call(call, NULL, &ftrace_event_id_fops, |
| 1157 | &ftrace_enable_fops, |
| 1158 | &ftrace_event_filter_fops, |
| 1159 | &ftrace_event_format_fops); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1160 | mutex_unlock(&event_mutex); |
| 1161 | return ret; |
| 1162 | } |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1163 | |
Frederic Weisbecker | a2ca5e0 | 2009-08-06 07:32:21 +0200 | [diff] [blame] | 1164 | static void remove_subsystem_dir(const char *name) |
| 1165 | { |
| 1166 | struct event_subsystem *system; |
| 1167 | |
| 1168 | if (strcmp(name, TRACE_SYSTEM) == 0) |
| 1169 | return; |
| 1170 | |
| 1171 | list_for_each_entry(system, &event_subsystems, list) { |
| 1172 | if (strcmp(system->name, name) == 0) { |
| 1173 | if (!--system->nr_events) { |
| 1174 | struct event_filter *filter = system->filter; |
| 1175 | |
| 1176 | debugfs_remove_recursive(system->entry); |
| 1177 | list_del(&system->list); |
| 1178 | if (filter) { |
| 1179 | kfree(filter->filter_string); |
| 1180 | kfree(filter); |
| 1181 | } |
| 1182 | kfree(system->name); |
| 1183 | kfree(system); |
| 1184 | } |
| 1185 | break; |
| 1186 | } |
| 1187 | } |
| 1188 | } |
| 1189 | |
Masami Hiramatsu | 4fead8e | 2009-09-14 16:49:12 -0400 | [diff] [blame] | 1190 | /* |
| 1191 | * Must be called under locking both of event_mutex and trace_event_mutex. |
| 1192 | */ |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1193 | static void __trace_remove_event_call(struct ftrace_event_call *call) |
| 1194 | { |
| 1195 | ftrace_event_enable_disable(call, 0); |
Steven Rostedt | 80decc7 | 2010-04-23 10:00:22 -0400 | [diff] [blame] | 1196 | if (call->event.funcs) |
| 1197 | __unregister_ftrace_event(&call->event); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1198 | debugfs_remove_recursive(call->dir); |
| 1199 | list_del(&call->list); |
| 1200 | trace_destroy_fields(call); |
| 1201 | destroy_preds(call); |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 1202 | remove_subsystem_dir(call->class->system); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1203 | } |
| 1204 | |
| 1205 | /* Remove an event_call */ |
| 1206 | void trace_remove_event_call(struct ftrace_event_call *call) |
| 1207 | { |
| 1208 | mutex_lock(&event_mutex); |
Masami Hiramatsu | 4fead8e | 2009-09-14 16:49:12 -0400 | [diff] [blame] | 1209 | down_write(&trace_event_mutex); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1210 | __trace_remove_event_call(call); |
Masami Hiramatsu | 4fead8e | 2009-09-14 16:49:12 -0400 | [diff] [blame] | 1211 | up_write(&trace_event_mutex); |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1212 | mutex_unlock(&event_mutex); |
| 1213 | } |
| 1214 | |
| 1215 | #define for_each_event(event, start, end) \ |
| 1216 | for (event = start; \ |
| 1217 | (unsigned long)event < (unsigned long)end; \ |
| 1218 | event++) |
| 1219 | |
| 1220 | #ifdef CONFIG_MODULES |
| 1221 | |
| 1222 | static LIST_HEAD(ftrace_module_file_list); |
| 1223 | |
| 1224 | /* |
| 1225 | * Modules must own their file_operations to keep up with |
| 1226 | * reference counting. |
| 1227 | */ |
| 1228 | struct ftrace_module_file_ops { |
| 1229 | struct list_head list; |
| 1230 | struct module *mod; |
| 1231 | struct file_operations id; |
| 1232 | struct file_operations enable; |
| 1233 | struct file_operations format; |
| 1234 | struct file_operations filter; |
| 1235 | }; |
| 1236 | |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1237 | static struct ftrace_module_file_ops * |
| 1238 | trace_create_file_ops(struct module *mod) |
| 1239 | { |
| 1240 | struct ftrace_module_file_ops *file_ops; |
| 1241 | |
| 1242 | /* |
| 1243 | * This is a bit of a PITA. To allow for correct reference |
| 1244 | * counting, modules must "own" their file_operations. |
| 1245 | * To do this, we allocate the file operations that will be |
| 1246 | * used in the event directory. |
| 1247 | */ |
| 1248 | |
| 1249 | file_ops = kmalloc(sizeof(*file_ops), GFP_KERNEL); |
| 1250 | if (!file_ops) |
| 1251 | return NULL; |
| 1252 | |
| 1253 | file_ops->mod = mod; |
| 1254 | |
| 1255 | file_ops->id = ftrace_event_id_fops; |
| 1256 | file_ops->id.owner = mod; |
| 1257 | |
| 1258 | file_ops->enable = ftrace_enable_fops; |
| 1259 | file_ops->enable.owner = mod; |
| 1260 | |
| 1261 | file_ops->filter = ftrace_event_filter_fops; |
| 1262 | file_ops->filter.owner = mod; |
| 1263 | |
| 1264 | file_ops->format = ftrace_event_format_fops; |
| 1265 | file_ops->format.owner = mod; |
| 1266 | |
| 1267 | list_add(&file_ops->list, &ftrace_module_file_list); |
| 1268 | |
| 1269 | return file_ops; |
| 1270 | } |
| 1271 | |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1272 | static void trace_module_add_events(struct module *mod) |
| 1273 | { |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1274 | struct ftrace_module_file_ops *file_ops = NULL; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1275 | struct ftrace_event_call *call, *start, *end; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1276 | |
| 1277 | start = mod->trace_events; |
| 1278 | end = mod->trace_events + mod->num_trace_events; |
| 1279 | |
| 1280 | if (start == end) |
| 1281 | return; |
| 1282 | |
Li Zefan | 67ead0a | 2010-05-24 16:25:13 +0800 | [diff] [blame] | 1283 | file_ops = trace_create_file_ops(mod); |
| 1284 | if (!file_ops) |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1285 | return; |
| 1286 | |
| 1287 | for_each_event(call, start, end) { |
Li Zefan | 67ead0a | 2010-05-24 16:25:13 +0800 | [diff] [blame] | 1288 | __trace_add_event_call(call, mod, |
Masami Hiramatsu | 88f70d7 | 2009-09-25 11:20:54 -0700 | [diff] [blame] | 1289 | &file_ops->id, &file_ops->enable, |
| 1290 | &file_ops->filter, &file_ops->format); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1291 | } |
| 1292 | } |
| 1293 | |
| 1294 | static void trace_module_remove_events(struct module *mod) |
| 1295 | { |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1296 | struct ftrace_module_file_ops *file_ops; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1297 | struct ftrace_event_call *call, *p; |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1298 | bool found = false; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1299 | |
Steven Rostedt | 110bf2b | 2009-06-09 17:29:07 -0400 | [diff] [blame] | 1300 | down_write(&trace_event_mutex); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1301 | list_for_each_entry_safe(call, p, &ftrace_events, list) { |
| 1302 | if (call->mod == mod) { |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1303 | found = true; |
Masami Hiramatsu | bd1a5c8 | 2009-08-13 16:34:53 -0400 | [diff] [blame] | 1304 | __trace_remove_event_call(call); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1305 | } |
| 1306 | } |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1307 | |
| 1308 | /* Now free the file_operations */ |
| 1309 | list_for_each_entry(file_ops, &ftrace_module_file_list, list) { |
| 1310 | if (file_ops->mod == mod) |
| 1311 | break; |
| 1312 | } |
| 1313 | if (&file_ops->list != &ftrace_module_file_list) { |
| 1314 | list_del(&file_ops->list); |
| 1315 | kfree(file_ops); |
| 1316 | } |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1317 | |
| 1318 | /* |
| 1319 | * It is safest to reset the ring buffer if the module being unloaded |
| 1320 | * registered any events. |
| 1321 | */ |
| 1322 | if (found) |
| 1323 | tracing_reset_current_online_cpus(); |
Steven Rostedt | 110bf2b | 2009-06-09 17:29:07 -0400 | [diff] [blame] | 1324 | up_write(&trace_event_mutex); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1325 | } |
| 1326 | |
Steven Rostedt | 61f919a | 2009-04-14 18:22:32 -0400 | [diff] [blame] | 1327 | static int trace_module_notify(struct notifier_block *self, |
| 1328 | unsigned long val, void *data) |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1329 | { |
| 1330 | struct module *mod = data; |
| 1331 | |
| 1332 | mutex_lock(&event_mutex); |
| 1333 | switch (val) { |
| 1334 | case MODULE_STATE_COMING: |
| 1335 | trace_module_add_events(mod); |
| 1336 | break; |
| 1337 | case MODULE_STATE_GOING: |
| 1338 | trace_module_remove_events(mod); |
| 1339 | break; |
| 1340 | } |
| 1341 | mutex_unlock(&event_mutex); |
| 1342 | |
| 1343 | return 0; |
| 1344 | } |
Steven Rostedt | 61f919a | 2009-04-14 18:22:32 -0400 | [diff] [blame] | 1345 | #else |
| 1346 | static int trace_module_notify(struct notifier_block *self, |
| 1347 | unsigned long val, void *data) |
| 1348 | { |
| 1349 | return 0; |
| 1350 | } |
| 1351 | #endif /* CONFIG_MODULES */ |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1352 | |
Steven Rostedt | ec827c7 | 2009-09-14 10:50:23 -0400 | [diff] [blame] | 1353 | static struct notifier_block trace_module_nb = { |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1354 | .notifier_call = trace_module_notify, |
| 1355 | .priority = 0, |
| 1356 | }; |
| 1357 | |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 1358 | extern struct ftrace_event_call __start_ftrace_events[]; |
| 1359 | extern struct ftrace_event_call __stop_ftrace_events[]; |
| 1360 | |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 1361 | static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata; |
| 1362 | |
| 1363 | static __init int setup_trace_event(char *str) |
| 1364 | { |
| 1365 | strlcpy(bootup_event_buf, str, COMMAND_LINE_SIZE); |
| 1366 | ring_buffer_expanded = 1; |
| 1367 | tracing_selftest_disabled = 1; |
| 1368 | |
| 1369 | return 1; |
| 1370 | } |
| 1371 | __setup("trace_event=", setup_trace_event); |
| 1372 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1373 | static __init int event_trace_init(void) |
| 1374 | { |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 1375 | struct ftrace_event_call *call; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1376 | struct dentry *d_tracer; |
| 1377 | struct dentry *entry; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1378 | struct dentry *d_events; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1379 | int ret; |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 1380 | char *buf = bootup_event_buf; |
| 1381 | char *token; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1382 | |
| 1383 | d_tracer = tracing_init_dentry(); |
| 1384 | if (!d_tracer) |
| 1385 | return 0; |
| 1386 | |
Steven Rostedt | 2314c4a | 2009-03-10 12:04:02 -0400 | [diff] [blame] | 1387 | entry = debugfs_create_file("available_events", 0444, d_tracer, |
| 1388 | (void *)&show_event_seq_ops, |
| 1389 | &ftrace_avail_fops); |
| 1390 | if (!entry) |
| 1391 | pr_warning("Could not create debugfs " |
| 1392 | "'available_events' entry\n"); |
| 1393 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1394 | entry = debugfs_create_file("set_event", 0644, d_tracer, |
| 1395 | (void *)&show_set_event_seq_ops, |
| 1396 | &ftrace_set_event_fops); |
| 1397 | if (!entry) |
| 1398 | pr_warning("Could not create debugfs " |
| 1399 | "'set_event' entry\n"); |
| 1400 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1401 | d_events = event_trace_events_dir(); |
| 1402 | if (!d_events) |
| 1403 | return 0; |
| 1404 | |
Steven Rostedt | d1b182a | 2009-04-15 16:53:47 -0400 | [diff] [blame] | 1405 | /* ring buffer internal formats */ |
| 1406 | trace_create_file("header_page", 0444, d_events, |
| 1407 | ring_buffer_print_page_header, |
| 1408 | &ftrace_show_header_fops); |
| 1409 | |
| 1410 | trace_create_file("header_event", 0444, d_events, |
| 1411 | ring_buffer_print_entry_header, |
| 1412 | &ftrace_show_header_fops); |
| 1413 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1414 | trace_create_file("enable", 0644, d_events, |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 1415 | NULL, &ftrace_system_enable_fops); |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1416 | |
Li Zefan | 8728fe5 | 2010-05-24 16:22:49 +0800 | [diff] [blame] | 1417 | if (trace_define_common_fields()) |
| 1418 | pr_warning("tracing: Failed to allocate common fields"); |
| 1419 | |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1420 | for_each_event(call, __start_ftrace_events, __stop_ftrace_events) { |
Li Zefan | 67ead0a | 2010-05-24 16:25:13 +0800 | [diff] [blame] | 1421 | __trace_add_event_call(call, NULL, &ftrace_event_id_fops, |
Masami Hiramatsu | 88f70d7 | 2009-09-25 11:20:54 -0700 | [diff] [blame] | 1422 | &ftrace_enable_fops, |
| 1423 | &ftrace_event_filter_fops, |
| 1424 | &ftrace_event_format_fops); |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1425 | } |
| 1426 | |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 1427 | while (true) { |
| 1428 | token = strsep(&buf, ","); |
| 1429 | |
| 1430 | if (!token) |
| 1431 | break; |
| 1432 | if (!*token) |
| 1433 | continue; |
| 1434 | |
| 1435 | ret = ftrace_set_clr_event(token, 1); |
| 1436 | if (ret) |
| 1437 | pr_warning("Failed to enable trace event: %s\n", token); |
| 1438 | } |
| 1439 | |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1440 | ret = register_module_notifier(&trace_module_nb); |
Ming Lei | 5537937 | 2009-05-18 23:04:46 +0800 | [diff] [blame] | 1441 | if (ret) |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1442 | pr_warning("Failed to register trace events module notifier\n"); |
| 1443 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1444 | return 0; |
| 1445 | } |
| 1446 | fs_initcall(event_trace_init); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1447 | |
| 1448 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 1449 | |
| 1450 | static DEFINE_SPINLOCK(test_spinlock); |
| 1451 | static DEFINE_SPINLOCK(test_spinlock_irq); |
| 1452 | static DEFINE_MUTEX(test_mutex); |
| 1453 | |
| 1454 | static __init void test_work(struct work_struct *dummy) |
| 1455 | { |
| 1456 | spin_lock(&test_spinlock); |
| 1457 | spin_lock_irq(&test_spinlock_irq); |
| 1458 | udelay(1); |
| 1459 | spin_unlock_irq(&test_spinlock_irq); |
| 1460 | spin_unlock(&test_spinlock); |
| 1461 | |
| 1462 | mutex_lock(&test_mutex); |
| 1463 | msleep(1); |
| 1464 | mutex_unlock(&test_mutex); |
| 1465 | } |
| 1466 | |
| 1467 | static __init int event_test_thread(void *unused) |
| 1468 | { |
| 1469 | void *test_malloc; |
| 1470 | |
| 1471 | test_malloc = kmalloc(1234, GFP_KERNEL); |
| 1472 | if (!test_malloc) |
| 1473 | pr_info("failed to kmalloc\n"); |
| 1474 | |
| 1475 | schedule_on_each_cpu(test_work); |
| 1476 | |
| 1477 | kfree(test_malloc); |
| 1478 | |
| 1479 | set_current_state(TASK_INTERRUPTIBLE); |
| 1480 | while (!kthread_should_stop()) |
| 1481 | schedule(); |
| 1482 | |
| 1483 | return 0; |
| 1484 | } |
| 1485 | |
| 1486 | /* |
| 1487 | * Do various things that may trigger events. |
| 1488 | */ |
| 1489 | static __init void event_test_stuff(void) |
| 1490 | { |
| 1491 | struct task_struct *test_thread; |
| 1492 | |
| 1493 | test_thread = kthread_run(event_test_thread, NULL, "test-events"); |
| 1494 | msleep(1); |
| 1495 | kthread_stop(test_thread); |
| 1496 | } |
| 1497 | |
| 1498 | /* |
| 1499 | * For every trace event defined, we will test each trace point separately, |
| 1500 | * and then by groups, and finally all trace points. |
| 1501 | */ |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1502 | static __init void event_trace_self_tests(void) |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1503 | { |
| 1504 | struct ftrace_event_call *call; |
| 1505 | struct event_subsystem *system; |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1506 | int ret; |
| 1507 | |
| 1508 | pr_info("Running tests on trace events:\n"); |
| 1509 | |
| 1510 | list_for_each_entry(call, &ftrace_events, list) { |
| 1511 | |
Steven Rostedt | 2239291 | 2010-04-21 12:27:06 -0400 | [diff] [blame] | 1512 | /* Only test those that have a probe */ |
| 1513 | if (!call->class || !call->class->probe) |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1514 | continue; |
| 1515 | |
Steven Rostedt | 1f5a6b4 | 2009-09-14 11:58:24 -0400 | [diff] [blame] | 1516 | /* |
| 1517 | * Testing syscall events here is pretty useless, but |
| 1518 | * we still do it if configured. But this is time consuming. |
| 1519 | * What we really need is a user thread to perform the |
| 1520 | * syscalls as we test. |
| 1521 | */ |
| 1522 | #ifndef CONFIG_EVENT_TRACE_TEST_SYSCALLS |
Steven Rostedt | 8f08201 | 2010-04-20 10:47:33 -0400 | [diff] [blame] | 1523 | if (call->class->system && |
| 1524 | strcmp(call->class->system, "syscalls") == 0) |
Steven Rostedt | 1f5a6b4 | 2009-09-14 11:58:24 -0400 | [diff] [blame] | 1525 | continue; |
| 1526 | #endif |
| 1527 | |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1528 | pr_info("Testing event %s: ", call->name); |
| 1529 | |
| 1530 | /* |
| 1531 | * If an event is already enabled, someone is using |
| 1532 | * it and the self test should not be on. |
| 1533 | */ |
Steven Rostedt | 553552c | 2010-04-23 11:12:36 -0400 | [diff] [blame] | 1534 | if (call->flags & TRACE_EVENT_FL_ENABLED) { |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1535 | pr_warning("Enabled event during self test!\n"); |
| 1536 | WARN_ON_ONCE(1); |
| 1537 | continue; |
| 1538 | } |
| 1539 | |
Zhaolei | 0e907c9 | 2009-05-25 18:13:59 +0800 | [diff] [blame] | 1540 | ftrace_event_enable_disable(call, 1); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1541 | event_test_stuff(); |
Zhaolei | 0e907c9 | 2009-05-25 18:13:59 +0800 | [diff] [blame] | 1542 | ftrace_event_enable_disable(call, 0); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1543 | |
| 1544 | pr_cont("OK\n"); |
| 1545 | } |
| 1546 | |
| 1547 | /* Now test at the sub system level */ |
| 1548 | |
| 1549 | pr_info("Running tests on trace event systems:\n"); |
| 1550 | |
| 1551 | list_for_each_entry(system, &event_subsystems, list) { |
| 1552 | |
| 1553 | /* the ftrace system is special, skip it */ |
| 1554 | if (strcmp(system->name, "ftrace") == 0) |
| 1555 | continue; |
| 1556 | |
| 1557 | pr_info("Testing event system %s: ", system->name); |
| 1558 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 1559 | ret = __ftrace_set_clr_event(NULL, system->name, NULL, 1); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1560 | if (WARN_ON_ONCE(ret)) { |
| 1561 | pr_warning("error enabling system %s\n", |
| 1562 | system->name); |
| 1563 | continue; |
| 1564 | } |
| 1565 | |
| 1566 | event_test_stuff(); |
| 1567 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 1568 | ret = __ftrace_set_clr_event(NULL, system->name, NULL, 0); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1569 | if (WARN_ON_ONCE(ret)) |
| 1570 | pr_warning("error disabling system %s\n", |
| 1571 | system->name); |
| 1572 | |
| 1573 | pr_cont("OK\n"); |
| 1574 | } |
| 1575 | |
| 1576 | /* Test with all events enabled */ |
| 1577 | |
| 1578 | pr_info("Running tests on all trace events:\n"); |
| 1579 | pr_info("Testing all events: "); |
| 1580 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 1581 | ret = __ftrace_set_clr_event(NULL, NULL, NULL, 1); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1582 | if (WARN_ON_ONCE(ret)) { |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1583 | pr_warning("error enabling all events\n"); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1584 | return; |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | event_test_stuff(); |
| 1588 | |
| 1589 | /* reset sysname */ |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 1590 | ret = __ftrace_set_clr_event(NULL, NULL, NULL, 0); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1591 | if (WARN_ON_ONCE(ret)) { |
| 1592 | pr_warning("error disabling all events\n"); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1593 | return; |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1594 | } |
| 1595 | |
| 1596 | pr_cont("OK\n"); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1597 | } |
| 1598 | |
| 1599 | #ifdef CONFIG_FUNCTION_TRACER |
| 1600 | |
Tejun Heo | 245b2e7 | 2009-06-24 15:13:48 +0900 | [diff] [blame] | 1601 | static DEFINE_PER_CPU(atomic_t, ftrace_test_event_disable); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1602 | |
| 1603 | static void |
| 1604 | function_test_events_call(unsigned long ip, unsigned long parent_ip) |
| 1605 | { |
| 1606 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1607 | struct ring_buffer *buffer; |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1608 | struct ftrace_entry *entry; |
| 1609 | unsigned long flags; |
| 1610 | long disabled; |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1611 | int cpu; |
| 1612 | int pc; |
| 1613 | |
| 1614 | pc = preempt_count(); |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 1615 | preempt_disable_notrace(); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1616 | cpu = raw_smp_processor_id(); |
Tejun Heo | 245b2e7 | 2009-06-24 15:13:48 +0900 | [diff] [blame] | 1617 | disabled = atomic_inc_return(&per_cpu(ftrace_test_event_disable, cpu)); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1618 | |
| 1619 | if (disabled != 1) |
| 1620 | goto out; |
| 1621 | |
| 1622 | local_save_flags(flags); |
| 1623 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1624 | event = trace_current_buffer_lock_reserve(&buffer, |
| 1625 | TRACE_FN, sizeof(*entry), |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1626 | flags, pc); |
| 1627 | if (!event) |
| 1628 | goto out; |
| 1629 | entry = ring_buffer_event_data(event); |
| 1630 | entry->ip = ip; |
| 1631 | entry->parent_ip = parent_ip; |
| 1632 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 1633 | trace_nowake_buffer_unlock_commit(buffer, event, flags, pc); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1634 | |
| 1635 | out: |
Tejun Heo | 245b2e7 | 2009-06-24 15:13:48 +0900 | [diff] [blame] | 1636 | atomic_dec(&per_cpu(ftrace_test_event_disable, cpu)); |
Steven Rostedt | 5168ae5 | 2010-06-03 09:36:50 -0400 | [diff] [blame] | 1637 | preempt_enable_notrace(); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | static struct ftrace_ops trace_ops __initdata = |
| 1641 | { |
| 1642 | .func = function_test_events_call, |
| 1643 | }; |
| 1644 | |
| 1645 | static __init void event_trace_self_test_with_function(void) |
| 1646 | { |
| 1647 | register_ftrace_function(&trace_ops); |
| 1648 | pr_info("Running tests again, along with the function tracer\n"); |
| 1649 | event_trace_self_tests(); |
| 1650 | unregister_ftrace_function(&trace_ops); |
| 1651 | } |
| 1652 | #else |
| 1653 | static __init void event_trace_self_test_with_function(void) |
| 1654 | { |
| 1655 | } |
| 1656 | #endif |
| 1657 | |
| 1658 | static __init int event_trace_self_tests_init(void) |
| 1659 | { |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 1660 | if (!tracing_selftest_disabled) { |
| 1661 | event_trace_self_tests(); |
| 1662 | event_trace_self_test_with_function(); |
| 1663 | } |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1664 | |
| 1665 | return 0; |
| 1666 | } |
| 1667 | |
Steven Rostedt | 28d20e2 | 2009-04-20 12:12:44 -0400 | [diff] [blame] | 1668 | late_initcall(event_trace_self_tests_init); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1669 | |
| 1670 | #endif |