diff mbox series

[PATCHv3,bpf-next,23/26] selftests/bpf: Add usdt_multi bench test

Message ID 20230630083344.984305-24-jolsa@kernel.org (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series bpf: Add multi uprobe link | expand

Checks

Context Check Description
netdev/series_format fail Series longer than 15 patches (and no cover letter)
netdev/tree_selection success Clearly marked for bpf-next, async
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 8 this patch: 8
netdev/cc_maintainers warning 6 maintainers not CCed: kpsingh@kernel.org martin.lau@linux.dev shuah@kernel.org song@kernel.org mykolal@fb.com linux-kselftest@vger.kernel.org
netdev/build_clang fail Errors and warnings before: 18 this patch: 18
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 8 this patch: 8
netdev/checkpatch warning WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? WARNING: line length of 91 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR success PR summary
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ${{ matrix.test }} on ${{ matrix.arch }} with ${{ matrix.toolchain_full }}
bpf/vmtest-bpf-next-VM_Test-2 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-4 success Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-5 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-6 fail Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-7 success Logs for set-matrix
bpf/vmtest-bpf-next-VM_Test-8 success Logs for veristat

Commit Message

Jiri Olsa June 30, 2023, 8:33 a.m. UTC
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>
---
 .../bpf/prog_tests/uprobe_multi_test.c        | 50 +++++++++++++++++++
 .../selftests/bpf/progs/uprobe_multi_usdt.c   | 16 ++++++
 2 files changed, 66 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/progs/uprobe_multi_usdt.c

Comments

Andrii Nakryiko July 7, 2023, 4:42 a.m. UTC | #1
On Fri, Jun 30, 2023 at 1:38 AM Jiri Olsa <jolsa@kernel.org> wrote:
>
> 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
>

20 minutes, I commend your patience!

> 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

This is an impressive speed up, especially taking into account that
there is no batch attachment magic that we had to do for kprobes. Very
nice!

>
> Signed-off-by: Jiri Olsa <jolsa@kernel.org>
> ---
>  .../bpf/prog_tests/uprobe_multi_test.c        | 50 +++++++++++++++++++
>  .../selftests/bpf/progs/uprobe_multi_usdt.c   | 16 ++++++
>  2 files changed, 66 insertions(+)
>  create mode 100644 tools/testing/selftests/bpf/progs/uprobe_multi_usdt.c
>
> 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 547d46965d70..b12dc1f992e5 100644
> --- a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
> +++ b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
> @@ -4,6 +4,7 @@
>  #include <test_progs.h>
>  #include "uprobe_multi.skel.h"
>  #include "bpf/libbpf_elf.h"
> +#include "uprobe_multi_usdt.skel.h"
>
>  static char test_data[] = "test_data";
>
> @@ -256,6 +257,53 @@ static void test_bench_attach_uprobe(void)
>         printf("%s: detached in %7.3lfs\n", __func__, detach_delta);
>  }
>
> +static void test_bench_attach_usdt(void)
> +{
> +       struct uprobe_multi_usdt *skel = NULL;
> +       long attach_start_ns, attach_end_ns;
> +       long detach_start_ns, detach_end_ns;
> +       double attach_delta, detach_delta;
> +       struct bpf_program *prog;
> +       int err;
> +
> +       skel = uprobe_multi_usdt__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.usdt0, true);

there is nothing else in that skeleton, why this set_autoload() business?

> +
> +       err = uprobe_multi_usdt__load(skel);
> +       if (!ASSERT_EQ(err, 0, "uprobe_multi_usdt__load"))
> +               goto cleanup;
> +
> +       attach_start_ns = get_time_ns();
> +
> +       skel->links.usdt0 = bpf_program__attach_usdt(skel->progs.usdt0, -1, "./usdt_multi",
> +                                                    "test", "usdt", NULL);
> +       if (!ASSERT_OK_PTR(skel->links.usdt0, "bpf_program__attach_usdt"))
> +               goto cleanup;
> +
> +       attach_end_ns = get_time_ns();
> +
> +       system("./usdt_multi");
> +
> +       ASSERT_EQ(skel->bss->count, 50000, "usdt_count");
> +
> +cleanup:
> +       detach_start_ns = get_time_ns();
> +       uprobe_multi_usdt__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);
> +}
> +
>  void test_uprobe_multi_test(void)
>  {
>         if (test__start_subtest("skel_api"))
> @@ -268,4 +316,6 @@ void test_uprobe_multi_test(void)
>                 test_link_api();
>         if (test__start_subtest("bench_uprobe"))
>                 test_bench_attach_uprobe();
> +       if (test__start_subtest("bench_usdt"))
> +               test_bench_attach_usdt();
>  }
> diff --git a/tools/testing/selftests/bpf/progs/uprobe_multi_usdt.c b/tools/testing/selftests/bpf/progs/uprobe_multi_usdt.c
> new file mode 100644
> index 000000000000..9e1c33d0bd2f
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/progs/uprobe_multi_usdt.c
> @@ -0,0 +1,16 @@
> +// SPDX-License-Identifier: GPL-2.0
> +
> +#include "vmlinux.h"
> +#include <bpf/bpf_helpers.h>
> +#include <bpf/usdt.bpf.h>
> +
> +char _license[] SEC("license") = "GPL";
> +
> +int count;
> +
> +SEC("usdt")
> +int usdt0(struct pt_regs *ctx)
> +{
> +       count++;
> +       return 0;
> +}
> --
> 2.41.0
>
Jiri Olsa July 11, 2023, 9:07 a.m. UTC | #2
On Thu, Jul 06, 2023 at 09:42:05PM -0700, Andrii Nakryiko wrote:

