Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754650AbbHJGRj (ORCPT ); Mon, 10 Aug 2015 02:17:39 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:47627 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754473AbbHJGR1 (ORCPT ); Mon, 10 Aug 2015 02:17:27 -0400 From: Wang Nan To: , CC: , , , , , , , , , , , , Subject: [PATCH 03/27] perf tools: Enable passing bpf object file to --event Date: Mon, 10 Aug 2015 06:15:45 +0000 Message-ID: <1439187369-66492-4-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1439187369-66492-1-git-send-email-wangnan0@huawei.com> References: <1439187369-66492-1-git-send-email-wangnan0@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 7607 Lines: 226 By introducing new rules in tools/perf/util/parse-events.[ly], this patch enables 'perf record --event bpf_file.o' to select events by an eBPF object file. It calls parse_events_load_bpf() to load that file, which uses bpf__prepare_load() and finally calls bpf_object__open() for the object files. Instead of introducing evsel to evlist during parsing, events selected by eBPF object files are appended separately. The reason is: 1. During parsing, the probing points have not been initialized. 2. Currently we are unable to call add_perf_probe_events() twice, therefore we have to wait until all such events are collected, then probe all points by one call. The real probing and selecting is reside in following patches. Commiter note: Testing if the event parsing changes indeed call the BPF loading routines: [root@felicio ~]# ls -la foo.o ls: cannot access foo.o: No such file or directory [root@felicio ~]# perf record --event foo.o sleep libbpf: failed to open foo.o: No such file or directory bpf: failed to load foo.o invalid or unsupported event: 'foo.o' Run 'perf list' for a list of valid events usage: perf record [] [] or: perf record [] -- [] -e, --event event selector. use 'perf list' to list available events [root@felicio ~]# Yes, it does this time around. Signed-off-by: Wang Nan Acked-by: Alexei Starovoitov Tested-by: Arnaldo Carvalho de Melo Cc: Brendan Gregg Cc: Daniel Borkmann Cc: David Ahern Cc: He Kuang Cc: Jiri Olsa Cc: Kaixu Xia Cc: Masami Hiramatsu Cc: Namhyung Kim Cc: Peter Zijlstra Cc: Zefan Li Cc: pi3orama@163.com Link: http://lkml.kernel.org/n/1436445342-1402-19-git-send-email-wangnan0@huawei.com [ The veprintf() and bpf loader parts were split from this one ] Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/Build | 1 + tools/perf/util/parse-events.c | 26 ++++++++++++++++++++++++++ tools/perf/util/parse-events.h | 3 +++ tools/perf/util/parse-events.l | 3 +++ tools/perf/util/parse-events.y | 18 +++++++++++++++++- 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/Build b/tools/perf/util/Build index 1ce0adc..309b2d2 100644 --- a/tools/perf/util/Build +++ b/tools/perf/util/Build @@ -80,6 +80,7 @@ libperf-y += thread-stack.o libperf-$(CONFIG_AUXTRACE) += auxtrace.o libperf-y += parse-branch-options.o +libperf-$(CONFIG_LIBBPF) += bpf-loader.o libperf-$(CONFIG_LIBELF) += symbol-elf.o libperf-$(CONFIG_LIBELF) += probe-file.o libperf-$(CONFIG_LIBELF) += probe-event.o diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 828936d..dc5a03c 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -19,6 +19,7 @@ #include "thread_map.h" #include "cpumap.h" #include "asm/bug.h" +#include "bpf-loader.h" #define MAX_NAME_LEN 100 @@ -481,6 +482,31 @@ int parse_events_add_tracepoint(struct list_head *list, int *idx, return add_tracepoint_event(list, idx, sys, event); } +int parse_events_load_bpf(struct parse_events_evlist *data, + struct list_head *list __maybe_unused, + char *bpf_file_name) +{ + int err; + char errbuf[BUFSIZ]; + + /* + * Currently don't link any event to list. BPF object files + * should be saved to a seprated list and processed together. + * + * Things could be changed if we solve perf probe reentering + * problem. After that probe events file by file is possible. + * However, probing cost is still need to be considered. + */ + err = bpf__prepare_load(bpf_file_name); + if (err) { + bpf__strerror_prepare_load(bpf_file_name, err, + errbuf, sizeof(errbuf)); + data->error->str = strdup(errbuf); + data->error->help = strdup("(add -v to see detail)"); + } + return err; +} + static int parse_breakpoint_type(const char *type, struct perf_event_attr *attr) { diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h index e6f9aacc..51ca930 100644 --- a/tools/perf/util/parse-events.h +++ b/tools/perf/util/parse-events.h @@ -116,6 +116,9 @@ int parse_events__modifier_group(struct list_head *list, char *event_mod); int parse_events_name(struct list_head *list, char *name); int parse_events_add_tracepoint(struct list_head *list, int *idx, char *sys, char *event); +int parse_events_load_bpf(struct parse_events_evlist *data, + struct list_head *list, + char *bpf_file_name); int parse_events_add_numeric(struct parse_events_evlist *data, struct list_head *list, u32 type, u64 config, diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index f542750..1067caf 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -115,6 +115,7 @@ do { \ group [^,{}/]*[{][^}]*[}][^,{}/]* event_pmu [^,{}/]+[/][^/]*[/][^,{}/]* event [^,{}/]+ +bpf_object .*\.(o|bpf) num_dec [0-9]+ num_hex 0x[a-fA-F0-9]+ @@ -159,6 +160,7 @@ modifier_bp [rwx]{1,3} } {event_pmu} | +{bpf_object} | {event} { BEGIN(INITIAL); REWIND(1); @@ -261,6 +263,7 @@ r{num_raw_hex} { return raw(yyscanner); } {num_hex} { return value(yyscanner, 16); } {modifier_event} { return str(yyscanner, PE_MODIFIER_EVENT); } +{bpf_object} { return str(yyscanner, PE_BPF_OBJECT); } {name} { return pmu_str_check(yyscanner); } "/" { BEGIN(config); return '/'; } - { return '-'; } diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index 591905a..3ee3a32 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -42,6 +42,7 @@ static inc_group_count(struct list_head *list, %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM %token PE_EVENT_NAME %token PE_NAME +%token PE_BPF_OBJECT %token PE_MODIFIER_EVENT PE_MODIFIER_BP %token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT %token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP @@ -53,6 +54,7 @@ static inc_group_count(struct list_head *list, %type PE_RAW %type PE_TERM %type PE_NAME +%type PE_BPF_OBJECT %type PE_NAME_CACHE_TYPE %type PE_NAME_CACHE_OP_RESULT %type PE_MODIFIER_EVENT @@ -69,6 +71,7 @@ static inc_group_count(struct list_head *list, %type event_legacy_tracepoint %type event_legacy_numeric %type event_legacy_raw +%type event_bpf_file %type event_def %type event_mod %type event_name @@ -198,7 +201,8 @@ event_def: event_pmu | event_legacy_mem | event_legacy_tracepoint sep_dc | event_legacy_numeric sep_dc | - event_legacy_raw sep_dc + event_legacy_raw sep_dc | + event_bpf_file event_pmu: PE_NAME '/' event_config '/' @@ -420,6 +424,18 @@ PE_RAW $$ = list; } +event_bpf_file: +PE_BPF_OBJECT +{ + struct parse_events_evlist *data = _data; + struct list_head *list; + + ALLOC_LIST(list); + ABORT_ON(parse_events_load_bpf(data, list, $1)); + $$ = list; +} + + start_terms: event_config { struct parse_events_terms *data = _data; -- 1.8.3.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/