selftests/bpf: Add benchmark for local_storage RCU Tasks Trace usage
Subsystems (4)
PATCH v4 1/1 selftests/bpf: Add benchmark for local_storage RCU Tasks Trace usage
This benchmark measures grace period latency and kthread cpu usage of RCU Tasks Trace when many processes are creating/deleting BPF local_storage. Intent here is to quantify improvement on these metrics after Paul's recent RCU Tasks patches [0].
Specifically, fork 15k tasks which call a bpf prog that creates/destroys task local_storage and sleep in a loop, resulting in many call_rcu_tasks_trace calls.
To determine grace period latency, trace time elapsed between rcu_tasks_trace_pregp_step and rcu_tasks_trace_postgp; for cpu usage look at rcu_task_trace_kthread's stime in /proc/PID/stat.
On my virtualized test environment (Skylake, 8 cpus) benchmark results demonstrate significant improvement:
BEFORE Paul's patches:
SUMMARY tasks_trace grace period latency avg 22298.551 us stddev 1302.165 us
SUMMARY ticks per tasks_trace grace period avg 2.291 stddev 0.324
AFTER Paul's patches:
SUMMARY tasks_trace grace period latency avg 16969.197 us stddev 2525.053 us
SUMMARY ticks per tasks_trace grace period avg 1.146 stddev 0.178
Note that since these patches are not in bpf-next benchmarking was done by cherry-picking this patch onto rcu tree.
[0]: https://lore.kernel.org/rcu/20220620225402.GA3842369@paulmck-ThinkPad-P17-Gen-1/
---
v3 -> v4: lore.kernel.org/bpf/[email protected]
* check fscanf result (Daniel)
v2 -> v3: lore.kernel.org/bpf/[email protected]
* print errno when prctl fails, fprintf -> printf nit (Martin)
v1 -> v2: lore.kernel.org/bpf/[email protected]
* kprobe -> fentry for pregp/postgp probes (Martin)
* Make 'Unexpected order of bpf prog calls' detection less brittle by only looking for unexpected prog call order after a postgp has been seen (Martin, Paul)
tools/testing/selftests/bpf/Makefile | 4 +- tools/testing/selftests/bpf/bench.c | 42 +++ tools/testing/selftests/bpf/bench.h | 12 + .../bench_local_storage_rcu_tasks_trace.c | 281 ++++++++++++++++++ ...run_bench_local_storage_rcu_tasks_trace.sh | 11 + .../local_storage_rcu_tasks_trace_bench.c | 67 +++++ 6 files changed, 416 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/bpf/benchs/bench_local_storage_rcu_tasks_trace.c create mode 100755 tools/testing/selftests/bpf/benchs/run_bench_local_storage_rcu_tasks_trace.sh create mode 100644 tools/testing/selftests/bpf/progs/local_storage_rcu_tasks_trace_bench.c
tools/testing/selftests/bpf/Makefile +3 -1
@@ -574,6 +574,7 @@ $(OUTPUT)/bench_bpf_loop.o: $(OUTPUT)/bpf_loop_bench.skel.h $(OUTPUT)/bench_strncmp.o: $(OUTPUT)/strncmp_bench.skel.h $(OUTPUT)/bench_bpf_hashmap_full_update.o: $(OUTPUT)/bpf_hashmap_full_update_bench.skel.h $(OUTPUT)/bench_local_storage.o: $(OUTPUT)/local_storage_bench.skel.h +$(OUTPUT)/bench_local_storage_rcu_tasks_trace.o: $(OUTPUT)/local_storage_rcu_tasks_trace_bench.skel.h $(OUTPUT)/bench.o: bench.h testing_helpers.h $(BPFOBJ) $(OUTPUT)/bench: LDLIBS += -lm $(OUTPUT)/bench: $(OUTPUT)/bench.o \
@@ -587,7 +588,8 @@ $(OUTPUT)/bench: $(OUTPUT)/bench.o \ $(OUTPUT)/bench_bpf_loop.o \ $(OUTPUT)/bench_strncmp.o \ $(OUTPUT)/bench_bpf_hashmap_full_update.o \ - $(OUTPUT)/bench_local_storage.o + $(OUTPUT)/bench_local_storage.o \ + $(OUTPUT)/bench_local_storage_rcu_tasks_trace.o $(call msg,BINARY,,$@) $(Q)$(CC) $(CFLAGS) $(LDFLAGS) $(filter %.a %.o,$^) $(LDLIBS) -o $@
tools/testing/selftests/bpf/bench.c +42 -0
72 lines not on this page · raw message
tools/testing/selftests/bpf/bench.h +12 -0
@@ -30,11 +30,19 @@ struct env {struct cpu_set cons_cpus; }; +struct basic_stats { +double mean; +double stddev; +}; +struct bench_res {long hits;long drops;long false_hits;long important_hits; +unsigned long gp_ns; +unsigned long gp_ct; +unsigned int stime; };struct bench {
@@ -65,6 +73,10 @@ void ops_report_final(struct bench_res res[], int res_cnt);void local_storage_report_progress (int iter,struct bench_res *res,long delta_ns);void local_storage_report_final (struct bench_res res[],int res_cnt); +void grace_period_latency_basic_stats (struct bench_res res[],int res_cnt, +struct basic_stats *gp_stat); +void grace_period_ticks_basic_stats (struct bench_res res[],int res_cnt, +struct basic_stats *gp_stat);static inline __u64 get_time_ns (void ) {
tools/testing/selftests/bpf/benchs/bench_local_storage_rcu_tasks_trace.c new file +281 -0
281 lines not on this page · raw message
tools/testing/selftests/bpf/benchs/run_bench_local_storage_rcu_tasks_trace.sh new file +11 -0
@@ -0,0 +1,11 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 + +kthread_pid=`pgrep rcu_tasks_trace_kthread` + +if [ -z $kthread_pid ]; then + echo "error: Couldn't find rcu_tasks_trace_kthread" + exit 1 +fi + +./bench --nr_procs 15000 --kthread_pid $kthread_pid -d 600 --quiet 1 local-storage-tasks-trace
tools/testing/selftests/bpf/progs/local_storage_rcu_tasks_trace_bench.c new file +67 -0
67 lines not on this page · raw message
Signature · 1 line
2.30.2
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Hello:
This patch was applied to bpf/bpf-next.git (master) by Daniel Borkmann <[email protected]>:
Quoted 10 lines · On Tue, 5 Jul 2022 12:00:18 -0700 you wrote:
This benchmark measures grace period latency and kthread cpu usage of RCU Tasks Trace when many processes are creating/deleting BPF
local_storage. Intent here is to quantify improvement on these metrics after Paul's recent RCU Tasks patches [0].Specifically, fork 15k tasks which call a bpf prog that creates/destroys task
local_storageand sleep in a loop, resulting in manycall_rcu_tasks_tracecalls.[...]
Here is the summary with links:
- [v4,bpf-next] selftests/bpf: Add benchmark for local_storage RCU Tasks Trace usage
https://git.kernel.org/bpf/bpf-next/c/2b4b2621fd64
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html