Message ID | 20231206-rb-new-condvar-methods-v1-1-33a4cab7fdaa@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp4004360vqy; Wed, 6 Dec 2023 02:10:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IGjoc1goIXzfUXzdjR5Sn7Bv/c6X1OJ/TVtFYz2Hnqq6XFGrP6Vs890mi9c3CvE4xA1qv9U X-Received: by 2002:a05:6870:a44a:b0:1bf:b863:b6d with SMTP id n10-20020a056870a44a00b001bfb8630b6dmr730390oal.1.1701857401331; Wed, 06 Dec 2023 02:10:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1701857401; cv=none; d=google.com; s=arc-20160816; b=tW5KnmYoezcon6qAtV6YVNy1LsVO/7crmLsSZzXiEa+R2FevRNXyGWk+gNVmA0tcpP Zpvpk5JSSvsUKhLOsDIS0ediIM8ZrWlO1lIJQiY/e57WCDXPSjmEoKuwGYMbysOuc4X8 okizbmxIeRCUVZF6R6PGWhR7H5BD2335EDit4sFDrf8B5P/vuT833BP6mFS/Jr7Eqt8a O3Z87a40f/zSLODmGvULFZ66elPflL9e8a4xkRjsrAnHpwi9fCgBj2YR2ycHO/DuL4Ti D+lPJBQu1YGUsmWOkzLgB+0i+xnQJ5SPEF5yzvG01p12V30NGGbMqbg0Aq9HWwkr19m6 Pygg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:dkim-signature; bh=U1L9PtqvjoQFgO5q+VnM788vYaeOUUwutSgupIUHrpw=; fh=4Ll0qDznmJCNJvJ+PsATqWDPrXYFX8AsCU+k6YytCaY=; b=e+20RNKpmYN8p0RBn4A5Jly3cgEntA0/19u2YfBBXYbiOOdeVjmTYLKAQcSLmemUst Lhf2abgUEr4+J6A1KcaC/AZ+sFFdjyZsX8Q9+x/iJ6EblpNcJzPe3ng8fG0lKzgUKaXt o1KDG/G9PV1WY4lW1oCxlfRRjb9IavNNtLxOkMoavOStW90h7MNP/r2suxSw75MaJbjY JhfaUfWNCRltpUIaEDbBBJM9iUSPo+ETIXZl1wREESoRA02F1aOHyUo8hNyp9Y/M6mCu u14tNRAX1eM6FzznV0tVurhU1Dq06wueU0b8kwMhgj20oXsx/IizJecAuo6/U3KGLEjt Xb/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=YvSNrajp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from agentk.vger.email (agentk.vger.email. [23.128.96.32]) by mx.google.com with ESMTPS id r16-20020a63d910000000b005b884a11fdcsi10883211pgg.28.2023.12.06.02.10.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Dec 2023 02:10:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) client-ip=23.128.96.32; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=YvSNrajp; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.32 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id CC1EF80C47BA; Wed, 6 Dec 2023 02:09:58 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377414AbjLFKJo (ORCPT <rfc822;pusanteemu@gmail.com> + 99 others); Wed, 6 Dec 2023 05:09:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37442 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377412AbjLFKJm (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 6 Dec 2023 05:09:42 -0500 Received: from mail-lf1-x14a.google.com (mail-lf1-x14a.google.com [IPv6:2a00:1450:4864:20::14a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7AB5ED49 for <linux-kernel@vger.kernel.org>; Wed, 6 Dec 2023 02:09:48 -0800 (PST) Received: by mail-lf1-x14a.google.com with SMTP id 2adb3069b0e04-50bf1bbf67aso3230753e87.0 for <linux-kernel@vger.kernel.org>; Wed, 06 Dec 2023 02:09:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1701857386; x=1702462186; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=U1L9PtqvjoQFgO5q+VnM788vYaeOUUwutSgupIUHrpw=; b=YvSNrajpI6D3Jtgrhf87UOkAQtV42jT6EuKVxcORvVfGmOBjxQwf/468Bfmb1Tad4w 1OG5QbY850Nsq5K/1qg3meLgwRzJoi7geNkugR5aiXqrKdt2Z3N9Zw2hD+W3/KHAr8rA ++uwupYC8+5W/+613FbIvS3CeRMPtD9J23yyyfbSTVx1EL8uKgzx+2j1mcARMWGDTxrD 33B6iu+1Vc6/z1g50EMcZk0hVY9K/ZvfYhj9+3vwOgG3jiI8veHsyfCdC2qwa/oDFrdk z2vZbDaybdLwA5BiXODRoKLYm8OBWq3mUfoy6BYogLIqhPt2qBxLK044cU2kyvWqDHxG pjJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701857386; x=1702462186; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=U1L9PtqvjoQFgO5q+VnM788vYaeOUUwutSgupIUHrpw=; b=j6GhZ0GtsP/dyx45wFEeZPfF1auxmCmLIhi8f9Kn90/qc4T4MVbUcp2+eSyGkmHjJ+ UR794Esa5SUq16bPGzrYCF3ErLMOBalezq5fqGEKb4msMqBAPy/yyIGf3e5l9WEj9xBI 64GNfpZEYUqFUSftGyjP1woHhRklhZlWhSOqQz7Z1bYIEbLJ9rj9t+m8tSxlHQr0z63g tEqZYMLbpKa2BHW8n1mnSm1+e16V+ctIXrQAq4/MQ5pVIiOejnHNggvGnU3Iuc2n59HS IQCmi815tmRsinMmTmGkzXmhaoAEDIJSSoHYC/VMJhrKh0rmxi/HNy26hSw/swanZ/gq 645w== X-Gm-Message-State: AOJu0YzLCH/+2Cf51htq9sJImoTXmC7PSI8+JF/Hv4W2c4p1sY0g1osC /ZSPD2THQec11sjCqtPHBbbtVQ7Ow9C9BjE= X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:ac2:5f6f:0:b0:50b:f822:eacf with SMTP id c15-20020ac25f6f000000b0050bf822eacfmr7060lfc.9.1701857386498; Wed, 06 Dec 2023 02:09:46 -0800 (PST) Date: Wed, 06 Dec 2023 10:09:23 +0000 In-Reply-To: <20231206-rb-new-condvar-methods-v1-0-33a4cab7fdaa@google.com> Mime-Version: 1.0 References: <20231206-rb-new-condvar-methods-v1-0-33a4cab7fdaa@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=1342; i=aliceryhl@google.com; h=from:subject:message-id; bh=gjsFTUAv4pM5ZDJTd0sbTeFQ61hWz6BaOzuWVUqxq5w=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBlcEhjgsTlj7q910nqwwTDSnkQsaj8PWPzf/p24 xNoUDnQ9huJAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZXBIYwAKCRAEWL7uWMY5 Rhx4D/9VIZRDqteITL/cUGikpx6VfrHfTxuyPcTCIR+GBin1ORtXgW+Bt6OwxBi3hwmsdrhgAbD 3108bBJ5qfRCoI6Lt5pmvQwWE6X1rBF1CWvwWhJHseTDg5ddzP9IiMRforJXCt7kitqp1ORX2TK i+1/aJomLqn7Wgka2NGua5btH6ixeZetd7KZMe+0QeeYMM7326rbf16LSoOSOcHcZSzL5vAxD19 F/H+hEfilOKYsoVGpFPbDYpXcO7zIuWfKVssGmFXhpROxJM4iFdDytnmXsv3d/Ak76N+hJBzcn9 ZJi5twiTHlgWjEclmhEVG7vJA9mmnGfKPWv0ddRn1+d+gXksYgqDInQ/vS3XrkuC7VP5aegFabQ tPjSCyS4iJh75zIgbdPgDISDIwict5SjjC0MNli6WI5pNOugCjP5fekPne54LC7aSsAUGLsa6PI vWFX1AsnQViiHdsFFnPVbTRYc0V8o07TbPdlx4tMsdJduWvF8+wW5IGZ1IffvFess7dcrksF6np AikW4+oesXvSf/CMoXl+kJy9EcxcXRP91Oec08ayBv4KSdRit3ScvYmjsE6PdxARtylFOhIR87I 7OM/5aalMAmvl3lHw52Kn7b7nxBalpM73+jnBjzKnqz/FO2j2Cm4jTNm685HgT6o/+FkGG5PPRB /L7P5iNaWdSc9+g== X-Mailer: b4 0.13-dev-26615 Message-ID: <20231206-rb-new-condvar-methods-v1-1-33a4cab7fdaa@google.com> Subject: [PATCH 1/2] rust: sync: add `CondVar::notify_sync` From: Alice Ryhl <aliceryhl@google.com> To: Miguel Ojeda <ojeda@kernel.org>, Alex Gaynor <alex.gaynor@gmail.com>, Wedson Almeida Filho <wedsonaf@gmail.com>, Boqun Feng <boqun.feng@gmail.com>, Gary Guo <gary@garyguo.net>, " =?utf-8?q?Bj=C3=B6rn_Roy_Baron?= " <bjorn3_gh@protonmail.com>, Benno Lossin <benno.lossin@proton.me>, Andreas Hindborg <a.hindborg@samsung.com>, Peter Zijlstra <peterz@infradead.org>, Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>, Waiman Long <longman@redhat.com> Cc: rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alice Ryhl <aliceryhl@google.com> Content-Type: text/plain; charset="utf-8" X-Spam-Status: No, score=-8.4 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 06 Dec 2023 02:09:58 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784526826120106002 X-GMAIL-MSGID: 1784526826120106002 |
Series |
Additional CondVar methods needed by Rust Binder
|
|
Commit Message
Alice Ryhl
Dec. 6, 2023, 10:09 a.m. UTC
Wake up another thread synchronously.
This method behaves like `notify_one`, except that it hints to the
scheduler that the current thread is about to go to sleep, so it should
schedule the target thread on the same CPU.
This is used by Rust Binder as a performance optimization. When sending
a transaction to a different process, we usually know which thread will
handle it, so we can schedule that thread for execution next on this
CPU for better cache locality.
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
---
rust/kernel/sync/condvar.rs | 6 ++++++
1 file changed, 6 insertions(+)
Comments
On 12/6/23 07:09, Alice Ryhl wrote: > Wake up another thread synchronously. > > This method behaves like `notify_one`, except that it hints to the > scheduler that the current thread is about to go to sleep, so it should > schedule the target thread on the same CPU. > > This is used by Rust Binder as a performance optimization. When sending > a transaction to a different process, we usually know which thread will > handle it, so we can schedule that thread for execution next on this > CPU for better cache locality. > > Signed-off-by: Alice Ryhl <aliceryhl@google.com> > --- > [...] Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com>
On 12/6/23 11:09, Alice Ryhl wrote: > Wake up another thread synchronously. > > This method behaves like `notify_one`, except that it hints to the > scheduler that the current thread is about to go to sleep, so it should > schedule the target thread on the same CPU. > > This is used by Rust Binder as a performance optimization. When sending > a transaction to a different process, we usually know which thread will > handle it, so we can schedule that thread for execution next on this > CPU for better cache locality. > > Signed-off-by: Alice Ryhl <aliceryhl@google.com> > --- > rust/kernel/sync/condvar.rs | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs > index b679b6f6dbeb..9861c6749ad0 100644 > --- a/rust/kernel/sync/condvar.rs > +++ b/rust/kernel/sync/condvar.rs > @@ -155,6 +155,12 @@ fn notify(&self, count: i32, flags: u32) { > }; > } > > + /// Calls the kernel function to notify one thread synchronously. > + pub fn notify_sync(&self) { > + // SAFETY: `wait_list` points to valid memory. > + unsafe { bindings::__wake_up_sync(self.wait_list.get(), bindings::TASK_NORMAL) }; I took a look at the C function (i.e. __wake_up_common) and there I found this: lockdep_assert_held(&wq_head->lock); So I think this function requires that the lock is held, how are you ensuring this?
On Thu, Dec 7, 2023 at 9:22 PM Benno Lossin <benno.lossin@proton.me> wrote: > > On 12/6/23 11:09, Alice Ryhl wrote: > > Wake up another thread synchronously. > > > > This method behaves like `notify_one`, except that it hints to the > > scheduler that the current thread is about to go to sleep, so it should > > schedule the target thread on the same CPU. > > > > This is used by Rust Binder as a performance optimization. When sending > > a transaction to a different process, we usually know which thread will > > handle it, so we can schedule that thread for execution next on this > > CPU for better cache locality. > > > > Signed-off-by: Alice Ryhl <aliceryhl@google.com> > > --- > > rust/kernel/sync/condvar.rs | 6 ++++++ > > 1 file changed, 6 insertions(+) > > > > diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs > > index b679b6f6dbeb..9861c6749ad0 100644 > > --- a/rust/kernel/sync/condvar.rs > > +++ b/rust/kernel/sync/condvar.rs > > @@ -155,6 +155,12 @@ fn notify(&self, count: i32, flags: u32) { > > }; > > } > > > > + /// Calls the kernel function to notify one thread synchronously. > > + pub fn notify_sync(&self) { > > + // SAFETY: `wait_list` points to valid memory. > > + unsafe { bindings::__wake_up_sync(self.wait_list.get(), bindings::TASK_NORMAL) }; > > I took a look at the C function (i.e. __wake_up_common) and there I > found this: > > lockdep_assert_held(&wq_head->lock); > > So I think this function requires that the lock is held, how are you > ensuring this? No, we don't need to hold a lock. The call stack is: 1. __wake_up_sync 2. __wake_up_sync_key 3. __wake_up_common_lock 4. __wake_up_common And __wake_up_common_lock will lock wq_head->lock before calling __wake_up_common. Alice
On 12/8/23 08:29, Alice Ryhl wrote: > On Thu, Dec 7, 2023 at 9:22 PM Benno Lossin <benno.lossin@proton.me> wrote: >> >> On 12/6/23 11:09, Alice Ryhl wrote: >>> Wake up another thread synchronously. >>> >>> This method behaves like `notify_one`, except that it hints to the >>> scheduler that the current thread is about to go to sleep, so it should >>> schedule the target thread on the same CPU. >>> >>> This is used by Rust Binder as a performance optimization. When sending >>> a transaction to a different process, we usually know which thread will >>> handle it, so we can schedule that thread for execution next on this >>> CPU for better cache locality. >>> >>> Signed-off-by: Alice Ryhl <aliceryhl@google.com> >>> --- >>> rust/kernel/sync/condvar.rs | 6 ++++++ >>> 1 file changed, 6 insertions(+) >>> >>> diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs >>> index b679b6f6dbeb..9861c6749ad0 100644 >>> --- a/rust/kernel/sync/condvar.rs >>> +++ b/rust/kernel/sync/condvar.rs >>> @@ -155,6 +155,12 @@ fn notify(&self, count: i32, flags: u32) { >>> }; >>> } >>> >>> + /// Calls the kernel function to notify one thread synchronously. >>> + pub fn notify_sync(&self) { >>> + // SAFETY: `wait_list` points to valid memory. >>> + unsafe { bindings::__wake_up_sync(self.wait_list.get(), bindings::TASK_NORMAL) }; >> >> I took a look at the C function (i.e. __wake_up_common) and there I >> found this: >> >> lockdep_assert_held(&wq_head->lock); >> >> So I think this function requires that the lock is held, how are you >> ensuring this? > > No, we don't need to hold a lock. The call stack is: > > 1. __wake_up_sync > 2. __wake_up_sync_key > 3. __wake_up_common_lock > 4. __wake_up_common > > And __wake_up_common_lock will lock wq_head->lock before calling > __wake_up_common. Seems like I just looked at the wrong function. Reviewed-by: Benno Lossin <benno.lossin@proton.me>
diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs index b679b6f6dbeb..9861c6749ad0 100644 --- a/rust/kernel/sync/condvar.rs +++ b/rust/kernel/sync/condvar.rs @@ -155,6 +155,12 @@ fn notify(&self, count: i32, flags: u32) { }; } + /// Calls the kernel function to notify one thread synchronously. + pub fn notify_sync(&self) { + // SAFETY: `wait_list` points to valid memory. + unsafe { bindings::__wake_up_sync(self.wait_list.get(), bindings::TASK_NORMAL) }; + } + /// Wakes a single waiter up, if any. /// /// This is not 'sticky' in the sense that if no thread is waiting, the notification is lost