SNIP

> > +static void test_bench_attach_usdt(void)
> > +{
> > +       struct uprobe_multi_usdt *skel = NULL;
> > +       long attach_start_ns, attach_end_ns;
> > +       long detach_start_ns, detach_end_ns;
> > +       double attach_delta, detach_delta;
> > +       struct bpf_program *prog;
> > +       int err;
> > +
> > +       skel = uprobe_multi_usdt__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.usdt0, true);
> 
> there is nothing else in that skeleton, why this set_autoload() business?

nah copy&paste error from the uprobe bench test.. will change ;-)

jirka

SNIP
diff mbox series

Patch

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 547d46965d70..b12dc1f992e5 100644
--- a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
@@ -4,6 +4,7 @@ 
 #include <test_progs.h>
 #include "uprobe_multi.skel.h"
 #include "bpf/libbpf_elf.h"
+#include "uprobe_multi_usdt.skel.h"
 
 static char test_data[] = "test_data";
 
@@ -256,6 +257,53 @@  static void test_bench_attach_uprobe(void)
 	printf("%s: detached in %7.3lfs\n", __func__, detach_delta);
 }
 
+static void test_bench_attach_usdt(void)
+{
+	struct uprobe_multi_usdt *skel = NULL;
+	long attach_start_ns, attach_end_ns;
+	long detach_start_ns, detach_end_ns;
+	double attach_delta, detach_delta;
+	struct bpf_program *prog;
+	int err;
+
+	skel = uprobe_multi_usdt__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.usdt0, true);
+
+	err = uprobe_multi_usdt__load(skel);
+	if (!ASSERT_EQ(err, 0, "uprobe_multi_usdt__load"))
+		goto cleanup;
+
+	attach_start_ns = get_time_ns();
+
+	skel->links.usdt0 = bpf_program__attach_usdt(skel->progs.usdt0, -1, "./usdt_multi",
+						     "test", "usdt", NULL);
+	if (!ASSERT_OK_PTR(skel->links.usdt0, "bpf_program__attach_usdt"))
+		goto cleanup;
+
+	attach_end_ns = get_time_ns();
+
+	system("./usdt_multi");
+
+	ASSERT_EQ(skel->bss->count, 50000, "usdt_count");
+
+cleanup:
+	detach_start_ns = get_time_ns();
+	uprobe_multi_usdt__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);
+}
+
 void test_uprobe_multi_test(void)
 {
 	if (test__start_subtest("skel_api"))
@@ -268,4 +316,6 @@  void test_uprobe_multi_test(void)
 		test_link_api();
 	if (test__start_subtest("bench_uprobe"))
 		test_bench_attach_uprobe();
+	if (test__start_subtest("bench_usdt"))
+		test_bench_attach_usdt();
 }
diff --git a/tools/testing/selftests/bpf/progs/uprobe_multi_usdt.c b/tools/testing/selftests/bpf/progs/uprobe_multi_usdt.c
new file mode 100644
index 000000000000..9e1c33d0bd2f
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/uprobe_multi_usdt.c
@@ -0,0 +1,16 @@ 
+// SPDX-License-Identifier: GPL-2.0
+
+#include "vmlinux.h"
+#include <bpf/bpf_helpers.h>
+#include <bpf/usdt.bpf.h>
+
+char _license[] SEC("license") = "GPL";
+
+int count;
+
+SEC("usdt")
+int usdt0(struct pt_regs *ctx)
+{
+	count++;
+	return 0;
+}