Skip to contentSkip to conversation

perf bpf: Add bpf_map() helper

tip:perf/core tip-bot for Arnaldo Carvalho de Melo 1 participant 1 message Jan 26, 2019 perf events

lore
Share & tools
lore
#0 lore raw
Commit-ID:  b45d5511aa9029264740e2353ad7faf3cd444703
Gitweb:     https://git.kernel.org/tip/b45d5511aa9029264740e2353ad7faf3cd444703
Author:     Arnaldo Carvalho de Melo <[email protected]>
AuthorDate: Thu, 24 Jan 2019 15:01:46 +0100
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Fri, 25 Jan 2019 15:12:10 +0100

perf bpf: Add bpf_map() helper

To make the declaration of maps more compact, the following patches will make use of it.

Standardizing on it will allow to add the BTF details, i.e. BPF_ANNOTATE_KV_PAIR() (tools/testing/selftests/bpf/bpf_helpers.h) transparently.

Cc Adrian Hunter <[email protected]>
Cc Daniel Borkmann <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Luis Cláudio Gonçalves <[email protected]>
Cc Martin KaFai Lau <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Wang Nan <[email protected]>
Cc Yonghong Song <[email protected]>
---
 tools/perf/include/bpf/bpf.h | 8 ++++++++
 1 file changed, 8 insertions(+)
tools/perf/include/bpf/bpf.h +8 -0
index e667577207dc..0482028c1d11 100644
@@ -18,6 +18,14 @@ struct bpf_map {
         unsigned int numa_node;
 };
 
+#define bpf_map(name, _type, type_key, type_val, _max_entries)	\
+struct bpf_map SEC("maps") name = {				\
+	.type	     = BPF_MAP_TYPE_##_type,			\
+	.key_size    = sizeof(type_key),			\
+	.value_size  = sizeof(type_val),			\
+	.max_entries = _max_entries,				\
+}
+
 /*
  * FIXME: this should receive .max_entries as a parameter, as careful
  *	  tuning of these limits is needed to avoid hitting limits that