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