diff options
Diffstat (limited to 'kernel/trace/trace_events.c')
| -rw-r--r-- | kernel/trace/trace_events.c | 203 |
1 files changed, 196 insertions, 7 deletions
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c index 3047b56f6637..64ec4d278ffb 100644 --- a/kernel/trace/trace_events.c +++ b/kernel/trace/trace_events.c | |||
| @@ -19,6 +19,39 @@ | |||
| 19 | 19 | ||
| 20 | static DEFINE_MUTEX(event_mutex); | 20 | static DEFINE_MUTEX(event_mutex); |
| 21 | 21 | ||
| 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 = kzalloc(sizeof(*field), GFP_KERNEL); | ||
| 28 | if (!field) | ||
| 29 | goto err; | ||
| 30 | |||
| 31 | field->name = kstrdup(name, GFP_KERNEL); | ||
| 32 | if (!field->name) | ||
| 33 | goto err; | ||
| 34 | |||
| 35 | field->type = kstrdup(type, GFP_KERNEL); | ||
| 36 | if (!field->type) | ||
| 37 | goto err; | ||
| 38 | |||
| 39 | field->offset = offset; | ||
| 40 | field->size = size; | ||
| 41 | list_add(&field->link, &call->fields); | ||
| 42 | |||
| 43 | return 0; | ||
| 44 | |||
| 45 | err: | ||
| 46 | if (field) { | ||
| 47 | kfree(field->name); | ||
| 48 | kfree(field->type); | ||
| 49 | } | ||
| 50 | kfree(field); | ||
| 51 | |||
| 52 | return -ENOMEM; | ||
| 53 | } | ||
| 54 | |||
| 22 | static void ftrace_clear_events(void) | 55 | static void ftrace_clear_events(void) |
| 23 | { | 56 | { |
| 24 | struct ftrace_event_call *call = (void *)__start_ftrace_events; | 57 | struct ftrace_event_call *call = (void *)__start_ftrace_events; |
| @@ -343,7 +376,8 @@ event_enable_write(struct file *filp, const char __user *ubuf, size_t cnt, | |||
| 343 | 376 | ||
| 344 | #undef FIELD | 377 | #undef FIELD |
| 345 | #define FIELD(type, name) \ | 378 | #define FIELD(type, name) \ |
| 346 | #type, #name, offsetof(typeof(field), name), sizeof(field.name) | 379 | #type, "common_" #name, offsetof(typeof(field), name), \ |
| 380 | sizeof(field.name) | ||
| 347 | 381 | ||
| 348 | static int trace_write_header(struct trace_seq *s) | 382 | static int trace_write_header(struct trace_seq *s) |
| 349 | { | 383 | { |
| @@ -430,6 +464,139 @@ event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) | |||
| 430 | return r; | 464 | return r; |
| 431 | } | 465 | } |
| 432 | 466 | ||
| 467 | static ssize_t | ||
| 468 | event_filter_read(struct file *filp, char __user *ubuf, size_t cnt, | ||
| 469 | loff_t *ppos) | ||
| 470 | { | ||
| 471 | struct ftrace_event_call *call = filp->private_data; | ||
| 472 | struct trace_seq *s; | ||
| 473 | int r; | ||
| 474 | |||
| 475 | if (*ppos) | ||
| 476 | return 0; | ||
| 477 | |||
| 478 | s = kmalloc(sizeof(*s), GFP_KERNEL); | ||
| 479 | if (!s) | ||
| 480 | return -ENOMEM; | ||
| 481 | |||
| 482 | trace_seq_init(s); | ||
| 483 | |||
| 484 | filter_print_preds(call->preds, s); | ||
| 485 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); | ||
| 486 | |||
| 487 | kfree(s); | ||
| 488 | |||
| 489 | return r; | ||
| 490 | } | ||
| 491 | |||
| 492 | static ssize_t | ||
| 493 | event_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, | ||
| 494 | loff_t *ppos) | ||
| 495 | { | ||
| 496 | struct ftrace_event_call *call = filp->private_data; | ||
| 497 | char buf[64], *pbuf = buf; | ||
| 498 | struct filter_pred *pred; | ||
| 499 | int err; | ||
| 500 | |||
| 501 | if (cnt >= sizeof(buf)) | ||
| 502 | return -EINVAL; | ||
| 503 | |||
| 504 | if (copy_from_user(&buf, ubuf, cnt)) | ||
| 505 | return -EFAULT; | ||
| 506 | |||
| 507 | pred = kzalloc(sizeof(*pred), GFP_KERNEL); | ||
| 508 | if (!pred) | ||
| 509 | return -ENOMEM; | ||
| 510 | |||
| 511 | err = filter_parse(&pbuf, pred); | ||
| 512 | if (err < 0) { | ||
| 513 | filter_free_pred(pred); | ||
| 514 | return err; | ||
| 515 | } | ||
| 516 | |||
| 517 | if (pred->clear) { | ||
| 518 | filter_free_preds(call); | ||
| 519 | filter_free_pred(pred); | ||
| 520 | return cnt; | ||
| 521 | } | ||
| 522 | |||
| 523 | if (filter_add_pred(call, pred)) { | ||
| 524 | filter_free_pred(pred); | ||
| 525 | return -EINVAL; | ||
| 526 | } | ||
| 527 | |||
| 528 | *ppos += cnt; | ||
| 529 | |||
| 530 | return cnt; | ||
| 531 | } | ||
| 532 | |||
| 533 | static ssize_t | ||
| 534 | subsystem_filter_read(struct file *filp, char __user *ubuf, size_t cnt, | ||
| 535 | loff_t *ppos) | ||
| 536 | { | ||
| 537 | struct event_subsystem *system = filp->private_data; | ||
| 538 | struct trace_seq *s; | ||
| 539 | int r; | ||
| 540 | |||
| 541 | if (*ppos) | ||
| 542 | return 0; | ||
| 543 | |||
| 544 | s = kmalloc(sizeof(*s), GFP_KERNEL); | ||
| 545 | if (!s) | ||
| 546 | return -ENOMEM; | ||
| 547 | |||
| 548 | trace_seq_init(s); | ||
| 549 | |||
| 550 | filter_print_preds(system->preds, s); | ||
| 551 | r = simple_read_from_buffer(ubuf, cnt, ppos, s->buffer, s->len); | ||
| 552 | |||
| 553 | kfree(s); | ||
| 554 | |||
| 555 | return r; | ||
| 556 | } | ||
| 557 | |||
| 558 | static ssize_t | ||
| 559 | subsystem_filter_write(struct file *filp, const char __user *ubuf, size_t cnt, | ||
| 560 | loff_t *ppos) | ||
| 561 | { | ||
| 562 | struct event_subsystem *system = filp->private_data; | ||
| 563 | char buf[64], *pbuf = buf; | ||
| 564 | struct filter_pred *pred; | ||
| 565 | int err; | ||
| 566 | |||
| 567 | if (cnt >= sizeof(buf)) | ||
| 568 | return -EINVAL; | ||
| 569 | |||
| 570 | if (copy_from_user(&buf, ubuf, cnt)) | ||
| 571 | return -EFAULT; | ||
| 572 | |||
| 573 | pred = kzalloc(sizeof(*pred), GFP_KERNEL); | ||
| 574 | if (!pred) | ||
| 575 | return -ENOMEM; | ||
| 576 | |||
| 577 | err = filter_parse(&pbuf, pred); | ||
| 578 | if (err < 0) { | ||
| 579 | filter_free_pred(pred); | ||
| 580 | return err; | ||
| 581 | } | ||
| 582 | |||
| 583 | if (pred->clear) { | ||
| 584 | filter_free_subsystem_preds(system); | ||
| 585 | filter_free_pred(pred); | ||
| 586 | return cnt; | ||
| 587 | } | ||
| 588 | |||
| 589 | if (filter_add_subsystem_pred(system, pred)) { | ||
| 590 | filter_free_subsystem_preds(system); | ||
| 591 | filter_free_pred(pred); | ||
| 592 | return -EINVAL; | ||
| 593 | } | ||
| 594 | |||
| 595 | *ppos += cnt; | ||
| 596 | |||
| 597 | return cnt; | ||
| 598 | } | ||
| 599 | |||
| 433 | static const struct seq_operations show_event_seq_ops = { | 600 | static const struct seq_operations show_event_seq_ops = { |
| 434 | .start = t_start, | 601 | .start = t_start, |
| 435 | .next = t_next, | 602 | .next = t_next, |
| @@ -475,6 +642,18 @@ static const struct file_operations ftrace_event_id_fops = { | |||
| 475 | .read = event_id_read, | 642 | .read = event_id_read, |
| 476 | }; | 643 | }; |
| 477 | 644 | ||
| 645 | static const struct file_operations ftrace_event_filter_fops = { | ||
| 646 | .open = tracing_open_generic, | ||
| 647 | .read = event_filter_read, | ||
| 648 | .write = event_filter_write, | ||
| 649 | }; | ||
| 650 | |||
| 651 | static const struct file_operations ftrace_subsystem_filter_fops = { | ||
| 652 | .open = tracing_open_generic, | ||
| 653 | .read = subsystem_filter_read, | ||
| 654 | .write = subsystem_filter_write, | ||
| 655 | }; | ||
| 656 | |||
| 478 | static struct dentry *event_trace_events_dir(void) | 657 | static struct dentry *event_trace_events_dir(void) |
| 479 | { | 658 | { |
| 480 | static struct dentry *d_tracer; | 659 | static struct dentry *d_tracer; |
| @@ -495,12 +674,6 @@ static struct dentry *event_trace_events_dir(void) | |||
| 495 | return d_events; | 674 | return d_events; |
| 496 | } | 675 | } |
| 497 | 676 | ||
| 498 | struct event_subsystem { | ||
| 499 | struct list_head list; | ||
| 500 | const char *name; | ||
| 501 | struct dentry *entry; | ||
| 502 | }; | ||
| 503 | |||
| 504 | static LIST_HEAD(event_subsystems); | 677 | static LIST_HEAD(event_subsystems); |
| 505 | 678 | ||
| 506 | static struct dentry * | 679 | static struct dentry * |
| @@ -533,6 +706,8 @@ event_subsystem_dir(const char *name, struct dentry *d_events) | |||
| 533 | system->name = name; | 706 | system->name = name; |
| 534 | list_add(&system->list, &event_subsystems); | 707 | list_add(&system->list, &event_subsystems); |
| 535 | 708 | ||
| 709 | system->preds = NULL; | ||
| 710 | |||
| 536 | return system->entry; | 711 | return system->entry; |
| 537 | } | 712 | } |
| 538 | 713 | ||
| @@ -581,6 +756,20 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events) | |||
| 581 | call->name); | 756 | call->name); |
| 582 | } | 757 | } |
| 583 | 758 | ||
| 759 | if (call->define_fields) { | ||
| 760 | ret = call->define_fields(); | ||
| 761 | if (ret < 0) { | ||
| 762 | pr_warning("Could not initialize trace point" | ||
| 763 | " events/%s\n", call->name); | ||
| 764 | return ret; | ||
| 765 | } | ||
| 766 | entry = debugfs_create_file("filter", 0644, call->dir, call, | ||
| 767 | &ftrace_event_filter_fops); | ||
| 768 | if (!entry) | ||
| 769 | pr_warning("Could not create debugfs " | ||
| 770 | "'%s/filter' entry\n", call->name); | ||
| 771 | } | ||
| 772 | |||
| 584 | /* A trace may not want to export its format */ | 773 | /* A trace may not want to export its format */ |
| 585 | if (!call->show_format) | 774 | if (!call->show_format) |
| 586 | return 0; | 775 | return 0; |
