]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - kernel/rcu/tree_plugin.h
rcu: Make rcu_is_watching() really notrace
[mirror_ubuntu-zesty-kernel.git] / kernel / rcu / tree_plugin.h
CommitLineData
f41d911f
PM
1/*
2 * Read-Copy Update mechanism for mutual exclusion (tree-based version)
3 * Internal non-public definitions that provide either classic
6cc68793 4 * or preemptible semantics.
f41d911f
PM
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
87de1cfd
PM
17 * along with this program; if not, you can access it online at
18 * http://www.gnu.org/licenses/gpl-2.0.html.
f41d911f
PM
19 *
20 * Copyright Red Hat, 2009
21 * Copyright IBM Corporation, 2009
22 *
23 * Author: Ingo Molnar <mingo@elte.hu>
24 * Paul E. McKenney <paulmck@linux.vnet.ibm.com>
25 */
26
d9a3da06 27#include <linux/delay.h>
3fbfbf7a 28#include <linux/gfp.h>
b626c1b6 29#include <linux/oom.h>
62ab7072 30#include <linux/smpboot.h>
4102adab 31#include "../time/tick-internal.h"
f41d911f 32
5b61b0ba 33#ifdef CONFIG_RCU_BOOST
61cfd097 34
abaa93d9 35#include "../locking/rtmutex_common.h"
21871d7e 36
61cfd097
PM
37/*
38 * Control variables for per-CPU and per-rcu_node kthreads. These
39 * handle all flavors of RCU.
40 */
41static DEFINE_PER_CPU(struct task_struct *, rcu_cpu_kthread_task);
42DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_status);
43DEFINE_PER_CPU(unsigned int, rcu_cpu_kthread_loops);
44DEFINE_PER_CPU(char, rcu_cpu_has_work);
45
727b705b
PM
46#else /* #ifdef CONFIG_RCU_BOOST */
47
48/*
49 * Some architectures do not define rt_mutexes, but if !CONFIG_RCU_BOOST,
50 * all uses are in dead code. Provide a definition to keep the compiler
51 * happy, but add WARN_ON_ONCE() to complain if used in the wrong place.
52 * This probably needs to be excluded from -rt builds.
53 */
54#define rt_mutex_owner(a) ({ WARN_ON_ONCE(1); NULL; })
55
56#endif /* #else #ifdef CONFIG_RCU_BOOST */
5b61b0ba 57
3fbfbf7a
PM
58#ifdef CONFIG_RCU_NOCB_CPU
59static cpumask_var_t rcu_nocb_mask; /* CPUs to have callbacks offloaded. */
60static bool have_rcu_nocb_mask; /* Was rcu_nocb_mask allocated? */
1b0048a4 61static bool __read_mostly rcu_nocb_poll; /* Offload kthread are to poll. */
3fbfbf7a
PM
62#endif /* #ifdef CONFIG_RCU_NOCB_CPU */
63
26845c28
PM
64/*
65 * Check the RCU kernel configuration parameters and print informative
66 * messages about anything out of the ordinary. If you like #ifdef, you
67 * will love this function.
68 */
69static void __init rcu_bootup_announce_oddness(void)
70{
ab6f5bd6
PM
71 if (IS_ENABLED(CONFIG_RCU_TRACE))
72 pr_info("\tRCU debugfs-based tracing is enabled.\n");
05c5df31
PM
73 if ((IS_ENABLED(CONFIG_64BIT) && RCU_FANOUT != 64) ||
74 (!IS_ENABLED(CONFIG_64BIT) && RCU_FANOUT != 32))
ab6f5bd6 75 pr_info("\tCONFIG_RCU_FANOUT set to non-default value of %d\n",
05c5df31 76 RCU_FANOUT);
7fa27001 77 if (rcu_fanout_exact)
ab6f5bd6
PM
78 pr_info("\tHierarchical RCU autobalancing is disabled.\n");
79 if (IS_ENABLED(CONFIG_RCU_FAST_NO_HZ))
80 pr_info("\tRCU dyntick-idle grace-period acceleration is enabled.\n");
81 if (IS_ENABLED(CONFIG_PROVE_RCU))
82 pr_info("\tRCU lockdep checking is enabled.\n");
83 if (IS_ENABLED(CONFIG_RCU_TORTURE_TEST_RUNNABLE))
84 pr_info("\tRCU torture testing starts during boot.\n");
85 if (IS_ENABLED(CONFIG_RCU_CPU_STALL_INFO))
86 pr_info("\tAdditional per-CPU info printed with stalls.\n");
87 if (NUM_RCU_LVL_4 != 0)
88 pr_info("\tFour-level hierarchy is enabled.\n");
47d631af 89 if (RCU_FANOUT_LEAF != 16)
a3bd2c09 90 pr_info("\tBuild-time adjustment of leaf fanout to %d.\n",
47d631af
PM
91 RCU_FANOUT_LEAF);
92 if (rcu_fanout_leaf != RCU_FANOUT_LEAF)
9a5739d7 93 pr_info("\tBoot-time adjustment of leaf fanout to %d.\n", rcu_fanout_leaf);
cca6f393 94 if (nr_cpu_ids != NR_CPUS)
efc151c3 95 pr_info("\tRCU restricting CPUs from NR_CPUS=%d to nr_cpu_ids=%d.\n", NR_CPUS, nr_cpu_ids);
ab6f5bd6
PM
96 if (IS_ENABLED(CONFIG_RCU_BOOST))
97 pr_info("\tRCU kthread priority: %d.\n", kthread_prio);
26845c28
PM
98}
99
28f6569a 100#ifdef CONFIG_PREEMPT_RCU
f41d911f 101
a41bfeb2 102RCU_STATE_INITIALIZER(rcu_preempt, 'p', call_rcu);
b28a7c01 103static struct rcu_state *const rcu_state_p = &rcu_preempt_state;
2927a689 104static struct rcu_data __percpu *const rcu_data_p = &rcu_preempt_data;
f41d911f 105
d9a3da06 106static int rcu_preempted_readers_exp(struct rcu_node *rnp);
d19fb8d1
PM
107static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp,
108 bool wake);
d9a3da06 109
f41d911f
PM
110/*
111 * Tell them what RCU they are running.
112 */
0e0fc1c2 113static void __init rcu_bootup_announce(void)
f41d911f 114{
efc151c3 115 pr_info("Preemptible hierarchical RCU implementation.\n");
26845c28 116 rcu_bootup_announce_oddness();
f41d911f
PM
117}
118
f41d911f 119/*
6cc68793 120 * Record a preemptible-RCU quiescent state for the specified CPU. Note
f41d911f
PM
121 * that this just means that the task currently running on the CPU is
122 * not in a quiescent state. There might be any number of tasks blocked
123 * while in an RCU read-side critical section.
25502a6c 124 *
1d082fd0
PM
125 * As with the other rcu_*_qs() functions, callers to this function
126 * must disable preemption.
f41d911f 127 */
284a8c93 128static void rcu_preempt_qs(void)
f41d911f 129{
2927a689 130 if (!__this_cpu_read(rcu_data_p->passed_quiesce)) {
284a8c93 131 trace_rcu_grace_period(TPS("rcu_preempt"),
2927a689 132 __this_cpu_read(rcu_data_p->gpnum),
284a8c93 133 TPS("cpuqs"));
2927a689 134 __this_cpu_write(rcu_data_p->passed_quiesce, 1);
284a8c93
PM
135 barrier(); /* Coordinate with rcu_preempt_check_callbacks(). */
136 current->rcu_read_unlock_special.b.need_qs = false;
137 }
f41d911f
PM
138}
139
140/*
c3422bea
PM
141 * We have entered the scheduler, and the current task might soon be
142 * context-switched away from. If this task is in an RCU read-side
143 * critical section, we will no longer be able to rely on the CPU to
12f5f524
PM
144 * record that fact, so we enqueue the task on the blkd_tasks list.
145 * The task will dequeue itself when it exits the outermost enclosing
146 * RCU read-side critical section. Therefore, the current grace period
147 * cannot be permitted to complete until the blkd_tasks list entries
148 * predating the current grace period drain, in other words, until
149 * rnp->gp_tasks becomes NULL.
c3422bea
PM
150 *
151 * Caller must disable preemption.
f41d911f 152 */
38200cf2 153static void rcu_preempt_note_context_switch(void)
f41d911f
PM
154{
155 struct task_struct *t = current;
c3422bea 156 unsigned long flags;
f41d911f
PM
157 struct rcu_data *rdp;
158 struct rcu_node *rnp;
159
10f39bb1 160 if (t->rcu_read_lock_nesting > 0 &&
1d082fd0 161 !t->rcu_read_unlock_special.b.blocked) {
f41d911f
PM
162
163 /* Possibly blocking in an RCU read-side critical section. */
e63c887c 164 rdp = this_cpu_ptr(rcu_state_p->rda);
f41d911f 165 rnp = rdp->mynode;
1304afb2 166 raw_spin_lock_irqsave(&rnp->lock, flags);
6303b9c8 167 smp_mb__after_unlock_lock();
1d082fd0 168 t->rcu_read_unlock_special.b.blocked = true;
86848966 169 t->rcu_blocked_node = rnp;
f41d911f
PM
170
171 /*
172 * If this CPU has already checked in, then this task
173 * will hold up the next grace period rather than the
174 * current grace period. Queue the task accordingly.
175 * If the task is queued for the current grace period
176 * (i.e., this CPU has not yet passed through a quiescent
177 * state for the current grace period), then as long
178 * as that task remains queued, the current grace period
12f5f524
PM
179 * cannot end. Note that there is some uncertainty as
180 * to exactly when the current grace period started.
181 * We take a conservative approach, which can result
182 * in unnecessarily waiting on tasks that started very
183 * slightly after the current grace period began. C'est
184 * la vie!!!
b0e165c0
PM
185 *
186 * But first, note that the current CPU must still be
187 * on line!
f41d911f 188 */
0aa04b05 189 WARN_ON_ONCE((rdp->grpmask & rcu_rnp_online_cpus(rnp)) == 0);
e7d8842e 190 WARN_ON_ONCE(!list_empty(&t->rcu_node_entry));
12f5f524
PM
191 if ((rnp->qsmask & rdp->grpmask) && rnp->gp_tasks != NULL) {
192 list_add(&t->rcu_node_entry, rnp->gp_tasks->prev);
193 rnp->gp_tasks = &t->rcu_node_entry;
727b705b
PM
194 if (IS_ENABLED(CONFIG_RCU_BOOST) &&
195 rnp->boost_tasks != NULL)
27f4d280 196 rnp->boost_tasks = rnp->gp_tasks;
12f5f524
PM
197 } else {
198 list_add(&t->rcu_node_entry, &rnp->blkd_tasks);
199 if (rnp->qsmask & rdp->grpmask)
200 rnp->gp_tasks = &t->rcu_node_entry;
201 }
d4c08f2a
PM
202 trace_rcu_preempt_task(rdp->rsp->name,
203 t->pid,
204 (rnp->qsmask & rdp->grpmask)
205 ? rnp->gpnum
206 : rnp->gpnum + 1);
1304afb2 207 raw_spin_unlock_irqrestore(&rnp->lock, flags);
10f39bb1 208 } else if (t->rcu_read_lock_nesting < 0 &&
1d082fd0 209 t->rcu_read_unlock_special.s) {
10f39bb1
PM
210
211 /*
212 * Complete exit from RCU read-side critical section on
213 * behalf of preempted instance of __rcu_read_unlock().
214 */
215 rcu_read_unlock_special(t);
f41d911f
PM
216 }
217
218 /*
219 * Either we were not in an RCU read-side critical section to
220 * begin with, or we have now recorded that critical section
221 * globally. Either way, we can now note a quiescent state
222 * for this CPU. Again, if we were in an RCU read-side critical
223 * section, and if that critical section was blocking the current
224 * grace period, then the fact that the task has been enqueued
225 * means that we continue to block the current grace period.
226 */
284a8c93 227 rcu_preempt_qs();
f41d911f
PM
228}
229
fc2219d4
PM
230/*
231 * Check for preempted RCU readers blocking the current grace period
232 * for the specified rcu_node structure. If the caller needs a reliable
233 * answer, it must hold the rcu_node's ->lock.
234 */
27f4d280 235static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp)
fc2219d4 236{
12f5f524 237 return rnp->gp_tasks != NULL;
fc2219d4
PM
238}
239
12f5f524
PM
240/*
241 * Advance a ->blkd_tasks-list pointer to the next entry, instead
242 * returning NULL if at the end of the list.
243 */
244static struct list_head *rcu_next_node_entry(struct task_struct *t,
245 struct rcu_node *rnp)
246{
247 struct list_head *np;
248
249 np = t->rcu_node_entry.next;
250 if (np == &rnp->blkd_tasks)
251 np = NULL;
252 return np;
253}
254
8af3a5e7
PM
255/*
256 * Return true if the specified rcu_node structure has tasks that were
257 * preempted within an RCU read-side critical section.
258 */
259static bool rcu_preempt_has_tasks(struct rcu_node *rnp)
260{
261 return !list_empty(&rnp->blkd_tasks);
262}
263
b668c9cf
PM
264/*
265 * Handle special cases during rcu_read_unlock(), such as needing to
266 * notify RCU core processing or task having blocked during the RCU
267 * read-side critical section.
268 */
2a3fa843 269void rcu_read_unlock_special(struct task_struct *t)
f41d911f 270{
b6a932d1
PM
271 bool empty_exp;
272 bool empty_norm;
273 bool empty_exp_now;
f41d911f 274 unsigned long flags;
12f5f524 275 struct list_head *np;
abaa93d9 276 bool drop_boost_mutex = false;
f41d911f 277 struct rcu_node *rnp;
1d082fd0 278 union rcu_special special;
f41d911f
PM
279
280 /* NMI handlers cannot block and cannot safely manipulate state. */
281 if (in_nmi())
282 return;
283
284 local_irq_save(flags);
285
286 /*
287 * If RCU core is waiting for this CPU to exit critical section,
1d082fd0
PM
288 * let it know that we have done so. Because irqs are disabled,
289 * t->rcu_read_unlock_special cannot change.
f41d911f
PM
290 */
291 special = t->rcu_read_unlock_special;
1d082fd0 292 if (special.b.need_qs) {
284a8c93 293 rcu_preempt_qs();
c0135d07 294 t->rcu_read_unlock_special.b.need_qs = false;
1d082fd0 295 if (!t->rcu_read_unlock_special.s) {
79a62f95
LJ
296 local_irq_restore(flags);
297 return;
298 }
f41d911f
PM
299 }
300
79a62f95 301 /* Hardware IRQ handlers cannot block, complain if they get here. */
d24209bb
PM
302 if (in_irq() || in_serving_softirq()) {
303 lockdep_rcu_suspicious(__FILE__, __LINE__,
304 "rcu_read_unlock() from irq or softirq with blocking in critical section!!!\n");
305 pr_alert("->rcu_read_unlock_special: %#x (b: %d, nq: %d)\n",
306 t->rcu_read_unlock_special.s,
307 t->rcu_read_unlock_special.b.blocked,
308 t->rcu_read_unlock_special.b.need_qs);
f41d911f
PM
309 local_irq_restore(flags);
310 return;
311 }
312
313 /* Clean up if blocked during RCU read-side critical section. */
1d082fd0
PM
314 if (special.b.blocked) {
315 t->rcu_read_unlock_special.b.blocked = false;
f41d911f 316
dd5d19ba 317 /*
0a0ba1c9
PM
318 * Remove this task from the list it blocked on. The task
319 * now remains queued on the rcu_node corresponding to
320 * the CPU it first blocked on, so the first attempt to
321 * acquire the task's rcu_node's ->lock will succeed.
322 * Keep the loop and add a WARN_ON() out of sheer paranoia.
dd5d19ba
PM
323 */
324 for (;;) {
86848966 325 rnp = t->rcu_blocked_node;
1304afb2 326 raw_spin_lock(&rnp->lock); /* irqs already disabled. */
6303b9c8 327 smp_mb__after_unlock_lock();
86848966 328 if (rnp == t->rcu_blocked_node)
dd5d19ba 329 break;
0a0ba1c9 330 WARN_ON_ONCE(1);
1304afb2 331 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
dd5d19ba 332 }
74e871ac 333 empty_norm = !rcu_preempt_blocked_readers_cgp(rnp);
d9a3da06
PM
334 empty_exp = !rcu_preempted_readers_exp(rnp);
335 smp_mb(); /* ensure expedited fastpath sees end of RCU c-s. */
12f5f524 336 np = rcu_next_node_entry(t, rnp);
f41d911f 337 list_del_init(&t->rcu_node_entry);
82e78d80 338 t->rcu_blocked_node = NULL;
f7f7bac9 339 trace_rcu_unlock_preempted_task(TPS("rcu_preempt"),
d4c08f2a 340 rnp->gpnum, t->pid);
12f5f524
PM
341 if (&t->rcu_node_entry == rnp->gp_tasks)
342 rnp->gp_tasks = np;
343 if (&t->rcu_node_entry == rnp->exp_tasks)
344 rnp->exp_tasks = np;
727b705b
PM
345 if (IS_ENABLED(CONFIG_RCU_BOOST)) {
346 if (&t->rcu_node_entry == rnp->boost_tasks)
347 rnp->boost_tasks = np;
348 /* Snapshot ->boost_mtx ownership w/rnp->lock held. */
349 drop_boost_mutex = rt_mutex_owner(&rnp->boost_mtx) == t;
350 }
f41d911f
PM
351
352 /*
353 * If this was the last task on the current list, and if
354 * we aren't waiting on any CPUs, report the quiescent state.
389abd48
PM
355 * Note that rcu_report_unblock_qs_rnp() releases rnp->lock,
356 * so we must take a snapshot of the expedited state.
f41d911f 357 */
389abd48 358 empty_exp_now = !rcu_preempted_readers_exp(rnp);
74e871ac 359 if (!empty_norm && !rcu_preempt_blocked_readers_cgp(rnp)) {
f7f7bac9 360 trace_rcu_quiescent_state_report(TPS("preempt_rcu"),
d4c08f2a
PM
361 rnp->gpnum,
362 0, rnp->qsmask,
363 rnp->level,
364 rnp->grplo,
365 rnp->grphi,
366 !!rnp->gp_tasks);
e63c887c 367 rcu_report_unblock_qs_rnp(rcu_state_p, rnp, flags);
c701d5d9 368 } else {
d4c08f2a 369 raw_spin_unlock_irqrestore(&rnp->lock, flags);
c701d5d9 370 }
d9a3da06 371
27f4d280 372 /* Unboost if we were boosted. */
727b705b 373 if (IS_ENABLED(CONFIG_RCU_BOOST) && drop_boost_mutex)
abaa93d9 374 rt_mutex_unlock(&rnp->boost_mtx);
27f4d280 375
d9a3da06
PM
376 /*
377 * If this was the last task on the expedited lists,
378 * then we need to report up the rcu_node hierarchy.
379 */
389abd48 380 if (!empty_exp && empty_exp_now)
e63c887c 381 rcu_report_exp_rnp(rcu_state_p, rnp, true);
b668c9cf
PM
382 } else {
383 local_irq_restore(flags);
f41d911f 384 }
f41d911f
PM
385}
386
1ed509a2
PM
387/*
388 * Dump detailed information for all tasks blocking the current RCU
389 * grace period on the specified rcu_node structure.
390 */
391static void rcu_print_detail_task_stall_rnp(struct rcu_node *rnp)
392{
393 unsigned long flags;
1ed509a2
PM
394 struct task_struct *t;
395
12f5f524 396 raw_spin_lock_irqsave(&rnp->lock, flags);
5fd4dc06
PM
397 if (!rcu_preempt_blocked_readers_cgp(rnp)) {
398 raw_spin_unlock_irqrestore(&rnp->lock, flags);
399 return;
400 }
82efed06 401 t = list_entry(rnp->gp_tasks->prev,
12f5f524
PM
402 struct task_struct, rcu_node_entry);
403 list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry)
404 sched_show_task(t);
405 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1ed509a2
PM
406}
407
408/*
409 * Dump detailed information for all tasks blocking the current RCU
410 * grace period.
411 */
412static void rcu_print_detail_task_stall(struct rcu_state *rsp)
413{
414 struct rcu_node *rnp = rcu_get_root(rsp);
415
416 rcu_print_detail_task_stall_rnp(rnp);
417 rcu_for_each_leaf_node(rsp, rnp)
418 rcu_print_detail_task_stall_rnp(rnp);
419}
420
a858af28
PM
421#ifdef CONFIG_RCU_CPU_STALL_INFO
422
423static void rcu_print_task_stall_begin(struct rcu_node *rnp)
424{
efc151c3 425 pr_err("\tTasks blocked on level-%d rcu_node (CPUs %d-%d):",
a858af28
PM
426 rnp->level, rnp->grplo, rnp->grphi);
427}
428
429static void rcu_print_task_stall_end(void)
430{
efc151c3 431 pr_cont("\n");
a858af28
PM
432}
433
434#else /* #ifdef CONFIG_RCU_CPU_STALL_INFO */
435
436static void rcu_print_task_stall_begin(struct rcu_node *rnp)
437{
438}
439
440static void rcu_print_task_stall_end(void)
441{
442}
443
444#endif /* #else #ifdef CONFIG_RCU_CPU_STALL_INFO */
445
f41d911f
PM
446/*
447 * Scan the current list of tasks blocked within RCU read-side critical
448 * sections, printing out the tid of each.
449 */
9bc8b558 450static int rcu_print_task_stall(struct rcu_node *rnp)
f41d911f 451{
f41d911f 452 struct task_struct *t;
9bc8b558 453 int ndetected = 0;
f41d911f 454
27f4d280 455 if (!rcu_preempt_blocked_readers_cgp(rnp))
9bc8b558 456 return 0;
a858af28 457 rcu_print_task_stall_begin(rnp);
82efed06 458 t = list_entry(rnp->gp_tasks->prev,
12f5f524 459 struct task_struct, rcu_node_entry);
9bc8b558 460 list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry) {
efc151c3 461 pr_cont(" P%d", t->pid);
9bc8b558
PM
462 ndetected++;
463 }
a858af28 464 rcu_print_task_stall_end();
9bc8b558 465 return ndetected;
f41d911f
PM
466}
467
b0e165c0
PM
468/*
469 * Check that the list of blocked tasks for the newly completed grace
470 * period is in fact empty. It is a serious bug to complete a grace
471 * period that still has RCU readers blocked! This function must be
472 * invoked -before- updating this rnp's ->gpnum, and the rnp's ->lock
473 * must be held by the caller.
12f5f524
PM
474 *
475 * Also, if there are blocked tasks on the list, they automatically
476 * block the newly created grace period, so set up ->gp_tasks accordingly.
b0e165c0
PM
477 */
478static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp)
479{
27f4d280 480 WARN_ON_ONCE(rcu_preempt_blocked_readers_cgp(rnp));
96e92021 481 if (rcu_preempt_has_tasks(rnp))
12f5f524 482 rnp->gp_tasks = rnp->blkd_tasks.next;
28ecd580 483 WARN_ON_ONCE(rnp->qsmask);
b0e165c0
PM
484}
485
f41d911f
PM
486/*
487 * Check for a quiescent state from the current CPU. When a task blocks,
488 * the task is recorded in the corresponding CPU's rcu_node structure,
489 * which is checked elsewhere.
490 *
491 * Caller must disable hard irqs.
492 */
86aea0e6 493static void rcu_preempt_check_callbacks(void)
f41d911f
PM
494{
495 struct task_struct *t = current;
496
497 if (t->rcu_read_lock_nesting == 0) {
284a8c93 498 rcu_preempt_qs();
f41d911f
PM
499 return;
500 }
10f39bb1 501 if (t->rcu_read_lock_nesting > 0 &&
2927a689
PM
502 __this_cpu_read(rcu_data_p->qs_pending) &&
503 !__this_cpu_read(rcu_data_p->passed_quiesce))
1d082fd0 504 t->rcu_read_unlock_special.b.need_qs = true;
f41d911f
PM
505}
506
a46e0899
PM
507#ifdef CONFIG_RCU_BOOST
508
09223371
SL
509static void rcu_preempt_do_callbacks(void)
510{
2927a689 511 rcu_do_batch(rcu_state_p, this_cpu_ptr(rcu_data_p));
09223371
SL
512}
513
a46e0899
PM
514#endif /* #ifdef CONFIG_RCU_BOOST */
515
f41d911f 516/*
6cc68793 517 * Queue a preemptible-RCU callback for invocation after a grace period.
f41d911f
PM
518 */
519void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
520{
e63c887c 521 __call_rcu(head, func, rcu_state_p, -1, 0);
f41d911f
PM
522}
523EXPORT_SYMBOL_GPL(call_rcu);
524
6ebb237b
PM
525/**
526 * synchronize_rcu - wait until a grace period has elapsed.
527 *
528 * Control will return to the caller some time after a full grace
529 * period has elapsed, in other words after all currently executing RCU
77d8485a
PM
530 * read-side critical sections have completed. Note, however, that
531 * upon return from synchronize_rcu(), the caller might well be executing
532 * concurrently with new RCU read-side critical sections that began while
533 * synchronize_rcu() was waiting. RCU read-side critical sections are
534 * delimited by rcu_read_lock() and rcu_read_unlock(), and may be nested.
f0a0e6f2
PM
535 *
536 * See the description of synchronize_sched() for more detailed information
537 * on memory ordering guarantees.
6ebb237b
PM
538 */
539void synchronize_rcu(void)
540{
fe15d706
PM
541 rcu_lockdep_assert(!lock_is_held(&rcu_bh_lock_map) &&
542 !lock_is_held(&rcu_lock_map) &&
543 !lock_is_held(&rcu_sched_lock_map),
544 "Illegal synchronize_rcu() in RCU read-side critical section");
6ebb237b
PM
545 if (!rcu_scheduler_active)
546 return;
5afff48b 547 if (rcu_gp_is_expedited())
3705b88d
AM
548 synchronize_rcu_expedited();
549 else
550 wait_rcu_gp(call_rcu);
6ebb237b
PM
551}
552EXPORT_SYMBOL_GPL(synchronize_rcu);
553
d9a3da06 554static DECLARE_WAIT_QUEUE_HEAD(sync_rcu_preempt_exp_wq);
bcfa57ce 555static unsigned long sync_rcu_preempt_exp_count;
d9a3da06
PM
556static DEFINE_MUTEX(sync_rcu_preempt_exp_mutex);
557
558/*
559 * Return non-zero if there are any tasks in RCU read-side critical
560 * sections blocking the current preemptible-RCU expedited grace period.
561 * If there is no preemptible-RCU expedited grace period currently in
562 * progress, returns zero unconditionally.
563 */
564static int rcu_preempted_readers_exp(struct rcu_node *rnp)
565{
12f5f524 566 return rnp->exp_tasks != NULL;
d9a3da06
PM
567}
568
569/*
570 * return non-zero if there is no RCU expedited grace period in progress
571 * for the specified rcu_node structure, in other words, if all CPUs and
572 * tasks covered by the specified rcu_node structure have done their bit
573 * for the current expedited grace period. Works only for preemptible
574 * RCU -- other RCU implementation use other means.
575 *
576 * Caller must hold sync_rcu_preempt_exp_mutex.
577 */
578static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
579{
580 return !rcu_preempted_readers_exp(rnp) &&
7d0ae808 581 READ_ONCE(rnp->expmask) == 0;
d9a3da06
PM
582}
583
584/*
585 * Report the exit from RCU read-side critical section for the last task
586 * that queued itself during or before the current expedited preemptible-RCU
587 * grace period. This event is reported either to the rcu_node structure on
588 * which the task was queued or to one of that rcu_node structure's ancestors,
589 * recursively up the tree. (Calm down, calm down, we do the recursion
590 * iteratively!)
591 *
592 * Caller must hold sync_rcu_preempt_exp_mutex.
593 */
b40d293e
TG
594static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp,
595 bool wake)
d9a3da06
PM
596{
597 unsigned long flags;
598 unsigned long mask;
599
1304afb2 600 raw_spin_lock_irqsave(&rnp->lock, flags);
6303b9c8 601 smp_mb__after_unlock_lock();
d9a3da06 602 for (;;) {
131906b0
PM
603 if (!sync_rcu_preempt_exp_done(rnp)) {
604 raw_spin_unlock_irqrestore(&rnp->lock, flags);
d9a3da06 605 break;
131906b0 606 }
d9a3da06 607 if (rnp->parent == NULL) {
131906b0 608 raw_spin_unlock_irqrestore(&rnp->lock, flags);
78e4bc34
PM
609 if (wake) {
610 smp_mb(); /* EGP done before wake_up(). */
b40d293e 611 wake_up(&sync_rcu_preempt_exp_wq);
78e4bc34 612 }
d9a3da06
PM
613 break;
614 }
615 mask = rnp->grpmask;
1304afb2 616 raw_spin_unlock(&rnp->lock); /* irqs remain disabled */
d9a3da06 617 rnp = rnp->parent;
1304afb2 618 raw_spin_lock(&rnp->lock); /* irqs already disabled */
6303b9c8 619 smp_mb__after_unlock_lock();
d9a3da06
PM
620 rnp->expmask &= ~mask;
621 }
d9a3da06
PM
622}
623
624/*
625 * Snapshot the tasks blocking the newly started preemptible-RCU expedited
8eb74b2b
PM
626 * grace period for the specified rcu_node structure, phase 1. If there
627 * are such tasks, set the ->expmask bits up the rcu_node tree and also
628 * set the ->expmask bits on the leaf rcu_node structures to tell phase 2
629 * that work is needed here.
d9a3da06 630 *
8eb74b2b 631 * Caller must hold sync_rcu_preempt_exp_mutex.
d9a3da06
PM
632 */
633static void
8eb74b2b 634sync_rcu_preempt_exp_init1(struct rcu_state *rsp, struct rcu_node *rnp)
d9a3da06 635{
1217ed1b 636 unsigned long flags;
8eb74b2b
PM
637 unsigned long mask;
638 struct rcu_node *rnp_up;
d9a3da06 639
1217ed1b 640 raw_spin_lock_irqsave(&rnp->lock, flags);
6303b9c8 641 smp_mb__after_unlock_lock();
8eb74b2b
PM
642 WARN_ON_ONCE(rnp->expmask);
643 WARN_ON_ONCE(rnp->exp_tasks);
96e92021 644 if (!rcu_preempt_has_tasks(rnp)) {
8eb74b2b 645 /* No blocked tasks, nothing to do. */
1217ed1b 646 raw_spin_unlock_irqrestore(&rnp->lock, flags);
8eb74b2b
PM
647 return;
648 }
649 /* Call for Phase 2 and propagate ->expmask bits up the tree. */
650 rnp->expmask = 1;
651 rnp_up = rnp;
652 while (rnp_up->parent) {
653 mask = rnp_up->grpmask;
654 rnp_up = rnp_up->parent;
655 if (rnp_up->expmask & mask)
656 break;
657 raw_spin_lock(&rnp_up->lock); /* irqs already off */
658 smp_mb__after_unlock_lock();
659 rnp_up->expmask |= mask;
660 raw_spin_unlock(&rnp_up->lock); /* irqs still off */
661 }
662 raw_spin_unlock_irqrestore(&rnp->lock, flags);
663}
664
665/*
666 * Snapshot the tasks blocking the newly started preemptible-RCU expedited
667 * grace period for the specified rcu_node structure, phase 2. If the
668 * leaf rcu_node structure has its ->expmask field set, check for tasks.
669 * If there are some, clear ->expmask and set ->exp_tasks accordingly,
670 * then initiate RCU priority boosting. Otherwise, clear ->expmask and
671 * invoke rcu_report_exp_rnp() to clear out the upper-level ->expmask bits,
672 * enabling rcu_read_unlock_special() to do the bit-clearing.
673 *
674 * Caller must hold sync_rcu_preempt_exp_mutex.
675 */
676static void
677sync_rcu_preempt_exp_init2(struct rcu_state *rsp, struct rcu_node *rnp)
678{
679 unsigned long flags;
680
681 raw_spin_lock_irqsave(&rnp->lock, flags);
682 smp_mb__after_unlock_lock();
683 if (!rnp->expmask) {
684 /* Phase 1 didn't do anything, so Phase 2 doesn't either. */
685 raw_spin_unlock_irqrestore(&rnp->lock, flags);
686 return;
687 }
688
689 /* Phase 1 is over. */
690 rnp->expmask = 0;
691
692 /*
693 * If there are still blocked tasks, set up ->exp_tasks so that
694 * rcu_read_unlock_special() will wake us and then boost them.
695 */
696 if (rcu_preempt_has_tasks(rnp)) {
12f5f524 697 rnp->exp_tasks = rnp->blkd_tasks.next;
1217ed1b 698 rcu_initiate_boost(rnp, flags); /* releases rnp->lock */
8eb74b2b 699 return;
12f5f524 700 }
8eb74b2b
PM
701
702 /* No longer any blocked tasks, so undo bit setting. */
703 raw_spin_unlock_irqrestore(&rnp->lock, flags);
704 rcu_report_exp_rnp(rsp, rnp, false);
d9a3da06
PM
705}
706
236fefaf
PM
707/**
708 * synchronize_rcu_expedited - Brute-force RCU grace period
709 *
710 * Wait for an RCU-preempt grace period, but expedite it. The basic
711 * idea is to invoke synchronize_sched_expedited() to push all the tasks to
712 * the ->blkd_tasks lists and wait for this list to drain. This consumes
713 * significant time on all CPUs and is unfriendly to real-time workloads,
714 * so is thus not recommended for any sort of common-case code.
715 * In fact, if you are using synchronize_rcu_expedited() in a loop,
716 * please restructure your code to batch your updates, and then Use a
717 * single synchronize_rcu() instead.
019129d5
PM
718 */
719void synchronize_rcu_expedited(void)
720{
d9a3da06 721 struct rcu_node *rnp;
e63c887c 722 struct rcu_state *rsp = rcu_state_p;
bcfa57ce 723 unsigned long snap;
d9a3da06
PM
724 int trycount = 0;
725
726 smp_mb(); /* Caller's modifications seen first by other CPUs. */
7d0ae808 727 snap = READ_ONCE(sync_rcu_preempt_exp_count) + 1;
d9a3da06
PM
728 smp_mb(); /* Above access cannot bleed into critical section. */
729
1943c89d
PM
730 /*
731 * Block CPU-hotplug operations. This means that any CPU-hotplug
732 * operation that finds an rcu_node structure with tasks in the
733 * process of being boosted will know that all tasks blocking
734 * this expedited grace period will already be in the process of
735 * being boosted. This simplifies the process of moving tasks
736 * from leaf to root rcu_node structures.
737 */
dd56af42
PM
738 if (!try_get_online_cpus()) {
739 /* CPU-hotplug operation in flight, fall back to normal GP. */
740 wait_rcu_gp(call_rcu);
741 return;
742 }
1943c89d 743
d9a3da06
PM
744 /*
745 * Acquire lock, falling back to synchronize_rcu() if too many
746 * lock-acquisition failures. Of course, if someone does the
747 * expedited grace period for us, just leave.
748 */
749 while (!mutex_trylock(&sync_rcu_preempt_exp_mutex)) {
1943c89d 750 if (ULONG_CMP_LT(snap,
7d0ae808 751 READ_ONCE(sync_rcu_preempt_exp_count))) {
1943c89d
PM
752 put_online_cpus();
753 goto mb_ret; /* Others did our work for us. */
754 }
c701d5d9 755 if (trycount++ < 10) {
d9a3da06 756 udelay(trycount * num_online_cpus());
c701d5d9 757 } else {
1943c89d 758 put_online_cpus();
3705b88d 759 wait_rcu_gp(call_rcu);
d9a3da06
PM
760 return;
761 }
d9a3da06 762 }
7d0ae808 763 if (ULONG_CMP_LT(snap, READ_ONCE(sync_rcu_preempt_exp_count))) {
1943c89d 764 put_online_cpus();
d9a3da06 765 goto unlock_mb_ret; /* Others did our work for us. */
1943c89d 766 }
d9a3da06 767
12f5f524 768 /* force all RCU readers onto ->blkd_tasks lists. */
d9a3da06
PM
769 synchronize_sched_expedited();
770
8eb74b2b
PM
771 /*
772 * Snapshot current state of ->blkd_tasks lists into ->expmask.
773 * Phase 1 sets bits and phase 2 permits rcu_read_unlock_special()
774 * to start clearing them. Doing this in one phase leads to
775 * strange races between setting and clearing bits, so just say "no"!
776 */
d9a3da06 777 rcu_for_each_leaf_node(rsp, rnp)
8eb74b2b 778 sync_rcu_preempt_exp_init1(rsp, rnp);
d9a3da06 779 rcu_for_each_leaf_node(rsp, rnp)
8eb74b2b 780 sync_rcu_preempt_exp_init2(rsp, rnp);
d9a3da06 781
1943c89d 782 put_online_cpus();
d9a3da06 783
12f5f524 784 /* Wait for snapshotted ->blkd_tasks lists to drain. */
d9a3da06
PM
785 rnp = rcu_get_root(rsp);
786 wait_event(sync_rcu_preempt_exp_wq,
787 sync_rcu_preempt_exp_done(rnp));
788
789 /* Clean up and exit. */
790 smp_mb(); /* ensure expedited GP seen before counter increment. */
7d0ae808 791 WRITE_ONCE(sync_rcu_preempt_exp_count, sync_rcu_preempt_exp_count + 1);
d9a3da06
PM
792unlock_mb_ret:
793 mutex_unlock(&sync_rcu_preempt_exp_mutex);
794mb_ret:
795 smp_mb(); /* ensure subsequent action seen after grace period. */
019129d5
PM
796}
797EXPORT_SYMBOL_GPL(synchronize_rcu_expedited);
798
e74f4c45
PM
799/**
800 * rcu_barrier - Wait until all in-flight call_rcu() callbacks complete.
f0a0e6f2
PM
801 *
802 * Note that this primitive does not necessarily wait for an RCU grace period
803 * to complete. For example, if there are no RCU callbacks queued anywhere
804 * in the system, then rcu_barrier() is within its rights to return
805 * immediately, without waiting for anything, much less an RCU grace period.
e74f4c45
PM
806 */
807void rcu_barrier(void)
808{
e63c887c 809 _rcu_barrier(rcu_state_p);
e74f4c45
PM
810}
811EXPORT_SYMBOL_GPL(rcu_barrier);
812
1eba8f84 813/*
6cc68793 814 * Initialize preemptible RCU's state structures.
1eba8f84
PM
815 */
816static void __init __rcu_init_preempt(void)
817{
2927a689 818 rcu_init_one(rcu_state_p, rcu_data_p);
1eba8f84
PM
819}
820
2439b696
PM
821/*
822 * Check for a task exiting while in a preemptible-RCU read-side
823 * critical section, clean up if so. No need to issue warnings,
824 * as debug_check_no_locks_held() already does this if lockdep
825 * is enabled.
826 */
827void exit_rcu(void)
828{
829 struct task_struct *t = current;
830
831 if (likely(list_empty(&current->rcu_node_entry)))
832 return;
833 t->rcu_read_lock_nesting = 1;
834 barrier();
1d082fd0 835 t->rcu_read_unlock_special.b.blocked = true;
2439b696
PM
836 __rcu_read_unlock();
837}
838
28f6569a 839#else /* #ifdef CONFIG_PREEMPT_RCU */
f41d911f 840
b28a7c01 841static struct rcu_state *const rcu_state_p = &rcu_sched_state;
2927a689 842static struct rcu_data __percpu *const rcu_data_p = &rcu_sched_data;
27f4d280 843
f41d911f
PM
844/*
845 * Tell them what RCU they are running.
846 */
0e0fc1c2 847static void __init rcu_bootup_announce(void)
f41d911f 848{
efc151c3 849 pr_info("Hierarchical RCU implementation.\n");
26845c28 850 rcu_bootup_announce_oddness();
f41d911f
PM
851}
852
cba6d0d6
PM
853/*
854 * Because preemptible RCU does not exist, we never have to check for
855 * CPUs being in quiescent states.
856 */
38200cf2 857static void rcu_preempt_note_context_switch(void)
cba6d0d6
PM
858{
859}
860
fc2219d4 861/*
6cc68793 862 * Because preemptible RCU does not exist, there are never any preempted
fc2219d4
PM
863 * RCU readers.
864 */
27f4d280 865static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp)
fc2219d4
PM
866{
867 return 0;
868}
869
8af3a5e7
PM
870/*
871 * Because there is no preemptible RCU, there can be no readers blocked.
872 */
873static bool rcu_preempt_has_tasks(struct rcu_node *rnp)
b668c9cf 874{
8af3a5e7 875 return false;
b668c9cf
PM
876}
877
1ed509a2 878/*
6cc68793 879 * Because preemptible RCU does not exist, we never have to check for
1ed509a2
PM
880 * tasks blocked within RCU read-side critical sections.
881 */
882static void rcu_print_detail_task_stall(struct rcu_state *rsp)
883{
884}
885
f41d911f 886/*
6cc68793 887 * Because preemptible RCU does not exist, we never have to check for
f41d911f
PM
888 * tasks blocked within RCU read-side critical sections.
889 */
9bc8b558 890static int rcu_print_task_stall(struct rcu_node *rnp)
f41d911f 891{
9bc8b558 892 return 0;
f41d911f
PM
893}
894
b0e165c0 895/*
6cc68793 896 * Because there is no preemptible RCU, there can be no readers blocked,
49e29126
PM
897 * so there is no need to check for blocked tasks. So check only for
898 * bogus qsmask values.
b0e165c0
PM
899 */
900static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp)
901{
49e29126 902 WARN_ON_ONCE(rnp->qsmask);
b0e165c0
PM
903}
904
f41d911f 905/*
6cc68793 906 * Because preemptible RCU does not exist, it never has any callbacks
f41d911f
PM
907 * to check.
908 */
86aea0e6 909static void rcu_preempt_check_callbacks(void)
f41d911f
PM
910{
911}
912
019129d5
PM
913/*
914 * Wait for an rcu-preempt grace period, but make it happen quickly.
6cc68793 915 * But because preemptible RCU does not exist, map to rcu-sched.
019129d5
PM
916 */
917void synchronize_rcu_expedited(void)
918{
919 synchronize_sched_expedited();
920}
921EXPORT_SYMBOL_GPL(synchronize_rcu_expedited);
922
e74f4c45 923/*
6cc68793 924 * Because preemptible RCU does not exist, rcu_barrier() is just
e74f4c45
PM
925 * another name for rcu_barrier_sched().
926 */
927void rcu_barrier(void)
928{
929 rcu_barrier_sched();
930}
931EXPORT_SYMBOL_GPL(rcu_barrier);
932
1eba8f84 933/*
6cc68793 934 * Because preemptible RCU does not exist, it need not be initialized.
1eba8f84
PM
935 */
936static void __init __rcu_init_preempt(void)
937{
938}
939
2439b696
PM
940/*
941 * Because preemptible RCU does not exist, tasks cannot possibly exit
942 * while in preemptible RCU read-side critical sections.
943 */
944void exit_rcu(void)
945{
946}
947
28f6569a 948#endif /* #else #ifdef CONFIG_PREEMPT_RCU */
8bd93a2c 949
27f4d280
PM
950#ifdef CONFIG_RCU_BOOST
951
1696a8be 952#include "../locking/rtmutex_common.h"
27f4d280 953
0ea1f2eb
PM
954#ifdef CONFIG_RCU_TRACE
955
956static void rcu_initiate_boost_trace(struct rcu_node *rnp)
957{
96e92021 958 if (!rcu_preempt_has_tasks(rnp))
0ea1f2eb
PM
959 rnp->n_balk_blkd_tasks++;
960 else if (rnp->exp_tasks == NULL && rnp->gp_tasks == NULL)
961 rnp->n_balk_exp_gp_tasks++;
962 else if (rnp->gp_tasks != NULL && rnp->boost_tasks != NULL)
963 rnp->n_balk_boost_tasks++;
964 else if (rnp->gp_tasks != NULL && rnp->qsmask != 0)
965 rnp->n_balk_notblocked++;
966 else if (rnp->gp_tasks != NULL &&
a9f4793d 967 ULONG_CMP_LT(jiffies, rnp->boost_time))
0ea1f2eb
PM
968 rnp->n_balk_notyet++;
969 else
970 rnp->n_balk_nos++;
971}
972
973#else /* #ifdef CONFIG_RCU_TRACE */
974
975static void rcu_initiate_boost_trace(struct rcu_node *rnp)
976{
977}
978
979#endif /* #else #ifdef CONFIG_RCU_TRACE */
980
5d01bbd1
TG
981static void rcu_wake_cond(struct task_struct *t, int status)
982{
983 /*
984 * If the thread is yielding, only wake it when this
985 * is invoked from idle
986 */
987 if (status != RCU_KTHREAD_YIELDING || is_idle_task(current))
988 wake_up_process(t);
989}
990
27f4d280
PM
991/*
992 * Carry out RCU priority boosting on the task indicated by ->exp_tasks
993 * or ->boost_tasks, advancing the pointer to the next task in the
994 * ->blkd_tasks list.
995 *
996 * Note that irqs must be enabled: boosting the task can block.
997 * Returns 1 if there are more tasks needing to be boosted.
998 */
999static int rcu_boost(struct rcu_node *rnp)
1000{
1001 unsigned long flags;
27f4d280
PM
1002 struct task_struct *t;
1003 struct list_head *tb;
1004
7d0ae808
PM
1005 if (READ_ONCE(rnp->exp_tasks) == NULL &&
1006 READ_ONCE(rnp->boost_tasks) == NULL)
27f4d280
PM
1007 return 0; /* Nothing left to boost. */
1008
1009 raw_spin_lock_irqsave(&rnp->lock, flags);
6303b9c8 1010 smp_mb__after_unlock_lock();
27f4d280
PM
1011
1012 /*
1013 * Recheck under the lock: all tasks in need of boosting
1014 * might exit their RCU read-side critical sections on their own.
1015 */
1016 if (rnp->exp_tasks == NULL && rnp->boost_tasks == NULL) {
1017 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1018 return 0;
1019 }
1020
1021 /*
1022 * Preferentially boost tasks blocking expedited grace periods.
1023 * This cannot starve the normal grace periods because a second
1024 * expedited grace period must boost all blocked tasks, including
1025 * those blocking the pre-existing normal grace period.
1026 */
0ea1f2eb 1027 if (rnp->exp_tasks != NULL) {
27f4d280 1028 tb = rnp->exp_tasks;
0ea1f2eb
PM
1029 rnp->n_exp_boosts++;
1030 } else {
27f4d280 1031 tb = rnp->boost_tasks;
0ea1f2eb
PM
1032 rnp->n_normal_boosts++;
1033 }
1034 rnp->n_tasks_boosted++;
27f4d280
PM
1035
1036 /*
1037 * We boost task t by manufacturing an rt_mutex that appears to
1038 * be held by task t. We leave a pointer to that rt_mutex where
1039 * task t can find it, and task t will release the mutex when it
1040 * exits its outermost RCU read-side critical section. Then
1041 * simply acquiring this artificial rt_mutex will boost task
1042 * t's priority. (Thanks to tglx for suggesting this approach!)
1043 *
1044 * Note that task t must acquire rnp->lock to remove itself from
1045 * the ->blkd_tasks list, which it will do from exit() if from
1046 * nowhere else. We therefore are guaranteed that task t will
1047 * stay around at least until we drop rnp->lock. Note that
1048 * rnp->lock also resolves races between our priority boosting
1049 * and task t's exiting its outermost RCU read-side critical
1050 * section.
1051 */
1052 t = container_of(tb, struct task_struct, rcu_node_entry);
abaa93d9 1053 rt_mutex_init_proxy_locked(&rnp->boost_mtx, t);
27f4d280 1054 raw_spin_unlock_irqrestore(&rnp->lock, flags);
abaa93d9
PM
1055 /* Lock only for side effect: boosts task t's priority. */
1056 rt_mutex_lock(&rnp->boost_mtx);
1057 rt_mutex_unlock(&rnp->boost_mtx); /* Then keep lockdep happy. */
27f4d280 1058
7d0ae808
PM
1059 return READ_ONCE(rnp->exp_tasks) != NULL ||
1060 READ_ONCE(rnp->boost_tasks) != NULL;
27f4d280
PM
1061}
1062
27f4d280 1063/*
bc17ea10 1064 * Priority-boosting kthread, one per leaf rcu_node.
27f4d280
PM
1065 */
1066static int rcu_boost_kthread(void *arg)
1067{
1068 struct rcu_node *rnp = (struct rcu_node *)arg;
1069 int spincnt = 0;
1070 int more2boost;
1071
f7f7bac9 1072 trace_rcu_utilization(TPS("Start boost kthread@init"));
27f4d280 1073 for (;;) {
d71df90e 1074 rnp->boost_kthread_status = RCU_KTHREAD_WAITING;
f7f7bac9 1075 trace_rcu_utilization(TPS("End boost kthread@rcu_wait"));
08bca60a 1076 rcu_wait(rnp->boost_tasks || rnp->exp_tasks);
f7f7bac9 1077 trace_rcu_utilization(TPS("Start boost kthread@rcu_wait"));
d71df90e 1078 rnp->boost_kthread_status = RCU_KTHREAD_RUNNING;
27f4d280
PM
1079 more2boost = rcu_boost(rnp);
1080 if (more2boost)
1081 spincnt++;
1082 else
1083 spincnt = 0;
1084 if (spincnt > 10) {
5d01bbd1 1085 rnp->boost_kthread_status = RCU_KTHREAD_YIELDING;
f7f7bac9 1086 trace_rcu_utilization(TPS("End boost kthread@rcu_yield"));
5d01bbd1 1087 schedule_timeout_interruptible(2);
f7f7bac9 1088 trace_rcu_utilization(TPS("Start boost kthread@rcu_yield"));
27f4d280
PM
1089 spincnt = 0;
1090 }
1091 }
1217ed1b 1092 /* NOTREACHED */
f7f7bac9 1093 trace_rcu_utilization(TPS("End boost kthread@notreached"));
27f4d280
PM
1094 return 0;
1095}
1096
1097/*
1098 * Check to see if it is time to start boosting RCU readers that are
1099 * blocking the current grace period, and, if so, tell the per-rcu_node
1100 * kthread to start boosting them. If there is an expedited grace
1101 * period in progress, it is always time to boost.
1102 *
b065a853
PM
1103 * The caller must hold rnp->lock, which this function releases.
1104 * The ->boost_kthread_task is immortal, so we don't need to worry
1105 * about it going away.
27f4d280 1106 */
1217ed1b 1107static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags)
615e41c6 1108 __releases(rnp->lock)
27f4d280
PM
1109{
1110 struct task_struct *t;
1111
0ea1f2eb
PM
1112 if (!rcu_preempt_blocked_readers_cgp(rnp) && rnp->exp_tasks == NULL) {
1113 rnp->n_balk_exp_gp_tasks++;
1217ed1b 1114 raw_spin_unlock_irqrestore(&rnp->lock, flags);
27f4d280 1115 return;
0ea1f2eb 1116 }
27f4d280
PM
1117 if (rnp->exp_tasks != NULL ||
1118 (rnp->gp_tasks != NULL &&
1119 rnp->boost_tasks == NULL &&
1120 rnp->qsmask == 0 &&
1121 ULONG_CMP_GE(jiffies, rnp->boost_time))) {
1122 if (rnp->exp_tasks == NULL)
1123 rnp->boost_tasks = rnp->gp_tasks;
1217ed1b 1124 raw_spin_unlock_irqrestore(&rnp->lock, flags);
27f4d280 1125 t = rnp->boost_kthread_task;
5d01bbd1
TG
1126 if (t)
1127 rcu_wake_cond(t, rnp->boost_kthread_status);
1217ed1b 1128 } else {
0ea1f2eb 1129 rcu_initiate_boost_trace(rnp);
1217ed1b
PM
1130 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1131 }
27f4d280
PM
1132}
1133
a46e0899
PM
1134/*
1135 * Wake up the per-CPU kthread to invoke RCU callbacks.
1136 */
1137static void invoke_rcu_callbacks_kthread(void)
1138{
1139 unsigned long flags;
1140
1141 local_irq_save(flags);
1142 __this_cpu_write(rcu_cpu_has_work, 1);
1eb52121 1143 if (__this_cpu_read(rcu_cpu_kthread_task) != NULL &&
5d01bbd1
TG
1144 current != __this_cpu_read(rcu_cpu_kthread_task)) {
1145 rcu_wake_cond(__this_cpu_read(rcu_cpu_kthread_task),
1146 __this_cpu_read(rcu_cpu_kthread_status));
1147 }
a46e0899
PM
1148 local_irq_restore(flags);
1149}
1150
dff1672d
PM
1151/*
1152 * Is the current CPU running the RCU-callbacks kthread?
1153 * Caller must have preemption disabled.
1154 */
1155static bool rcu_is_callbacks_kthread(void)
1156{
c9d4b0af 1157 return __this_cpu_read(rcu_cpu_kthread_task) == current;
dff1672d
PM
1158}
1159
27f4d280
PM
1160#define RCU_BOOST_DELAY_JIFFIES DIV_ROUND_UP(CONFIG_RCU_BOOST_DELAY * HZ, 1000)
1161
1162/*
1163 * Do priority-boost accounting for the start of a new grace period.
1164 */
1165static void rcu_preempt_boost_start_gp(struct rcu_node *rnp)
1166{
1167 rnp->boost_time = jiffies + RCU_BOOST_DELAY_JIFFIES;
1168}
1169
27f4d280
PM
1170/*
1171 * Create an RCU-boost kthread for the specified node if one does not
1172 * already exist. We only create this kthread for preemptible RCU.
1173 * Returns zero if all is well, a negated errno otherwise.
1174 */
49fb4c62 1175static int rcu_spawn_one_boost_kthread(struct rcu_state *rsp,
0aa04b05 1176 struct rcu_node *rnp)
27f4d280 1177{
5d01bbd1 1178 int rnp_index = rnp - &rsp->node[0];
27f4d280
PM
1179 unsigned long flags;
1180 struct sched_param sp;
1181 struct task_struct *t;
1182
e63c887c 1183 if (rcu_state_p != rsp)
27f4d280 1184 return 0;
5d01bbd1 1185
0aa04b05 1186 if (!rcu_scheduler_fully_active || rcu_rnp_online_cpus(rnp) == 0)
5d01bbd1
TG
1187 return 0;
1188
a46e0899 1189 rsp->boost = 1;
27f4d280
PM
1190 if (rnp->boost_kthread_task != NULL)
1191 return 0;
1192 t = kthread_create(rcu_boost_kthread, (void *)rnp,
5b61b0ba 1193 "rcub/%d", rnp_index);
27f4d280
PM
1194 if (IS_ERR(t))
1195 return PTR_ERR(t);
1196 raw_spin_lock_irqsave(&rnp->lock, flags);
6303b9c8 1197 smp_mb__after_unlock_lock();
27f4d280
PM
1198 rnp->boost_kthread_task = t;
1199 raw_spin_unlock_irqrestore(&rnp->lock, flags);
21871d7e 1200 sp.sched_priority = kthread_prio;
27f4d280 1201 sched_setscheduler_nocheck(t, SCHED_FIFO, &sp);
9a432736 1202 wake_up_process(t); /* get to TASK_INTERRUPTIBLE quickly. */
27f4d280
PM
1203 return 0;
1204}
1205
f8b7fc6b
PM
1206static void rcu_kthread_do_work(void)
1207{
c9d4b0af
CL
1208 rcu_do_batch(&rcu_sched_state, this_cpu_ptr(&rcu_sched_data));
1209 rcu_do_batch(&rcu_bh_state, this_cpu_ptr(&rcu_bh_data));
f8b7fc6b
PM
1210 rcu_preempt_do_callbacks();
1211}
1212
62ab7072 1213static void rcu_cpu_kthread_setup(unsigned int cpu)
f8b7fc6b 1214{
f8b7fc6b 1215 struct sched_param sp;
f8b7fc6b 1216
21871d7e 1217 sp.sched_priority = kthread_prio;
62ab7072 1218 sched_setscheduler_nocheck(current, SCHED_FIFO, &sp);
f8b7fc6b
PM
1219}
1220
62ab7072 1221static void rcu_cpu_kthread_park(unsigned int cpu)
f8b7fc6b 1222{
62ab7072 1223 per_cpu(rcu_cpu_kthread_status, cpu) = RCU_KTHREAD_OFFCPU;
f8b7fc6b
PM
1224}
1225
62ab7072 1226static int rcu_cpu_kthread_should_run(unsigned int cpu)
f8b7fc6b 1227{
c9d4b0af 1228 return __this_cpu_read(rcu_cpu_has_work);
f8b7fc6b
PM
1229}
1230
1231/*
1232 * Per-CPU kernel thread that invokes RCU callbacks. This replaces the
e0f23060
PM
1233 * RCU softirq used in flavors and configurations of RCU that do not
1234 * support RCU priority boosting.
f8b7fc6b 1235 */
62ab7072 1236static void rcu_cpu_kthread(unsigned int cpu)
f8b7fc6b 1237{
c9d4b0af
CL
1238 unsigned int *statusp = this_cpu_ptr(&rcu_cpu_kthread_status);
1239 char work, *workp = this_cpu_ptr(&rcu_cpu_has_work);
62ab7072 1240 int spincnt;
f8b7fc6b 1241
62ab7072 1242 for (spincnt = 0; spincnt < 10; spincnt++) {
f7f7bac9 1243 trace_rcu_utilization(TPS("Start CPU kthread@rcu_wait"));
f8b7fc6b 1244 local_bh_disable();
f8b7fc6b 1245 *statusp = RCU_KTHREAD_RUNNING;
62ab7072
PM
1246 this_cpu_inc(rcu_cpu_kthread_loops);
1247 local_irq_disable();
f8b7fc6b
PM
1248 work = *workp;
1249 *workp = 0;
62ab7072 1250 local_irq_enable();
f8b7fc6b
PM
1251 if (work)
1252 rcu_kthread_do_work();
1253 local_bh_enable();
62ab7072 1254 if (*workp == 0) {
f7f7bac9 1255 trace_rcu_utilization(TPS("End CPU kthread@rcu_wait"));
62ab7072
PM
1256 *statusp = RCU_KTHREAD_WAITING;
1257 return;
f8b7fc6b
PM
1258 }
1259 }
62ab7072 1260 *statusp = RCU_KTHREAD_YIELDING;
f7f7bac9 1261 trace_rcu_utilization(TPS("Start CPU kthread@rcu_yield"));
62ab7072 1262 schedule_timeout_interruptible(2);
f7f7bac9 1263 trace_rcu_utilization(TPS("End CPU kthread@rcu_yield"));
62ab7072 1264 *statusp = RCU_KTHREAD_WAITING;
f8b7fc6b
PM
1265}
1266
1267/*
1268 * Set the per-rcu_node kthread's affinity to cover all CPUs that are
1269 * served by the rcu_node in question. The CPU hotplug lock is still
1270 * held, so the value of rnp->qsmaskinit will be stable.
1271 *
1272 * We don't include outgoingcpu in the affinity set, use -1 if there is
1273 * no outgoing CPU. If there are no CPUs left in the affinity set,
1274 * this function allows the kthread to execute on any CPU.
1275 */
5d01bbd1 1276static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
f8b7fc6b 1277{
5d01bbd1 1278 struct task_struct *t = rnp->boost_kthread_task;
0aa04b05 1279 unsigned long mask = rcu_rnp_online_cpus(rnp);
f8b7fc6b
PM
1280 cpumask_var_t cm;
1281 int cpu;
f8b7fc6b 1282
5d01bbd1 1283 if (!t)
f8b7fc6b 1284 return;
5d01bbd1 1285 if (!zalloc_cpumask_var(&cm, GFP_KERNEL))
f8b7fc6b 1286 return;
f8b7fc6b
PM
1287 for (cpu = rnp->grplo; cpu <= rnp->grphi; cpu++, mask >>= 1)
1288 if ((mask & 0x1) && cpu != outgoingcpu)
1289 cpumask_set_cpu(cpu, cm);
5d0b0249 1290 if (cpumask_weight(cm) == 0)
f8b7fc6b 1291 cpumask_setall(cm);
5d01bbd1 1292 set_cpus_allowed_ptr(t, cm);
f8b7fc6b
PM
1293 free_cpumask_var(cm);
1294}
1295
62ab7072
PM
1296static struct smp_hotplug_thread rcu_cpu_thread_spec = {
1297 .store = &rcu_cpu_kthread_task,
1298 .thread_should_run = rcu_cpu_kthread_should_run,
1299 .thread_fn = rcu_cpu_kthread,
1300 .thread_comm = "rcuc/%u",
1301 .setup = rcu_cpu_kthread_setup,
1302 .park = rcu_cpu_kthread_park,
1303};
f8b7fc6b
PM
1304
1305/*
9386c0b7 1306 * Spawn boost kthreads -- called as soon as the scheduler is running.
f8b7fc6b 1307 */
9386c0b7 1308static void __init rcu_spawn_boost_kthreads(void)
f8b7fc6b 1309{
f8b7fc6b 1310 struct rcu_node *rnp;
5d01bbd1 1311 int cpu;
f8b7fc6b 1312
62ab7072 1313 for_each_possible_cpu(cpu)
f8b7fc6b 1314 per_cpu(rcu_cpu_has_work, cpu) = 0;
62ab7072 1315 BUG_ON(smpboot_register_percpu_thread(&rcu_cpu_thread_spec));
3e9f5c70
PM
1316 rcu_for_each_leaf_node(rcu_state_p, rnp)
1317 (void)rcu_spawn_one_boost_kthread(rcu_state_p, rnp);
f8b7fc6b 1318}
f8b7fc6b 1319
49fb4c62 1320static void rcu_prepare_kthreads(int cpu)
f8b7fc6b 1321{
e534165b 1322 struct rcu_data *rdp = per_cpu_ptr(rcu_state_p->rda, cpu);
f8b7fc6b
PM
1323 struct rcu_node *rnp = rdp->mynode;
1324
1325 /* Fire up the incoming CPU's kthread and leaf rcu_node kthread. */
62ab7072 1326 if (rcu_scheduler_fully_active)
e534165b 1327 (void)rcu_spawn_one_boost_kthread(rcu_state_p, rnp);
f8b7fc6b
PM
1328}
1329
27f4d280
PM
1330#else /* #ifdef CONFIG_RCU_BOOST */
1331
1217ed1b 1332static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags)
615e41c6 1333 __releases(rnp->lock)
27f4d280 1334{
1217ed1b 1335 raw_spin_unlock_irqrestore(&rnp->lock, flags);
27f4d280
PM
1336}
1337
a46e0899 1338static void invoke_rcu_callbacks_kthread(void)
27f4d280 1339{
a46e0899 1340 WARN_ON_ONCE(1);
27f4d280
PM
1341}
1342
dff1672d
PM
1343static bool rcu_is_callbacks_kthread(void)
1344{
1345 return false;
1346}
1347
27f4d280
PM
1348static void rcu_preempt_boost_start_gp(struct rcu_node *rnp)
1349{
1350}
1351
5d01bbd1 1352static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
f8b7fc6b
PM
1353{
1354}
1355
9386c0b7 1356static void __init rcu_spawn_boost_kthreads(void)
b0d30417 1357{
b0d30417 1358}
b0d30417 1359
49fb4c62 1360static void rcu_prepare_kthreads(int cpu)
f8b7fc6b
PM
1361{
1362}
1363
27f4d280
PM
1364#endif /* #else #ifdef CONFIG_RCU_BOOST */
1365
8bd93a2c
PM
1366#if !defined(CONFIG_RCU_FAST_NO_HZ)
1367
1368/*
1369 * Check to see if any future RCU-related work will need to be done
1370 * by the current CPU, even if none need be done immediately, returning
1371 * 1 if so. This function is part of the RCU implementation; it is -not-
1372 * an exported member of the RCU API.
1373 *
7cb92499
PM
1374 * Because we not have RCU_FAST_NO_HZ, just check whether this CPU needs
1375 * any flavor of RCU.
8bd93a2c 1376 */
c1ad348b 1377int rcu_needs_cpu(u64 basemono, u64 *nextevt)
8bd93a2c 1378{
c1ad348b 1379 *nextevt = KTIME_MAX;
3382adbc
PM
1380 return IS_ENABLED(CONFIG_RCU_NOCB_CPU_ALL)
1381 ? 0 : rcu_cpu_has_callbacks(NULL);
7cb92499
PM
1382}
1383
1384/*
1385 * Because we do not have RCU_FAST_NO_HZ, don't bother cleaning up
1386 * after it.
1387 */
8fa7845d 1388static void rcu_cleanup_after_idle(void)
7cb92499
PM
1389{
1390}
1391
aea1b35e 1392/*
a858af28 1393 * Do the idle-entry grace-period work, which, because CONFIG_RCU_FAST_NO_HZ=n,
aea1b35e
PM
1394 * is nothing.
1395 */
198bbf81 1396static void rcu_prepare_for_idle(void)
aea1b35e
PM
1397{
1398}
1399
c57afe80
PM
1400/*
1401 * Don't bother keeping a running count of the number of RCU callbacks
1402 * posted because CONFIG_RCU_FAST_NO_HZ=n.
1403 */
1404static void rcu_idle_count_callbacks_posted(void)
1405{
1406}
1407
8bd93a2c
PM
1408#else /* #if !defined(CONFIG_RCU_FAST_NO_HZ) */
1409
f23f7fa1
PM
1410/*
1411 * This code is invoked when a CPU goes idle, at which point we want
1412 * to have the CPU do everything required for RCU so that it can enter
1413 * the energy-efficient dyntick-idle mode. This is handled by a
1414 * state machine implemented by rcu_prepare_for_idle() below.
1415 *
1416 * The following three proprocessor symbols control this state machine:
1417 *
f23f7fa1
PM
1418 * RCU_IDLE_GP_DELAY gives the number of jiffies that a CPU is permitted
1419 * to sleep in dyntick-idle mode with RCU callbacks pending. This
1420 * is sized to be roughly one RCU grace period. Those energy-efficiency
1421 * benchmarkers who might otherwise be tempted to set this to a large
1422 * number, be warned: Setting RCU_IDLE_GP_DELAY too high can hang your
1423 * system. And if you are -that- concerned about energy efficiency,
1424 * just power the system down and be done with it!
778d250a
PM
1425 * RCU_IDLE_LAZY_GP_DELAY gives the number of jiffies that a CPU is
1426 * permitted to sleep in dyntick-idle mode with only lazy RCU
1427 * callbacks pending. Setting this too high can OOM your system.
f23f7fa1
PM
1428 *
1429 * The values below work well in practice. If future workloads require
1430 * adjustment, they can be converted into kernel config parameters, though
1431 * making the state machine smarter might be a better option.
1432 */
e84c48ae 1433#define RCU_IDLE_GP_DELAY 4 /* Roughly one grace period. */
778d250a 1434#define RCU_IDLE_LAZY_GP_DELAY (6 * HZ) /* Roughly six seconds. */
f23f7fa1 1435
5e44ce35
PM
1436static int rcu_idle_gp_delay = RCU_IDLE_GP_DELAY;
1437module_param(rcu_idle_gp_delay, int, 0644);
1438static int rcu_idle_lazy_gp_delay = RCU_IDLE_LAZY_GP_DELAY;
1439module_param(rcu_idle_lazy_gp_delay, int, 0644);
486e2593 1440
486e2593 1441/*
c229828c
PM
1442 * Try to advance callbacks for all flavors of RCU on the current CPU, but
1443 * only if it has been awhile since the last time we did so. Afterwards,
1444 * if there are any callbacks ready for immediate invocation, return true.
486e2593 1445 */
f1f399d1 1446static bool __maybe_unused rcu_try_advance_all_cbs(void)
486e2593 1447{
c0f4dfd4
PM
1448 bool cbs_ready = false;
1449 struct rcu_data *rdp;
c229828c 1450 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
c0f4dfd4
PM
1451 struct rcu_node *rnp;
1452 struct rcu_state *rsp;
486e2593 1453
c229828c
PM
1454 /* Exit early if we advanced recently. */
1455 if (jiffies == rdtp->last_advance_all)
d0bc90fd 1456 return false;
c229828c
PM
1457 rdtp->last_advance_all = jiffies;
1458
c0f4dfd4
PM
1459 for_each_rcu_flavor(rsp) {
1460 rdp = this_cpu_ptr(rsp->rda);
1461 rnp = rdp->mynode;
486e2593 1462
c0f4dfd4
PM
1463 /*
1464 * Don't bother checking unless a grace period has
1465 * completed since we last checked and there are
1466 * callbacks not yet ready to invoke.
1467 */
e3663b10 1468 if ((rdp->completed != rnp->completed ||
7d0ae808 1469 unlikely(READ_ONCE(rdp->gpwrap))) &&
c0f4dfd4 1470 rdp->nxttail[RCU_DONE_TAIL] != rdp->nxttail[RCU_NEXT_TAIL])
470716fc 1471 note_gp_changes(rsp, rdp);
486e2593 1472
c0f4dfd4
PM
1473 if (cpu_has_callbacks_ready_to_invoke(rdp))
1474 cbs_ready = true;
1475 }
1476 return cbs_ready;
486e2593
PM
1477}
1478
aa9b1630 1479/*
c0f4dfd4
PM
1480 * Allow the CPU to enter dyntick-idle mode unless it has callbacks ready
1481 * to invoke. If the CPU has callbacks, try to advance them. Tell the
1482 * caller to set the timeout based on whether or not there are non-lazy
1483 * callbacks.
aa9b1630 1484 *
c0f4dfd4 1485 * The caller must have disabled interrupts.
aa9b1630 1486 */
c1ad348b 1487int rcu_needs_cpu(u64 basemono, u64 *nextevt)
aa9b1630 1488{
aa6da514 1489 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
c1ad348b 1490 unsigned long dj;
aa9b1630 1491
3382adbc 1492 if (IS_ENABLED(CONFIG_RCU_NOCB_CPU_ALL)) {
43224b96 1493 *nextevt = KTIME_MAX;
3382adbc
PM
1494 return 0;
1495 }
1496
c0f4dfd4
PM
1497 /* Snapshot to detect later posting of non-lazy callback. */
1498 rdtp->nonlazy_posted_snap = rdtp->nonlazy_posted;
1499
aa9b1630 1500 /* If no callbacks, RCU doesn't need the CPU. */
aa6da514 1501 if (!rcu_cpu_has_callbacks(&rdtp->all_lazy)) {
c1ad348b 1502 *nextevt = KTIME_MAX;
aa9b1630
PM
1503 return 0;
1504 }
c0f4dfd4
PM
1505
1506 /* Attempt to advance callbacks. */
1507 if (rcu_try_advance_all_cbs()) {
1508 /* Some ready to invoke, so initiate later invocation. */
1509 invoke_rcu_core();
aa9b1630
PM
1510 return 1;
1511 }
c0f4dfd4
PM
1512 rdtp->last_accelerate = jiffies;
1513
1514 /* Request timer delay depending on laziness, and round. */
6faf7283 1515 if (!rdtp->all_lazy) {
c1ad348b 1516 dj = round_up(rcu_idle_gp_delay + jiffies,
c0f4dfd4 1517 rcu_idle_gp_delay) - jiffies;
e84c48ae 1518 } else {
c1ad348b 1519 dj = round_jiffies(rcu_idle_lazy_gp_delay + jiffies) - jiffies;
e84c48ae 1520 }
c1ad348b 1521 *nextevt = basemono + dj * TICK_NSEC;
aa9b1630
PM
1522 return 0;
1523}
1524
21e52e15 1525/*
c0f4dfd4
PM
1526 * Prepare a CPU for idle from an RCU perspective. The first major task
1527 * is to sense whether nohz mode has been enabled or disabled via sysfs.
1528 * The second major task is to check to see if a non-lazy callback has
1529 * arrived at a CPU that previously had only lazy callbacks. The third
1530 * major task is to accelerate (that is, assign grace-period numbers to)
1531 * any recently arrived callbacks.
aea1b35e
PM
1532 *
1533 * The caller must have disabled interrupts.
8bd93a2c 1534 */
198bbf81 1535static void rcu_prepare_for_idle(void)
8bd93a2c 1536{
48a7639c 1537 bool needwake;
c0f4dfd4 1538 struct rcu_data *rdp;
198bbf81 1539 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
c0f4dfd4
PM
1540 struct rcu_node *rnp;
1541 struct rcu_state *rsp;
9d2ad243
PM
1542 int tne;
1543
3382adbc
PM
1544 if (IS_ENABLED(CONFIG_RCU_NOCB_CPU_ALL))
1545 return;
1546
9d2ad243 1547 /* Handle nohz enablement switches conservatively. */
7d0ae808 1548 tne = READ_ONCE(tick_nohz_active);
9d2ad243 1549 if (tne != rdtp->tick_nohz_enabled_snap) {
aa6da514 1550 if (rcu_cpu_has_callbacks(NULL))
9d2ad243
PM
1551 invoke_rcu_core(); /* force nohz to see update. */
1552 rdtp->tick_nohz_enabled_snap = tne;
1553 return;
1554 }
1555 if (!tne)
1556 return;
f511fc62 1557
c0f4dfd4 1558 /* If this is a no-CBs CPU, no callbacks, just return. */
198bbf81 1559 if (rcu_is_nocb_cpu(smp_processor_id()))
9a0c6fef 1560 return;
9a0c6fef 1561
c57afe80 1562 /*
c0f4dfd4
PM
1563 * If a non-lazy callback arrived at a CPU having only lazy
1564 * callbacks, invoke RCU core for the side-effect of recalculating
1565 * idle duration on re-entry to idle.
c57afe80 1566 */
c0f4dfd4
PM
1567 if (rdtp->all_lazy &&
1568 rdtp->nonlazy_posted != rdtp->nonlazy_posted_snap) {
c337f8f5
PM
1569 rdtp->all_lazy = false;
1570 rdtp->nonlazy_posted_snap = rdtp->nonlazy_posted;
c0f4dfd4 1571 invoke_rcu_core();
c57afe80
PM
1572 return;
1573 }
c57afe80 1574
3084f2f8 1575 /*
c0f4dfd4
PM
1576 * If we have not yet accelerated this jiffy, accelerate all
1577 * callbacks on this CPU.
3084f2f8 1578 */
c0f4dfd4 1579 if (rdtp->last_accelerate == jiffies)
aea1b35e 1580 return;
c0f4dfd4
PM
1581 rdtp->last_accelerate = jiffies;
1582 for_each_rcu_flavor(rsp) {
198bbf81 1583 rdp = this_cpu_ptr(rsp->rda);
c0f4dfd4
PM
1584 if (!*rdp->nxttail[RCU_DONE_TAIL])
1585 continue;
1586 rnp = rdp->mynode;
1587 raw_spin_lock(&rnp->lock); /* irqs already disabled. */
6303b9c8 1588 smp_mb__after_unlock_lock();
48a7639c 1589 needwake = rcu_accelerate_cbs(rsp, rnp, rdp);
c0f4dfd4 1590 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
48a7639c
PM
1591 if (needwake)
1592 rcu_gp_kthread_wake(rsp);
77e38ed3 1593 }
c0f4dfd4 1594}
3084f2f8 1595
c0f4dfd4
PM
1596/*
1597 * Clean up for exit from idle. Attempt to advance callbacks based on
1598 * any grace periods that elapsed while the CPU was idle, and if any
1599 * callbacks are now ready to invoke, initiate invocation.
1600 */
8fa7845d 1601static void rcu_cleanup_after_idle(void)
c0f4dfd4 1602{
3382adbc
PM
1603 if (IS_ENABLED(CONFIG_RCU_NOCB_CPU_ALL) ||
1604 rcu_is_nocb_cpu(smp_processor_id()))
aea1b35e 1605 return;
7a497c96
PM
1606 if (rcu_try_advance_all_cbs())
1607 invoke_rcu_core();
8bd93a2c
PM
1608}
1609
c57afe80 1610/*
98248a0e
PM
1611 * Keep a running count of the number of non-lazy callbacks posted
1612 * on this CPU. This running counter (which is never decremented) allows
1613 * rcu_prepare_for_idle() to detect when something out of the idle loop
1614 * posts a callback, even if an equal number of callbacks are invoked.
1615 * Of course, callbacks should only be posted from within a trace event
1616 * designed to be called from idle or from within RCU_NONIDLE().
c57afe80
PM
1617 */
1618static void rcu_idle_count_callbacks_posted(void)
1619{
5955f7ee 1620 __this_cpu_add(rcu_dynticks.nonlazy_posted, 1);
c57afe80
PM
1621}
1622
b626c1b6
PM
1623/*
1624 * Data for flushing lazy RCU callbacks at OOM time.
1625 */
1626static atomic_t oom_callback_count;
1627static DECLARE_WAIT_QUEUE_HEAD(oom_callback_wq);
1628
1629/*
1630 * RCU OOM callback -- decrement the outstanding count and deliver the
1631 * wake-up if we are the last one.
1632 */
1633static void rcu_oom_callback(struct rcu_head *rhp)
1634{
1635 if (atomic_dec_and_test(&oom_callback_count))
1636 wake_up(&oom_callback_wq);
1637}
1638
1639/*
1640 * Post an rcu_oom_notify callback on the current CPU if it has at
1641 * least one lazy callback. This will unnecessarily post callbacks
1642 * to CPUs that already have a non-lazy callback at the end of their
1643 * callback list, but this is an infrequent operation, so accept some
1644 * extra overhead to keep things simple.
1645 */
1646static void rcu_oom_notify_cpu(void *unused)
1647{
1648 struct rcu_state *rsp;
1649 struct rcu_data *rdp;
1650
1651 for_each_rcu_flavor(rsp) {
fa07a58f 1652 rdp = raw_cpu_ptr(rsp->rda);
b626c1b6
PM
1653 if (rdp->qlen_lazy != 0) {
1654 atomic_inc(&oom_callback_count);
1655 rsp->call(&rdp->oom_head, rcu_oom_callback);
1656 }
1657 }
1658}
1659
1660/*
1661 * If low on memory, ensure that each CPU has a non-lazy callback.
1662 * This will wake up CPUs that have only lazy callbacks, in turn
1663 * ensuring that they free up the corresponding memory in a timely manner.
1664 * Because an uncertain amount of memory will be freed in some uncertain
1665 * timeframe, we do not claim to have freed anything.
1666 */
1667static int rcu_oom_notify(struct notifier_block *self,
1668 unsigned long notused, void *nfreed)
1669{
1670 int cpu;
1671
1672 /* Wait for callbacks from earlier instance to complete. */
1673 wait_event(oom_callback_wq, atomic_read(&oom_callback_count) == 0);
78e4bc34 1674 smp_mb(); /* Ensure callback reuse happens after callback invocation. */
b626c1b6
PM
1675
1676 /*
1677 * Prevent premature wakeup: ensure that all increments happen
1678 * before there is a chance of the counter reaching zero.
1679 */
1680 atomic_set(&oom_callback_count, 1);
1681
1682 get_online_cpus();
1683 for_each_online_cpu(cpu) {
1684 smp_call_function_single(cpu, rcu_oom_notify_cpu, NULL, 1);
bde6c3aa 1685 cond_resched_rcu_qs();
b626c1b6
PM
1686 }
1687 put_online_cpus();
1688
1689 /* Unconditionally decrement: no need to wake ourselves up. */
1690 atomic_dec(&oom_callback_count);
1691
1692 return NOTIFY_OK;
1693}
1694
1695static struct notifier_block rcu_oom_nb = {
1696 .notifier_call = rcu_oom_notify
1697};
1698
1699static int __init rcu_register_oom_notifier(void)
1700{
1701 register_oom_notifier(&rcu_oom_nb);
1702 return 0;
1703}
1704early_initcall(rcu_register_oom_notifier);
1705
8bd93a2c 1706#endif /* #else #if !defined(CONFIG_RCU_FAST_NO_HZ) */
a858af28
PM
1707
1708#ifdef CONFIG_RCU_CPU_STALL_INFO
1709
1710#ifdef CONFIG_RCU_FAST_NO_HZ
1711
1712static void print_cpu_stall_fast_no_hz(char *cp, int cpu)
1713{
5955f7ee 1714 struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu);
c0f4dfd4 1715 unsigned long nlpd = rdtp->nonlazy_posted - rdtp->nonlazy_posted_snap;
a858af28 1716
c0f4dfd4
PM
1717 sprintf(cp, "last_accelerate: %04lx/%04lx, nonlazy_posted: %ld, %c%c",
1718 rdtp->last_accelerate & 0xffff, jiffies & 0xffff,
1719 ulong2long(nlpd),
1720 rdtp->all_lazy ? 'L' : '.',
1721 rdtp->tick_nohz_enabled_snap ? '.' : 'D');
a858af28
PM
1722}
1723
1724#else /* #ifdef CONFIG_RCU_FAST_NO_HZ */
1725
1726static void print_cpu_stall_fast_no_hz(char *cp, int cpu)
1727{
1c17e4d4 1728 *cp = '\0';
a858af28
PM
1729}
1730
1731#endif /* #else #ifdef CONFIG_RCU_FAST_NO_HZ */
1732
1733/* Initiate the stall-info list. */
1734static void print_cpu_stall_info_begin(void)
1735{
efc151c3 1736 pr_cont("\n");
a858af28
PM
1737}
1738
1739/*
1740 * Print out diagnostic information for the specified stalled CPU.
1741 *
1742 * If the specified CPU is aware of the current RCU grace period
1743 * (flavor specified by rsp), then print the number of scheduling
1744 * clock interrupts the CPU has taken during the time that it has
1745 * been aware. Otherwise, print the number of RCU grace periods
1746 * that this CPU is ignorant of, for example, "1" if the CPU was
1747 * aware of the previous grace period.
1748 *
1749 * Also print out idle and (if CONFIG_RCU_FAST_NO_HZ) idle-entry info.
1750 */
1751static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
1752{
1753 char fast_no_hz[72];
1754 struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
1755 struct rcu_dynticks *rdtp = rdp->dynticks;
1756 char *ticks_title;
1757 unsigned long ticks_value;
1758
1759 if (rsp->gpnum == rdp->gpnum) {
1760 ticks_title = "ticks this GP";
1761 ticks_value = rdp->ticks_this_gp;
1762 } else {
1763 ticks_title = "GPs behind";
1764 ticks_value = rsp->gpnum - rdp->gpnum;
1765 }
1766 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
fc908ed3 1767 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u fqs=%ld %s\n",
a858af28
PM
1768 cpu, ticks_value, ticks_title,
1769 atomic_read(&rdtp->dynticks) & 0xfff,
1770 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
6231069b 1771 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
7d0ae808 1772 READ_ONCE(rsp->n_force_qs) - rsp->n_force_qs_gpstart,
a858af28
PM
1773 fast_no_hz);
1774}
1775
1776/* Terminate the stall-info list. */
1777static void print_cpu_stall_info_end(void)
1778{
efc151c3 1779 pr_err("\t");
a858af28
PM
1780}
1781
1782/* Zero ->ticks_this_gp for all flavors of RCU. */
1783static void zero_cpu_stall_ticks(struct rcu_data *rdp)
1784{
1785 rdp->ticks_this_gp = 0;
6231069b 1786 rdp->softirq_snap = kstat_softirqs_cpu(RCU_SOFTIRQ, smp_processor_id());
a858af28
PM
1787}
1788
1789/* Increment ->ticks_this_gp for all flavors of RCU. */
1790static void increment_cpu_stall_ticks(void)
1791{
115f7a7c
PM
1792 struct rcu_state *rsp;
1793
1794 for_each_rcu_flavor(rsp)
fa07a58f 1795 raw_cpu_inc(rsp->rda->ticks_this_gp);
a858af28
PM
1796}
1797
1798#else /* #ifdef CONFIG_RCU_CPU_STALL_INFO */
1799
1800static void print_cpu_stall_info_begin(void)
1801{
efc151c3 1802 pr_cont(" {");
a858af28
PM
1803}
1804
1805static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
1806{
efc151c3 1807 pr_cont(" %d", cpu);
a858af28
PM
1808}
1809
1810static void print_cpu_stall_info_end(void)
1811{
efc151c3 1812 pr_cont("} ");
a858af28
PM
1813}
1814
1815static void zero_cpu_stall_ticks(struct rcu_data *rdp)
1816{
1817}
1818
1819static void increment_cpu_stall_ticks(void)
1820{
1821}
1822
1823#endif /* #else #ifdef CONFIG_RCU_CPU_STALL_INFO */
3fbfbf7a
PM
1824
1825#ifdef CONFIG_RCU_NOCB_CPU
1826
1827/*
1828 * Offload callback processing from the boot-time-specified set of CPUs
1829 * specified by rcu_nocb_mask. For each CPU in the set, there is a
1830 * kthread created that pulls the callbacks from the corresponding CPU,
1831 * waits for a grace period to elapse, and invokes the callbacks.
1832 * The no-CBs CPUs do a wake_up() on their kthread when they insert
1833 * a callback into any empty list, unless the rcu_nocb_poll boot parameter
1834 * has been specified, in which case each kthread actively polls its
1835 * CPU. (Which isn't so great for energy efficiency, but which does
1836 * reduce RCU's overhead on that CPU.)
1837 *
1838 * This is intended to be used in conjunction with Frederic Weisbecker's
1839 * adaptive-idle work, which would seriously reduce OS jitter on CPUs
1840 * running CPU-bound user-mode computations.
1841 *
1842 * Offloading of callback processing could also in theory be used as
1843 * an energy-efficiency measure because CPUs with no RCU callbacks
1844 * queued are more aggressive about entering dyntick-idle mode.
1845 */
1846
1847
1848/* Parse the boot-time rcu_nocb_mask CPU list from the kernel parameters. */
1849static int __init rcu_nocb_setup(char *str)
1850{
1851 alloc_bootmem_cpumask_var(&rcu_nocb_mask);
1852 have_rcu_nocb_mask = true;
1853 cpulist_parse(str, rcu_nocb_mask);
1854 return 1;
1855}
1856__setup("rcu_nocbs=", rcu_nocb_setup);
1857
1b0048a4
PG
1858static int __init parse_rcu_nocb_poll(char *arg)
1859{
1860 rcu_nocb_poll = 1;
1861 return 0;
1862}
1863early_param("rcu_nocb_poll", parse_rcu_nocb_poll);
1864
dae6e64d 1865/*
0446be48
PM
1866 * Wake up any no-CBs CPUs' kthreads that were waiting on the just-ended
1867 * grace period.
dae6e64d 1868 */
0446be48 1869static void rcu_nocb_gp_cleanup(struct rcu_state *rsp, struct rcu_node *rnp)
dae6e64d 1870{
0446be48 1871 wake_up_all(&rnp->nocb_gp_wq[rnp->completed & 0x1]);
dae6e64d
PM
1872}
1873
1874/*
8b425aa8 1875 * Set the root rcu_node structure's ->need_future_gp field
dae6e64d
PM
1876 * based on the sum of those of all rcu_node structures. This does
1877 * double-count the root rcu_node structure's requests, but this
1878 * is necessary to handle the possibility of a rcu_nocb_kthread()
1879 * having awakened during the time that the rcu_node structures
1880 * were being updated for the end of the previous grace period.
34ed6246 1881 */
dae6e64d
PM
1882static void rcu_nocb_gp_set(struct rcu_node *rnp, int nrq)
1883{
8b425aa8 1884 rnp->need_future_gp[(rnp->completed + 1) & 0x1] += nrq;
dae6e64d
PM
1885}
1886
1887static void rcu_init_one_nocb(struct rcu_node *rnp)
34ed6246 1888{
dae6e64d
PM
1889 init_waitqueue_head(&rnp->nocb_gp_wq[0]);
1890 init_waitqueue_head(&rnp->nocb_gp_wq[1]);
34ed6246
PM
1891}
1892
2f33b512 1893#ifndef CONFIG_RCU_NOCB_CPU_ALL
24342c96 1894/* Is the specified CPU a no-CBs CPU? */
d1e43fa5 1895bool rcu_is_nocb_cpu(int cpu)
3fbfbf7a
PM
1896{
1897 if (have_rcu_nocb_mask)
1898 return cpumask_test_cpu(cpu, rcu_nocb_mask);
1899 return false;
1900}
2f33b512 1901#endif /* #ifndef CONFIG_RCU_NOCB_CPU_ALL */
3fbfbf7a 1902
fbce7497
PM
1903/*
1904 * Kick the leader kthread for this NOCB group.
1905 */
1906static void wake_nocb_leader(struct rcu_data *rdp, bool force)
1907{
1908 struct rcu_data *rdp_leader = rdp->nocb_leader;
1909
7d0ae808 1910 if (!READ_ONCE(rdp_leader->nocb_kthread))
fbce7497 1911 return;
7d0ae808 1912 if (READ_ONCE(rdp_leader->nocb_leader_sleep) || force) {
39953dfd 1913 /* Prior smp_mb__after_atomic() orders against prior enqueue. */
7d0ae808 1914 WRITE_ONCE(rdp_leader->nocb_leader_sleep, false);
fbce7497
PM
1915 wake_up(&rdp_leader->nocb_wq);
1916 }
1917}
1918
d7e29933
PM
1919/*
1920 * Does the specified CPU need an RCU callback for the specified flavor
1921 * of rcu_barrier()?
1922 */
1923static bool rcu_nocb_cpu_needs_barrier(struct rcu_state *rsp, int cpu)
1924{
1925 struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
41050a00
PM
1926 unsigned long ret;
1927#ifdef CONFIG_PROVE_RCU
d7e29933 1928 struct rcu_head *rhp;
41050a00 1929#endif /* #ifdef CONFIG_PROVE_RCU */
d7e29933 1930
41050a00
PM
1931 /*
1932 * Check count of all no-CBs callbacks awaiting invocation.
1933 * There needs to be a barrier before this function is called,
1934 * but associated with a prior determination that no more
1935 * callbacks would be posted. In the worst case, the first
1936 * barrier in _rcu_barrier() suffices (but the caller cannot
1937 * necessarily rely on this, not a substitute for the caller
1938 * getting the concurrency design right!). There must also be
1939 * a barrier between the following load an posting of a callback
1940 * (if a callback is in fact needed). This is associated with an
1941 * atomic_inc() in the caller.
1942 */
1943 ret = atomic_long_read(&rdp->nocb_q_count);
d7e29933 1944
41050a00 1945#ifdef CONFIG_PROVE_RCU
7d0ae808 1946 rhp = READ_ONCE(rdp->nocb_head);
d7e29933 1947 if (!rhp)
7d0ae808 1948 rhp = READ_ONCE(rdp->nocb_gp_head);
d7e29933 1949 if (!rhp)
7d0ae808 1950 rhp = READ_ONCE(rdp->nocb_follower_head);
d7e29933
PM
1951
1952 /* Having no rcuo kthread but CBs after scheduler starts is bad! */
7d0ae808 1953 if (!READ_ONCE(rdp->nocb_kthread) && rhp &&
59f792d1 1954 rcu_scheduler_fully_active) {
d7e29933
PM
1955 /* RCU callback enqueued before CPU first came online??? */
1956 pr_err("RCU: Never-onlined no-CBs CPU %d has CB %p\n",
1957 cpu, rhp->func);
1958 WARN_ON_ONCE(1);
1959 }
41050a00 1960#endif /* #ifdef CONFIG_PROVE_RCU */
d7e29933 1961
41050a00 1962 return !!ret;
d7e29933
PM
1963}
1964
3fbfbf7a
PM
1965/*
1966 * Enqueue the specified string of rcu_head structures onto the specified
1967 * CPU's no-CBs lists. The CPU is specified by rdp, the head of the
1968 * string by rhp, and the tail of the string by rhtp. The non-lazy/lazy
1969 * counts are supplied by rhcount and rhcount_lazy.
1970 *
1971 * If warranted, also wake up the kthread servicing this CPUs queues.
1972 */
1973static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
1974 struct rcu_head *rhp,
1975 struct rcu_head **rhtp,
96d3fd0d
PM
1976 int rhcount, int rhcount_lazy,
1977 unsigned long flags)
3fbfbf7a
PM
1978{
1979 int len;
1980 struct rcu_head **old_rhpp;
1981 struct task_struct *t;
1982
1983 /* Enqueue the callback on the nocb list and update counts. */
41050a00
PM
1984 atomic_long_add(rhcount, &rdp->nocb_q_count);
1985 /* rcu_barrier() relies on ->nocb_q_count add before xchg. */
3fbfbf7a 1986 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
7d0ae808 1987 WRITE_ONCE(*old_rhpp, rhp);
3fbfbf7a 1988 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
39953dfd 1989 smp_mb__after_atomic(); /* Store *old_rhpp before _wake test. */
3fbfbf7a
PM
1990
1991 /* If we are not being polled and there is a kthread, awaken it ... */
7d0ae808 1992 t = READ_ONCE(rdp->nocb_kthread);
25e03a74 1993 if (rcu_nocb_poll || !t) {
9261dd0d
PM
1994 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
1995 TPS("WakeNotPoll"));
3fbfbf7a 1996 return;
9261dd0d 1997 }
3fbfbf7a
PM
1998 len = atomic_long_read(&rdp->nocb_q_count);
1999 if (old_rhpp == &rdp->nocb_head) {
96d3fd0d 2000 if (!irqs_disabled_flags(flags)) {
fbce7497
PM
2001 /* ... if queue was empty ... */
2002 wake_nocb_leader(rdp, false);
96d3fd0d
PM
2003 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
2004 TPS("WakeEmpty"));
2005 } else {
9fdd3bc9 2006 rdp->nocb_defer_wakeup = RCU_NOGP_WAKE;
96d3fd0d
PM
2007 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
2008 TPS("WakeEmptyIsDeferred"));
2009 }
3fbfbf7a
PM
2010 rdp->qlen_last_fqs_check = 0;
2011 } else if (len > rdp->qlen_last_fqs_check + qhimark) {
fbce7497 2012 /* ... or if many callbacks queued. */
9fdd3bc9
PM
2013 if (!irqs_disabled_flags(flags)) {
2014 wake_nocb_leader(rdp, true);
2015 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
2016 TPS("WakeOvf"));
2017 } else {
2018 rdp->nocb_defer_wakeup = RCU_NOGP_WAKE_FORCE;
2019 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
2020 TPS("WakeOvfIsDeferred"));
2021 }
3fbfbf7a 2022 rdp->qlen_last_fqs_check = LONG_MAX / 2;
9261dd0d
PM
2023 } else {
2024 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("WakeNot"));
3fbfbf7a
PM
2025 }
2026 return;
2027}
2028
2029/*
2030 * This is a helper for __call_rcu(), which invokes this when the normal
2031 * callback queue is inoperable. If this is not a no-CBs CPU, this
2032 * function returns failure back to __call_rcu(), which can complain
2033 * appropriately.
2034 *
2035 * Otherwise, this function queues the callback where the corresponding
2036 * "rcuo" kthread can find it.
2037 */
2038static bool __call_rcu_nocb(struct rcu_data *rdp, struct rcu_head *rhp,
96d3fd0d 2039 bool lazy, unsigned long flags)
3fbfbf7a
PM
2040{
2041
d1e43fa5 2042 if (!rcu_is_nocb_cpu(rdp->cpu))
c271d3a9 2043 return false;
96d3fd0d 2044 __call_rcu_nocb_enqueue(rdp, rhp, &rhp->next, 1, lazy, flags);
21e7a608
PM
2045 if (__is_kfree_rcu_offset((unsigned long)rhp->func))
2046 trace_rcu_kfree_callback(rdp->rsp->name, rhp,
2047 (unsigned long)rhp->func,
756cbf6b
PM
2048 -atomic_long_read(&rdp->nocb_q_count_lazy),
2049 -atomic_long_read(&rdp->nocb_q_count));
21e7a608
PM
2050 else
2051 trace_rcu_callback(rdp->rsp->name, rhp,
756cbf6b
PM
2052 -atomic_long_read(&rdp->nocb_q_count_lazy),
2053 -atomic_long_read(&rdp->nocb_q_count));
1772947b
PM
2054
2055 /*
2056 * If called from an extended quiescent state with interrupts
2057 * disabled, invoke the RCU core in order to allow the idle-entry
2058 * deferred-wakeup check to function.
2059 */
2060 if (irqs_disabled_flags(flags) &&
2061 !rcu_is_watching() &&
2062 cpu_online(smp_processor_id()))
2063 invoke_rcu_core();
2064
c271d3a9 2065 return true;
3fbfbf7a
PM
2066}
2067
2068/*
2069 * Adopt orphaned callbacks on a no-CBs CPU, or return 0 if this is
2070 * not a no-CBs CPU.
2071 */
2072static bool __maybe_unused rcu_nocb_adopt_orphan_cbs(struct rcu_state *rsp,
96d3fd0d
PM
2073 struct rcu_data *rdp,
2074 unsigned long flags)
3fbfbf7a
PM
2075{
2076 long ql = rsp->qlen;
2077 long qll = rsp->qlen_lazy;
2078
2079 /* If this is not a no-CBs CPU, tell the caller to do it the old way. */
d1e43fa5 2080 if (!rcu_is_nocb_cpu(smp_processor_id()))
0a9e1e11 2081 return false;
3fbfbf7a
PM
2082 rsp->qlen = 0;
2083 rsp->qlen_lazy = 0;
2084
2085 /* First, enqueue the donelist, if any. This preserves CB ordering. */
2086 if (rsp->orphan_donelist != NULL) {
2087 __call_rcu_nocb_enqueue(rdp, rsp->orphan_donelist,
96d3fd0d 2088 rsp->orphan_donetail, ql, qll, flags);
3fbfbf7a
PM
2089 ql = qll = 0;
2090 rsp->orphan_donelist = NULL;
2091 rsp->orphan_donetail = &rsp->orphan_donelist;
2092 }
2093 if (rsp->orphan_nxtlist != NULL) {
2094 __call_rcu_nocb_enqueue(rdp, rsp->orphan_nxtlist,
96d3fd0d 2095 rsp->orphan_nxttail, ql, qll, flags);
3fbfbf7a
PM
2096 ql = qll = 0;
2097 rsp->orphan_nxtlist = NULL;
2098 rsp->orphan_nxttail = &rsp->orphan_nxtlist;
2099 }
0a9e1e11 2100 return true;
3fbfbf7a
PM
2101}
2102
2103/*
34ed6246
PM
2104 * If necessary, kick off a new grace period, and either way wait
2105 * for a subsequent grace period to complete.
3fbfbf7a 2106 */
34ed6246 2107static void rcu_nocb_wait_gp(struct rcu_data *rdp)
3fbfbf7a 2108{
34ed6246 2109 unsigned long c;
dae6e64d 2110 bool d;
34ed6246 2111 unsigned long flags;
48a7639c 2112 bool needwake;
34ed6246
PM
2113 struct rcu_node *rnp = rdp->mynode;
2114
2115 raw_spin_lock_irqsave(&rnp->lock, flags);
6303b9c8 2116 smp_mb__after_unlock_lock();
48a7639c 2117 needwake = rcu_start_future_gp(rnp, rdp, &c);
0446be48 2118 raw_spin_unlock_irqrestore(&rnp->lock, flags);
48a7639c
PM
2119 if (needwake)
2120 rcu_gp_kthread_wake(rdp->rsp);
3fbfbf7a
PM
2121
2122 /*
34ed6246
PM
2123 * Wait for the grace period. Do so interruptibly to avoid messing
2124 * up the load average.
3fbfbf7a 2125 */
f7f7bac9 2126 trace_rcu_future_gp(rnp, rdp, c, TPS("StartWait"));
34ed6246 2127 for (;;) {
dae6e64d
PM
2128 wait_event_interruptible(
2129 rnp->nocb_gp_wq[c & 0x1],
7d0ae808 2130 (d = ULONG_CMP_GE(READ_ONCE(rnp->completed), c)));
dae6e64d 2131 if (likely(d))
34ed6246 2132 break;
73a860cd 2133 WARN_ON(signal_pending(current));
f7f7bac9 2134 trace_rcu_future_gp(rnp, rdp, c, TPS("ResumeWait"));
34ed6246 2135 }
f7f7bac9 2136 trace_rcu_future_gp(rnp, rdp, c, TPS("EndWait"));
34ed6246 2137 smp_mb(); /* Ensure that CB invocation happens after GP end. */
3fbfbf7a
PM
2138}
2139
fbce7497
PM
2140/*
2141 * Leaders come here to wait for additional callbacks to show up.
2142 * This function does not return until callbacks appear.
2143 */
2144static void nocb_leader_wait(struct rcu_data *my_rdp)
2145{
2146 bool firsttime = true;
2147 bool gotcbs;
2148 struct rcu_data *rdp;
2149 struct rcu_head **tail;
2150
2151wait_again:
2152
2153 /* Wait for callbacks to appear. */
2154 if (!rcu_nocb_poll) {
2155 trace_rcu_nocb_wake(my_rdp->rsp->name, my_rdp->cpu, "Sleep");
2156 wait_event_interruptible(my_rdp->nocb_wq,
7d0ae808 2157 !READ_ONCE(my_rdp->nocb_leader_sleep));
fbce7497
PM
2158 /* Memory barrier handled by smp_mb() calls below and repoll. */
2159 } else if (firsttime) {
2160 firsttime = false; /* Don't drown trace log with "Poll"! */
2161 trace_rcu_nocb_wake(my_rdp->rsp->name, my_rdp->cpu, "Poll");
2162 }
2163
2164 /*
2165 * Each pass through the following loop checks a follower for CBs.
2166 * We are our own first follower. Any CBs found are moved to
2167 * nocb_gp_head, where they await a grace period.
2168 */
2169 gotcbs = false;
2170 for (rdp = my_rdp; rdp; rdp = rdp->nocb_next_follower) {
7d0ae808 2171 rdp->nocb_gp_head = READ_ONCE(rdp->nocb_head);
fbce7497
PM
2172 if (!rdp->nocb_gp_head)
2173 continue; /* No CBs here, try next follower. */
2174
2175 /* Move callbacks to wait-for-GP list, which is empty. */
7d0ae808 2176 WRITE_ONCE(rdp->nocb_head, NULL);
fbce7497 2177 rdp->nocb_gp_tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
fbce7497
PM
2178 gotcbs = true;
2179 }
2180
2181 /*
2182 * If there were no callbacks, sleep a bit, rescan after a
2183 * memory barrier, and go retry.
2184 */
2185 if (unlikely(!gotcbs)) {
2186 if (!rcu_nocb_poll)
2187 trace_rcu_nocb_wake(my_rdp->rsp->name, my_rdp->cpu,
2188 "WokeEmpty");
73a860cd 2189 WARN_ON(signal_pending(current));
fbce7497
PM
2190 schedule_timeout_interruptible(1);
2191
2192 /* Rescan in case we were a victim of memory ordering. */
11ed7f93
PK
2193 my_rdp->nocb_leader_sleep = true;
2194 smp_mb(); /* Ensure _sleep true before scan. */
fbce7497 2195 for (rdp = my_rdp; rdp; rdp = rdp->nocb_next_follower)
7d0ae808 2196 if (READ_ONCE(rdp->nocb_head)) {
fbce7497 2197 /* Found CB, so short-circuit next wait. */
11ed7f93 2198 my_rdp->nocb_leader_sleep = false;
fbce7497
PM
2199 break;
2200 }
2201 goto wait_again;
2202 }
2203
2204 /* Wait for one grace period. */
2205 rcu_nocb_wait_gp(my_rdp);
2206
2207 /*
11ed7f93
PK
2208 * We left ->nocb_leader_sleep unset to reduce cache thrashing.
2209 * We set it now, but recheck for new callbacks while
fbce7497
PM
2210 * traversing our follower list.
2211 */
11ed7f93
PK
2212 my_rdp->nocb_leader_sleep = true;
2213 smp_mb(); /* Ensure _sleep true before scan of ->nocb_head. */
fbce7497
PM
2214
2215 /* Each pass through the following loop wakes a follower, if needed. */
2216 for (rdp = my_rdp; rdp; rdp = rdp->nocb_next_follower) {
7d0ae808 2217 if (READ_ONCE(rdp->nocb_head))
11ed7f93 2218 my_rdp->nocb_leader_sleep = false;/* No need to sleep.*/
fbce7497
PM
2219 if (!rdp->nocb_gp_head)
2220 continue; /* No CBs, so no need to wake follower. */
2221
2222 /* Append callbacks to follower's "done" list. */
2223 tail = xchg(&rdp->nocb_follower_tail, rdp->nocb_gp_tail);
2224 *tail = rdp->nocb_gp_head;
c847f142 2225 smp_mb__after_atomic(); /* Store *tail before wakeup. */
fbce7497
PM
2226 if (rdp != my_rdp && tail == &rdp->nocb_follower_head) {
2227 /*
2228 * List was empty, wake up the follower.
2229 * Memory barriers supplied by atomic_long_add().
2230 */
2231 wake_up(&rdp->nocb_wq);
2232 }
2233 }
2234
2235 /* If we (the leader) don't have CBs, go wait some more. */
2236 if (!my_rdp->nocb_follower_head)
2237 goto wait_again;
2238}
2239
2240/*
2241 * Followers come here to wait for additional callbacks to show up.
2242 * This function does not return until callbacks appear.
2243 */
2244static void nocb_follower_wait(struct rcu_data *rdp)
2245{
2246 bool firsttime = true;
2247
2248 for (;;) {
2249 if (!rcu_nocb_poll) {
2250 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
2251 "FollowerSleep");
2252 wait_event_interruptible(rdp->nocb_wq,
7d0ae808 2253 READ_ONCE(rdp->nocb_follower_head));
fbce7497
PM
2254 } else if (firsttime) {
2255 /* Don't drown trace log with "Poll"! */
2256 firsttime = false;
2257 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, "Poll");
2258 }
2259 if (smp_load_acquire(&rdp->nocb_follower_head)) {
2260 /* ^^^ Ensure CB invocation follows _head test. */
2261 return;
2262 }
2263 if (!rcu_nocb_poll)
2264 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
2265 "WokeEmpty");
73a860cd 2266 WARN_ON(signal_pending(current));
fbce7497
PM
2267 schedule_timeout_interruptible(1);
2268 }
2269}
2270
3fbfbf7a
PM
2271/*
2272 * Per-rcu_data kthread, but only for no-CBs CPUs. Each kthread invokes
fbce7497
PM
2273 * callbacks queued by the corresponding no-CBs CPU, however, there is
2274 * an optional leader-follower relationship so that the grace-period
2275 * kthreads don't have to do quite so many wakeups.
3fbfbf7a
PM
2276 */
2277static int rcu_nocb_kthread(void *arg)
2278{
2279 int c, cl;
2280 struct rcu_head *list;
2281 struct rcu_head *next;
2282 struct rcu_head **tail;
2283 struct rcu_data *rdp = arg;
2284
2285 /* Each pass through this loop invokes one batch of callbacks */
2286 for (;;) {
fbce7497
PM
2287 /* Wait for callbacks. */
2288 if (rdp->nocb_leader == rdp)
2289 nocb_leader_wait(rdp);
2290 else
2291 nocb_follower_wait(rdp);
2292
2293 /* Pull the ready-to-invoke callbacks onto local list. */
7d0ae808 2294 list = READ_ONCE(rdp->nocb_follower_head);
fbce7497
PM
2295 BUG_ON(!list);
2296 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, "WokeNonEmpty");
7d0ae808 2297 WRITE_ONCE(rdp->nocb_follower_head, NULL);
fbce7497 2298 tail = xchg(&rdp->nocb_follower_tail, &rdp->nocb_follower_head);
3fbfbf7a
PM
2299
2300 /* Each pass through the following loop invokes a callback. */
41050a00
PM
2301 trace_rcu_batch_start(rdp->rsp->name,
2302 atomic_long_read(&rdp->nocb_q_count_lazy),
2303 atomic_long_read(&rdp->nocb_q_count), -1);
3fbfbf7a
PM
2304 c = cl = 0;
2305 while (list) {
2306 next = list->next;
2307 /* Wait for enqueuing to complete, if needed. */
2308 while (next == NULL && &list->next != tail) {
69a79bb1
PM
2309 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
2310 TPS("WaitQueue"));
3fbfbf7a 2311 schedule_timeout_interruptible(1);
69a79bb1
PM
2312 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
2313 TPS("WokeQueue"));
3fbfbf7a
PM
2314 next = list->next;
2315 }
2316 debug_rcu_head_unqueue(list);
2317 local_bh_disable();
2318 if (__rcu_reclaim(rdp->rsp->name, list))
2319 cl++;
2320 c++;
2321 local_bh_enable();
2322 list = next;
2323 }
2324 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
41050a00
PM
2325 smp_mb__before_atomic(); /* _add after CB invocation. */
2326 atomic_long_add(-c, &rdp->nocb_q_count);
2327 atomic_long_add(-cl, &rdp->nocb_q_count_lazy);
c635a4e1 2328 rdp->n_nocbs_invoked += c;
3fbfbf7a
PM
2329 }
2330 return 0;
2331}
2332
96d3fd0d 2333/* Is a deferred wakeup of rcu_nocb_kthread() required? */
9fdd3bc9 2334static int rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp)
96d3fd0d 2335{
7d0ae808 2336 return READ_ONCE(rdp->nocb_defer_wakeup);
96d3fd0d
PM
2337}
2338
2339/* Do a deferred wakeup of rcu_nocb_kthread(). */
2340static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
2341{
9fdd3bc9
PM
2342 int ndw;
2343
96d3fd0d
PM
2344 if (!rcu_nocb_need_deferred_wakeup(rdp))
2345 return;
7d0ae808
PM
2346 ndw = READ_ONCE(rdp->nocb_defer_wakeup);
2347 WRITE_ONCE(rdp->nocb_defer_wakeup, RCU_NOGP_WAKE_NOT);
9fdd3bc9
PM
2348 wake_nocb_leader(rdp, ndw == RCU_NOGP_WAKE_FORCE);
2349 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWake"));
96d3fd0d
PM
2350}
2351
f4579fc5
PM
2352void __init rcu_init_nohz(void)
2353{
2354 int cpu;
2355 bool need_rcu_nocb_mask = true;
2356 struct rcu_state *rsp;
2357
2358#ifdef CONFIG_RCU_NOCB_CPU_NONE
2359 need_rcu_nocb_mask = false;
2360#endif /* #ifndef CONFIG_RCU_NOCB_CPU_NONE */
2361
2362#if defined(CONFIG_NO_HZ_FULL)
2363 if (tick_nohz_full_running && cpumask_weight(tick_nohz_full_mask))
2364 need_rcu_nocb_mask = true;
2365#endif /* #if defined(CONFIG_NO_HZ_FULL) */
2366
2367 if (!have_rcu_nocb_mask && need_rcu_nocb_mask) {
949cccdb
PK
2368 if (!zalloc_cpumask_var(&rcu_nocb_mask, GFP_KERNEL)) {
2369 pr_info("rcu_nocb_mask allocation failed, callback offloading disabled.\n");
2370 return;
2371 }
f4579fc5
PM
2372 have_rcu_nocb_mask = true;
2373 }
2374 if (!have_rcu_nocb_mask)
2375 return;
2376
2377#ifdef CONFIG_RCU_NOCB_CPU_ZERO
2378 pr_info("\tOffload RCU callbacks from CPU 0\n");
2379 cpumask_set_cpu(0, rcu_nocb_mask);
2380#endif /* #ifdef CONFIG_RCU_NOCB_CPU_ZERO */
2381#ifdef CONFIG_RCU_NOCB_CPU_ALL
2382 pr_info("\tOffload RCU callbacks from all CPUs\n");
2383 cpumask_copy(rcu_nocb_mask, cpu_possible_mask);
2384#endif /* #ifdef CONFIG_RCU_NOCB_CPU_ALL */
2385#if defined(CONFIG_NO_HZ_FULL)
2386 if (tick_nohz_full_running)
2387 cpumask_or(rcu_nocb_mask, rcu_nocb_mask, tick_nohz_full_mask);
2388#endif /* #if defined(CONFIG_NO_HZ_FULL) */
2389
2390 if (!cpumask_subset(rcu_nocb_mask, cpu_possible_mask)) {
2391 pr_info("\tNote: kernel parameter 'rcu_nocbs=' contains nonexistent CPUs.\n");
2392 cpumask_and(rcu_nocb_mask, cpu_possible_mask,
2393 rcu_nocb_mask);
2394 }
ad853b48
TH
2395 pr_info("\tOffload RCU callbacks from CPUs: %*pbl.\n",
2396 cpumask_pr_args(rcu_nocb_mask));
f4579fc5
PM
2397 if (rcu_nocb_poll)
2398 pr_info("\tPoll for callbacks from no-CBs CPUs.\n");
2399
2400 for_each_rcu_flavor(rsp) {
34404ca8
PM
2401 for_each_cpu(cpu, rcu_nocb_mask)
2402 init_nocb_callback_list(per_cpu_ptr(rsp->rda, cpu));
35ce7f29 2403 rcu_organize_nocb_kthreads(rsp);
f4579fc5 2404 }
96d3fd0d
PM
2405}
2406
3fbfbf7a
PM
2407/* Initialize per-rcu_data variables for no-CBs CPUs. */
2408static void __init rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp)
2409{
2410 rdp->nocb_tail = &rdp->nocb_head;
2411 init_waitqueue_head(&rdp->nocb_wq);
fbce7497 2412 rdp->nocb_follower_tail = &rdp->nocb_follower_head;
3fbfbf7a
PM
2413}
2414
35ce7f29
PM
2415/*
2416 * If the specified CPU is a no-CBs CPU that does not already have its
2417 * rcuo kthread for the specified RCU flavor, spawn it. If the CPUs are
2418 * brought online out of order, this can require re-organizing the
2419 * leader-follower relationships.
2420 */
2421static void rcu_spawn_one_nocb_kthread(struct rcu_state *rsp, int cpu)
2422{
2423 struct rcu_data *rdp;
2424 struct rcu_data *rdp_last;
2425 struct rcu_data *rdp_old_leader;
2426 struct rcu_data *rdp_spawn = per_cpu_ptr(rsp->rda, cpu);
2427 struct task_struct *t;
2428
2429 /*
2430 * If this isn't a no-CBs CPU or if it already has an rcuo kthread,
2431 * then nothing to do.
2432 */
2433 if (!rcu_is_nocb_cpu(cpu) || rdp_spawn->nocb_kthread)
2434 return;
2435
2436 /* If we didn't spawn the leader first, reorganize! */
2437 rdp_old_leader = rdp_spawn->nocb_leader;
2438 if (rdp_old_leader != rdp_spawn && !rdp_old_leader->nocb_kthread) {
2439 rdp_last = NULL;
2440 rdp = rdp_old_leader;
2441 do {
2442 rdp->nocb_leader = rdp_spawn;
2443 if (rdp_last && rdp != rdp_spawn)
2444 rdp_last->nocb_next_follower = rdp;
bbe5d7a9
PM
2445 if (rdp == rdp_spawn) {
2446 rdp = rdp->nocb_next_follower;
2447 } else {
2448 rdp_last = rdp;
2449 rdp = rdp->nocb_next_follower;
2450 rdp_last->nocb_next_follower = NULL;
2451 }
35ce7f29
PM
2452 } while (rdp);
2453 rdp_spawn->nocb_next_follower = rdp_old_leader;
2454 }
2455
2456 /* Spawn the kthread for this CPU and RCU flavor. */
2457 t = kthread_run(rcu_nocb_kthread, rdp_spawn,
2458 "rcuo%c/%d", rsp->abbr, cpu);
2459 BUG_ON(IS_ERR(t));
7d0ae808 2460 WRITE_ONCE(rdp_spawn->nocb_kthread, t);
35ce7f29
PM
2461}
2462
2463/*
2464 * If the specified CPU is a no-CBs CPU that does not already have its
2465 * rcuo kthreads, spawn them.
2466 */
2467static void rcu_spawn_all_nocb_kthreads(int cpu)
2468{
2469 struct rcu_state *rsp;
2470
2471 if (rcu_scheduler_fully_active)
2472 for_each_rcu_flavor(rsp)
2473 rcu_spawn_one_nocb_kthread(rsp, cpu);
2474}
2475
2476/*
2477 * Once the scheduler is running, spawn rcuo kthreads for all online
2478 * no-CBs CPUs. This assumes that the early_initcall()s happen before
2479 * non-boot CPUs come online -- if this changes, we will need to add
2480 * some mutual exclusion.
2481 */
2482static void __init rcu_spawn_nocb_kthreads(void)
2483{
2484 int cpu;
2485
2486 for_each_online_cpu(cpu)
2487 rcu_spawn_all_nocb_kthreads(cpu);
2488}
2489
fbce7497
PM
2490/* How many follower CPU IDs per leader? Default of -1 for sqrt(nr_cpu_ids). */
2491static int rcu_nocb_leader_stride = -1;
2492module_param(rcu_nocb_leader_stride, int, 0444);
2493
2494/*
35ce7f29 2495 * Initialize leader-follower relationships for all no-CBs CPU.
fbce7497 2496 */
35ce7f29 2497static void __init rcu_organize_nocb_kthreads(struct rcu_state *rsp)
3fbfbf7a
PM
2498{
2499 int cpu;
fbce7497
PM
2500 int ls = rcu_nocb_leader_stride;
2501 int nl = 0; /* Next leader. */
3fbfbf7a 2502 struct rcu_data *rdp;
fbce7497
PM
2503 struct rcu_data *rdp_leader = NULL; /* Suppress misguided gcc warn. */
2504 struct rcu_data *rdp_prev = NULL;
3fbfbf7a 2505
22c2f669 2506 if (!have_rcu_nocb_mask)
3fbfbf7a 2507 return;
fbce7497
PM
2508 if (ls == -1) {
2509 ls = int_sqrt(nr_cpu_ids);
2510 rcu_nocb_leader_stride = ls;
2511 }
2512
2513 /*
2514 * Each pass through this loop sets up one rcu_data structure and
2515 * spawns one rcu_nocb_kthread().
2516 */
3fbfbf7a
PM
2517 for_each_cpu(cpu, rcu_nocb_mask) {
2518 rdp = per_cpu_ptr(rsp->rda, cpu);
fbce7497
PM
2519 if (rdp->cpu >= nl) {
2520 /* New leader, set up for followers & next leader. */
2521 nl = DIV_ROUND_UP(rdp->cpu + 1, ls) * ls;
2522 rdp->nocb_leader = rdp;
2523 rdp_leader = rdp;
2524 } else {
2525 /* Another follower, link to previous leader. */
2526 rdp->nocb_leader = rdp_leader;
2527 rdp_prev->nocb_next_follower = rdp;
2528 }
2529 rdp_prev = rdp;
3fbfbf7a
PM
2530 }
2531}
2532
2533/* Prevent __call_rcu() from enqueuing callbacks on no-CBs CPUs */
34ed6246 2534static bool init_nocb_callback_list(struct rcu_data *rdp)
3fbfbf7a 2535{
22c2f669 2536 if (!rcu_is_nocb_cpu(rdp->cpu))
34ed6246 2537 return false;
22c2f669 2538
34404ca8
PM
2539 /* If there are early-boot callbacks, move them to nocb lists. */
2540 if (rdp->nxtlist) {
2541 rdp->nocb_head = rdp->nxtlist;
2542 rdp->nocb_tail = rdp->nxttail[RCU_NEXT_TAIL];
2543 atomic_long_set(&rdp->nocb_q_count, rdp->qlen);
2544 atomic_long_set(&rdp->nocb_q_count_lazy, rdp->qlen_lazy);
2545 rdp->nxtlist = NULL;
2546 rdp->qlen = 0;
2547 rdp->qlen_lazy = 0;
2548 }
3fbfbf7a 2549 rdp->nxttail[RCU_NEXT_TAIL] = NULL;
34ed6246 2550 return true;
3fbfbf7a
PM
2551}
2552
34ed6246
PM
2553#else /* #ifdef CONFIG_RCU_NOCB_CPU */
2554
d7e29933
PM
2555static bool rcu_nocb_cpu_needs_barrier(struct rcu_state *rsp, int cpu)
2556{
2557 WARN_ON_ONCE(1); /* Should be dead code. */
2558 return false;
2559}
2560
0446be48 2561static void rcu_nocb_gp_cleanup(struct rcu_state *rsp, struct rcu_node *rnp)
3fbfbf7a 2562{
3fbfbf7a
PM
2563}
2564
dae6e64d
PM
2565static void rcu_nocb_gp_set(struct rcu_node *rnp, int nrq)
2566{
2567}
2568
2569static void rcu_init_one_nocb(struct rcu_node *rnp)
2570{
2571}
3fbfbf7a 2572
3fbfbf7a 2573static bool __call_rcu_nocb(struct rcu_data *rdp, struct rcu_head *rhp,
96d3fd0d 2574 bool lazy, unsigned long flags)
3fbfbf7a 2575{
4afc7e26 2576 return false;
3fbfbf7a
PM
2577}
2578
2579static bool __maybe_unused rcu_nocb_adopt_orphan_cbs(struct rcu_state *rsp,
96d3fd0d
PM
2580 struct rcu_data *rdp,
2581 unsigned long flags)
3fbfbf7a 2582{
f4aa84ba 2583 return false;
3fbfbf7a
PM
2584}
2585
3fbfbf7a
PM
2586static void __init rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp)
2587{
2588}
2589
9fdd3bc9 2590static int rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp)
96d3fd0d
PM
2591{
2592 return false;
2593}
2594
2595static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
2596{
2597}
2598
35ce7f29
PM
2599static void rcu_spawn_all_nocb_kthreads(int cpu)
2600{
2601}
2602
2603static void __init rcu_spawn_nocb_kthreads(void)
3fbfbf7a
PM
2604{
2605}
2606
34ed6246 2607static bool init_nocb_callback_list(struct rcu_data *rdp)
3fbfbf7a 2608{
34ed6246 2609 return false;
3fbfbf7a
PM
2610}
2611
2612#endif /* #else #ifdef CONFIG_RCU_NOCB_CPU */
65d798f0
PM
2613
2614/*
2615 * An adaptive-ticks CPU can potentially execute in kernel mode for an
2616 * arbitrarily long period of time with the scheduling-clock tick turned
2617 * off. RCU will be paying attention to this CPU because it is in the
2618 * kernel, but the CPU cannot be guaranteed to be executing the RCU state
2619 * machine because the scheduling-clock tick has been disabled. Therefore,
2620 * if an adaptive-ticks CPU is failing to respond to the current grace
2621 * period and has not be idle from an RCU perspective, kick it.
2622 */
4a81e832 2623static void __maybe_unused rcu_kick_nohz_cpu(int cpu)
65d798f0
PM
2624{
2625#ifdef CONFIG_NO_HZ_FULL
2626 if (tick_nohz_full_cpu(cpu))
2627 smp_send_reschedule(cpu);
2628#endif /* #ifdef CONFIG_NO_HZ_FULL */
2629}
2333210b
PM
2630
2631
2632#ifdef CONFIG_NO_HZ_FULL_SYSIDLE
2633
0edd1b17 2634static int full_sysidle_state; /* Current system-idle state. */
d4bd54fb
PM
2635#define RCU_SYSIDLE_NOT 0 /* Some CPU is not idle. */
2636#define RCU_SYSIDLE_SHORT 1 /* All CPUs idle for brief period. */
2637#define RCU_SYSIDLE_LONG 2 /* All CPUs idle for long enough. */
2638#define RCU_SYSIDLE_FULL 3 /* All CPUs idle, ready for sysidle. */
2639#define RCU_SYSIDLE_FULL_NOTED 4 /* Actually entered sysidle state. */
2640
eb348b89
PM
2641/*
2642 * Invoked to note exit from irq or task transition to idle. Note that
2643 * usermode execution does -not- count as idle here! After all, we want
2644 * to detect full-system idle states, not RCU quiescent states and grace
2645 * periods. The caller must have disabled interrupts.
2646 */
28ced795 2647static void rcu_sysidle_enter(int irq)
eb348b89
PM
2648{
2649 unsigned long j;
28ced795 2650 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
eb348b89 2651
663e1310
PM
2652 /* If there are no nohz_full= CPUs, no need to track this. */
2653 if (!tick_nohz_full_enabled())
2654 return;
2655
eb348b89
PM
2656 /* Adjust nesting, check for fully idle. */
2657 if (irq) {
2658 rdtp->dynticks_idle_nesting--;
2659 WARN_ON_ONCE(rdtp->dynticks_idle_nesting < 0);
2660 if (rdtp->dynticks_idle_nesting != 0)
2661 return; /* Still not fully idle. */
2662 } else {
2663 if ((rdtp->dynticks_idle_nesting & DYNTICK_TASK_NEST_MASK) ==
2664 DYNTICK_TASK_NEST_VALUE) {
2665 rdtp->dynticks_idle_nesting = 0;
2666 } else {
2667 rdtp->dynticks_idle_nesting -= DYNTICK_TASK_NEST_VALUE;
2668 WARN_ON_ONCE(rdtp->dynticks_idle_nesting < 0);
2669 return; /* Still not fully idle. */
2670 }
2671 }
2672
2673 /* Record start of fully idle period. */
2674 j = jiffies;
7d0ae808 2675 WRITE_ONCE(rdtp->dynticks_idle_jiffies, j);
4e857c58 2676 smp_mb__before_atomic();
eb348b89 2677 atomic_inc(&rdtp->dynticks_idle);
4e857c58 2678 smp_mb__after_atomic();
eb348b89
PM
2679 WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
2680}
2681
0edd1b17
PM
2682/*
2683 * Unconditionally force exit from full system-idle state. This is
2684 * invoked when a normal CPU exits idle, but must be called separately
2685 * for the timekeeping CPU (tick_do_timer_cpu). The reason for this
2686 * is that the timekeeping CPU is permitted to take scheduling-clock
2687 * interrupts while the system is in system-idle state, and of course
2688 * rcu_sysidle_exit() has no way of distinguishing a scheduling-clock
2689 * interrupt from any other type of interrupt.
2690 */
2691void rcu_sysidle_force_exit(void)
2692{
7d0ae808 2693 int oldstate = READ_ONCE(full_sysidle_state);
0edd1b17
PM
2694 int newoldstate;
2695
2696 /*
2697 * Each pass through the following loop attempts to exit full
2698 * system-idle state. If contention proves to be a problem,
2699 * a trylock-based contention tree could be used here.
2700 */
2701 while (oldstate > RCU_SYSIDLE_SHORT) {
2702 newoldstate = cmpxchg(&full_sysidle_state,
2703 oldstate, RCU_SYSIDLE_NOT);
2704 if (oldstate == newoldstate &&
2705 oldstate == RCU_SYSIDLE_FULL_NOTED) {
2706 rcu_kick_nohz_cpu(tick_do_timer_cpu);
2707 return; /* We cleared it, done! */
2708 }
2709 oldstate = newoldstate;
2710 }
2711 smp_mb(); /* Order initial oldstate fetch vs. later non-idle work. */
2712}
2713
eb348b89
PM
2714/*
2715 * Invoked to note entry to irq or task transition from idle. Note that
2716 * usermode execution does -not- count as idle here! The caller must
2717 * have disabled interrupts.
2718 */
28ced795 2719static void rcu_sysidle_exit(int irq)
eb348b89 2720{
28ced795
CL
2721 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
2722
663e1310
PM
2723 /* If there are no nohz_full= CPUs, no need to track this. */
2724 if (!tick_nohz_full_enabled())
2725 return;
2726
eb348b89
PM
2727 /* Adjust nesting, check for already non-idle. */
2728 if (irq) {
2729 rdtp->dynticks_idle_nesting++;
2730 WARN_ON_ONCE(rdtp->dynticks_idle_nesting <= 0);
2731 if (rdtp->dynticks_idle_nesting != 1)
2732 return; /* Already non-idle. */
2733 } else {
2734 /*
2735 * Allow for irq misnesting. Yes, it really is possible
2736 * to enter an irq handler then never leave it, and maybe
2737 * also vice versa. Handle both possibilities.
2738 */
2739 if (rdtp->dynticks_idle_nesting & DYNTICK_TASK_NEST_MASK) {
2740 rdtp->dynticks_idle_nesting += DYNTICK_TASK_NEST_VALUE;
2741 WARN_ON_ONCE(rdtp->dynticks_idle_nesting <= 0);
2742 return; /* Already non-idle. */
2743 } else {
2744 rdtp->dynticks_idle_nesting = DYNTICK_TASK_EXIT_IDLE;
2745 }
2746 }
2747
2748 /* Record end of idle period. */
4e857c58 2749 smp_mb__before_atomic();
eb348b89 2750 atomic_inc(&rdtp->dynticks_idle);
4e857c58 2751 smp_mb__after_atomic();
eb348b89 2752 WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
0edd1b17
PM
2753
2754 /*
2755 * If we are the timekeeping CPU, we are permitted to be non-idle
2756 * during a system-idle state. This must be the case, because
2757 * the timekeeping CPU has to take scheduling-clock interrupts
2758 * during the time that the system is transitioning to full
2759 * system-idle state. This means that the timekeeping CPU must
2760 * invoke rcu_sysidle_force_exit() directly if it does anything
2761 * more than take a scheduling-clock interrupt.
2762 */
2763 if (smp_processor_id() == tick_do_timer_cpu)
2764 return;
2765
2766 /* Update system-idle state: We are clearly no longer fully idle! */
2767 rcu_sysidle_force_exit();
2768}
2769
2770/*
2771 * Check to see if the current CPU is idle. Note that usermode execution
5871968d
PM
2772 * does not count as idle. The caller must have disabled interrupts,
2773 * and must be running on tick_do_timer_cpu.
0edd1b17
PM
2774 */
2775static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
2776 unsigned long *maxj)
2777{
2778 int cur;
2779 unsigned long j;
2780 struct rcu_dynticks *rdtp = rdp->dynticks;
2781
663e1310
PM
2782 /* If there are no nohz_full= CPUs, don't check system-wide idleness. */
2783 if (!tick_nohz_full_enabled())
2784 return;
2785
0edd1b17
PM
2786 /*
2787 * If some other CPU has already reported non-idle, if this is
2788 * not the flavor of RCU that tracks sysidle state, or if this
2789 * is an offline or the timekeeping CPU, nothing to do.
2790 */
417e8d26 2791 if (!*isidle || rdp->rsp != rcu_state_p ||
0edd1b17
PM
2792 cpu_is_offline(rdp->cpu) || rdp->cpu == tick_do_timer_cpu)
2793 return;
5871968d
PM
2794 /* Verify affinity of current kthread. */
2795 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
0edd1b17
PM
2796
2797 /* Pick up current idle and NMI-nesting counter and check. */
2798 cur = atomic_read(&rdtp->dynticks_idle);
2799 if (cur & 0x1) {
2800 *isidle = false; /* We are not idle! */
2801 return;
2802 }
2803 smp_mb(); /* Read counters before timestamps. */
2804
2805 /* Pick up timestamps. */
7d0ae808 2806 j = READ_ONCE(rdtp->dynticks_idle_jiffies);
0edd1b17
PM
2807 /* If this CPU entered idle more recently, update maxj timestamp. */
2808 if (ULONG_CMP_LT(*maxj, j))
2809 *maxj = j;
2810}
2811
2812/*
2813 * Is this the flavor of RCU that is handling full-system idle?
2814 */
2815static bool is_sysidle_rcu_state(struct rcu_state *rsp)
2816{
417e8d26 2817 return rsp == rcu_state_p;
0edd1b17
PM
2818}
2819
2820/*
2821 * Return a delay in jiffies based on the number of CPUs, rcu_node
2822 * leaf fanout, and jiffies tick rate. The idea is to allow larger
2823 * systems more time to transition to full-idle state in order to
2824 * avoid the cache thrashing that otherwise occur on the state variable.
2825 * Really small systems (less than a couple of tens of CPUs) should
2826 * instead use a single global atomically incremented counter, and later
2827 * versions of this will automatically reconfigure themselves accordingly.
2828 */
2829static unsigned long rcu_sysidle_delay(void)
2830{
2831 if (nr_cpu_ids <= CONFIG_NO_HZ_FULL_SYSIDLE_SMALL)
2832 return 0;
2833 return DIV_ROUND_UP(nr_cpu_ids * HZ, rcu_fanout_leaf * 1000);
2834}
2835
2836/*
2837 * Advance the full-system-idle state. This is invoked when all of
2838 * the non-timekeeping CPUs are idle.
2839 */
2840static void rcu_sysidle(unsigned long j)
2841{
2842 /* Check the current state. */
7d0ae808 2843 switch (READ_ONCE(full_sysidle_state)) {
0edd1b17
PM
2844 case RCU_SYSIDLE_NOT:
2845
2846 /* First time all are idle, so note a short idle period. */
7d0ae808 2847 WRITE_ONCE(full_sysidle_state, RCU_SYSIDLE_SHORT);
0edd1b17
PM
2848 break;
2849
2850 case RCU_SYSIDLE_SHORT:
2851
2852 /*
2853 * Idle for a bit, time to advance to next state?
2854 * cmpxchg failure means race with non-idle, let them win.
2855 */
2856 if (ULONG_CMP_GE(jiffies, j + rcu_sysidle_delay()))
2857 (void)cmpxchg(&full_sysidle_state,
2858 RCU_SYSIDLE_SHORT, RCU_SYSIDLE_LONG);
2859 break;
2860
2861 case RCU_SYSIDLE_LONG:
2862
2863 /*
2864 * Do an additional check pass before advancing to full.
2865 * cmpxchg failure means race with non-idle, let them win.
2866 */
2867 if (ULONG_CMP_GE(jiffies, j + rcu_sysidle_delay()))
2868 (void)cmpxchg(&full_sysidle_state,
2869 RCU_SYSIDLE_LONG, RCU_SYSIDLE_FULL);
2870 break;
2871
2872 default:
2873 break;
2874 }
2875}
2876
2877/*
2878 * Found a non-idle non-timekeeping CPU, so kick the system-idle state
2879 * back to the beginning.
2880 */
2881static void rcu_sysidle_cancel(void)
2882{
2883 smp_mb();
becb41bf 2884 if (full_sysidle_state > RCU_SYSIDLE_SHORT)
7d0ae808 2885 WRITE_ONCE(full_sysidle_state, RCU_SYSIDLE_NOT);
0edd1b17
PM
2886}
2887
2888/*
2889 * Update the sysidle state based on the results of a force-quiescent-state
2890 * scan of the CPUs' dyntick-idle state.
2891 */
2892static void rcu_sysidle_report(struct rcu_state *rsp, int isidle,
2893 unsigned long maxj, bool gpkt)
2894{
417e8d26 2895 if (rsp != rcu_state_p)
0edd1b17
PM
2896 return; /* Wrong flavor, ignore. */
2897 if (gpkt && nr_cpu_ids <= CONFIG_NO_HZ_FULL_SYSIDLE_SMALL)
2898 return; /* Running state machine from timekeeping CPU. */
2899 if (isidle)
2900 rcu_sysidle(maxj); /* More idle! */
2901 else
2902 rcu_sysidle_cancel(); /* Idle is over. */
2903}
2904
2905/*
2906 * Wrapper for rcu_sysidle_report() when called from the grace-period
2907 * kthread's context.
2908 */
2909static void rcu_sysidle_report_gp(struct rcu_state *rsp, int isidle,
2910 unsigned long maxj)
2911{
663e1310
PM
2912 /* If there are no nohz_full= CPUs, no need to track this. */
2913 if (!tick_nohz_full_enabled())
2914 return;
2915
0edd1b17
PM
2916 rcu_sysidle_report(rsp, isidle, maxj, true);
2917}
2918
2919/* Callback and function for forcing an RCU grace period. */
2920struct rcu_sysidle_head {
2921 struct rcu_head rh;
2922 int inuse;
2923};
2924
2925static void rcu_sysidle_cb(struct rcu_head *rhp)
2926{
2927 struct rcu_sysidle_head *rshp;
2928
2929 /*
2930 * The following memory barrier is needed to replace the
2931 * memory barriers that would normally be in the memory
2932 * allocator.
2933 */
2934 smp_mb(); /* grace period precedes setting inuse. */
2935
2936 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
7d0ae808 2937 WRITE_ONCE(rshp->inuse, 0);
0edd1b17
PM
2938}
2939
2940/*
2941 * Check to see if the system is fully idle, other than the timekeeping CPU.
663e1310
PM
2942 * The caller must have disabled interrupts. This is not intended to be
2943 * called unless tick_nohz_full_enabled().
0edd1b17
PM
2944 */
2945bool rcu_sys_is_idle(void)
2946{
2947 static struct rcu_sysidle_head rsh;
7d0ae808 2948 int rss = READ_ONCE(full_sysidle_state);
0edd1b17
PM
2949
2950 if (WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu))
2951 return false;
2952
2953 /* Handle small-system case by doing a full scan of CPUs. */
2954 if (nr_cpu_ids <= CONFIG_NO_HZ_FULL_SYSIDLE_SMALL) {
2955 int oldrss = rss - 1;
2956
2957 /*
2958 * One pass to advance to each state up to _FULL.
2959 * Give up if any pass fails to advance the state.
2960 */
2961 while (rss < RCU_SYSIDLE_FULL && oldrss < rss) {
2962 int cpu;
2963 bool isidle = true;
2964 unsigned long maxj = jiffies - ULONG_MAX / 4;
2965 struct rcu_data *rdp;
2966
2967 /* Scan all the CPUs looking for nonidle CPUs. */
2968 for_each_possible_cpu(cpu) {
417e8d26 2969 rdp = per_cpu_ptr(rcu_state_p->rda, cpu);
0edd1b17
PM
2970 rcu_sysidle_check_cpu(rdp, &isidle, &maxj);
2971 if (!isidle)
2972 break;
2973 }
417e8d26 2974 rcu_sysidle_report(rcu_state_p, isidle, maxj, false);
0edd1b17 2975 oldrss = rss;
7d0ae808 2976 rss = READ_ONCE(full_sysidle_state);
0edd1b17
PM
2977 }
2978 }
2979
2980 /* If this is the first observation of an idle period, record it. */
2981 if (rss == RCU_SYSIDLE_FULL) {
2982 rss = cmpxchg(&full_sysidle_state,
2983 RCU_SYSIDLE_FULL, RCU_SYSIDLE_FULL_NOTED);
2984 return rss == RCU_SYSIDLE_FULL;
2985 }
2986
2987 smp_mb(); /* ensure rss load happens before later caller actions. */
2988
2989 /* If already fully idle, tell the caller (in case of races). */
2990 if (rss == RCU_SYSIDLE_FULL_NOTED)
2991 return true;
2992
2993 /*
2994 * If we aren't there yet, and a grace period is not in flight,
2995 * initiate a grace period. Either way, tell the caller that
2996 * we are not there yet. We use an xchg() rather than an assignment
2997 * to make up for the memory barriers that would otherwise be
2998 * provided by the memory allocator.
2999 */
3000 if (nr_cpu_ids > CONFIG_NO_HZ_FULL_SYSIDLE_SMALL &&
417e8d26 3001 !rcu_gp_in_progress(rcu_state_p) &&
0edd1b17
PM
3002 !rsh.inuse && xchg(&rsh.inuse, 1) == 0)
3003 call_rcu(&rsh.rh, rcu_sysidle_cb);
3004 return false;
eb348b89
PM
3005}
3006
2333210b
PM
3007/*
3008 * Initialize dynticks sysidle state for CPUs coming online.
3009 */
3010static void rcu_sysidle_init_percpu_data(struct rcu_dynticks *rdtp)
3011{
3012 rdtp->dynticks_idle_nesting = DYNTICK_TASK_NEST_VALUE;
3013}
3014
3015#else /* #ifdef CONFIG_NO_HZ_FULL_SYSIDLE */
3016
28ced795 3017static void rcu_sysidle_enter(int irq)
eb348b89
PM
3018{
3019}
3020
28ced795 3021static void rcu_sysidle_exit(int irq)
eb348b89
PM
3022{
3023}
3024
0edd1b17
PM
3025static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
3026 unsigned long *maxj)
3027{
3028}
3029
3030static bool is_sysidle_rcu_state(struct rcu_state *rsp)
3031{
3032 return false;
3033}
3034
3035static void rcu_sysidle_report_gp(struct rcu_state *rsp, int isidle,
3036 unsigned long maxj)
3037{
3038}
3039
2333210b
PM
3040static void rcu_sysidle_init_percpu_data(struct rcu_dynticks *rdtp)
3041{
3042}
3043
3044#endif /* #else #ifdef CONFIG_NO_HZ_FULL_SYSIDLE */
a096932f
PM
3045
3046/*
3047 * Is this CPU a NO_HZ_FULL CPU that should ignore RCU so that the
3048 * grace-period kthread will do force_quiescent_state() processing?
3049 * The idea is to avoid waking up RCU core processing on such a
3050 * CPU unless the grace period has extended for too long.
3051 *
3052 * This code relies on the fact that all NO_HZ_FULL CPUs are also
52e2bb95 3053 * CONFIG_RCU_NOCB_CPU CPUs.
a096932f
PM
3054 */
3055static bool rcu_nohz_full_cpu(struct rcu_state *rsp)
3056{
3057#ifdef CONFIG_NO_HZ_FULL
3058 if (tick_nohz_full_cpu(smp_processor_id()) &&
3059 (!rcu_gp_in_progress(rsp) ||
7d0ae808 3060 ULONG_CMP_LT(jiffies, READ_ONCE(rsp->gp_start) + HZ)))
5ce035fb 3061 return true;
a096932f 3062#endif /* #ifdef CONFIG_NO_HZ_FULL */
5ce035fb 3063 return false;
a096932f 3064}
5057f55e
PM
3065
3066/*
3067 * Bind the grace-period kthread for the sysidle flavor of RCU to the
3068 * timekeeping CPU.
3069 */
3070static void rcu_bind_gp_kthread(void)
3071{
c0f489d2 3072 int __maybe_unused cpu;
5057f55e 3073
c0f489d2 3074 if (!tick_nohz_full_enabled())
5057f55e 3075 return;
c0f489d2
PM
3076#ifdef CONFIG_NO_HZ_FULL_SYSIDLE
3077 cpu = tick_do_timer_cpu;
5871968d 3078 if (cpu >= 0 && cpu < nr_cpu_ids)
5057f55e 3079 set_cpus_allowed_ptr(current, cpumask_of(cpu));
c0f489d2 3080#else /* #ifdef CONFIG_NO_HZ_FULL_SYSIDLE */
5871968d 3081 housekeeping_affine(current);
c0f489d2 3082#endif /* #else #ifdef CONFIG_NO_HZ_FULL_SYSIDLE */
5057f55e 3083}
176f8f7a
PM
3084
3085/* Record the current task on dyntick-idle entry. */
3086static void rcu_dynticks_task_enter(void)
3087{
3088#if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
7d0ae808 3089 WRITE_ONCE(current->rcu_tasks_idle_cpu, smp_processor_id());
176f8f7a
PM
3090#endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
3091}
3092
3093/* Record no current task on dyntick-idle exit. */
3094static void rcu_dynticks_task_exit(void)
3095{
3096#if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL)
7d0ae808 3097 WRITE_ONCE(current->rcu_tasks_idle_cpu, -1);
176f8f7a
PM
3098#endif /* #if defined(CONFIG_TASKS_RCU) && defined(CONFIG_NO_HZ_FULL) */
3099}