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