On Thu, Jul 06, 2023 at 09:38:20PM -0700, Andrii Nakryiko wrote: > On Fri, Jun 30, 2023 at 1:38 AM Jiri Olsa <jolsa@xxxxxxxxxx> wrote: > > > > Adding test that attaches 50k uprobes in uprobe_multi binary. > > > > After the attach is done we run the binary and make sure we > > get proper amount of hits. > > > > Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx> > > --- > > .../bpf/prog_tests/uprobe_multi_test.c | 56 +++++++++++++++++++ > > .../selftests/bpf/progs/uprobe_multi.c | 9 +++ > > 2 files changed, 65 insertions(+) > > > > diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c > > index fd858636b8b0..547d46965d70 100644 > > --- a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c > > +++ b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c > > @@ -202,6 +202,60 @@ static void test_link_api(void) > > free(offsets); > > } > > > > +static inline __u64 get_time_ns(void) > > +{ > > + struct timespec t; > > + > > + clock_gettime(CLOCK_MONOTONIC, &t); > > + return (__u64) t.tv_sec * 1000000000 + t.tv_nsec; > > +} > > + > > hmm.. I would expect we have this helper somewhere in common headers. > If not, we should probably move all such helpers into one header and > use it everywhere hum, now I see it's also defined in bench.h, I'll try to use it from there ;-) also perhaps in kprobe multi test > > > +static void test_bench_attach_uprobe(void) > > +{ > > + long attach_start_ns, attach_end_ns; > > + long detach_start_ns, detach_end_ns; > > + double attach_delta, detach_delta; > > + struct uprobe_multi *skel = NULL; > > + struct bpf_program *prog; > > + int err; > > + > > + skel = uprobe_multi__open(); > > + if (!ASSERT_OK_PTR(skel, "uprobe_multi__open")) > > + goto cleanup; > > + > > + bpf_object__for_each_program(prog, skel->obj) > > + bpf_program__set_autoload(prog, false); > > + > > + bpf_program__set_autoload(skel->progs.test_uprobe_bench, true); > > I don't get why you bothered adding this test_uprobe_bench into > progs/uprobe_multi and go through this manual auto-load > setting/resetting, instead of just having test_uprobe_bench in a > separate skeleton?... ok, will add separate file for that.. will be simpler > > > + > > + err = uprobe_multi__load(skel); > > + if (!ASSERT_EQ(err, 0, "uprobe_multi__load")) > > + goto cleanup; > > + > > + attach_start_ns = get_time_ns(); > > + > > + err = uprobe_multi__attach(skel); > > + if (!ASSERT_OK(err, "uprobe_multi__attach")) > > + goto cleanup; > > + > > + attach_end_ns = get_time_ns(); > > + > > + system("./uprobe_multi"); > > + > > + ASSERT_EQ(skel->bss->count, 50000, "uprobes_count"); > > + > > +cleanup: > > + detach_start_ns = get_time_ns(); > > + uprobe_multi__destroy(skel); > > + detach_end_ns = get_time_ns(); > > + > > + attach_delta = (attach_end_ns - attach_start_ns) / 1000000000.0; > > + detach_delta = (detach_end_ns - detach_start_ns) / 1000000000.0; > > + > > + printf("%s: attached in %7.3lfs\n", __func__, attach_delta); > > + printf("%s: detached in %7.3lfs\n", __func__, detach_delta); > > and for us lazy folks, what are the numbers you see on your machine? right, will put it to the changelog # ./test_progs -n 260/5 -v bpf_testmod.ko is already unloaded. Loading bpf_testmod.ko... Successfully loaded bpf_testmod.ko. test_bench_attach_uprobe:PASS:uprobe_multi__open 0 nsec test_bench_attach_uprobe:PASS:uprobe_multi__load 0 nsec test_bench_attach_uprobe:PASS:uprobe_multi__attach 0 nsec test_bench_attach_uprobe:PASS:uprobes_count 0 nsec test_bench_attach_uprobe: attached in 0.398s test_bench_attach_uprobe: detached in 0.443s #260/5 uprobe_multi_test/bench_uprobe:OK #260 uprobe_multi_test:OK Summary: 1/1 PASSED, 0 SKIPPED, 0 FAILED Successfully unloaded bpf_testmod.ko. thanks, jirka > > > +} > > + > > void test_uprobe_multi_test(void) > > { > > if (test__start_subtest("skel_api")) > > @@ -212,4 +266,6 @@ void test_uprobe_multi_test(void) > > test_attach_api_syms(); > > if (test__start_subtest("link_api")) > > test_link_api(); > > + if (test__start_subtest("bench_uprobe")) > > + test_bench_attach_uprobe(); > > } > > diff --git a/tools/testing/selftests/bpf/progs/uprobe_multi.c b/tools/testing/selftests/bpf/progs/uprobe_multi.c > > index 1eeb9b7b9cad..cd73139dc881 100644 > > --- a/tools/testing/selftests/bpf/progs/uprobe_multi.c > > +++ b/tools/testing/selftests/bpf/progs/uprobe_multi.c > > @@ -89,3 +89,12 @@ int test_uretprobe_sleep(struct pt_regs *ctx) > > uprobe_multi_check(ctx, true, true); > > return 0; > > } > > + > > +int count; > > + > > +SEC("?uprobe.multi/./uprobe_multi:uprobe_multi_func_*") > > +int test_uprobe_bench(struct pt_regs *ctx) > > +{ > > + count++; > > + return 0; > > +} > > -- > > 2.41.0 > >