Prepare to use libubpf. Add ubpf.h into libbpf.c. Add corresponding
makefile options.

Allow ignoring UBPF when building libbpf by setting NO_UBPF=1 for
libbpf building.

Allow perf controling ubpf using NO_UBPF=1.

Signed-off-by: Wang Nan <wangn...@huawei.com>
Cc: Arnaldo Carvalho de Melo <a...@redhat.com>
Cc: Alexei Starovoitov <a...@kernel.org>
Cc: Brendan Gregg <brendan.d.gr...@gmail.com>
Cc: Jiri Olsa <jo...@kernel.org>
Cc: Li Zefan <lize...@huawei.com>
---
 tools/lib/bpf/Makefile     | 16 ++++++++++++++--
 tools/lib/bpf/libbpf.c     |  3 +++
 tools/perf/Makefile.perf   |  2 ++
 tools/perf/config/Makefile |  7 +++++++
 4 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile
index 8dfa512..6944d02 100644
--- a/tools/lib/bpf/Makefile
+++ b/tools/lib/bpf/Makefile
@@ -64,9 +64,17 @@ ifndef VERBOSE
   VERBOSE = 0
 endif
 
+ifndef NO_UBPF
+  FEATURE_UBPF := ubpf
+  CFLAGS_UBPF := -DHAVE_UBPF_SUPPORT
+else
+  FEATURE_UBPF :=
+  CFLAGS_UBPF :=
+endif
+
 FEATURE_USER = .libbpf
-FEATURE_TESTS = libelf libelf-getphdrnum libelf-mmap bpf ubpf
-FEATURE_DISPLAY = libelf bpf ubpf
+FEATURE_TESTS = libelf libelf-getphdrnum libelf-mmap bpf $(FEATURE_UBPF)
+FEATURE_DISPLAY = libelf bpf $(FEATURE_UBPF)
 
 INCLUDES = -I. -I$(srctree)/tools/include 
-I$(srctree)/arch/$(ARCH)/include/uapi -I$(srctree)/include/uapi
 FEATURE_CHECK_CFLAGS-bpf = $(INCLUDES)
@@ -120,6 +128,10 @@ ifeq ($(feature-libelf-getphdrnum), 1)
   override CFLAGS += -DHAVE_ELF_GETPHDRNUM_SUPPORT
 endif
 
+ifeq ($(feature-ubpf), 1)
+  override CFLAGS += $(CFLAGS_UBPF)
+endif
+
 # Append required CFLAGS
 override CFLAGS += $(EXTRA_WARNINGS)
 override CFLAGS += -Werror -Wall
diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index 7e543c3..55b739e 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -21,6 +21,9 @@
 #include <libelf.h>
 #include <gelf.h>
 
+#ifdef HAVE_UBPF_SUPPORT
+# include <ubpf.h>
+#endif
 #include "libbpf.h"
 #include "bpf.h"
 
diff --git a/tools/perf/Makefile.perf b/tools/perf/Makefile.perf
index bde8cba..5334e29 100644
--- a/tools/perf/Makefile.perf
+++ b/tools/perf/Makefile.perf
@@ -81,6 +81,8 @@ include ../scripts/utilities.mak
 #
 # Define NO_LIBBPF if you do not want BPF support
 #
+# Define NO_UBPF if you do not want user space BPF support
+#
 # Define FEATURES_DUMP to provide features detection dump file
 # and bypass the feature detection
 
diff --git a/tools/perf/config/Makefile b/tools/perf/config/Makefile
index 1e46277..89d0470 100644
--- a/tools/perf/config/Makefile
+++ b/tools/perf/config/Makefile
@@ -315,6 +315,13 @@ ifndef NO_LIBELF
     ifeq ($(feature-bpf), 1)
       CFLAGS += -DHAVE_LIBBPF_SUPPORT
       $(call detected,CONFIG_LIBBPF)
+      ifndef NO_UBPF
+        ifeq ($(feature-ubpf), 1)
+          CFLAGS += -DHAVE_UBPF_SUPPORT
+          EXTLIBS += -lubpf
+          $(call detected,CONFIG_UBPF)
+        endif
+      endif
     endif
 
     ifndef NO_DWARF
-- 
1.8.3.4

Reply via email to