Skip to content

Commit 01f89b6

Browse files
committed
test/recv-mshot-fair: submit !DEFER receives at the same time
The test currently allows !DEFER to be unfair after resubmission, because it would arm each recv as needed and submit it at the same time. This means that once they are all done, R1 will be submitted separately and process the remaining, and repeat for R2..R4. That causes unfairness, as only one recv would be pending at the time for that case. Keep track of pending submits and do them in one go, preserving fairness even for !DEFER. Signed-off-by: Jens Axboe <[email protected]>
1 parent ed1108f commit 01f89b6

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

test/recv-mshot-fair.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ static int recv_get_cqe(struct io_uring *ring,
155155
int ret;
156156

157157
do {
158-
ret = io_uring_submit_and_wait_timeout(ring, cqe, 1, &ts, NULL);
158+
ret = io_uring_wait_cqe_timeout(ring, cqe, &ts);
159159
if (!ret) {
160160
struct recv_data *rd = io_uring_cqe_get_data(*cqe);
161161

@@ -196,6 +196,7 @@ static int do_recv(struct io_uring *ring)
196196
struct recv_data *rd;
197197
int ret = 1;
198198
int done = 0;
199+
int pending_submit = 0;
199200

200201
last_rd = NULL;
201202
bytes_since_last = 0;
@@ -224,8 +225,12 @@ static int do_recv(struct io_uring *ring)
224225
continue;
225226
}
226227
io_uring_cqe_seen(ring, cqe);
227-
if (!(cqe->flags & IORING_CQE_F_MORE) && rd->recv_bytes)
228+
if (!(cqe->flags & IORING_CQE_F_MORE) && rd->recv_bytes) {
228229
arm_recv(ring, rd);
230+
pending_submit++;
231+
}
232+
if (pending_submit == NR_RDS)
233+
io_uring_submit(ring);
229234
} while (done < NR_RDS);
230235

231236
ret = 0;
@@ -455,7 +460,6 @@ static int run_tests(void)
455460
return T_EXIT_FAIL;
456461
}
457462

458-
/* DEFER_TASKRUN should be fully fair and not have overshoots */
459463
if (r.unfair || r.mshot_too_big) {
460464
fprintf(stderr, "DEFER unfair=%d, too_big=%d\n", r.unfair, r.mshot_too_big);
461465
return T_EXIT_FAIL;
@@ -467,13 +471,7 @@ static int run_tests(void)
467471
return T_EXIT_FAIL;
468472
}
469473

470-
/*
471-
* normal task_work should not have overshoots, but may not be fair
472-
* because of the re-arming.
473-
*/
474-
if (r.unfair)
475-
fprintf(stdout, "!DEFER bundle unfair, expected\n");
476-
if (r.mshot_too_big) {
474+
if (r.unfair || r.mshot_too_big) {
477475
fprintf(stderr, "!DEFER bundle too_big=%d\n", r.mshot_too_big);
478476
return T_EXIT_FAIL;
479477
}
@@ -484,13 +482,7 @@ static int run_tests(void)
484482
return T_EXIT_FAIL;
485483
}
486484

487-
/*
488-
* normal task_work should not have overshoots, but may not be fair
489-
* because of the re-arming.
490-
*/
491-
if (r.unfair)
492-
fprintf(stdout, "!DEFER unfair, expected\n");
493-
if (r.mshot_too_big) {
485+
if (r.unfair || r.mshot_too_big) {
494486
fprintf(stderr, "!DEFER too_big=%d\n", r.mshot_too_big);
495487
return T_EXIT_FAIL;
496488
}

0 commit comments

Comments
 (0)