public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@kernel.org>
To: Oleg Nesterov <oleg@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	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@fomichev.me>, Hao Luo <haoluo@google.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Subject: [PATCHv4 14/14] selftests/bpf: Add consumers stress test on single uprobe
Date: Tue, 17 Sep 2024 10:50:24 +0200	[thread overview]
Message-ID: <20240917085024.765883-15-jolsa@kernel.org> (raw)
In-Reply-To: <20240917085024.765883-1-jolsa@kernel.org>

We create multiple threads each trying to attach and detach uprobe
consumers on the same uprobe, while main thread is hitting on that
uprobe. All that for 5 seconds.

Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 .../bpf/prog_tests/uprobe_multi_test.c        | 82 +++++++++++++++++++
 .../bpf/progs/uprobe_multi_consumer_stress.c  | 29 +++++++
 2 files changed, 111 insertions(+)
 create mode 100644 tools/testing/selftests/bpf/progs/uprobe_multi_consumer_stress.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 594aa8c06f58..dcc128507212 100644
--- a/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/uprobe_multi_test.c
@@ -3,6 +3,7 @@
 #include <unistd.h>
 #include <pthread.h>
 #include <test_progs.h>
+#include <time.h>
 #include "uprobe_multi.skel.h"
 #include "uprobe_multi_bench.skel.h"
 #include "uprobe_multi_usdt.skel.h"
@@ -10,6 +11,7 @@
 #include "uprobe_multi_session_single.skel.h"
 #include "uprobe_multi_session_cookie.skel.h"
 #include "uprobe_multi_session_recursive.skel.h"
+#include "uprobe_multi_consumer_stress.skel.h"
 #include "uprobe_multi_verifier.skel.h"
 #include "bpf/libbpf_internal.h"
 #include "testing_helpers.h"
@@ -848,6 +850,84 @@ static void test_bench_attach_usdt(void)
 	printf("%s: detached in %7.3lfs\n", __func__, detach_delta);
 }
 
+static int done;
+
+static void *worker(void *p)
+{
+	struct uprobe_multi_consumer_stress *skel = p;
+	struct bpf_link *link = NULL;
+
+	srand(time(NULL));
+
+	while (!done) {
+		LIBBPF_OPTS(bpf_uprobe_multi_opts, opts);
+		struct bpf_program *prog;
+
+		switch (rand() % 4) {
+		case 0:
+			prog = skel->progs.uprobe_session_0;
+			opts.session = true;
+			break;
+		case 1:
+			prog = skel->progs.uprobe_session_1;
+			opts.session = true;
+			break;
+		case 2:
+			prog = skel->progs.uprobe;
+			break;
+		case 3:
+			prog = skel->progs.uretprobe;
+			opts.retprobe = true;
+			break;
+		}
+
+		link = bpf_program__attach_uprobe_multi(prog, -1, "/proc/self/exe",
+							"uprobe_multi_func_1", &opts);
+		bpf_link__destroy(link);
+	}
+
+	return NULL;
+}
+
+#define THREAD_COUNT 4
+
+static void test_session_consumer_stress(void)
+{
+	struct uprobe_multi_consumer_stress *skel;
+	pthread_t threads[THREAD_COUNT];
+	time_t start;
+	int i, err;
+
+	/*
+	 * We create multiple threads each trying to attach and detach uprobe
+	 * consumer on the same uprobe, while main thread is hitting on that
+	 * uprobe. All that for 5 seconds.
+	 */
+	skel = uprobe_multi_consumer_stress__open_and_load();
+	if (!ASSERT_OK_PTR(skel, "uprobe_multi_consumer_stress"))
+		goto cleanup;
+
+	for (i = 0; i < THREAD_COUNT; i++) {
+		err = pthread_create(threads + i, NULL, worker, skel);
+		if (!ASSERT_OK(err, "pthread_create"))
+			goto join;
+	}
+
+	start = time(NULL);
+
+	while (start + 5 > time(NULL))
+		uprobe_multi_func_1();
+
+	done = 1;
+
+join:
+	for (i = 0; i < THREAD_COUNT; i++)
+		pthread_join(threads[i], NULL);
+
+cleanup:
+	uprobe_multi_consumer_stress__destroy(skel);
+}
+
 void test_uprobe_multi_test(void)
 {
 	if (test__start_subtest("skel_api"))
@@ -872,5 +952,7 @@ void test_uprobe_multi_test(void)
 		test_session_cookie_skel_api();
 	if (test__start_subtest("session_cookie_recursive"))
 		test_session_recursive_skel_api();
+	if (test__start_subtest("consumer_stress"))
+		test_session_consumer_stress();
 	RUN_TESTS(uprobe_multi_verifier);
 }
