Skip to content

Commit 29bc83e

Browse files
inwardvesselNeeraj Upadhyay
authored andcommitted
srcu: faster gp seq wrap-around
Using a higher value for the initial gp sequence counters allows for wrapping to occur faster. It can help with surfacing any issues that may be happening as a result of the wrap around. Signed-off-by: JP Kobryn <[email protected]> Tested-by: Paul E. McKenney <[email protected]> Signed-off-by: Neeraj Upadhyay <[email protected]>
1 parent 8400291 commit 29bc83e

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

include/linux/rcupdate.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
#define ULONG_CMP_GE(a, b) (ULONG_MAX / 2 >= (a) - (b))
3535
#define ULONG_CMP_LT(a, b) (ULONG_MAX / 2 < (a) - (b))
3636

37+
#define RCU_SEQ_CTR_SHIFT 2
38+
#define RCU_SEQ_STATE_MASK ((1 << RCU_SEQ_CTR_SHIFT) - 1)
39+
3740
/* Exported common interfaces */
3841
void call_rcu(struct rcu_head *head, rcu_callback_t func);
3942
void rcu_barrier_tasks(void);

include/linux/srcutree.h

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,23 @@ struct srcu_struct {
129129
#define SRCU_STATE_SCAN1 1
130130
#define SRCU_STATE_SCAN2 2
131131

132+
/*
133+
* Values for initializing gp sequence fields. Higher values allow wrap arounds to
134+
* occur earlier.
135+
* The second value with state is useful in the case of static initialization of
136+
* srcu_usage where srcu_gp_seq_needed is expected to have some state value in its
137+
* lower bits (or else it will appear to be already initialized within
138+
* the call check_init_srcu_struct()).
139+
*/
140+
#define SRCU_GP_SEQ_INITIAL_VAL ((0UL - 100UL) << RCU_SEQ_CTR_SHIFT)
141+
#define SRCU_GP_SEQ_INITIAL_VAL_WITH_STATE (SRCU_GP_SEQ_INITIAL_VAL - 1)
142+
132143
#define __SRCU_USAGE_INIT(name) \
133144
{ \
134145
.lock = __SPIN_LOCK_UNLOCKED(name.lock), \
135-
.srcu_gp_seq_needed = -1UL, \
146+
.srcu_gp_seq = SRCU_GP_SEQ_INITIAL_VAL, \
147+
.srcu_gp_seq_needed = SRCU_GP_SEQ_INITIAL_VAL_WITH_STATE, \
148+
.srcu_gp_seq_needed_exp = SRCU_GP_SEQ_INITIAL_VAL, \
136149
.work = __DELAYED_WORK_INITIALIZER(name.work, NULL, 0), \
137150
}
138151

kernel/rcu/rcu.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@
5454
* grace-period sequence number.
5555
*/
5656

57-
#define RCU_SEQ_CTR_SHIFT 2
58-
#define RCU_SEQ_STATE_MASK ((1 << RCU_SEQ_CTR_SHIFT) - 1)
59-
6057
/* Low-order bit definition for polled grace-period APIs. */
6158
#define RCU_GET_STATE_COMPLETED 0x1
6259

kernel/rcu/srcutree.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)
247247
mutex_init(&ssp->srcu_sup->srcu_cb_mutex);
248248
mutex_init(&ssp->srcu_sup->srcu_gp_mutex);
249249
ssp->srcu_idx = 0;
250-
ssp->srcu_sup->srcu_gp_seq = 0;
250+
ssp->srcu_sup->srcu_gp_seq = SRCU_GP_SEQ_INITIAL_VAL;
251251
ssp->srcu_sup->srcu_barrier_seq = 0;
252252
mutex_init(&ssp->srcu_sup->srcu_barrier_mutex);
253253
atomic_set(&ssp->srcu_sup->srcu_barrier_cpu_cnt, 0);
@@ -258,15 +258,16 @@ static int init_srcu_struct_fields(struct srcu_struct *ssp, bool is_static)
258258
if (!ssp->sda)
259259
goto err_free_sup;
260260
init_srcu_struct_data(ssp);
261-
ssp->srcu_sup->srcu_gp_seq_needed_exp = 0;
261+
ssp->srcu_sup->srcu_gp_seq_needed_exp = SRCU_GP_SEQ_INITIAL_VAL;
262262
ssp->srcu_sup->srcu_last_gp_end = ktime_get_mono_fast_ns();
263263
if (READ_ONCE(ssp->srcu_sup->srcu_size_state) == SRCU_SIZE_SMALL && SRCU_SIZING_IS_INIT()) {
264264
if (!init_srcu_struct_nodes(ssp, GFP_ATOMIC))
265265
goto err_free_sda;
266266
WRITE_ONCE(ssp->srcu_sup->srcu_size_state, SRCU_SIZE_BIG);
267267
}
268268
ssp->srcu_sup->srcu_ssp = ssp;
269-
smp_store_release(&ssp->srcu_sup->srcu_gp_seq_needed, 0); /* Init done. */
269+
smp_store_release(&ssp->srcu_sup->srcu_gp_seq_needed,
270+
SRCU_GP_SEQ_INITIAL_VAL); /* Init done. */
270271
return 0;
271272

272273
err_free_sda:

0 commit comments

Comments
 (0)