There is a need for a polling interface for SRCU grace periods. This polling needs to distinguish between an SRCU instance being idle on the one hand or in the middle of a grace period on the other. This commit therefore converts the Tiny SRCU srcu_struct structure's srcu_idx from a defacto boolean to a free-running counter, using the bottom bit to indicate that a grace period is in progress. The second-from-bottom bit is thus used as the index returned by srcu_read_lock().
Unified · Split
| @@ -15,7 +15,7 @@ · 14 unmodified lines | ||
| 15 | 15 | |
| 16 | 16 | struct srcu_struct { |
| 17 | 17 | short srcu_lock_nesting[2]; /* srcu_read_lock() nesting depth. */ |
| 18 | − short srcu_idx; /* Current reader array element. */ | |
| 18 | + unsigned short srcu_idx; /* Current reader array element in bit 0x2. */ | |
| 19 | 19 | u8 srcu_gp_running; /* GP workqueue running? */ |
| 20 | 20 | u8 srcu_gp_waiting; /* GP waiting for readers? */ |
| 21 | 21 | struct swait_queue_head srcu_wq; |
| @@ -59,7 +59,7 @@ static inline int __srcu_read_lock(struct srcu_struct *ssp) · 37 unmodified lines | ||
| 59 | 59 | { |
| 60 | 60 | int idx; |
| 61 | 61 | |
| 62 | − idx = READ_ONCE(ssp->srcu_idx); | |
| 62 | + idx = ((READ_ONCE(ssp->srcu_idx) + 1) & 0x2) >> 1; | |
| 63 | 63 | WRITE_ONCE(ssp->srcu_lock_nesting[idx], ssp->srcu_lock_nesting[idx] + 1); |
| 64 | 64 | return idx; |
| 65 | 65 | } |
| @@ -80,7 +80,7 @@ static inline void srcu_torture_stats_print(struct srcu_struct *ssp, · 14 unmodified lines | ||
| 80 | 80 | { |
| 81 | 81 | int idx; |
| 82 | 82 | |
| 83 | − idx = READ_ONCE(ssp->srcu_idx) & 0x1; | |
| 83 | + idx = ((READ_ONCE(ssp->srcu_idx) + 1) & 0x2) >> 1; | |
| 84 | 84 | pr_alert("%s%s Tiny SRCU per-CPU(idx=%d): (%hd,%hd)\n", |
| 85 | 85 | tt, tf, idx, |
| 86 | 86 | READ_ONCE(ssp->srcu_lock_nesting[!idx]), |
| @@ -124,11 +124,12 @@ void srcu_drive_gp(struct work_struct *wp) · 123 unmodified lines | ||
| 124 | 124 | ssp->srcu_cb_head = NULL; |
| 125 | 125 | ssp->srcu_cb_tail = &ssp->srcu_cb_head; |
| 126 | 126 | local_irq_enable(); |
| 127 | − idx = ssp->srcu_idx; | |
| 128 | − WRITE_ONCE(ssp->srcu_idx, !ssp->srcu_idx); | |
| 127 | + idx = (ssp->srcu_idx & 0x2) / 2; | |
| 128 | + WRITE_ONCE(ssp->srcu_idx, ssp->srcu_idx + 1); | |
| 129 | 129 | WRITE_ONCE(ssp->srcu_gp_waiting, true); /* srcu_read_unlock() wakes! */ |
| 130 | 130 | swait_event_exclusive(ssp->srcu_wq, !READ_ONCE(ssp->srcu_lock_nesting[idx])); |
| 131 | 131 | WRITE_ONCE(ssp->srcu_gp_waiting, false); /* srcu_read_unlock() cheap. */ |
| 132 | + WRITE_ONCE(ssp->srcu_idx, ssp->srcu_idx + 1); | |
| 132 | 133 | |
| 133 | 134 | /* Invoke the callbacks we removed above. */ |
| 134 | 135 | while (lh) { |