On Tue, Sep 03, 2024 at 12:45:23PM -0700, Alexei Starovoitov wrote: > 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. I vaguely recall #include issues for old-times srcu_read_lock() and srcu_read_unlock(), but I will try it and see what happens. In the meantime, if you are too curious for your own good... ;-) One way to check the performance is to work in the other direction. For example, add ndelay(10) or similar to the current srcu_read_lock_lite() implementation and seeing if this is visible at the system level. Thanx, Paul