Skip to content

Commit 4937096

Browse files
paulmckrcufbq
authored andcommitted
srcu: Pull integer-to-pointer conversion into __srcu_ctr_to_ptr()
This commit abstracts the srcu_read_unlock*() integer-to-pointer conversion into a new __srcu_ctr_to_ptr(). This will be used in rcutorture for testing an srcu_read_unlock_fast() that avoids array-indexing overhead by taking a pointer rather than an integer. [ paulmck: Apply kernel test robot feedback. ] Signed-off-by: Paul E. McKenney <paulmck@kernel.org> Cc: Alexei Starovoitov <ast@kernel.org> Cc: Andrii Nakryiko <andrii@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Kent Overstreet <kent.overstreet@linux.dev> Cc: <bpf@vger.kernel.org> Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
1 parent f4bde41 commit 4937096

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

include/linux/srcutree.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,13 @@ static inline bool __srcu_ptr_to_ctr(struct srcu_struct *ssp, struct srcu_ctr __
218218
return scpp - &ssp->sda->srcu_ctrs[0];
219219
}
220220

221+
// Converts an integer to a per-CPU pointer to the corresponding
222+
// ->srcu_ctrs[] array element.
223+
static inline struct srcu_ctr __percpu *__srcu_ctr_to_ptr(struct srcu_struct *ssp, int idx)
224+
{
225+
return &ssp->sda->srcu_ctrs[idx];
226+
}
227+
221228
/*
222229
* Counts the new reader in the appropriate per-CPU element of the
223230
* srcu_struct. Returns an index that must be passed to the matching
@@ -252,7 +259,7 @@ static inline int __srcu_read_lock_lite(struct srcu_struct *ssp)
252259
static inline void __srcu_read_unlock_lite(struct srcu_struct *ssp, int idx)
253260
{
254261
barrier(); /* Avoid leaking the critical section. */
255-
this_cpu_inc(ssp->sda->srcu_ctrs[idx].srcu_unlocks.counter); /* Z */
262+
this_cpu_inc(__srcu_ctr_to_ptr(ssp, idx)->srcu_unlocks.counter); /* Z */
256263
RCU_LOCKDEP_WARN(!rcu_is_watching(), "RCU must be watching srcu_read_unlock_lite().");
257264
}
258265

kernel/rcu/srcutree.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ EXPORT_SYMBOL_GPL(__srcu_read_lock);
765765
void __srcu_read_unlock(struct srcu_struct *ssp, int idx)
766766
{
767767
smp_mb(); /* C */ /* Avoid leaking the critical section. */
768-
this_cpu_inc(ssp->sda->srcu_ctrs[idx].srcu_unlocks.counter);
768+
this_cpu_inc(__srcu_ctr_to_ptr(ssp, idx)->srcu_unlocks.counter);
769769
}
770770
EXPORT_SYMBOL_GPL(__srcu_read_unlock);
771771

@@ -794,10 +794,8 @@ EXPORT_SYMBOL_GPL(__srcu_read_lock_nmisafe);
794794
*/
795795
void __srcu_read_unlock_nmisafe(struct srcu_struct *ssp, int idx)
796796
{
797-
struct srcu_data *sdp = raw_cpu_ptr(ssp->sda);
798-
799797
smp_mb__before_atomic(); /* C */ /* Avoid leaking the critical section. */
800-
atomic_long_inc(&sdp->srcu_ctrs[idx].srcu_unlocks);
798+
atomic_long_inc(&raw_cpu_ptr(__srcu_ctr_to_ptr(ssp, idx))->srcu_unlocks);
801799
}
802800
EXPORT_SYMBOL_GPL(__srcu_read_unlock_nmisafe);
803801

0 commit comments

Comments
 (0)