selftests/bpf: simplify the kernel_count bench trigger
Subsystems (3)
PATCH 1/1 selftests/bpf: simplify the kernel_count bench trigger
Remove the "trigger_count" in trigger_bench.c and reuse trigger_driver() instead for trigger_kernel_count_setup().
With the calling to bpf_get_numa_node_id(), the result for "kernel_count" will become a little more accurate.
It will also easier if we want to test the performance of livepatch, just hook the bpf_get_numa_node_id() and run the "kernel_count" bench trigger.
--- .../selftests/bpf/benchs/bench_trigger.c | 5 +---- .../testing/selftests/bpf/progs/trigger_bench.c | 17 +++++------------ 2 files changed, 6 insertions(+), 16 deletions(-)
tools/testing/selftests/bpf/benchs/bench_trigger.c +1 -4
@@ -179,11 +179,8 @@ static void trigger_syscall_count_setup(void)static void trigger_kernel_count_setup (void ) {setup_ctx (); -bpf_program__set_autoload (ctx.skel->progs.trigger_driver, false); -bpf_program__set_autoload (ctx.skel->progs.trigger_count, true); + ctx.skel->rodata->kernel_count =1 ;load_ctx (); -/* override driver program */ - ctx.driver_prog_fd =bpf_program__fd (ctx.skel->progs.trigger_count); }static void trigger_kprobe_setup (void )
tools/testing/selftests/bpf/progs/trigger_bench.c +5 -12
@@ -39,26 +39,19 @@ int bench_trigger_uprobe_multi(void *ctx)return 0 ; } +const volatile int kernel_count =0 ;const volatile int batch_iters =0 ; -SEC("?raw_tp") -int trigger_count (void *ctx) -{ -int i; - -for (i =0 ; i < batch_iters; i++) -inc_counter (); - -return 0 ; -} - SEC("?raw_tp")int trigger_driver (void *ctx) {int i; -for (i =0 ; i < batch_iters; i++) +for (i =0 ; i < batch_iters; i++) { (void )bpf_get_numa_node_id ();/* attach point for benchmarking */ +if (kernel_count) +inc_counter (); + }return 0 ; }
Signature · 1 line
2.51.2
Quoted 6 lines · Menglong Dong
Remove the "
trigger_count" intrigger_bench.cand reusetrigger_driver()instead fortrigger_kernel_count_setup().With the calling to
bpf_get_numa_node_id(), the result for "kernel_count" will become a little more accurate.
"more accurate" is a bit misleading here. I think you meant that it will do same amount of helper calls as fentry and other benchmarks, and in that sense will be closer as a baseline comparison, is that right? Can you clarify that in the next revision, please?
Quoted 32 lines
It will also easier if we want to test the performance of livepatch, just hook the
bpf_get_numa_node_id()and run the "kernel_count" bench trigger.Signed-off-by Menglong Dong <[email protected]>--- .../selftests/bpf/benchs/bench_trigger.c | 5 +---- .../testing/selftests/bpf/progs/trigger_bench.c | 17 +++++------------ 2 files changed, 6 insertions(+), 16 deletions(-)tools/testing/selftests/bpf/benchs/bench_trigger.c +1
-4@@ -179,11 +179,8 @@ static void trigger_syscall_count_setup(void)static void trigger_kernel_count_setup (void ) {setup_ctx (); -bpf_program__set_autoload (ctx.skel->progs.trigger_driver, false); -bpf_program__set_autoload (ctx.skel->progs.trigger_count, true); + ctx.skel->rodata->kernel_count =1 ;load_ctx (); -/* override driver program */ - ctx.driver_prog_fd =bpf_program__fd (ctx.skel->progs.trigger_count); }static void trigger_kprobe_setup (void )tools/testing/selftests/bpf/progs/trigger_bench.c +0
-0
tools/testing/selftests/bpf/progs/trigger_bench.c int bench_trigger_uprobe_multi(void *ctx) · line 42
Quoted 4 lines
tools/testing/selftests/bpf/progs/trigger_bench.c +1
-0@@ -39,26 +39,19 @@ int bench_trigger_uprobe_multi(void *ctx)return 0 ; } +const volatile int kernel_count =0 ;
nit: use bool? it's not a counter, no need to use int here
Quoted 14 lines
tools/testing/selftests/bpf/progs/trigger_bench.c +0
-11const volatile int batch_iters =0 ; -SEC("?raw_tp") -int trigger_count (void *ctx) -{ -int i; - -for (i =0 ; i < batch_iters; i++) -inc_counter (); - -return 0 ; -} -SEC ("?raw_tp" )
tools/testing/selftests/bpf/progs/trigger_bench.c int bench_trigger_uprobe_multi(void *ctx) · line 54
Quoted 10 lines
tools/testing/selftests/bpf/progs/trigger_bench.c +4
-1int trigger_driver (void *ctx) {int i; -for (i =0 ; i < batch_iters; i++) +for (i =0 ; i < batch_iters; i++) { (void )bpf_get_numa_node_id ();/* attach point for benchmarking */ +if (kernel_count) +inc_counter (); + }
tbh, I wouldn't touch trigger_driver() adding unnecessary if conditions to it. It's fine, IMO, to have bpf_get_numa_node_id() call in trigger_count() for being closer in terms of actual work being done, but I'd keep trigger_driver and trigger_count separate (maybe renaming trigger_count to trigger_kernel_count would help, I don't know)
pw-bot: cr
Quoted 6 lines
tools/testing/selftests/bpf/progs/trigger_bench.c +0
-1return 0 ; } --2.51.2
Quoted 6 lines · Andrii Nakryiko
Quoted 4 lines · Menglong Dong
Remove the "
trigger_count" intrigger_bench.cand reusetrigger_driver()instead fortrigger_kernel_count_setup().
Quoted 7 lines
Quoted 2 lines
With the calling to
bpf_get_numa_node_id(), the result for "kernel_count" will become a little more accurate."more accurate" is a bit misleading here. I think you meant that it will do same amount of helper calls as fentry and other benchmarks, and in that sense will be closer as a baseline comparison, is that right? Can you clarify that in the next revision, please?
Yeah, this is what I mean. The call to "bpf_get_numa_node_id" should be considered as the baseline comparison.
Quoted 58 lines
Quoted 33 lines
It will also easier if we want to test the performance of livepatch, just hook the
bpf_get_numa_node_id()and run the "kernel_count" bench trigger.Signed-off-by Menglong Dong <[email protected]>--- .../selftests/bpf/benchs/bench_trigger.c | 5 +---- .../testing/selftests/bpf/progs/trigger_bench.c | 17 +++++------------ 2 files changed, 6 insertions(+), 16 deletions(-)tools/testing/selftests/bpf/benchs/bench_trigger.c +1
-4@@ -179,11 +179,8 @@ static void trigger_syscall_count_setup(void)static void trigger_kernel_count_setup (void ) {setup_ctx (); -bpf_program__set_autoload (ctx.skel->progs.trigger_driver, false); -bpf_program__set_autoload (ctx.skel->progs.trigger_count, true); + ctx.skel->rodata->kernel_count =1 ;load_ctx (); -/* override driver program */ - ctx.driver_prog_fd =bpf_program__fd (ctx.skel->progs.trigger_count); }static void trigger_kprobe_setup (void )tools/testing/selftests/bpf/progs/trigger_bench.c +0
-0tools/testing/selftests/bpf/progs/trigger_bench.c int bench_trigger_uprobe_multi(void *ctx) · line 42
Quoted 4 lines
tools/testing/selftests/bpf/progs/trigger_bench.c +1
-0@@ -39,26 +39,19 @@ int bench_trigger_uprobe_multi(void *ctx)return 0 ; } +const volatile int kernel_count =0 ;nit: use bool? it's not a counter, no need to use int here
Quoted 18 lines
tools/testing/selftests/bpf/progs/trigger_bench.c +0
-11const volatile int batch_iters =0 ; -SEC("?raw_tp") -int trigger_count (void *ctx) -{ -int i; - -for (i =0 ; i < batch_iters; i++) -inc_counter (); - -return 0 ; -} - SEC("?raw_tp")int trigger_driver (void *ctx) {int i;
Quoted 14 lines
tools/testing/selftests/bpf/progs/trigger_bench.c int bench_trigger_uprobe_multi(void *ctx) · line 54
Quoted 6 lines
tools/testing/selftests/bpf/progs/trigger_bench.c +4
-1-for (i =0 ; i < batch_iters; i++) +for (i =0 ; i < batch_iters; i++) { (void )bpf_get_numa_node_id ();/* attach point for benchmarking */ +if (kernel_count) +inc_counter (); + }tbh, I wouldn't touch
trigger_driver()adding unnecessary if conditions to it. It's fine, IMO, to havebpf_get_numa_node_id()call intrigger_count()for being closer in terms of actual work being done, but I'd keeptrigger_driverandtrigger_countseparate (maybe renamingtrigger_counttotrigger_kernel_countwould help, I don't know)
Ah, OK! I'll add the call to bpf_get_numa_node_id() in trigger_count() instead. I think the "trigger_kernel_count" makes more sense to me.
Thanks!
Menglong Dong
Quoted 9 lines
pw-bot: cr
Quoted 6 lines
tools/testing/selftests/bpf/progs/trigger_bench.c +0
-1return 0 ; } --2.51.2