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> |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 18 | #include <linux/delay.h> |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 19 | |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 20 | #include <asm/setup.h> |
| 21 | |
Steven Rostedt | 91729ef9 | 2009-03-02 15:03:01 -0500 | [diff] [blame] | 22 | #include "trace_output.h" |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 23 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 24 | #define TRACE_SYSTEM "TRACE_SYSTEM" |
| 25 | |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 26 | DEFINE_MUTEX(event_mutex); |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 27 | |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 28 | LIST_HEAD(ftrace_events); |
| 29 | |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 30 | int trace_define_field(struct ftrace_event_call *call, char *type, |
Tom Zanussi | a118e4d | 2009-04-28 03:04:53 -0500 | [diff] [blame] | 31 | char *name, int offset, int size, int is_signed) |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 32 | { |
| 33 | struct ftrace_event_field *field; |
| 34 | |
Ingo Molnar | fe9f57f | 2009-03-22 18:41:59 +0100 | [diff] [blame] | 35 | field = kzalloc(sizeof(*field), GFP_KERNEL); |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 36 | if (!field) |
| 37 | goto err; |
Ingo Molnar | fe9f57f | 2009-03-22 18:41:59 +0100 | [diff] [blame] | 38 | |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 39 | field->name = kstrdup(name, GFP_KERNEL); |
| 40 | if (!field->name) |
| 41 | goto err; |
Ingo Molnar | fe9f57f | 2009-03-22 18:41:59 +0100 | [diff] [blame] | 42 | |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 43 | field->type = kstrdup(type, GFP_KERNEL); |
| 44 | if (!field->type) |
| 45 | goto err; |
Ingo Molnar | fe9f57f | 2009-03-22 18:41:59 +0100 | [diff] [blame] | 46 | |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 47 | field->offset = offset; |
| 48 | field->size = size; |
Tom Zanussi | a118e4d | 2009-04-28 03:04:53 -0500 | [diff] [blame] | 49 | field->is_signed = is_signed; |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 50 | list_add(&field->link, &call->fields); |
| 51 | |
| 52 | return 0; |
Ingo Molnar | fe9f57f | 2009-03-22 18:41:59 +0100 | [diff] [blame] | 53 | |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 54 | err: |
| 55 | if (field) { |
| 56 | kfree(field->name); |
| 57 | kfree(field->type); |
| 58 | } |
| 59 | kfree(field); |
Ingo Molnar | fe9f57f | 2009-03-22 18:41:59 +0100 | [diff] [blame] | 60 | |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 61 | return -ENOMEM; |
| 62 | } |
Steven Rostedt | 17c873e | 2009-04-10 18:12:50 -0400 | [diff] [blame] | 63 | EXPORT_SYMBOL_GPL(trace_define_field); |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 64 | |
Li Zefan | 2df75e4 | 2009-05-06 10:33:04 +0800 | [diff] [blame] | 65 | #ifdef CONFIG_MODULES |
| 66 | |
| 67 | static void trace_destroy_fields(struct ftrace_event_call *call) |
| 68 | { |
| 69 | struct ftrace_event_field *field, *next; |
| 70 | |
| 71 | list_for_each_entry_safe(field, next, &call->fields, link) { |
| 72 | list_del(&field->link); |
| 73 | kfree(field->type); |
| 74 | kfree(field->name); |
| 75 | kfree(field); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | #endif /* CONFIG_MODULES */ |
| 80 | |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 81 | static void ftrace_event_enable_disable(struct ftrace_event_call *call, |
| 82 | int enable) |
| 83 | { |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 84 | switch (enable) { |
| 85 | case 0: |
| 86 | if (call->enabled) { |
| 87 | call->enabled = 0; |
Zhaolei | b11c53e | 2009-05-25 18:11:59 +0800 | [diff] [blame] | 88 | tracing_stop_cmdline_record(); |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 89 | call->unregfunc(); |
| 90 | } |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 91 | break; |
| 92 | case 1: |
Steven Rostedt | da4d030 | 2009-03-09 17:14:30 -0400 | [diff] [blame] | 93 | if (!call->enabled) { |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 94 | call->enabled = 1; |
Zhaolei | b11c53e | 2009-05-25 18:11:59 +0800 | [diff] [blame] | 95 | tracing_start_cmdline_record(); |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 96 | call->regfunc(); |
| 97 | } |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 98 | break; |
| 99 | } |
| 100 | } |
| 101 | |
Zhaolei | 0e907c9 | 2009-05-25 18:13:59 +0800 | [diff] [blame] | 102 | static void ftrace_clear_events(void) |
| 103 | { |
| 104 | struct ftrace_event_call *call; |
| 105 | |
| 106 | mutex_lock(&event_mutex); |
| 107 | list_for_each_entry(call, &ftrace_events, list) { |
| 108 | ftrace_event_enable_disable(call, 0); |
| 109 | } |
| 110 | mutex_unlock(&event_mutex); |
| 111 | } |
| 112 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 113 | /* |
| 114 | * __ftrace_set_clr_event(NULL, NULL, NULL, set) will set/unset all events. |
| 115 | */ |
| 116 | static int __ftrace_set_clr_event(const char *match, const char *sub, |
| 117 | const char *event, int set) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 118 | { |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 119 | struct ftrace_event_call *call; |
Steven Rostedt | 29f9394 | 2009-05-08 16:06:47 -0400 | [diff] [blame] | 120 | int ret = -EINVAL; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 121 | |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 122 | mutex_lock(&event_mutex); |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 123 | list_for_each_entry(call, &ftrace_events, list) { |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 124 | |
Steven Rostedt | 40e2681 | 2009-03-10 11:32:40 -0400 | [diff] [blame] | 125 | if (!call->name || !call->regfunc) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 126 | continue; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 127 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 128 | if (match && |
| 129 | strcmp(match, call->name) != 0 && |
| 130 | strcmp(match, call->system) != 0) |
| 131 | continue; |
| 132 | |
| 133 | if (sub && strcmp(sub, call->system) != 0) |
| 134 | continue; |
| 135 | |
| 136 | if (event && strcmp(event, call->name) != 0) |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 137 | continue; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 138 | |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 139 | ftrace_event_enable_disable(call, set); |
| 140 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 141 | ret = 0; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 142 | } |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 143 | mutex_unlock(&event_mutex); |
| 144 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 145 | return ret; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 146 | } |
| 147 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 148 | static int ftrace_set_clr_event(char *buf, int set) |
| 149 | { |
| 150 | char *event = NULL, *sub = NULL, *match; |
| 151 | |
| 152 | /* |
| 153 | * The buf format can be <subsystem>:<event-name> |
| 154 | * *:<event-name> means any event by that name. |
| 155 | * :<event-name> is the same. |
| 156 | * |
| 157 | * <subsystem>:* means all events in that subsystem |
| 158 | * <subsystem>: means the same. |
| 159 | * |
| 160 | * <name> (no ':') means all events in a subsystem with |
| 161 | * the name <name> or any event that matches <name> |
| 162 | */ |
| 163 | |
| 164 | match = strsep(&buf, ":"); |
| 165 | if (buf) { |
| 166 | sub = match; |
| 167 | event = buf; |
| 168 | match = NULL; |
| 169 | |
| 170 | if (!strlen(sub) || strcmp(sub, "*") == 0) |
| 171 | sub = NULL; |
| 172 | if (!strlen(event) || strcmp(event, "*") == 0) |
| 173 | event = NULL; |
| 174 | } |
| 175 | |
| 176 | return __ftrace_set_clr_event(match, sub, event, set); |
| 177 | } |
| 178 | |
Steven Rostedt | 4671c79 | 2009-05-08 16:27:41 -0400 | [diff] [blame] | 179 | /** |
| 180 | * trace_set_clr_event - enable or disable an event |
| 181 | * @system: system name to match (NULL for any system) |
| 182 | * @event: event name to match (NULL for all events, within system) |
| 183 | * @set: 1 to enable, 0 to disable |
| 184 | * |
| 185 | * This is a way for other parts of the kernel to enable or disable |
| 186 | * event recording. |
| 187 | * |
| 188 | * Returns 0 on success, -EINVAL if the parameters do not match any |
| 189 | * registered events. |
| 190 | */ |
| 191 | int trace_set_clr_event(const char *system, const char *event, int set) |
| 192 | { |
| 193 | return __ftrace_set_clr_event(NULL, system, event, set); |
| 194 | } |
| 195 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 196 | /* 128 should be much more than enough */ |
| 197 | #define EVENT_BUF_SIZE 127 |
| 198 | |
| 199 | static ssize_t |
| 200 | ftrace_event_write(struct file *file, const char __user *ubuf, |
| 201 | size_t cnt, loff_t *ppos) |
| 202 | { |
| 203 | size_t read = 0; |
| 204 | int i, set = 1; |
| 205 | ssize_t ret; |
| 206 | char *buf; |
| 207 | char ch; |
| 208 | |
| 209 | if (!cnt || cnt < 0) |
| 210 | return 0; |
| 211 | |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 212 | ret = tracing_update_buffers(); |
| 213 | if (ret < 0) |
| 214 | return ret; |
| 215 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 216 | ret = get_user(ch, ubuf++); |
| 217 | if (ret) |
| 218 | return ret; |
| 219 | read++; |
| 220 | cnt--; |
| 221 | |
| 222 | /* skip white space */ |
| 223 | while (cnt && isspace(ch)) { |
| 224 | ret = get_user(ch, ubuf++); |
| 225 | if (ret) |
| 226 | return ret; |
| 227 | read++; |
| 228 | cnt--; |
| 229 | } |
| 230 | |
| 231 | /* Only white space found? */ |
| 232 | if (isspace(ch)) { |
| 233 | file->f_pos += read; |
| 234 | ret = read; |
| 235 | return ret; |
| 236 | } |
| 237 | |
| 238 | buf = kmalloc(EVENT_BUF_SIZE+1, GFP_KERNEL); |
| 239 | if (!buf) |
| 240 | return -ENOMEM; |
| 241 | |
| 242 | if (cnt > EVENT_BUF_SIZE) |
| 243 | cnt = EVENT_BUF_SIZE; |
| 244 | |
| 245 | i = 0; |
| 246 | while (cnt && !isspace(ch)) { |
| 247 | if (!i && ch == '!') |
| 248 | set = 0; |
| 249 | else |
| 250 | buf[i++] = ch; |
| 251 | |
| 252 | ret = get_user(ch, ubuf++); |
| 253 | if (ret) |
| 254 | goto out_free; |
| 255 | read++; |
| 256 | cnt--; |
| 257 | } |
| 258 | buf[i] = 0; |
| 259 | |
| 260 | file->f_pos += read; |
| 261 | |
| 262 | ret = ftrace_set_clr_event(buf, set); |
| 263 | if (ret) |
| 264 | goto out_free; |
| 265 | |
| 266 | ret = read; |
| 267 | |
| 268 | out_free: |
| 269 | kfree(buf); |
| 270 | |
| 271 | return ret; |
| 272 | } |
| 273 | |
| 274 | static void * |
| 275 | t_next(struct seq_file *m, void *v, loff_t *pos) |
| 276 | { |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 277 | struct list_head *list = m->private; |
| 278 | struct ftrace_event_call *call; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 279 | |
| 280 | (*pos)++; |
| 281 | |
Steven Rostedt | 40e2681 | 2009-03-10 11:32:40 -0400 | [diff] [blame] | 282 | for (;;) { |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 283 | if (list == &ftrace_events) |
Steven Rostedt | 40e2681 | 2009-03-10 11:32:40 -0400 | [diff] [blame] | 284 | return NULL; |
| 285 | |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 286 | call = list_entry(list, struct ftrace_event_call, list); |
| 287 | |
Steven Rostedt | 40e2681 | 2009-03-10 11:32:40 -0400 | [diff] [blame] | 288 | /* |
| 289 | * The ftrace subsystem is for showing formats only. |
| 290 | * They can not be enabled or disabled via the event files. |
| 291 | */ |
| 292 | if (call->regfunc) |
| 293 | break; |
| 294 | |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 295 | list = list->next; |
Steven Rostedt | 40e2681 | 2009-03-10 11:32:40 -0400 | [diff] [blame] | 296 | } |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 297 | |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 298 | m->private = list->next; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 299 | |
| 300 | return call; |
| 301 | } |
| 302 | |
| 303 | static void *t_start(struct seq_file *m, loff_t *pos) |
| 304 | { |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 305 | struct ftrace_event_call *call = NULL; |
| 306 | loff_t l; |
| 307 | |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 308 | mutex_lock(&event_mutex); |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 309 | |
| 310 | m->private = ftrace_events.next; |
| 311 | for (l = 0; l <= *pos; ) { |
| 312 | call = t_next(m, NULL, &l); |
| 313 | if (!call) |
| 314 | break; |
| 315 | } |
| 316 | return call; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | static void * |
| 320 | s_next(struct seq_file *m, void *v, loff_t *pos) |
| 321 | { |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 322 | struct list_head *list = m->private; |
| 323 | struct ftrace_event_call *call; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 324 | |
| 325 | (*pos)++; |
| 326 | |
| 327 | retry: |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 328 | if (list == &ftrace_events) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 329 | return NULL; |
| 330 | |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 331 | call = list_entry(list, struct ftrace_event_call, list); |
| 332 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 333 | if (!call->enabled) { |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 334 | list = list->next; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 335 | goto retry; |
| 336 | } |
| 337 | |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 338 | m->private = list->next; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 339 | |
| 340 | return call; |
| 341 | } |
| 342 | |
| 343 | static void *s_start(struct seq_file *m, loff_t *pos) |
| 344 | { |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 345 | struct ftrace_event_call *call = NULL; |
| 346 | loff_t l; |
| 347 | |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 348 | mutex_lock(&event_mutex); |
Li Zefan | e1c7e2a | 2009-06-24 09:52:29 +0800 | [diff] [blame] | 349 | |
| 350 | m->private = ftrace_events.next; |
| 351 | for (l = 0; l <= *pos; ) { |
| 352 | call = s_next(m, NULL, &l); |
| 353 | if (!call) |
| 354 | break; |
| 355 | } |
| 356 | return call; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | static int t_show(struct seq_file *m, void *v) |
| 360 | { |
| 361 | struct ftrace_event_call *call = v; |
| 362 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 363 | if (strcmp(call->system, TRACE_SYSTEM) != 0) |
| 364 | seq_printf(m, "%s:", call->system); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 365 | seq_printf(m, "%s\n", call->name); |
| 366 | |
| 367 | return 0; |
| 368 | } |
| 369 | |
| 370 | static void t_stop(struct seq_file *m, void *p) |
| 371 | { |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 372 | mutex_unlock(&event_mutex); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 373 | } |
| 374 | |
| 375 | static int |
| 376 | ftrace_event_seq_open(struct inode *inode, struct file *file) |
| 377 | { |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 378 | const struct seq_operations *seq_ops; |
| 379 | |
| 380 | if ((file->f_mode & FMODE_WRITE) && |
| 381 | !(file->f_flags & O_APPEND)) |
| 382 | ftrace_clear_events(); |
| 383 | |
| 384 | seq_ops = inode->i_private; |
Li Zefan | 20c8928 | 2009-05-06 10:33:45 +0800 | [diff] [blame] | 385 | return seq_open(file, seq_ops); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 386 | } |
| 387 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 388 | static ssize_t |
| 389 | event_enable_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 390 | loff_t *ppos) |
| 391 | { |
| 392 | struct ftrace_event_call *call = filp->private_data; |
| 393 | char *buf; |
| 394 | |
Steven Rostedt | da4d030 | 2009-03-09 17:14:30 -0400 | [diff] [blame] | 395 | if (call->enabled) |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 396 | buf = "1\n"; |
| 397 | else |
| 398 | buf = "0\n"; |
| 399 | |
| 400 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 401 | } |
| 402 | |
| 403 | static ssize_t |
| 404 | event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 405 | loff_t *ppos) |
| 406 | { |
| 407 | struct ftrace_event_call *call = filp->private_data; |
| 408 | char buf[64]; |
| 409 | unsigned long val; |
| 410 | int ret; |
| 411 | |
| 412 | if (cnt >= sizeof(buf)) |
| 413 | return -EINVAL; |
| 414 | |
| 415 | if (copy_from_user(&buf, ubuf, cnt)) |
| 416 | return -EFAULT; |
| 417 | |
| 418 | buf[cnt] = 0; |
| 419 | |
| 420 | ret = strict_strtoul(buf, 10, &val); |
| 421 | if (ret < 0) |
| 422 | return ret; |
| 423 | |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 424 | ret = tracing_update_buffers(); |
| 425 | if (ret < 0) |
| 426 | return ret; |
| 427 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 428 | switch (val) { |
| 429 | case 0: |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 430 | case 1: |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 431 | mutex_lock(&event_mutex); |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 432 | ftrace_event_enable_disable(call, val); |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 433 | mutex_unlock(&event_mutex); |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 434 | break; |
| 435 | |
| 436 | default: |
| 437 | return -EINVAL; |
| 438 | } |
| 439 | |
| 440 | *ppos += cnt; |
| 441 | |
| 442 | return cnt; |
| 443 | } |
| 444 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 445 | static ssize_t |
| 446 | system_enable_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 447 | loff_t *ppos) |
| 448 | { |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 449 | const char set_to_char[4] = { '?', '0', '1', 'X' }; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 450 | const char *system = filp->private_data; |
| 451 | struct ftrace_event_call *call; |
| 452 | char buf[2]; |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 453 | int set = 0; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 454 | int ret; |
| 455 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 456 | mutex_lock(&event_mutex); |
| 457 | list_for_each_entry(call, &ftrace_events, list) { |
| 458 | if (!call->name || !call->regfunc) |
| 459 | continue; |
| 460 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 461 | if (system && strcmp(call->system, system) != 0) |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 462 | continue; |
| 463 | |
| 464 | /* |
| 465 | * We need to find out if all the events are set |
| 466 | * or if all events or cleared, or if we have |
| 467 | * a mixture. |
| 468 | */ |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 469 | set |= (1 << !!call->enabled); |
| 470 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 471 | /* |
| 472 | * If we have a mixture, no need to look further. |
| 473 | */ |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 474 | if (set == 3) |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 475 | break; |
| 476 | } |
| 477 | mutex_unlock(&event_mutex); |
| 478 | |
Li Zefan | c142b15 | 2009-05-08 10:32:05 +0800 | [diff] [blame] | 479 | buf[0] = set_to_char[set]; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 480 | buf[1] = '\n'; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 481 | |
| 482 | ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 483 | |
| 484 | return ret; |
| 485 | } |
| 486 | |
| 487 | static ssize_t |
| 488 | system_enable_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 489 | loff_t *ppos) |
| 490 | { |
| 491 | const char *system = filp->private_data; |
| 492 | unsigned long val; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 493 | char buf[64]; |
| 494 | ssize_t ret; |
| 495 | |
| 496 | if (cnt >= sizeof(buf)) |
| 497 | return -EINVAL; |
| 498 | |
| 499 | if (copy_from_user(&buf, ubuf, cnt)) |
| 500 | return -EFAULT; |
| 501 | |
| 502 | buf[cnt] = 0; |
| 503 | |
| 504 | ret = strict_strtoul(buf, 10, &val); |
| 505 | if (ret < 0) |
| 506 | return ret; |
| 507 | |
| 508 | ret = tracing_update_buffers(); |
| 509 | if (ret < 0) |
| 510 | return ret; |
| 511 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 512 | if (val != 0 && val != 1) |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 513 | return -EINVAL; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 514 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 515 | ret = __ftrace_set_clr_event(NULL, system, NULL, val); |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 516 | if (ret) |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 517 | goto out; |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 518 | |
| 519 | ret = cnt; |
| 520 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 521 | out: |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 522 | *ppos += cnt; |
| 523 | |
| 524 | return ret; |
| 525 | } |
| 526 | |
Steven Rostedt | 75db37d | 2009-03-26 11:43:36 -0400 | [diff] [blame] | 527 | extern char *__bad_type_size(void); |
| 528 | |
Steven Rostedt | 91729ef9 | 2009-03-02 15:03:01 -0500 | [diff] [blame] | 529 | #undef FIELD |
Steven Rostedt | 156b5f1 | 2009-03-06 10:50:53 -0500 | [diff] [blame] | 530 | #define FIELD(type, name) \ |
Steven Rostedt | 75db37d | 2009-03-26 11:43:36 -0400 | [diff] [blame] | 531 | sizeof(type) != sizeof(field.name) ? __bad_type_size() : \ |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 532 | #type, "common_" #name, offsetof(typeof(field), name), \ |
| 533 | sizeof(field.name) |
Steven Rostedt | 91729ef9 | 2009-03-02 15:03:01 -0500 | [diff] [blame] | 534 | |
| 535 | static int trace_write_header(struct trace_seq *s) |
| 536 | { |
| 537 | struct trace_entry field; |
| 538 | |
| 539 | /* struct trace_entry */ |
| 540 | return trace_seq_printf(s, |
Steven Rostedt | ce8eb2b | 2009-03-10 10:14:35 -0400 | [diff] [blame] | 541 | "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" |
| 542 | "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" |
| 543 | "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" |
| 544 | "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" |
| 545 | "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" |
Steven Rostedt | 91729ef9 | 2009-03-02 15:03:01 -0500 | [diff] [blame] | 546 | "\n", |
Steven Rostedt | 89ec0de | 2009-03-26 11:03:29 -0400 | [diff] [blame] | 547 | FIELD(unsigned short, type), |
Steven Rostedt | 91729ef9 | 2009-03-02 15:03:01 -0500 | [diff] [blame] | 548 | FIELD(unsigned char, flags), |
| 549 | FIELD(unsigned char, preempt_count), |
| 550 | FIELD(int, pid), |
| 551 | FIELD(int, tgid)); |
| 552 | } |
Steven Rostedt | da4d030 | 2009-03-09 17:14:30 -0400 | [diff] [blame] | 553 | |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 554 | static ssize_t |
| 555 | event_format_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 556 | loff_t *ppos) |
| 557 | { |
| 558 | struct ftrace_event_call *call = filp->private_data; |
| 559 | struct trace_seq *s; |
| 560 | char *buf; |
| 561 | int r; |
| 562 | |
Tom Zanussi | c269fc8 | 2009-03-17 01:20:59 -0500 | [diff] [blame] | 563 | if (*ppos) |
| 564 | return 0; |
| 565 | |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 566 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 567 | if (!s) |
| 568 | return -ENOMEM; |
| 569 | |
| 570 | trace_seq_init(s); |
| 571 | |
Steven Rostedt | c5e4e19 | 2009-03-02 15:10:02 -0500 | [diff] [blame] | 572 | /* If any of the first writes fail, so will the show_format. */ |
| 573 | |
| 574 | trace_seq_printf(s, "name: %s\n", call->name); |
| 575 | trace_seq_printf(s, "ID: %d\n", call->id); |
| 576 | trace_seq_printf(s, "format:\n"); |
Steven Rostedt | 91729ef9 | 2009-03-02 15:03:01 -0500 | [diff] [blame] | 577 | trace_write_header(s); |
| 578 | |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 579 | r = call->show_format(s); |
| 580 | if (!r) { |
| 581 | /* |
| 582 | * ug! The format output is bigger than a PAGE!! |
| 583 | */ |
| 584 | buf = "FORMAT TOO BIG\n"; |
| 585 | r = simple_read_from_buffer(ubuf, cnt, ppos, |
| 586 | buf, strlen(buf)); |
| 587 | goto out; |
| 588 | } |
| 589 | |
| 590 | r = simple_read_from_buffer(ubuf, cnt, ppos, |
| 591 | s->buffer, s->len); |
| 592 | out: |
| 593 | kfree(s); |
| 594 | return r; |
| 595 | } |
| 596 | |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 597 | static ssize_t |
| 598 | event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) |
| 599 | { |
| 600 | struct ftrace_event_call *call = filp->private_data; |
| 601 | struct trace_seq *s; |
| 602 | int r; |
| 603 | |
| 604 | if (*ppos) |
| 605 | return 0; |
| 606 | |
| 607 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 608 | if (!s) |
| 609 | return -ENOMEM; |
| 610 | |
| 611 | trace_seq_init(s); |
| 612 | trace_seq_printf(s, "%d\n", call->id); |
| 613 | |
| 614 | r = simple_read_from_buffer(ubuf, cnt, ppos, |
| 615 | s->buffer, s->len); |
| 616 | kfree(s); |
| 617 | return r; |
| 618 | } |
| 619 | |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 620 | static ssize_t |
| 621 | event_filter_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 622 | loff_t *ppos) |
| 623 | { |
| 624 | struct ftrace_event_call *call = filp->private_data; |
| 625 | struct trace_seq *s; |
| 626 | int r; |
| 627 | |
| 628 | if (*ppos) |
| 629 | return 0; |
| 630 | |
| 631 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 632 | if (!s) |
| 633 | return -ENOMEM; |
| 634 | |
| 635 | trace_seq_init(s); |
| 636 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 637 | print_event_filter(call, s); |
Tom Zanussi | 4bda2d5 | 2009-03-24 02:14:31 -0500 | [diff] [blame] | 638 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 639 | |
| 640 | kfree(s); |
| 641 | |
| 642 | return r; |
| 643 | } |
| 644 | |
| 645 | static ssize_t |
| 646 | event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 647 | loff_t *ppos) |
| 648 | { |
| 649 | struct ftrace_event_call *call = filp->private_data; |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 650 | char *buf; |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 651 | int err; |
| 652 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 653 | if (cnt >= PAGE_SIZE) |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 654 | return -EINVAL; |
| 655 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 656 | buf = (char *)__get_free_page(GFP_TEMPORARY); |
| 657 | if (!buf) |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 658 | return -ENOMEM; |
| 659 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 660 | if (copy_from_user(buf, ubuf, cnt)) { |
| 661 | free_page((unsigned long) buf); |
| 662 | return -EFAULT; |
| 663 | } |
| 664 | buf[cnt] = '\0'; |
| 665 | |
| 666 | err = apply_event_filter(call, buf); |
| 667 | free_page((unsigned long) buf); |
| 668 | if (err < 0) |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 669 | return err; |
Tom Zanussi | 0a19e53 | 2009-04-13 03:17:50 -0500 | [diff] [blame] | 670 | |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 671 | *ppos += cnt; |
| 672 | |
| 673 | return cnt; |
| 674 | } |
| 675 | |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 676 | static ssize_t |
| 677 | subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 678 | loff_t *ppos) |
| 679 | { |
| 680 | struct event_subsystem *system = filp->private_data; |
| 681 | struct trace_seq *s; |
| 682 | int r; |
| 683 | |
| 684 | if (*ppos) |
| 685 | return 0; |
| 686 | |
| 687 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 688 | if (!s) |
| 689 | return -ENOMEM; |
| 690 | |
| 691 | trace_seq_init(s); |
| 692 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 693 | print_subsystem_event_filter(system, s); |
Tom Zanussi | 4bda2d5 | 2009-03-24 02:14:31 -0500 | [diff] [blame] | 694 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 695 | |
| 696 | kfree(s); |
| 697 | |
| 698 | return r; |
| 699 | } |
| 700 | |
| 701 | static ssize_t |
| 702 | subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 703 | loff_t *ppos) |
| 704 | { |
| 705 | struct event_subsystem *system = filp->private_data; |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 706 | char *buf; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 707 | int err; |
| 708 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 709 | if (cnt >= PAGE_SIZE) |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 710 | return -EINVAL; |
| 711 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 712 | buf = (char *)__get_free_page(GFP_TEMPORARY); |
| 713 | if (!buf) |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 714 | return -ENOMEM; |
| 715 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 716 | if (copy_from_user(buf, ubuf, cnt)) { |
| 717 | free_page((unsigned long) buf); |
| 718 | return -EFAULT; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 719 | } |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 720 | buf[cnt] = '\0'; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 721 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 722 | err = apply_subsystem_event_filter(system, buf); |
| 723 | free_page((unsigned long) buf); |
| 724 | if (err < 0) |
Li Zefan | 44e9c8b | 2009-04-11 15:55:28 +0800 | [diff] [blame] | 725 | return err; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 726 | |
| 727 | *ppos += cnt; |
| 728 | |
| 729 | return cnt; |
| 730 | } |
| 731 | |
Steven Rostedt | d1b182a | 2009-04-15 16:53:47 -0400 | [diff] [blame] | 732 | static ssize_t |
| 733 | show_header(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) |
| 734 | { |
| 735 | int (*func)(struct trace_seq *s) = filp->private_data; |
| 736 | struct trace_seq *s; |
| 737 | int r; |
| 738 | |
| 739 | if (*ppos) |
| 740 | return 0; |
| 741 | |
| 742 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 743 | if (!s) |
| 744 | return -ENOMEM; |
| 745 | |
| 746 | trace_seq_init(s); |
| 747 | |
| 748 | func(s); |
| 749 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); |
| 750 | |
| 751 | kfree(s); |
| 752 | |
| 753 | return r; |
| 754 | } |
| 755 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 756 | static const struct seq_operations show_event_seq_ops = { |
| 757 | .start = t_start, |
| 758 | .next = t_next, |
| 759 | .show = t_show, |
| 760 | .stop = t_stop, |
| 761 | }; |
| 762 | |
| 763 | static const struct seq_operations show_set_event_seq_ops = { |
| 764 | .start = s_start, |
| 765 | .next = s_next, |
| 766 | .show = t_show, |
| 767 | .stop = t_stop, |
| 768 | }; |
| 769 | |
Steven Rostedt | 2314c4a | 2009-03-10 12:04:02 -0400 | [diff] [blame] | 770 | static const struct file_operations ftrace_avail_fops = { |
| 771 | .open = ftrace_event_seq_open, |
| 772 | .read = seq_read, |
| 773 | .llseek = seq_lseek, |
| 774 | .release = seq_release, |
| 775 | }; |
| 776 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 777 | static const struct file_operations ftrace_set_event_fops = { |
| 778 | .open = ftrace_event_seq_open, |
| 779 | .read = seq_read, |
| 780 | .write = ftrace_event_write, |
| 781 | .llseek = seq_lseek, |
| 782 | .release = seq_release, |
| 783 | }; |
| 784 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 785 | static const struct file_operations ftrace_enable_fops = { |
| 786 | .open = tracing_open_generic, |
| 787 | .read = event_enable_read, |
| 788 | .write = event_enable_write, |
| 789 | }; |
| 790 | |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 791 | static const struct file_operations ftrace_event_format_fops = { |
| 792 | .open = tracing_open_generic, |
| 793 | .read = event_format_read, |
| 794 | }; |
| 795 | |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 796 | static const struct file_operations ftrace_event_id_fops = { |
| 797 | .open = tracing_open_generic, |
| 798 | .read = event_id_read, |
| 799 | }; |
| 800 | |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame] | 801 | static const struct file_operations ftrace_event_filter_fops = { |
| 802 | .open = tracing_open_generic, |
| 803 | .read = event_filter_read, |
| 804 | .write = event_filter_write, |
| 805 | }; |
| 806 | |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 807 | static const struct file_operations ftrace_subsystem_filter_fops = { |
| 808 | .open = tracing_open_generic, |
| 809 | .read = subsystem_filter_read, |
| 810 | .write = subsystem_filter_write, |
| 811 | }; |
| 812 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 813 | static const struct file_operations ftrace_system_enable_fops = { |
| 814 | .open = tracing_open_generic, |
| 815 | .read = system_enable_read, |
| 816 | .write = system_enable_write, |
| 817 | }; |
| 818 | |
Steven Rostedt | d1b182a | 2009-04-15 16:53:47 -0400 | [diff] [blame] | 819 | static const struct file_operations ftrace_show_header_fops = { |
| 820 | .open = tracing_open_generic, |
| 821 | .read = show_header, |
| 822 | }; |
| 823 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 824 | static struct dentry *event_trace_events_dir(void) |
| 825 | { |
| 826 | static struct dentry *d_tracer; |
| 827 | static struct dentry *d_events; |
| 828 | |
| 829 | if (d_events) |
| 830 | return d_events; |
| 831 | |
| 832 | d_tracer = tracing_init_dentry(); |
| 833 | if (!d_tracer) |
| 834 | return NULL; |
| 835 | |
| 836 | d_events = debugfs_create_dir("events", d_tracer); |
| 837 | if (!d_events) |
| 838 | pr_warning("Could not create debugfs " |
| 839 | "'events' directory\n"); |
| 840 | |
| 841 | return d_events; |
| 842 | } |
| 843 | |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 844 | static LIST_HEAD(event_subsystems); |
| 845 | |
| 846 | static struct dentry * |
| 847 | event_subsystem_dir(const char *name, struct dentry *d_events) |
| 848 | { |
| 849 | struct event_subsystem *system; |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 850 | struct dentry *entry; |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 851 | |
| 852 | /* First see if we did not already create this dir */ |
| 853 | list_for_each_entry(system, &event_subsystems, list) { |
Xiao Guangrong | dc82ec98a | 2009-07-09 16:22:22 +0800 | [diff] [blame] | 854 | if (strcmp(system->name, name) == 0) { |
| 855 | system->nr_events++; |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 856 | return system->entry; |
Xiao Guangrong | dc82ec98a | 2009-07-09 16:22:22 +0800 | [diff] [blame] | 857 | } |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | /* need to create new entry */ |
| 861 | system = kmalloc(sizeof(*system), GFP_KERNEL); |
| 862 | if (!system) { |
| 863 | pr_warning("No memory to create event subsystem %s\n", |
| 864 | name); |
| 865 | return d_events; |
| 866 | } |
| 867 | |
| 868 | system->entry = debugfs_create_dir(name, d_events); |
| 869 | if (!system->entry) { |
| 870 | pr_warning("Could not create event subsystem %s\n", |
| 871 | name); |
| 872 | kfree(system); |
| 873 | return d_events; |
| 874 | } |
| 875 | |
Xiao Guangrong | dc82ec98a | 2009-07-09 16:22:22 +0800 | [diff] [blame] | 876 | system->nr_events = 1; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 877 | system->name = kstrdup(name, GFP_KERNEL); |
| 878 | if (!system->name) { |
| 879 | debugfs_remove(system->entry); |
| 880 | kfree(system); |
| 881 | return d_events; |
| 882 | } |
| 883 | |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 884 | list_add(&system->list, &event_subsystems); |
| 885 | |
Tom Zanussi | 30e673b | 2009-04-28 03:04:47 -0500 | [diff] [blame] | 886 | system->filter = NULL; |
Tom Zanussi | cfb180f | 2009-03-22 03:31:17 -0500 | [diff] [blame] | 887 | |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 888 | system->filter = kzalloc(sizeof(struct event_filter), GFP_KERNEL); |
| 889 | if (!system->filter) { |
| 890 | pr_warning("Could not allocate filter for subsystem " |
| 891 | "'%s'\n", name); |
| 892 | return system->entry; |
| 893 | } |
| 894 | |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 895 | entry = debugfs_create_file("filter", 0644, system->entry, system, |
| 896 | &ftrace_subsystem_filter_fops); |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 897 | if (!entry) { |
| 898 | kfree(system->filter); |
| 899 | system->filter = NULL; |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 900 | pr_warning("Could not create debugfs " |
| 901 | "'%s/filter' entry\n", name); |
Tom Zanussi | 8b37256 | 2009-04-28 03:04:59 -0500 | [diff] [blame] | 902 | } |
Tom Zanussi | e1112b4 | 2009-03-31 00:48:49 -0500 | [diff] [blame] | 903 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 904 | entry = trace_create_file("enable", 0644, system->entry, |
| 905 | (void *)system->name, |
| 906 | &ftrace_system_enable_fops); |
| 907 | |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 908 | return system->entry; |
| 909 | } |
| 910 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 911 | static int |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 912 | event_create_dir(struct ftrace_event_call *call, struct dentry *d_events, |
| 913 | const struct file_operations *id, |
| 914 | const struct file_operations *enable, |
| 915 | const struct file_operations *filter, |
| 916 | const struct file_operations *format) |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 917 | { |
| 918 | struct dentry *entry; |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 919 | int ret; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 920 | |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 921 | /* |
| 922 | * If the trace point header did not define TRACE_SYSTEM |
| 923 | * then the system would be called "TRACE_SYSTEM". |
| 924 | */ |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 925 | if (strcmp(call->system, TRACE_SYSTEM) != 0) |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 926 | d_events = event_subsystem_dir(call->system, d_events); |
| 927 | |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 928 | if (call->raw_init) { |
| 929 | ret = call->raw_init(); |
| 930 | if (ret < 0) { |
| 931 | pr_warning("Could not initialize trace point" |
| 932 | " events/%s\n", call->name); |
| 933 | return ret; |
| 934 | } |
| 935 | } |
| 936 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 937 | call->dir = debugfs_create_dir(call->name, d_events); |
| 938 | if (!call->dir) { |
| 939 | pr_warning("Could not create debugfs " |
| 940 | "'%s' directory\n", call->name); |
| 941 | return -1; |
| 942 | } |
| 943 | |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 944 | if (call->regfunc) |
| 945 | entry = trace_create_file("enable", 0644, call->dir, call, |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 946 | enable); |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 947 | |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 948 | if (call->id) |
| 949 | entry = trace_create_file("id", 0444, call->dir, call, |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 950 | id); |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 951 | |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 952 | if (call->define_fields) { |
| 953 | ret = call->define_fields(); |
| 954 | if (ret < 0) { |
| 955 | pr_warning("Could not initialize trace point" |
| 956 | " events/%s\n", call->name); |
| 957 | return ret; |
| 958 | } |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 959 | entry = trace_create_file("filter", 0644, call->dir, call, |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 960 | filter); |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 961 | } |
| 962 | |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 963 | /* A trace may not want to export its format */ |
| 964 | if (!call->show_format) |
| 965 | return 0; |
| 966 | |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 967 | entry = trace_create_file("format", 0444, call->dir, call, |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 968 | format); |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 969 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 970 | return 0; |
| 971 | } |
| 972 | |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 973 | #define for_each_event(event, start, end) \ |
| 974 | for (event = start; \ |
| 975 | (unsigned long)event < (unsigned long)end; \ |
| 976 | event++) |
| 977 | |
Steven Rostedt | 61f919a | 2009-04-14 18:22:32 -0400 | [diff] [blame] | 978 | #ifdef CONFIG_MODULES |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 979 | |
| 980 | static LIST_HEAD(ftrace_module_file_list); |
| 981 | |
| 982 | /* |
| 983 | * Modules must own their file_operations to keep up with |
| 984 | * reference counting. |
| 985 | */ |
| 986 | struct ftrace_module_file_ops { |
| 987 | struct list_head list; |
| 988 | struct module *mod; |
| 989 | struct file_operations id; |
| 990 | struct file_operations enable; |
| 991 | struct file_operations format; |
| 992 | struct file_operations filter; |
| 993 | }; |
| 994 | |
Frederic Weisbecker | a2ca5e0 | 2009-08-06 07:32:21 +0200 | [diff] [blame^] | 995 | static void remove_subsystem_dir(const char *name) |
| 996 | { |
| 997 | struct event_subsystem *system; |
| 998 | |
| 999 | if (strcmp(name, TRACE_SYSTEM) == 0) |
| 1000 | return; |
| 1001 | |
| 1002 | list_for_each_entry(system, &event_subsystems, list) { |
| 1003 | if (strcmp(system->name, name) == 0) { |
| 1004 | if (!--system->nr_events) { |
| 1005 | struct event_filter *filter = system->filter; |
| 1006 | |
| 1007 | debugfs_remove_recursive(system->entry); |
| 1008 | list_del(&system->list); |
| 1009 | if (filter) { |
| 1010 | kfree(filter->filter_string); |
| 1011 | kfree(filter); |
| 1012 | } |
| 1013 | kfree(system->name); |
| 1014 | kfree(system); |
| 1015 | } |
| 1016 | break; |
| 1017 | } |
| 1018 | } |
| 1019 | } |
| 1020 | |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1021 | static struct ftrace_module_file_ops * |
| 1022 | trace_create_file_ops(struct module *mod) |
| 1023 | { |
| 1024 | struct ftrace_module_file_ops *file_ops; |
| 1025 | |
| 1026 | /* |
| 1027 | * This is a bit of a PITA. To allow for correct reference |
| 1028 | * counting, modules must "own" their file_operations. |
| 1029 | * To do this, we allocate the file operations that will be |
| 1030 | * used in the event directory. |
| 1031 | */ |
| 1032 | |
| 1033 | file_ops = kmalloc(sizeof(*file_ops), GFP_KERNEL); |
| 1034 | if (!file_ops) |
| 1035 | return NULL; |
| 1036 | |
| 1037 | file_ops->mod = mod; |
| 1038 | |
| 1039 | file_ops->id = ftrace_event_id_fops; |
| 1040 | file_ops->id.owner = mod; |
| 1041 | |
| 1042 | file_ops->enable = ftrace_enable_fops; |
| 1043 | file_ops->enable.owner = mod; |
| 1044 | |
| 1045 | file_ops->filter = ftrace_event_filter_fops; |
| 1046 | file_ops->filter.owner = mod; |
| 1047 | |
| 1048 | file_ops->format = ftrace_event_format_fops; |
| 1049 | file_ops->format.owner = mod; |
| 1050 | |
| 1051 | list_add(&file_ops->list, &ftrace_module_file_list); |
| 1052 | |
| 1053 | return file_ops; |
| 1054 | } |
| 1055 | |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1056 | static void trace_module_add_events(struct module *mod) |
| 1057 | { |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1058 | struct ftrace_module_file_ops *file_ops = NULL; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1059 | struct ftrace_event_call *call, *start, *end; |
| 1060 | struct dentry *d_events; |
| 1061 | |
| 1062 | start = mod->trace_events; |
| 1063 | end = mod->trace_events + mod->num_trace_events; |
| 1064 | |
| 1065 | if (start == end) |
| 1066 | return; |
| 1067 | |
| 1068 | d_events = event_trace_events_dir(); |
| 1069 | if (!d_events) |
| 1070 | return; |
| 1071 | |
| 1072 | for_each_event(call, start, end) { |
| 1073 | /* The linker may leave blanks */ |
| 1074 | if (!call->name) |
| 1075 | continue; |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1076 | |
| 1077 | /* |
| 1078 | * This module has events, create file ops for this module |
| 1079 | * if not already done. |
| 1080 | */ |
| 1081 | if (!file_ops) { |
| 1082 | file_ops = trace_create_file_ops(mod); |
| 1083 | if (!file_ops) |
| 1084 | return; |
| 1085 | } |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1086 | call->mod = mod; |
| 1087 | list_add(&call->list, &ftrace_events); |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1088 | event_create_dir(call, d_events, |
| 1089 | &file_ops->id, &file_ops->enable, |
| 1090 | &file_ops->filter, &file_ops->format); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1091 | } |
| 1092 | } |
| 1093 | |
| 1094 | static void trace_module_remove_events(struct module *mod) |
| 1095 | { |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1096 | struct ftrace_module_file_ops *file_ops; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1097 | struct ftrace_event_call *call, *p; |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1098 | bool found = false; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1099 | |
Steven Rostedt | 110bf2b | 2009-06-09 17:29:07 -0400 | [diff] [blame] | 1100 | down_write(&trace_event_mutex); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1101 | list_for_each_entry_safe(call, p, &ftrace_events, list) { |
| 1102 | if (call->mod == mod) { |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1103 | found = true; |
Zhaolei | 0e907c9 | 2009-05-25 18:13:59 +0800 | [diff] [blame] | 1104 | ftrace_event_enable_disable(call, 0); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1105 | if (call->event) |
Steven Rostedt | 110bf2b | 2009-06-09 17:29:07 -0400 | [diff] [blame] | 1106 | __unregister_ftrace_event(call->event); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1107 | debugfs_remove_recursive(call->dir); |
| 1108 | list_del(&call->list); |
Li Zefan | 2df75e4 | 2009-05-06 10:33:04 +0800 | [diff] [blame] | 1109 | trace_destroy_fields(call); |
| 1110 | destroy_preds(call); |
Xiao Guangrong | dc82ec98a | 2009-07-09 16:22:22 +0800 | [diff] [blame] | 1111 | remove_subsystem_dir(call->system); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1112 | } |
| 1113 | } |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1114 | |
| 1115 | /* Now free the file_operations */ |
| 1116 | list_for_each_entry(file_ops, &ftrace_module_file_list, list) { |
| 1117 | if (file_ops->mod == mod) |
| 1118 | break; |
| 1119 | } |
| 1120 | if (&file_ops->list != &ftrace_module_file_list) { |
| 1121 | list_del(&file_ops->list); |
| 1122 | kfree(file_ops); |
| 1123 | } |
Steven Rostedt | 9456f0f | 2009-05-06 21:54:09 -0400 | [diff] [blame] | 1124 | |
| 1125 | /* |
| 1126 | * It is safest to reset the ring buffer if the module being unloaded |
| 1127 | * registered any events. |
| 1128 | */ |
| 1129 | if (found) |
| 1130 | tracing_reset_current_online_cpus(); |
Steven Rostedt | 110bf2b | 2009-06-09 17:29:07 -0400 | [diff] [blame] | 1131 | up_write(&trace_event_mutex); |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1132 | } |
| 1133 | |
Steven Rostedt | 61f919a | 2009-04-14 18:22:32 -0400 | [diff] [blame] | 1134 | static int trace_module_notify(struct notifier_block *self, |
| 1135 | unsigned long val, void *data) |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1136 | { |
| 1137 | struct module *mod = data; |
| 1138 | |
| 1139 | mutex_lock(&event_mutex); |
| 1140 | switch (val) { |
| 1141 | case MODULE_STATE_COMING: |
| 1142 | trace_module_add_events(mod); |
| 1143 | break; |
| 1144 | case MODULE_STATE_GOING: |
| 1145 | trace_module_remove_events(mod); |
| 1146 | break; |
| 1147 | } |
| 1148 | mutex_unlock(&event_mutex); |
| 1149 | |
| 1150 | return 0; |
| 1151 | } |
Steven Rostedt | 61f919a | 2009-04-14 18:22:32 -0400 | [diff] [blame] | 1152 | #else |
| 1153 | static int trace_module_notify(struct notifier_block *self, |
| 1154 | unsigned long val, void *data) |
| 1155 | { |
| 1156 | return 0; |
| 1157 | } |
| 1158 | #endif /* CONFIG_MODULES */ |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1159 | |
| 1160 | struct notifier_block trace_module_nb = { |
| 1161 | .notifier_call = trace_module_notify, |
| 1162 | .priority = 0, |
| 1163 | }; |
| 1164 | |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 1165 | extern struct ftrace_event_call __start_ftrace_events[]; |
| 1166 | extern struct ftrace_event_call __stop_ftrace_events[]; |
| 1167 | |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 1168 | static char bootup_event_buf[COMMAND_LINE_SIZE] __initdata; |
| 1169 | |
| 1170 | static __init int setup_trace_event(char *str) |
| 1171 | { |
| 1172 | strlcpy(bootup_event_buf, str, COMMAND_LINE_SIZE); |
| 1173 | ring_buffer_expanded = 1; |
| 1174 | tracing_selftest_disabled = 1; |
| 1175 | |
| 1176 | return 1; |
| 1177 | } |
| 1178 | __setup("trace_event=", setup_trace_event); |
| 1179 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1180 | static __init int event_trace_init(void) |
| 1181 | { |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 1182 | struct ftrace_event_call *call; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1183 | struct dentry *d_tracer; |
| 1184 | struct dentry *entry; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1185 | struct dentry *d_events; |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1186 | int ret; |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 1187 | char *buf = bootup_event_buf; |
| 1188 | char *token; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1189 | |
| 1190 | d_tracer = tracing_init_dentry(); |
| 1191 | if (!d_tracer) |
| 1192 | return 0; |
| 1193 | |
Steven Rostedt | 2314c4a | 2009-03-10 12:04:02 -0400 | [diff] [blame] | 1194 | entry = debugfs_create_file("available_events", 0444, d_tracer, |
| 1195 | (void *)&show_event_seq_ops, |
| 1196 | &ftrace_avail_fops); |
| 1197 | if (!entry) |
| 1198 | pr_warning("Could not create debugfs " |
| 1199 | "'available_events' entry\n"); |
| 1200 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1201 | entry = debugfs_create_file("set_event", 0644, d_tracer, |
| 1202 | (void *)&show_set_event_seq_ops, |
| 1203 | &ftrace_set_event_fops); |
| 1204 | if (!entry) |
| 1205 | pr_warning("Could not create debugfs " |
| 1206 | "'set_event' entry\n"); |
| 1207 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1208 | d_events = event_trace_events_dir(); |
| 1209 | if (!d_events) |
| 1210 | return 0; |
| 1211 | |
Steven Rostedt | d1b182a | 2009-04-15 16:53:47 -0400 | [diff] [blame] | 1212 | /* ring buffer internal formats */ |
| 1213 | trace_create_file("header_page", 0444, d_events, |
| 1214 | ring_buffer_print_page_header, |
| 1215 | &ftrace_show_header_fops); |
| 1216 | |
| 1217 | trace_create_file("header_event", 0444, d_events, |
| 1218 | ring_buffer_print_entry_header, |
| 1219 | &ftrace_show_header_fops); |
| 1220 | |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1221 | trace_create_file("enable", 0644, d_events, |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 1222 | NULL, &ftrace_system_enable_fops); |
Steven Rostedt | 8ae79a1 | 2009-05-06 22:52:15 -0400 | [diff] [blame] | 1223 | |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1224 | for_each_event(call, __start_ftrace_events, __stop_ftrace_events) { |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1225 | /* The linker may leave blanks */ |
| 1226 | if (!call->name) |
| 1227 | continue; |
Steven Rostedt | a59fd60 | 2009-04-10 13:52:20 -0400 | [diff] [blame] | 1228 | list_add(&call->list, &ftrace_events); |
Steven Rostedt | 701970b | 2009-04-24 23:11:22 -0400 | [diff] [blame] | 1229 | event_create_dir(call, d_events, &ftrace_event_id_fops, |
| 1230 | &ftrace_enable_fops, &ftrace_event_filter_fops, |
| 1231 | &ftrace_event_format_fops); |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 1232 | } |
| 1233 | |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 1234 | while (true) { |
| 1235 | token = strsep(&buf, ","); |
| 1236 | |
| 1237 | if (!token) |
| 1238 | break; |
| 1239 | if (!*token) |
| 1240 | continue; |
| 1241 | |
| 1242 | ret = ftrace_set_clr_event(token, 1); |
| 1243 | if (ret) |
| 1244 | pr_warning("Failed to enable trace event: %s\n", token); |
| 1245 | } |
| 1246 | |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1247 | ret = register_module_notifier(&trace_module_nb); |
Ming Lei | 5537937 | 2009-05-18 23:04:46 +0800 | [diff] [blame] | 1248 | if (ret) |
Steven Rostedt | 6d72373 | 2009-04-10 14:53:50 -0400 | [diff] [blame] | 1249 | pr_warning("Failed to register trace events module notifier\n"); |
| 1250 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 1251 | return 0; |
| 1252 | } |
| 1253 | fs_initcall(event_trace_init); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1254 | |
| 1255 | #ifdef CONFIG_FTRACE_STARTUP_TEST |
| 1256 | |
| 1257 | static DEFINE_SPINLOCK(test_spinlock); |
| 1258 | static DEFINE_SPINLOCK(test_spinlock_irq); |
| 1259 | static DEFINE_MUTEX(test_mutex); |
| 1260 | |
| 1261 | static __init void test_work(struct work_struct *dummy) |
| 1262 | { |
| 1263 | spin_lock(&test_spinlock); |
| 1264 | spin_lock_irq(&test_spinlock_irq); |
| 1265 | udelay(1); |
| 1266 | spin_unlock_irq(&test_spinlock_irq); |
| 1267 | spin_unlock(&test_spinlock); |
| 1268 | |
| 1269 | mutex_lock(&test_mutex); |
| 1270 | msleep(1); |
| 1271 | mutex_unlock(&test_mutex); |
| 1272 | } |
| 1273 | |
| 1274 | static __init int event_test_thread(void *unused) |
| 1275 | { |
| 1276 | void *test_malloc; |
| 1277 | |
| 1278 | test_malloc = kmalloc(1234, GFP_KERNEL); |
| 1279 | if (!test_malloc) |
| 1280 | pr_info("failed to kmalloc\n"); |
| 1281 | |
| 1282 | schedule_on_each_cpu(test_work); |
| 1283 | |
| 1284 | kfree(test_malloc); |
| 1285 | |
| 1286 | set_current_state(TASK_INTERRUPTIBLE); |
| 1287 | while (!kthread_should_stop()) |
| 1288 | schedule(); |
| 1289 | |
| 1290 | return 0; |
| 1291 | } |
| 1292 | |
| 1293 | /* |
| 1294 | * Do various things that may trigger events. |
| 1295 | */ |
| 1296 | static __init void event_test_stuff(void) |
| 1297 | { |
| 1298 | struct task_struct *test_thread; |
| 1299 | |
| 1300 | test_thread = kthread_run(event_test_thread, NULL, "test-events"); |
| 1301 | msleep(1); |
| 1302 | kthread_stop(test_thread); |
| 1303 | } |
| 1304 | |
| 1305 | /* |
| 1306 | * For every trace event defined, we will test each trace point separately, |
| 1307 | * and then by groups, and finally all trace points. |
| 1308 | */ |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1309 | static __init void event_trace_self_tests(void) |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1310 | { |
| 1311 | struct ftrace_event_call *call; |
| 1312 | struct event_subsystem *system; |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1313 | int ret; |
| 1314 | |
| 1315 | pr_info("Running tests on trace events:\n"); |
| 1316 | |
| 1317 | list_for_each_entry(call, &ftrace_events, list) { |
| 1318 | |
| 1319 | /* Only test those that have a regfunc */ |
| 1320 | if (!call->regfunc) |
| 1321 | continue; |
| 1322 | |
| 1323 | pr_info("Testing event %s: ", call->name); |
| 1324 | |
| 1325 | /* |
| 1326 | * If an event is already enabled, someone is using |
| 1327 | * it and the self test should not be on. |
| 1328 | */ |
| 1329 | if (call->enabled) { |
| 1330 | pr_warning("Enabled event during self test!\n"); |
| 1331 | WARN_ON_ONCE(1); |
| 1332 | continue; |
| 1333 | } |
| 1334 | |
Zhaolei | 0e907c9 | 2009-05-25 18:13:59 +0800 | [diff] [blame] | 1335 | ftrace_event_enable_disable(call, 1); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1336 | event_test_stuff(); |
Zhaolei | 0e907c9 | 2009-05-25 18:13:59 +0800 | [diff] [blame] | 1337 | ftrace_event_enable_disable(call, 0); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1338 | |
| 1339 | pr_cont("OK\n"); |
| 1340 | } |
| 1341 | |
| 1342 | /* Now test at the sub system level */ |
| 1343 | |
| 1344 | pr_info("Running tests on trace event systems:\n"); |
| 1345 | |
| 1346 | list_for_each_entry(system, &event_subsystems, list) { |
| 1347 | |
| 1348 | /* the ftrace system is special, skip it */ |
| 1349 | if (strcmp(system->name, "ftrace") == 0) |
| 1350 | continue; |
| 1351 | |
| 1352 | pr_info("Testing event system %s: ", system->name); |
| 1353 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 1354 | ret = __ftrace_set_clr_event(NULL, system->name, NULL, 1); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1355 | if (WARN_ON_ONCE(ret)) { |
| 1356 | pr_warning("error enabling system %s\n", |
| 1357 | system->name); |
| 1358 | continue; |
| 1359 | } |
| 1360 | |
| 1361 | event_test_stuff(); |
| 1362 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 1363 | ret = __ftrace_set_clr_event(NULL, system->name, NULL, 0); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1364 | if (WARN_ON_ONCE(ret)) |
| 1365 | pr_warning("error disabling system %s\n", |
| 1366 | system->name); |
| 1367 | |
| 1368 | pr_cont("OK\n"); |
| 1369 | } |
| 1370 | |
| 1371 | /* Test with all events enabled */ |
| 1372 | |
| 1373 | pr_info("Running tests on all trace events:\n"); |
| 1374 | pr_info("Testing all events: "); |
| 1375 | |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 1376 | ret = __ftrace_set_clr_event(NULL, NULL, NULL, 1); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1377 | if (WARN_ON_ONCE(ret)) { |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1378 | pr_warning("error enabling all events\n"); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1379 | return; |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1380 | } |
| 1381 | |
| 1382 | event_test_stuff(); |
| 1383 | |
| 1384 | /* reset sysname */ |
Li Zefan | 8f31bfe | 2009-05-08 10:31:42 +0800 | [diff] [blame] | 1385 | ret = __ftrace_set_clr_event(NULL, NULL, NULL, 0); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1386 | if (WARN_ON_ONCE(ret)) { |
| 1387 | pr_warning("error disabling all events\n"); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1388 | return; |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1389 | } |
| 1390 | |
| 1391 | pr_cont("OK\n"); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1392 | } |
| 1393 | |
| 1394 | #ifdef CONFIG_FUNCTION_TRACER |
| 1395 | |
| 1396 | static DEFINE_PER_CPU(atomic_t, test_event_disable); |
| 1397 | |
| 1398 | static void |
| 1399 | function_test_events_call(unsigned long ip, unsigned long parent_ip) |
| 1400 | { |
| 1401 | struct ring_buffer_event *event; |
| 1402 | struct ftrace_entry *entry; |
| 1403 | unsigned long flags; |
| 1404 | long disabled; |
| 1405 | int resched; |
| 1406 | int cpu; |
| 1407 | int pc; |
| 1408 | |
| 1409 | pc = preempt_count(); |
| 1410 | resched = ftrace_preempt_disable(); |
| 1411 | cpu = raw_smp_processor_id(); |
| 1412 | disabled = atomic_inc_return(&per_cpu(test_event_disable, cpu)); |
| 1413 | |
| 1414 | if (disabled != 1) |
| 1415 | goto out; |
| 1416 | |
| 1417 | local_save_flags(flags); |
| 1418 | |
| 1419 | event = trace_current_buffer_lock_reserve(TRACE_FN, sizeof(*entry), |
| 1420 | flags, pc); |
| 1421 | if (!event) |
| 1422 | goto out; |
| 1423 | entry = ring_buffer_event_data(event); |
| 1424 | entry->ip = ip; |
| 1425 | entry->parent_ip = parent_ip; |
| 1426 | |
Steven Rostedt | cb4764a | 2009-04-20 18:16:44 -0400 | [diff] [blame] | 1427 | trace_nowake_buffer_unlock_commit(event, flags, pc); |
Steven Rostedt | 9ea21c1 | 2009-04-16 12:15:44 -0400 | [diff] [blame] | 1428 | |
| 1429 | out: |
| 1430 | atomic_dec(&per_cpu(test_event_disable, cpu)); |
| 1431 | ftrace_preempt_enable(resched); |
| 1432 | } |
| 1433 | |
| 1434 | static struct ftrace_ops trace_ops __initdata = |
| 1435 | { |
| 1436 | .func = function_test_events_call, |
| 1437 | }; |
| 1438 | |
| 1439 | static __init void event_trace_self_test_with_function(void) |
| 1440 | { |
| 1441 | register_ftrace_function(&trace_ops); |
| 1442 | pr_info("Running tests again, along with the function tracer\n"); |
| 1443 | event_trace_self_tests(); |
| 1444 | unregister_ftrace_function(&trace_ops); |
| 1445 | } |
| 1446 | #else |
| 1447 | static __init void event_trace_self_test_with_function(void) |
| 1448 | { |
| 1449 | } |
| 1450 | #endif |
| 1451 | |
| 1452 | static __init int event_trace_self_tests_init(void) |
| 1453 | { |
Li Zefan | 020e5f8 | 2009-07-01 10:47:05 +0800 | [diff] [blame] | 1454 | if (!tracing_selftest_disabled) { |
| 1455 | event_trace_self_tests(); |
| 1456 | event_trace_self_test_with_function(); |
| 1457 | } |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1458 | |
| 1459 | return 0; |
| 1460 | } |
| 1461 | |
Steven Rostedt | 28d20e2 | 2009-04-20 12:12:44 -0400 | [diff] [blame] | 1462 | late_initcall(event_trace_self_tests_init); |
Steven Rostedt | e618700 | 2009-04-15 13:36:40 -0400 | [diff] [blame] | 1463 | |
| 1464 | #endif |