Skip to content

Commit 5fe8919

Browse files
committed
srcu: Make Tiny SRCU use full-sized grace-period counters
This commit makes Tiny SRCU use full-sized grace-period counters to further avoid counter-wrap issues when using polled grace-period APIs. Signed-off-by: Paul E. McKenney <[email protected]>
1 parent de3f267 commit 5fe8919

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

include/linux/srcutiny.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616
struct srcu_struct {
1717
short srcu_lock_nesting[2]; /* srcu_read_lock() nesting depth. */
18-
unsigned short srcu_idx; /* Current reader array element in bit 0x2. */
19-
unsigned short srcu_idx_max; /* Furthest future srcu_idx request. */
2018
u8 srcu_gp_running; /* GP workqueue running? */
2119
u8 srcu_gp_waiting; /* GP waiting for readers? */
20+
unsigned long srcu_idx; /* Current reader array element in bit 0x2. */
21+
unsigned long srcu_idx_max; /* Furthest future srcu_idx request. */
2222
struct swait_queue_head srcu_wq;
2323
/* Last srcu_read_unlock() wakes GP. */
2424
struct rcu_head *srcu_cb_head; /* Pending callbacks: Head. */
@@ -82,7 +82,7 @@ static inline void srcu_torture_stats_print(struct srcu_struct *ssp,
8282
int idx;
8383

8484
idx = ((data_race(READ_ONCE(ssp->srcu_idx)) + 1) & 0x2) >> 1;
85-
pr_alert("%s%s Tiny SRCU per-CPU(idx=%d): (%hd,%hd) gp: %hu->%hu\n",
85+
pr_alert("%s%s Tiny SRCU per-CPU(idx=%d): (%hd,%hd) gp: %lu->%lu\n",
8686
tt, tf, idx,
8787
data_race(READ_ONCE(ssp->srcu_lock_nesting[!idx])),
8888
data_race(READ_ONCE(ssp->srcu_lock_nesting[idx])),

kernel/rcu/srcutiny.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ void srcu_drive_gp(struct work_struct *wp)
117117
struct srcu_struct *ssp;
118118

119119
ssp = container_of(wp, struct srcu_struct, srcu_work);
120-
if (ssp->srcu_gp_running || USHORT_CMP_GE(ssp->srcu_idx, READ_ONCE(ssp->srcu_idx_max)))
120+
if (ssp->srcu_gp_running || ULONG_CMP_GE(ssp->srcu_idx, READ_ONCE(ssp->srcu_idx_max)))
121121
return; /* Already running or nothing to do. */
122122

123123
/* Remove recently arrived callbacks and wait for readers. */
@@ -150,17 +150,17 @@ void srcu_drive_gp(struct work_struct *wp)
150150
* straighten that out.
151151
*/
152152
WRITE_ONCE(ssp->srcu_gp_running, false);
153-
if (USHORT_CMP_LT(ssp->srcu_idx, READ_ONCE(ssp->srcu_idx_max)))
153+
if (ULONG_CMP_LT(ssp->srcu_idx, READ_ONCE(ssp->srcu_idx_max)))
154154
schedule_work(&ssp->srcu_work);
155155
}
156156
EXPORT_SYMBOL_GPL(srcu_drive_gp);
157157

158158
static void srcu_gp_start_if_needed(struct srcu_struct *ssp)
159159
{
160-
unsigned short cookie;
160+
unsigned long cookie;
161161

162162
cookie = get_state_synchronize_srcu(ssp);
163-
if (USHORT_CMP_GE(READ_ONCE(ssp->srcu_idx_max), cookie))
163+
if (ULONG_CMP_GE(READ_ONCE(ssp->srcu_idx_max), cookie))
164164
return;
165165
WRITE_ONCE(ssp->srcu_idx_max, cookie);
166166
if (!READ_ONCE(ssp->srcu_gp_running)) {
@@ -215,7 +215,7 @@ unsigned long get_state_synchronize_srcu(struct srcu_struct *ssp)
215215
barrier();
216216
ret = (READ_ONCE(ssp->srcu_idx) + 3) & ~0x1;
217217
barrier();
218-
return ret & USHRT_MAX;
218+
return ret;
219219
}
220220
EXPORT_SYMBOL_GPL(get_state_synchronize_srcu);
221221

@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(start_poll_synchronize_srcu);
240240
*/
241241
bool poll_state_synchronize_srcu(struct srcu_struct *ssp, unsigned long cookie)
242242
{
243-
unsigned short cur_s = READ_ONCE(ssp->srcu_idx);
243+
unsigned long cur_s = READ_ONCE(ssp->srcu_idx);
244244

245245
barrier();
246-
return USHORT_CMP_GE(cur_s, cookie) || USHORT_CMP_LT(cur_s, cookie - 3);
246+
return ULONG_CMP_GE(cur_s, cookie) || ULONG_CMP_LT(cur_s, cookie - 3);
247247
}
248248
EXPORT_SYMBOL_GPL(poll_state_synchronize_srcu);
249249

0 commit comments

Comments
 (0)