Commit 3e645417 authored by Alice Ryhl's avatar Alice Ryhl Committed by Miguel Ojeda

rust: sync: add `CondVar::notify_sync`

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: default avatarBenno Lossin <benno.lossin@proton.me>
Reviewed-by: default avatarMartin Rodriguez Reboredo <yakoyoku@gmail.com>
Reviewed-by: default avatarTiago Lam <tiagolam@gmail.com>
Reviewed-by: default avatarBoqun Feng <boqun.feng@gmail.com>
Signed-off-by: default avatarAlice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20240108-rb-new-condvar-methods-v4-1-88e0c871cc05@google.comSigned-off-by: default avatarMiguel Ojeda <ojeda@kernel.org>
parent 6b1b2326
...@@ -159,6 +159,16 @@ fn notify(&self, count: i32, flags: u32) { ...@@ -159,6 +159,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_queue_head` points to valid memory.
unsafe { bindings::__wake_up_sync(self.wait_queue_head.get(), bindings::TASK_NORMAL) };
}
/// Wakes a single waiter up, if any. /// Wakes a single waiter up, if any.
/// ///
/// This is not 'sticky' in the sense that if no thread is waiting, the notification is lost /// This is not 'sticky' in the sense that if no thread is waiting, the notification is lost
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment