From: Jonathan Bastari Thamrin <[email protected]>

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 <[email protected]>
---
 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 <[email protected]>



Reply via email to