Commit c1d5a224 authored by Pavel Begunkov's avatar Pavel Begunkov Committed by Jens Axboe

io_uring: refactor scheduling in io_cqring_wait

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: default avatarPavel Begunkov <asml.silence@gmail.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 9936c7c2
...@@ -7213,9 +7213,8 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, ...@@ -7213,9 +7213,8 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
.to_wait = min_events, .to_wait = min_events,
}; };
struct io_rings *rings = ctx->rings; struct io_rings *rings = ctx->rings;
struct timespec64 ts; signed long timeout = MAX_SCHEDULE_TIMEOUT;
signed long timeout = 0; int ret;
int ret = 0;
do { do {
io_cqring_overflow_flush(ctx, false, NULL, NULL); io_cqring_overflow_flush(ctx, false, NULL, NULL);
...@@ -7239,6 +7238,8 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, ...@@ -7239,6 +7238,8 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
} }
if (uts) { if (uts) {
struct timespec64 ts;
if (get_timespec64(&ts, uts)) if (get_timespec64(&ts, uts))
return -EFAULT; return -EFAULT;
timeout = timespec64_to_jiffies(&ts); timeout = timespec64_to_jiffies(&ts);
...@@ -7264,15 +7265,11 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, ...@@ -7264,15 +7265,11 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
finish_wait(&ctx->wait, &iowq.wq); finish_wait(&ctx->wait, &iowq.wq);
continue; continue;
} }
if (uts) {
timeout = schedule_timeout(timeout); timeout = schedule_timeout(timeout);
if (timeout == 0) { if (timeout == 0) {
ret = -ETIME; ret = -ETIME;
break; break;
} }
} else {
schedule();
}
} while (1); } while (1);
finish_wait(&ctx->wait, &iowq.wq); finish_wait(&ctx->wait, &iowq.wq);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment