bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 bpf-next 0/3] Fixes for bpftool-prog-profile
@ 2020-03-12 18:23 Song Liu
  2020-03-12 18:23 ` [PATCH v3 bpf-next 1/3] bpftool: only build bpftool-prog-profile if supported by clang Song Liu
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Song Liu @ 2020-03-12 18:23 UTC (permalink / raw)
  To: netdev, bpf
  Cc: john.fastabend, quentin, kernel-team, ast, daniel, arnaldo.melo,
	jolsa, Song Liu

1. Fix build for older clang;
2. Fix skeleton's dependency on libbpf;
3. Add files to .gitignore.

Changes v2 => v3:
1. Add -I$(LIBBPF_PATH) to Makefile (Quentin);
2. Use p_err() for error message (Quentin).

Changes v1 => v2:
1. Rewrite patch 1 with real feature detection (Quentin, Alexei).
2. Add files to .gitignore (Andrii).

Song Liu (3):
  bpftool: only build bpftool-prog-profile if supported by clang
  bpftool: skeleton should depend on libbpf
  bpftool: add _bpftool and profiler.skel.h to .gitignore

 tools/bpf/bpftool/.gitignore                  |  2 ++
 tools/bpf/bpftool/Makefile                    | 20 +++++++++++++------
 tools/bpf/bpftool/prog.c                      |  1 +
 tools/build/feature/Makefile                  |  9 ++++++++-
 .../build/feature/test-clang-bpf-global-var.c |  4 ++++
 5 files changed, 29 insertions(+), 7 deletions(-)
 create mode 100644 tools/build/feature/test-clang-bpf-global-var.c

--
2.17.1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v3 bpf-next 1/3] bpftool: only build bpftool-prog-profile if supported by clang
  2020-03-12 18:23 [PATCH v3 bpf-next 0/3] Fixes for bpftool-prog-profile Song Liu
@ 2020-03-12 18:23 ` Song Liu
  2020-03-12 18:23 ` [PATCH v3 bpf-next 2/3] bpftool: skeleton should depend on libbpf Song Liu
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Song Liu @ 2020-03-12 18:23 UTC (permalink / raw)
  To: netdev, bpf
  Cc: john.fastabend, quentin, kernel-team, ast, daniel, arnaldo.melo,
	jolsa, Song Liu

bpftool-prog-profile requires clang to generate BTF for global variables.
When compared with older clang, skip this command. This is achieved by
adding a new feature, clang-bpf-global-var, to tools/build/feature.

Signed-off-by: Song Liu <songliubraving@fb.com>
---
 tools/bpf/bpftool/Makefile                      | 15 +++++++++++----
 tools/bpf/bpftool/prog.c                        |  1 +
 tools/build/feature/Makefile                    |  9 ++++++++-
 tools/build/feature/test-clang-bpf-global-var.c |  4 ++++
 4 files changed, 24 insertions(+), 5 deletions(-)
 create mode 100644 tools/build/feature/test-clang-bpf-global-var.c

diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
index f294f6c1e795..b0574751f231 100644
--- a/tools/bpf/bpftool/Makefile
+++ b/tools/bpf/bpftool/Makefile
@@ -62,8 +62,9 @@ RM ?= rm -f
 CLANG ?= clang
 
 FEATURE_USER = .bpftool
-FEATURE_TESTS = libbfd disassembler-four-args reallocarray zlib
-FEATURE_DISPLAY = libbfd disassembler-four-args zlib
+FEATURE_TESTS = libbfd disassembler-four-args reallocarray zlib \
+	clang-bpf-global-var
+FEATURE_DISPLAY = libbfd disassembler-four-args zlib clang-bpf-global-var
 
 check_feat := 1
 NON_CHECK_FEAT_TARGETS := clean uninstall doc doc-clean doc-install doc-uninstall
@@ -113,6 +114,12 @@ endif
 OBJS = $(patsubst %.c,$(OUTPUT)%.o,$(SRCS)) $(OUTPUT)disasm.o
 _OBJS = $(filter-out $(OUTPUT)prog.o,$(OBJS)) $(OUTPUT)_prog.o
 
+ifeq ($(feature-clang-bpf-global-var),1)
+	__OBJS = $(OBJS)
+else
+	__OBJS = $(_OBJS)
+endif
+
 $(OUTPUT)_prog.o: prog.c
 	$(QUIET_CC)$(COMPILE.c) -MMD -DBPFTOOL_WITHOUT_SKELETONS -o $@ $<
 
@@ -136,8 +143,8 @@ $(OUTPUT)disasm.o: $(srctree)/kernel/bpf/disasm.c
 
 $(OUTPUT)feature.o: | zdep
 
-$(OUTPUT)bpftool: $(OBJS) $(LIBBPF)
-	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(OBJS) $(LIBS)
+$(OUTPUT)bpftool: $(__OBJS) $(LIBBPF)
+	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(__OBJS) $(LIBS)
 
 $(OUTPUT)%.o: %.c
 	$(QUIET_CC)$(COMPILE.c) -MMD -o $@ $<
diff --git a/tools/bpf/bpftool/prog.c b/tools/bpf/bpftool/prog.c
index 576ddd82bc96..925c6c66aad7 100644
--- a/tools/bpf/bpftool/prog.c
+++ b/tools/bpf/bpftool/prog.c
@@ -1545,6 +1545,7 @@ static int do_loadall(int argc, char **argv)
 
 static int do_profile(int argc, char **argv)
 {
+	p_err("bpftool prog profile command is not supported. Please build bpftool with clang >= 10.0.0");
 	return 0;
 }
 
diff --git a/tools/build/feature/Makefile b/tools/build/feature/Makefile
index 7ac0d8088565..ab8e89a7009c 100644
--- a/tools/build/feature/Makefile
+++ b/tools/build/feature/Makefile
@@ -67,7 +67,8 @@ FILES=                                          \
          test-llvm.bin				\
          test-llvm-version.bin			\
          test-libaio.bin			\
-         test-libzstd.bin
+         test-libzstd.bin			\
+         test-clang-bpf-global-var.bin
 
 FILES := $(addprefix $(OUTPUT),$(FILES))
 
@@ -75,6 +76,7 @@ CC ?= $(CROSS_COMPILE)gcc
 CXX ?= $(CROSS_COMPILE)g++
 PKG_CONFIG ?= $(CROSS_COMPILE)pkg-config
 LLVM_CONFIG ?= llvm-config
+CLANG ?= clang
 
 all: $(FILES)
 
@@ -321,6 +323,11 @@ $(OUTPUT)test-libaio.bin:
 $(OUTPUT)test-libzstd.bin:
 	$(BUILD) -lzstd
 
+$(OUTPUT)test-clang-bpf-global-var.bin:
+	$(CLANG) -S -g -target bpf -o - $(patsubst %.bin,%.c,$(@F)) |	\
+		grep BTF_KIND_VAR
+
+
 ###############################
 
 clean:
diff --git a/tools/build/feature/test-clang-bpf-global-var.c b/tools/build/feature/test-clang-bpf-global-var.c
new file mode 100644
index 000000000000..221f1481d52e
--- /dev/null
+++ b/tools/build/feature/test-clang-bpf-global-var.c
@@ -0,0 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2020 Facebook
+
+volatile int global_value_for_test = 1;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 bpf-next 2/3] bpftool: skeleton should depend on libbpf
  2020-03-12 18:23 [PATCH v3 bpf-next 0/3] Fixes for bpftool-prog-profile Song Liu
  2020-03-12 18:23 ` [PATCH v3 bpf-next 1/3] bpftool: only build bpftool-prog-profile if supported by clang Song Liu
