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@xxxxxxxxxx>
Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
Cc: Alexei Starovoitov <ast@xxxxxxxxxxxx>
Cc: Brendan Gregg <brendan.d.gregg@xxxxxxxxx>
Cc: Daniel Borkmann <daniel@xxxxxxxxxxxxx>
Cc: David Ahern <dsahern@xxxxxxxxx>
Cc: He Kuang <hekuang@xxxxxxxxxx>
Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
Cc: Kaixu Xia <xiakaixu@xxxxxxxxxx>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@xxxxxxxxxxx>
Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
Cc: Paul Mackerras <paulus@xxxxxxxxx>
Cc: Peter Zijlstra <a.p.zijlstra@xxxxxxxxx>
Cc: Zefan Li <lizefan@xxxxxxxxxx>
Cc: pi3orama@xxxxxxx
---
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;
+ }
+ }