From: Peder Bergan via B4 Relay <devnull+peder.bergan.gmail.com@kernel.org>
To: Alice Ryhl <aliceryhl@google.com>,
Carlos Llamas <cmllamas@google.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: "Arve Hjønnevåg" <arve@android.com>,
"Todd Kjos" <tkjos@android.com>,
"Christian Brauner" <brauner@kernel.org>,
rust-for-linux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] rust_binder: Reuse the thread lock in get_work_local()
Date: Tue, 24 Nov 2026 16:04:27 +0100 [thread overview]
Message-ID: <20261124-perf-binder-local-work-lock-v1-1-bd8de1a840c1@gmail.com> (raw)
From: Peder Bergan <peder.bergan@gmail.com>
get_work_local() takes the thread lock to check looper_need_return.
When the flag is clear, it drops and retakes the lock before trying to
pop work for either a blocking or a nonblocking read.
Keep the guard across the flag check and the first pop. A blocking
read that finds no work still registers its wait before the condition
variable releases the guard, so a producer can wake the reader.
Signed-off-by: Peder Bergan <peder.bergan@gmail.com>
---
Reusing the guard eliminated 4,013 lock acquisitions and 4,013 releases
on each of two x86-64 KVM hosts. Each trace covered setup and 1,000
synchronous Binder echo calls. Both kernels passed checks for empty
nonblocking reads, signal interruption and waking a blocked reader by
closing a duplicate Binder file descriptor.
OpenAI Codex assisted with coding and testing.
---
drivers/android/binder/thread.rs | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/drivers/android/binder/thread.rs b/drivers/android/binder/thread.rs
index 54a208caebe12..8efda6e9ded1e 100644
--- a/drivers/android/binder/thread.rs
+++ b/drivers/android/binder/thread.rs
@@ -549,20 +549,17 @@ pub(crate) fn has_current_transaction(&self) -> bool {
// mangled symbol names.
#[export_name = "rust_binder_waitlcl"]
fn get_work_local(self: &Arc<Self>, wait: bool) -> Result<Option<DLArc<dyn DeliverToRead>>> {
- {
- let mut inner = self.inner.lock();
- if inner.looper_need_return {
- return Ok(inner.pop_work());
- }
+ let mut inner = self.inner.lock();
+ if inner.looper_need_return {
+ return Ok(inner.pop_work());
}
// Try once if the caller does not want to wait.
if !wait {
- return self.inner.lock().pop_work().ok_or(EAGAIN).map(Some);
+ return inner.pop_work().ok_or(EAGAIN).map(Some);
}
// Loop waiting only on the local queue (i.e., not registering with the process queue).
- let mut inner = self.inner.lock();
loop {
if let Some(work) = inner.pop_work() {
return Ok(Some(work));
---
base-commit: 917fcbf033154a6c8d83cfa6c88f012b71eb37b2
change-id: 20261124-perf-binder-local-work-lock-9ce5d1f365bc
Best regards,
--
Peder Bergan <peder.bergan@gmail.com>
reply other threads:[~2026-11-24 15:04 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261124-perf-binder-local-work-lock-v1-1-bd8de1a840c1@gmail.com \
--to=devnull+peder.bergan.gmail.com@kernel.org \
--cc=aliceryhl@google.com \
--cc=arve@android.com \
--cc=brauner@kernel.org \
--cc=cmllamas@google.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peder.bergan@gmail.com \
--cc=rust-for-linux@vger.kernel.org \
--cc=tkjos@android.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®