Re: [PATCH v2 01/10] rust: rcu: Add get_state_synchronize_rcu()
From: Gary Guo
Date: Wed Nov 25 2026 - 11:47:54 EST
On Tue Nov 24, 2026 at 12:29 PM GMT, Philipp Stanner wrote:
> Some users don't want to perform a full call to synchronize_rcu() if it
> is avoidable.
>
> Add abstractions for get_state_synchronize_rcu() to obtain a grace
> period identifier.
>
> Signed-off-by: Philipp Stanner <phasta@xxxxxxxxxx>
> ---
> rust/kernel/sync/rcu.rs | 10 ++++++++++
> 1 file changed, 10 insertions(+)
>
> diff --git a/rust/kernel/sync/rcu.rs b/rust/kernel/sync/rcu.rs
> index 0daa1ac87d81..7afc78b34759 100644
> --- a/rust/kernel/sync/rcu.rs
> +++ b/rust/kernel/sync/rcu.rs
> @@ -86,3 +86,13 @@ pub fn synchronize_rcu() {
> // SAFETY: `synchronize_rcu()` is always safe to be called from process context.
> unsafe { bindings::synchronize_rcu() };
> }
> +
> +/// Obtain a cookie identifying a grace period.
> +///
> +/// Returns an identifier that can be used by other functions to check whether
> +/// a specific grace period has passed already.
> +#[inline]
> +pub fn get_state_synchronize_rcu() -> usize {
> + // SAFETY: `get_state_synchronize_rcu()` is always safe to be called.
> + unsafe { bindings::get_state_synchronize_rcu() }
> +}
Please create a new type for this since people are not supposed to poke into
this. It also saves you from having to make cond_synchronize_rcu unsafe.
pub struct RcuState(usize);
impl RcuState {
/// Snapshot current RCU state.
fn get() -> Self { ... }
/// Check if RCU grace period has been completed since the `RcuState::get`.
fn poll() -> bool { ... }
/// Ensure that a RCU grace period has been completed since `RcuState::get`.
fn synchronize_rcu() { ... }
}
Best,
Gary