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
1132711327 ctx->user = get_uid(current_user());
1132811328
1132911329 /*
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.
1133111332 */
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;
1133311338 ctx->notify_method = TWA_SIGNAL_NO_IPI;
11334− else
11339+ } else if (ctx->flags & IORING_SETUP_COOP_TASKRUN) {
11340+ ctx->notify_method = TWA_SIGNAL_NO_IPI;
11341+ } else {
1133511342 ctx->notify_method = TWA_SIGNAL;
11343+ }
1133611344
1133711345 /*
1133811346 * 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
1143111439 if (p.flags & ~(IORING_SETUP_IOPOLL | IORING_SETUP_SQPOLL |
1143211440 IORING_SETUP_SQ_AFF | IORING_SETUP_CQSIZE |
1143311441 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))
1143511444 return -EINVAL;
1143611445
1143711446 return io_uring_create(entries, &p, params);
include/uapi/linux/io_uring.h+8−0
@@ -102,6 +102,14 @@ enum { · 101 unmodified lines
102102 #define IORING_SETUP_ATTACH_WQ (1U << 5) /* attach to existing wq */
103103 #define IORING_SETUP_R_DISABLED (1U << 6) /* start with ring disabled */
104104 #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)
105113
106114 enum {
107115 IORING_OP_NOP,