1 /* SPDX-License-Identifier: GPL-2.0+ */ << 2 /* 1 /* 3 * Read-Copy Update mechanism for mutual exclu 2 * Read-Copy Update mechanism for mutual exclusion (tree-based version) 4 * Internal non-public definitions. 3 * Internal non-public definitions. 5 * 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 * 6 * Copyright IBM Corporation, 2008 19 * Copyright IBM Corporation, 2008 7 * 20 * 8 * Author: Ingo Molnar <mingo@elte.hu> 21 * Author: Ingo Molnar <mingo@elte.hu> 9 * Paul E. McKenney <paulmck@linux.ibm !! 22 * Paul E. McKenney <paulmck@linux.vnet.ibm.com> 10 */ 23 */ 11 24 12 #include <linux/cache.h> 25 #include <linux/cache.h> 13 #include <linux/kthread.h> << 14 #include <linux/spinlock.h> 26 #include <linux/spinlock.h> 15 #include <linux/rtmutex.h> 27 #include <linux/rtmutex.h> 16 #include <linux/threads.h> 28 #include <linux/threads.h> 17 #include <linux/cpumask.h> 29 #include <linux/cpumask.h> 18 #include <linux/seqlock.h> 30 #include <linux/seqlock.h> 19 #include <linux/swait.h> 31 #include <linux/swait.h> >> 32 #include <linux/stop_machine.h> 20 #include <linux/rcu_node_tree.h> 33 #include <linux/rcu_node_tree.h> 21 34 22 #include "rcu_segcblist.h" 35 #include "rcu_segcblist.h" 23 36 24 /* Communicate arguments to a kthread worker h !! 37 /* Communicate arguments to a workqueue handler. */ 25 struct rcu_exp_work { 38 struct rcu_exp_work { >> 39 smp_call_func_t rew_func; 26 unsigned long rew_s; 40 unsigned long rew_s; 27 struct kthread_work rew_work; !! 41 struct work_struct rew_work; 28 }; 42 }; 29 43 30 /* RCU's kthread states for tracing. */ 44 /* RCU's kthread states for tracing. */ 31 #define RCU_KTHREAD_STOPPED 0 45 #define RCU_KTHREAD_STOPPED 0 32 #define RCU_KTHREAD_RUNNING 1 46 #define RCU_KTHREAD_RUNNING 1 33 #define RCU_KTHREAD_WAITING 2 47 #define RCU_KTHREAD_WAITING 2 34 #define RCU_KTHREAD_OFFCPU 3 48 #define RCU_KTHREAD_OFFCPU 3 35 #define RCU_KTHREAD_YIELDING 4 49 #define RCU_KTHREAD_YIELDING 4 36 #define RCU_KTHREAD_MAX 4 50 #define RCU_KTHREAD_MAX 4 37 51 38 /* 52 /* 39 * Definition for node within the RCU grace-pe 53 * Definition for node within the RCU grace-period-detection hierarchy. 40 */ 54 */ 41 struct rcu_node { 55 struct rcu_node { 42 raw_spinlock_t __private lock; /* Roo 56 raw_spinlock_t __private lock; /* Root rcu_node's lock protects */ 43 /* so 57 /* some rcu_state fields as well as */ 44 /* fo 58 /* following. */ 45 unsigned long gp_seq; /* Track rsp-> !! 59 unsigned long gp_seq; /* Track rsp->rcu_gp_seq. */ 46 unsigned long gp_seq_needed; /* Track !! 60 unsigned long gp_seq_needed; /* Track rsp->rcu_gp_seq_needed. */ 47 unsigned long completedqs; /* All QSes 61 unsigned long completedqs; /* All QSes done for this node. */ 48 unsigned long qsmask; /* CPUs or gro 62 unsigned long qsmask; /* CPUs or groups that need to switch in */ 49 /* order for 63 /* order for current grace period to proceed.*/ 50 /* In leaf rc 64 /* In leaf rcu_node, each bit corresponds to */ 51 /* an rcu_dat 65 /* an rcu_data structure, otherwise, each */ 52 /* bit corres 66 /* bit corresponds to a child rcu_node */ 53 /* structure. 67 /* structure. */ 54 unsigned long rcu_gp_init_mask; /* Mas 68 unsigned long rcu_gp_init_mask; /* Mask of offline CPUs at GP init. */ 55 unsigned long qsmaskinit; 69 unsigned long qsmaskinit; 56 /* Per-GP init 70 /* Per-GP initial value for qsmask. */ 57 /* Initialize 71 /* Initialized from ->qsmaskinitnext at the */ 58 /* beginning 72 /* beginning of each grace period. */ 59 unsigned long qsmaskinitnext; 73 unsigned long qsmaskinitnext; >> 74 /* Online CPUs for next grace period. */ 60 unsigned long expmask; /* CPUs or gro 75 unsigned long expmask; /* CPUs or groups that need to check in */ 61 /* to allow t 76 /* to allow the current expedited GP */ 62 /* to complet 77 /* to complete. */ 63 unsigned long expmaskinit; 78 unsigned long expmaskinit; 64 /* Per-GP init 79 /* Per-GP initial values for expmask. */ 65 /* Initialize 80 /* Initialized from ->expmaskinitnext at the */ 66 /* beginning 81 /* beginning of each expedited GP. */ 67 unsigned long expmaskinitnext; 82 unsigned long expmaskinitnext; 68 /* Online CPUs 83 /* Online CPUs for next expedited GP. */ 69 /* Any CPU th 84 /* Any CPU that has ever been online will */ 70 /* have its b 85 /* have its bit set. */ 71 struct kthread_worker *exp_kworker; << 72 /* Workers per << 73 /* initializat << 74 unsigned long cbovldmask; << 75 /* CPUs experi << 76 unsigned long ffmask; /* Fully funct 86 unsigned long ffmask; /* Fully functional CPUs. */ 77 unsigned long grpmask; /* Mask to app 87 unsigned long grpmask; /* Mask to apply to parent qsmask. */ 78 /* Only one b 88 /* Only one bit will be set in this mask. */ 79 int grplo; /* lowest-numb !! 89 int grplo; /* lowest-numbered CPU or group here. */ 80 int grphi; /* highest-num !! 90 int grphi; /* highest-numbered CPU or group here. */ 81 u8 grpnum; /* group numbe !! 91 u8 grpnum; /* CPU/group number for next level up. */ 82 u8 level; /* root is at 92 u8 level; /* root is at level 0. */ 83 bool wait_blkd_tasks;/* Necessary t 93 bool wait_blkd_tasks;/* Necessary to wait for blocked tasks to */ 84 /* exit RCU r 94 /* exit RCU read-side critical sections */ 85 /* before pro 95 /* before propagating offline up the */ 86 /* rcu_node t 96 /* rcu_node tree? */ 87 struct rcu_node *parent; 97 struct rcu_node *parent; 88 struct list_head blkd_tasks; 98 struct list_head blkd_tasks; 89 /* Tasks block 99 /* Tasks blocked in RCU read-side critical */ 90 /* section. 100 /* section. Tasks are placed at the head */ 91 /* of this li 101 /* of this list and age towards the tail. */ 92 struct list_head *gp_tasks; 102 struct list_head *gp_tasks; 93 /* Pointer to 103 /* Pointer to the first task blocking the */ 94 /* current gr 104 /* current grace period, or NULL if there */ 95 /* is no such 105 /* is no such task. */ 96 struct list_head *exp_tasks; 106 struct list_head *exp_tasks; 97 /* Pointer to 107 /* Pointer to the first task blocking the */ 98 /* current ex 108 /* current expedited grace period, or NULL */ 99 /* if there i 109 /* if there is no such task. If there */ 100 /* is no curr 110 /* is no current expedited grace period, */ 101 /* then there 111 /* then there can cannot be any such task. */ 102 struct list_head *boost_tasks; 112 struct list_head *boost_tasks; 103 /* Pointer to 113 /* Pointer to first task that needs to be */ 104 /* priority b 114 /* priority boosted, or NULL if no priority */ 105 /* boosting i 115 /* boosting is needed for this rcu_node */ 106 /* structure. 116 /* structure. If there are no tasks */ 107 /* queued on 117 /* queued on this rcu_node structure that */ 108 /* are blocki 118 /* are blocking the current grace period, */ 109 /* there can 119 /* there can be no such task. */ 110 struct rt_mutex boost_mtx; 120 struct rt_mutex boost_mtx; 111 /* Used only f 121 /* Used only for the priority-boosting */ 112 /* side effec 122 /* side effect, not as a lock. */ 113 unsigned long boost_time; 123 unsigned long boost_time; 114 /* When to sta 124 /* When to start boosting (jiffies). */ 115 struct mutex kthread_mutex; << 116 /* Exclusion f << 117 /* manipulati << 118 struct task_struct *boost_kthread_task 125 struct task_struct *boost_kthread_task; 119 /* kthread tha 126 /* kthread that takes care of priority */ 120 /* boosting f 127 /* boosting for this rcu_node structure. */ 121 unsigned int boost_kthread_status; 128 unsigned int boost_kthread_status; 122 /* State of bo 129 /* State of boost_kthread_task for tracing. */ 123 unsigned long n_boosts; /* Number of b << 124 #ifdef CONFIG_RCU_NOCB_CPU 130 #ifdef CONFIG_RCU_NOCB_CPU 125 struct swait_queue_head nocb_gp_wq[2]; 131 struct swait_queue_head nocb_gp_wq[2]; 126 /* Place for r 132 /* Place for rcu_nocb_kthread() to wait GP. */ 127 #endif /* #ifdef CONFIG_RCU_NOCB_CPU */ 133 #endif /* #ifdef CONFIG_RCU_NOCB_CPU */ 128 raw_spinlock_t fqslock ____cacheline_i 134 raw_spinlock_t fqslock ____cacheline_internodealigned_in_smp; 129 135 130 spinlock_t exp_lock ____cacheline_inte 136 spinlock_t exp_lock ____cacheline_internodealigned_in_smp; 131 unsigned long exp_seq_rq; 137 unsigned long exp_seq_rq; 132 wait_queue_head_t exp_wq[4]; 138 wait_queue_head_t exp_wq[4]; 133 struct rcu_exp_work rew; 139 struct rcu_exp_work rew; 134 bool exp_need_flush; /* Need to flu 140 bool exp_need_flush; /* Need to flush workitem? */ 135 raw_spinlock_t exp_poll_lock; << 136 /* Lock and da << 137 unsigned long exp_seq_poll_rq; << 138 struct work_struct exp_poll_wq; << 139 } ____cacheline_internodealigned_in_smp; 141 } ____cacheline_internodealigned_in_smp; 140 142 141 /* 143 /* 142 * Bitmasks in an rcu_node cover the interval 144 * Bitmasks in an rcu_node cover the interval [grplo, grphi] of CPU IDs, and 143 * are indexed relative to this interval rathe 145 * are indexed relative to this interval rather than the global CPU ID space. 144 * This generates the bit for a CPU in node-lo 146 * This generates the bit for a CPU in node-local masks. 145 */ 147 */ 146 #define leaf_node_cpu_bit(rnp, cpu) (BIT((cpu) 148 #define leaf_node_cpu_bit(rnp, cpu) (BIT((cpu) - (rnp)->grplo)) 147 149 148 /* 150 /* 149 * Union to allow "aggregate OR" operation on 151 * Union to allow "aggregate OR" operation on the need for a quiescent 150 * state by the normal and expedited grace per 152 * state by the normal and expedited grace periods. 151 */ 153 */ 152 union rcu_noqs { 154 union rcu_noqs { 153 struct { 155 struct { 154 u8 norm; 156 u8 norm; 155 u8 exp; 157 u8 exp; 156 } b; /* Bits. */ 158 } b; /* Bits. */ 157 u16 s; /* Set of bits, aggregate OR he 159 u16 s; /* Set of bits, aggregate OR here. */ 158 }; 160 }; 159 161 160 /* << 161 * Record the snapshot of the core stats at ha << 162 * The member gp_seq is used to ensure that al << 163 * during the sampling period. The snapshot is << 164 * equal to rdp->gp_seq. << 165 */ << 166 struct rcu_snap_record { << 167 unsigned long gp_seq; /* Tra << 168 u64 cputime_irq; /* Acc << 169 u64 cputime_softirq;/* Acc << 170 u64 cputime_system; /* Acc << 171 unsigned long nr_hardirqs; /* Acc << 172 unsigned int nr_softirqs; /* Acc << 173 unsigned long long nr_csw; /* Acc << 174 unsigned long jiffies; /* Tra << 175 }; << 176 << 177 /* Per-CPU data for read-copy update. */ 162 /* Per-CPU data for read-copy update. */ 178 struct rcu_data { 163 struct rcu_data { 179 /* 1) quiescent-state and grace-period 164 /* 1) quiescent-state and grace-period handling : */ 180 unsigned long gp_seq; /* Tra !! 165 unsigned long gp_seq; /* Track rsp->rcu_gp_seq counter. */ 181 unsigned long gp_seq_needed; /* Tra !! 166 unsigned long gp_seq_needed; /* Track rsp->rcu_gp_seq_needed ctr. */ 182 union rcu_noqs cpu_no_qs; /* No 167 union rcu_noqs cpu_no_qs; /* No QSes yet for this CPU. */ 183 bool core_needs_qs; /* Cor !! 168 bool core_needs_qs; /* Core waits for quiesc state. */ 184 bool beenonline; /* CPU 169 bool beenonline; /* CPU online at least once. */ 185 bool gpwrap; /* Pos 170 bool gpwrap; /* Possible ->gp_seq wrap. */ 186 bool cpu_started; /* RCU !! 171 bool deferred_qs; /* This CPU awaiting a deferred QS? */ 187 struct rcu_node *mynode; /* Thi 172 struct rcu_node *mynode; /* This CPU's leaf of hierarchy */ 188 unsigned long grpmask; /* Mas 173 unsigned long grpmask; /* Mask to apply to leaf qsmask. */ 189 unsigned long ticks_this_gp; /* The 174 unsigned long ticks_this_gp; /* The number of scheduling-clock */ 190 /* ti 175 /* ticks this CPU has handled */ 191 /* du 176 /* during and after the last grace */ 192 /* per 177 /* period it is aware of. */ 193 struct irq_work defer_qs_iw; /* Obt << 194 bool defer_qs_iw_pending; /* Sch << 195 struct work_struct strict_work; /* Sch << 196 178 197 /* 2) batch handling */ 179 /* 2) batch handling */ 198 struct rcu_segcblist cblist; /* Seg 180 struct rcu_segcblist cblist; /* Segmented callback list, with */ 199 /* dif 181 /* different callbacks waiting for */ 200 /* dif 182 /* different grace periods. */ 201 long qlen_last_fqs_check; 183 long qlen_last_fqs_check; 202 /* qle 184 /* qlen at last check for QS forcing */ 203 unsigned long n_cbs_invoked; /* # c << 204 unsigned long n_force_qs_snap; 185 unsigned long n_force_qs_snap; 205 /* did 186 /* did other CPU force QS recently? */ 206 long blimit; /* Upp 187 long blimit; /* Upper limit on a processed batch */ 207 188 208 /* 3) dynticks interface. */ 189 /* 3) dynticks interface. */ 209 int watching_snap; /* Per !! 190 int dynticks_snap; /* Per-GP tracking for dynticks. */ >> 191 long dynticks_nesting; /* Track process nesting level. */ >> 192 long dynticks_nmi_nesting; /* Track irq/NMI nesting level. */ >> 193 atomic_t dynticks; /* Even value for idle, else odd. */ 210 bool rcu_need_heavy_qs; /* GP 194 bool rcu_need_heavy_qs; /* GP old, so heavy quiescent state! */ 211 bool rcu_urgent_qs; /* GP 195 bool rcu_urgent_qs; /* GP old need light quiescent state. */ 212 bool rcu_forced_tick; /* For !! 196 #ifdef CONFIG_RCU_FAST_NO_HZ 213 bool rcu_forced_tick_exp; /* . !! 197 bool all_lazy; /* Are all CPU's CBs lazy? */ >> 198 unsigned long nonlazy_posted; /* # times non-lazy CB posted to CPU. */ >> 199 unsigned long nonlazy_posted_snap; >> 200 /* Nonlazy_posted snapshot. */ >> 201 unsigned long last_accelerate; /* Last jiffy CBs were accelerated. */ >> 202 unsigned long last_advance_all; /* Last jiffy CBs were all advanced. */ >> 203 int tick_nohz_enabled_snap; /* Previously seen value from sysfs. */ >> 204 #endif /* #ifdef CONFIG_RCU_FAST_NO_HZ */ 214 205 215 /* 4) rcu_barrier(), OOM callbacks, an 206 /* 4) rcu_barrier(), OOM callbacks, and expediting. */ 216 unsigned long barrier_seq_snap; /* Sna << 217 struct rcu_head barrier_head; 207 struct rcu_head barrier_head; 218 int exp_watching_snap; /* Dou !! 208 int exp_dynticks_snap; /* Double-check need for IPI. */ 219 209 220 /* 5) Callback offloading. */ 210 /* 5) Callback offloading. */ 221 #ifdef CONFIG_RCU_NOCB_CPU 211 #ifdef CONFIG_RCU_NOCB_CPU 222 struct swait_queue_head nocb_cb_wq; /* !! 212 struct rcu_head *nocb_head; /* CBs waiting for kthread. */ 223 struct swait_queue_head nocb_state_wq; !! 213 struct rcu_head **nocb_tail; 224 struct task_struct *nocb_gp_kthread; !! 214 atomic_long_t nocb_q_count; /* # CBs waiting for nocb */ >> 215 atomic_long_t nocb_q_count_lazy; /* invocation (all stages). */ >> 216 struct rcu_head *nocb_follower_head; /* CBs ready to invoke. */ >> 217 struct rcu_head **nocb_follower_tail; >> 218 struct swait_queue_head nocb_wq; /* For nocb kthreads to sleep on. */ >> 219 struct task_struct *nocb_kthread; 225 raw_spinlock_t nocb_lock; /* Gua 220 raw_spinlock_t nocb_lock; /* Guard following pair of fields. */ 226 int nocb_defer_wakeup; /* Def 221 int nocb_defer_wakeup; /* Defer wakeup of nocb_kthread. */ 227 struct timer_list nocb_timer; /* Enf 222 struct timer_list nocb_timer; /* Enforce finite deferral. */ 228 unsigned long nocb_gp_adv_time; /* Las << 229 struct mutex nocb_gp_kthread_mutex; /* << 230 /* << 231 << 232 /* The following fields are used by ca << 233 raw_spinlock_t nocb_bypass_lock ____ca << 234 struct rcu_cblist nocb_bypass; /* Loc << 235 unsigned long nocb_bypass_first; /* Ti << 236 unsigned long nocb_nobypass_last; /* L << 237 int nocb_nobypass_count; /* # - << 238 << 239 /* The following fields are used by GP << 240 raw_spinlock_t nocb_gp_lock ____cachel << 241 u8 nocb_gp_sleep; /* Is << 242 u8 nocb_gp_bypass; /* Fou << 243 u8 nocb_gp_gp; /* GP << 244 unsigned long nocb_gp_seq; /* If << 245 unsigned long nocb_gp_loops; /* # p << 246 struct swait_queue_head nocb_gp_wq; /* << 247 bool nocb_cb_sleep; /* Is << 248 struct task_struct *nocb_cb_kthread; << 249 struct list_head nocb_head_rdp; /* << 250 * Hea << 251 * if << 252 */ << 253 struct list_head nocb_entry_rdp; /* rc << 254 struct rcu_data *nocb_toggling_rdp; /* << 255 << 256 /* The following fields are used by CB << 257 struct rcu_data *nocb_gp_rdp ____cache << 258 /* GP << 259 #endif /* #ifdef CONFIG_RCU_NOCB_CPU */ << 260 223 261 /* 6) RCU priority boosting. */ !! 224 /* The following fields are used by the leader, hence own cacheline. */ 262 struct task_struct *rcu_cpu_kthread_ta !! 225 struct rcu_head *nocb_gp_head ____cacheline_internodealigned_in_smp; 263 /* rcu !! 226 /* CBs waiting for GP. */ 264 unsigned int rcu_cpu_kthread_status; !! 227 struct rcu_head **nocb_gp_tail; 265 char rcu_cpu_has_work; !! 228 bool nocb_leader_sleep; /* Is the nocb leader thread asleep? */ 266 unsigned long rcuc_activity; !! 229 struct rcu_data *nocb_next_follower; >> 230 /* Next follower in wakeup chain. */ >> 231 >> 232 /* The following fields are used by the follower, hence new cachline. */ >> 233 struct rcu_data *nocb_leader ____cacheline_internodealigned_in_smp; >> 234 /* Leader CPU takes GP-end wakeups. */ >> 235 #endif /* #ifdef CONFIG_RCU_NOCB_CPU */ 267 236 268 /* 7) Diagnostic data, including RCU C !! 237 /* 6) Diagnostic data, including RCU CPU stall warnings. */ 269 unsigned int softirq_snap; /* Sna 238 unsigned int softirq_snap; /* Snapshot of softirq activity. */ 270 /* ->rcu_iw* fields protected by leaf 239 /* ->rcu_iw* fields protected by leaf rcu_node ->lock. */ 271 struct irq_work rcu_iw; /* Che 240 struct irq_work rcu_iw; /* Check for non-irq activity. */ 272 bool rcu_iw_pending; /* Is 241 bool rcu_iw_pending; /* Is ->rcu_iw pending? */ 273 unsigned long rcu_iw_gp_seq; /* ->g 242 unsigned long rcu_iw_gp_seq; /* ->gp_seq associated with ->rcu_iw. */ 274 unsigned long rcu_ofl_gp_seq; /* ->g 243 unsigned long rcu_ofl_gp_seq; /* ->gp_seq at last offline. */ 275 short rcu_ofl_gp_state; /* ->g !! 244 short rcu_ofl_gp_flags; /* ->gp_flags at last offline. */ 276 unsigned long rcu_onl_gp_seq; /* ->g 245 unsigned long rcu_onl_gp_seq; /* ->gp_seq at last online. */ 277 short rcu_onl_gp_state; /* ->g !! 246 short rcu_onl_gp_flags; /* ->gp_flags at last online. */ 278 unsigned long last_fqs_resched; /* Tim 247 unsigned long last_fqs_resched; /* Time of last rcu_resched(). */ 279 unsigned long last_sched_clock; /* Jif << 280 struct rcu_snap_record snap_record; /* << 281 /* << 282 248 283 long lazy_len; /* Len << 284 int cpu; 249 int cpu; 285 }; 250 }; 286 251 287 /* Values for nocb_defer_wakeup field in struc 252 /* Values for nocb_defer_wakeup field in struct rcu_data. */ 288 #define RCU_NOCB_WAKE_NOT 0 253 #define RCU_NOCB_WAKE_NOT 0 289 #define RCU_NOCB_WAKE_BYPASS 1 !! 254 #define RCU_NOCB_WAKE 1 290 #define RCU_NOCB_WAKE_LAZY 2 !! 255 #define RCU_NOCB_WAKE_FORCE 2 291 #define RCU_NOCB_WAKE 3 << 292 #define RCU_NOCB_WAKE_FORCE 4 << 293 256 294 #define RCU_JIFFIES_TILL_FORCE_QS (1 + (HZ > 2 257 #define RCU_JIFFIES_TILL_FORCE_QS (1 + (HZ > 250) + (HZ > 500)) 295 /* For 258 /* For jiffies_till_first_fqs and */ 296 /* an 259 /* and jiffies_till_next_fqs. */ 297 260 298 #define RCU_JIFFIES_FQS_DIV 256 /* Ver 261 #define RCU_JIFFIES_FQS_DIV 256 /* Very large systems need more */ 299 /* de 262 /* delay between bouts of */ 300 /* qu 263 /* quiescent-state forcing. */ 301 264 302 #define RCU_STALL_RAT_DELAY 2 /* All 265 #define RCU_STALL_RAT_DELAY 2 /* Allow other CPUs time to take */ 303 /* at 266 /* at least one scheduling clock */ 304 /* ir 267 /* irq before ratting on them. */ 305 268 306 #define rcu_wait(cond) 269 #define rcu_wait(cond) \ 307 do { 270 do { \ 308 for (;;) { 271 for (;;) { \ 309 set_current_state(TASK_INTERRU 272 set_current_state(TASK_INTERRUPTIBLE); \ 310 if (cond) 273 if (cond) \ 311 break; 274 break; \ 312 schedule(); 275 schedule(); \ 313 } 276 } \ 314 __set_current_state(TASK_RUNNING); 277 __set_current_state(TASK_RUNNING); \ 315 } while (0) 278 } while (0) 316 279 317 /* 280 /* 318 * A max threshold for synchronize_rcu() users << 319 * awaken directly by the rcu_gp_kthread(). Le << 320 * deferred to the main worker. << 321 */ << 322 #define SR_MAX_USERS_WAKE_FROM_GP 5 << 323 #define SR_NORMAL_GP_WAIT_HEAD_MAX 5 << 324 << 325 struct sr_wait_node { << 326 atomic_t inuse; << 327 struct llist_node node; << 328 }; << 329 << 330 /* << 331 * RCU global state, including node hierarchy. 281 * RCU global state, including node hierarchy. This hierarchy is 332 * represented in "heap" form in a dense array 282 * represented in "heap" form in a dense array. The root (first level) 333 * of the hierarchy is in ->node[0] (reference 283 * of the hierarchy is in ->node[0] (referenced by ->level[0]), the second 334 * level in ->node[1] through ->node[m] (->nod 284 * level in ->node[1] through ->node[m] (->node[1] referenced by ->level[1]), 335 * and the third level in ->node[m+1] and foll 285 * and the third level in ->node[m+1] and following (->node[m+1] referenced 336 * by ->level[2]). The number of levels is de 286 * by ->level[2]). The number of levels is determined by the number of 337 * CPUs and by CONFIG_RCU_FANOUT. Small syste 287 * CPUs and by CONFIG_RCU_FANOUT. Small systems will have a "hierarchy" 338 * consisting of a single rcu_node. 288 * consisting of a single rcu_node. 339 */ 289 */ 340 struct rcu_state { 290 struct rcu_state { 341 struct rcu_node node[NUM_RCU_NODES]; 291 struct rcu_node node[NUM_RCU_NODES]; /* Hierarchy. */ 342 struct rcu_node *level[RCU_NUM_LVLS + 292 struct rcu_node *level[RCU_NUM_LVLS + 1]; 343 293 /* Hierarchy levels (+1 to */ 344 294 /* shut bogus gcc warning) */ 345 int ncpus; 295 int ncpus; /* # CPUs seen so far. */ 346 int n_online_cpus; << 347 296 348 /* The following fields are guarded by 297 /* The following fields are guarded by the root rcu_node's lock. */ 349 298 350 unsigned long gp_seq ____cacheline_int !! 299 u8 boost ____cacheline_internodealigned_in_smp; 351 !! 300 /* Subject to priority boost. */ 352 unsigned long gp_max; !! 301 unsigned long gp_seq; /* Grace-period sequence #. */ 353 << 354 struct task_struct *gp_kthread; 302 struct task_struct *gp_kthread; /* Task for grace periods. */ 355 struct swait_queue_head gp_wq; 303 struct swait_queue_head gp_wq; /* Where GP task waits. */ 356 short gp_flags; 304 short gp_flags; /* Commands for GP task. */ 357 short gp_state; 305 short gp_state; /* GP kthread sleep state. */ 358 unsigned long gp_wake_time; << 359 unsigned long gp_wake_seq; << 360 unsigned long gp_seq_polled; << 361 unsigned long gp_seq_polled_snap; << 362 unsigned long gp_seq_polled_exp_snap; << 363 306 364 /* End of fields guarded by root rcu_n 307 /* End of fields guarded by root rcu_node's lock. */ 365 308 366 struct mutex barrier_mutex; 309 struct mutex barrier_mutex; /* Guards barrier fields. */ 367 atomic_t barrier_cpu_count; 310 atomic_t barrier_cpu_count; /* # CPUs waiting on. */ 368 struct completion barrier_completion; 311 struct completion barrier_completion; /* Wake at barrier end. */ 369 unsigned long barrier_sequence; 312 unsigned long barrier_sequence; /* ++ at start and end of */ 370 313 /* rcu_barrier(). */ 371 /* End of fields guarded by barrier_mu 314 /* End of fields guarded by barrier_mutex. */ 372 315 373 raw_spinlock_t barrier_lock; << 374 << 375 struct mutex exp_mutex; 316 struct mutex exp_mutex; /* Serialize expedited GP. */ 376 struct mutex exp_wake_mutex; 317 struct mutex exp_wake_mutex; /* Serialize wakeup. */ 377 unsigned long expedited_sequence; 318 unsigned long expedited_sequence; /* Take a ticket. */ 378 atomic_t expedited_need_qs; 319 atomic_t expedited_need_qs; /* # CPUs left to check in. */ 379 struct swait_queue_head expedited_wq; 320 struct swait_queue_head expedited_wq; /* Wait for check-ins. */ 380 int ncpus_snap; 321 int ncpus_snap; /* # CPUs seen last time. */ 381 u8 cbovld; << 382 u8 cbovldnext; << 383 322 384 unsigned long jiffies_force_qs; 323 unsigned long jiffies_force_qs; /* Time at which to invoke */ 385 324 /* force_quiescent_state(). */ 386 unsigned long jiffies_kick_kthreads; 325 unsigned long jiffies_kick_kthreads; /* Time at which to kick */ 387 326 /* kthreads, if configured. */ 388 unsigned long n_force_qs; 327 unsigned long n_force_qs; /* Number of calls to */ 389 328 /* force_quiescent_state(). */ 390 unsigned long gp_start; 329 unsigned long gp_start; /* Time at which GP started, */ 391 330 /* but in jiffies. */ 392 unsigned long gp_end; << 393 << 394 unsigned long gp_activity; 331 unsigned long gp_activity; /* Time of last GP kthread */ 395 332 /* activity in jiffies. */ 396 unsigned long gp_req_activity; 333 unsigned long gp_req_activity; /* Time of last GP request */ 397 334 /* in jiffies. */ 398 unsigned long jiffies_stall; 335 unsigned long jiffies_stall; /* Time at which to check */ 399 336 /* for CPU stalls. */ 400 int nr_fqs_jiffies_stall; << 401 << 402 << 403 << 404 unsigned long jiffies_resched; 337 unsigned long jiffies_resched; /* Time at which to resched */ 405 338 /* a reluctant CPU. */ 406 unsigned long n_force_qs_gpstart; 339 unsigned long n_force_qs_gpstart; /* Snapshot of n_force_qs at */ 407 340 /* GP start. */ >> 341 unsigned long gp_max; /* Maximum GP duration in */ >> 342 /* jiffies. */ 408 const char *name; 343 const char *name; /* Name of structure. */ 409 char abbr; 344 char abbr; /* Abbreviated name. */ 410 345 411 arch_spinlock_t ofl_lock ____cacheline !! 346 raw_spinlock_t ofl_lock ____cacheline_internodealigned_in_smp; 412 347 /* Synchronize offline with */ 413 348 /* GP pre-initialization. */ 414 << 415 /* synchronize_rcu() part. */ << 416 struct llist_head srs_next; /* req << 417 struct llist_node *srs_wait_tail; /* w << 418 struct llist_node *srs_done_tail; /* r << 419 struct sr_wait_node srs_wait_nodes[SR_ << 420 struct work_struct srs_cleanup_work; << 421 atomic_t srs_cleanups_pending; /* srs << 422 << 423 #ifdef CONFIG_RCU_NOCB_CPU << 424 struct mutex nocb_mutex; << 425 int nocb_is_setup; << 426 #endif << 427 }; 349 }; 428 350 429 /* Values for rcu_state structure's gp_flags f 351 /* Values for rcu_state structure's gp_flags field. */ 430 #define RCU_GP_FLAG_INIT 0x1 /* Need grace- 352 #define RCU_GP_FLAG_INIT 0x1 /* Need grace-period initialization. */ 431 #define RCU_GP_FLAG_FQS 0x2 /* Need grace- 353 #define RCU_GP_FLAG_FQS 0x2 /* Need grace-period quiescent-state forcing. */ 432 #define RCU_GP_FLAG_OVLD 0x4 /* Experiencin << 433 354 434 /* Values for rcu_state structure's gp_state f 355 /* Values for rcu_state structure's gp_state field. */ 435 #define RCU_GP_IDLE 0 /* Initial sta 356 #define RCU_GP_IDLE 0 /* Initial state and no GP in progress. */ 436 #define RCU_GP_WAIT_GPS 1 /* Wait for gr 357 #define RCU_GP_WAIT_GPS 1 /* Wait for grace-period start. */ 437 #define RCU_GP_DONE_GPS 2 /* Wait done f 358 #define RCU_GP_DONE_GPS 2 /* Wait done for grace-period start. */ 438 #define RCU_GP_ONOFF 3 /* Grace-perio 359 #define RCU_GP_ONOFF 3 /* Grace-period initialization hotplug. */ 439 #define RCU_GP_INIT 4 /* Grace-perio 360 #define RCU_GP_INIT 4 /* Grace-period initialization. */ 440 #define RCU_GP_WAIT_FQS 5 /* Wait for fo 361 #define RCU_GP_WAIT_FQS 5 /* Wait for force-quiescent-state time. */ 441 #define RCU_GP_DOING_FQS 6 /* Wait done f 362 #define RCU_GP_DOING_FQS 6 /* Wait done for force-quiescent-state time. */ 442 #define RCU_GP_CLEANUP 7 /* Grace-perio 363 #define RCU_GP_CLEANUP 7 /* Grace-period cleanup started. */ 443 #define RCU_GP_CLEANED 8 /* Grace-perio 364 #define RCU_GP_CLEANED 8 /* Grace-period cleanup complete. */ 444 365 >> 366 static const char * const gp_state_names[] = { >> 367 "RCU_GP_IDLE", >> 368 "RCU_GP_WAIT_GPS", >> 369 "RCU_GP_DONE_GPS", >> 370 "RCU_GP_ONOFF", >> 371 "RCU_GP_INIT", >> 372 "RCU_GP_WAIT_FQS", >> 373 "RCU_GP_DOING_FQS", >> 374 "RCU_GP_CLEANUP", >> 375 "RCU_GP_CLEANED", >> 376 }; >> 377 445 /* 378 /* 446 * In order to export the rcu_state name to th 379 * In order to export the rcu_state name to the tracing tools, it 447 * needs to be added in the __tracepoint_strin 380 * needs to be added in the __tracepoint_string section. 448 * This requires defining a separate variable 381 * This requires defining a separate variable tp_<sname>_varname 449 * that points to the string being used, and t 382 * that points to the string being used, and this will allow 450 * the tracing userspace tools to be able to d 383 * the tracing userspace tools to be able to decipher the string 451 * address to the matching string. 384 * address to the matching string. 452 */ 385 */ 453 #ifdef CONFIG_PREEMPT_RCU 386 #ifdef CONFIG_PREEMPT_RCU 454 #define RCU_ABBR 'p' 387 #define RCU_ABBR 'p' 455 #define RCU_NAME_RAW "rcu_preempt" 388 #define RCU_NAME_RAW "rcu_preempt" 456 #else /* #ifdef CONFIG_PREEMPT_RCU */ 389 #else /* #ifdef CONFIG_PREEMPT_RCU */ 457 #define RCU_ABBR 's' 390 #define RCU_ABBR 's' 458 #define RCU_NAME_RAW "rcu_sched" 391 #define RCU_NAME_RAW "rcu_sched" 459 #endif /* #else #ifdef CONFIG_PREEMPT_RCU */ 392 #endif /* #else #ifdef CONFIG_PREEMPT_RCU */ 460 #ifndef CONFIG_TRACING 393 #ifndef CONFIG_TRACING 461 #define RCU_NAME RCU_NAME_RAW 394 #define RCU_NAME RCU_NAME_RAW 462 #else /* #ifdef CONFIG_TRACING */ 395 #else /* #ifdef CONFIG_TRACING */ 463 static char rcu_name[] = RCU_NAME_RAW; 396 static char rcu_name[] = RCU_NAME_RAW; 464 static const char *tp_rcu_varname __used __tra 397 static const char *tp_rcu_varname __used __tracepoint_string = rcu_name; 465 #define RCU_NAME rcu_name 398 #define RCU_NAME rcu_name 466 #endif /* #else #ifdef CONFIG_TRACING */ 399 #endif /* #else #ifdef CONFIG_TRACING */ 467 400 468 /* Forward declarations for tree_plugin.h */ !! 401 /* >> 402 * RCU implementation internal declarations: >> 403 */ >> 404 extern struct rcu_state rcu_sched_state; >> 405 >> 406 extern struct rcu_state rcu_bh_state; >> 407 >> 408 #ifdef CONFIG_PREEMPT_RCU >> 409 extern struct rcu_state rcu_preempt_state; >> 410 #endif /* #ifdef CONFIG_PREEMPT_RCU */ >> 411 >> 412 int rcu_dynticks_snap(struct rcu_data *rdp); >> 413 >> 414 #ifdef CONFIG_RCU_BOOST >> 415 DECLARE_PER_CPU(unsigned int, rcu_cpu_kthread_status); >> 416 DECLARE_PER_CPU(int, rcu_cpu_kthread_cpu); >> 417 DECLARE_PER_CPU(unsigned int, rcu_cpu_kthread_loops); >> 418 DECLARE_PER_CPU(char, rcu_cpu_has_work); >> 419 #endif /* #ifdef CONFIG_RCU_BOOST */ >> 420 >> 421 /* Forward declarations for rcutree_plugin.h */ 469 static void rcu_bootup_announce(void); 422 static void rcu_bootup_announce(void); 470 static void rcu_qs(void); 423 static void rcu_qs(void); 471 static int rcu_preempt_blocked_readers_cgp(str 424 static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp); 472 #ifdef CONFIG_HOTPLUG_CPU 425 #ifdef CONFIG_HOTPLUG_CPU 473 static bool rcu_preempt_has_tasks(struct rcu_n 426 static bool rcu_preempt_has_tasks(struct rcu_node *rnp); 474 #endif /* #ifdef CONFIG_HOTPLUG_CPU */ 427 #endif /* #ifdef CONFIG_HOTPLUG_CPU */ >> 428 static void rcu_print_detail_task_stall(void); >> 429 static int rcu_print_task_stall(struct rcu_node *rnp); 475 static int rcu_print_task_exp_stall(struct rcu 430 static int rcu_print_task_exp_stall(struct rcu_node *rnp); 476 static void rcu_preempt_check_blocked_tasks(st 431 static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp); 477 static void rcu_flavor_sched_clock_irq(int use !! 432 static void rcu_flavor_check_callbacks(int user); >> 433 void call_rcu(struct rcu_head *head, rcu_callback_t func); 478 static void dump_blkd_tasks(struct rcu_node *r 434 static void dump_blkd_tasks(struct rcu_node *rnp, int ncheck); 479 static void rcu_initiate_boost(struct rcu_node 435 static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags); 480 static void rcu_preempt_boost_start_gp(struct 436 static void rcu_preempt_boost_start_gp(struct rcu_node *rnp); 481 static bool rcu_is_callbacks_kthread(struct rc !! 437 static void invoke_rcu_callbacks_kthread(void); 482 static void rcu_cpu_kthread_setup(unsigned int !! 438 static bool rcu_is_callbacks_kthread(void); 483 static void rcu_spawn_one_boost_kthread(struct !! 439 static void __init rcu_spawn_boost_kthreads(void); >> 440 static void rcu_prepare_kthreads(int cpu); >> 441 static void rcu_cleanup_after_idle(void); >> 442 static void rcu_prepare_for_idle(void); >> 443 static void rcu_idle_count_callbacks_posted(void); 484 static bool rcu_preempt_has_tasks(struct rcu_n 444 static bool rcu_preempt_has_tasks(struct rcu_node *rnp); 485 static bool rcu_preempt_need_deferred_qs(struc 445 static bool rcu_preempt_need_deferred_qs(struct task_struct *t); >> 446 static void rcu_preempt_deferred_qs(struct task_struct *t); >> 447 static void print_cpu_stall_info_begin(void); >> 448 static void print_cpu_stall_info(int cpu); >> 449 static void print_cpu_stall_info_end(void); 486 static void zero_cpu_stall_ticks(struct rcu_da 450 static void zero_cpu_stall_ticks(struct rcu_data *rdp); >> 451 static bool rcu_nocb_cpu_needs_barrier(int cpu); 487 static struct swait_queue_head *rcu_nocb_gp_ge 452 static struct swait_queue_head *rcu_nocb_gp_get(struct rcu_node *rnp); 488 static void rcu_nocb_gp_cleanup(struct swait_q 453 static void rcu_nocb_gp_cleanup(struct swait_queue_head *sq); 489 static void rcu_init_one_nocb(struct rcu_node 454 static void rcu_init_one_nocb(struct rcu_node *rnp); 490 static bool wake_nocb_gp(struct rcu_data *rdp, !! 455 static bool __call_rcu_nocb(struct rcu_data *rdp, struct rcu_head *rhp, 491 static bool rcu_nocb_flush_bypass(struct rcu_d !! 456 bool lazy, unsigned long flags); 492 unsigned lon !! 457 static bool rcu_nocb_adopt_orphan_cbs(struct rcu_data *my_rdp, 493 static void call_rcu_nocb(struct rcu_data *rdp !! 458 struct rcu_data *rdp, 494 rcu_callback_t func, !! 459 unsigned long flags); 495 static void __maybe_unused __call_rcu_nocb_wak !! 460 static int rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp); 496 !! 461 static void do_nocb_deferred_wakeup(struct rcu_data *rdp); 497 static int rcu_nocb_need_deferred_wakeup(struc << 498 static bool do_nocb_deferred_wakeup(struct rcu << 499 static void rcu_boot_init_nocb_percpu_data(str 462 static void rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp); 500 static void rcu_spawn_cpu_nocb_kthread(int cpu !! 463 static void rcu_spawn_all_nocb_kthreads(int cpu); 501 static void show_rcu_nocb_state(struct rcu_dat !! 464 static void __init rcu_spawn_nocb_kthreads(void); 502 static void rcu_nocb_lock(struct rcu_data *rdp << 503 static void rcu_nocb_unlock(struct rcu_data *r << 504 static void rcu_nocb_unlock_irqrestore(struct << 505 unsigne << 506 static void rcu_lockdep_assert_cblist_protecte << 507 #ifdef CONFIG_RCU_NOCB_CPU 465 #ifdef CONFIG_RCU_NOCB_CPU 508 static void __init rcu_organize_nocb_kthreads( 466 static void __init rcu_organize_nocb_kthreads(void); 509 !! 467 #endif /* #ifdef CONFIG_RCU_NOCB_CPU */ 510 /* !! 468 static bool init_nocb_callback_list(struct rcu_data *rdp); 511 * Disable IRQs before checking offloaded stat << 512 * locking is safe against concurrent de-offlo << 513 */ << 514 #define rcu_nocb_lock_irqsave(rdp, flags) << 515 do { << 516 local_irq_save(flags); << 517 if (rcu_segcblist_is_offloaded(&(rdp)- << 518 raw_spin_lock(&(rdp)->nocb_loc << 519 } while (0) << 520 #else /* #ifdef CONFIG_RCU_NOCB_CPU */ << 521 #define rcu_nocb_lock_irqsave(rdp, flags) loca << 522 #endif /* #else #ifdef CONFIG_RCU_NOCB_CPU */ << 523 << 524 static void rcu_bind_gp_kthread(void); 469 static void rcu_bind_gp_kthread(void); 525 static bool rcu_nohz_full_cpu(void); 470 static bool rcu_nohz_full_cpu(void); >> 471 static void rcu_dynticks_task_enter(void); >> 472 static void rcu_dynticks_task_exit(void); 526 473 527 /* Forward declarations for tree_stall.h */ !! 474 #ifdef CONFIG_SRCU 528 static void record_gp_stall_check_time(void); !! 475 void srcu_online_cpu(unsigned int cpu); 529 static void rcu_iw_handler(struct irq_work *iw !! 476 void srcu_offline_cpu(unsigned int cpu); 530 static void check_cpu_stall(struct rcu_data *r !! 477 #else /* #ifdef CONFIG_SRCU */ 531 static void rcu_check_gp_start_stall(struct rc !! 478 void srcu_online_cpu(unsigned int cpu) { } 532 const uns !! 479 void srcu_offline_cpu(unsigned int cpu) { } 533 !! 480 #endif /* #else #ifdef CONFIG_SRCU */ 534 /* Forward declarations for tree_exp.h. */ << 535 static void sync_rcu_do_polled_gp(struct work_ << 536 481
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.