perf bpf: Add bpf.h to be used in eBPF proggies
authorArnaldo Carvalho de Melo <acme@redhat.com>
Fri, 4 May 2018 15:23:29 +0000 (12:23 -0300)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Tue, 15 May 2018 17:31:23 +0000 (14:31 -0300)
So, the first helper is the one shortening a variable/function section
attribute, from, for instance:

  char _license[] __attribute__((section("license"), used)) = "GPL";

to:

  char _license[] SEC("license") = "GPL";

Convert empty.c to that and it becomes:

  # cat ~acme/lib/examples/perf/bpf/empty.c
  #include <bpf.h>

  char _license[] SEC("license") = "GPL";
  int _version SEC("version") = LINUX_VERSION_CODE;
  #

Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: David Ahern <dsahern@gmail.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Wang Nan <wangnan0@huawei.com>
Link: https://lkml.kernel.org/n/tip-zmeg52dlvy51rdlhyumfl5yf@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
tools/perf/Makefile.perf
tools/perf/examples/bpf/empty.c
tools/perf/include/bpf/bpf.h [new file with mode: 0644]

index 9343b7d945bb5cf1be042b182f38151b53db3ca9..c63a3971d7193163d2cc40be6368e59f7672071d 100644 (file)
@@ -770,6 +770,7 @@ endif
 ifndef NO_LIBBPF
        $(call QUIET_INSTALL, lib) \
                $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf'
+               $(INSTALL) include/bpf/*.h '$(DESTDIR_SQ)$(perf_include_instdir_SQ)/bpf'
        $(call QUIET_INSTALL, lib) \
                $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf'
                $(INSTALL) examples/bpf/*.c '$(DESTDIR_SQ)$(perf_examples_instdir_SQ)/bpf'
index 78754df53ac1d3891235e2180528f3c78dc373a3..86f97763355d718a15147d8f8446b3a4f5aa9e20 100644 (file)
@@ -1,2 +1,4 @@
-char _license[] __attribute__((section("license"), used)) = "GPL";
-int _version __attribute__((section("version"), used)) = LINUX_VERSION_CODE;
+#include <bpf.h>
+
+char _license[] SEC("license") = "GPL";
+int _version SEC("version") = LINUX_VERSION_CODE;
diff --git a/tools/perf/include/bpf/bpf.h b/tools/perf/include/bpf/bpf.h
new file mode 100644 (file)
index 0000000..003afca
--- /dev/null
@@ -0,0 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0
+#ifndef _PERF_BPF_H
+#define _PERF_BPF_H
+#define SEC(NAME) __attribute__((section(NAME),  used))
+#endif /* _PERF_BPF_H */