@ 2020-03-12 18:23 ` Song Liu
  2020-03-12 18:23 ` [PATCH v3 bpf-next 3/3] bpftool: add _bpftool and profiler.skel.h to .gitignore Song Liu
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Song Liu @ 2020-03-12 18:23 UTC (permalink / raw)
  To: netdev, bpf
  Cc: john.fastabend, quentin, kernel-team, ast, daniel, arnaldo.melo,
	jolsa, Song Liu

Add the dependency to libbpf, to fix build errors like:

  In file included from skeleton/profiler.bpf.c:5:
  .../bpf_helpers.h:5:10: fatal error: 'bpf_helper_defs.h' file not found
  #include "bpf_helper_defs.h"
           ^~~~~~~~~~~~~~~~~~~
  1 error generated.
  make: *** [skeleton/profiler.bpf.o] Error 1
  make: *** Waiting for unfinished jobs....

Fixes: 47c09d6a9f67 ("bpftool: Introduce "prog profile" command")
Suggested-by: Quentin Monnet <quentin@isovalent.com>
Acked-by: John Fastabend <john.fastabend@gmail.com>
Signed-off-by: Song Liu <songliubraving@fb.com>
---
 tools/bpf/bpftool/Makefile | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
index b0574751f231..9ca3bfbb9ac4 100644
--- a/tools/bpf/bpftool/Makefile
+++ b/tools/bpf/bpftool/Makefile
@@ -126,11 +126,12 @@ $(OUTPUT)_prog.o: prog.c
 $(OUTPUT)_bpftool: $(_OBJS) $(LIBBPF)
 	$(QUIET_LINK)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $(_OBJS) $(LIBS)
 
