samples/bpf: Use getppid instead of getpgrp for array map stress
Subsystems (5)
PATCH v4 1/4 samples/bpf: Use getppid instead of getpgrp for array map stress
When cross-compiling the bpf sample map_perf_test for aarch64, I find that __NR_getpgrp is undefined. This causes build errors. This syscall is deprecated and requires defining __ARCH_WANT_SYSCALL_DEPRECATED. To avoid having to define that, just use a different syscall (getppid) for the array map stress test.
--- samples/bpf/map_perf_test_kern.c | 2 +- samples/bpf/map_perf_test_user.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
samples/bpf/map_perf_test_kern.c +1 -1
@@ -266,7 +266,7 @@ int stress_hash_map_lookup(struct pt_regs *ctx)return 0 ; } -SEC("kprobe/sys_getpgrp") +SEC("kprobe/sys_getppid")int stress_array_map_lookup (struct pt_regs *ctx) {u32 key =1 , i;
samples/bpf/map_perf_test_user.c +1 -1
@@ -282,7 +282,7 @@ static void test_array_lookup(int cpu) start_time =time_get_ns ();for (i =0 ; i < max_cnt; i++) -syscall (__NR_getpgrp,0 ); +syscall (__NR_getppid,0 );printf ("%d:array_lookup %lld lookups per sec\n" , cpu, max_cnt *1000000000ll *64 / (time_get_ns () - start_time)); }
Signature · 1 line
2.14.1.821.g8fa685d3b7-goog
PATCH v4 2/4 samples/bpf: Enable cross compiler support
When cross compiling, bpf samples use HOSTCC for compiling the non-BPF part of the sample, however what we really want is to use the cross compiler to build for the cross target since that is what will load and run the BPF sample. Detect this and compile samples correctly.
--- samples/bpf/Makefile | 5 +++++ 1 file changed, 5 insertions(+)
samples/bpf/Makefile +5 -0
@@ -177,6 +177,11 @@ HOSTLOADLIBES_syscall_tp += -lelf LLC ?= llc CLANG ?= clang +# Detect that we're cross compiling and use the cross compiler +ifdef CROSS_COMPILE +HOSTCC = $(CROSS_COMPILE)gcc +endif + # Trick to allow make to be run from this directory all: $(MAKE) -C ../../ $(CURDIR)/
Signature · 1 line
2.14.1.821.g8fa685d3b7-goog
Re: [PATCH v4 2/4] samples/bpf: Enable cross compiler support
Quoted 7 lines · Joel Fernandes
When cross compiling, bpf samples use HOSTCC for compiling the non-BPF part of the sample, however what we really want is to use the cross compiler to build for the cross target since that is what will load and run the BPF sample. Detect this and compile samples correctly.
Signed-off-by Joel Fernandes <[email protected]>
PATCH v4 3/4 samples/bpf: Fix pt_regs issues when cross-compiling
In reply to Joel FernandesBPF samples fail to build when cross-compiling for ARM64 because of incorrect pt_regs param selection. This is because clang defines __x86_64__ and bpf_headers thinks we're building for x86. Since clang is building for the BPF target, it shouldn't make assumptions about what target the BPF program is going to run on. To fix this, lets pass ARCH so the header knows which target the BPF program is being compiled for and can use the correct pt_regs code.
--- samples/bpf/Makefile | 2 +- tools/testing/selftests/bpf/bpf_helpers.h | 56 +++++++++++++++++++++++++++---- 2 files changed, 50 insertions(+), 8 deletions(-)
samples/bpf/Makefile +1 -1
@@ -230,7 +230,7 @@ $(obj)/%.o: $(src)/%.c $(CLANG) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) $(EXTRA_CFLAGS) -I$(obj) \ -I$(srctree)/tools/testing/selftests/bpf/ \ -D__KERNEL__ -D__ASM_SYSREG_H -Wno-unused-value -Wno-pointer-sign \ - -Wno-compare-distinct-pointer-types \ + -D__TARGET_ARCH_$(ARCH) -Wno-compare-distinct-pointer-types \ -Wno-gnu-variable-sized-type-not-at-end \ -Wno-address-of-packed-member -Wno-tautological-compare \ -Wno-unknown-warning-option \
tools/testing/selftests/bpf/bpf_helpers.h +49 -7
107 lines not on this page · raw message
Signature · 1 line
2.14.1.821.g8fa685d3b7-goog
Re: [PATCH v4 3/4] samples/bpf: Fix pt_regs issues when cross-compiling
Quoted 9 lines · Joel Fernandes
BPF samples fail to build when cross-compiling for ARM64 because of incorrect
pt_regsparam selection. This is because clang defines__x86_64__andbpf_headersthinks we're building for x86. Since clang is building for the BPF target, it shouldn't make assumptions about what target the BPF program is going to run on. To fix this, lets pass ARCH so the header knows which target the BPF program is being compiled for and can use the correctpt_regscode.Signed-off-by Joel Fernandes <[email protected]>
PATCH v4 4/4 samples/bpf: Add documentation on cross compilation
In reply to Joel Fernandes--- samples/bpf/README.rst | 10 ++++++++++ 1 file changed, 10 insertions(+)
samples/bpf/README.rst +10 -0
@@ -64,3 +64,13 @@ It is also possible to point make to the newly compiled 'llc' or 'clang' command via redefining LLC or CLANG on the make command line:: make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang + +Cross compiling samples +----------------------- +Inorder to cross-compile, say for arm64 targets, export CROSS_COMPILE and ARCH +environment variables before calling make. This will direct make to build +samples for the cross target. + +export ARCH=arm64 +export CROSS_COMPILE="aarch64-linux-gnu-" +make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
Signature · 1 line
2.14.1.821.g8fa685d3b7-goog
Re: [PATCH v4 4/4] samples/bpf: Add documentation on cross compilation
Quoted 11 lines · Joel Fernandes
Signed-off-by Joel Fernandes <[email protected]>--- samples/bpf/README.rst | 10 ++++++++++ 1 file changed, 10 insertions(+)samples/bpf/README.rst +0
-0
samples/bpf/README.rst It is also possible to point make to the newly compiled 'llc' or · line 70
Quoted 7 lines
samples/bpf/README.rst +4
-0@@ -64,3 +64,13 @@ It is also possible to point make to the newly compiled 'llc' or 'clang' command via redefining LLC or CLANG on the make command line:: make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang + +Cross compiling samples +----------------------- +Inorder to cross-compile, say for arm64 targets, export CROSS_COMPILE and ARCH
In order to
Quoted 7 lines
samples/bpf/README.rst +6
-0+environment variables before calling make. This will direct make to build +samples for the cross target. + +export ARCH=arm64 +export CROSS_COMPILE="aarch64-linux-gnu-" +make samples/bpf/ LLC=~/git/llvm/build/bin/llc CLANG=~/git/llvm/build/bin/clang
Signature · 1 line
~Randy
Re: [PATCH v4 4/4] samples/bpf: Add documentation on cross compilation
In reply to Joel FernandesQuoted 2 lines · Joel Fernandes
Signed-off-by Joel Fernandes <[email protected]>
(Minor typo pointed out by Randy, but rest looks fine.)
Quoted 7 lines · Joel Fernandes
When cross-compiling the bpf sample
map_perf_testfor aarch64, I find that__NR_getpgrpis undefined. This causes build errors. This syscall is deprecated and requires defining__ARCH_WANT_SYSCALL_DEPRECATED. To avoid having to define that, just use a different syscall (getppid) for the array map stress test.Signed-off-by Joel Fernandes <[email protected]>