Skip to content

Commit d29cb37

Browse files
isilenceaxboe
authored andcommitted
io_uring: add absolute mode wait timeouts
In addition to current relative timeouts for the waiting loop, where the timespec argument specifies the maximum time it can wait for, add support for the absolute mode, with the value carrying a CLOCK_MONOTONIC absolute time until which we should return control back to the user. Suggested-by: Lewis Baker <[email protected]> Signed-off-by: Pavel Begunkov <[email protected]> Link: https://lore.kernel.org/r/4d5b74d67ada882590b2e42aa3aa7117bbf6b55f.1723039801.git.asml.silence@gmail.com Signed-off-by: Jens Axboe <[email protected]>
1 parent d5cce40 commit d29cb37

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

include/uapi/linux/io_uring.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,6 +507,7 @@ struct io_cqring_offsets {
507507
#define IORING_ENTER_SQ_WAIT (1U << 2)
508508
#define IORING_ENTER_EXT_ARG (1U << 3)
509509
#define IORING_ENTER_REGISTERED_RING (1U << 4)
510+
#define IORING_ENTER_ABS_TIMER (1U << 5)
510511

511512
/*
512513
* Passed in for io_uring_setup(2). Copied back with updated info on success

io_uring/io_uring.c

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2387,7 +2387,7 @@ static inline int io_cqring_wait_schedule(struct io_ring_ctx *ctx,
23872387
* Wait until events become available, if we don't already have some. The
23882388
* application must reap them itself, as they reside on the shared cq ring.
23892389
*/
2390-
static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
2390+
static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags,
23912391
const sigset_t __user *sig, size_t sigsz,
23922392
struct __kernel_timespec __user *uts)
23932393
{
@@ -2416,13 +2416,13 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events,
24162416

24172417
if (uts) {
24182418
struct timespec64 ts;
2419-
ktime_t dt;
24202419

24212420
if (get_timespec64(&ts, uts))
24222421
return -EFAULT;
24232422

2424-
dt = timespec64_to_ktime(ts);
2425-
iowq.timeout = ktime_add(dt, ktime_get());
2423+
iowq.timeout = timespec64_to_ktime(ts);
2424+
if (!(flags & IORING_ENTER_ABS_TIMER))
2425+
iowq.timeout = ktime_add(iowq.timeout, ktime_get());
24262426
}
24272427

24282428
if (sig) {
@@ -3153,7 +3153,8 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
31533153

31543154
if (unlikely(flags & ~(IORING_ENTER_GETEVENTS | IORING_ENTER_SQ_WAKEUP |
31553155
IORING_ENTER_SQ_WAIT | IORING_ENTER_EXT_ARG |
3156-
IORING_ENTER_REGISTERED_RING)))
3156+
IORING_ENTER_REGISTERED_RING |
3157+
IORING_ENTER_ABS_TIMER)))
31573158
return -EINVAL;
31583159

31593160
/*
@@ -3251,8 +3252,8 @@ SYSCALL_DEFINE6(io_uring_enter, unsigned int, fd, u32, to_submit,
32513252
if (likely(!ret2)) {
32523253
min_complete = min(min_complete,
32533254
ctx->cq_entries);
3254-
ret2 = io_cqring_wait(ctx, min_complete, sig,
3255-
argsz, ts);
3255+
ret2 = io_cqring_wait(ctx, min_complete, flags,
3256+
sig, argsz, ts);
32563257
}
32573258
}
32583259

0 commit comments

Comments
 (0)