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 5/7] perf tools: Support setting different slots in a BPF map separately
Date: Sat, 17 Oct 2015 10:48:28 +0000	[thread overview]
Message-ID: <1445078910-73699-6-git-send-email-wangnan0@huawei.com> (raw)
In-Reply-To: <1445078910-73699-1-git-send-email-wangnan0@huawei.com>

This patch introduces basic facilities to support config different
slots in a BPF map one by one.

nr_indics and indics are introduced into 'struct parse_events_term',
where indics is an array of indics which will be configured by this
config term, nr_indics is the size of the array. The array is passed
to 'struct bpf_map_priv'. To indicate the new type of configuration,
BPF_MAP_PRIV_KEY_INDICS is added as a new key type.
bpf_map_config_foreach_key() is extended to iterate over those indics
instead of all possible keys.

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/bpf-loader.c   | 68 +++++++++++++++++++++++++++++++++++++++++-
 tools/perf/util/parse-events.c |  4 ++-
 tools/perf/util/parse-events.h |  2 ++
 3 files changed, 72 insertions(+), 2 deletions(-)

diff --git a/tools/perf/util/bpf-loader.c b/tools/perf/util/bpf-loader.c
index 15cf27a..023fc12 100644
--- a/tools/perf/util/bpf-loader.c
+++ b/tools/perf/util/bpf-loader.c
@@ -638,6 +638,7 @@ int bpf__foreach_tev(struct bpf_object *obj,
 
 enum bpf_map_priv_key_type {
 	BPF_MAP_PRIV_KEY_ALL,
+	BPF_MAP_PRIV_KEY_INDICS,
 };
 
 enum bpf_map_priv_value_type {
@@ -647,6 +648,12 @@ enum bpf_map_priv_value_type {
 struct bpf_map_priv {
 	struct {
 		enum bpf_map_priv_key_type type;
+		union {
+			struct {
+				size_t nr_indics;
+				u64 *indics;
+			} indics;
+		};
 	} key;
 
 	struct {
@@ -663,6 +670,8 @@ bpf_map_priv__clear(struct bpf_map *map __maybe_unused,
 {
 	struct bpf_map_priv *priv = _priv;
 
+	if (priv->key.type == BPF_MAP_PRIV_KEY_INDICS)
+		zfree(&priv->key.indics.indics);
 	free(priv);
 }
 
@@ -718,6 +727,20 @@ bpf_map_config_foreach_key(struct bpf_map *map,
 				}
 			}
 			return 0;
+		case BPF_MAP_PRIV_KEY_INDICS:
+			for (i = 0; i < priv->key.indics.nr_indics; i++) {
+				u64 _idx = priv->key.indics.indics[i];
+				unsigned int idx = (unsigned int)(_idx);
+
+				err = (*func)(name, map_fd, &def,
+					      priv, &idx, arg);
+				if (err) {
+					pr_debug("ERROR: failed to insert value to %s[%u]\n",
+						 name, idx);
+					return err;
+				}
+			}
+			return 0;
 		default:
 			pr_debug("ERROR: keytype for map '%s' invalid\n", name);
 			return -EINVAL;
@@ -728,6 +751,28 @@ bpf_map_config_foreach_key(struct bpf_map *map,
 	}
 }
 
+static int
+bpf_map_priv_setkey(struct bpf_map_priv *priv,
+		    struct parse_events_term *term,
+		    const char *map_name)
+{
+	if (!term->nr_indics)
+		priv->key.type = BPF_MAP_PRIV_KEY_ALL;
+	else {
+		size_t memsz = term->nr_indics * sizeof(term->indics[0]);
+
+		priv->key.indics.indics = malloc(memsz);
+		if (!priv->key.indics.indics) {
+			pr_debug("No enough memory to alloc indics for %s\n",
+				 map_name);
+			return -ENOMEM;
+		}
+		memcpy(priv->key.indics.indics, term->indics, memsz);
+		priv->key.type = BPF_MAP_PRIV_KEY_INDICS;
+		priv->key.indics.nr_indics = term->nr_indics;
+	}
+	return 0;
+}
 
 static int
 bpf__config_obj_map_array_value(struct bpf_map *map,
@@ -773,7 +818,9 @@ bpf__config_obj_map_array_value(struct bpf_map *map,
 		return -ENOMEM;
 	}
 
-	priv->key.type = BPF_MAP_PRIV_KEY_ALL;
+	err = bpf_map_priv_setkey(priv, term, map_name);
+	if (err)
+		return err;
 	priv->value.type = BPF_MAP_PRIV_VAL_VALUE;
 	priv->value.val = term->val.num;
 	return bpf_map__set_private(map, priv, bpf_map_priv__clear);
@@ -834,6 +881,24 @@ bpf__config_obj_map(struct bpf_object *obj,
 		goto out;
 	}
 
+	if (term->nr_indics) {
+		struct bpf_map_def def;
+
+		err = bpf_map__get_def(map, &def);
+		if (err) {
+			pr_debug("ERROR: Unable to get map definition from '%s'\n",
+				 map_name);
+			goto out;
+		}
+		for (i = 0; i < term->nr_indics; i++)
+			if (term->indics[i] >= def.max_entries) {
+				pr_debug("ERROR: index %d too large\n",
+					 (int)term->indics[i]);
+				err = -E2BIG;
+				goto out;
+			}
+	}
+
 	for (i = 0; i < ARRAY_SIZE(bpf_config_map_funcs); i++) {
 		struct bpf_config_map_func *func = &bpf_config_map_funcs[i];
 
@@ -1004,6 +1069,7 @@ int bpf__strerror_config_obj(struct bpf_object *obj __maybe_unused,
 {
 	bpf__strerror_head(err, buf, size);
 	bpf__strerror_entry(ENODEV, "Invalid config option: '%s'", term->config)
+	bpf__strerror_entry(E2BIG,  "Index in '%s' too big", term->config)
 	bpf__strerror_entry(ENOENT, "Config target in '%s' is invalid", term->config)
 	bpf__strerror_entry(EBADF,  "Map type mismatch in '%s'", term->config)
 	bpf__strerror_entry(EINVAL, "Invalid config value")
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 9f081a1..42ac1cb 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -2123,8 +2123,10 @@ void parse_events__free_terms(struct list_head *terms)
 {
 	struct parse_events_term *term, *h;
 
-	list_for_each_entry_safe(term, h, terms, list)
+	list_for_each_entry_safe(term, h, terms, list) {
+		free(term->indics);
 		free(term);
+	}
 }
 
 void parse_events_evlist_error(struct parse_events_evlist *data,
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index d4aa88e..5ba1d3e 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -71,6 +71,8 @@ enum {
 
 struct parse_events_term {
 	char *config;
+	size_t nr_indics;
+	u64 *indics;
 	union {
 		char *str;
 		u64  num;
-- 
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 ` Wang Nan [this message]
2015-11-20 13:25   ` [RFC PATCH 5/7] perf tools: Support setting different slots in a BPF map separately 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 ` [RFC PATCH 6/7] perf tools: Enable indics setting syntax for BPF maps Wang Nan
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-6-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®