Skip to content

Commit

Permalink
io_uring: refactor scheduling in io_cqring_wait
Browse files Browse the repository at this point in the history
[ Upstream commit c1d5a22 ]

schedule_timeout() with timeout=MAX_SCHEDULE_TIMEOUT is guaranteed to
work just as schedule(), so instead of hand-coding it based on arguments
always use the timeout version and simplify code.

Signed-off-by: Pavel Begunkov <asml.silence@gmail.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
isilence authored and gregkh committed Mar 20, 2021
1 parent bda646b commit f6acca6
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions fs/io_uring.c
Original file line number Diff line number Diff line change
Expand Up @@ -7226,9 +7226,8 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
.to_wait = min_events,
};
struct io_rings *rings = ctx->rings;
struct timespec64 ts;
signed long timeout = 0;
int ret = 0;
signed long timeout = MAX_SCHEDULE_TIMEOUT;
int ret;

do {
io_cqring_overflow_flush(ctx, false, NULL, NULL);
Expand All @@ -7252,6 +7251,8 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
}

if (uts) {
struct timespec64 ts;

if (get_timespec64(&ts, uts))
return -EFAULT;
timeout = timespec64_to_jiffies(&ts);
Expand All @@ -7277,14 +7278,10 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
finish_wait(&ctx->wait, &iowq.wq);
continue;
}
if (uts) {
timeout = schedule_timeout(timeout);
if (timeout == 0) {
ret = -ETIME;
break;
}
} else {
schedule();
timeout = schedule_timeout(timeout);
if (timeout == 0) {
ret = -ETIME;
break;
}
} while (1);
finish_wait(&ctx->wait, &iowq.wq);
Expand Down

0 comments on commit f6acca6

Please sign in to comment.