Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests/bpf: remove syscall-driven benchs, keep syscall-count only

Remove "legacy" benchmarks triggered by syscalls in favor of newly added
in-kernel/batched benchmarks. Drop -batched suffix now as well.
Next patch will restore "feature parity" by adding back
tp/raw_tp/fmodret benchmarks based on in-kernel kfunc approach.

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/r/20240326162151.3981687-4-andrii@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Andrii Nakryiko and committed by
Alexei Starovoitov
208c4391 7df4e597

+42 -299
+5 -27
tools/testing/selftests/bpf/bench.c
··· 496 496 497 497 /* pure counting benchmarks to establish theoretical lmits */ 498 498 extern const struct bench bench_trig_usermode_count; 499 - extern const struct bench bench_trig_base; 499 + extern const struct bench bench_trig_syscall_count; 500 + extern const struct bench bench_trig_kernel_count; 500 501 501 - /* kernel-side syscall-triggered benchmarks */ 502 - extern const struct bench bench_trig_tp; 503 - extern const struct bench bench_trig_rawtp; 502 + /* batched, staying mostly in-kernel benchmarks */ 504 503 extern const struct bench bench_trig_kprobe; 505 504 extern const struct bench bench_trig_kretprobe; 506 505 extern const struct bench bench_trig_kprobe_multi; 507 506 extern const struct bench bench_trig_kretprobe_multi; 508 507 extern const struct bench bench_trig_fentry; 509 508 extern const struct bench bench_trig_fexit; 510 - extern const struct bench bench_trig_fentry_sleep; 511 - extern const struct bench bench_trig_fmodret; 512 - 513 - /* batched, staying mostly in-kernel benchmarks */ 514 - extern const struct bench bench_trig_kernel_count; 515 - extern const struct bench bench_trig_kprobe_batch; 516 - extern const struct bench bench_trig_kretprobe_batch; 517 - extern const struct bench bench_trig_kprobe_multi_batch; 518 - extern const struct bench bench_trig_kretprobe_multi_batch; 519 - extern const struct bench bench_trig_fentry_batch; 520 - extern const struct bench bench_trig_fexit_batch; 521 509 522 510 /* uprobe/uretprobe benchmarks */ 523 511 extern const struct bench bench_trig_uprobe_nop; ··· 548 560 /* pure counting benchmarks for establishing theoretical limits */ 549 561 &bench_trig_usermode_count, 550 562 &bench_trig_kernel_count, 551 - /* syscall-driven triggering benchmarks */ 552 - &bench_trig_tp, 553 - &bench_trig_rawtp, 563 + &bench_trig_syscall_count, 564 + /* batched, staying mostly in-kernel triggers */ 554 565 &bench_trig_kprobe, 555 566 &bench_trig_kretprobe, 556 567 &bench_trig_kprobe_multi, 557 568 &bench_trig_kretprobe_multi, 558 569 &bench_trig_fentry, 559 570 &bench_trig_fexit, 560 - &bench_trig_fentry_sleep, 561 - &bench_trig_fmodret, 562 - /* batched, staying mostly in-kernel triggers */ 563 - &bench_trig_kprobe_batch, 564 - &bench_trig_kretprobe_batch, 565 - &bench_trig_kprobe_multi_batch, 566 - &bench_trig_kretprobe_multi_batch, 567 - &bench_trig_fentry_batch, 568 - &bench_trig_fexit_batch, 569 571 /* uprobes */ 570 572 &bench_trig_uprobe_nop, 571 573 &bench_trig_uretprobe_nop,
+26 -187
tools/testing/selftests/bpf/benchs/bench_trigger.c
··· 99 99 } 100 100 } 101 101 102 - static void *trigger_base_producer(void *input) 103 - { 104 - while (true) { 105 - (void)syscall(__NR_getpgid); 106 - inc_counter(base_hits); 107 - } 108 - return NULL; 109 - } 110 - 111 - static void trigger_base_measure(struct bench_res *res) 112 - { 113 - res->hits = sum_and_reset_counters(base_hits); 114 - } 115 - 116 102 static void *trigger_producer(void *input) 117 103 { 118 - while (true) 119 - (void)syscall(__NR_getpgid); 104 + if (ctx.usermode_counters) { 105 + while (true) { 106 + (void)syscall(__NR_getpgid); 107 + inc_counter(base_hits); 108 + } 109 + } else { 110 + while (true) 111 + (void)syscall(__NR_getpgid); 112 + } 120 113 return NULL; 121 114 } 122 115 ··· 163 170 } 164 171 } 165 172 166 - static void trigger_tp_setup(void) 173 + static void trigger_syscall_count_setup(void) 167 174 { 168 - setup_ctx(); 169 - attach_bpf(ctx.skel->progs.bench_trigger_tp); 175 + ctx.usermode_counters = true; 170 176 } 171 177 172 - static void trigger_rawtp_setup(void) 178 + /* Batched, staying mostly in-kernel triggering setups */ 179 + static void trigger_kernel_count_setup(void) 173 180 { 174 181 setup_ctx(); 175 - attach_bpf(ctx.skel->progs.bench_trigger_raw_tp); 182 + /* override driver program */ 183 + ctx.driver_prog_fd = bpf_program__fd(ctx.skel->progs.trigger_count); 176 184 } 177 185 178 186 static void trigger_kprobe_setup(void) ··· 210 216 { 211 217 setup_ctx(); 212 218 attach_bpf(ctx.skel->progs.bench_trigger_fexit); 213 - } 214 - 215 - static void trigger_fentry_sleep_setup(void) 216 - { 217 - setup_ctx(); 218 - attach_bpf(ctx.skel->progs.bench_trigger_fentry_sleep); 219 - } 220 - 221 - static void trigger_fmodret_setup(void) 222 - { 223 - setup_ctx(); 224 - attach_bpf(ctx.skel->progs.bench_trigger_fmodret); 225 - } 226 - 227 - /* Batched, staying mostly in-kernel triggering setups */ 228 - static void trigger_kernel_count_setup(void) 229 - { 230 - setup_ctx(); 231 - /* override driver program */ 232 - ctx.driver_prog_fd = bpf_program__fd(ctx.skel->progs.trigger_count); 233 - } 234 - 235 - static void trigger_kprobe_batch_setup(void) 236 - { 237 - setup_ctx(); 238 - attach_bpf(ctx.skel->progs.bench_trigger_kprobe_batch); 239 - } 240 - 241 - static void trigger_kretprobe_batch_setup(void) 242 - { 243 - setup_ctx(); 244 - attach_bpf(ctx.skel->progs.bench_trigger_kretprobe_batch); 245 - } 246 - 247 - static void trigger_kprobe_multi_batch_setup(void) 248 - { 249 - setup_ctx(); 250 - attach_bpf(ctx.skel->progs.bench_trigger_kprobe_multi_batch); 251 - } 252 - 253 - static void trigger_kretprobe_multi_batch_setup(void) 254 - { 255 - setup_ctx(); 256 - attach_bpf(ctx.skel->progs.bench_trigger_kretprobe_multi_batch); 257 - } 258 - 259 - static void trigger_fentry_batch_setup(void) 260 - { 261 - setup_ctx(); 262 - attach_bpf(ctx.skel->progs.bench_trigger_fentry_batch); 263 - } 264 - 265 - static void trigger_fexit_batch_setup(void) 266 - { 267 - setup_ctx(); 268 - attach_bpf(ctx.skel->progs.bench_trigger_fexit_batch); 269 219 } 270 220 271 221 /* make sure call is not inlined and not avoided by compiler, so __weak and ··· 336 398 usetup(true, &uprobe_target_ret); 337 399 } 338 400 339 - const struct bench bench_trig_base = { 340 - .name = "trig-base", 401 + const struct bench bench_trig_syscall_count = { 402 + .name = "trig-syscall-count", 341 403 .validate = trigger_validate, 342 - .producer_thread = trigger_base_producer, 343 - .measure = trigger_base_measure, 344 - .report_progress = hits_drops_report_progress, 345 - .report_final = hits_drops_report_final, 346 - }; 347 - 348 - const struct bench bench_trig_tp = { 349 - .name = "trig-tp", 350 - .validate = trigger_validate, 351 - .setup = trigger_tp_setup, 352 - .producer_thread = trigger_producer, 353 - .measure = trigger_measure, 354 - .report_progress = hits_drops_report_progress, 355 - .report_final = hits_drops_report_final, 356 - }; 357 - 358 - const struct bench bench_trig_rawtp = { 359 - .name = "trig-rawtp", 360 - .validate = trigger_validate, 361 - .setup = trigger_rawtp_setup, 362 - .producer_thread = trigger_producer, 363 - .measure = trigger_measure, 364 - .report_progress = hits_drops_report_progress, 365 - .report_final = hits_drops_report_final, 366 - }; 367 - 368 - const struct bench bench_trig_kprobe = { 369 - .name = "trig-kprobe", 370 - .validate = trigger_validate, 371 - .setup = trigger_kprobe_setup, 372 - .producer_thread = trigger_producer, 373 - .measure = trigger_measure, 374 - .report_progress = hits_drops_report_progress, 375 - .report_final = hits_drops_report_final, 376 - }; 377 - 378 - const struct bench bench_trig_kretprobe = { 379 - .name = "trig-kretprobe", 380 - .validate = trigger_validate, 381 - .setup = trigger_kretprobe_setup, 382 - .producer_thread = trigger_producer, 383 - .measure = trigger_measure, 384 - .report_progress = hits_drops_report_progress, 385 - .report_final = hits_drops_report_final, 386 - }; 387 - 388 - const struct bench bench_trig_kprobe_multi = { 389 - .name = "trig-kprobe-multi", 390 - .validate = trigger_validate, 391 - .setup = trigger_kprobe_multi_setup, 392 - .producer_thread = trigger_producer, 393 - .measure = trigger_measure, 394 - .report_progress = hits_drops_report_progress, 395 - .report_final = hits_drops_report_final, 396 - }; 397 - 398 - const struct bench bench_trig_kretprobe_multi = { 399 - .name = "trig-kretprobe-multi", 400 - .validate = trigger_validate, 401 - .setup = trigger_kretprobe_multi_setup, 402 - .producer_thread = trigger_producer, 403 - .measure = trigger_measure, 404 - .report_progress = hits_drops_report_progress, 405 - .report_final = hits_drops_report_final, 406 - }; 407 - 408 - const struct bench bench_trig_fentry = { 409 - .name = "trig-fentry", 410 - .validate = trigger_validate, 411 - .setup = trigger_fentry_setup, 412 - .producer_thread = trigger_producer, 413 - .measure = trigger_measure, 414 - .report_progress = hits_drops_report_progress, 415 - .report_final = hits_drops_report_final, 416 - }; 417 - 418 - const struct bench bench_trig_fexit = { 419 - .name = "trig-fexit", 420 - .validate = trigger_validate, 421 - .setup = trigger_fexit_setup, 422 - .producer_thread = trigger_producer, 423 - .measure = trigger_measure, 424 - .report_progress = hits_drops_report_progress, 425 - .report_final = hits_drops_report_final, 426 - }; 427 - 428 - const struct bench bench_trig_fentry_sleep = { 429 - .name = "trig-fentry-sleep", 430 - .validate = trigger_validate, 431 - .setup = trigger_fentry_sleep_setup, 432 - .producer_thread = trigger_producer, 433 - .measure = trigger_measure, 434 - .report_progress = hits_drops_report_progress, 435 - .report_final = hits_drops_report_final, 436 - }; 437 - 438 - const struct bench bench_trig_fmodret = { 439 - .name = "trig-fmodret", 440 - .validate = trigger_validate, 441 - .setup = trigger_fmodret_setup, 404 + .setup = trigger_syscall_count_setup, 442 405 .producer_thread = trigger_producer, 443 406 .measure = trigger_measure, 444 407 .report_progress = hits_drops_report_progress, ··· 347 508 }; 348 509 349 510 /* batched (staying mostly in kernel) kprobe/fentry benchmarks */ 350 - #define BENCH_TRIG_BATCH(KIND, NAME) \ 511 + #define BENCH_TRIG_KERNEL(KIND, NAME) \ 351 512 const struct bench bench_trig_##KIND = { \ 352 513 .name = "trig-" NAME, \ 353 514 .setup = trigger_##KIND##_setup, \ ··· 358 519 .argp = &bench_trigger_batch_argp, \ 359 520 } 360 521 361 - BENCH_TRIG_BATCH(kernel_count, "kernel-count"); 362 - BENCH_TRIG_BATCH(kprobe_batch, "kprobe-batch"); 363 - BENCH_TRIG_BATCH(kretprobe_batch, "kretprobe-batch"); 364 - BENCH_TRIG_BATCH(kprobe_multi_batch, "kprobe-multi-batch"); 365 - BENCH_TRIG_BATCH(kretprobe_multi_batch, "kretprobe-multi-batch"); 366 - BENCH_TRIG_BATCH(fentry_batch, "fentry-batch"); 367 - BENCH_TRIG_BATCH(fexit_batch, "fexit-batch"); 522 + BENCH_TRIG_KERNEL(kernel_count, "kernel-count"); 523 + BENCH_TRIG_KERNEL(kprobe, "kprobe"); 524 + BENCH_TRIG_KERNEL(kretprobe, "kretprobe"); 525 + BENCH_TRIG_KERNEL(kprobe_multi, "kprobe-multi"); 526 + BENCH_TRIG_KERNEL(kretprobe_multi, "kretprobe-multi"); 527 + BENCH_TRIG_KERNEL(fentry, "fentry"); 528 + BENCH_TRIG_KERNEL(fexit, "fexit"); 368 529 369 530 /* uprobe benchmarks */ 370 531 #define BENCH_TRIG_USERMODE(KIND, PRODUCER, NAME) \
+4 -7
tools/testing/selftests/bpf/benchs/run_bench_trigger.sh
··· 4 4 5 5 def_tests=( \ 6 6 usermode-count kernel-count syscall-count \ 7 - fentry-batch fexit-batch \ 8 - kprobe-batch kprobe-multi-batch \ 9 - kretprobe-batch kretprobe-multi-batch \ 10 - fentry fexit fmodret \ 11 - rawtp tp \ 12 - kprobe kprobe-multi kretprobe kretprobe-multi \ 7 + fentry fexit \ 8 + kprobe kprobe-multi \ 9 + kretprobe kretprobe-multi \ 13 10 ) 14 11 15 12 tests=("$@") ··· 18 21 19 22 for t in "${tests[@]}"; do 20 23 summary=$(sudo ./bench -w2 -d5 -a -p$p trig-$t | tail -n1 | cut -d'(' -f1 | cut -d' ' -f3-) 21 - printf "%-21s: %s\n" $t "$summary" 24 + printf "%-15s: %s\n" $t "$summary" 22 25 done
+1 -1
tools/testing/selftests/bpf/benchs/run_bench_uprobes.sh
··· 2 2 3 3 set -eufo pipefail 4 4 5 - for i in usermode-count base {uprobe,uretprobe}-{nop,push,ret} 5 + for i in usermode-count syscall-count {uprobe,uretprobe}-{nop,push,ret} 6 6 do 7 7 summary=$(sudo ./bench -w2 -d5 -a trig-$i | tail -n1 | cut -d'(' -f1 | cut -d' ' -f3-) 8 8 printf "%-15s: %s\n" $i "$summary"
+6 -77
tools/testing/selftests/bpf/progs/trigger_bench.c
··· 25 25 __sync_add_and_fetch(&hits[cpu & CPU_MASK].value, 1); 26 26 } 27 27 28 - SEC("tp/syscalls/sys_enter_getpgid") 29 - int bench_trigger_tp(void *ctx) 30 - { 31 - inc_counter(); 32 - return 0; 33 - } 34 - 35 - SEC("raw_tp/sys_enter") 36 - int BPF_PROG(bench_trigger_raw_tp, struct pt_regs *regs, long id) 37 - { 38 - if (id == __NR_getpgid) 39 - inc_counter(); 40 - return 0; 41 - } 42 - 43 - SEC("kprobe/" SYS_PREFIX "sys_getpgid") 44 - int bench_trigger_kprobe(void *ctx) 45 - { 46 - inc_counter(); 47 - return 0; 48 - } 49 - 50 - SEC("kretprobe/" SYS_PREFIX "sys_getpgid") 51 - int bench_trigger_kretprobe(void *ctx) 52 - { 53 - inc_counter(); 54 - return 0; 55 - } 56 - 57 - SEC("kprobe.multi/" SYS_PREFIX "sys_getpgid") 58 - int bench_trigger_kprobe_multi(void *ctx) 59 - { 60 - inc_counter(); 61 - return 0; 62 - } 63 - 64 - SEC("kretprobe.multi/" SYS_PREFIX "sys_getpgid") 65 - int bench_trigger_kretprobe_multi(void *ctx) 66 - { 67 - inc_counter(); 68 - return 0; 69 - } 70 - 71 - SEC("fentry/" SYS_PREFIX "sys_getpgid") 72 - int bench_trigger_fentry(void *ctx) 73 - { 74 - inc_counter(); 75 - return 0; 76 - } 77 - 78 - SEC("fexit/" SYS_PREFIX "sys_getpgid") 79 - int bench_trigger_fexit(void *ctx) 80 - { 81 - inc_counter(); 82 - return 0; 83 - } 84 - 85 - SEC("fentry.s/" SYS_PREFIX "sys_getpgid") 86 - int bench_trigger_fentry_sleep(void *ctx) 87 - { 88 - inc_counter(); 89 - return 0; 90 - } 91 - 92 - SEC("fmod_ret/" SYS_PREFIX "sys_getpgid") 93 - int bench_trigger_fmodret(void *ctx) 94 - { 95 - inc_counter(); 96 - return -22; 97 - } 98 - 99 28 SEC("uprobe") 100 29 int bench_trigger_uprobe(void *ctx) 101 30 { ··· 57 128 } 58 129 59 130 SEC("kprobe/bpf_get_numa_node_id") 60 - int bench_trigger_kprobe_batch(void *ctx) 131 + int bench_trigger_kprobe(void *ctx) 61 132 { 62 133 inc_counter(); 63 134 return 0; 64 135 } 65 136 66 137 SEC("kretprobe/bpf_get_numa_node_id") 67 - int bench_trigger_kretprobe_batch(void *ctx) 138 + int bench_trigger_kretprobe(void *ctx) 68 139 { 69 140 inc_counter(); 70 141 return 0; 71 142 } 72 143 73 144 SEC("kprobe.multi/bpf_get_numa_node_id") 74 - int bench_trigger_kprobe_multi_batch(void *ctx) 145 + int bench_trigger_kprobe_multi(void *ctx) 75 146 { 76 147 inc_counter(); 77 148 return 0; 78 149 } 79 150 80 151 SEC("kretprobe.multi/bpf_get_numa_node_id") 81 - int bench_trigger_kretprobe_multi_batch(void *ctx) 152 + int bench_trigger_kretprobe_multi(void *ctx) 82 153 { 83 154 inc_counter(); 84 155 return 0; 85 156 } 86 157 87 158 SEC("fentry/bpf_get_numa_node_id") 88 - int bench_trigger_fentry_batch(void *ctx) 159 + int bench_trigger_fentry(void *ctx) 89 160 { 90 161 inc_counter(); 91 162 return 0; 92 163 } 93 164 94 165 SEC("fexit/bpf_get_numa_node_id") 95 - int bench_trigger_fexit_batch(void *ctx) 166 + int bench_trigger_fexit(void *ctx) 96 167 { 97 168 inc_counter(); 98 169 return 0;