diff --git a/tools/testing/selftests/bpf/progs/uprobe_multi_consumer_stress.c b/tools/testing/selftests/bpf/progs/uprobe_multi_consumer_stress.c
new file mode 100644
index 000000000000..5390108a21ff
--- /dev/null
+++ b/tools/testing/selftests/bpf/progs/uprobe_multi_consumer_stress.c
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0
+#include <linux/bpf.h>
+#include <bpf/bpf_tracing.h>
+
+char _license[] SEC("license") = "GPL";
+
+SEC("uprobe.session")
+int uprobe_session_0(struct pt_regs *ctx)
+{
+	return 0;
+}
+
+SEC("uprobe.session")
+int uprobe_session_1(struct pt_regs *ctx)
+{
+	return 1;
+}
+
+SEC("uprobe.multi")
+int uprobe(struct pt_regs *ctx)
+{
+	return 0;
+}
+
+SEC("uprobe.multi")
+int uretprobe(struct pt_regs *ctx)
+{
+	return 0;
+}
-- 
2.46.0


  parent reply	other threads:[~2024-09-17  8:53 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-17  8:50 [PATCHv4 00/14] uprobe, bpf: Add session support Jiri Olsa
2024-09-17  8:50 ` [PATCHv4 01/14] uprobe: Add data pointer to consumer handlers Jiri Olsa
2024-09-17  8:50 ` [PATCHv4 02/14] uprobe: Add support for session consumer Jiri Olsa
2024-09-17 12:03   ` Oleg Nesterov
2024-09-17 12:51     ` Jiri Olsa
2024-09-22 15:27       ` Oleg Nesterov
2024-09-23  8:05         ` Jiri Olsa
2024-09-23 10:05           ` Oleg Nesterov
2024-09-23 11:02             ` Jiri Olsa
2024-09-23 12:13               ` Oleg Nesterov
2024-09-17 12:22   ` Oleg Nesterov
2024-09-17  8:50 ` [PATCHv4 03/14] bpf: Add support for uprobe multi session attach Jiri Olsa
2024-09-17  8:50 ` [PATCHv4 04/14] bpf: Add support for uprobe multi session context Jiri Olsa
2024-09-17  8:50 ` [PATCHv4 05/14] bpf: Allow return values 0 and 1 for uprobe/kprobe session Jiri Olsa
2024-09-17  8:50 ` [PATCHv4 06/14] libbpf: Fix uretprobe.multi.s programs auto attachment Jiri Olsa
2024-09-17  8:50 ` [PATCHv4 07/14] libbpf: Add support for uprobe multi session attach Jiri Olsa
2024-09-17  8:50 ` [PATCHv4 08/14] selftests/bpf: Add uprobe session test Jiri Olsa
2024-09-17  8:50 ` [PATCHv4 09/14] selftests/bpf: Add uprobe session cookie test Jiri Olsa
2024-09-17  8:50 ` [PATCHv4 10/14] selftests/bpf: Add uprobe session recursive test Jiri Olsa
2024-09-17  8:50 ` [PATCHv4 11/14] selftests/bpf: Add uprobe session verifier test for return value Jiri Olsa
2024-09-17  8:50 ` [PATCHv4 12/14] selftests/bpf: Add kprobe " Jiri Olsa
2024-09-17  8:50 ` [PATCHv4 13/14] selftests/bpf: Add uprobe session single consumer test Jiri Olsa
2024-09-17  8:50 ` Jiri Olsa [this message]
2024-09-23  8:34 ` [PATCHv4 00/14] uprobe, bpf: Add session support 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=20240917085024.765883-15-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=linux-kernel@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=oleg@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=sdf@fomichev.me \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox