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