Re: [PATCH perf/core 15/22] selftests/bpf: Add hit/attach/detach race optimized uprobe test

Jiri Olsa
2025-04-24T12:51:29Z

On Wed, Apr 23, 2025 at 10:42:43AM -0700, Andrii Nakryiko wrote:

SNIP

> > +
> > +static void test_uprobe_race(void)
> > +{
> > + int err, i, nr_threads;
> > + pthread_t *threads;
> > +
> > + nr_threads = libbpf_num_possible_cpus();
> > + if (!ASSERT_GE(nr_threads, 0, "libbpf_num_possible_cpus"))
>
> I hope there are strictly more than zero CPUs... ;)
>
> > + return;
> > +
> > + threads = malloc(sizeof(*threads) * nr_threads);
> > + if (!ASSERT_OK_PTR(threads, "malloc"))
> > + return;
> > +
> > + for (i = 0; i < nr_threads; i++) {
> > + err = pthread_create(&threads[i], NULL, i % 2 ? worker_trigger : worker_attach,
> > + NULL);
>
> What happens when three is just one CPU?
>

right, we need at least 2 threads, how about the change below

thanks,
jirka

---
diff --git a/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c b/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c
index d55c3579cebe..c885f097eed4 100644
--- a/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c
+++ b/tools/testing/selftests/bpf/prog_tests/uprobe_syscall.c
@@ -701,8 +701,9 @@ static void test_uprobe_race(void)
pthread_t *threads;

nr_threads = libbpf_num_possible_cpus();
- if (!ASSERT_GE(nr_threads, 0, "libbpf_num_possible_cpus"))
+ if (!ASSERT_GT(nr_threads, 0, "libbpf_num_possible_cpus"))
return;
+ nr_threads = max(2, nr_threads);

threads = malloc(sizeof(*threads) * nr_threads);
if (!ASSERT_OK_PTR(threads, "malloc"))