Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

perf parse-events: Populate error column for BPF/tracepoint events

Follow convention from parse_events_terms__num/str and pass the
YYLTYPE for the location.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: bpf@vger.kernel.org
Link: https://lore.kernel.org/r/20230627181030.95608-12-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Ian Rogers and committed by
Arnaldo Carvalho de Melo
d81fa63b b30d4f0b

+57 -39
+1 -1
tools/perf/tests/bpf.c
··· 124 124 parse_state.error = &parse_error; 125 125 INIT_LIST_HEAD(&parse_state.list); 126 126 127 - err = parse_events_load_bpf_obj(&parse_state, &parse_state.list, obj, NULL); 127 + err = parse_events_load_bpf_obj(&parse_state, &parse_state.list, obj, NULL, NULL); 128 128 parse_events_error__exit(&parse_error); 129 129 if (err == -ENODATA) { 130 130 pr_debug("Failed to add events selected by BPF, debuginfo package not installed\n");
+48 -32
tools/perf/util/parse-events.c
··· 499 499 500 500 #ifdef HAVE_LIBTRACEEVENT 501 501 static void tracepoint_error(struct parse_events_error *e, int err, 502 - const char *sys, const char *name) 502 + const char *sys, const char *name, int column) 503 503 { 504 504 const char *str; 505 505 char help[BUFSIZ]; ··· 526 526 } 527 527 528 528 tracing_path__strerror_open_tp(err, help, sizeof(help), sys, name); 529 - parse_events_error__handle(e, 0, strdup(str), strdup(help)); 529 + parse_events_error__handle(e, column, strdup(str), strdup(help)); 530 530 } 531 531 532 532 static int add_tracepoint(struct list_head *list, int *idx, 533 533 const char *sys_name, const char *evt_name, 534 534 struct parse_events_error *err, 535 - struct list_head *head_config) 535 + struct list_head *head_config, void *loc_) 536 536 { 537 + YYLTYPE *loc = loc_; 537 538 struct evsel *evsel = evsel__newtp_idx(sys_name, evt_name, (*idx)++); 538 539 539 540 if (IS_ERR(evsel)) { 540 - tracepoint_error(err, PTR_ERR(evsel), sys_name, evt_name); 541 + tracepoint_error(err, PTR_ERR(evsel), sys_name, evt_name, loc->first_column); 541 542 return PTR_ERR(evsel); 542 543 } 543 544 ··· 557 556 static int add_tracepoint_multi_event(struct list_head *list, int *idx, 558 557 const char *sys_name, const char *evt_name, 559 558 struct parse_events_error *err, 560 - struct list_head *head_config) 559 + struct list_head *head_config, YYLTYPE *loc) 561 560 { 562 561 char *evt_path; 563 562 struct dirent *evt_ent; ··· 566 565 567 566 evt_path = get_events_file(sys_name); 568 567 if (!evt_path) { 569 - tracepoint_error(err, errno, sys_name, evt_name); 568 + tracepoint_error(err, errno, sys_name, evt_name, loc->first_column); 570 569 return -1; 571 570 } 572 571 evt_dir = opendir(evt_path); 573 572 if (!evt_dir) { 574 573 put_events_file(evt_path); 575 - tracepoint_error(err, errno, sys_name, evt_name); 574 + tracepoint_error(err, errno, sys_name, evt_name, loc->first_column); 576 575 return -1; 577 576 } 578 577 ··· 589 588 found++; 590 589 591 590 ret = add_tracepoint(list, idx, sys_name, evt_ent->d_name, 592 - err, head_config); 591 + err, head_config, loc); 593 592 } 594 593 595 594 if (!found) { 596 - tracepoint_error(err, ENOENT, sys_name, evt_name); 595 + tracepoint_error(err, ENOENT, sys_name, evt_name, loc->first_column); 597 596 ret = -1; 598 597 } 599 598 ··· 605 604 static int add_tracepoint_event(struct list_head *list, int *idx, 606 605 const char *sys_name, const char *evt_name, 607 606 struct parse_events_error *err, 608 - struct list_head *head_config) 607 + struct list_head *head_config, YYLTYPE *loc) 609 608 { 610 609 return strpbrk(evt_name, "*?") ? 611 - add_tracepoint_multi_event(list, idx, sys_name, evt_name, 612 - err, head_config) : 613 - add_tracepoint(list, idx, sys_name, evt_name, 614 - err, head_config); 610 + add_tracepoint_multi_event(list, idx, sys_name, evt_name, 611 + err, head_config, loc) : 612 + add_tracepoint(list, idx, sys_name, evt_name, 613 + err, head_config, loc); 615 614 } 616 615 617 616 static int add_tracepoint_multi_sys(struct list_head *list, int *idx, 618 617 const char *sys_name, const char *evt_name, 619 618 struct parse_events_error *err, 620 - struct list_head *head_config) 619 + struct list_head *head_config, YYLTYPE *loc) 621 620 { 622 621 struct dirent *events_ent; 623 622 DIR *events_dir; ··· 625 624 626 625 events_dir = tracing_events__opendir(); 627 626 if (!events_dir) { 628 - tracepoint_error(err, errno, sys_name, evt_name); 627 + tracepoint_error(err, errno, sys_name, evt_name, loc->first_column); 629 628 return -1; 630 629 } 631 630 ··· 641 640 continue; 642 641 643 642 ret = add_tracepoint_event(list, idx, events_ent->d_name, 644 - evt_name, err, head_config); 643 + evt_name, err, head_config, loc); 645 644 } 646 645 647 646 closedir(events_dir); ··· 654 653 struct parse_events_state *parse_state; 655 654 struct list_head *list; 656 655 struct list_head *head_config; 656 + YYLTYPE *loc; 657 657 }; 658 658 659 659 static int add_bpf_event(const char *group, const char *event, int fd, struct bpf_object *obj, ··· 681 679 682 680 err = parse_events_add_tracepoint(&new_evsels, &parse_state->idx, group, 683 681 event, parse_state->error, 684 - param->head_config); 682 + param->head_config, param->loc); 685 683 if (err) { 686 684 struct evsel *evsel, *tmp; 687 685 ··· 708 706 int parse_events_load_bpf_obj(struct parse_events_state *parse_state, 709 707 struct list_head *list, 710 708 struct bpf_object *obj, 711 - struct list_head *head_config) 709 + struct list_head *head_config, 710 + void *loc) 712 711 { 713 712 int err; 714 713 char errbuf[BUFSIZ]; 715 - struct __add_bpf_event_param param = {parse_state, list, head_config}; 714 + struct __add_bpf_event_param param = {parse_state, list, head_config, loc}; 716 715 static bool registered_unprobe_atexit = false; 716 + YYLTYPE test_loc = {.first_column = -1}; 717 717 718 718 if (IS_ERR(obj) || !obj) { 719 719 snprintf(errbuf, sizeof(errbuf), ··· 746 742 goto errout; 747 743 } 748 744 745 + if (!param.loc) 746 + param.loc = &test_loc; 747 + 749 748 err = bpf__foreach_event(obj, add_bpf_event, &param); 750 749 if (err) { 751 750 snprintf(errbuf, sizeof(errbuf), ··· 758 751 759 752 return 0; 760 753 errout: 761 - parse_events_error__handle(parse_state->error, 0, 754 + parse_events_error__handle(parse_state->error, param.loc->first_column, 762 755 strdup(errbuf), strdup("(add -v to see detail)")); 763 756 return err; 764 757 } ··· 846 839 struct list_head *list, 847 840 char *bpf_file_name, 848 841 bool source, 849 - struct list_head *head_config) 842 + struct list_head *head_config, 843 + void *loc_) 850 844 { 851 845 int err; 852 846 struct bpf_object *obj; 853 847 LIST_HEAD(obj_head_config); 848 + YYLTYPE *loc = loc_; 854 849 855 850 if (head_config) 856 851 split_bpf_config_terms(head_config, &obj_head_config); ··· 872 863 -err, errbuf, 873 864 sizeof(errbuf)); 874 865 875 - parse_events_error__handle(parse_state->error, 0, 866 + parse_events_error__handle(parse_state->error, loc->first_column, 876 867 strdup(errbuf), strdup("(add -v to see detail)")); 877 868 return err; 878 869 } 879 870 880 - err = parse_events_load_bpf_obj(parse_state, list, obj, head_config); 871 + err = parse_events_load_bpf_obj(parse_state, list, obj, head_config, loc); 881 872 if (err) 882 873 return err; 883 874 err = parse_events_config_bpf(parse_state, obj, &obj_head_config); ··· 894 885 int parse_events_load_bpf_obj(struct parse_events_state *parse_state, 895 886 struct list_head *list __maybe_unused, 896 887 struct bpf_object *obj __maybe_unused, 897 - struct list_head *head_config __maybe_unused) 888 + struct list_head *head_config __maybe_unused, 889 + void *loc_) 898 890 { 899 - parse_events_error__handle(parse_state->error, 0, 891 + YYLTYPE *loc = loc_; 892 + 893 + parse_events_error__handle(parse_state->error, loc->first_column, 900 894 strdup("BPF support is not compiled"), 901 895 strdup("Make sure libbpf-devel is available at build time.")); 902 896 return -ENOTSUP; ··· 909 897 struct list_head *list __maybe_unused, 910 898 char *bpf_file_name __maybe_unused, 911 899 bool source __maybe_unused, 912 - struct list_head *head_config __maybe_unused) 900 + struct list_head *head_config __maybe_unused, 901 + void *loc_) 913 902 { 914 - parse_events_error__handle(parse_state->error, 0, 903 + YYLTYPE *loc = loc_; 904 + 905 + parse_events_error__handle(parse_state->error, loc->first_column, 915 906 strdup("BPF support is not compiled"), 916 907 strdup("Make sure libbpf-devel is available at build time.")); 917 908 return -ENOTSUP; ··· 1456 1441 int parse_events_add_tracepoint(struct list_head *list, int *idx, 1457 1442 const char *sys, const char *event, 1458 1443 struct parse_events_error *err, 1459 - struct list_head *head_config) 1444 + struct list_head *head_config, void *loc_) 1460 1445 { 1446 + YYLTYPE *loc = loc_; 1461 1447 #ifdef HAVE_LIBTRACEEVENT 1462 1448 if (head_config) { 1463 1449 struct perf_event_attr attr; ··· 1470 1454 1471 1455 if (strpbrk(sys, "*?")) 1472 1456 return add_tracepoint_multi_sys(list, idx, sys, event, 1473 - err, head_config); 1457 + err, head_config, loc); 1474 1458 else 1475 1459 return add_tracepoint_event(list, idx, sys, event, 1476 - err, head_config); 1460 + err, head_config, loc); 1477 1461 #else 1478 1462 (void)list; 1479 1463 (void)idx; 1480 1464 (void)sys; 1481 1465 (void)event; 1482 1466 (void)head_config; 1483 - parse_events_error__handle(err, 0, strdup("unsupported tracepoint"), 1467 + parse_events_error__handle(err, loc->first_column, strdup("unsupported tracepoint"), 1484 1468 strdup("libtraceevent is necessary for tracepoint support")); 1485 1469 return -1; 1486 1470 #endif
+5 -3
tools/perf/util/parse-events.h
··· 169 169 int parse_events_add_tracepoint(struct list_head *list, int *idx, 170 170 const char *sys, const char *event, 171 171 struct parse_events_error *error, 172 - struct list_head *head_config); 172 + struct list_head *head_config, void *loc); 173 173 int parse_events_load_bpf(struct parse_events_state *parse_state, 174 174 struct list_head *list, 175 175 char *bpf_file_name, 176 176 bool source, 177 - struct list_head *head_config); 177 + struct list_head *head_config, 178 + void *loc); 178 179 /* Provide this function for perf test */ 179 180 struct bpf_object; 180 181 int parse_events_load_bpf_obj(struct parse_events_state *parse_state, 181 182 struct list_head *list, 182 183 struct bpf_object *obj, 183 - struct list_head *head_config); 184 + struct list_head *head_config, 185 + void *loc); 184 186 int parse_events_add_numeric(struct parse_events_state *parse_state, 185 187 struct list_head *list, 186 188 u32 type, u64 config,
+3 -3
tools/perf/util/parse-events.y
··· 567 567 error->idx = @1.first_column; 568 568 569 569 err = parse_events_add_tracepoint(list, &parse_state->idx, $1.sys, $1.event, 570 - error, $2); 570 + error, $2, &@1); 571 571 572 572 parse_events_terms__delete($2); 573 573 free($1.sys); ··· 640 640 list = alloc_list(); 641 641 if (!list) 642 642 YYNOMEM; 643 - err = parse_events_load_bpf(parse_state, list, $1, false, $2); 643 + err = parse_events_load_bpf(parse_state, list, $1, false, $2, &@1); 644 644 parse_events_terms__delete($2); 645 645 free($1); 646 646 if (err) { ··· 658 658 list = alloc_list(); 659 659 if (!list) 660 660 YYNOMEM; 661 - err = parse_events_load_bpf(_parse_state, list, $1, true, $2); 661 + err = parse_events_load_bpf(_parse_state, list, $1, true, $2, &@1); 662 662 parse_events_terms__delete($2); 663 663 if (err) { 664 664 free(list);