-skeleton/profiler.bpf.o: skeleton/profiler.bpf.c
+skeleton/profiler.bpf.o: skeleton/profiler.bpf.c $(LIBBPF)
 	$(QUIET_CLANG)$(CLANG) \
 		-I$(srctree)/tools/include/uapi/ \
 		-I$(srctree)/tools/testing/selftests/bpf/include/uapi \
-		-I$(srctree)/tools/lib -g -O2 -target bpf -c $< -o $@
+		-I$(LIBBPF_PATH) -I$(srctree)/tools/lib \
+		-g -O2 -target bpf -c $< -o $@
 
 profiler.skel.h: $(OUTPUT)_bpftool skeleton/profiler.bpf.o
 	$(QUIET_GEN)$(OUTPUT)./_bpftool gen skeleton skeleton/profiler.bpf.o > $@
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v3 bpf-next 3/3] bpftool: add _bpftool and profiler.skel.h to .gitignore
  2020-03-12 18:23 [PATCH v3 bpf-next 0/3] Fixes for bpftool-prog-profile Song Liu
  2020-03-12 18:23 ` [PATCH v3 bpf-next 1/3] bpftool: only build bpftool-prog-profile if supported by clang Song Liu
  2020-03-12 18:23 ` [PATCH v3 bpf-next 2/3] bpftool: skeleton should depend on libbpf Song Liu
@ 2020-03-12 18:23 ` Song Liu
  2020-03-12 18:29 ` [PATCH v3 bpf-next 0/3] Fixes for bpftool-prog-profile Quentin Monnet
  2020-03-12 23:11 ` Daniel Borkmann
  4 siblings, 0 replies; 6+ messages in thread
From: Song Liu @ 2020-03-12 18:23 UTC (permalink / raw)
  To: netdev, bpf
  Cc: john.fastabend, quentin, kernel-team, ast, daniel, arnaldo.melo,
	jolsa, Song Liu

These files are generated, so ignore them.

Reviewed-by: Quentin Monnet <quentin@isovalent.com>
Signed-off-by: Song Liu <songliubraving@fb.com>
---
 tools/bpf/bpftool/.gitignore | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/tools/bpf/bpftool/.gitignore b/tools/bpf/bpftool/.gitignore
index b13926432b84..8d6e8901ed2b 100644
--- a/tools/bpf/bpftool/.gitignore
+++ b/tools/bpf/bpftool/.gitignore
@@ -1,7 +1,9 @@
 *.d
+/_bpftool
 /bpftool
 bpftool*.8
 bpf-helpers.*
 FEATURE-DUMP.bpftool
 feature
 libbpf
+profiler.skel.h
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 bpf-next 0/3] Fixes for bpftool-prog-profile
  2020-03-12 18:23 [PATCH v3 bpf-next 0/3] Fixes for bpftool-prog-profile Song Liu
                   ` (2 preceding siblings ...)
  2020-03-12 18:23 ` [PATCH v3 bpf-next 3/3] bpftool: add _bpftool and profiler.skel.h to .gitignore Song Liu
@ 2020-03-12 18:29 ` Quentin Monnet
  2020-03-12 23:11 ` Daniel Borkmann
  4 siblings, 0 replies; 6+ messages in thread
From: Quentin Monnet @ 2020-03-12 18:29 UTC (permalink / raw)
  To: Song Liu, netdev, bpf
  Cc: john.fastabend, kernel-team, ast, daniel, arnaldo.melo, jolsa

2020-03-12 11:23 UTC-0700 ~ Song Liu <songliubraving@fb.com>
> 1. Fix build for older clang;
> 2. Fix skeleton's dependency on libbpf;
> 3. Add files to .gitignore.
> 
> Changes v2 => v3:
> 1. Add -I$(LIBBPF_PATH) to Makefile (Quentin);
> 2. Use p_err() for error message (Quentin).
> 
> Changes v1 => v2:
> 1. Rewrite patch 1 with real feature detection (Quentin, Alexei).
> 2. Add files to .gitignore (Andrii).
> 
> Song Liu (3):
>   bpftool: only build bpftool-prog-profile if supported by clang
>   bpftool: skeleton should depend on libbpf
>   bpftool: add _bpftool and profiler.skel.h to .gitignore
> 
>  tools/bpf/bpftool/.gitignore                  |  2 ++
>  tools/bpf/bpftool/Makefile                    | 20 +++++++++++++------
>  tools/bpf/bpftool/prog.c                      |  1 +
>  tools/build/feature/Makefile                  |  9 ++++++++-
>  .../build/feature/test-clang-bpf-global-var.c |  4 ++++
>  5 files changed, 29 insertions(+), 7 deletions(-)
>  create mode 100644 tools/build/feature/test-clang-bpf-global-var.c
> 
> --
> 2.17.1
> 

Series looks great, thank you!

Reviewed-by: Quentin Monnet <quentin@isovalent.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v3 bpf-next 0/3] Fixes for bpftool-prog-profile
  2020-03-12 18:23 [PATCH v3 bpf-next 0/3] Fixes for bpftool-prog-profile Song Liu
                   ` (3 preceding siblings ...)
  2020-03-12 18:29 ` [PATCH v3 bpf-next 0/3] Fixes for bpftool-prog-profile Quentin Monnet
@ 2020-03-12 23:11 ` Daniel Borkmann
  4 siblings, 0 replies; 6+ messages in thread
