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

selftests/bpf: Add uprobe_multi usdt bench test

Adding test that attaches 50k usdt probes in usdt_multi binary.

After the attach is done we run the binary and make sure we get
proper amount of hits.

With current uprobes:

# perf stat --null ./test_progs -n 254/6
#254/6 uprobe_multi_test/bench_usdt:OK
#254 uprobe_multi_test:OK
Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED

Performance counter stats for './test_progs -n 254/6':

1353.659680562 seconds time elapsed

With uprobe_multi link:

# perf stat --null ./test_progs -n 254/6
#254/6 uprobe_multi_test/bench_usdt:OK
#254 uprobe_multi_test:OK
Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED

Performance counter stats for './test_progs -n 254/6':

0.322046364 seconds time elapsed

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/r/20230809083440.3209381-26-jolsa@kernel.org
Signed-off-by: Alexei Starovoitov <ast@kernel.org>

authored by

Jiri Olsa and committed by
Alexei Starovoitov
85209e83 4cde2d8a

+55
+39
tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
··· 4 4 #include <test_progs.h> 5 5 #include "uprobe_multi.skel.h" 6 6 #include "uprobe_multi_bench.skel.h" 7 + #include "uprobe_multi_usdt.skel.h" 7 8 #include "bpf/libbpf_internal.h" 8 9 #include "testing_helpers.h" 9 10 ··· 236 235 printf("%s: detached in %7.3lfs\n", __func__, detach_delta); 237 236 } 238 237 238 + static void test_bench_attach_usdt(void) 239 + { 240 + long attach_start_ns = 0, attach_end_ns = 0; 241 + struct uprobe_multi_usdt *skel = NULL; 242 + long detach_start_ns, detach_end_ns; 243 + double attach_delta, detach_delta; 244 + 245 + skel = uprobe_multi_usdt__open_and_load(); 246 + if (!ASSERT_OK_PTR(skel, "uprobe_multi__open")) 247 + goto cleanup; 248 + 249 + attach_start_ns = get_time_ns(); 250 + 251 + skel->links.usdt0 = bpf_program__attach_usdt(skel->progs.usdt0, -1, "./uprobe_multi", 252 + "test", "usdt", NULL); 253 + if (!ASSERT_OK_PTR(skel->links.usdt0, "bpf_program__attach_usdt")) 254 + goto cleanup; 255 + 256 + attach_end_ns = get_time_ns(); 257 + 258 + system("./uprobe_multi usdt"); 259 + 260 + ASSERT_EQ(skel->bss->count, 50000, "usdt_count"); 261 + 262 + cleanup: 263 + detach_start_ns = get_time_ns(); 264 + uprobe_multi_usdt__destroy(skel); 265 + detach_end_ns = get_time_ns(); 266 + 267 + attach_delta = (attach_end_ns - attach_start_ns) / 1000000000.0; 268 + detach_delta = (detach_end_ns - detach_start_ns) / 1000000000.0; 269 + 270 + printf("%s: attached in %7.3lfs\n", __func__, attach_delta); 271 + printf("%s: detached in %7.3lfs\n", __func__, detach_delta); 272 + } 273 + 239 274 void test_uprobe_multi_test(void) 240 275 { 241 276 if (test__start_subtest("skel_api")) ··· 284 247 test_link_api(); 285 248 if (test__start_subtest("bench_uprobe")) 286 249 test_bench_attach_uprobe(); 250 + if (test__start_subtest("bench_usdt")) 251 + test_bench_attach_usdt(); 287 252 }
+16
tools/testing/selftests/bpf/progs/uprobe_multi_usdt.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + 3 + #include "vmlinux.h" 4 + #include <bpf/bpf_helpers.h> 5 + #include <bpf/usdt.bpf.h> 6 + 7 + char _license[] SEC("license") = "GPL"; 8 + 9 + int count; 10 + 11 + SEC("usdt") 12 + int usdt0(struct pt_regs *ctx) 13 + { 14 + count++; 15 + return 0; 16 + }