Skip to content

Commit 3e64541

Browse files
Darksonnojeda
authored andcommitted
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: Benno Lossin <benno.lossin@proton.me> Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by: Tiago Lam <tiagolam@gmail.com> Reviewed-by: Boqun Feng <boqun.feng@gmail.com> Signed-off-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20240108-rb-new-condvar-methods-v4-1-88e0c871cc05@google.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 6b1b232 commit 3e64541

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

rust/kernel/sync/condvar.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,16 @@ impl CondVar {
159159
};
160160
}
161161

162+
/// Calls the kernel function to notify one thread synchronously.
163+
///
164+
/// This method behaves like `notify_one`, except that it hints to the scheduler that the
165+
/// current thread is about to go to sleep, so it should schedule the target thread on the same
166+
/// CPU.
167+
pub fn notify_sync(&self) {
168+
// SAFETY: `wait_queue_head` points to valid memory.
169+
unsafe { bindings::__wake_up_sync(self.wait_queue_head.get(), bindings::TASK_NORMAL) };
170+
}
171+
162172
/// Wakes a single waiter up, if any.
163173
///
164174
/// This is not 'sticky' in the sense that if no thread is waiting, the notification is lost

0 commit comments

Comments
 (0)