samples/bpf: add bpf map stress test
Subsystems (3)
PATCH 1/3 samples/bpf: add bpf map stress test
this test calls bpf programs from different contexts:
from inside of slub, from rcu, from pretty much everywhere, since it kprobes all spin_lock functions.
It stresses the bpf hash and percpu map pre-allocation, deallocation logic and call_rcu mechanisms.
User space part adding more stress by walking and deleting map elements.
Note that due to nature bpf_load.c the earlier kprobe+bpf programs are already active while loader loads new programs, creates new kprobes and attaches them.
--- samples/bpf/Makefile | 4 +++ samples/bpf/spintest_kern.c | 59 +++++++++++++++++++++++++++++++++++++++++++++ samples/bpf/spintest_user.c | 50 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 samples/bpf/spintest_kern.c create mode 100644 samples/bpf/spintest_user.c
samples/bpf/Makefile +4 -0
@@ -17,6 +17,7 @@ hostprogs-y += tracex6 hostprogs-y += trace_output hostprogs-y += lathist hostprogs-y += offwaketime +hostprogs-y += spintest test_verifier-objs := test_verifier.o libbpf.o test_maps-objs := test_maps.o libbpf.o
@@ -34,6 +35,7 @@ tracex6-objs := bpf_load.o libbpf.o tracex6_user.o trace_output-objs := bpf_load.o libbpf.o trace_output_user.o lathist-objs := bpf_load.o libbpf.o lathist_user.o offwaketime-objs := bpf_load.o libbpf.o offwaketime_user.o +spintest-objs := bpf_load.o libbpf.o spintest_user.o # Tell kbuild to always build the programs always := $(hostprogs-y)
@@ -50,6 +52,7 @@ always += trace_output_kern.o always += tcbpf1_kern.o always += lathist_kern.o always += offwaketime_kern.o +always += spintest_kern.o HOSTCFLAGS += -I$(objtree)/usr/include
@@ -67,6 +70,7 @@ HOSTLOADLIBES_tracex6 += -lelf HOSTLOADLIBES_trace_output += -lelf -lrt HOSTLOADLIBES_lathist += -lelf HOSTLOADLIBES_offwaketime += -lelf +HOSTLOADLIBES_spintest += -lelf # point this to your LLVM backend with bpf support LLC=$(srctree)/tools/bpf/llvm/bld/Debug+Asserts/bin/llc
samples/bpf/spintest_kern.c new file +59 -0
59 lines not on this page · raw message
samples/bpf/spintest_user.c new file +50 -0
50 lines not on this page · raw message
Signature · 1 line
2.8.0.rc1
PATCH 2/3 samples/bpf: stress test bpf_get_stackid
increase stress by also calling bpf_get_stackid() from various *spin* functions
--- samples/bpf/spintest_kern.c | 9 +++++++++ 1 file changed, 9 insertions(+)
samples/bpf/spintest_kern.c +9 -0
@@ -8,6 +8,7 @@#include <linux/netdevice.h> #include <linux/version.h> #include <uapi/linux/bpf.h> +#include <uapi/linux/perf_event.h> #include "bpf_helpers.h" struct bpf_map_def SEC("maps") my_map = {
@@ -23,6 +24,13 @@ struct bpf_map_def SEC("maps") my_map2 = { .max_entries = 1024, }; +struct bpf_map_def SEC("maps") stackmap = { + .type = BPF_MAP_TYPE_STACK_TRACE, + .key_size = sizeof(u32), + .value_size = PERF_MAX_STACK_DEPTH * sizeof(u64), + .max_entries = 10000, +}; +#define PROG (foo) \ int foo(struct pt_regs *ctx) \ { \
@@ -32,6 +40,7 @@ int foo(struct pt_regs *ctx) \bpf_map_update_elem (&my_map, &v, &v,BPF_ANY ); \bpf_map_update_elem (&my_map2, &v, &v,BPF_ANY ); \bpf_map_delete_elem (&my_map2, &v); \ +bpf_get_stackid (ctx, &stackmap,BPF_F_REUSE_STACKID ); \return 0 ; \ }
Signature · 1 line
2.8.0.rc1
Re: [PATCH net-next 2/3] samples/bpf: stress test bpf_get_stackid
From: Alexei Starovoitov <[email protected]>
Date: Tue, 8 Mar 2016 15:07:53 -0800
Quoted 4 lines
increase stress by also calling
bpf_get_stackid()from various *spin* functionsSigned-off-by Alexei Starovoitov <[email protected]>
Applied.
PATCH 3/3 samples/bpf: add map performance test
In reply to Alexei Starovoitovperformance tests for hash map and per-cpu hash map with and without pre-allocation
--- samples/bpf/Makefile | 4 + samples/bpf/map_perf_test_kern.c | 100 +++++++++++++++++++++++++ samples/bpf/map_perf_test_user.c | 155 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 259 insertions(+) create mode 100644 samples/bpf/map_perf_test_kern.c create mode 100644 samples/bpf/map_perf_test_user.c
samples/bpf/Makefile +4 -0
@@ -18,6 +18,7 @@ hostprogs-y += trace_output hostprogs-y += lathist hostprogs-y += offwaketime hostprogs-y += spintest +hostprogs-y += map_perf_test test_verifier-objs := test_verifier.o libbpf.o test_maps-objs := test_maps.o libbpf.o
@@ -36,6 +37,7 @@ trace_output-objs := bpf_load.o libbpf.o trace_output_user.o lathist-objs := bpf_load.o libbpf.o lathist_user.o offwaketime-objs := bpf_load.o libbpf.o offwaketime_user.o spintest-objs := bpf_load.o libbpf.o spintest_user.o +map_perf_test-objs := bpf_load.o libbpf.o map_perf_test_user.o # Tell kbuild to always build the programs always := $(hostprogs-y)
@@ -53,6 +55,7 @@ always += tcbpf1_kern.o always += lathist_kern.o always += offwaketime_kern.o always += spintest_kern.o +always += map_perf_test_kern.o HOSTCFLAGS += -I$(objtree)/usr/include
@@ -71,6 +74,7 @@ HOSTLOADLIBES_trace_output += -lelf -lrt HOSTLOADLIBES_lathist += -lelf HOSTLOADLIBES_offwaketime += -lelf HOSTLOADLIBES_spintest += -lelf +HOSTLOADLIBES_map_perf_test += -lelf -lrt # point this to your LLVM backend with bpf support LLC=$(srctree)/tools/bpf/llvm/bld/Debug+Asserts/bin/llc
samples/bpf/map_perf_test_kern.c new file +100 -0
100 lines not on this page · raw message
samples/bpf/map_perf_test_user.c new file +155 -0
155 lines not on this page · raw message
Signature · 1 line
2.8.0.rc1
Re: [PATCH net-next 3/3] samples/bpf: add map performance test
From: Alexei Starovoitov <[email protected]>
Date: Tue, 8 Mar 2016 15:07:54 -0800
Quoted 4 lines
performance tests for hash map and per-cpu hash map with and without pre-allocation
Signed-off-by Alexei Starovoitov <[email protected]>
Applied.
From: Alexei Starovoitov <[email protected]>
Date: Tue, 8 Mar 2016 15:07:52 -0800
Quoted 7 lines
this test calls bpf programs from different contexts:
from inside of slub, from rcu, from pretty much everywhere, since it kprobes allspin_lockfunctions.
It stresses the bpf hash and percpu map pre-allocation, deallocation logic andcall_rcumechanisms.
User space part adding more stress by walking and deleting map elements.
Quoted 5 lines
Note that due to nature
bpf_load.cthe earlier kprobe+bpf programs are already active while loader loads new programs, creates new kprobes and attaches them.Signed-off-by Alexei Starovoitov <[email protected]>
Applied.