Skip to content

Commit d02944d

Browse files
Darksonnfbq
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 <[email protected]> Reviewed-by: Martin Rodriguez Reboredo <[email protected]> Reviewed-by: Tiago Lam <[email protected]> Reviewed-by: Boqun Feng <[email protected]> Signed-off-by: Alice Ryhl <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent b01a973 commit d02944d

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
@@ -155,6 +155,16 @@ impl CondVar {
155155
};
156156
}
157157

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

0 commit comments

Comments
 (0)