Skip to contentSkip to conversation

tools/bpf: turn on llvm alu32 attribute by default

PATCH Superseded Yonghong Song 2 participants 3 messages Oct 22, 2019

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/bpf: turn on llvm alu32 attribute by default

llvm alu32 was introduced in llvm7:
https://reviews.llvm.org/rL325987
https://reviews.llvm.org/rL325989
Experiments showed that in general performance is better with alu32 enabled:
https://lwn.net/Articles/775316/

This patch turned on alu32 with no-flavor test_progs which is tested most often. The flavor test at no_alu32/test_progs can be used to test without alu32 enabled. The Makefile check for whether llvm supports '-mattr=+alu32 -mcpu=v3' is removed as llvm7 should be available for recent distributions and also latest llvm is preferred to run bpf selftests.

Note that jmp32 is checked by -mcpu=probe and will be enabled if the host kernel supports it.

Cc Jiong Wang <[email protected]>
Cc Andrii Nakryiko <[email protected]>
---
 tools/testing/selftests/bpf/Makefile | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)
tools/testing/selftests/bpf/Makefile +8 -18
index 4ff5f4aada08..5a0bca2802fe 100644
@@ -32,15 +32,7 @@ TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test
 	test_netcnt test_tcpnotify_user test_sock_fields test_sysctl test_hashmap \
 	test_cgroup_attach xdping
 
-# Also test sub-register code-gen if LLVM has eBPF v3 processor support which
-# contains both ALU32 and JMP32 instructions.
-SUBREG_CODEGEN := $(shell echo "int cal(int a) { return a > 0; }" | \
-			$(CLANG) -target bpf -O2 -emit-llvm -S -x c - -o - | \
-			$(LLC) -mattr=+alu32 -mcpu=v3 2>&1 | \
-			grep 'if w')
-ifneq ($(SUBREG_CODEGEN),)
-TEST_GEN_PROGS += test_progs-alu32
-endif
+TEST_GEN_PROGS += test_progs-no_alu32
 
 # Also test bpf-gcc, if present
 ifneq ($(BPF_GCC),)
@@ -179,7 +171,7 @@ endef
 # $eval()) and pass control to DEFINE_TEST_RUNNER_RULES.
 # Parameters:
 # $1 - test runner base binary name (e.g., test_progs)
-# $2 - test runner extra "flavor" (e.g., alu32, gcc-bpf, etc)
+# $2 - test runner extra "flavor" (e.g., no_alu32, gcc-bpf, etc)
 define DEFINE_TEST_RUNNER
 
 TRUNNER_OUTPUT := $(OUTPUT)$(if $2,/)$2
@@ -201,7 +193,7 @@ endef
 # Using TRUNNER_XXX variables, provided by callers of DEFINE_TEST_RUNNER and
 # set up by DEFINE_TEST_RUNNER itself, create test runner build rules with:
 # $1 - test runner base binary name (e.g., test_progs)
-# $2 - test runner extra "flavor" (e.g., alu32, gcc-bpf, etc)
+# $2 - test runner extra "flavor" (e.g., no_alu32, gcc-bpf, etc)
 define DEFINE_TEST_RUNNER_RULES
 
 ifeq ($($(TRUNNER_OUTPUT)-dir),)
@@ -272,14 +264,12 @@ TRUNNER_EXTRA_FILES := $(OUTPUT)/urandom_read				\
 		       $(wildcard progs/btf_dump_test_case_*.c)
 TRUNNER_BPF_BUILD_RULE := CLANG_BPF_BUILD_RULE
 TRUNNER_BPF_CFLAGS := -I. -I$(OUTPUT) $(BPF_CFLAGS) $(CLANG_CFLAGS)
-TRUNNER_BPF_LDFLAGS :=
+TRUNNER_BPF_LDFLAGS := -mattr=+alu32
 $(eval $(call DEFINE_TEST_RUNNER,test_progs))
 
-# Define test_progs-alu32 test runner.
-ifneq ($(SUBREG_CODEGEN),)
-TRUNNER_BPF_LDFLAGS += -mattr=+alu32
-$(eval $(call DEFINE_TEST_RUNNER,test_progs,alu32))
-endif
+# Define test_progs-no_alu32 test runner.
+TRUNNER_BPF_LDFLAGS :=
+$(eval $(call DEFINE_TEST_RUNNER,test_progs,no_alu32))
 
 # Define test_progs BPF-GCC-flavored test runner.
 ifneq ($(BPF_GCC),)
@@ -319,4 +309,4 @@ $(OUTPUT)/test_verifier: test_verifier.c verifier/tests.h $(BPFOBJ) | $(OUTPUT)
 
 EXTRA_CLEAN := $(TEST_CUSTOM_PROGS)					\
 	prog_tests/tests.h map_tests/tests.h verifier/tests.h		\
