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 | |
| 11 | #include <linux/debugfs.h> |
| 12 | #include <linux/uaccess.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/ctype.h> |
| 15 | |
Steven Rostedt | 91729ef9 | 2009-03-02 15:03:01 -0500 | [diff] [blame] | 16 | #include "trace_output.h" |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 17 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 18 | #define TRACE_SYSTEM "TRACE_SYSTEM" |
| 19 | |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 20 | static DEFINE_MUTEX(event_mutex); |
| 21 | |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 22 | int trace_define_field(struct ftrace_event_call *call, char *type, |
| 23 | char *name, int offset, int size) |
| 24 | { |
| 25 | struct ftrace_event_field *field; |
| 26 | |
| 27 | field = kmalloc(sizeof(*field), GFP_KERNEL); |
| 28 | if (!field) |
| 29 | goto err; |
| 30 | field->name = kstrdup(name, GFP_KERNEL); |
| 31 | if (!field->name) |
| 32 | goto err; |
| 33 | field->type = kstrdup(type, GFP_KERNEL); |
| 34 | if (!field->type) |
| 35 | goto err; |
| 36 | field->offset = offset; |
| 37 | field->size = size; |
| 38 | list_add(&field->link, &call->fields); |
| 39 | |
| 40 | return 0; |
| 41 | err: |
| 42 | if (field) { |
| 43 | kfree(field->name); |
| 44 | kfree(field->type); |
| 45 | } |
| 46 | kfree(field); |
| 47 | return -ENOMEM; |
| 48 | } |
| 49 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 50 | static void ftrace_clear_events(void) |
| 51 | { |
| 52 | struct ftrace_event_call *call = (void *)__start_ftrace_events; |
| 53 | |
| 54 | |
| 55 | while ((unsigned long)call < (unsigned long)__stop_ftrace_events) { |
| 56 | |
| 57 | if (call->enabled) { |
| 58 | call->enabled = 0; |
| 59 | call->unregfunc(); |
| 60 | } |
| 61 | call++; |
| 62 | } |
| 63 | } |
| 64 | |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 65 | static void ftrace_event_enable_disable(struct ftrace_event_call *call, |
| 66 | int enable) |
| 67 | { |
| 68 | |
| 69 | switch (enable) { |
| 70 | case 0: |
| 71 | if (call->enabled) { |
| 72 | call->enabled = 0; |
| 73 | call->unregfunc(); |
| 74 | } |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 75 | break; |
| 76 | case 1: |
Steven Rostedt | da4d030 | 2009-03-09 17:14:30 -0400 | [diff] [blame] | 77 | if (!call->enabled) { |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 78 | call->enabled = 1; |
| 79 | call->regfunc(); |
| 80 | } |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 81 | break; |
| 82 | } |
| 83 | } |
| 84 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 85 | static int ftrace_set_clr_event(char *buf, int set) |
| 86 | { |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 87 | struct ftrace_event_call *call = __start_ftrace_events; |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 88 | char *event = NULL, *sub = NULL, *match; |
| 89 | int ret = -EINVAL; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 90 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 91 | /* |
| 92 | * The buf format can be <subsystem>:<event-name> |
| 93 | * *:<event-name> means any event by that name. |
| 94 | * :<event-name> is the same. |
| 95 | * |
| 96 | * <subsystem>:* means all events in that subsystem |
| 97 | * <subsystem>: means the same. |
| 98 | * |
| 99 | * <name> (no ':') means all events in a subsystem with |
| 100 | * the name <name> or any event that matches <name> |
| 101 | */ |
| 102 | |
| 103 | match = strsep(&buf, ":"); |
| 104 | if (buf) { |
| 105 | sub = match; |
| 106 | event = buf; |
| 107 | match = NULL; |
| 108 | |
| 109 | if (!strlen(sub) || strcmp(sub, "*") == 0) |
| 110 | sub = NULL; |
| 111 | if (!strlen(event) || strcmp(event, "*") == 0) |
| 112 | event = NULL; |
| 113 | } |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 114 | |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 115 | mutex_lock(&event_mutex); |
Peter Zijlstra | ac199db | 2009-03-19 20:26:15 +0100 | [diff] [blame] | 116 | for_each_event(call) { |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 117 | |
Steven Rostedt | 40e2681 | 2009-03-10 11:32:40 -0400 | [diff] [blame] | 118 | if (!call->name || !call->regfunc) |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 119 | continue; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 120 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 121 | if (match && |
| 122 | strcmp(match, call->name) != 0 && |
| 123 | strcmp(match, call->system) != 0) |
| 124 | continue; |
| 125 | |
| 126 | if (sub && strcmp(sub, call->system) != 0) |
| 127 | continue; |
| 128 | |
| 129 | if (event && strcmp(event, call->name) != 0) |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 130 | continue; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 131 | |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 132 | ftrace_event_enable_disable(call, set); |
| 133 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 134 | ret = 0; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 135 | } |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 136 | mutex_unlock(&event_mutex); |
| 137 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 138 | return ret; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | /* 128 should be much more than enough */ |
| 142 | #define EVENT_BUF_SIZE 127 |
| 143 | |
| 144 | static ssize_t |
| 145 | ftrace_event_write(struct file *file, const char __user *ubuf, |
| 146 | size_t cnt, loff_t *ppos) |
| 147 | { |
| 148 | size_t read = 0; |
| 149 | int i, set = 1; |
| 150 | ssize_t ret; |
| 151 | char *buf; |
| 152 | char ch; |
| 153 | |
| 154 | if (!cnt || cnt < 0) |
| 155 | return 0; |
| 156 | |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 157 | ret = tracing_update_buffers(); |
| 158 | if (ret < 0) |
| 159 | return ret; |
| 160 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 161 | ret = get_user(ch, ubuf++); |
| 162 | if (ret) |
| 163 | return ret; |
| 164 | read++; |
| 165 | cnt--; |
| 166 | |
| 167 | /* skip white space */ |
| 168 | while (cnt && isspace(ch)) { |
| 169 | ret = get_user(ch, ubuf++); |
| 170 | if (ret) |
| 171 | return ret; |
| 172 | read++; |
| 173 | cnt--; |
| 174 | } |
| 175 | |
| 176 | /* Only white space found? */ |
| 177 | if (isspace(ch)) { |
| 178 | file->f_pos += read; |
| 179 | ret = read; |
| 180 | return ret; |
| 181 | } |
| 182 | |
| 183 | buf = kmalloc(EVENT_BUF_SIZE+1, GFP_KERNEL); |
| 184 | if (!buf) |
| 185 | return -ENOMEM; |
| 186 | |
| 187 | if (cnt > EVENT_BUF_SIZE) |
| 188 | cnt = EVENT_BUF_SIZE; |
| 189 | |
| 190 | i = 0; |
| 191 | while (cnt && !isspace(ch)) { |
| 192 | if (!i && ch == '!') |
| 193 | set = 0; |
| 194 | else |
| 195 | buf[i++] = ch; |
| 196 | |
| 197 | ret = get_user(ch, ubuf++); |
| 198 | if (ret) |
| 199 | goto out_free; |
| 200 | read++; |
| 201 | cnt--; |
| 202 | } |
| 203 | buf[i] = 0; |
| 204 | |
| 205 | file->f_pos += read; |
| 206 | |
| 207 | ret = ftrace_set_clr_event(buf, set); |
| 208 | if (ret) |
| 209 | goto out_free; |
| 210 | |
| 211 | ret = read; |
| 212 | |
| 213 | out_free: |
| 214 | kfree(buf); |
| 215 | |
| 216 | return ret; |
| 217 | } |
| 218 | |
| 219 | static void * |
| 220 | t_next(struct seq_file *m, void *v, loff_t *pos) |
| 221 | { |
| 222 | struct ftrace_event_call *call = m->private; |
| 223 | struct ftrace_event_call *next = call; |
| 224 | |
| 225 | (*pos)++; |
| 226 | |
Steven Rostedt | 40e2681 | 2009-03-10 11:32:40 -0400 | [diff] [blame] | 227 | for (;;) { |
| 228 | if ((unsigned long)call >= (unsigned long)__stop_ftrace_events) |
| 229 | return NULL; |
| 230 | |
| 231 | /* |
| 232 | * The ftrace subsystem is for showing formats only. |
| 233 | * They can not be enabled or disabled via the event files. |
| 234 | */ |
| 235 | if (call->regfunc) |
| 236 | break; |
| 237 | |
| 238 | call++; |
| 239 | next = call; |
| 240 | } |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 241 | |
| 242 | m->private = ++next; |
| 243 | |
| 244 | return call; |
| 245 | } |
| 246 | |
| 247 | static void *t_start(struct seq_file *m, loff_t *pos) |
| 248 | { |
| 249 | return t_next(m, NULL, pos); |
| 250 | } |
| 251 | |
| 252 | static void * |
| 253 | s_next(struct seq_file *m, void *v, loff_t *pos) |
| 254 | { |
| 255 | struct ftrace_event_call *call = m->private; |
| 256 | struct ftrace_event_call *next; |
| 257 | |
| 258 | (*pos)++; |
| 259 | |
| 260 | retry: |
| 261 | if ((unsigned long)call >= (unsigned long)__stop_ftrace_events) |
| 262 | return NULL; |
| 263 | |
| 264 | if (!call->enabled) { |
| 265 | call++; |
| 266 | goto retry; |
| 267 | } |
| 268 | |
| 269 | next = call; |
| 270 | m->private = ++next; |
| 271 | |
| 272 | return call; |
| 273 | } |
| 274 | |
| 275 | static void *s_start(struct seq_file *m, loff_t *pos) |
| 276 | { |
| 277 | return s_next(m, NULL, pos); |
| 278 | } |
| 279 | |
| 280 | static int t_show(struct seq_file *m, void *v) |
| 281 | { |
| 282 | struct ftrace_event_call *call = v; |
| 283 | |
Steven Rostedt | b628b3e | 2009-02-27 23:32:58 -0500 | [diff] [blame] | 284 | if (strcmp(call->system, TRACE_SYSTEM) != 0) |
| 285 | seq_printf(m, "%s:", call->system); |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 286 | seq_printf(m, "%s\n", call->name); |
| 287 | |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | static void t_stop(struct seq_file *m, void *p) |
| 292 | { |
| 293 | } |
| 294 | |
| 295 | static int |
| 296 | ftrace_event_seq_open(struct inode *inode, struct file *file) |
| 297 | { |
| 298 | int ret; |
| 299 | const struct seq_operations *seq_ops; |
| 300 | |
| 301 | if ((file->f_mode & FMODE_WRITE) && |
| 302 | !(file->f_flags & O_APPEND)) |
| 303 | ftrace_clear_events(); |
| 304 | |
| 305 | seq_ops = inode->i_private; |
| 306 | ret = seq_open(file, seq_ops); |
| 307 | if (!ret) { |
| 308 | struct seq_file *m = file->private_data; |
| 309 | |
| 310 | m->private = __start_ftrace_events; |
| 311 | } |
| 312 | return ret; |
| 313 | } |
| 314 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 315 | static ssize_t |
| 316 | event_enable_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 317 | loff_t *ppos) |
| 318 | { |
| 319 | struct ftrace_event_call *call = filp->private_data; |
| 320 | char *buf; |
| 321 | |
Steven Rostedt | da4d030 | 2009-03-09 17:14:30 -0400 | [diff] [blame] | 322 | if (call->enabled) |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 323 | buf = "1\n"; |
| 324 | else |
| 325 | buf = "0\n"; |
| 326 | |
| 327 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, 2); |
| 328 | } |
| 329 | |
| 330 | static ssize_t |
| 331 | event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 332 | loff_t *ppos) |
| 333 | { |
| 334 | struct ftrace_event_call *call = filp->private_data; |
| 335 | char buf[64]; |
| 336 | unsigned long val; |
| 337 | int ret; |
| 338 | |
| 339 | if (cnt >= sizeof(buf)) |
| 340 | return -EINVAL; |
| 341 | |
| 342 | if (copy_from_user(&buf, ubuf, cnt)) |
| 343 | return -EFAULT; |
| 344 | |
| 345 | buf[cnt] = 0; |
| 346 | |
| 347 | ret = strict_strtoul(buf, 10, &val); |
| 348 | if (ret < 0) |
| 349 | return ret; |
| 350 | |
Steven Rostedt | 1852fcc | 2009-03-11 14:33:00 -0400 | [diff] [blame] | 351 | ret = tracing_update_buffers(); |
| 352 | if (ret < 0) |
| 353 | return ret; |
| 354 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 355 | switch (val) { |
| 356 | case 0: |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 357 | case 1: |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 358 | mutex_lock(&event_mutex); |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 359 | ftrace_event_enable_disable(call, val); |
Steven Rostedt | 11a241a | 2009-03-02 11:49:04 -0500 | [diff] [blame] | 360 | mutex_unlock(&event_mutex); |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 361 | break; |
| 362 | |
| 363 | default: |
| 364 | return -EINVAL; |
| 365 | } |
| 366 | |
| 367 | *ppos += cnt; |
| 368 | |
| 369 | return cnt; |
| 370 | } |
| 371 | |
Steven Rostedt | 91729ef9 | 2009-03-02 15:03:01 -0500 | [diff] [blame] | 372 | #undef FIELD |
Steven Rostedt | 156b5f1 | 2009-03-06 10:50:53 -0500 | [diff] [blame] | 373 | #define FIELD(type, name) \ |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 374 | #type, "common_" #name, offsetof(typeof(field), name), \ |
| 375 | sizeof(field.name) |
Steven Rostedt | 91729ef9 | 2009-03-02 15:03:01 -0500 | [diff] [blame] | 376 | |
| 377 | static int trace_write_header(struct trace_seq *s) |
| 378 | { |
| 379 | struct trace_entry field; |
| 380 | |
| 381 | /* struct trace_entry */ |
| 382 | return trace_seq_printf(s, |
Steven Rostedt | ce8eb2b | 2009-03-10 10:14:35 -0400 | [diff] [blame] | 383 | "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" |
| 384 | "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" |
| 385 | "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" |
| 386 | "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" |
| 387 | "\tfield:%s %s;\toffset:%zu;\tsize:%zu;\n" |
Steven Rostedt | 91729ef9 | 2009-03-02 15:03:01 -0500 | [diff] [blame] | 388 | "\n", |
| 389 | FIELD(unsigned char, type), |
| 390 | FIELD(unsigned char, flags), |
| 391 | FIELD(unsigned char, preempt_count), |
| 392 | FIELD(int, pid), |
| 393 | FIELD(int, tgid)); |
| 394 | } |
Steven Rostedt | da4d030 | 2009-03-09 17:14:30 -0400 | [diff] [blame] | 395 | |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 396 | static ssize_t |
| 397 | event_format_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 398 | loff_t *ppos) |
| 399 | { |
| 400 | struct ftrace_event_call *call = filp->private_data; |
| 401 | struct trace_seq *s; |
| 402 | char *buf; |
| 403 | int r; |
| 404 | |
Tom Zanussi | c269fc8 | 2009-03-17 01:20:59 -0500 | [diff] [blame] | 405 | if (*ppos) |
| 406 | return 0; |
| 407 | |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 408 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 409 | if (!s) |
| 410 | return -ENOMEM; |
| 411 | |
| 412 | trace_seq_init(s); |
| 413 | |
Steven Rostedt | c5e4e19 | 2009-03-02 15:10:02 -0500 | [diff] [blame] | 414 | /* If any of the first writes fail, so will the show_format. */ |
| 415 | |
| 416 | trace_seq_printf(s, "name: %s\n", call->name); |
| 417 | trace_seq_printf(s, "ID: %d\n", call->id); |
| 418 | trace_seq_printf(s, "format:\n"); |
Steven Rostedt | 91729ef9 | 2009-03-02 15:03:01 -0500 | [diff] [blame] | 419 | trace_write_header(s); |
| 420 | |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 421 | r = call->show_format(s); |
| 422 | if (!r) { |
| 423 | /* |
| 424 | * ug! The format output is bigger than a PAGE!! |
| 425 | */ |
| 426 | buf = "FORMAT TOO BIG\n"; |
| 427 | r = simple_read_from_buffer(ubuf, cnt, ppos, |
| 428 | buf, strlen(buf)); |
| 429 | goto out; |
| 430 | } |
| 431 | |
| 432 | r = simple_read_from_buffer(ubuf, cnt, ppos, |
| 433 | s->buffer, s->len); |
| 434 | out: |
| 435 | kfree(s); |
| 436 | return r; |
| 437 | } |
| 438 | |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 439 | static ssize_t |
| 440 | event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) |
| 441 | { |
| 442 | struct ftrace_event_call *call = filp->private_data; |
| 443 | struct trace_seq *s; |
| 444 | int r; |
| 445 | |
| 446 | if (*ppos) |
| 447 | return 0; |
| 448 | |
| 449 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 450 | if (!s) |
| 451 | return -ENOMEM; |
| 452 | |
| 453 | trace_seq_init(s); |
| 454 | trace_seq_printf(s, "%d\n", call->id); |
| 455 | |
| 456 | r = simple_read_from_buffer(ubuf, cnt, ppos, |
| 457 | s->buffer, s->len); |
| 458 | kfree(s); |
| 459 | return r; |
| 460 | } |
| 461 | |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame^] | 462 | static ssize_t |
| 463 | event_filter_read(struct file *filp, char __user *ubuf, size_t cnt, |
| 464 | loff_t *ppos) |
| 465 | { |
| 466 | struct ftrace_event_call *call = filp->private_data; |
| 467 | struct trace_seq *s; |
| 468 | int r; |
| 469 | |
| 470 | if (*ppos) |
| 471 | return 0; |
| 472 | |
| 473 | s = kmalloc(sizeof(*s), GFP_KERNEL); |
| 474 | if (!s) |
| 475 | return -ENOMEM; |
| 476 | |
| 477 | trace_seq_init(s); |
| 478 | |
| 479 | r = filter_print_preds(call->preds, s->buffer); |
| 480 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, r); |
| 481 | |
| 482 | kfree(s); |
| 483 | |
| 484 | return r; |
| 485 | } |
| 486 | |
| 487 | static ssize_t |
| 488 | event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, |
| 489 | loff_t *ppos) |
| 490 | { |
| 491 | struct ftrace_event_call *call = filp->private_data; |
| 492 | char buf[64], *pbuf = buf; |
| 493 | struct filter_pred *pred; |
| 494 | int err; |
| 495 | |
| 496 | if (cnt >= sizeof(buf)) |
| 497 | return -EINVAL; |
| 498 | |
| 499 | if (copy_from_user(&buf, ubuf, cnt)) |
| 500 | return -EFAULT; |
| 501 | |
| 502 | pred = kzalloc(sizeof(*pred), GFP_KERNEL); |
| 503 | if (!pred) |
| 504 | return -ENOMEM; |
| 505 | |
| 506 | err = filter_parse(&pbuf, pred); |
| 507 | if (err < 0) { |
| 508 | filter_free_pred(pred); |
| 509 | return err; |
| 510 | } |
| 511 | |
| 512 | if (pred->clear) { |
| 513 | filter_free_preds(call); |
| 514 | return cnt; |
| 515 | } |
| 516 | |
| 517 | if (filter_add_pred(call, pred)) { |
| 518 | filter_free_pred(pred); |
| 519 | return -EINVAL; |
| 520 | } |
| 521 | |
| 522 | *ppos += cnt; |
| 523 | |
| 524 | return cnt; |
| 525 | } |
| 526 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 527 | static const struct seq_operations show_event_seq_ops = { |
| 528 | .start = t_start, |
| 529 | .next = t_next, |
| 530 | .show = t_show, |
| 531 | .stop = t_stop, |
| 532 | }; |
| 533 | |
| 534 | static const struct seq_operations show_set_event_seq_ops = { |
| 535 | .start = s_start, |
| 536 | .next = s_next, |
| 537 | .show = t_show, |
| 538 | .stop = t_stop, |
| 539 | }; |
| 540 | |
Steven Rostedt | 2314c4a | 2009-03-10 12:04:02 -0400 | [diff] [blame] | 541 | static const struct file_operations ftrace_avail_fops = { |
| 542 | .open = ftrace_event_seq_open, |
| 543 | .read = seq_read, |
| 544 | .llseek = seq_lseek, |
| 545 | .release = seq_release, |
| 546 | }; |
| 547 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 548 | static const struct file_operations ftrace_set_event_fops = { |
| 549 | .open = ftrace_event_seq_open, |
| 550 | .read = seq_read, |
| 551 | .write = ftrace_event_write, |
| 552 | .llseek = seq_lseek, |
| 553 | .release = seq_release, |
| 554 | }; |
| 555 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 556 | static const struct file_operations ftrace_enable_fops = { |
| 557 | .open = tracing_open_generic, |
| 558 | .read = event_enable_read, |
| 559 | .write = event_enable_write, |
| 560 | }; |
| 561 | |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 562 | static const struct file_operations ftrace_event_format_fops = { |
| 563 | .open = tracing_open_generic, |
| 564 | .read = event_format_read, |
| 565 | }; |
| 566 | |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 567 | static const struct file_operations ftrace_event_id_fops = { |
| 568 | .open = tracing_open_generic, |
| 569 | .read = event_id_read, |
| 570 | }; |
| 571 | |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame^] | 572 | static const struct file_operations ftrace_event_filter_fops = { |
| 573 | .open = tracing_open_generic, |
| 574 | .read = event_filter_read, |
| 575 | .write = event_filter_write, |
| 576 | }; |
| 577 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 578 | static struct dentry *event_trace_events_dir(void) |
| 579 | { |
| 580 | static struct dentry *d_tracer; |
| 581 | static struct dentry *d_events; |
| 582 | |
| 583 | if (d_events) |
| 584 | return d_events; |
| 585 | |
| 586 | d_tracer = tracing_init_dentry(); |
| 587 | if (!d_tracer) |
| 588 | return NULL; |
| 589 | |
| 590 | d_events = debugfs_create_dir("events", d_tracer); |
| 591 | if (!d_events) |
| 592 | pr_warning("Could not create debugfs " |
| 593 | "'events' directory\n"); |
| 594 | |
| 595 | return d_events; |
| 596 | } |
| 597 | |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 598 | struct event_subsystem { |
| 599 | struct list_head list; |
| 600 | const char *name; |
| 601 | struct dentry *entry; |
| 602 | }; |
| 603 | |
| 604 | static LIST_HEAD(event_subsystems); |
| 605 | |
| 606 | static struct dentry * |
| 607 | event_subsystem_dir(const char *name, struct dentry *d_events) |
| 608 | { |
| 609 | struct event_subsystem *system; |
| 610 | |
| 611 | /* First see if we did not already create this dir */ |
| 612 | list_for_each_entry(system, &event_subsystems, list) { |
| 613 | if (strcmp(system->name, name) == 0) |
| 614 | return system->entry; |
| 615 | } |
| 616 | |
| 617 | /* need to create new entry */ |
| 618 | system = kmalloc(sizeof(*system), GFP_KERNEL); |
| 619 | if (!system) { |
| 620 | pr_warning("No memory to create event subsystem %s\n", |
| 621 | name); |
| 622 | return d_events; |
| 623 | } |
| 624 | |
| 625 | system->entry = debugfs_create_dir(name, d_events); |
| 626 | if (!system->entry) { |
| 627 | pr_warning("Could not create event subsystem %s\n", |
| 628 | name); |
| 629 | kfree(system); |
| 630 | return d_events; |
| 631 | } |
| 632 | |
| 633 | system->name = name; |
| 634 | list_add(&system->list, &event_subsystems); |
| 635 | |
| 636 | return system->entry; |
| 637 | } |
| 638 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 639 | static int |
| 640 | event_create_dir(struct ftrace_event_call *call, struct dentry *d_events) |
| 641 | { |
| 642 | struct dentry *entry; |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 643 | int ret; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 644 | |
Steven Rostedt | 6ecc2d1 | 2009-02-27 21:33:02 -0500 | [diff] [blame] | 645 | /* |
| 646 | * If the trace point header did not define TRACE_SYSTEM |
| 647 | * then the system would be called "TRACE_SYSTEM". |
| 648 | */ |
| 649 | if (strcmp(call->system, "TRACE_SYSTEM") != 0) |
| 650 | d_events = event_subsystem_dir(call->system, d_events); |
| 651 | |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 652 | if (call->raw_init) { |
| 653 | ret = call->raw_init(); |
| 654 | if (ret < 0) { |
| 655 | pr_warning("Could not initialize trace point" |
| 656 | " events/%s\n", call->name); |
| 657 | return ret; |
| 658 | } |
| 659 | } |
| 660 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 661 | call->dir = debugfs_create_dir(call->name, d_events); |
| 662 | if (!call->dir) { |
| 663 | pr_warning("Could not create debugfs " |
| 664 | "'%s' directory\n", call->name); |
| 665 | return -1; |
| 666 | } |
| 667 | |
Steven Rostedt | 770cb24 | 2009-03-05 21:35:29 -0500 | [diff] [blame] | 668 | if (call->regfunc) { |
| 669 | entry = debugfs_create_file("enable", 0644, call->dir, call, |
| 670 | &ftrace_enable_fops); |
| 671 | if (!entry) |
| 672 | pr_warning("Could not create debugfs " |
| 673 | "'%s/enable' entry\n", call->name); |
| 674 | } |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 675 | |
Peter Zijlstra | 23725ae | 2009-03-19 20:26:13 +0100 | [diff] [blame] | 676 | if (call->id) { |
| 677 | entry = debugfs_create_file("id", 0444, call->dir, call, |
| 678 | &ftrace_event_id_fops); |
| 679 | if (!entry) |
| 680 | pr_warning("Could not create debugfs '%s/id' entry\n", |
| 681 | call->name); |
| 682 | } |
| 683 | |
Tom Zanussi | cf027f6 | 2009-03-22 03:30:39 -0500 | [diff] [blame] | 684 | if (call->define_fields) { |
| 685 | ret = call->define_fields(); |
| 686 | if (ret < 0) { |
| 687 | pr_warning("Could not initialize trace point" |
| 688 | " events/%s\n", call->name); |
| 689 | return ret; |
| 690 | } |
| 691 | } |
| 692 | |
Tom Zanussi | 7ce7e42 | 2009-03-22 03:31:04 -0500 | [diff] [blame^] | 693 | entry = debugfs_create_file("filter", 0444, call->dir, call, |
| 694 | &ftrace_event_filter_fops); |
| 695 | if (!entry) |
| 696 | pr_warning("Could not create debugfs " |
| 697 | "'%s/filter' entry\n", call->name); |
| 698 | |
Steven Rostedt | 981d081 | 2009-03-02 13:53:59 -0500 | [diff] [blame] | 699 | /* A trace may not want to export its format */ |
| 700 | if (!call->show_format) |
| 701 | return 0; |
| 702 | |
| 703 | entry = debugfs_create_file("format", 0444, call->dir, call, |
| 704 | &ftrace_event_format_fops); |
| 705 | if (!entry) |
| 706 | pr_warning("Could not create debugfs " |
| 707 | "'%s/format' entry\n", call->name); |
Steven Rostedt | fd99498 | 2009-02-28 02:41:25 -0500 | [diff] [blame] | 708 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 709 | return 0; |
| 710 | } |
| 711 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 712 | static __init int event_trace_init(void) |
| 713 | { |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 714 | struct ftrace_event_call *call = __start_ftrace_events; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 715 | struct dentry *d_tracer; |
| 716 | struct dentry *entry; |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 717 | struct dentry *d_events; |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 718 | |
| 719 | d_tracer = tracing_init_dentry(); |
| 720 | if (!d_tracer) |
| 721 | return 0; |
| 722 | |
Steven Rostedt | 2314c4a | 2009-03-10 12:04:02 -0400 | [diff] [blame] | 723 | entry = debugfs_create_file("available_events", 0444, d_tracer, |
| 724 | (void *)&show_event_seq_ops, |
| 725 | &ftrace_avail_fops); |
| 726 | if (!entry) |
| 727 | pr_warning("Could not create debugfs " |
| 728 | "'available_events' entry\n"); |
| 729 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 730 | entry = debugfs_create_file("set_event", 0644, d_tracer, |
| 731 | (void *)&show_set_event_seq_ops, |
| 732 | &ftrace_set_event_fops); |
| 733 | if (!entry) |
| 734 | pr_warning("Could not create debugfs " |
| 735 | "'set_event' entry\n"); |
| 736 | |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 737 | d_events = event_trace_events_dir(); |
| 738 | if (!d_events) |
| 739 | return 0; |
| 740 | |
Peter Zijlstra | ac199db | 2009-03-19 20:26:15 +0100 | [diff] [blame] | 741 | for_each_event(call) { |
Steven Rostedt | 1473e44 | 2009-02-24 14:15:08 -0500 | [diff] [blame] | 742 | /* The linker may leave blanks */ |
| 743 | if (!call->name) |
| 744 | continue; |
| 745 | event_create_dir(call, d_events); |
| 746 | } |
| 747 | |
Steven Rostedt | b77e38a | 2009-02-24 10:21:36 -0500 | [diff] [blame] | 748 | return 0; |
| 749 | } |
| 750 | fs_initcall(event_trace_init); |