Skip to contentSkip to conversation

samples/bpf: Use getppid instead of getpgrp for array map stress

PATCH In review Joel Fernandes 3 participants 9 messages Sep 20, 2017

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

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
index 098c857f1eda..2b2ffb97018b 100644
@@ -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
index f388254896f6..a0310fc70057 100644
@@ -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
#1 lore raw

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
index cf17c7932a6e..13f74b67ca44 100644
@@ -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
maintainer Acked-by on v4 2/4
#2 lore raw

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.

#3 lore raw

PATCH v4 3/4 samples/bpf: Fix pt_regs issues when cross-compiling

In reply to Joel Fernandes

BPF 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
index 13f74b67ca44..ebc2ad69b62c 100644
@@ -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
maintainer Acked-by on v4 3/4
#4 lore raw

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_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.

#5 lore raw

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
index 79f9a58f1872..2b906127ef54 100644
@@ -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
#6 lore raw

Re: [PATCH v4 4/4] samples/bpf: Add documentation on cross compilation

Quoted 11 lines · Joel Fernandes
---
 samples/bpf/README.rst | 10 ++++++++++
 1 file changed, 10 insertions(+)
samples/bpf/README.rst +0 -0
index 79f9a58f1872..2b906127ef54 100644

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
maintainer Acked-by on v4 1/4
#8 lore raw
In reply to Joel Fernandes
Quoted 7 lines · Joel Fernandes

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.