-	feature $(OUTPUT)/*.o $(OUTPUT)/alu32 $(OUTPUT)/bpf_gcc
+	feature $(OUTPUT)/*.o $(OUTPUT)/no_alu32 $(OUTPUT)/bpf_gcc
Signature · 1 line
2.17.1
Acked-by on v1 1/1
#1 lore raw
Quoted 17 lines · Yonghong Song

llvm alu32 was introduced in llvm7:
https://reviews.llvm.org/rL325987
https://reviews.llvm.org/rL325989
Experiments showed that in general performance is better with alu32 enabled:
https://lwn.net/Articles/775316/

This patch turned on alu32 with no-flavor test_progs which is tested most often. The flavor test at no_alu32/test_progs can be used to test without alu32 enabled. The Makefile check for whether llvm supports '-mattr=+alu32 -mcpu=v3' is removed as llvm7 should be available for recent distributions and also latest llvm is preferred to run bpf selftests.

Quoted 7 lines

Note that jmp32 is checked by -mcpu=probe and will be enabled if the host kernel supports it.

Cc Jiong Wang <[email protected]>
Cc Andrii Nakryiko <[email protected]>

---

Sounds good to me, see minor nit below.

Quoted 11 lines
 tools/testing/selftests/bpf/Makefile | 26 ++++++++------------------
 1 file changed, 8 insertions(+), 18 deletions(-)
tools/testing/selftests/bpf/Makefile +0 -0
index 4ff5f4aada08..5a0bca2802fe 100644
@@ -32,15 +32,7 @@ TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test
        test_netcnt test_tcpnotify_user test_sock_fields test_sysctl test_hashmap \
        test_cgroup_attach xdping
 

tools/testing/selftests/bpf/Makefile TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test · line 35

Quoted 10 lines
tools/testing/selftests/bpf/Makefile +1 -9
-# Also test sub-register code-gen if LLVM has eBPF v3 processor support which
-# contains both ALU32 and JMP32 instructions.
-SUBREG_CODEGEN := $(shell echo "int cal(int a) { return a > 0; }" | \
-                       $(CLANG) -target bpf -O2 -emit-llvm -S -x c - -o - | \
-                       $(LLC) -mattr=+alu32 -mcpu=v3 2>&1 | \
-                       grep 'if w')
-ifneq ($(SUBREG_CODEGEN),)
-TEST_GEN_PROGS += test_progs-alu32
-endif
+TEST_GEN_PROGS += test_progs-no_alu32

combine this with TEST_GEN_PROGS list above, it's not conditional anymore?

Quoted 6 lines
tools/testing/selftests/bpf/Makefile +0 -0
 # Also test bpf-gcc, if present
 ifneq ($(BPF_GCC),)
@@ -179,7 +171,7 @@ endef
 # $eval()) and pass control to DEFINE_TEST_RUNNER_RULES.
 # Parameters:

[...]

#2 lore raw
Quoted 41 lines · Andrii Nakryiko
Quoted 17 lines · Yonghong Song

llvm alu32 was introduced in llvm7:

   https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_rL325987&d=DwIBaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=DA8e1B5r073vIqRrFz7MRA&m=NHAn2DX4M75upJno8E_Vhg5Wx0cj_CtKLDdMYJJHgVA&s=zlXKgOdNDd7V6cQk3lYECzrp8MYswrOnc-ApTPJ6Q5o&e=
   https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_rL325989&d=DwIBaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=DA8e1B5r073vIqRrFz7MRA&m=NHAn2DX4M75upJno8E_Vhg5Wx0cj_CtKLDdMYJJHgVA&s=NSHiry5gsEeL5ThRWj-kc0yfD0YpZCt-OhAsBIvwNZQ&e=
Experiments showed that in general performance
is better with alu32 enabled:
   https://urldefense.proofpoint.com/v2/url?u=https-3A__lwn.net_Articles_775316_&d=DwIBaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=DA8e1B5r073vIqRrFz7MRA&m=NHAn2DX4M75upJno8E_Vhg5Wx0cj_CtKLDdMYJJHgVA&s=FaOOW0RJNF7B2U4JUKG2dPlKk0c1oQtnq06-eFx8mBg&e=

This patch turned on alu32 with no-flavor test_progs which is tested most often. The flavor test at no_alu32/test_progs can be used to test without alu32 enabled. The Makefile check for whether llvm supports '-mattr=+alu32 -mcpu=v3' is removed as llvm7 should be available for recent distributions and also latest llvm is preferred to run bpf selftests.

Quoted 7 lines

Note that jmp32 is checked by -mcpu=probe and will be enabled if the host kernel supports it.

Cc Jiong Wang <[email protected]>
Cc Andrii Nakryiko <[email protected]>

---

Sounds good to me, see minor nit below.

Quoted 11 lines
  tools/testing/selftests/bpf/Makefile | 26 ++++++++------------------
  1 file changed, 8 insertions(+), 18 deletions(-)
tools/testing/selftests/bpf/Makefile +0 -0
index 4ff5f4aada08..5a0bca2802fe 100644
@@ -32,15 +32,7 @@ TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test
         test_netcnt test_tcpnotify_user test_sock_fields test_sysctl test_hashmap \
         test_cgroup_attach xdping
 
Quoted 12 lines

tools/testing/selftests/bpf/Makefile TEST_GEN_PROGS = test_verifier test_tag test_maps test_lru_map test_lpm_map test · line 35

Quoted 10 lines
tools/testing/selftests/bpf/Makefile +1 -9
-# Also test sub-register code-gen if LLVM has eBPF v3 processor support which
-# contains both ALU32 and JMP32 instructions.
-SUBREG_CODEGEN := $(shell echo "int cal(int a) { return a > 0; }" | \
-                       $(CLANG) -target bpf -O2 -emit-llvm -S -x c - -o - | \
-                       $(LLC) -mattr=+alu32 -mcpu=v3 2>&1 | \
-                       grep 'if w')
-ifneq ($(SUBREG_CODEGEN),)
-TEST_GEN_PROGS += test_progs-alu32
-endif
+TEST_GEN_PROGS += test_progs-no_alu32

combine this with TEST_GEN_PROGS list above, it's not conditional anymore?

Ya, make sense. Will respin.

Quoted 10 lines
Quoted 7 lines
tools/testing/selftests/bpf/Makefile +0 -0
  # Also test bpf-gcc, if present
  ifneq ($(BPF_GCC),)
@@ -179,7 +171,7 @@ endef
  # $eval()) and pass control to DEFINE_TEST_RUNNER_RULES.
  # Parameters:

[...]