blob: 44edd0a98ffe042420c0a3ce13f30704294596ef [file] [log] [blame]
Paul E. McKenney22e40922019-01-17 10:23:39 -08001/* SPDX-License-Identifier: GPL-2.0+ */
Paul E. McKenney9f77da92009-08-22 13:56:45 -07002/*
3 * Read-Copy Update mechanism for mutual exclusion (tree-based version)
4 * Internal non-public definitions.
5 *
Paul E. McKenney9f77da92009-08-22 13:56:45 -07006 * Copyright IBM Corporation, 2008
7 *
8 * Author: Ingo Molnar <mingo@elte.hu>
Paul E. McKenney22e40922019-01-17 10:23:39 -08009 * Paul E. McKenney <paulmck@linux.ibm.com>
Paul E. McKenney9f77da92009-08-22 13:56:45 -070010 */
11
12#include <linux/cache.h>
13#include <linux/spinlock.h>
Ingo Molnar037741a2017-02-03 10:08:30 +010014#include <linux/rtmutex.h>
Paul E. McKenney9f77da92009-08-22 13:56:45 -070015#include <linux/threads.h>
16#include <linux/cpumask.h>
17#include <linux/seqlock.h>
Paul Gortmakerabedf8e2016-02-19 09:46:41 +010018#include <linux/swait.h>
Paul E. McKenneyf2425b42017-03-14 12:42:30 -070019#include <linux/rcu_node_tree.h>
Paul E. McKenneyf885b7f2012-04-23 15:52:53 -070020
Ingo Molnar45753c52017-05-02 10:31:18 +020021#include "rcu_segcblist.h"
22
Paul E. McKenney25f3d7e2018-02-01 22:05:38 -080023/* Communicate arguments to a workqueue handler. */
24struct rcu_exp_work {
Paul E. McKenney25f3d7e2018-02-01 22:05:38 -080025 unsigned long rew_s;
26 struct work_struct rew_work;
27};
28
Paul E. McKenneyd71df902011-03-29 17:48:28 -070029/* RCU's kthread states for tracing. */
30#define RCU_KTHREAD_STOPPED 0
31#define RCU_KTHREAD_RUNNING 1
32#define RCU_KTHREAD_WAITING 2
Paul E. McKenney15ba0ba2011-04-06 16:01:16 -070033#define RCU_KTHREAD_OFFCPU 3
34#define RCU_KTHREAD_YIELDING 4
35#define RCU_KTHREAD_MAX 4
Paul E. McKenneyd71df902011-03-29 17:48:28 -070036
Paul E. McKenney9f77da92009-08-22 13:56:45 -070037/*
38 * Definition for node within the RCU grace-period-detection hierarchy.
39 */
40struct rcu_node {
Boqun Feng67c583a72015-12-29 12:18:47 +080041 raw_spinlock_t __private lock; /* Root rcu_node's lock protects */
42 /* some rcu_state fields as well as */
43 /* following. */
Paul E. McKenneyde30ad52018-04-26 11:52:09 -070044 unsigned long gp_seq; /* Track rsp->rcu_gp_seq. */
Joel Fernandes (Google)adbccdd2018-09-22 19:41:26 -040045 unsigned long gp_seq_needed; /* Track furthest future GP request. */
Paul E. McKenney4bc8d552017-11-27 15:13:56 -080046 unsigned long completedqs; /* All QSes done for this node. */
Paul E. McKenney9f77da92009-08-22 13:56:45 -070047 unsigned long qsmask; /* CPUs or groups that need to switch in */
48 /* order for current grace period to proceed.*/
Paul E. McKenney1eba8f82009-09-23 09:50:42 -070049 /* In leaf rcu_node, each bit corresponds to */
50 /* an rcu_data structure, otherwise, each */
51 /* bit corresponds to a child rcu_node */
52 /* structure. */
Paul E. McKenneyf2e2df52018-05-15 16:23:23 -070053 unsigned long rcu_gp_init_mask; /* Mask of offline CPUs at GP init. */
Paul E. McKenney9f77da92009-08-22 13:56:45 -070054 unsigned long qsmaskinit;
Paul E. McKenneyb9585e92015-07-31 16:04:45 -070055 /* Per-GP initial value for qsmask. */
Paul E. McKenney0aa04b02015-01-23 21:52:37 -080056 /* Initialized from ->qsmaskinitnext at the */
57 /* beginning of each grace period. */
58 unsigned long qsmaskinitnext;
59 /* Online CPUs for next grace period. */
Paul E. McKenneyb9585e92015-07-31 16:04:45 -070060 unsigned long expmask; /* CPUs or groups that need to check in */
61 /* to allow the current expedited GP */
62 /* to complete. */
63 unsigned long expmaskinit;
64 /* Per-GP initial values for expmask. */
65 /* Initialized from ->expmaskinitnext at the */
66 /* beginning of each expedited GP. */
67 unsigned long expmaskinitnext;
68 /* Online CPUs for next expedited GP. */
Paul E. McKenney1de6e562015-09-29 09:45:00 -070069 /* Any CPU that has ever been online will */
70 /* have its bit set. */
Paul E. McKenneyb2b00dd2019-10-30 11:56:10 -070071 unsigned long cbovldmask;
72 /* CPUs experiencing callback overload. */
Paul E. McKenney9b9500d2017-08-17 17:05:59 -070073 unsigned long ffmask; /* Fully functional CPUs. */
Paul E. McKenney9f77da92009-08-22 13:56:45 -070074 unsigned long grpmask; /* Mask to apply to parent qsmask. */
Paul E. McKenney1eba8f82009-09-23 09:50:42 -070075 /* Only one bit will be set in this mask. */
Paul E. McKenney9f77da92009-08-22 13:56:45 -070076 int grplo; /* lowest-numbered CPU or group here. */
77 int grphi; /* highest-numbered CPU or group here. */
78 u8 grpnum; /* CPU/group number for next level up. */
79 u8 level; /* root is at level 0. */
Paul E. McKenney0aa04b02015-01-23 21:52:37 -080080 bool wait_blkd_tasks;/* Necessary to wait for blocked tasks to */
81 /* exit RCU read-side critical sections */
82 /* before propagating offline up the */
83 /* rcu_node tree? */
Paul E. McKenney9f77da92009-08-22 13:56:45 -070084 struct rcu_node *parent;
Paul E. McKenney12f5f522010-11-29 21:56:39 -080085 struct list_head blkd_tasks;
86 /* Tasks blocked in RCU read-side critical */
87 /* section. Tasks are placed at the head */
88 /* of this list and age towards the tail. */
89 struct list_head *gp_tasks;
90 /* Pointer to the first task blocking the */
91 /* current grace period, or NULL if there */
92 /* is no such task. */
93 struct list_head *exp_tasks;
94 /* Pointer to the first task blocking the */
95 /* current expedited grace period, or NULL */
96 /* if there is no such task. If there */
97 /* is no current expedited grace period, */
98 /* then there can cannot be any such task. */
Paul E. McKenney27f4d282011-02-07 12:47:15 -080099 struct list_head *boost_tasks;
100 /* Pointer to first task that needs to be */
101 /* priority boosted, or NULL if no priority */
102 /* boosting is needed for this rcu_node */
103 /* structure. If there are no tasks */
104 /* queued on this rcu_node structure that */
105 /* are blocking the current grace period, */
106 /* there can be no such task. */
Paul E. McKenneyabaa93d2014-06-12 13:30:25 -0700107 struct rt_mutex boost_mtx;
108 /* Used only for the priority-boosting */
109 /* side effect, not as a lock. */
Paul E. McKenney27f4d282011-02-07 12:47:15 -0800110 unsigned long boost_time;
111 /* When to start boosting (jiffies). */
112 struct task_struct *boost_kthread_task;
113 /* kthread that takes care of priority */
114 /* boosting for this rcu_node structure. */
Paul E. McKenneyd71df902011-03-29 17:48:28 -0700115 unsigned int boost_kthread_status;
116 /* State of boost_kthread_task for tracing. */
Paul E. McKenneydae6e642013-02-10 20:48:58 -0800117#ifdef CONFIG_RCU_NOCB_CPU
Paul Gortmakerabedf8e2016-02-19 09:46:41 +0100118 struct swait_queue_head nocb_gp_wq[2];
Paul E. McKenneydae6e642013-02-10 20:48:58 -0800119 /* Place for rcu_nocb_kthread() to wait GP. */
Paul E. McKenneydae6e642013-02-10 20:48:58 -0800120#endif /* #ifdef CONFIG_RCU_NOCB_CPU */
Paul E. McKenney394f2762012-06-26 17:00:35 -0700121 raw_spinlock_t fqslock ____cacheline_internodealigned_in_smp;
Paul E. McKenney385b73c2015-06-24 14:20:08 -0700122
Paul E. McKenneyf6a12f32016-01-30 17:57:35 -0800123 spinlock_t exp_lock ____cacheline_internodealigned_in_smp;
124 unsigned long exp_seq_rq;
Paul E. McKenney3b5f6682016-03-16 16:47:55 -0700125 wait_queue_head_t exp_wq[4];
Paul E. McKenney25f3d7e2018-02-01 22:05:38 -0800126 struct rcu_exp_work rew;
127 bool exp_need_flush; /* Need to flush workitem? */
Paul E. McKenney9f77da92009-08-22 13:56:45 -0700128} ____cacheline_internodealigned_in_smp;
129
Paul E. McKenneya0b6c9a2009-09-28 07:46:33 -0700130/*
Mark Rutlandbc75e992016-06-03 15:20:04 +0100131 * Bitmasks in an rcu_node cover the interval [grplo, grphi] of CPU IDs, and
132 * are indexed relative to this interval rather than the global CPU ID space.
133 * This generates the bit for a CPU in node-local masks.
134 */
Paul E. McKenneydf63fa5b2018-07-31 09:49:20 -0700135#define leaf_node_cpu_bit(rnp, cpu) (BIT((cpu) - (rnp)->grplo))
Mark Rutlandbc75e992016-06-03 15:20:04 +0100136
137/*
Paul E. McKenney5b74c452015-08-06 15:16:57 -0700138 * Union to allow "aggregate OR" operation on the need for a quiescent
139 * state by the normal and expedited grace periods.
140 */
141union rcu_noqs {
142 struct {
143 u8 norm;
144 u8 exp;
145 } b; /* Bits. */
146 u16 s; /* Set of bits, aggregate OR here. */
147};
148
Paul E. McKenney9f77da92009-08-22 13:56:45 -0700149/* Per-CPU data for read-copy update. */
150struct rcu_data {
151 /* 1) quiescent-state and grace-period handling : */
Paul E. McKenneyde30ad52018-04-26 11:52:09 -0700152 unsigned long gp_seq; /* Track rsp->rcu_gp_seq counter. */
Joel Fernandes (Google)adbccdd2018-09-22 19:41:26 -0400153 unsigned long gp_seq_needed; /* Track furthest future GP request. */
Paul E. McKenney5b74c452015-08-06 15:16:57 -0700154 union rcu_noqs cpu_no_qs; /* No QSes yet for this CPU. */
Paul E. McKenney97c668b2015-08-06 11:31:51 -0700155 bool core_needs_qs; /* Core waits for quiesc state. */
Paul E. McKenney9f77da92009-08-22 13:56:45 -0700156 bool beenonline; /* CPU online at least once. */
Paul E. McKenneyff3bb6f2018-05-01 14:34:08 -0700157 bool gpwrap; /* Possible ->gp_seq wrap. */
Paul E. McKenney1bb33642019-03-27 15:51:25 -0700158 bool exp_deferred_qs; /* This CPU awaiting a deferred QS? */
Paul E. McKenney9f77da92009-08-22 13:56:45 -0700159 struct rcu_node *mynode; /* This CPU's leaf of hierarchy */
160 unsigned long grpmask; /* Mask to apply to leaf qsmask. */
Paul E. McKenneya858af22012-01-16 13:29:10 -0800161 unsigned long ticks_this_gp; /* The number of scheduling-clock */
162 /* ticks this CPU has handled */
163 /* during and after the last grace */
164 /* period it is aware of. */
Paul E. McKenney0864f052019-04-04 12:19:25 -0700165 struct irq_work defer_qs_iw; /* Obtain later scheduler attention. */
166 bool defer_qs_iw_pending; /* Scheduler attention pending? */
Paul E. McKenney9f77da92009-08-22 13:56:45 -0700167
168 /* 2) batch handling */
Paul E. McKenney15fecf82017-02-08 12:36:42 -0800169 struct rcu_segcblist cblist; /* Segmented callback list, with */
170 /* different callbacks waiting for */
171 /* different grace periods. */
Paul E. McKenney37c72e52009-10-14 10:15:55 -0700172 long qlen_last_fqs_check;
173 /* qlen at last check for QS forcing */
174 unsigned long n_force_qs_snap;
175 /* did other CPU force QS recently? */
Paul E. McKenney9f77da92009-08-22 13:56:45 -0700176 long blimit; /* Upper limit on a processed batch */
177
Paul E. McKenney9f77da92009-08-22 13:56:45 -0700178 /* 3) dynticks interface. */
Paul E. McKenney9f77da92009-08-22 13:56:45 -0700179 int dynticks_snap; /* Per-GP tracking for dynticks. */
Paul E. McKenneydc5a4f22018-08-03 21:00:38 -0700180 long dynticks_nesting; /* Track process nesting level. */
181 long dynticks_nmi_nesting; /* Track irq/NMI nesting level. */
182 atomic_t dynticks; /* Even value for idle, else odd. */
183 bool rcu_need_heavy_qs; /* GP old, so heavy quiescent state! */
184 bool rcu_urgent_qs; /* GP old need light quiescent state. */
Paul E. McKenney66e4c332019-08-12 16:14:00 -0700185 bool rcu_forced_tick; /* Forced tick to provide QS. */
Paul E. McKenneydf1e8492019-11-27 16:36:45 -0800186 bool rcu_forced_tick_exp; /* ... provide QS to expedited GP. */
Paul E. McKenneycc720462018-08-03 19:31:39 -0700187#ifdef CONFIG_RCU_FAST_NO_HZ
Paul E. McKenneydc5a4f22018-08-03 21:00:38 -0700188 unsigned long last_accelerate; /* Last jiffy CBs were accelerated. */
189 unsigned long last_advance_all; /* Last jiffy CBs were all advanced. */
190 int tick_nohz_enabled_snap; /* Previously seen value from sysfs. */
Paul E. McKenneycc720462018-08-03 19:31:39 -0700191#endif /* #ifdef CONFIG_RCU_FAST_NO_HZ */
Paul E. McKenney9f77da92009-08-22 13:56:45 -0700192
Paul E. McKenney8d8a9d02018-08-04 20:32:07 -0700193 /* 4) rcu_barrier(), OOM callbacks, and expediting. */
Paul E. McKenney06668ef2012-05-28 23:57:46 -0700194 struct rcu_head barrier_head;
Paul E. McKenney0742ac32016-10-11 06:09:59 -0700195 int exp_dynticks_snap; /* Double-check need for IPI. */
Paul E. McKenney06668ef2012-05-28 23:57:46 -0700196
Paul E. McKenney8d8a9d02018-08-04 20:32:07 -0700197 /* 5) Callback offloading. */
Paul E. McKenney3fbfbf72012-08-19 21:35:53 -0700198#ifdef CONFIG_RCU_NOCB_CPU
Paul E. McKenney12f54c3a2019-03-29 16:43:51 -0700199 struct swait_queue_head nocb_cb_wq; /* For nocb kthreads to sleep on. */
200 struct task_struct *nocb_gp_kthread;
Paul E. McKenney8be6e1b2017-04-29 20:03:20 -0700201 raw_spinlock_t nocb_lock; /* Guard following pair of fields. */
Paul E. McKenney81c0b3d2019-05-28 07:18:08 -0700202 atomic_t nocb_lock_contended; /* Contention experienced. */
Paul E. McKenney9fdd3bc2014-07-29 14:50:47 -0700203 int nocb_defer_wakeup; /* Defer wakeup of nocb_kthread. */
Paul E. McKenney8be6e1b2017-04-29 20:03:20 -0700204 struct timer_list nocb_timer; /* Enforce finite deferral. */
Paul E. McKenneyd1b222c2019-07-02 16:03:33 -0700205 unsigned long nocb_gp_adv_time; /* Last call_rcu() CB adv (jiffies). */
206
207 /* The following fields are used by call_rcu, hence own cacheline. */
208 raw_spinlock_t nocb_bypass_lock ____cacheline_internodealigned_in_smp;
209 struct rcu_cblist nocb_bypass; /* Lock-contention-bypass CB list. */
210 unsigned long nocb_bypass_first; /* Time (jiffies) of first enqueue. */
211 unsigned long nocb_nobypass_last; /* Last ->cblist enqueue (jiffies). */
212 int nocb_nobypass_count; /* # ->cblist enqueues at ^^^ time. */
Paul E. McKenneyfbce7492014-06-24 09:26:11 -0700213
Paul E. McKenney6484fe52019-03-28 15:44:18 -0700214 /* The following fields are used by GP kthread, hence own cacheline. */
Paul E. McKenney4fd8c5f2019-06-02 13:41:08 -0700215 raw_spinlock_t nocb_gp_lock ____cacheline_internodealigned_in_smp;
Paul E. McKenneyd1b222c2019-07-02 16:03:33 -0700216 struct timer_list nocb_bypass_timer; /* Force nocb_bypass flush. */
Paul E. McKenneyf7a81b12019-06-25 13:32:51 -0700217 u8 nocb_gp_sleep; /* Is the nocb GP thread asleep? */
218 u8 nocb_gp_bypass; /* Found a bypass on last scan? */
219 u8 nocb_gp_gp; /* GP to wait for on last scan? */
220 unsigned long nocb_gp_seq; /* If so, ->gp_seq to wait for. */
221 unsigned long nocb_gp_loops; /* # passes through wait code. */
Paul E. McKenney12f54c3a2019-03-29 16:43:51 -0700222 struct swait_queue_head nocb_gp_wq; /* For nocb kthreads to sleep on. */
Paul E. McKenney5d6742b2019-05-15 09:56:40 -0700223 bool nocb_cb_sleep; /* Is the nocb CB thread asleep? */
Paul E. McKenney12f54c3a2019-03-29 16:43:51 -0700224 struct task_struct *nocb_cb_kthread;
Paul E. McKenney58bf6f72019-03-28 15:33:59 -0700225 struct rcu_data *nocb_next_cb_rdp;
226 /* Next rcu_data in wakeup chain. */
Paul E. McKenneyfbce7492014-06-24 09:26:11 -0700227
Paul E. McKenneyd1b222c2019-07-02 16:03:33 -0700228 /* The following fields are used by CB kthread, hence new cacheline. */
Paul E. McKenney58bf6f72019-03-28 15:33:59 -0700229 struct rcu_data *nocb_gp_rdp ____cacheline_internodealigned_in_smp;
Paul E. McKenney6484fe52019-03-28 15:44:18 -0700230 /* GP rdp takes GP-end wakeups. */
Paul E. McKenney3fbfbf72012-08-19 21:35:53 -0700231#endif /* #ifdef CONFIG_RCU_NOCB_CPU */
232
Paul E. McKenney37f62d72018-11-30 16:11:14 -0800233 /* 6) RCU priority boosting. */
234 struct task_struct *rcu_cpu_kthread_task;
235 /* rcuc per-CPU kthread or NULL. */
Paul E. McKenney6ffdde22018-11-30 16:43:05 -0800236 unsigned int rcu_cpu_kthread_status;
Paul E. McKenneyf7e972e2018-11-30 18:21:32 -0800237 char rcu_cpu_has_work;
Paul E. McKenney37f62d72018-11-30 16:11:14 -0800238
239 /* 7) Diagnostic data, including RCU CPU stall warnings. */
Paul E. McKenney62310692013-03-06 13:37:09 -0800240 unsigned int softirq_snap; /* Snapshot of softirq activity. */
Paul E. McKenney9b9500d2017-08-17 17:05:59 -0700241 /* ->rcu_iw* fields protected by leaf rcu_node ->lock. */
242 struct irq_work rcu_iw; /* Check for non-irq activity. */
243 bool rcu_iw_pending; /* Is ->rcu_iw pending? */
Paul E. McKenney8aa670c2018-04-28 14:15:40 -0700244 unsigned long rcu_iw_gp_seq; /* ->gp_seq associated with ->rcu_iw. */
Paul E. McKenney57738942018-05-08 14:18:57 -0700245 unsigned long rcu_ofl_gp_seq; /* ->gp_seq at last offline. */
246 short rcu_ofl_gp_flags; /* ->gp_flags at last offline. */
247 unsigned long rcu_onl_gp_seq; /* ->gp_seq at last online. */
248 short rcu_onl_gp_flags; /* ->gp_flags at last online. */
Paul E. McKenneyd3052102018-07-25 11:49:47 -0700249 unsigned long last_fqs_resched; /* Time of last rcu_resched(). */
Paul E. McKenney62310692013-03-06 13:37:09 -0800250
Paul E. McKenney9f77da92009-08-22 13:56:45 -0700251 int cpu;
252};
253
Paul E. McKenney9fdd3bc2014-07-29 14:50:47 -0700254/* Values for nocb_defer_wakeup field in struct rcu_data. */
Paul E. McKenney511324e2017-04-28 17:04:09 -0700255#define RCU_NOCB_WAKE_NOT 0
256#define RCU_NOCB_WAKE 1
257#define RCU_NOCB_WAKE_FORCE 2
Paul E. McKenney9fdd3bc2014-07-29 14:50:47 -0700258
Paul E. McKenney026ad282013-04-03 22:14:11 -0700259#define RCU_JIFFIES_TILL_FORCE_QS (1 + (HZ > 250) + (HZ > 500))
260 /* For jiffies_till_first_fqs and */
261 /* and jiffies_till_next_fqs. */
Paul E. McKenney007b0922010-03-05 15:03:26 -0800262
Paul E. McKenney026ad282013-04-03 22:14:11 -0700263#define RCU_JIFFIES_FQS_DIV 256 /* Very large systems need more */
264 /* delay between bouts of */
265 /* quiescent-state forcing. */
266
267#define RCU_STALL_RAT_DELAY 2 /* Allow other CPUs time to take */
268 /* at least one scheduling clock */
269 /* irq before ratting on them. */
Paul E. McKenney9f77da92009-08-22 13:56:45 -0700270
Peter Zijlstra08bca602011-05-20 16:06:29 -0700271#define rcu_wait(cond) \
272do { \
273 for (;;) { \
274 set_current_state(TASK_INTERRUPTIBLE); \
275 if (cond) \
276 break; \
277 schedule(); \
278 } \
279 __set_current_state(TASK_RUNNING); \
280} while (0)
Paul E. McKenney9f77da92009-08-22 13:56:45 -0700281
282/*
283 * RCU global state, including node hierarchy. This hierarchy is
284 * represented in "heap" form in a dense array. The root (first level)
285 * of the hierarchy is in ->node[0] (referenced by ->level[0]), the second
286 * level in ->node[1] through ->node[m] (->node[1] referenced by ->level[1]),
287 * and the third level in ->node[m+1] and following (->node[m+1] referenced
288 * by ->level[2]). The number of levels is determined by the number of
289 * CPUs and by CONFIG_RCU_FANOUT. Small systems will have a "hierarchy"
290 * consisting of a single rcu_node.
291 */
292struct rcu_state {
293 struct rcu_node node[NUM_RCU_NODES]; /* Hierarchy. */
Alexander Gordeev032dfc82015-07-09 15:34:23 +0200294 struct rcu_node *level[RCU_NUM_LVLS + 1];
295 /* Hierarchy levels (+1 to */
296 /* shut bogus gcc warning) */
Paul E. McKenneyb9585e92015-07-31 16:04:45 -0700297 int ncpus; /* # CPUs seen so far. */
Paul E. McKenney9f77da92009-08-22 13:56:45 -0700298
299 /* The following fields are guarded by the root rcu_node's lock. */
300
Petr Mladek77f81fe2015-09-09 12:09:49 -0700301 u8 boost ____cacheline_internodealigned_in_smp;
302 /* Subject to priority boost. */
Paul E. McKenneyde30ad52018-04-26 11:52:09 -0700303 unsigned long gp_seq; /* Grace-period sequence #. */
Paul E. McKenneyb3dbec72012-06-18 18:36:08 -0700304 struct task_struct *gp_kthread; /* Task for grace periods. */
Paul Gortmakerabedf8e2016-02-19 09:46:41 +0100305 struct swait_queue_head gp_wq; /* Where GP task waits. */
Paul E. McKenneyafea2272014-03-12 07:10:41 -0700306 short gp_flags; /* Commands for GP task. */
307 short gp_state; /* GP kthread sleep state. */
Paul E. McKenneyfd897572018-12-10 16:09:49 -0800308 unsigned long gp_wake_time; /* Last GP kthread wake. */
309 unsigned long gp_wake_seq; /* ->gp_seq at ^^^. */
Paul E. McKenney1eba8f82009-09-23 09:50:42 -0700310
Paul E. McKenneyd9a3da02009-12-02 12:10:15 -0800311 /* End of fields guarded by root rcu_node's lock. */
Paul E. McKenney1eba8f82009-09-23 09:50:42 -0700312
Paul E. McKenney7be7f0b2012-05-29 05:18:53 -0700313 struct mutex barrier_mutex; /* Guards barrier fields. */
Paul E. McKenney24ebbca2012-05-29 00:34:56 -0700314 atomic_t barrier_cpu_count; /* # CPUs waiting on. */
Paul E. McKenney7db74df2012-05-29 03:03:37 -0700315 struct completion barrier_completion; /* Wake at barrier end. */
Paul E. McKenney4f525a52015-06-26 11:20:00 -0700316 unsigned long barrier_sequence; /* ++ at start and end of */
Paul E. McKenneydd46a782018-07-10 18:37:30 -0700317 /* rcu_barrier(). */
Paul E. McKenneya4fbe352012-10-07 08:36:12 -0700318 /* End of fields guarded by barrier_mutex. */
319
Paul E. McKenneyf6a12f32016-01-30 17:57:35 -0800320 struct mutex exp_mutex; /* Serialize expedited GP. */
Paul E. McKenney3b5f6682016-03-16 16:47:55 -0700321 struct mutex exp_wake_mutex; /* Serialize wakeup. */
Paul E. McKenneyd6ada2c2015-06-24 10:46:30 -0700322 unsigned long expedited_sequence; /* Take a ticket. */
Peter Zijlstra3a6d7c62015-06-25 11:27:10 -0700323 atomic_t expedited_need_qs; /* # CPUs left to check in. */
Paul Gortmakerabedf8e2016-02-19 09:46:41 +0100324 struct swait_queue_head expedited_wq; /* Wait for check-ins. */
Paul E. McKenneyb9585e92015-07-31 16:04:45 -0700325 int ncpus_snap; /* # CPUs seen last time. */
Paul E. McKenneyb2b00dd2019-10-30 11:56:10 -0700326 u8 cbovld; /* Callback overload now? */
327 u8 cbovldnext; /* ^ ^ next time? */
Paul E. McKenney40694d62012-10-11 15:24:03 -0700328
Paul E. McKenney9f77da92009-08-22 13:56:45 -0700329 unsigned long jiffies_force_qs; /* Time at which to invoke */
330 /* force_quiescent_state(). */
Paul E. McKenney8c7c4822016-01-03 20:29:57 -0800331 unsigned long jiffies_kick_kthreads; /* Time at which to kick */
332 /* kthreads, if configured. */
Paul E. McKenney9f77da92009-08-22 13:56:45 -0700333 unsigned long n_force_qs; /* Number of calls to */
334 /* force_quiescent_state(). */
Paul E. McKenney9f77da92009-08-22 13:56:45 -0700335 unsigned long gp_start; /* Time at which GP started, */
336 /* but in jiffies. */
Paul E. McKenneyc51d7b52018-10-03 17:25:33 -0700337 unsigned long gp_end; /* Time last GP ended, again */
338 /* in jiffies. */
Paul E. McKenney6ccd2ec2014-12-11 10:20:59 -0800339 unsigned long gp_activity; /* Time of last GP kthread */
340 /* activity in jiffies. */
Paul E. McKenney26d950a2018-04-21 20:44:11 -0700341 unsigned long gp_req_activity; /* Time of last GP request */
342 /* in jiffies. */
Paul E. McKenney9f77da92009-08-22 13:56:45 -0700343 unsigned long jiffies_stall; /* Time at which to check */
344 /* for CPU stalls. */
Paul E. McKenney6193c762013-09-23 13:57:18 -0700345 unsigned long jiffies_resched; /* Time at which to resched */
346 /* a reluctant CPU. */
Paul E. McKenneyfc908ed2014-12-08 09:57:48 -0800347 unsigned long n_force_qs_gpstart; /* Snapshot of n_force_qs at */
348 /* GP start. */
Paul E. McKenney15ba0ba2011-04-06 16:01:16 -0700349 unsigned long gp_max; /* Maximum GP duration in */
350 /* jiffies. */
Steven Rostedt (Red Hat)e66c33d2013-07-12 16:50:28 -0400351 const char *name; /* Name of structure. */
Paul E. McKenneya4889852012-12-03 08:16:28 -0800352 char abbr; /* Abbreviated name. */
Paul E. McKenney1e64b152018-05-25 19:23:09 -0700353
Mike Galbraith894d45b2018-08-15 09:05:29 -0700354 raw_spinlock_t ofl_lock ____cacheline_internodealigned_in_smp;
Paul E. McKenney1e64b152018-05-25 19:23:09 -0700355 /* Synchronize offline with */
356 /* GP pre-initialization. */
Paul E. McKenney9f77da92009-08-22 13:56:45 -0700357};
358
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -0700359/* Values for rcu_state structure's gp_flags field. */
360#define RCU_GP_FLAG_INIT 0x1 /* Need grace-period initialization. */
361#define RCU_GP_FLAG_FQS 0x2 /* Need grace-period quiescent-state forcing. */
Paul E. McKenney1fca4d12020-02-22 20:07:09 -0800362#define RCU_GP_FLAG_OVLD 0x4 /* Experiencing callback overload. */
Paul E. McKenney4cdfc1752012-06-22 17:06:26 -0700363
Paul E. McKenneyc34d2f42015-09-10 11:21:28 -0700364/* Values for rcu_state structure's gp_state field. */
Petr Mladek77f81fe2015-09-09 12:09:49 -0700365#define RCU_GP_IDLE 0 /* Initial state and no GP in progress. */
Paul E. McKenneyafea2272014-03-12 07:10:41 -0700366#define RCU_GP_WAIT_GPS 1 /* Wait for grace-period start. */
Paul E. McKenney319362c2015-05-19 14:16:52 -0700367#define RCU_GP_DONE_GPS 2 /* Wait done for grace-period start. */
Paul E. McKenneyfea3f222018-05-15 15:47:30 -0700368#define RCU_GP_ONOFF 3 /* Grace-period initialization hotplug. */
369#define RCU_GP_INIT 4 /* Grace-period initialization. */
370#define RCU_GP_WAIT_FQS 5 /* Wait for force-quiescent-state time. */
371#define RCU_GP_DOING_FQS 6 /* Wait done for force-quiescent-state time. */
372#define RCU_GP_CLEANUP 7 /* Grace-period cleanup started. */
373#define RCU_GP_CLEANED 8 /* Grace-period cleanup complete. */
Paul E. McKenneyafea2272014-03-12 07:10:41 -0700374
Paul E. McKenney358be2d2018-07-03 14:15:31 -0700375/*
376 * In order to export the rcu_state name to the tracing tools, it
377 * needs to be added in the __tracepoint_string section.
378 * This requires defining a separate variable tp_<sname>_varname
379 * that points to the string being used, and this will allow
380 * the tracing userspace tools to be able to decipher the string
381 * address to the matching string.
382 */
383#ifdef CONFIG_PREEMPT_RCU
384#define RCU_ABBR 'p'
385#define RCU_NAME_RAW "rcu_preempt"
386#else /* #ifdef CONFIG_PREEMPT_RCU */
387#define RCU_ABBR 's'
388#define RCU_NAME_RAW "rcu_sched"
389#endif /* #else #ifdef CONFIG_PREEMPT_RCU */
390#ifndef CONFIG_TRACING
391#define RCU_NAME RCU_NAME_RAW
392#else /* #ifdef CONFIG_TRACING */
393static char rcu_name[] = RCU_NAME_RAW;
394static const char *tp_rcu_varname __used __tracepoint_string = rcu_name;
395#define RCU_NAME rcu_name
396#endif /* #else #ifdef CONFIG_TRACING */
Paul E. McKenney6b50e112015-11-17 14:39:26 -0800397
Paul E. McKenney32255d52019-01-11 16:57:41 -0800398/* Forward declarations for tree_plugin.h */
Paul E. McKenneydbe01352009-11-10 13:37:19 -0800399static void rcu_bootup_announce(void);
Paul E. McKenney45975c72018-07-02 14:30:37 -0700400static void rcu_qs(void);
Paul E. McKenney27f4d282011-02-07 12:47:15 -0800401static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp);
Paul E. McKenneyb668c9c2009-11-22 08:53:48 -0800402#ifdef CONFIG_HOTPLUG_CPU
Paul E. McKenney8af3a5e2014-10-31 11:22:37 -0700403static bool rcu_preempt_has_tasks(struct rcu_node *rnp);
Paul E. McKenneyb668c9c2009-11-22 08:53:48 -0800404#endif /* #ifdef CONFIG_HOTPLUG_CPU */
Paul E. McKenney74611ec2015-08-18 10:20:43 -0700405static int rcu_print_task_exp_stall(struct rcu_node *rnp);
Paul E. McKenney81ab59a2018-07-03 17:22:34 -0700406static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp);
Paul E. McKenneyc98cac62018-11-21 11:35:03 -0800407static void rcu_flavor_sched_clock_irq(int user);
Paul E. McKenney81ab59a2018-07-03 17:22:34 -0700408static void dump_blkd_tasks(struct rcu_node *rnp, int ncheck);
Paul E. McKenney1217ed12011-05-04 21:43:49 -0700409static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags);
Paul E. McKenneya46e0892011-06-15 15:47:09 -0700410static void rcu_preempt_boost_start_gp(struct rcu_node *rnp);
Paul E. McKenneydff16722011-11-29 15:57:13 -0800411static bool rcu_is_callbacks_kthread(void);
Sebastian Andrzej Siewior48d07c02019-03-20 22:13:33 +0100412static void rcu_cpu_kthread_setup(unsigned int cpu);
Paul E. McKenney9386c0b2014-07-13 12:00:53 -0700413static void __init rcu_spawn_boost_kthreads(void);
Paul Gortmaker49fb4c62013-06-19 14:52:21 -0400414static void rcu_prepare_kthreads(int cpu);
Paul E. McKenney8fa78452014-10-22 15:07:37 -0700415static void rcu_cleanup_after_idle(void);
Paul E. McKenney198bbf82014-10-22 15:03:43 -0700416static void rcu_prepare_for_idle(void);
Paul E. McKenney0aa04b02015-01-23 21:52:37 -0800417static bool rcu_preempt_has_tasks(struct rcu_node *rnp);
Paul E. McKenney3e310092018-06-21 12:50:01 -0700418static bool rcu_preempt_need_deferred_qs(struct task_struct *t);
419static void rcu_preempt_deferred_qs(struct task_struct *t);
Paul E. McKenneya858af22012-01-16 13:29:10 -0800420static void zero_cpu_stall_ticks(struct rcu_data *rdp);
Paul Gortmakerabedf8e2016-02-19 09:46:41 +0100421static struct swait_queue_head *rcu_nocb_gp_get(struct rcu_node *rnp);
422static void rcu_nocb_gp_cleanup(struct swait_queue_head *sq);
Paul E. McKenneydae6e642013-02-10 20:48:58 -0800423static void rcu_init_one_nocb(struct rcu_node *rnp);
Paul E. McKenneyd1b222c2019-07-02 16:03:33 -0700424static bool rcu_nocb_flush_bypass(struct rcu_data *rdp, struct rcu_head *rhp,
425 unsigned long j);
426static bool rcu_nocb_try_bypass(struct rcu_data *rdp, struct rcu_head *rhp,
427 bool *was_alldone, unsigned long flags);
Paul E. McKenney5d6742b2019-05-15 09:56:40 -0700428static void __call_rcu_nocb_wake(struct rcu_data *rdp, bool was_empty,
429 unsigned long flags);
Paul E. McKenney9fdd3bc2014-07-29 14:50:47 -0700430static int rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp);
Paul E. McKenney96d3fd02013-10-04 14:33:34 -0700431static void do_nocb_deferred_wakeup(struct rcu_data *rdp);
Paul E. McKenney3fbfbf72012-08-19 21:35:53 -0700432static void rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp);
Paul E. McKenneyad368d12018-11-27 13:55:53 -0800433static void rcu_spawn_cpu_nocb_kthread(int cpu);
Paul E. McKenney35ce7f22014-07-11 11:30:24 -0700434static void __init rcu_spawn_nocb_kthreads(void);
Paul E. McKenneyf7a81b12019-06-25 13:32:51 -0700435static void show_rcu_nocb_state(struct rcu_data *rdp);
Paul E. McKenney5d6742b2019-05-15 09:56:40 -0700436static void rcu_nocb_lock(struct rcu_data *rdp);
437static void rcu_nocb_unlock(struct rcu_data *rdp);
438static void rcu_nocb_unlock_irqrestore(struct rcu_data *rdp,
439 unsigned long flags);
Paul E. McKenneyd1b222c2019-07-02 16:03:33 -0700440static void rcu_lockdep_assert_cblist_protected(struct rcu_data *rdp);
Paul E. McKenney35ce7f22014-07-11 11:30:24 -0700441#ifdef CONFIG_RCU_NOCB_CPU
Paul E. McKenney4580b052018-07-03 17:22:34 -0700442static void __init rcu_organize_nocb_kthreads(void);
Paul E. McKenney81c0b3d2019-05-28 07:18:08 -0700443#define rcu_nocb_lock_irqsave(rdp, flags) \
444do { \
Paul E. McKenneyd1b222c2019-07-02 16:03:33 -0700445 if (!rcu_segcblist_is_offloaded(&(rdp)->cblist)) \
Paul E. McKenney81c0b3d2019-05-28 07:18:08 -0700446 local_irq_save(flags); \
Paul E. McKenneyd1b222c2019-07-02 16:03:33 -0700447 else \
Paul E. McKenney81c0b3d2019-05-28 07:18:08 -0700448 raw_spin_lock_irqsave(&(rdp)->nocb_lock, (flags)); \
Paul E. McKenney81c0b3d2019-05-28 07:18:08 -0700449} while (0)
450#else /* #ifdef CONFIG_RCU_NOCB_CPU */
451#define rcu_nocb_lock_irqsave(rdp, flags) local_irq_save(flags)
452#endif /* #else #ifdef CONFIG_RCU_NOCB_CPU */
453
Paul E. McKenneyeb757672013-06-21 17:10:40 -0700454static void rcu_bind_gp_kthread(void);
Paul E. McKenney4580b052018-07-03 17:22:34 -0700455static bool rcu_nohz_full_cpu(void);
Paul E. McKenney176f8f72014-08-04 17:43:50 -0700456static void rcu_dynticks_task_enter(void);
457static void rcu_dynticks_task_exit(void);
Paul E. McKenney32255d52019-01-11 16:57:41 -0800458
459/* Forward declarations for tree_stall.h */
Paul E. McKenney32255d52019-01-11 16:57:41 -0800460static void record_gp_stall_check_time(void);
Paul E. McKenney7ac19072019-01-14 10:19:20 -0800461static void rcu_iw_handler(struct irq_work *iwp);
Paul E. McKenney32255d52019-01-11 16:57:41 -0800462static void check_cpu_stall(struct rcu_data *rdp);
Paul E. McKenneyb51bcbb2019-01-15 07:01:33 -0800463static void rcu_check_gp_start_stall(struct rcu_node *rnp, struct rcu_data *rdp,
464 const unsigned long gpssdelay);