]>
Commit | Line | Data |
---|---|---|
d8be8173 PM |
1 | /* |
2 | * Sleepable Read-Copy Update mechanism for mutual exclusion, | |
3 | * tree variant. | |
4 | * | |
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 | * Copyright (C) IBM Corporation, 2017 | |
20 | * | |
21 | * Author: Paul McKenney <paulmck@us.ibm.com> | |
22 | */ | |
23 | ||
24 | #ifndef _LINUX_SRCU_TREE_H | |
25 | #define _LINUX_SRCU_TREE_H | |
26 | ||
da915ad5 PM |
27 | #include <linux/rcu_node_tree.h> |
28 | #include <linux/completion.h> | |
29 | ||
30 | struct srcu_node; | |
31 | struct srcu_struct; | |
32 | ||
33 | /* | |
34 | * Per-CPU structure feeding into leaf srcu_node, similar in function | |
35 | * to rcu_node. | |
36 | */ | |
37 | struct srcu_data { | |
38 | /* Read-side state. */ | |
39 | unsigned long srcu_lock_count[2]; /* Locks per CPU. */ | |
40 | unsigned long srcu_unlock_count[2]; /* Unlocks per CPU. */ | |
41 | ||
42 | /* Update-side state. */ | |
43 | spinlock_t lock ____cacheline_internodealigned_in_smp; | |
44 | struct rcu_segcblist srcu_cblist; /* List of callbacks.*/ | |
45 | unsigned long srcu_gp_seq_needed; /* Furthest future GP needed. */ | |
46 | bool srcu_cblist_invoking; /* Invoking these CBs? */ | |
47 | struct delayed_work work; /* Context for CB invoking. */ | |
48 | struct rcu_head srcu_barrier_head; /* For srcu_barrier() use. */ | |
49 | struct srcu_node *mynode; /* Leaf srcu_node. */ | |
c7e88067 PM |
50 | unsigned long grpmask; /* Mask for leaf srcu_node */ |
51 | /* ->srcu_data_have_cbs[]. */ | |
da915ad5 PM |
52 | int cpu; |
53 | struct srcu_struct *sp; | |
d8be8173 PM |
54 | }; |
55 | ||
da915ad5 PM |
56 | /* |
57 | * Node in SRCU combining tree, similar in function to rcu_data. | |
58 | */ | |
59 | struct srcu_node { | |
60 | spinlock_t lock; | |
61 | unsigned long srcu_have_cbs[4]; /* GP seq for children */ | |
62 | /* having CBs, but only */ | |
63 | /* is > ->srcu_gq_seq. */ | |
c7e88067 PM |
64 | unsigned long srcu_data_have_cbs[4]; /* Which srcu_data structs */ |
65 | /* have CBs for given GP? */ | |
da915ad5 PM |
66 | struct srcu_node *srcu_parent; /* Next up in tree. */ |
67 | int grplo; /* Least CPU for node. */ | |
68 | int grphi; /* Biggest CPU for node. */ | |
69 | }; | |
70 | ||
71 | /* | |
72 | * Per-SRCU-domain structure, similar in function to rcu_state. | |
73 | */ | |
d8be8173 | 74 | struct srcu_struct { |
da915ad5 PM |
75 | struct srcu_node node[NUM_RCU_NODES]; /* Combining tree. */ |
76 | struct srcu_node *level[RCU_NUM_LVLS + 1]; | |
77 | /* First node at each level. */ | |
78 | struct mutex srcu_cb_mutex; /* Serialize CB preparation. */ | |
79 | spinlock_t gp_lock; /* protect ->srcu_cblist */ | |
80 | struct mutex srcu_gp_mutex; /* Serialize GP work. */ | |
81 | unsigned int srcu_idx; /* Current rdr array element. */ | |
82 | unsigned long srcu_gp_seq; /* Grace-period seq #. */ | |
83 | unsigned long srcu_gp_seq_needed; /* Latest gp_seq needed. */ | |
84 | atomic_t srcu_exp_cnt; /* # ongoing expedited GPs. */ | |
85 | struct srcu_data __percpu *sda; /* Per-CPU srcu_data array. */ | |
86 | unsigned long srcu_barrier_seq; /* srcu_barrier seq #. */ | |
87 | struct mutex srcu_barrier_mutex; /* Serialize barrier ops. */ | |
88 | struct completion srcu_barrier_completion; | |
89 | /* Awaken barrier rq at end. */ | |
90 | atomic_t srcu_barrier_cpu_cnt; /* # CPUs not yet posting a */ | |
91 | /* callback for the barrier */ | |
92 | /* operation. */ | |
d8be8173 PM |
93 | struct delayed_work work; |
94 | #ifdef CONFIG_DEBUG_LOCK_ALLOC | |
95 | struct lockdep_map dep_map; | |
96 | #endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */ | |
97 | }; | |
98 | ||
da915ad5 | 99 | /* Values for state variable (bottom bits of ->srcu_gp_seq). */ |
d8be8173 PM |
100 | #define SRCU_STATE_IDLE 0 |
101 | #define SRCU_STATE_SCAN1 1 | |
102 | #define SRCU_STATE_SCAN2 2 | |
103 | ||
104 | void process_srcu(struct work_struct *work); | |
105 | ||
106 | #define __SRCU_STRUCT_INIT(name) \ | |
107 | { \ | |
da915ad5 PM |
108 | .sda = &name##_srcu_data, \ |
109 | .gp_lock = __SPIN_LOCK_UNLOCKED(name.gp_lock), \ | |
110 | .srcu_gp_seq_needed = 0 - 1, \ | |
d8be8173 PM |
111 | __SRCU_DEP_MAP_INIT(name) \ |
112 | } | |
113 | ||
114 | /* | |
115 | * Define and initialize a srcu struct at build time. | |
116 | * Do -not- call init_srcu_struct() nor cleanup_srcu_struct() on it. | |
117 | * | |
118 | * Note that although DEFINE_STATIC_SRCU() hides the name from other | |
119 | * files, the per-CPU variable rules nevertheless require that the | |
120 | * chosen name be globally unique. These rules also prohibit use of | |
121 | * DEFINE_STATIC_SRCU() within a function. If these rules are too | |
122 | * restrictive, declare the srcu_struct manually. For example, in | |
123 | * each file: | |
124 | * | |
125 | * static struct srcu_struct my_srcu; | |
126 | * | |
127 | * Then, before the first use of each my_srcu, manually initialize it: | |
128 | * | |
129 | * init_srcu_struct(&my_srcu); | |
130 | * | |
131 | * See include/linux/percpu-defs.h for the rules on per-CPU variables. | |
132 | */ | |
133 | #define __DEFINE_SRCU(name, is_static) \ | |
da915ad5 | 134 | static DEFINE_PER_CPU(struct srcu_data, name##_srcu_data);\ |
d8be8173 PM |
135 | is_static struct srcu_struct name = __SRCU_STRUCT_INIT(name) |
136 | #define DEFINE_SRCU(name) __DEFINE_SRCU(name, /* not static */) | |
137 | #define DEFINE_STATIC_SRCU(name) __DEFINE_SRCU(name, static) | |
138 | ||
139 | void synchronize_srcu_expedited(struct srcu_struct *sp); | |
140 | void srcu_barrier(struct srcu_struct *sp); | |
141 | unsigned long srcu_batches_completed(struct srcu_struct *sp); | |
142 | ||
7f6733c3 PM |
143 | void srcutorture_get_gp_data(enum rcutorture_type test_type, |
144 | struct srcu_struct *sp, int *flags, | |
145 | unsigned long *gpnum, unsigned long *completed); | |
146 | ||
d8be8173 | 147 | #endif |