Skip to content

Commit 7ed9e09

Browse files
committed
io_uring: wire up min batch wake timeout
Expose min_wait_usec in io_uring_getevents_arg, replacing the pad member that is currently in there. The value is in usecs, which is explained in the name as well. Note that if min_wait_usec and a normal timeout is used in conjunction, the normal timeout is still relative to the base time. For example, if min_wait_usec is set to 100 and the normal timeout is 1000, the max total time waited is still 1000. This also means that if the normal timeout is shorter than min_wait_usec, then only the min_wait_usec will take effect. See previous commit for an explanation of how this works. IORING_FEAT_MIN_TIMEOUT is added as a feature flag for this, as applications doing submit_and_wait_timeout() style operations will generally not see the -EINVAL from the wait side as they return the number of IOs submitted. Only if no IOs are submitted will the -EINVAL bubble back up to the application. Signed-off-by: Jens Axboe <[email protected]>
1 parent 1100c4a commit 7ed9e09

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

include/uapi/linux/io_uring.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,7 @@ struct io_uring_params {
543543
#define IORING_FEAT_LINKED_FILE (1U << 12)
544544
#define IORING_FEAT_REG_REG_RING (1U << 13)
545545
#define IORING_FEAT_RECVSEND_BUNDLE (1U << 14)
546+
#define IORING_FEAT_MIN_TIMEOUT (1U << 15)
546547

547548
/*
548549
* io_uring_register(2) opcodes and arguments
@@ -766,7 +767,7 @@ enum io_uring_register_restriction_op {
766767
struct io_uring_getevents_arg {
767768
__u64 sigmask;
768769
__u32 sigmask_sz;
769-
__u32 pad;
770+
__u32 min_wait_usec;
770771
__u64 ts;
771772
};
772773

io_uring/io_uring.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2475,6 +2475,7 @@ struct ext_arg {
24752475
size_t argsz;
24762476
struct __kernel_timespec __user *ts;
24772477
const sigset_t __user *sig;
2478+
ktime_t min_time;
24782479
};
24792480

24802481
/*
@@ -2508,7 +2509,7 @@ static int io_cqring_wait(struct io_ring_ctx *ctx, int min_events, u32 flags,
25082509
iowq.cq_min_tail = READ_ONCE(ctx->rings->cq.tail);
25092510
iowq.nr_timeouts = atomic_read(&ctx->cq_timeouts);
25102511
iowq.hit_timeout = 0;
2511-
iowq.min_timeout = 0;
2512+
iowq.min_timeout = ext_arg->min_time;
25122513
iowq.timeout = KTIME_MAX;
25132514
start_time = io_get_time(ctx);
25142515

@@ -3239,8 +3240,7 @@ static int io_get_ext_arg(unsigned flags, const void __user *argp,
32393240
return -EINVAL;
32403241
if (copy_from_user(&arg, argp, sizeof(arg)))
32413242
return -EFAULT;
3242-
if (arg.pad)
3243-
return -EINVAL;
3243+
ext_arg->min_time = arg.min_wait_usec * NSEC_PER_USEC;
32443244
ext_arg->sig = u64_to_user_ptr(arg.sigmask);
32453245
ext_arg->argsz = arg.sigmask_sz;
32463246
ext_arg->ts = u64_to_user_ptr(arg.ts);
@@ -3641,7 +3641,7 @@ static __cold int io_uring_create(unsigned entries, struct io_uring_params *p,
36413641
IORING_FEAT_EXT_ARG | IORING_FEAT_NATIVE_WORKERS |
36423642
IORING_FEAT_RSRC_TAGS | IORING_FEAT_CQE_SKIP |
36433643
IORING_FEAT_LINKED_FILE | IORING_FEAT_REG_REG_RING |
3644-
IORING_FEAT_RECVSEND_BUNDLE;
3644+
IORING_FEAT_RECVSEND_BUNDLE | IORING_FEAT_MIN_TIMEOUT;
36453645

36463646
if (copy_to_user(params, p, sizeof(*p))) {
36473647
ret = -EFAULT;

0 commit comments

Comments
 (0)