History

io_uring: use TWA_SIGNAL_NO_IPI if IORING_SETUP_COOP_TASKRUN is used

If this is set, io_uring will never use an IPI to deliver a task_work notification. This can be used in the common case where a single task or thread communicates with the ring, and doesn't rely on io_uring_cqe_peek(). This provides a noticeable win in performance, both from eliminating the IPI itself, but also from avoiding interrupting the submitting task unnecessarily.

Jens Axboe committed 4 years ago

Commit e1169f01 parent 9f010502 files · +21 −4Browse files

Unified · Split

2 files
  1. fs/io_uring.c +13 −4
  2. include/uapi/linux/io_uring.h +8 −0
fs/io_uring.c+13−4
@@ -11327,12 +11327,20 @@ static __cold int io_uring_create(unsigned entries, struct io_uring_params *p, · 11326 unmodified lines
11327 ctx->user = get_uid(current_user());11327 ctx->user = get_uid(current_user());
11328 11328
11329 /*11329 /*
11330 * For SQPOLL, we just need a wakeup, always.11330 * For SQPOLL, we just need a wakeup, always. For !SQPOLL, if
11331 * COOP_TASKRUN is set, then IPIs are never needed by the app.
11331 */11332 */
11332 if (ctx->flags & IORING_SETUP_SQPOLL)11333 ret = -EINVAL;
11334 if (ctx->flags & IORING_SETUP_SQPOLL) {
11335 /* IPI related flags don't make sense with SQPOLL */
11336 if (ctx->flags & IORING_SETUP_COOP_TASKRUN)
11337 goto err;
11333 ctx->notify_method = TWA_SIGNAL_NO_IPI;11338 ctx->notify_method = TWA_SIGNAL_NO_IPI;
11334 else11339 } else if (ctx->flags & IORING_SETUP_COOP_TASKRUN) {
11340 ctx->notify_method = TWA_SIGNAL_NO_IPI;
11341 } else {
11335 ctx->notify_method = TWA_SIGNAL;11342 ctx->notify_method = TWA_SIGNAL;
11343 }
11336 11344
11337 /*11345 /*
11338 * This is just grabbed for accounting purposes. When a process exits,11346 * This is just grabbed for accounting purposes. When a process exits,
@@ -11431,7 +11439,8 @@ static long io_uring_setup(u32 entries, struct io_uring_params __user *params) · 92 unmodified lines
11431 if (p.flags & ~(IORING_SETUP_IOPOLL | IORING_SETUP_SQPOLL |11439 if (p.flags & ~(IORING_SETUP_IOPOLL | IORING_SETUP_SQPOLL |
11432 IORING_SETUP_SQ_AFF | IORING_SETUP_CQSIZE |11440 IORING_SETUP_SQ_AFF | IORING_SETUP_CQSIZE |
11433 IORING_SETUP_CLAMP | IORING_SETUP_ATTACH_WQ |11441 IORING_SETUP_CLAMP | IORING_SETUP_ATTACH_WQ |
11434 IORING_SETUP_R_DISABLED | IORING_SETUP_SUBMIT_ALL))11442 IORING_SETUP_R_DISABLED | IORING_SETUP_SUBMIT_ALL |
11443 IORING_SETUP_COOP_TASKRUN))
11435 return -EINVAL;11444 return -EINVAL;
11436 11445
11437 return io_uring_create(entries, &p, params);11446 return io_uring_create(entries, &p, params);
include/uapi/linux/io_uring.h+8−0
@@ -102,6 +102,14 @@ enum { · 101 unmodified lines
102#define IORING_SETUP_ATTACH_WQ (1U << 5) /* attach to existing wq */102#define IORING_SETUP_ATTACH_WQ (1U << 5) /* attach to existing wq */
103#define IORING_SETUP_R_DISABLED (1U << 6) /* start with ring disabled */103#define IORING_SETUP_R_DISABLED (1U << 6) /* start with ring disabled */
104#define IORING_SETUP_SUBMIT_ALL (1U << 7) /* continue submit on error */104#define IORING_SETUP_SUBMIT_ALL (1U << 7) /* continue submit on error */
105/*
106 * Cooperative task running. When requests complete, they often require
107 * forcing the submitter to transition to the kernel to complete. If this
108 * flag is set, work will be done when the task transitions anyway, rather
109 * than force an inter-processor interrupt reschedule. This avoids interrupting
110 * a task running in userspace, and saves an IPI.
111 */
112#define IORING_SETUP_COOP_TASKRUN (1U << 8)
105 113
106enum {114enum {
107 IORING_OP_NOP,115 IORING_OP_NOP,