From patchwork Thu Mar 28 18:52:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13609296 Received: from mail-pf1-f179.google.com (mail-pf1-f179.google.com [209.85.210.179]) (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 5BF23137766 for ; Thu, 28 Mar 2024 18:54:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711652061; cv=none; b=OpB1oTxdv2xh82R6vD7nWdH+dxy6U7xmDJKvuhTMZSlPf7DFN0PkO3+z1Sq9AO2QPYGviCSkviCY4B+RwGB9E4M2nHUipUGm3meggQ7nqTdA5YqOkA+pBewWUkGjmH/fvT7TS+Iw48FuZo3og4f/rYMlSVNtWHxx5IoEZriAFJw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711652061; c=relaxed/simple; bh=SuVysJvN/C0i3B+xcpafFcXUecl4OdhFCgCxJR2gnx8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SV+w8gCj+Oyunp7/r8p+a0oecn6vNHUNrNCZTiffB/N/VWXVCy/TG0LsAgv7rwZ2kqSb7ZTEd0RjFpMLqKLQ1ZI11i5G/76qMq99KaEKEDXhHrW8Y6auTWxEsdAgBR+EL2vX6CAfJ3LXH/hQrRyLxWcJKzwItvRZJdmxPrYgZps= 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=LevyyLA5; arc=none smtp.client-ip=209.85.210.179 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="LevyyLA5" Received: by mail-pf1-f179.google.com with SMTP id d2e1a72fcca58-6ea729f2e38so275304b3a.1 for ; Thu, 28 Mar 2024 11:54:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1711652057; x=1712256857; 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=jDmmOrv9idjYjnsKvLCtkIkZDzm6Obo3xt1sDFxhCKw=; b=LevyyLA5461a9vfPlnHQHPEmxv26bfVt3OrNIqd1Sn2gJpQfIDihtt978OTXQSqNDz DSgWjCGELvndv4iX3FBC/VeNzOnQu3s1ta9u3zSFjtRihuwVVHnLKtRyiFcj35H7eyej 2z3/yxk1j7W0LaZWFqRQScuO7rMR+fmhZqgEm10AWIdlKvVoWC+CdlqmmAKMqA6ykdYH fLeptQc2LLBfC6KfdC64AXdnH0arc9H/G1m3WWLi/VT5YSV49qN+YuJCnJ9qJOVv/oxK eXBJRRXBXI37PS+zviC/wYc1qHmIAdeiVlK71OWugWjIMIRaCfMnWe8hKuIZi0091Em+ SKiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711652057; x=1712256857; 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=jDmmOrv9idjYjnsKvLCtkIkZDzm6Obo3xt1sDFxhCKw=; b=ddPqX8qM4rb191r7ytIyFnPVcUiQRlH6sIR/SJUJ/8/4/HtJsSR1SSbxI7cRiY+WOf TYPh5UPfYbHBpJxOrqqy5PdB4NpYDQFVe6afuzGIOCETFB1HtvzG6GvR1+kWZNrXQ+mY 7PFBMUgl6HW0qhooukSM94DRqX0B8EvyELKMqn80m7WKgaeD5mHhVS4foBmFigWDh0I6 4cfdIVuiIU0pb8ObyVi0skvi3tl6NXp9W+YbdvyjpsirSfLp8kW9jkkw9QmZ4YupDSlI WX0JWVK4XuIl3i7Uc33/s/mPtqOkeB2AX/dMyc4YBSq297bQXUqs1MDwiIdjndXG6SS0 cmnA== X-Gm-Message-State: AOJu0YwZI1wve+lhTAOaigqDjgWF5/eN3f4CHMd+tC1gaLOcPARbu6e+ Dt2SSZtFEFcuy4L9JffkeAhTlEMjZswCOUQtvMRs19oYZPofWPdof5WZXRc9NWmqw2WmuCTTwRo + X-Google-Smtp-Source: AGHT+IG0uGNLUvBaa0KwXhiDsTpLdZs9JJnqX7s8GV+6QUQo9jgdW2Z9ndEV9yErSxRCMiokGN8mtg== X-Received: by 2002:a05:6a00:d4d:b0:6ea:bb00:a52f with SMTP id n13-20020a056a000d4d00b006eabb00a52fmr138075pfv.3.1711652057214; Thu, 28 Mar 2024 11:54:17 -0700 (PDT) Received: from m2max.thefacebook.com ([2620:10d:c090:600::1:b138]) by smtp.gmail.com with ESMTPSA id v17-20020a056a00149100b006e631af9cefsm1717357pfu.62.2024.03.28.11.54.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 11:54:15 -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: Thu, 28 Mar 2024 12:52:43 -0600 Message-ID: <20240328185413.759531-2-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240328185413.759531-1-axboe@kernel.dk> References: <20240328185413.759531-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 and task. Signed-off-by: Jens Axboe --- io_uring/io_uring.c | 27 +++++++++++++++++++-------- io_uring/io_uring.h | 2 ++ 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/io_uring/io_uring.c b/io_uring/io_uring.c index 9978dbe00027..609ff9ea5930 100644 --- a/io_uring/io_uring.c +++ b/io_uring/io_uring.c @@ -1241,9 +1241,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 tw_flags) +static inline void io_req_local_work_add(struct io_kiocb *req, + struct io_ring_ctx *ctx, + unsigned tw_flags) { - struct io_ring_ctx *ctx = req->ctx; unsigned nr_wait, nr_tw, nr_tw_prev; unsigned long flags; @@ -1291,9 +1292,10 @@ static inline void io_req_local_work_add(struct io_kiocb *req, unsigned tw_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; unsigned long flags; bool was_empty; @@ -1319,7 +1321,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); @@ -1328,9 +1330,18 @@ static void io_req_normal_work_add(struct io_kiocb *req) void __io_req_task_work_add(struct io_kiocb *req, unsigned flags) { if (req->ctx->flags & IORING_SETUP_DEFER_TASKRUN) - io_req_local_work_add(req, flags); + io_req_local_work_add(req, req->ctx, flags); + else + io_req_normal_work_add(req, req->task); +} + +void io_req_task_work_add_remote(struct io_kiocb *req, struct task_struct *task, + struct io_ring_ctx *ctx, unsigned flags) +{ + if (req->ctx->flags & IORING_SETUP_DEFER_TASKRUN) + io_req_local_work_add(req, ctx, flags); else - io_req_normal_work_add(req); + io_req_normal_work_add(req, task); } static void __cold io_move_task_work_from_local(struct io_ring_ctx *ctx) @@ -1349,7 +1360,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 bde463642c71..a6dec5321ec4 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 task_struct *task, + 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 Thu Mar 28 18:52:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13609297 Received: from mail-pg1-f169.google.com (mail-pg1-f169.google.com [209.85.215.169]) (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 4C3D91311B5 for ; Thu, 28 Mar 2024 18:54:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711652062; cv=none; b=YFcEz+fQ5enEzF9XFZx01sV6eNly7LGMxWB9DQ/qEM9lqB3rHvvu8/Ahr14ENuB1sxj3wXyAZYqn8+dDWRLK9JgVnDyIudP3nd7KH+FotLo3OTcwqTn+Z9cVspyfXGM7HAjru3olMZtjyM6YMQT+kUPJnt01O4ue7TIb5gvyJD4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711652062; c=relaxed/simple; bh=ZOc31Chv9GMzFMptACL4IWPv63UmYAghUAlkMAAqqNc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=utZf5h/EkcksujPOrawiF0Dh4oUyI1QNDgyoGJchqLkY02cI8+hPvxE4oOF/eYbHYBvA6xI0RAcgtXRe15HSxZX1lWNTSGgCJ8kkiSe6A5/eW+6NtV0nFP2RzhtY/uS+Eyosmvn8uSmD/K0c+UmlLXJrb7QFD2VWOpwncZUztSU= 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=2gNlY9r+; arc=none smtp.client-ip=209.85.215.169 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="2gNlY9r+" Received: by mail-pg1-f169.google.com with SMTP id 41be03b00d2f7-58962bf3f89so278592a12.0 for ; Thu, 28 Mar 2024 11:54:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1711652059; x=1712256859; 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=2gNlY9r+olumqQ98oX4AFKDlUvHve2+35EbzTjsKnGpHfbtKbru++V4hy/9zW5oRPU x+lAQWCrDNW9iuSHJeKcS0oLW61lqbIOmUCV2SHzzVW6WyvPI8XtGLr35m7NKtv1IdA8 +yz6WwZ56gwk4hz75qZG1IXdo/lfGTe36egi5m+F0PrWWDh33b/KMfX8vnwQ++d62KOp pMtL9ACfPoyg3q7/mrnZ1jCgi3DKRBxhoF3AyZMcm1eKAHSmkz9RY7DFQBPoyBs8OIXm pRGPIO3ZPXkdZU9761y8OcNxwGKzbSs0pPkKgfBsfVyxxk4A/KDNCoT5Pyd1XUly3i3g ZjsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711652059; x=1712256859; 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=kvFNZeSwbQpSb1a3JBtBcHEvFUgDamx0rUkuAmWEOAxzA8W/1sY0oAxPTSAQFBZoW8 /wTQQdiwY+ILJb5Wy+0Df2LN+NRIPo4XPpu4VHm2JF8UeRQWJ9R3NtLgH4NYw9FE/e9q Et+g+2M0mRuszMQdLCxZxr/7xHA85yel2s30PoUMbw1A/ciJcRqiI25GUFUL4Jig4Bgg Wo9DBrkPEpU10raz56sXjlI8JpOGIXfzA8ZFWNUuU2xuA2JOsfuz0ofnV3r1ptV4LOWG IWHRe75WOulJiaJM7DAygDOeYYeKfvJrEzU38p29AfY6gQTx1LRdio8M/hp6/pTvHOrU AqfA== X-Gm-Message-State: AOJu0YyjcdqfJSHTNFd0WjgjWp2hRGyFgZhG4f2huSbqB2DlSKCsyNVh 3cTVQSmnNjs9plA5qwPTzq6ltgJ73A4OaQx0aXdkER0qUT+IKO1weGNcqe7Y9v1JDMkqUSmtrfn v X-Google-Smtp-Source: AGHT+IH7kb59sJ7qa3POBzK1hxtzPC68XZeIBAGSywjb6vnTXc/QoaON9vbP3nY1dab1Yxgmrm57xA== X-Received: by 2002:a05:6a00:b31:b0:6ea:8604:cb1d with SMTP id f49-20020a056a000b3100b006ea8604cb1dmr213256pfu.0.1711652059112; Thu, 28 Mar 2024 11:54:19 -0700 (PDT) Received: from m2max.thefacebook.com ([2620:10d:c090:600::1:b138]) by smtp.gmail.com with ESMTPSA id v17-20020a056a00149100b006e631af9cefsm1717357pfu.62.2024.03.28.11.54.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 11:54:17 -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: Thu, 28 Mar 2024 12:52:44 -0600 Message-ID: <20240328185413.759531-3-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240328185413.759531-1-axboe@kernel.dk> References: <20240328185413.759531-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 Thu Mar 28 18:52:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Axboe X-Patchwork-Id: 13609298 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 DB679137766 for ; Thu, 28 Mar 2024 18:54:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711652064; cv=none; b=emMlfsjrXSUQdZ5BLbpDOiGml3MUxz1gZ6sWdJTlorvDXuQvWgkQa0bTJSC3OBebBZP812QzWLRPrgNKA/VJin4Ik5zmTBc8X/Px9sjKAOpck+tSJTVf/JBxUD6KFqGFG8Z2FVwR9BLfa1uIXvIRrJkLXJFJAhQi6KaWyO3jrLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711652064; c=relaxed/simple; bh=ulvOA/fOGKjlgOCiBkh6HRvedlSctzNkeP6g239frL8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Qok9Vft2tY6AfLFSiHL62jJo1p2c8mGNWGwzlAfxpErGbDlcLspYQSKS9AJPAsB5V+CzbKHF0pNzEZ1t7Cp9Nsv6y27tTNWKTobQZ43ILNPagMgEe2bDSZxksJL7umvBkm1iourBzPHMRpeJb4TPU6RPPwp+5ZudO9btRdeO6AU= 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=ROI/DpX6; arc=none smtp.client-ip=209.85.210.181 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="ROI/DpX6" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-6ea7b38f773so277724b3a.0 for ; Thu, 28 Mar 2024 11:54:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20230601.gappssmtp.com; s=20230601; t=1711652061; x=1712256861; 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=65KYXuavK2ROJ0oYC9aH8brlw8GCzH/RY253MWquCC4=; b=ROI/DpX6qX926PLwdGdWB2d8s1qpgfvQus1ymS8nGLxYxmwAUNyqLDNn5N4QuuhKsm Z/pC0A8Ue8784JWY/n66xjrrHkY2AC3i2uku6iO30NpZKLcAaXVobXojtW8NJZw7iTHL Qvj5qJfdbHQ/SdrIpgFKLMb9k94vjAvY/f+TLKxjG7qCn8kla+lBMDTAGzepsFBAtJjI QBCNReaYSvsDOTPyk0MXRpHRwURiMtHcOf44p36KPzdsFiufNML2F3zSIk+OMDZbp5pt hf9+HcAuf32Uv2Vf6qsfqsO78Hvq0+eqrNeIxm6IIJfpTgTYvfDR70gPF018K/nUN/Ts jfIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711652061; x=1712256861; 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=65KYXuavK2ROJ0oYC9aH8brlw8GCzH/RY253MWquCC4=; b=TJBwwuHRR3VpRkMPoI/RdsgHP2UHrdgB2c6LV0tfZZ3rhio9eqXZmlf4NviWTalWe0 +SmIN9qOBtMwTBhZUtYDqdDA6+Er+UoYA50CDuVv/mCrKTfPgieU77QCMcxqQh7OxFa7 BMyM00ACG1PYNTnKM+f4S7sUZZxxL+KBb1f6dgrvEkrW7t7adimcIh1qhdsyjnz3o+gb pdQekeZUjUkS3+dLDY2n6Gk0u7LIRLaWf4+EZ9g78yIkDvqT7cVjplpZAnemB5ixY8e4 gwCebtda+gMDttYG7/GfObqgHaTOWLQskxOGH5rdaO9+huXya5CfS8fiq6JwLR2/Ihq8 BaxA== X-Gm-Message-State: AOJu0YwxS+6Zsh7+3RTqQnkfIVfDn93h6CZevxa2qq7bD4k1YIfQ6L4U MVZPI/xE+o6rfBq3Go/FAz45vLbnMt9+O6zsL4s7VobEaA/uVVN8iliF1E5ypbpO8e4nuLBmNAL X X-Google-Smtp-Source: AGHT+IH/w+XJdAxeUW6QIeSGh+YpfJ5xScO30UfRqIqv0krUtAkpGgz1BvY7cKZT/y4fiHnM2sgjMQ== X-Received: by 2002:a05:6a00:198c:b0:6ea:ba47:a63b with SMTP id d12-20020a056a00198c00b006eaba47a63bmr213217pfl.0.1711652060934; Thu, 28 Mar 2024 11:54:20 -0700 (PDT) Received: from m2max.thefacebook.com ([2620:10d:c090:600::1:b138]) by smtp.gmail.com with ESMTPSA id v17-20020a056a00149100b006e631af9cefsm1717357pfu.62.2024.03.28.11.54.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 11:54:19 -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: Thu, 28 Mar 2024 12:52:45 -0600 Message-ID: <20240328185413.759531-4-axboe@kernel.dk> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240328185413.759531-1-axboe@kernel.dk> References: <20240328185413.759531-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 | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/io_uring/msg_ring.c b/io_uring/msg_ring.c index d1f66a40b4b4..e12a9e8a910a 100644 --- a/io_uring/msg_ring.c +++ b/io_uring/msg_ring.c @@ -11,9 +11,9 @@ #include "io_uring.h" #include "rsrc.h" #include "filetable.h" +#include "refs.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 +21,6 @@ struct io_msg { struct file *file; struct file *src_file; - struct callback_head tw; u64 user_data; u32 len; u32 cmd; @@ -73,26 +72,20 @@ 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; - + __io_req_set_refcount(req, 2); + req->io_task_work.func = func; + io_req_task_work_add_remote(req, task, 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; @@ -120,6 +113,7 @@ static void io_msg_tw_complete(struct callback_head *head) if (ret < 0) req_set_fail(req); + req_ref_put_and_test(req); io_req_queue_tw_complete(req, ret); } @@ -205,16 +199,15 @@ 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)) ret = io_msg_install_complete(req, IO_URING_F_UNLOCKED); if (ret < 0) req_set_fail(req); + req_ref_put_and_test(req); io_req_queue_tw_complete(req, ret); }