From patchwork Fri Mar 29 20:09:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13610999 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2670313B2BF for ; Fri, 29 Mar 2024 20:12:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711743169; cv=none; b=tebcE/Wg3An/+2FagOuMbRJZ9Pw3pAZLON4RNjC74BQcb1xhxEyHIaJoNXD2IEmrv/kyiwWixgDMQk2TARgXWHKNYCRAii3HTjYskghAbASqXJhBbzjMFsmgXwf9NDi9EuO0ICcKZbUtr79w+4pYnozzbdkeYxEZb5ynDjT+fys= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711743169; c=relaxed/simple; bh=qDcqDLDpAnd9K/RjdyVGBRpxWCnWUrsRiDpoplnVPpc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l+jCJwIIZHwV7neDq+PTFu7ubp0+0i7n+uoKpiuiA/1FMTG6VaQp+1GS0in1VBqtlTeaYppPGwUe6R3iZ3nTI2NHJPzZluB+duELyuo9kh68ofYwh+QJv6T4uZh1BsAFF2t9g3CXW9QgAI2v+cHQm9XG6EXbeB2rdT4kn3OsUE8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=KnaRqCO5; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="KnaRqCO5" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-6e6ca65edc9so587273b3a.0 for ; Fri, 29 Mar 2024 13:12:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1711743166; x=1712347966; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JPzqmNhp9AOxTrMleb/aj2Nsy4wAvG/gncziR99ZHk8=; b=KnaRqCO5GDmNVPYsxBojn/U32/SJkpJ8gREPRfyBOUEEt2b3S6dQPqhPfLFfUg+nbz +pbPOyHTOSGCxBIcwokjFT445lCxN/JvJZbZ+DG1zs5XVBGjNDw4pBN1nbZHXZBAkVyO AuOelra47q5bHGZx/PWL+/KdL4+uzk+lzKYwR+cYZeSepDDvAGo8Gqj4/BDhDWBOlIei CAy3s1ECXS01TqH/vy/N6QJbsA3t47OxrZz87366PHhXQ7LPcE2V7czBi7O6LlwbX4hr I8mpDdCNOS25RGZCO+nxPYRQ4cpEiNXHfPJ4nknWWNP3BW4wQXmOiX8XH4RR9UduPdyW PHxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711743166; x=1712347966; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JPzqmNhp9AOxTrMleb/aj2Nsy4wAvG/gncziR99ZHk8=; b=adiVuKQC9B9vLiDaAupY9F5rXx8FX8MgKUriqGzaWAh6lpLaIoYpvsn96gGItjrIeo ntq8bBG2l48uY1D+xfmtsRGULySCbf8BnB3PqD3is9DhzYM7/3ZCWYVeihZqOaPyU4Am 0vOceB1gAbfhSTPu1Bogrzg0Z2TVaZ6EKPlv0O3w48EsshgwysglMOzSgf91Rze1I013 RGcv0saK4ZqrqWdYUKSW5GnAyMqj1PU79oouKoTvAQgkkNRZuAPpHn5QfnHDL2K/muDT C8xsicLffSEO4pqNHLrTSnu6ZleG6yyWHZ4L902f6t3s6/b6TCPGqoTBDb2DnCsAMsZh h3sA== X-Gm-Message-State: AOJu0YwWhEpxJ0NFUrXyP8SIz4Tg821Qr+m3PVWDIp677LK9XwC2C4Ib y3E5UzZ4NJWq0yI/K+JlAZxBmO0cPEIhMHHb2I4+M+jIy6HW4GCcotKGGkStR2SI6/2iYfmgqaI f X-Google-Smtp-Source: AGHT+IHSoG03GFYcjR0a75xAP7usojCkIso5NXcueassNABkKMK7nBar/I6g717QUyphOH+HG4Hz4A== X-Received: by 2002:a05:6a00:bda:b0:6ea:d0b0:3f96 with SMTP id x26-20020a056a000bda00b006ead0b03f96mr3433388pfu.1.1711743165678; Fri, 29 Mar 2024 13:12:45 -0700 (PDT) Received: from m2max.thefacebook.com ([2620:10d:c090:600::1:40c6]) by smtp.gmail.com with ESMTPSA id b11-20020aa7810b000000b006ea90941b22sm3388728pfi.40.2024.03.29.13.12.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 13:12:43 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 1/3] io_uring: add remote task_work execution helper Date: Fri, 29 Mar 2024 14:09:28 -0600 Message-ID: <20240329201241.874888-2-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329201241.874888-1-axboe@kernel.dk> References: <20240329201241.874888-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 All our task_work handling is targeted at the state in the io_kiocb itself, which is what it is being used for. However, MSG_RING rolls its own task_work handling, ignoring how that is usually done. In preparation for switching MSG_RING to be able to use the normal task_work handling, add io_req_task_work_add_remote() which allows the caller to pass in the target io_ring_ctx. Signed-off-by: Jens Axboe --- io_uring/io_uring.c | 30 ++++++++++++++++++++++-------- io_uring/io_uring.h | 2 ++ 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index fddaefb9cbff..a311a244914b 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -1232,9 +1232,10 @@ void tctx_task_work(struct callback_head *cb) WARN_ON_ONCE(ret); } -static inline void io_req_local_work_add(struct io_kiocb *req, unsigned flags) +static inline void io_req_local_work_add(struct io_kiocb *req, + struct io_ring_ctx *ctx, + unsigned flags) { - struct io_ring_ctx *ctx = req->ctx; unsigned nr_wait, nr_tw, nr_tw_prev; struct llist_node *head; @@ -1300,9 +1301,10 @@ static inline void io_req_local_work_add(struct io_kiocb *req, unsigned flags) wake_up_state(ctx->submitter_task, TASK_INTERRUPTIBLE); } -static void io_req_normal_work_add(struct io_kiocb *req) +static void io_req_normal_work_add(struct io_kiocb *req, + struct task_struct *task) { - struct io_uring_task *tctx = req->task->io_uring; + struct io_uring_task *tctx = task->io_uring; struct io_ring_ctx *ctx = req->ctx; /* task_work already pending, we're done */ @@ -1321,7 +1323,7 @@ static void io_req_normal_work_add(struct io_kiocb *req) return; } - if (likely(!task_work_add(req->task, &tctx->task_work, ctx->notify_method))) + if (likely(!task_work_add(task, &tctx->task_work, ctx->notify_method))) return; io_fallback_tw(tctx, false); @@ -1331,10 +1333,22 @@ void __io_req_task_work_add(struct io_kiocb *req, unsigned flags) { if (req->ctx->flags & IORING_SETUP_DEFER_TASKRUN) { rcu_read_lock(); - io_req_local_work_add(req, flags); + io_req_local_work_add(req, req->ctx, flags); + rcu_read_unlock(); + } else { + io_req_normal_work_add(req, req->task); + } +} + +void io_req_task_work_add_remote(struct io_kiocb *req, struct io_ring_ctx *ctx, + unsigned flags) +{ + if (ctx->flags & IORING_SETUP_DEFER_TASKRUN) { + rcu_read_lock(); + io_req_local_work_add(req, ctx, flags); rcu_read_unlock(); } else { - io_req_normal_work_add(req); + io_req_normal_work_add(req, READ_ONCE(ctx->submitter_task)); } } @@ -1348,7 +1362,7 @@ static void __cold io_move_task_work_from_local(struct io_ring_ctx *ctx) io_task_work.node); node = node->next; - io_req_normal_work_add(req); + io_req_normal_work_add(req, req->task); } } diff --git a/io_uring/io_uring.h b/io_uring/io_uring.h index 1eb65324792a..4155379ee586 100644 --- a/io_uring/io_uring.h +++ b/io_uring/io_uring.h @@ -74,6 +74,8 @@ struct file *io_file_get_fixed(struct io_kiocb *req, int fd, unsigned issue_flags); void __io_req_task_work_add(struct io_kiocb *req, unsigned flags); +void io_req_task_work_add_remote(struct io_kiocb *req, struct io_ring_ctx *ctx, + unsigned flags); bool io_alloc_async_data(struct io_kiocb *req); void io_req_task_queue(struct io_kiocb *req); void io_req_task_complete(struct io_kiocb *req, struct io_tw_state *ts); From patchwork Fri Mar 29 20:09:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13611000 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0D1313AA3C for ; Fri, 29 Mar 2024 20:12:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711743170; cv=none; b=SH/pXEvrLMNP33Wryil1/MRdb8zXuSa0ZJi1YlUVbPjrFj9V5y7RvpGxorY5/O+igAXePX0813x9QTvIKp78WpShXGbn0ZNv5Z5GDy58+8oOp5QlnxVYiHEI8CLSl4dcj5lqYqFcZVM11JvChEW7O0HpEmRizveo+Klwj1J1CIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711743170; c=relaxed/simple; bh=ZOc31Chv9GMzFMptACL4IWPv63UmYAghUAlkMAAqqNc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=iVDjOhjE0XW4y0ta07XTKNuUziNTTSuYdHCz7U9iZxbrUlOQhvsKfYCMtALOylBr2phHCWvfcSB72XlaR+5yN76VAU962/74daqILIMSiPxvdSr2d55ZKCJF+Hi+rG8lctXyorxet3Meus9TsHef1uu2Uvr93q39sJ2U0thPeEI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=nYM6/V5T; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="nYM6/V5T" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-6ea729f2e38so419901b3a.1 for ; Fri, 29 Mar 2024 13:12:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1711743168; x=1712347968; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D1mvpGKi0DP7HNfgie+1LU8g3Dn3YtdBR+/r1RYG5X0=; b=nYM6/V5TEO5HhpSa7N9Y1/dPkxIZoL9mvJLJF2NbgiJOwpmZIst/QZA+4swRe0Rus8 RGGoIK9Ols+LX7KbUYY19BiftNMOpLOLywrHChBqt6wyRbR03T3ezyatDPXMY9g7GqHS qF4+8tyoL6IE8vVOTCd5leYUhQIFs/oK7LcB+SOHNDOkPz6es3jTnhWUQnrwzErjrboD wFDlae/wn/uTjoMSpbIGOBXGkYpUUoyrKi71PZR9t0Vj/qYgd7abTlQQ1Kp/cNZSES9n zxhqIUMBzlbxymymFpwuTw4SyVxSOGBeWnWxaa27MChjc+3/a9sH9PxUbV3a093XSsab vfGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711743168; x=1712347968; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D1mvpGKi0DP7HNfgie+1LU8g3Dn3YtdBR+/r1RYG5X0=; b=sLX2LZit6s4dIcSVlM/xaXG7Hpr/NG5f+aWfsDzVNEyDANdxfpmzm3DnVY7JoSBLcj yYNTvbqYQSx7DD2CtUlsJw1hXNioyMLRmt+GlCGLkU872xjQ5GM1tOmSlQVlHwFsQCg3 EykIjnrx+vsVbUo42WNPxRSpJAjS2HLRG8Ptx9Y2sAEM7jXpLIhMxG5chcVVGRDF7YTH ySR1GAp1kPUlzCCOFX9enq0dGkgaOB3qZL9V1gAfm+j24yYeWItUPdfG/C/4FxDtMOUa qRK38eQnC7/7xI32gv5kcIUJGw+6MAXXLctE5gode2C5Dx3/yPEFd5yQseTIvdk+BGPE XEGQ== X-Gm-Message-State: AOJu0YwYd000FmJfgXnwwKSbB+qEdjnu3GqfVvMUyf4x1EJQqNbdgoPt 00/p0tR5R45f1M/QM7R55ROURuz6OmpzasgucAzduZXw1mZLSUkH4AXYj3rSC2yMGgNCDtwx0ol Q X-Google-Smtp-Source: AGHT+IFtWzjL7WnecHgR7Yj3ZpMbpcbrgJUu6C/tv9xdrMO7em/CpefSa4GW18HWQQSbKlcqmJsVCA== X-Received: by 2002:a05:6a20:72a8:b0:1a3:c3e6:aef9 with SMTP id o40-20020a056a2072a800b001a3c3e6aef9mr3544438pzk.1.1711743167744; Fri, 29 Mar 2024 13:12:47 -0700 (PDT) Received: from m2max.thefacebook.com ([2620:10d:c090:600::1:40c6]) by smtp.gmail.com with ESMTPSA id b11-20020aa7810b000000b006ea90941b22sm3388728pfi.40.2024.03.29.13.12.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 13:12:46 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 2/3] io_uring/msg_ring: cleanup posting to IOPOLL vs !IOPOLL ring Date: Fri, 29 Mar 2024 14:09:29 -0600 Message-ID: <20240329201241.874888-3-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329201241.874888-1-axboe@kernel.dk> References: <20240329201241.874888-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move the posting outside the checking and locking, it's cleaner that way. Signed-off-by: Jens Axboe --- io_uring/msg_ring.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/io_uring/msg_ring.c b/io_uring/msg_ring.c index cd6dcf634ba3..d1f66a40b4b4 100644 --- a/io_uring/msg_ring.c +++ b/io_uring/msg_ring.c @@ -147,13 +147,11 @@ static int io_msg_ring_data(struct io_kiocb *req, unsigned int issue_flags) if (target_ctx->flags & IORING_SETUP_IOPOLL) { if (unlikely(io_double_lock_ctx(target_ctx, issue_flags))) return -EAGAIN; - if (io_post_aux_cqe(target_ctx, msg->user_data, msg->len, flags)) - ret = 0; - io_double_unlock_ctx(target_ctx); - } else { - if (io_post_aux_cqe(target_ctx, msg->user_data, msg->len, flags)) - ret = 0; } + if (io_post_aux_cqe(target_ctx, msg->user_data, msg->len, flags)) + ret = 0; + if (target_ctx->flags & IORING_SETUP_IOPOLL) + io_double_unlock_ctx(target_ctx); return ret; } From patchwork Fri Mar 29 20:09:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13611001 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D997B13B5A4 for ; Fri, 29 Mar 2024 20:12:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711743172; cv=none; b=VOPGPeGLBvOMikhJaopyexDDRqimgcOixEI3rL3TaT/zw2JHbyiH2KtJ64H1V9mCgY8BZUtwm3EuHv7zvSkcrWSDYfgXqLYsnjfh9A9n6kngd2a71DJ5skPq4kKSpE+q33NL5wAXdGYuDzUKQ9AW8dmV7RWqOV/+SrBcKUwl4V4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711743172; c=relaxed/simple; bh=jKKLFWjxNQWTqThGaOZiBEJeDaQD/usM2iI10hkWvuU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=I7HPGYzX0Jg02uixgKD2JX3UHNN7keZ/qE/+tFg54Z61Y5Fkbv1JLV2sItRcn1XUKTIc/lHjQCU3HjnhQXqXXtUQhmBqQ7agusZPfAj7mEe5XRlOJq9zdUlegDnes+QuvAZkIZ1R82gsy7vs5cmNXrQ1imnCCyUxjqXpKz1uWXk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk; spf=pass smtp.mailfrom=kernel.dk; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b=HqVfC0OH; arc=none smtp.client-ip=209.85.210.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kernel.dk Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kernel.dk Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel-dk.20230601.gappssmtp.com header.i=@kernel-dk.20230601.gappssmtp.com header.b="HqVfC0OH" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-6ea895eaaadso450351b3a.1 for ; Fri, 29 Mar 2024 13:12:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1711743169; x=1712347969; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zvdXlhGVTrVxzlERO6fNQI/6ve5uCwFdRTdehFJpceA=; b=HqVfC0OHZLj8A1SDGFvOvDLcB1NoJc30ZOhx9N4r9k42KiA05DEKMD4jHNp9mdRyKv HWafFosf3PSggVPLYSun8wDqKNb8g0dAgY/wZK4k38V6moCvwh3ENdPJBtUPp2DXcT+T HkRH0Q0uDfDbTsO2/r2Oc7/I4BvfAPadBMtTZnyZ1YBXk3eABaju+X5R/SlqNR0rv4DZ lZ97iAKtk7j0fbVgPh/OC1zKB5Q82+h/nIcNnuI1Rj8cjn0/ZcK1Z4UE212sPc9k0pfG afPI+r9c+c/nSkFbMRJMR3My/NLmhcdU+6/9QVDpficcw63VZcb6jaODRPyCfldrLHjX d7wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711743169; x=1712347969; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zvdXlhGVTrVxzlERO6fNQI/6ve5uCwFdRTdehFJpceA=; b=WtlXYm1dDLGpZBvGRoBLAbv2U+WYYbMzJ050lyJbr+OdsWJBP26U2oFzBeLPBkCXhB XY79o8AVTOR45GS9yolBa233PqhdIRZ15XGIs03FaGsssNQvgv3eG2j6YrhhsKsqvqhu lDnynVud9YH+rDIERrHfxsrx4+UULF/QQxTtdFeDKLz6eBnPQQ5aY7KzqgocRzZaQ33y xSf/PU+xroRvbjTZJg7pJaFdvPeG13DjfMRDdErOPosxgf1p7hqoEDksBZnxnAm8rs26 QQUPU5R/q+Tqs4gxMZ3t1DEHcU+gg2tlEZwQLcEKmkVilgXj02Xb9j/QLgJE4TC2vXJG JuRA== X-Gm-Message-State: AOJu0YwfUBpG1VY3zhm80XsM9xJxcaetOVKCoWX1iXkBUqpclLzXUcIP +vQxPj3Q8PW1TDJqzFTDzKvO/0jVW99gUMHdAF1VP2/Dn9gHkKjs7DvR+NoqTqh9Ei3+05bcmPu X X-Google-Smtp-Source: AGHT+IF+bEWA+HrIruhSaF3VIEGK/y7EqMOtlsp/vD952PaDksDWq/t6znUfTFonB6gccOervgiRUg== X-Received: by 2002:a05:6a21:a593:b0:1a3:c61f:c2d5 with SMTP id gd19-20020a056a21a59300b001a3c61fc2d5mr3073965pzc.6.1711743169569; Fri, 29 Mar 2024 13:12:49 -0700 (PDT) Received: from m2max.thefacebook.com ([2620:10d:c090:600::1:40c6]) by smtp.gmail.com with ESMTPSA id b11-20020aa7810b000000b006ea90941b22sm3388728pfi.40.2024.03.29.13.12.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 29 Mar 2024 13:12:48 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: Jens Axboe Subject: [PATCH 3/3] io_uring/msg_ring: improve handling of target CQE posting Date: Fri, 29 Mar 2024 14:09:30 -0600 Message-ID: <20240329201241.874888-4-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240329201241.874888-1-axboe@kernel.dk> References: <20240329201241.874888-1-axboe@kernel.dk> Precedence: bulk X-Mailing-List: io-uring@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Use the exported helper for queueing task_work, rather than rolling our own. This improves peak performance of message passing by about 5x in some basic testing, with 2 threads just sending messages to each other. Before this change, it was capped at around 700K/sec, with the change it's at over 4M/sec. Signed-off-by: Jens Axboe --- io_uring/msg_ring.c | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/io_uring/msg_ring.c b/io_uring/msg_ring.c index d1f66a40b4b4..af8a5f2947b7 100644 --- a/io_uring/msg_ring.c +++ b/io_uring/msg_ring.c @@ -13,7 +13,6 @@ #include "filetable.h" #include "msg_ring.h" - /* All valid masks for MSG_RING */ #define IORING_MSG_RING_MASK (IORING_MSG_RING_CQE_SKIP | \ IORING_MSG_RING_FLAGS_PASS) @@ -21,7 +20,6 @@ struct io_msg { struct file *file; struct file *src_file; - struct callback_head tw; u64 user_data; u32 len; u32 cmd; @@ -73,26 +71,18 @@ static inline bool io_msg_need_remote(struct io_ring_ctx *target_ctx) return current != target_ctx->submitter_task; } -static int io_msg_exec_remote(struct io_kiocb *req, task_work_func_t func) +static int io_msg_exec_remote(struct io_kiocb *req, io_req_tw_func_t func) { struct io_ring_ctx *ctx = req->file->private_data; - struct io_msg *msg = io_kiocb_to_cmd(req, struct io_msg); - struct task_struct *task = READ_ONCE(ctx->submitter_task); - - if (unlikely(!task)) - return -EOWNERDEAD; - - init_task_work(&msg->tw, func); - if (task_work_add(ctx->submitter_task, &msg->tw, TWA_SIGNAL)) - return -EOWNERDEAD; + req->io_task_work.func = func; + io_req_task_work_add_remote(req, ctx, IOU_F_TWQ_LAZY_WAKE); return IOU_ISSUE_SKIP_COMPLETE; } -static void io_msg_tw_complete(struct callback_head *head) +static void io_msg_tw_complete(struct io_kiocb *req, struct io_tw_state *ts) { - struct io_msg *msg = container_of(head, struct io_msg, tw); - struct io_kiocb *req = cmd_to_io_kiocb(msg); + struct io_msg *msg = io_kiocb_to_cmd(req, struct io_msg); struct io_ring_ctx *target_ctx = req->file->private_data; int ret = 0; @@ -205,10 +195,8 @@ static int io_msg_install_complete(struct io_kiocb *req, unsigned int issue_flag return ret; } -static void io_msg_tw_fd_complete(struct callback_head *head) +static void io_msg_tw_fd_complete(struct io_kiocb *req, struct io_tw_state *ts) { - struct io_msg *msg = container_of(head, struct io_msg, tw); - struct io_kiocb *req = cmd_to_io_kiocb(msg); int ret = -EOWNERDEAD; if (!(current->flags & PF_EXITING))