* [PATCH] rust_binder: Reuse the thread lock in get_work_local()
@ 2026-11-24 15:04 Peder Bergan via B4 Relay
0 siblings, 0 replies; only message in thread
From: Peder Bergan via B4 Relay @ 2026-11-24 15:04 UTC (permalink / raw)
To: Alice Ryhl, Carlos Llamas, Greg Kroah-Hartman
Cc: Arve Hjønnevåg, Todd Kjos, Christian Brauner,
rust-for-linux, linux-kernel
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>
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-24 15:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-24 15:04 [PATCH] rust_binder: Reuse the thread lock in get_work_local() Peder Bergan via B4 Relay
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®