Re: [PATCH rcu 07/11] srcu: Add srcu_read_lock_lite() and srcu_read_unlock_lite()
From: Alexei Starovoitov
Date: Tue Sep 03 2024 - 15:46:27 EST
On Tue, Sep 3, 2024 at 9:33 AM Paul E. McKenney <paulmck@xxxxxxxxxx> wrote:
>
> diff --git a/include/linux/srcu.h b/include/linux/srcu.h
> index 84daaa33ea0ab..4ba96e2cfa405 100644
> --- a/include/linux/srcu.h
> +++ b/include/linux/srcu.h
...
> +static inline int srcu_read_lock_lite(struct srcu_struct *ssp) __acquires(ssp)
> +{
> + int retval;
> +
> + srcu_check_read_flavor(ssp, SRCU_READ_FLAVOR_LITE);
> + retval = __srcu_read_lock_lite(ssp);
> + rcu_try_lock_acquire(&ssp->dep_map);
> + return retval;
> +}
...
> diff --git a/kernel/rcu/srcutree.c b/kernel/rcu/srcutree.c
> index 602b4b8c4b891..bab888e86b9bb 100644
> --- a/kernel/rcu/srcutree.c
> +++ b/kernel/rcu/srcutree.c
> +int __srcu_read_lock_lite(struct srcu_struct *ssp)
> +{
> + int idx;
> +
> + RCU_LOCKDEP_WARN(!rcu_is_watching(), "RCU must be watching srcu_read_lock_lite().");
> + idx = READ_ONCE(ssp->srcu_idx) & 0x1;
> + this_cpu_inc(ssp->sda->srcu_lock_count[idx].counter); /* Y */
> + barrier(); /* Avoid leaking the critical section. */
> + return idx;
> +}
> +EXPORT_SYMBOL_GPL(__srcu_read_lock_lite);
The use cases where smp_mb() penalty is noticeable probably will notice
the cost of extra call too.
Can the main part be in srcu.h as well to make it truly "lite" ?
Otherwise we'd have to rely on compilers doing LTO which may or may not happen.