From: Daniel Borkmann @ 2020-03-12 23:11 UTC (permalink / raw)
  To: Song Liu, netdev, bpf
  Cc: john.fastabend, quentin, kernel-team, ast, arnaldo.melo, jolsa

On 3/12/20 7:23 PM, Song Liu wrote:
> 1. Fix build for older clang;
> 2. Fix skeleton's dependency on libbpf;
> 3. Add files to .gitignore.
> 
> Changes v2 => v3:
> 1. Add -I$(LIBBPF_PATH) to Makefile (Quentin);
> 2. Use p_err() for error message (Quentin).
> 
> Changes v1 => v2:
> 1. Rewrite patch 1 with real feature detection (Quentin, Alexei).
> 2. Add files to .gitignore (Andrii).
> 
> Song Liu (3):
>    bpftool: only build bpftool-prog-profile if supported by clang
>    bpftool: skeleton should depend on libbpf
>    bpftool: add _bpftool and profiler.skel.h to .gitignore
> 
>   tools/bpf/bpftool/.gitignore                  |  2 ++
>   tools/bpf/bpftool/Makefile                    | 20 +++++++++++++------
>   tools/bpf/bpftool/prog.c                      |  1 +
>   tools/build/feature/Makefile                  |  9 ++++++++-
>   .../build/feature/test-clang-bpf-global-var.c |  4 ++++
>   5 files changed, 29 insertions(+), 7 deletions(-)
>   create mode 100644 tools/build/feature/test-clang-bpf-global-var.c

Tested with clang-7 and clang-11; looks good, applied, thanks!

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-03-12 23:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-12 18:23 [PATCH v3 bpf-next 0/3] Fixes for bpftool-prog-profile Song Liu
2020-03-12 18:23 ` [PATCH v3 bpf-next 1/3] bpftool: only build bpftool-prog-profile if supported by clang Song Liu
2020-03-12 18:23 ` [PATCH v3 bpf-next 2/3] bpftool: skeleton should depend on libbpf Song Liu
2020-03-12 18:23 ` [PATCH v3 bpf-next 3/3] bpftool: add _bpftool and profiler.skel.h to .gitignore Song Liu
2020-03-12 18:29 ` [PATCH v3 bpf-next 0/3] Fixes for bpftool-prog-profile Quentin Monnet
2020-03-12 23:11 ` Daniel Borkmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).