Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp2218305rdb; Fri, 8 Dec 2023 01:31:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IGwptN5/hQUWoxQqADRAhgNm/+BIZuwphG+loG4IVkaSM3mNAlhy4O0eZATOYLD1Dokrofc X-Received: by 2002:a05:6830:2113:b0:6d9:e43d:7cba with SMTP id dy19-20020a056830211300b006d9e43d7cbamr1450723otb.14.1702027882864; Fri, 08 Dec 2023 01:31:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702027882; cv=none; d=google.com; s=arc-20160816; b=OhW5NX91xJmawzhdaby0fk2wUjFC/5/5yw4J9vL/hdT3OS632ycN/4Io9ow57mgYL2 jt7MTOJoPtlVN6t/eU8ufZn2ztlIs4XpkBChhqAokZHhAzSuUo/2pdagdtAAmB3rXEKp +VQFx+MpXYdJ4jvyN272q9i4NiL+MzNo0IENQJnKIfjMqbZy1g4uCLEa8dEuPfkj4JwC f6VrfvgfLXMKIXjn6r8TqAxJXVxj/3j8+RAHWWrQoaJGaHHZei30+rp40SCGavc3kRDm aZEmhH41QruYOX7+6PGbSWjmeUe8KgyPONpp8VR8ckg13weusXvSOA3yaYGOY+Q12ogS WF/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :feedback-id:references:in-reply-to:message-id:subject:cc:from:to :date:dkim-signature; bh=tIeS2/Jye7HIPtEZsp8KCwBQkwu9VpdtO7V1kQXigqc=; fh=A2E0LtHfen5vzl6zi7oB6cYaIuZGWaj7krUTbI9Debk=; b=Ts59iDT99O8jzXvAnnY0e8fCyozAIbu4zvl/bzc6WXbXx5dotqlwOaCYtFOheKhLrP cSvsVTyj5qyseEt7gWUzcwpE5SQOKt3bWstj6Mfz2gPFde2RCnAJVkj4+UerfjRsXMZY cjYgsEuHaW0xogMCkXwtFwFXorTcUsEYNMkZmnXCQ4lvNZcJcnFJbCJf71OwEG8EreOa dQZWj8chE30TLdD+6DppPUrzN/wY66PZVrkw1+IYdEss9hbpC9xCPOWJ8zzgSGxrP1+5 2vkKM1MGCpLlQn9X3hS9NfShoPi/s5t1SANC26teJ9BlfmYzGqRhyRSOC/Jwcsoc2KrJ ZwnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b="ScdRc/0F"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id bw9-20020a056a02048900b005c674eb1cb4si1267476pgb.477.2023.12.08.01.31.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 08 Dec 2023 01:31:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@proton.me header.s=protonmail header.b="ScdRc/0F"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=proton.me Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id 4F81A8183F17; Fri, 8 Dec 2023 01:31:20 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233259AbjLHJbF (ORCPT + 99 others); Fri, 8 Dec 2023 04:31:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232968AbjLHJbC (ORCPT ); Fri, 8 Dec 2023 04:31:02 -0500 Received: from mail-40131.protonmail.ch (mail-40131.protonmail.ch [185.70.40.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C7F6D53 for ; Fri, 8 Dec 2023 01:31:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=proton.me; s=protonmail; t=1702027865; x=1702287065; bh=tIeS2/Jye7HIPtEZsp8KCwBQkwu9VpdtO7V1kQXigqc=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=ScdRc/0Fvy3evj5RN7U6t2wLpBinuZSAnS6GluqehDBmCcrk/iL1MV2YChWPZBoc5 3ayvN+vz/q66pPKbS8IQCkFdy6MDouWErb2wG+v4vmiDtTG2jn844nkLltxTu4MPhM 1oBsK8Ww+d5wIOS/6gMQWx51Hlym0ktkQjnymZpIJKf3JASfcFsB9lyk94BvTqQhHI oFi7YzjUTZWZE6bjJvt1mDPhh5nvjOw8w1zULBBhkmwp1UUwQXIY0uoxKoZAQMel1V xmhcQ/cqZx5LtJyCgq3+r1ERBVXKUfr+tCP9EuQyGhUyT4pErhyZg/GkSPu/4wGQqT uhvDTwiMAdQ+A== Date: Fri, 08 Dec 2023 09:30:41 +0000 To: Alice Ryhl From: Benno Lossin Cc: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , =?utf-8?Q?Bj=C3=B6rn_Roy_Baron?= , Andreas Hindborg , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 1/2] rust: sync: add `CondVar::notify_sync` Message-ID: <2TyvgVxGiHf9tLVgLAuw9h9gjv5iM0f_5KE0bM4PGIWrnNXRASVZ-UwxnI4v1XQEIp6mkbTTg9Sr7jEigChMd5Sxhpnd2NV8IDJ9sDXgIPo=@proton.me> In-Reply-To: References: <20231206-rb-new-condvar-methods-v1-0-33a4cab7fdaa@google.com> <20231206-rb-new-condvar-methods-v1-1-33a4cab7fdaa@google.com> Feedback-ID: 71780778:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Fri, 08 Dec 2023 01:31:20 -0800 (PST) On 12/8/23 08:29, Alice Ryhl wrote: > On Thu, Dec 7, 2023 at 9:22=E2=80=AFPM Benno Lossin 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 >>> --- >>> 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(), bindin= gs::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? >=20 > No, we don't need to hold a lock. The call stack is: >=20 > 1. __wake_up_sync > 2. __wake_up_sync_key > 3. __wake_up_common_lock > 4. __wake_up_common >=20 > 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 --=20 Cheers, Benno