From: Yun Lu <[email protected]>

task_work_run() assumes every stress run observes both scheduler
contention and, when the delete thread is enabled, cancellation of at
least one pending callback.

Neither outcome is guaranteed. Contention is observed only when another
scheduler selects the same one of 128 map values while its task work is
outstanding. A valid run can therefore have no scheduling errors. This
was reproduced with a single scheduler: more than one million callbacks
were scheduled and completed while schedule_error remained zero.

Likewise, a successful map deletion may remove a value after its
callback has completed. delete_success can therefore be nonzero without
callback_success being smaller than callback_scheduled.

Drop the assertion that schedule_error is nonzero. Keep requiring exact
callback accounting when deletion is disabled. With deletion enabled,
allow equal counts but still reject callback_success greater than
callback_scheduled.

Fixes: c6ae18e0af5e ("selftests/bpf: add bpf task work stress tests")
Signed-off-by: Yun Lu <[email protected]>
---
 tools/testing/selftests/bpf/prog_tests/task_work_stress.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/task_work_stress.c 
b/tools/testing/selftests/bpf/prog_tests/task_work_stress.c
index 450d17d91a56..d61636ed5e3d 100644
--- a/tools/testing/selftests/bpf/prog_tests/task_work_stress.c
+++ b/tools/testing/selftests/bpf/prog_tests/task_work_stress.c
@@ -105,13 +105,11 @@ static void task_work_run(bool enable_delete)
                pthread_join(tid_del, NULL);
 
        ASSERT_GT(skel->bss->callback_scheduled, 0, "work scheduled");
-       /* Some scheduling attempts should have failed due to contention */
-       ASSERT_GT(skel->bss->schedule_error, 0, "schedule error");
 
        if (enable_delete) {
-               /* If delete thread is enabled, it has cancelled some callbacks 
*/
                ASSERT_GT(skel->bss->delete_success, 0, "delete success");
-               ASSERT_LT(skel->bss->callback_success, 
skel->bss->callback_scheduled, "callbacks");
+               /* Deletion may race after the task work has already run. */
+               ASSERT_LE(skel->bss->callback_success, 
skel->bss->callback_scheduled, "callbacks");
        } else {
                /* Without delete thread number of scheduled callbacks is the 
same as fired */
                ASSERT_EQ(skel->bss->callback_success, 
skel->bss->callback_scheduled, "callbacks");
-- 
2.43.0


Reply via email to