mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH bpf-next] selftests/bpf: Fix wq test by changing 50us sleep to polling over 1s
@ 2026-10-05  9:37 Jonathan Bastari Thamrin via B4 Relay
  2026-10-19  1:31 ` Kumar Kartikeya Dwivedi
  0 siblings, 1 reply; 2+ messages in thread
From: Jonathan Bastari Thamrin via B4 Relay @ 2026-10-05  9:37 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Eduard Zingerman, Kumar Kartikeya Dwivedi, Martin KaFai Lau,
	Song Liu, Yonghong Song, Jiri Olsa, Emil Tsalapatis,
	Ihor Solodrai, Shuah Khan
  Cc: bpf, linux-kselftest, linux-kernel, Jonathan Bastari Thamrin

From: Jonathan Bastari Thamrin <thamrinjonathan@gmail.com>

wq test fails with ok_sleepable reading 0 instead of 2 as workqueue
callback hasn't executed before check.

This happens as callback runs later on a kworker and 50us isn't always
enough.

Change from 50us sleep to polling over 1s.

Before (usleep(50)): 3 fails out of 5000 runs
Diagnosing issue (usleep(0)): 23 out of 100 runs
After (Polling): 0 out of 5000 runs
Tested using vmtest on x86_64, test pinned to one CPU with `yes` load

Link: https://github.com/kernel-patches/vmtest/issues/455

Signed-off-by: Jonathan Bastari Thamrin <thamrinjonathan@gmail.com>
---
 tools/testing/selftests/bpf/prog_tests/wq.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/wq.c b/tools/testing/selftests/bpf/prog_tests/wq.c
index 84831eecc..b55d8547f 100644
--- a/tools/testing/selftests/bpf/prog_tests/wq.c
+++ b/tools/testing/selftests/bpf/prog_tests/wq.c
@@ -7,7 +7,7 @@
 void serial_test_wq(void)
 {
 	struct wq *wq_skel = NULL;
-	int err, prog_fd;
+	int err, prog_fd, tries;
 
 	LIBBPF_OPTS(bpf_test_run_opts, topts);
 
@@ -28,7 +28,13 @@ void serial_test_wq(void)
 	ASSERT_OK(err, "test_run");
 	ASSERT_EQ(topts.retval, 0, "test_run");
 
-	usleep(50); /* 10 usecs should be enough, but give it extra */
+	/* loop check over 1 sec to make sure it doesn't fail early when busy */
+	for (tries = 1000; tries >= 0; tries--) {
+		if (wq_skel->bss->ok_sleepable == (1 << 1))
+			break;
+
+		usleep(1000);
+	}
 
 	ASSERT_EQ(wq_skel->bss->ok_sleepable, (1 << 1), "ok_sleepable");
 clean_up:

---
base-commit: b5a4aa31abd6fe90009b63e35dc18c67d041ec0c
change-id: 20261005-wq-poll-fix-f46c47dbaf03

Best regards,
-- 
Jonathan Bastari Thamrin <thamrinjonathan@gmail.com>



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-19  1:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-05  9:37 [PATCH bpf-next] selftests/bpf: Fix wq test by changing 50us sleep to polling over 1s Jonathan Bastari Thamrin via B4 Relay
2026-10-19  1:31 ` Kumar Kartikeya Dwivedi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®