Commit a41525ab authored by Jens Axboe's avatar Jens Axboe

io_uring: add support for absolute timeouts

This is a pretty trivial addition on top of the relative timeouts
we have now, but it's handy for ensuring tighter timing for those
that are building scheduling primitives on top of io_uring.
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent ba5290cc
...@@ -1978,13 +1978,17 @@ static int io_timeout(struct io_kiocb *req, const struct io_uring_sqe *sqe) ...@@ -1978,13 +1978,17 @@ static int io_timeout(struct io_kiocb *req, const struct io_uring_sqe *sqe)
unsigned count; unsigned count;
struct io_ring_ctx *ctx = req->ctx; struct io_ring_ctx *ctx = req->ctx;
struct list_head *entry; struct list_head *entry;
enum hrtimer_mode mode;
struct timespec64 ts; struct timespec64 ts;
unsigned span = 0; unsigned span = 0;
unsigned flags;
if (unlikely(ctx->flags & IORING_SETUP_IOPOLL)) if (unlikely(ctx->flags & IORING_SETUP_IOPOLL))
return -EINVAL; return -EINVAL;
if (sqe->flags || sqe->ioprio || sqe->buf_index || sqe->timeout_flags || if (sqe->flags || sqe->ioprio || sqe->buf_index || sqe->len != 1)
sqe->len != 1) return -EINVAL;
flags = READ_ONCE(sqe->timeout_flags);
if (flags & ~IORING_TIMEOUT_ABS)
return -EINVAL; return -EINVAL;
if (get_timespec64(&ts, u64_to_user_ptr(sqe->addr))) if (get_timespec64(&ts, u64_to_user_ptr(sqe->addr)))
...@@ -2042,10 +2046,13 @@ static int io_timeout(struct io_kiocb *req, const struct io_uring_sqe *sqe) ...@@ -2042,10 +2046,13 @@ static int io_timeout(struct io_kiocb *req, const struct io_uring_sqe *sqe)
list_add(&req->list, entry); list_add(&req->list, entry);
spin_unlock_irq(&ctx->completion_lock); spin_unlock_irq(&ctx->completion_lock);
hrtimer_init(&req->timeout.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); if (flags & IORING_TIMEOUT_ABS)
mode = HRTIMER_MODE_ABS;
else
mode = HRTIMER_MODE_REL;
hrtimer_init(&req->timeout.timer, CLOCK_MONOTONIC, mode);
req->timeout.timer.function = io_timeout_fn; req->timeout.timer.function = io_timeout_fn;
hrtimer_start(&req->timeout.timer, timespec64_to_ktime(ts), hrtimer_start(&req->timeout.timer, timespec64_to_ktime(ts), mode);
HRTIMER_MODE_REL);
return 0; return 0;
} }
......
...@@ -70,6 +70,11 @@ struct io_uring_sqe { ...@@ -70,6 +70,11 @@ struct io_uring_sqe {
*/ */
#define IORING_FSYNC_DATASYNC (1U << 0) #define IORING_FSYNC_DATASYNC (1U << 0)
/*
* sqe->timeout_flags
*/
#define IORING_TIMEOUT_ABS (1U << 0)
/* /*
* IO completion data structure (Completion Queue Entry) * IO completion data structure (Completion Queue Entry)
*/ */
......
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