All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@kernel.org>
To: Alexei Starovoitov <ast@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Andrii Nakryiko <andrii@kernel.org>
Cc: bpf@vger.kernel.org, Martin KaFai Lau <kafai@fb.com>,
	Song Liu <songliubraving@fb.com>, Yonghong Song <yhs@fb.com>,
	John Fastabend <john.fastabend@gmail.com>,
	KP Singh <kpsingh@chromium.org>,
	Stanislav Fomichev <sdf@google.com>, Hao Luo <haoluo@google.com>,
	Yafang Shao <laoar.shao@gmail.com>
Subject: [PATCHv7 bpf-next 23/28] selftests/bpf: Add uprobe_multi bench test
Date: Wed,  9 Aug 2023 10:34:35 +0200	[thread overview]
Message-ID: <20230809083440.3209381-24-jolsa@kernel.org> (raw)
In-Reply-To: <20230809083440.3209381-1-jolsa@kernel.org>

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.

The resulting attach/detach times on my setup:

  test_bench_attach_uprobe:PASS:uprobe_multi__open 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.346s
  test_bench_attach_uprobe: detached in   0.419s
  #262/5   uprobe_multi_test/bench_uprobe:OK

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 .../bpf/prog_tests/uprobe_multi_test.c        | 40 +++++++++++++++++++
 .../selftests/bpf/progs/uprobe_multi_bench.c  | 15 +++++++
 2 files changed, 55 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/progs/uprobe_multi_bench.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 3860beda82c8..5fa555f4f68d 100644
--- a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
@@ -3,7 +3,9 @@
 #include <unistd.h>
 #include <test_progs.h>
 #include "uprobe_multi.skel.h"
+#include "uprobe_multi_bench.skel.h"
 #include "bpf/libbpf_internal.h"
+#include "testing_helpers.h"
 
 static char test_data[] = "test_data";
 
@@ -197,6 +199,42 @@ static void test_link_api(void)
 	free(offsets);
 }
 
+static void test_bench_attach_uprobe(void)
+{
+	long attach_start_ns = 0, attach_end_ns = 0;
+	struct uprobe_multi_bench *skel = NULL;
+	long detach_start_ns, detach_end_ns;
+	double attach_delta, detach_delta;
+	int err;
+
+	skel = uprobe_multi_bench__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "uprobe_multi_bench__open_and_load"))
+		goto cleanup;
+
+	attach_start_ns = get_time_ns();
+
+	err = uprobe_multi_bench__attach(skel);
+	if (!ASSERT_OK(err, "uprobe_multi_bench__attach"))
+		goto cleanup;
+
+	attach_end_ns = get_time_ns();
+
+	system("./uprobe_multi bench");
+
+	ASSERT_EQ(skel->bss->count, 50000, "uprobes_count");
+
+cleanup:
+	detach_start_ns = get_time_ns();
+	uprobe_multi_bench__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"))
@@ -207,4 +245,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_bench.c b/tools/testing/selftests/bpf/progs/uprobe_multi_bench.c
new file mode 100644
index 000000000000..5367f6105e30
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/uprobe_multi_bench.c
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/bpf.h>
+#include <bpf/bpf_helpers.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "GPL";
+
+int count;
+
+SEC("uprobe.multi/./uprobe_multi:uprobe_multi_func_*")
+int uprobe_bench(struct pt_regs *ctx)
+{
+	count++;
+	return 0;
+}
-- 
2.41.0


  parent reply	other threads:[~2023-08-09  8:38 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-08-09  8:34 [PATCHv7 bpf-next 00/28] bpf: Add multi uprobe link Jiri Olsa
2023-08-09  8:34 ` [PATCHv7 bpf-next 01/28] bpf: Switch BPF_F_KPROBE_MULTI_RETURN macro to enum Jiri Olsa
2023-08-09 16:06   ` Yonghong Song
2023-08-09  8:34 ` [PATCHv7 bpf-next 02/28] bpf: Add attach_type checks under bpf_prog_attach_check_attach_type Jiri Olsa
2023-08-09 16:11   ` Yonghong Song
2023-08-09  8:34 ` [PATCHv7 bpf-next 03/28] bpf: Add multi uprobe link Jiri Olsa
2023-08-09 16:29   ` Yonghong Song
2023-08-09  8:34 ` [PATCHv7 bpf-next 04/28] bpf: Add cookies support for uprobe_multi link Jiri Olsa
2023-08-09 16:39   ` Yonghong Song
2023-08-11 13:19     ` Jiri Olsa
2023-08-11 16:45       ` Yonghong Song
2023-08-09  8:34 ` [PATCHv7 bpf-next 05/28] bpf: Add pid filter " Jiri Olsa
2023-08-09 16:45   ` Yonghong Song
2023-08-09  8:34 ` [PATCHv7 bpf-next 06/28] bpf: Add bpf_get_func_ip helper support for uprobe link Jiri Olsa
2023-08-09 16:48   ` Yonghong Song
2023-08-09  8:34 ` [PATCHv7 bpf-next 07/28] libbpf: Add uprobe_multi attach type and link names Jiri Olsa
2023-08-09  8:34 ` [PATCHv7 bpf-next 08/28] libbpf: Move elf_find_func_offset* functions to elf object Jiri Olsa
2023-08-09  8:34 ` [PATCHv7 bpf-next 09/28] libbpf: Add elf_open/elf_close functions Jiri Olsa
2023-08-09  8:34 ` [PATCHv7 bpf-next 10/28] libbpf: Add elf symbol iterator Jiri Olsa
2023-08-09  8:34 ` [PATCHv7 bpf-next 11/28] libbpf: Add elf_resolve_syms_offsets function Jiri Olsa
2023-08-09  8:34 ` [PATCHv7 bpf-next 12/28] libbpf: Add elf_resolve_pattern_offsets function Jiri Olsa
2023-08-09  8:34 ` [PATCHv7 bpf-next 13/28] libbpf: Add bpf_link_create support for multi uprobes Jiri Olsa
2023-08-09  8:34 ` [PATCHv7 bpf-next 14/28] libbpf: Add bpf_program__attach_uprobe_multi function Jiri Olsa
2023-08-09  8:34 ` [PATCHv7 bpf-next 15/28] libbpf: Add support for u[ret]probe.multi[.s] program sections Jiri Olsa
2023-08-09  8:34 ` [PATCHv7 bpf-next 16/28] libbpf: Add uprobe multi link detection Jiri Olsa
2023-08-09  8:34 ` [PATCHv7 bpf-next 17/28] libbpf: Add uprobe multi link support to bpf_program__attach_usdt Jiri Olsa
2023-08-09  8:34 ` [PATCHv7 bpf-next 18/28] selftests/bpf: Move get_time_ns to testing_helpers.h Jiri Olsa
2023-08-09  8:34 ` [PATCHv7 bpf-next 19/28] selftests/bpf: Add uprobe_multi skel test Jiri Olsa
2023-08-09  8:34 ` [PATCHv7 bpf-next 20/28] selftests/bpf: Add uprobe_multi api test Jiri Olsa
2023-08-09  8:34 ` [PATCHv7 bpf-next 21/28] selftests/bpf: Add uprobe_multi link test Jiri Olsa
2023-08-09  8:34 ` [PATCHv7 bpf-next 22/28] selftests/bpf: Add uprobe_multi test program Jiri Olsa
2023-08-09  8:34 ` Jiri Olsa [this message]
2023-08-09  8:34 ` [PATCHv7 bpf-next 24/28] selftests/bpf: Add uprobe_multi usdt test code Jiri Olsa
2023-08-09  8:34 ` [PATCHv7 bpf-next 25/28] selftests/bpf: Add uprobe_multi usdt bench test Jiri Olsa
2023-08-09  8:34 ` [PATCHv7 bpf-next 26/28] selftests/bpf: Add uprobe_multi cookie test Jiri Olsa
2023-08-09  8:34 ` [PATCHv7 bpf-next 27/28] selftests/bpf: Add uprobe_multi pid filter tests Jiri Olsa
2023-08-09  8:34 ` [PATCHv7 bpf-next 28/28] selftests/bpf: Add extra link to uprobe_multi tests Jiri Olsa
2023-08-21 23:00 ` [PATCHv7 bpf-next 00/28] bpf: Add multi uprobe link patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230809083440.3209381-24-jolsa@kernel.org \
    --to=jolsa@kernel.org \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=haoluo@google.com \
    --cc=john.fastabend@gmail.com \
    --cc=kafai@fb.com \
    --cc=kpsingh@chromium.org \
    --cc=laoar.shao@gmail.com \
    --cc=sdf@google.com \
    --cc=songliubraving@fb.com \
    --cc=yhs@fb.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.