mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wang Nan <wangnan0@huawei.com>
To: <acme@kernel.org>, <ast@plumgrid.com>, <brendan.d.gregg@gmail.com>
Cc: <a.p.zijlstra@chello.nl>, <daniel@iogearbox.net>,
	<dsahern@gmail.com>, <hekuang@huawei.com>, <jolsa@kernel.org>,
	<lizefan@huawei.com>, <masami.hiramatsu.pt@hitachi.com>,
	<namhyung@kernel.org>, <paulus@samba.org>,
	<linux-kernel@vger.kernel.org>, <pi3orama@163.com>,
	<xiakaixu@huawei.com>, Wang Nan <wangnan0@huawei.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>
Subject: [RFC PATCH 6/7] perf tools: Enable indics setting syntax for BPF maps
Date: Sat, 17 Oct 2015 10:48:29 +0000	[thread overview]
Message-ID: <1445078910-73699-7-git-send-email-wangnan0@huawei.com> (raw)
In-Reply-To: <1445078910-73699-1-git-send-email-wangnan0@huawei.com>

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 <wangnan0@huawei.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Alexei Starovoitov <ast@plumgrid.com>
Cc: Brendan Gregg <brendan.d.gregg@gmail.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>
Cc: David Ahern <dsahern@gmail.com>
Cc: He Kuang <hekuang@huawei.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kaixu Xia <xiakaixu@huawei.com>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Zefan Li <lizefan@huawei.com>
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.<mapname>.value\n"
+"     \tmaps.<mapname>.value<indics>\n"
+"\n"
+"     \twhere <indics> 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}
 
 }
 
+<array>{
+"]"			{ BEGIN(config); return ']'; }
+{num_dec}		{ return value(yyscanner, 10); }
+{num_hex}		{ return value(yyscanner, 16); }
+,			{ return ','; }
+-			{ return '-'; }
+}
+
 <config>{
 	/*
 	 * 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 '['; }
 }
 
 <mem>{
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 <num> PE_VALUE
 %type <num> PE_VALUE_SYM_HW
 %type <num> PE_VALUE_SYM_SW
@@ -84,6 +85,9 @@ static inc_group_count(struct list_head *list,
 %type <head> group_def
 %type <head> group
 %type <head> groups
+%type <array> array
+%type <array> array_term
+%type <array> 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


  parent reply	other threads:[~2015-10-17 10:49 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-17 10:48 [RFC PATCH 0/7] perf tools: Config BPF maps through perf cmdline Wang Nan
2015-10-17 10:48 ` [RFC PATCH 1/7] perf tools: Add API to config maps in bpf object Wang Nan
2015-11-20  8:13   ` Wangnan (F)
2015-11-23 11:20   ` Wangnan (F)
2015-10-17 10:48 ` [RFC PATCH 2/7] perf tools: Add API to apply config to BPF map Wang Nan
2015-10-17 10:48 ` [RFC PATCH 3/7] perf record: Apply config to BPF objects before recording Wang Nan
2015-10-17 10:48 ` [RFC PATCH 4/7] perf tools: Enable BPF object configure syntax Wang Nan
2015-10-23  4:48   ` Wangnan (F)
2015-10-17 10:48 ` [RFC PATCH 5/7] perf tools: Support setting different slots in a BPF map separately Wang Nan
2015-11-20 13:25   ` Wangnan (F)
2015-11-20 15:34     ` Arnaldo Carvalho de Melo
2015-11-23  2:01       ` Wangnan (F)
2015-11-23  5:45         ` Wangnan (F)
2015-10-17 10:48 ` Wang Nan [this message]
2015-10-17 10:48 ` [RFC PATCH 7/7] perf tools: Enable passing event to BPF object Wang Nan
2015-10-17 20:35 ` [RFC PATCH 0/7] perf tools: Config BPF maps through perf cmdline Alexei Starovoitov
2015-10-17 23:58   ` Wangnan (F)
2015-10-18  0:07     ` Alexei Starovoitov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1445078910-73699-7-git-send-email-wangnan0@huawei.com \
    --to=wangnan0@huawei.com \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=acme@redhat.com \
    --cc=ast@plumgrid.com \
    --cc=brendan.d.gregg@gmail.com \
    --cc=daniel@iogearbox.net \
    --cc=dsahern@gmail.com \
    --cc=hekuang@huawei.com \
    --cc=jolsa@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lizefan@huawei.com \
    --cc=masami.hiramatsu.pt@hitachi.com \
    --cc=namhyung@kernel.org \
    --cc=paulus@samba.org \
    --cc=pi3orama@163.com \
    --cc=xiakaixu@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®