.. | .. |
---|
| 1 | +/* SPDX-License-Identifier: GPL-2.0+ */ |
---|
1 | 2 | /* |
---|
2 | 3 | * Sleepable Read-Copy Update mechanism for mutual exclusion, |
---|
3 | 4 | * tiny variant. |
---|
4 | 5 | * |
---|
5 | | - * This program is free software; you can redistribute it and/or modify |
---|
6 | | - * it under the terms of the GNU General Public License as published by |
---|
7 | | - * the Free Software Foundation; either version 2 of the License, or |
---|
8 | | - * (at your option) any later version. |
---|
9 | | - * |
---|
10 | | - * This program is distributed in the hope that it will be useful, |
---|
11 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
12 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
13 | | - * GNU General Public License for more details. |
---|
14 | | - * |
---|
15 | | - * You should have received a copy of the GNU General Public License |
---|
16 | | - * along with this program; if not, you can access it online at |
---|
17 | | - * http://www.gnu.org/licenses/gpl-2.0.html. |
---|
18 | | - * |
---|
19 | 6 | * Copyright (C) IBM Corporation, 2017 |
---|
20 | 7 | * |
---|
21 | | - * Author: Paul McKenney <paulmck@us.ibm.com> |
---|
| 8 | + * Author: Paul McKenney <paulmck@linux.ibm.com> |
---|
22 | 9 | */ |
---|
23 | 10 | |
---|
24 | 11 | #ifndef _LINUX_SRCU_TINY_H |
---|
.. | .. |
---|
28 | 15 | |
---|
29 | 16 | struct srcu_struct { |
---|
30 | 17 | short srcu_lock_nesting[2]; /* srcu_read_lock() nesting depth. */ |
---|
31 | | - short srcu_idx; /* Current reader array element. */ |
---|
| 18 | + unsigned short srcu_idx; /* Current reader array element in bit 0x2. */ |
---|
| 19 | + unsigned short srcu_idx_max; /* Furthest future srcu_idx request. */ |
---|
32 | 20 | u8 srcu_gp_running; /* GP workqueue running? */ |
---|
33 | 21 | u8 srcu_gp_waiting; /* GP waiting for readers? */ |
---|
34 | 22 | struct swait_queue_head srcu_wq; |
---|
.. | .. |
---|
60 | 48 | #define DEFINE_STATIC_SRCU(name) \ |
---|
61 | 49 | static struct srcu_struct name = __SRCU_STRUCT_INIT(name, name) |
---|
62 | 50 | |
---|
63 | | -void synchronize_srcu(struct srcu_struct *sp); |
---|
| 51 | +void synchronize_srcu(struct srcu_struct *ssp); |
---|
64 | 52 | |
---|
65 | 53 | /* |
---|
66 | 54 | * Counts the new reader in the appropriate per-CPU element of the |
---|
.. | .. |
---|
68 | 56 | * __srcu_read_unlock() must be in the same handler instance. Returns an |
---|
69 | 57 | * index that must be passed to the matching srcu_read_unlock(). |
---|
70 | 58 | */ |
---|
71 | | -static inline int __srcu_read_lock(struct srcu_struct *sp) |
---|
| 59 | +static inline int __srcu_read_lock(struct srcu_struct *ssp) |
---|
72 | 60 | { |
---|
73 | 61 | int idx; |
---|
74 | 62 | |
---|
75 | | - idx = READ_ONCE(sp->srcu_idx); |
---|
76 | | - WRITE_ONCE(sp->srcu_lock_nesting[idx], sp->srcu_lock_nesting[idx] + 1); |
---|
| 63 | + idx = ((READ_ONCE(ssp->srcu_idx) + 1) & 0x2) >> 1; |
---|
| 64 | + WRITE_ONCE(ssp->srcu_lock_nesting[idx], ssp->srcu_lock_nesting[idx] + 1); |
---|
77 | 65 | return idx; |
---|
78 | 66 | } |
---|
79 | 67 | |
---|
80 | | -static inline void synchronize_srcu_expedited(struct srcu_struct *sp) |
---|
| 68 | +static inline void synchronize_srcu_expedited(struct srcu_struct *ssp) |
---|
81 | 69 | { |
---|
82 | | - synchronize_srcu(sp); |
---|
| 70 | + synchronize_srcu(ssp); |
---|
83 | 71 | } |
---|
84 | 72 | |
---|
85 | | -static inline void srcu_barrier(struct srcu_struct *sp) |
---|
| 73 | +static inline void srcu_barrier(struct srcu_struct *ssp) |
---|
86 | 74 | { |
---|
87 | | - synchronize_srcu(sp); |
---|
| 75 | + synchronize_srcu(ssp); |
---|
88 | 76 | } |
---|
89 | 77 | |
---|
90 | 78 | /* Defined here to avoid size increase for non-torture kernels. */ |
---|
91 | | -static inline void srcu_torture_stats_print(struct srcu_struct *sp, |
---|
| 79 | +static inline void srcu_torture_stats_print(struct srcu_struct *ssp, |
---|
92 | 80 | char *tt, char *tf) |
---|
93 | 81 | { |
---|
94 | 82 | int idx; |
---|
95 | 83 | |
---|
96 | | - idx = READ_ONCE(sp->srcu_idx) & 0x1; |
---|
| 84 | + idx = ((READ_ONCE(ssp->srcu_idx) + 1) & 0x2) >> 1; |
---|
97 | 85 | pr_alert("%s%s Tiny SRCU per-CPU(idx=%d): (%hd,%hd)\n", |
---|
98 | 86 | tt, tf, idx, |
---|
99 | | - READ_ONCE(sp->srcu_lock_nesting[!idx]), |
---|
100 | | - READ_ONCE(sp->srcu_lock_nesting[idx])); |
---|
| 87 | + READ_ONCE(ssp->srcu_lock_nesting[!idx]), |
---|
| 88 | + READ_ONCE(ssp->srcu_lock_nesting[idx])); |
---|
101 | 89 | } |
---|
102 | 90 | |
---|
103 | 91 | #endif |
---|