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