From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) (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 72F6947796 for ; Mon, 8 Jan 2024 14:50:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--aliceryhl.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="npUwnaWH" Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-5e7ac088580so28329007b3.1 for ; Mon, 08 Jan 2024 06:50:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1704725406; x=1705330206; 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=bnwJONZ3lqNGKjXAo9ka9hqMWO5IxVpynKJIV/pgiEE=; b=npUwnaWHdth44JfRUSJcmbfljZF4S2AeNXRi1PGjdxzN5m1OzFdhrASGJOi5uvTf8I R6b/I8uteGk/9dNYaqVYR8d7irj0riy0lEHrboDy8O7mb30aqFIDnRCDZbySmSZUsdc3 Rqj+VzXI/bp7oKB/gsoONy5nS4FGvlHgrd5mkDJDS0sHwD4lq5GkpYV3b9Dzipo2SlDD aZqGqxbUn48+xLeUwC85fC1Brng8Q5f0msXGE1lP3sdZ80aX4+AOAxNEAJFnpglGa5Hc OK2cGXglh5qz243xInDz2YBeDuz3t6HNPb5hsDFGsFIjAPuPzyp8Cayg/rkK69Wydkt0 yL/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704725406; x=1705330206; 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=bnwJONZ3lqNGKjXAo9ka9hqMWO5IxVpynKJIV/pgiEE=; b=eMYTOLuFKDnbhzcsfza9whe1X16oM8JOT6zrcSZYAK+zEokJnRh9mnFPFVKqN5oG7V Fdp+3R+U1Wb9Ycmev7/Rg3MEx3BcaqAu7PDPEiS6ZEgFPYqOWUInZhseMbj4d6BqGqtL MzVavMq3vWzo6pGmTp3q2UTww8B5e4YvR967aUpzdwd9f40mI61F548HAhq6AlqCRNzu 058RTNx26ojRSlVdoDNDKwxRWpoA0Xj9Dwz5aL3Hr/cLb50EK40m/CKKz0/U9FnHxUpk KaDXFiWzbbKrPD4svvf47dC+t58Tbp6zea4MaPd8lQb1k6P/MRw22uE+1f+4f3W6JtOc i/Pw== X-Gm-Message-State: AOJu0YzUL9V7btfkwiAV+Uy9080igQiKSdBhmu3ka7Ur3QlGRFGqmlxV g96lZJRtXpIT41iySgu4uHxs9Y+/WjIBis7ioHbKqA== X-Google-Smtp-Source: AGHT+IHmdP+w7bmx5EPMykFzlMsIrxFehhDztFE298PAMbn4SQjrtVVuX49AEZrgBveT4k9GTPZ7urGKfZDYpNQ= X-Received: from aliceryhl2.c.googlers.com ([fda3:e722:ac3:cc00:68:949d:c0a8:572]) (user=aliceryhl job=sendgmr) by 2002:a05:6902:136d:b0:dbd:b756:983a with SMTP id bt13-20020a056902136d00b00dbdb756983amr1431440ybb.9.1704725406476; Mon, 08 Jan 2024 06:50:06 -0800 (PST) Date: Mon, 08 Jan 2024 14:49:57 +0000 In-Reply-To: <20240108-rb-new-condvar-methods-v4-0-88e0c871cc05@google.com> Precedence: bulk X-Mailing-List: rust-for-linux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240108-rb-new-condvar-methods-v4-0-88e0c871cc05@google.com> X-Developer-Key: i=aliceryhl@google.com; a=openpgp; fpr=49F6C1FAA74960F43A5B86A1EE7A392FDE96209F X-Developer-Signature: v=1; a=openpgp-sha256; l=1773; i=aliceryhl@google.com; h=from:subject:message-id; bh=V4luaNSyjxN/VywBe1xxHgUOl/JEebqcSaoMufGn4dg=; b=owEBbQKS/ZANAwAKAQRYvu5YxjlGAcsmYgBlnAuWxfp8qMduMbMX2T2PGs8QR3xSAjwxXpgeG Dswbv5Jvq2JAjMEAAEKAB0WIQSDkqKUTWQHCvFIvbIEWL7uWMY5RgUCZZwLlgAKCRAEWL7uWMY5 Rp2qEACsiZji70Fyhw9whBLl/VPFPDVm+L+rmMqGgu3Ol3E8p/1zVOQPKcMarHJynTIkxIZ/BJz 00x5mlOpb1UwU0miyhSRd7hvTGEV6vYMMpPxQmnt2ufAZHGec8IiSt+6T5UYIM4J+tJ7WVO4qlD /lkGVlBFrTu/HsXqslRm5yuPowIGMcT9Z4e79BqNQ138EVshyosAKB67z5Au+b3zdiHMB/eJu2y zWOWTnDqmqIW27Jomq+hI3WON7JltKkhEc9qnJacsSmXukGUlxrEnlv8xWfNMgB0JMRcFB4iRYP i9YwUTtPgHoJ5NcbHiK94AdUcmW8fmDAL1H6aotymo9E0/QHEo4kVPMNCZxwjVZdVgMVo+oBKuo FsYF+t/4HQfVZhxIu+FP+F2OPL/RRIRR8IsScNfY7EVId+5K92wS2bk/n2e0etBEvcq7Qrqa1l2 QVhabtO9k+q1a9cbbZhoiy3b114SuXFe5CL6F+TWoKs6RE3oJIvNWJbBCmojtP5dlkxuhhLniWi +t5yvTS3o1OW8AHvWDGy+Wc2sABBPGMGCWw0Va/fYcYbG6vRke1xor8Dg4lcrJqtEcfj2ZfTupH bMq5O1WR21V4a6bCJ6QnQlBWjT7poRDxDAYwXNJbZ8ttEGRT+GvBEEjy83qmNERBam2nTqRYFVR 0D8lnfZ2ALcAPXQ== X-Mailer: b4 0.13-dev-26615 Message-ID: <20240108-rb-new-condvar-methods-v4-1-88e0c871cc05@google.com> Subject: [PATCH v4 1/4] rust: sync: add `CondVar::notify_sync` From: Alice Ryhl To: Miguel Ojeda , Alex Gaynor , Wedson Almeida Filho , Boqun Feng , Gary Guo , "=?utf-8?q?Bj=C3=B6rn_Roy_Baron?=" , Benno Lossin , Andreas Hindborg , Peter Zijlstra , Ingo Molnar , Will Deacon , Waiman Long , Tiago Lam , Thomas Gleixner Cc: Martin Rodriguez Reboredo , rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org, Alice Ryhl Content-Type: text/plain; charset="utf-8" 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. Reviewed-by: Benno Lossin Reviewed-by: Martin Rodriguez Reboredo Reviewed-by: Tiago Lam Reviewed-by: Boqun Feng Signed-off-by: Alice Ryhl --- rust/kernel/sync/condvar.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/rust/kernel/sync/condvar.rs b/rust/kernel/sync/condvar.rs index f65e19d5a37c..b323a0c26513 100644 --- a/rust/kernel/sync/condvar.rs +++ b/rust/kernel/sync/condvar.rs @@ -155,6 +155,16 @@ fn notify(&self, count: i32, flags: u32) { }; } + /// Calls the kernel function to notify one 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. + 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 -- 2.43.0.472.g3155946c3a-goog