Skip to content

Commit f4bde41

Browse files
paulmckrcufbq
authored andcommitted
srcu: Pull pointer-to-integer conversion into __srcu_ptr_to_ctr()
This commit abstracts the srcu_read_lock*() pointer-to-integer conversion into a new __srcu_ptr_to_ctr(). This will be used in rcutorture for testing an srcu_read_lock_fast() that returns a pointer rather than an integer. 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 4d86b1e commit f4bde41

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

include/linux/srcutree.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,13 @@ void synchronize_srcu_expedited(struct srcu_struct *ssp);
211211
void srcu_barrier(struct srcu_struct *ssp);
212212
void srcu_torture_stats_print(struct srcu_struct *ssp, char *tt, char *tf);
213213

214+
// Converts a per-CPU pointer to an ->srcu_ctrs[] array element to that
215+
// element's index.
216+
static inline bool __srcu_ptr_to_ctr(struct srcu_struct *ssp, struct srcu_ctr __percpu *scpp)
217+
{
218+
return scpp - &ssp->sda->srcu_ctrs[0];
219+
}
220+
214221
/*
215222
* Counts the new reader in the appropriate per-CPU element of the
216223
* srcu_struct. Returns an index that must be passed to the matching
@@ -228,7 +235,7 @@ static inline int __srcu_read_lock_lite(struct srcu_struct *ssp)
228235
RCU_LOCKDEP_WARN(!rcu_is_watching(), "RCU must be watching srcu_read_lock_lite().");
229236
this_cpu_inc(scp->srcu_locks.counter); /* Y */
230237
barrier(); /* Avoid leaking the critical section. */
231-
return scp - &ssp->sda->srcu_ctrs[0];
238+
return __srcu_ptr_to_ctr(ssp, scp);
232239
}
233240

234241
/*

kernel/rcu/srcutree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ int __srcu_read_lock(struct srcu_struct *ssp)
753753

754754
this_cpu_inc(scp->srcu_locks.counter);
755755
smp_mb(); /* B */ /* Avoid leaking the critical section. */
756-
return scp - &ssp->sda->srcu_ctrs[0];
756+
return __srcu_ptr_to_ctr(ssp, scp);
757757
}
758758
EXPORT_SYMBOL_GPL(__srcu_read_lock);
759759

@@ -783,7 +783,7 @@ int __srcu_read_lock_nmisafe(struct srcu_struct *ssp)
783783

784784
atomic_long_inc(&scp->srcu_locks);
785785
smp_mb__after_atomic(); /* B */ /* Avoid leaking the critical section. */
786-
return scpp - &ssp->sda->srcu_ctrs[0];
786+
return __srcu_ptr_to_ctr(ssp, scpp);
787787
}
788788
EXPORT_SYMBOL_GPL(__srcu_read_lock_nmisafe);
789789

0 commit comments

Comments
 (0)