From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752541AbbJQKtV (ORCPT ); Sat, 17 Oct 2015 06:49:21 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:7832 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751365AbbJQKtS (ORCPT ); Sat, 17 Oct 2015 06:49:18 -0400 From: Wang Nan To: , , CC: , , , , , , , , , , , , Wang Nan , Arnaldo Carvalho de Melo Subject: [RFC PATCH 6/7] perf tools: Enable indics setting syntax for BPF maps Date: Sat, 17 Oct 2015 10:48:29 +0000 Message-ID: <1445078910-73699-7-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 In-Reply-To: <1445078910-73699-1-git-send-email-wangnan0@huawei.com> References: <1445078910-73699-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 This patch introduce a new syntax to perf event parser: # perf record -e bpf_file.c/maps.mymap.value[0,3-5,7]=1234/ ... By utilizing the basic facilities in bpf-loader.c which allow setting different slots in a BPF map separately, the newly introduced syntax allows perf to control specific elements in a BPF map. Signed-off-by: Wang Nan Cc: Arnaldo Carvalho de Melo Cc: Alexei Starovoitov 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: Paul Mackerras Cc: Peter Zijlstra Cc: Zefan Li Cc: pi3orama@163.com --- tools/perf/util/parse-events.c | 4 +- tools/perf/util/parse-events.l | 11 +++++ tools/perf/util/parse-events.y | 92 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c index 42ac1cb..a2af5a8 100644 --- a/tools/perf/util/parse-events.c +++ b/tools/perf/util/parse-events.c @@ -654,7 +654,9 @@ parse_events_config_bpf(struct parse_events_evlist *data, err, errbuf, sizeof(errbuf)); data->error->help = strdup( "Hint:\tValid config term:\n" -" \tmaps..value\n" +" \tmaps..value\n" +"\n" +" \twhere is something like [0,3-4]\n" " \t(add -v to see detail)"); data->error->str = strdup(errbuf); if (err == -EINVAL) diff --git a/tools/perf/util/parse-events.l b/tools/perf/util/parse-events.l index eeea4e1..0d92a4d 100644 --- a/tools/perf/util/parse-events.l +++ b/tools/perf/util/parse-events.l @@ -111,6 +111,7 @@ do { \ %x mem %s config %x event +%x array group [^,{}/]*[{][^}]*[}][^,{}/]* event_pmu [^,{}/]+[/][^/]*[/][^,{}/]* @@ -176,6 +177,14 @@ modifier_bp [rwx]{1,3} } +{ +"]" { BEGIN(config); return ']'; } +{num_dec} { return value(yyscanner, 10); } +{num_hex} { return value(yyscanner, 16); } +, { return ','; } +- { return '-'; } +} + { /* * Please update parse_events_formats_error_string any time @@ -194,6 +203,8 @@ stack-size { return term(yyscanner, PARSE_EVENTS__TERM_TYPE_STACKSIZE); } , { return ','; } "/" { BEGIN(INITIAL); return '/'; } {name_minus} { return str(yyscanner, PE_NAME); } +\[all\] { return PE_ARRAY_ALL; } +"[" { BEGIN(array); return '['; } } { diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y index 255387a..81fe702 100644 --- a/tools/perf/util/parse-events.y +++ b/tools/perf/util/parse-events.y @@ -48,6 +48,7 @@ static inc_group_count(struct list_head *list, %token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP %token PE_ERROR %token PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT +%token PE_ARRAY_ALL %type PE_VALUE %type PE_VALUE_SYM_HW %type PE_VALUE_SYM_SW @@ -84,6 +85,9 @@ static inc_group_count(struct list_head *list, %type group_def %type group %type groups +%type array +%type array_term +%type array_terms %union { @@ -95,6 +99,10 @@ static inc_group_count(struct list_head *list, char *sys; char *event; } tracepoint_name; + struct array { + size_t nr_indics; + u64 *indics; + } array; } %% @@ -599,6 +607,90 @@ PE_TERM ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, &@1, NULL)); $$ = term; } +| +PE_NAME array '=' PE_NAME +{ + struct parse_events_term *term; + int i; + + ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, + $1, $4, &@1, &@4)); + + term->nr_indics = $2.nr_indics; + term->indics = $2.indics; + $$ = term; +} +| +PE_NAME array '=' PE_VALUE +{ + struct parse_events_term *term; + + ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, + $1, $4, &@1, &@4)); + term->nr_indics = $2.nr_indics; + term->indics = $2.indics; + $$ = term; +} + +array: +'[' array_terms ']' +{ + $$ = $2; +} +| +PE_ARRAY_ALL +{ + $$.nr_indics = 0; + $$.indics = NULL; +} + +array_terms: +array_terms ',' array_term +{ + struct array array = $1; + struct array new_array = $3; + u64 *new_indics; + + new_indics = realloc(array.indics, + (array.nr_indics + new_array.nr_indics) * sizeof(u64)); + ABORT_ON(!new_indics); + + memcpy(&new_indics[array.nr_indics], new_array.indics, + sizeof(u64) * new_array.nr_indics); + + array.nr_indics += new_array.nr_indics; + array.indics = new_indics; + free(new_array.indics); + $$ = array; +} +| +array_term + +array_term: +PE_VALUE +{ + struct array array; + array.nr_indics = 1; + array.indics = malloc(sizeof(u64)); + ABORT_ON(!array.indics); + array.indics[0] = $1; + $$ = array; +} +| +PE_VALUE '-' PE_VALUE +{ + struct array array; + int i; + + ABORT_ON($3 < $1); + array.nr_indics = $3 - $1 + 1; + array.indics = malloc(sizeof(u64) * array.nr_indics); + ABORT_ON(!array.indics); + + for (i = 0; i < array.nr_indics; i++) + array.indics[i] = $1 + i; + $$ = array; +} sep_dc: ':' | -- 1.8.3.4