blob: 608af87a50658e40c8494e836bad90c62e0eead7 [file] [log] [blame]
Paul E. McKenneyeacd6f02020-03-02 11:59:20 -08001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Task-based RCU implementations.
4 *
5 * Copyright (C) 2020 Paul E. McKenney
6 */
7
Paul E. McKenney8fd8ca32020-03-15 14:51:20 -07008#ifdef CONFIG_TASKS_RCU_GENERIC
Paul E. McKenney9b073de2021-11-08 16:18:57 -08009#include "rcu_segcblist.h"
Paul E. McKenney5873b8a2020-03-03 11:49:21 -080010
11////////////////////////////////////////////////////////////////////////
12//
13// Generic data structures.
14
15struct rcu_tasks;
16typedef void (*rcu_tasks_gp_func_t)(struct rcu_tasks *rtp);
Paul E. McKenneye4fe5dd2020-03-04 17:31:43 -080017typedef void (*pregp_func_t)(void);
18typedef void (*pertask_func_t)(struct task_struct *t, struct list_head *hop);
Paul E. McKenney9796e1a2020-03-22 13:18:54 -070019typedef void (*postscan_func_t)(struct list_head *hop);
Paul E. McKenneye4fe5dd2020-03-04 17:31:43 -080020typedef void (*holdouts_func_t)(struct list_head *hop, bool ndrpt, bool *frptp);
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -070021typedef void (*postgp_func_t)(struct rcu_tasks *rtp);
Paul E. McKenneyeacd6f02020-03-02 11:59:20 -080022
Paul E. McKenney07e10512020-03-02 15:16:57 -080023/**
Paul E. McKenneycafafd62021-11-05 21:52:00 -070024 * struct rcu_tasks_percpu - Per-CPU component of definition for a Tasks-RCU-like mechanism.
Paul E. McKenney9b073de2021-11-08 16:18:57 -080025 * @cblist: Callback list.
Paul E. McKenney381a4f32021-11-08 16:52:02 -080026 * @lock: Lock protecting per-CPU callback list.
Paul E. McKenneycafafd62021-11-05 21:52:00 -070027 */
28struct rcu_tasks_percpu {
Paul E. McKenney9b073de2021-11-08 16:18:57 -080029 struct rcu_segcblist cblist;
Paul E. McKenney381a4f32021-11-08 16:52:02 -080030 raw_spinlock_t __private lock;
Paul E. McKenneycafafd62021-11-05 21:52:00 -070031};
32
33/**
34 * struct rcu_tasks - Definition for a Tasks-RCU-like mechanism.
Ingo Molnara616aec2021-03-22 22:29:10 -070035 * @cbs_wq: Wait queue allowing new callback to get kthread's attention.
Paul E. McKenneycafafd62021-11-05 21:52:00 -070036 * @cbs_gbl_lock: Lock protecting callback list.
Paul E. McKenney07e10512020-03-02 15:16:57 -080037 * @kthread_ptr: This flavor's grace-period/callback-invocation kthread.
Paul E. McKenney5873b8a2020-03-03 11:49:21 -080038 * @gp_func: This flavor's grace-period-wait function.
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -070039 * @gp_state: Grace period's most recent state transition (debugging).
Paul E. McKenney4fe192d2020-09-09 22:05:41 -070040 * @gp_sleep: Per-grace-period sleep to prevent CPU-bound looping.
Paul E. McKenney2393a612020-09-09 21:36:34 -070041 * @init_fract: Initial backoff sleep interval.
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -070042 * @gp_jiffies: Time of last @gp_state transition.
43 * @gp_start: Most recent grace-period start in jiffies.
Paul E. McKenneyb14fb4f2021-11-08 14:14:43 -080044 * @tasks_gp_seq: Number of grace periods completed since boot.
Paul E. McKenney238dbce2020-03-18 10:54:05 -070045 * @n_ipis: Number of IPIs sent to encourage grace periods to end.
Paul E. McKenney7e0669c2020-03-25 14:36:05 -070046 * @n_ipis_fails: Number of IPI-send failures.
Paul E. McKenneye4fe5dd2020-03-04 17:31:43 -080047 * @pregp_func: This flavor's pre-grace-period function (optional).
48 * @pertask_func: This flavor's per-task scan function (optional).
49 * @postscan_func: This flavor's post-task scan function (optional).
Lukas Bulwahn85b86992021-01-25 08:41:05 +010050 * @holdouts_func: This flavor's holdout-list scan function (optional).
Paul E. McKenneye4fe5dd2020-03-04 17:31:43 -080051 * @postgp_func: This flavor's post-grace-period function (optional).
Paul E. McKenney5873b8a2020-03-03 11:49:21 -080052 * @call_func: This flavor's call_rcu()-equivalent function.
Paul E. McKenneycafafd62021-11-05 21:52:00 -070053 * @rtpcpu: This flavor's rcu_tasks_percpu structure.
Paul E. McKenney7a308712021-11-08 10:51:13 -080054 * @percpu_enqueue_shift: Shift down CPU ID this much when enqueuing callbacks.
Paul E. McKenney8dd593f2021-11-09 11:11:32 -080055 * @percpu_enqueue_lim: Number of per-CPU callback queues in use.
Paul E. McKenneyc97d12a2020-03-03 15:50:31 -080056 * @name: This flavor's textual name.
57 * @kname: This flavor's kthread name.
Paul E. McKenney07e10512020-03-02 15:16:57 -080058 */
59struct rcu_tasks {
Paul E. McKenney07e10512020-03-02 15:16:57 -080060 struct wait_queue_head cbs_wq;
Paul E. McKenneycafafd62021-11-05 21:52:00 -070061 raw_spinlock_t cbs_gbl_lock;
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -070062 int gp_state;
Paul E. McKenney4fe192d2020-09-09 22:05:41 -070063 int gp_sleep;
Paul E. McKenney2393a612020-09-09 21:36:34 -070064 int init_fract;
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -070065 unsigned long gp_jiffies;
Paul E. McKenney88092d02020-03-17 08:57:02 -070066 unsigned long gp_start;
Paul E. McKenneyb14fb4f2021-11-08 14:14:43 -080067 unsigned long tasks_gp_seq;
Paul E. McKenney238dbce2020-03-18 10:54:05 -070068 unsigned long n_ipis;
Paul E. McKenney7e0669c2020-03-25 14:36:05 -070069 unsigned long n_ipis_fails;
Paul E. McKenney07e10512020-03-02 15:16:57 -080070 struct task_struct *kthread_ptr;
Paul E. McKenney5873b8a2020-03-03 11:49:21 -080071 rcu_tasks_gp_func_t gp_func;
Paul E. McKenneye4fe5dd2020-03-04 17:31:43 -080072 pregp_func_t pregp_func;
73 pertask_func_t pertask_func;
74 postscan_func_t postscan_func;
75 holdouts_func_t holdouts_func;
76 postgp_func_t postgp_func;
Paul E. McKenney5873b8a2020-03-03 11:49:21 -080077 call_rcu_func_t call_func;
Paul E. McKenneycafafd62021-11-05 21:52:00 -070078 struct rcu_tasks_percpu __percpu *rtpcpu;
Paul E. McKenney7a308712021-11-08 10:51:13 -080079 int percpu_enqueue_shift;
Paul E. McKenney8dd593f2021-11-09 11:11:32 -080080 int percpu_enqueue_lim;
Paul E. McKenneyc97d12a2020-03-03 15:50:31 -080081 char *name;
82 char *kname;
Paul E. McKenney07e10512020-03-02 15:16:57 -080083};
84
Paul E. McKenneycafafd62021-11-05 21:52:00 -070085#define DEFINE_RCU_TASKS(rt_name, gp, call, n) \
86static DEFINE_PER_CPU(struct rcu_tasks_percpu, rt_name ## __percpu) = { \
Paul E. McKenney381a4f32021-11-08 16:52:02 -080087 .lock = __RAW_SPIN_LOCK_UNLOCKED(rt_name ## __percpu.cbs_pcpu_lock), \
Paul E. McKenneycafafd62021-11-05 21:52:00 -070088}; \
89static struct rcu_tasks rt_name = \
90{ \
91 .cbs_wq = __WAIT_QUEUE_HEAD_INITIALIZER(rt_name.cbs_wq), \
92 .cbs_gbl_lock = __RAW_SPIN_LOCK_UNLOCKED(rt_name.cbs_gbl_lock), \
93 .gp_func = gp, \
94 .call_func = call, \
95 .rtpcpu = &rt_name ## __percpu, \
96 .name = n, \
Paul E. McKenney7a308712021-11-08 10:51:13 -080097 .percpu_enqueue_shift = ilog2(CONFIG_NR_CPUS), \
Paul E. McKenney8dd593f2021-11-09 11:11:32 -080098 .percpu_enqueue_lim = 1, \
Paul E. McKenneycafafd62021-11-05 21:52:00 -070099 .kname = #rt_name, \
Paul E. McKenney07e10512020-03-02 15:16:57 -0800100}
101
Paul E. McKenneyeacd6f02020-03-02 11:59:20 -0800102/* Track exiting tasks in order to allow them to be waited for. */
103DEFINE_STATIC_SRCU(tasks_rcu_exit_srcu);
104
Paul E. McKenneyb0afa0f2020-03-17 11:39:26 -0700105/* Avoid IPIing CPUs early in the grace period. */
Paul E. McKenney574de872020-09-09 21:51:09 -0700106#define RCU_TASK_IPI_DELAY (IS_ENABLED(CONFIG_TASKS_TRACE_RCU_READ_MB) ? HZ / 2 : 0)
Paul E. McKenneyb0afa0f2020-03-17 11:39:26 -0700107static int rcu_task_ipi_delay __read_mostly = RCU_TASK_IPI_DELAY;
108module_param(rcu_task_ipi_delay, int, 0644);
109
Paul E. McKenneyeacd6f02020-03-02 11:59:20 -0800110/* Control stall timeouts. Disable with <= 0, otherwise jiffies till stall. */
111#define RCU_TASK_STALL_TIMEOUT (HZ * 60 * 10)
112static int rcu_task_stall_timeout __read_mostly = RCU_TASK_STALL_TIMEOUT;
113module_param(rcu_task_stall_timeout, int, 0644);
114
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -0700115/* RCU tasks grace-period state for debugging. */
116#define RTGS_INIT 0
117#define RTGS_WAIT_WAIT_CBS 1
118#define RTGS_WAIT_GP 2
119#define RTGS_PRE_WAIT_GP 3
120#define RTGS_SCAN_TASKLIST 4
121#define RTGS_POST_SCAN_TASKLIST 5
122#define RTGS_WAIT_SCAN_HOLDOUTS 6
123#define RTGS_SCAN_HOLDOUTS 7
124#define RTGS_POST_GP 8
125#define RTGS_WAIT_READERS 9
126#define RTGS_INVOKE_CBS 10
127#define RTGS_WAIT_CBS 11
Paul E. McKenney83444962020-05-28 20:03:48 -0700128#ifndef CONFIG_TINY_RCU
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -0700129static const char * const rcu_tasks_gp_state_names[] = {
130 "RTGS_INIT",
131 "RTGS_WAIT_WAIT_CBS",
132 "RTGS_WAIT_GP",
133 "RTGS_PRE_WAIT_GP",
134 "RTGS_SCAN_TASKLIST",
135 "RTGS_POST_SCAN_TASKLIST",
136 "RTGS_WAIT_SCAN_HOLDOUTS",
137 "RTGS_SCAN_HOLDOUTS",
138 "RTGS_POST_GP",
139 "RTGS_WAIT_READERS",
140 "RTGS_INVOKE_CBS",
141 "RTGS_WAIT_CBS",
142};
Paul E. McKenney83444962020-05-28 20:03:48 -0700143#endif /* #ifndef CONFIG_TINY_RCU */
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -0700144
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800145////////////////////////////////////////////////////////////////////////
146//
147// Generic code.
148
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -0700149/* Record grace-period phase and time. */
150static void set_tasks_gp_state(struct rcu_tasks *rtp, int newstate)
151{
152 rtp->gp_state = newstate;
153 rtp->gp_jiffies = jiffies;
154}
155
Paul E. McKenney83444962020-05-28 20:03:48 -0700156#ifndef CONFIG_TINY_RCU
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -0700157/* Return state name. */
158static const char *tasks_gp_state_getname(struct rcu_tasks *rtp)
159{
160 int i = data_race(rtp->gp_state); // Let KCSAN detect update races
161 int j = READ_ONCE(i); // Prevent the compiler from reading twice
162
163 if (j >= ARRAY_SIZE(rcu_tasks_gp_state_names))
164 return "???";
165 return rcu_tasks_gp_state_names[j];
166}
Paul E. McKenney83444962020-05-28 20:03:48 -0700167#endif /* #ifndef CONFIG_TINY_RCU */
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -0700168
Paul E. McKenneycafafd62021-11-05 21:52:00 -0700169// Initialize per-CPU callback lists for the specified flavor of
170// Tasks RCU.
171static void cblist_init_generic(struct rcu_tasks *rtp)
172{
173 int cpu;
174 unsigned long flags;
175
176 raw_spin_lock_irqsave(&rtp->cbs_gbl_lock, flags);
Paul E. McKenney7a308712021-11-08 10:51:13 -0800177 rtp->percpu_enqueue_shift = ilog2(nr_cpu_ids);
Paul E. McKenney8dd593f2021-11-09 11:11:32 -0800178 rtp->percpu_enqueue_lim = 1;
Paul E. McKenneycafafd62021-11-05 21:52:00 -0700179 for_each_possible_cpu(cpu) {
180 struct rcu_tasks_percpu *rtpcp = per_cpu_ptr(rtp->rtpcpu, cpu);
181
182 WARN_ON_ONCE(!rtpcp);
183 if (cpu)
Paul E. McKenney381a4f32021-11-08 16:52:02 -0800184 raw_spin_lock_init(&ACCESS_PRIVATE(rtpcp, lock));
185 raw_spin_lock_rcu_node(rtpcp); // irqs already disabled.
Paul E. McKenney9b073de2021-11-08 16:18:57 -0800186 if (rcu_segcblist_empty(&rtpcp->cblist))
187 rcu_segcblist_init(&rtpcp->cblist);
Paul E. McKenney381a4f32021-11-08 16:52:02 -0800188 raw_spin_unlock_rcu_node(rtpcp); // irqs remain disabled.
Paul E. McKenneycafafd62021-11-05 21:52:00 -0700189 }
190 raw_spin_unlock_irqrestore(&rtp->cbs_gbl_lock, flags);
191
192}
193
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800194// Enqueue a callback for the specified flavor of Tasks RCU.
195static void call_rcu_tasks_generic(struct rcu_head *rhp, rcu_callback_t func,
196 struct rcu_tasks *rtp)
Paul E. McKenneyeacd6f02020-03-02 11:59:20 -0800197{
198 unsigned long flags;
199 bool needwake;
Paul E. McKenneycafafd62021-11-05 21:52:00 -0700200 struct rcu_tasks_percpu *rtpcp;
Paul E. McKenneyeacd6f02020-03-02 11:59:20 -0800201
202 rhp->next = NULL;
203 rhp->func = func;
Paul E. McKenneycafafd62021-11-05 21:52:00 -0700204 local_irq_save(flags);
Paul E. McKenney7a308712021-11-08 10:51:13 -0800205 rtpcp = per_cpu_ptr(rtp->rtpcpu,
206 smp_processor_id() >> READ_ONCE(rtp->percpu_enqueue_shift));
Paul E. McKenney381a4f32021-11-08 16:52:02 -0800207 raw_spin_lock_rcu_node(rtpcp); // irqs already disabled.
Paul E. McKenney9b073de2021-11-08 16:18:57 -0800208 if (!rcu_segcblist_is_enabled(&rtpcp->cblist)) {
Paul E. McKenney381a4f32021-11-08 16:52:02 -0800209 raw_spin_unlock_rcu_node(rtpcp); // irqs remain disabled.
Paul E. McKenneycafafd62021-11-05 21:52:00 -0700210 cblist_init_generic(rtp);
Paul E. McKenney381a4f32021-11-08 16:52:02 -0800211 raw_spin_lock_rcu_node(rtpcp); // irqs already disabled.
Paul E. McKenneycafafd62021-11-05 21:52:00 -0700212 }
Paul E. McKenney9b073de2021-11-08 16:18:57 -0800213 needwake = rcu_segcblist_empty(&rtpcp->cblist);
214 rcu_segcblist_enqueue(&rtpcp->cblist, rhp);
Paul E. McKenney381a4f32021-11-08 16:52:02 -0800215 raw_spin_unlock_irqrestore_rcu_node(rtpcp, flags);
Paul E. McKenneyeacd6f02020-03-02 11:59:20 -0800216 /* We can't create the thread unless interrupts are enabled. */
Paul E. McKenney07e10512020-03-02 15:16:57 -0800217 if (needwake && READ_ONCE(rtp->kthread_ptr))
218 wake_up(&rtp->cbs_wq);
Paul E. McKenneyeacd6f02020-03-02 11:59:20 -0800219}
Paul E. McKenneyeacd6f02020-03-02 11:59:20 -0800220
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800221// Wait for a grace period for the specified flavor of Tasks RCU.
222static void synchronize_rcu_tasks_generic(struct rcu_tasks *rtp)
Paul E. McKenneyeacd6f02020-03-02 11:59:20 -0800223{
224 /* Complain if the scheduler has not started. */
225 RCU_LOCKDEP_WARN(rcu_scheduler_active == RCU_SCHEDULER_INACTIVE,
226 "synchronize_rcu_tasks called too soon");
227
228 /* Wait for the grace period. */
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800229 wait_rcu_gp(rtp->call_func);
Paul E. McKenneyeacd6f02020-03-02 11:59:20 -0800230}
Paul E. McKenneyeacd6f02020-03-02 11:59:20 -0800231
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800232/* RCU-tasks kthread that detects grace periods and invokes callbacks. */
233static int __noreturn rcu_tasks_kthread(void *arg)
Paul E. McKenneyeacd6f02020-03-02 11:59:20 -0800234{
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800235 unsigned long flags;
Paul E. McKenney9b073de2021-11-08 16:18:57 -0800236 int len;
237 struct rcu_cblist rcl = RCU_CBLIST_INITIALIZER(rcl);
238 struct rcu_head *rhp;
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800239 struct rcu_tasks *rtp = arg;
240
241 /* Run on housekeeping CPUs by default. Sysadm can move if desired. */
242 housekeeping_affine(current, HK_FLAG_RCU);
243 WRITE_ONCE(rtp->kthread_ptr, current); // Let GPs start!
244
245 /*
246 * Each pass through the following loop makes one check for
247 * newly arrived callbacks, and, if there are some, waits for
248 * one RCU-tasks grace period and then invokes the callbacks.
249 * This loop is terminated by the system going down. ;-)
250 */
251 for (;;) {
Paul E. McKenneycafafd62021-11-05 21:52:00 -0700252 struct rcu_tasks_percpu *rtpcp = per_cpu_ptr(rtp->rtpcpu, 0); // for_each...
253
Paul E. McKenney0db7c322021-08-11 09:07:44 -0700254 set_tasks_gp_state(rtp, RTGS_WAIT_CBS);
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800255
256 /* Pick up any new callbacks. */
Paul E. McKenney381a4f32021-11-08 16:52:02 -0800257 raw_spin_lock_irqsave_rcu_node(rtpcp, flags);
Paul E. McKenney9b073de2021-11-08 16:18:57 -0800258 rcu_segcblist_advance(&rtpcp->cblist, rcu_seq_current(&rtp->tasks_gp_seq));
259 (void)rcu_segcblist_accelerate(&rtpcp->cblist, rcu_seq_snap(&rtp->tasks_gp_seq));
Paul E. McKenney381a4f32021-11-08 16:52:02 -0800260 raw_spin_unlock_irqrestore_rcu_node(rtpcp, flags);
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800261
262 /* If there were none, wait a bit and start over. */
Paul E. McKenney9b073de2021-11-08 16:18:57 -0800263 if (!rcu_segcblist_pend_cbs(&rtpcp->cblist)) {
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800264 wait_event_interruptible(rtp->cbs_wq,
Paul E. McKenney9b073de2021-11-08 16:18:57 -0800265 rcu_segcblist_pend_cbs(&rtpcp->cblist));
266 if (!rcu_segcblist_pend_cbs(&rtpcp->cblist)) {
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800267 WARN_ON(signal_pending(current));
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -0700268 set_tasks_gp_state(rtp, RTGS_WAIT_WAIT_CBS);
Paul E. McKenneyea6eed92020-05-07 16:47:13 -0700269 schedule_timeout_idle(HZ/10);
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800270 }
271 continue;
272 }
273
274 // Wait for one grace period.
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -0700275 set_tasks_gp_state(rtp, RTGS_WAIT_GP);
Paul E. McKenney88092d02020-03-17 08:57:02 -0700276 rtp->gp_start = jiffies;
Paul E. McKenneyb14fb4f2021-11-08 14:14:43 -0800277 rcu_seq_start(&rtp->tasks_gp_seq);
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800278 rtp->gp_func(rtp);
Paul E. McKenneyb14fb4f2021-11-08 14:14:43 -0800279 rcu_seq_end(&rtp->tasks_gp_seq);
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800280
281 /* Invoke the callbacks. */
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -0700282 set_tasks_gp_state(rtp, RTGS_INVOKE_CBS);
Paul E. McKenney381a4f32021-11-08 16:52:02 -0800283 raw_spin_lock_irqsave_rcu_node(rtpcp, flags);
Paul E. McKenney9b073de2021-11-08 16:18:57 -0800284 rcu_segcblist_advance(&rtpcp->cblist, rcu_seq_current(&rtp->tasks_gp_seq));
285 rcu_segcblist_extract_done_cbs(&rtpcp->cblist, &rcl);
Paul E. McKenney381a4f32021-11-08 16:52:02 -0800286 raw_spin_unlock_irqrestore_rcu_node(rtpcp, flags);
Paul E. McKenney9b073de2021-11-08 16:18:57 -0800287 len = rcl.len;
288 for (rhp = rcu_cblist_dequeue(&rcl); rhp; rhp = rcu_cblist_dequeue(&rcl)) {
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800289 local_bh_disable();
Paul E. McKenney9b073de2021-11-08 16:18:57 -0800290 rhp->func(rhp);
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800291 local_bh_enable();
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800292 cond_resched();
293 }
Paul E. McKenney381a4f32021-11-08 16:52:02 -0800294 raw_spin_lock_irqsave_rcu_node(rtpcp, flags);
Paul E. McKenney9b073de2021-11-08 16:18:57 -0800295 rcu_segcblist_add_len(&rtpcp->cblist, -len);
296 (void)rcu_segcblist_accelerate(&rtpcp->cblist, rcu_seq_snap(&rtp->tasks_gp_seq));
Paul E. McKenney381a4f32021-11-08 16:52:02 -0800297 raw_spin_unlock_irqrestore_rcu_node(rtpcp, flags);
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800298 /* Paranoid sleep to keep this from entering a tight loop */
Paul E. McKenney4fe192d2020-09-09 22:05:41 -0700299 schedule_timeout_idle(rtp->gp_sleep);
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800300 }
Paul E. McKenneyeacd6f02020-03-02 11:59:20 -0800301}
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800302
Uladzislau Rezki (Sony)1b04fa92020-12-09 21:27:31 +0100303/* Spawn RCU-tasks grace-period kthread. */
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800304static void __init rcu_spawn_tasks_kthread_generic(struct rcu_tasks *rtp)
305{
306 struct task_struct *t;
307
Paul E. McKenneyc97d12a2020-03-03 15:50:31 -0800308 t = kthread_run(rcu_tasks_kthread, rtp, "%s_kthread", rtp->kname);
309 if (WARN_ONCE(IS_ERR(t), "%s: Could not start %s grace-period kthread, OOM is now expected behavior\n", __func__, rtp->name))
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800310 return;
311 smp_mb(); /* Ensure others see full kthread. */
312}
313
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800314#ifndef CONFIG_TINY_RCU
315
316/*
317 * Print any non-default Tasks RCU settings.
318 */
319static void __init rcu_tasks_bootup_oddness(void)
320{
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -0700321#if defined(CONFIG_TASKS_RCU) || defined(CONFIG_TASKS_TRACE_RCU)
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800322 if (rcu_task_stall_timeout != RCU_TASK_STALL_TIMEOUT)
323 pr_info("\tTasks-RCU CPU stall warnings timeout set to %d (rcu_task_stall_timeout).\n", rcu_task_stall_timeout);
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -0700324#endif /* #ifdef CONFIG_TASKS_RCU */
325#ifdef CONFIG_TASKS_RCU
326 pr_info("\tTrampoline variant of Tasks RCU enabled.\n");
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800327#endif /* #ifdef CONFIG_TASKS_RCU */
Paul E. McKenneyc84aad72020-03-02 21:06:43 -0800328#ifdef CONFIG_TASKS_RUDE_RCU
329 pr_info("\tRude variant of Tasks RCU enabled.\n");
330#endif /* #ifdef CONFIG_TASKS_RUDE_RCU */
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -0700331#ifdef CONFIG_TASKS_TRACE_RCU
332 pr_info("\tTracing variant of Tasks RCU enabled.\n");
333#endif /* #ifdef CONFIG_TASKS_TRACE_RCU */
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800334}
335
336#endif /* #ifndef CONFIG_TINY_RCU */
337
Paul E. McKenney83444962020-05-28 20:03:48 -0700338#ifndef CONFIG_TINY_RCU
Paul E. McKenneye21408c2020-03-16 11:01:55 -0700339/* Dump out rcutorture-relevant state common to all RCU-tasks flavors. */
340static void show_rcu_tasks_generic_gp_kthread(struct rcu_tasks *rtp, char *s)
341{
Paul E. McKenneycafafd62021-11-05 21:52:00 -0700342 struct rcu_tasks_percpu *rtpcp = per_cpu_ptr(rtp->rtpcpu, 0); // for_each...
Paul E. McKenney7e0669c2020-03-25 14:36:05 -0700343 pr_info("%s: %s(%d) since %lu g:%lu i:%lu/%lu %c%c %s\n",
Paul E. McKenneye21408c2020-03-16 11:01:55 -0700344 rtp->kname,
Paul E. McKenney7e0669c2020-03-25 14:36:05 -0700345 tasks_gp_state_getname(rtp), data_race(rtp->gp_state),
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -0700346 jiffies - data_race(rtp->gp_jiffies),
Paul E. McKenneyb14fb4f2021-11-08 14:14:43 -0800347 data_race(rcu_seq_current(&rtp->tasks_gp_seq)),
Paul E. McKenney7e0669c2020-03-25 14:36:05 -0700348 data_race(rtp->n_ipis_fails), data_race(rtp->n_ipis),
Paul E. McKenneye21408c2020-03-16 11:01:55 -0700349 ".k"[!!data_race(rtp->kthread_ptr)],
Paul E. McKenney9b073de2021-11-08 16:18:57 -0800350 ".C"[!data_race(rcu_segcblist_empty(&rtpcp->cblist))],
Paul E. McKenneye21408c2020-03-16 11:01:55 -0700351 s);
352}
Paul E. McKenney27c0f142020-09-15 17:08:03 -0700353#endif // #ifndef CONFIG_TINY_RCU
Paul E. McKenneye21408c2020-03-16 11:01:55 -0700354
Paul E. McKenney25246fc2020-04-05 20:49:13 -0700355static void exit_tasks_rcu_finish_trace(struct task_struct *t);
356
357#if defined(CONFIG_TASKS_RCU) || defined(CONFIG_TASKS_TRACE_RCU)
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800358
359////////////////////////////////////////////////////////////////////////
360//
Paul E. McKenneyd01aa262020-03-05 17:07:07 -0800361// Shared code between task-list-scanning variants of Tasks RCU.
362
363/* Wait for one RCU-tasks grace period. */
364static void rcu_tasks_wait_gp(struct rcu_tasks *rtp)
365{
366 struct task_struct *g, *t;
367 unsigned long lastreport;
368 LIST_HEAD(holdouts);
369 int fract;
370
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -0700371 set_tasks_gp_state(rtp, RTGS_PRE_WAIT_GP);
Paul E. McKenneyd01aa262020-03-05 17:07:07 -0800372 rtp->pregp_func();
373
374 /*
375 * There were callbacks, so we need to wait for an RCU-tasks
376 * grace period. Start off by scanning the task list for tasks
377 * that are not already voluntarily blocked. Mark these tasks
378 * and make a list of them in holdouts.
379 */
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -0700380 set_tasks_gp_state(rtp, RTGS_SCAN_TASKLIST);
Paul E. McKenneyd01aa262020-03-05 17:07:07 -0800381 rcu_read_lock();
382 for_each_process_thread(g, t)
383 rtp->pertask_func(t, &holdouts);
384 rcu_read_unlock();
385
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -0700386 set_tasks_gp_state(rtp, RTGS_POST_SCAN_TASKLIST);
Paul E. McKenney9796e1a2020-03-22 13:18:54 -0700387 rtp->postscan_func(&holdouts);
Paul E. McKenneyd01aa262020-03-05 17:07:07 -0800388
389 /*
390 * Each pass through the following loop scans the list of holdout
391 * tasks, removing any that are no longer holdouts. When the list
392 * is empty, we are done.
393 */
394 lastreport = jiffies;
395
Paul E. McKenney2393a612020-09-09 21:36:34 -0700396 // Start off with initial wait and slowly back off to 1 HZ wait.
397 fract = rtp->init_fract;
Paul E. McKenneyd01aa262020-03-05 17:07:07 -0800398
Paul E. McKenney77dc1742020-09-15 15:41:50 -0700399 while (!list_empty(&holdouts)) {
Paul E. McKenneyd01aa262020-03-05 17:07:07 -0800400 bool firstreport;
401 bool needreport;
402 int rtst;
403
Paul E. McKenneyd01aa262020-03-05 17:07:07 -0800404 /* Slowly back off waiting for holdouts */
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -0700405 set_tasks_gp_state(rtp, RTGS_WAIT_SCAN_HOLDOUTS);
Paul E. McKenney75dc2da2020-09-17 16:17:17 -0700406 schedule_timeout_idle(fract);
Paul E. McKenneyd01aa262020-03-05 17:07:07 -0800407
Paul E. McKenney75dc2da2020-09-17 16:17:17 -0700408 if (fract < HZ)
409 fract++;
Paul E. McKenneyd01aa262020-03-05 17:07:07 -0800410
411 rtst = READ_ONCE(rcu_task_stall_timeout);
412 needreport = rtst > 0 && time_after(jiffies, lastreport + rtst);
413 if (needreport)
414 lastreport = jiffies;
415 firstreport = true;
416 WARN_ON(signal_pending(current));
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -0700417 set_tasks_gp_state(rtp, RTGS_SCAN_HOLDOUTS);
Paul E. McKenneyd01aa262020-03-05 17:07:07 -0800418 rtp->holdouts_func(&holdouts, needreport, &firstreport);
419 }
420
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -0700421 set_tasks_gp_state(rtp, RTGS_POST_GP);
422 rtp->postgp_func(rtp);
Paul E. McKenneyd01aa262020-03-05 17:07:07 -0800423}
424
Paul E. McKenney25246fc2020-04-05 20:49:13 -0700425#endif /* #if defined(CONFIG_TASKS_RCU) || defined(CONFIG_TASKS_TRACE_RCU) */
426
427#ifdef CONFIG_TASKS_RCU
428
Paul E. McKenneyd01aa262020-03-05 17:07:07 -0800429////////////////////////////////////////////////////////////////////////
430//
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800431// Simple variant of RCU whose quiescent states are voluntary context
Paul E. McKenney8af9e2c2021-09-15 09:24:18 -0700432// switch, cond_resched_tasks_rcu_qs(), user-space execution, and idle.
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800433// As such, grace periods can take one good long time. There are no
434// read-side primitives similar to rcu_read_lock() and rcu_read_unlock()
435// because this implementation is intended to get the system into a safe
436// state for some of the manipulations involved in tracing and the like.
437// Finally, this implementation does not support high call_rcu_tasks()
438// rates from multiple CPUs. If this is required, per-CPU callback lists
439// will be needed.
Paul E. McKenney06a3ec92021-03-04 14:41:47 -0800440//
441// The implementation uses rcu_tasks_wait_gp(), which relies on function
442// pointers in the rcu_tasks structure. The rcu_spawn_tasks_kthread()
443// function sets these function pointers up so that rcu_tasks_wait_gp()
444// invokes these functions in this order:
445//
446// rcu_tasks_pregp_step():
447// Invokes synchronize_rcu() in order to wait for all in-flight
448// t->on_rq and t->nvcsw transitions to complete. This works because
449// all such transitions are carried out with interrupts disabled.
450// rcu_tasks_pertask(), invoked on every non-idle task:
451// For every runnable non-idle task other than the current one, use
452// get_task_struct() to pin down that task, snapshot that task's
453// number of voluntary context switches, and add that task to the
454// holdout list.
455// rcu_tasks_postscan():
456// Invoke synchronize_srcu() to ensure that all tasks that were
457// in the process of exiting (and which thus might not know to
458// synchronize with this RCU Tasks grace period) have completed
459// exiting.
460// check_all_holdout_tasks(), repeatedly until holdout list is empty:
461// Scans the holdout list, attempting to identify a quiescent state
462// for each task on the list. If there is a quiescent state, the
463// corresponding task is removed from the holdout list.
464// rcu_tasks_postgp():
465// Invokes synchronize_rcu() in order to ensure that all prior
466// t->on_rq and t->nvcsw transitions are seen by all CPUs and tasks
467// to have happened before the end of this RCU Tasks grace period.
468// Again, this works because all such transitions are carried out
469// with interrupts disabled.
470//
471// For each exiting task, the exit_tasks_rcu_start() and
472// exit_tasks_rcu_finish() functions begin and end, respectively, the SRCU
473// read-side critical sections waited for by rcu_tasks_postscan().
474//
Paul E. McKenney381a4f32021-11-08 16:52:02 -0800475// Pre-grace-period update-side code is ordered before the grace
476// via the raw_spin_lock.*rcu_node(). Pre-grace-period read-side code
477// is ordered before the grace period via synchronize_rcu() call in
478// rcu_tasks_pregp_step() and by the scheduler's locks and interrupt
Paul E. McKenney06a3ec92021-03-04 14:41:47 -0800479// disabling.
Paul E. McKenneyeacd6f02020-03-02 11:59:20 -0800480
Paul E. McKenneye4fe5dd2020-03-04 17:31:43 -0800481/* Pre-grace-period preparation. */
482static void rcu_tasks_pregp_step(void)
483{
484 /*
485 * Wait for all pre-existing t->on_rq and t->nvcsw transitions
486 * to complete. Invoking synchronize_rcu() suffices because all
487 * these transitions occur with interrupts disabled. Without this
488 * synchronize_rcu(), a read-side critical section that started
489 * before the grace period might be incorrectly seen as having
490 * started after the grace period.
491 *
492 * This synchronize_rcu() also dispenses with the need for a
493 * memory barrier on the first store to t->rcu_tasks_holdout,
494 * as it forces the store to happen after the beginning of the
495 * grace period.
496 */
497 synchronize_rcu();
498}
499
500/* Per-task initial processing. */
501static void rcu_tasks_pertask(struct task_struct *t, struct list_head *hop)
502{
503 if (t != current && READ_ONCE(t->on_rq) && !is_idle_task(t)) {
504 get_task_struct(t);
505 t->rcu_tasks_nvcsw = READ_ONCE(t->nvcsw);
506 WRITE_ONCE(t->rcu_tasks_holdout, true);
507 list_add(&t->rcu_tasks_holdout_list, hop);
508 }
509}
510
511/* Processing between scanning taskslist and draining the holdout list. */
Paul E. McKenney04a3c5a2020-05-28 19:27:06 -0700512static void rcu_tasks_postscan(struct list_head *hop)
Paul E. McKenneye4fe5dd2020-03-04 17:31:43 -0800513{
514 /*
515 * Wait for tasks that are in the process of exiting. This
516 * does only part of the job, ensuring that all tasks that were
517 * previously exiting reach the point where they have disabled
518 * preemption, allowing the later synchronize_rcu() to finish
519 * the job.
520 */
521 synchronize_srcu(&tasks_rcu_exit_srcu);
522}
523
Paul E. McKenneyeacd6f02020-03-02 11:59:20 -0800524/* See if tasks are still holding out, complain if so. */
525static void check_holdout_task(struct task_struct *t,
526 bool needreport, bool *firstreport)
527{
528 int cpu;
529
530 if (!READ_ONCE(t->rcu_tasks_holdout) ||
531 t->rcu_tasks_nvcsw != READ_ONCE(t->nvcsw) ||
532 !READ_ONCE(t->on_rq) ||
533 (IS_ENABLED(CONFIG_NO_HZ_FULL) &&
534 !is_idle_task(t) && t->rcu_tasks_idle_cpu >= 0)) {
535 WRITE_ONCE(t->rcu_tasks_holdout, false);
536 list_del_init(&t->rcu_tasks_holdout_list);
537 put_task_struct(t);
538 return;
539 }
540 rcu_request_urgent_qs_task(t);
541 if (!needreport)
542 return;
543 if (*firstreport) {
544 pr_err("INFO: rcu_tasks detected stalls on tasks:\n");
545 *firstreport = false;
546 }
547 cpu = task_cpu(t);
548 pr_alert("%p: %c%c nvcsw: %lu/%lu holdout: %d idle_cpu: %d/%d\n",
549 t, ".I"[is_idle_task(t)],
550 "N."[cpu < 0 || !tick_nohz_full_cpu(cpu)],
551 t->rcu_tasks_nvcsw, t->nvcsw, t->rcu_tasks_holdout,
552 t->rcu_tasks_idle_cpu, cpu);
553 sched_show_task(t);
554}
555
Paul E. McKenneye4fe5dd2020-03-04 17:31:43 -0800556/* Scan the holdout lists for tasks no longer holding out. */
557static void check_all_holdout_tasks(struct list_head *hop,
558 bool needreport, bool *firstreport)
Paul E. McKenneyeacd6f02020-03-02 11:59:20 -0800559{
Paul E. McKenneye4fe5dd2020-03-04 17:31:43 -0800560 struct task_struct *t, *t1;
Paul E. McKenneyeacd6f02020-03-02 11:59:20 -0800561
Paul E. McKenneye4fe5dd2020-03-04 17:31:43 -0800562 list_for_each_entry_safe(t, t1, hop, rcu_tasks_holdout_list) {
563 check_holdout_task(t, needreport, firstreport);
564 cond_resched();
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800565 }
Paul E. McKenneye4fe5dd2020-03-04 17:31:43 -0800566}
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800567
Paul E. McKenneye4fe5dd2020-03-04 17:31:43 -0800568/* Finish off the Tasks-RCU grace period. */
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -0700569static void rcu_tasks_postgp(struct rcu_tasks *rtp)
Paul E. McKenneye4fe5dd2020-03-04 17:31:43 -0800570{
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800571 /*
572 * Because ->on_rq and ->nvcsw are not guaranteed to have a full
573 * memory barriers prior to them in the schedule() path, memory
574 * reordering on other CPUs could cause their RCU-tasks read-side
575 * critical sections to extend past the end of the grace period.
576 * However, because these ->nvcsw updates are carried out with
577 * interrupts disabled, we can use synchronize_rcu() to force the
578 * needed ordering on all such CPUs.
579 *
580 * This synchronize_rcu() also confines all ->rcu_tasks_holdout
581 * accesses to be within the grace period, avoiding the need for
582 * memory barriers for ->rcu_tasks_holdout accesses.
583 *
584 * In addition, this synchronize_rcu() waits for exiting tasks
585 * to complete their final preempt_disable() region of execution,
586 * cleaning up after the synchronize_srcu() above.
587 */
588 synchronize_rcu();
Paul E. McKenneyeacd6f02020-03-02 11:59:20 -0800589}
590
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800591void call_rcu_tasks(struct rcu_head *rhp, rcu_callback_t func);
Paul E. McKenneyc97d12a2020-03-03 15:50:31 -0800592DEFINE_RCU_TASKS(rcu_tasks, rcu_tasks_wait_gp, call_rcu_tasks, "RCU Tasks");
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800593
594/**
595 * call_rcu_tasks() - Queue an RCU for invocation task-based grace period
596 * @rhp: structure to be used for queueing the RCU updates.
597 * @func: actual callback function to be invoked after the grace period
598 *
599 * The callback function will be invoked some time after a full grace
600 * period elapses, in other words after all currently executing RCU
601 * read-side critical sections have completed. call_rcu_tasks() assumes
602 * that the read-side critical sections end at a voluntary context
Paul E. McKenney8af9e2c2021-09-15 09:24:18 -0700603 * switch (not a preemption!), cond_resched_tasks_rcu_qs(), entry into idle,
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800604 * or transition to usermode execution. As such, there are no read-side
605 * primitives analogous to rcu_read_lock() and rcu_read_unlock() because
606 * this primitive is intended to determine that all tasks have passed
Ingo Molnara616aec2021-03-22 22:29:10 -0700607 * through a safe state, not so much for data-structure synchronization.
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800608 *
609 * See the description of call_rcu() for more detailed information on
610 * memory ordering guarantees.
611 */
612void call_rcu_tasks(struct rcu_head *rhp, rcu_callback_t func)
613{
614 call_rcu_tasks_generic(rhp, func, &rcu_tasks);
615}
616EXPORT_SYMBOL_GPL(call_rcu_tasks);
617
618/**
619 * synchronize_rcu_tasks - wait until an rcu-tasks grace period has elapsed.
620 *
621 * Control will return to the caller some time after a full rcu-tasks
622 * grace period has elapsed, in other words after all currently
623 * executing rcu-tasks read-side critical sections have elapsed. These
624 * read-side critical sections are delimited by calls to schedule(),
625 * cond_resched_tasks_rcu_qs(), idle execution, userspace execution, calls
626 * to synchronize_rcu_tasks(), and (in theory, anyway) cond_resched().
627 *
628 * This is a very specialized primitive, intended only for a few uses in
629 * tracing and other situations requiring manipulation of function
630 * preambles and profiling hooks. The synchronize_rcu_tasks() function
631 * is not (yet) intended for heavy use from multiple CPUs.
632 *
633 * See the description of synchronize_rcu() for more detailed information
634 * on memory ordering guarantees.
635 */
636void synchronize_rcu_tasks(void)
637{
638 synchronize_rcu_tasks_generic(&rcu_tasks);
639}
640EXPORT_SYMBOL_GPL(synchronize_rcu_tasks);
641
642/**
643 * rcu_barrier_tasks - Wait for in-flight call_rcu_tasks() callbacks.
644 *
645 * Although the current implementation is guaranteed to wait, it is not
646 * obligated to, for example, if there are no pending callbacks.
647 */
648void rcu_barrier_tasks(void)
649{
650 /* There is only one callback queue, so this is easy. ;-) */
651 synchronize_rcu_tasks();
652}
653EXPORT_SYMBOL_GPL(rcu_barrier_tasks);
654
Paul E. McKenneyeacd6f02020-03-02 11:59:20 -0800655static int __init rcu_spawn_tasks_kthread(void)
656{
Paul E. McKenneycafafd62021-11-05 21:52:00 -0700657 cblist_init_generic(&rcu_tasks);
Paul E. McKenney4fe192d2020-09-09 22:05:41 -0700658 rcu_tasks.gp_sleep = HZ / 10;
Paul E. McKenney75dc2da2020-09-17 16:17:17 -0700659 rcu_tasks.init_fract = HZ / 10;
Paul E. McKenneye4fe5dd2020-03-04 17:31:43 -0800660 rcu_tasks.pregp_func = rcu_tasks_pregp_step;
661 rcu_tasks.pertask_func = rcu_tasks_pertask;
662 rcu_tasks.postscan_func = rcu_tasks_postscan;
663 rcu_tasks.holdouts_func = check_all_holdout_tasks;
664 rcu_tasks.postgp_func = rcu_tasks_postgp;
Paul E. McKenney5873b8a2020-03-03 11:49:21 -0800665 rcu_spawn_tasks_kthread_generic(&rcu_tasks);
Paul E. McKenneyeacd6f02020-03-02 11:59:20 -0800666 return 0;
667}
Paul E. McKenneyeacd6f02020-03-02 11:59:20 -0800668
Paul E. McKenney27c0f142020-09-15 17:08:03 -0700669#if !defined(CONFIG_TINY_RCU)
670void show_rcu_tasks_classic_gp_kthread(void)
Paul E. McKenneye21408c2020-03-16 11:01:55 -0700671{
672 show_rcu_tasks_generic_gp_kthread(&rcu_tasks, "");
673}
Paul E. McKenney27c0f142020-09-15 17:08:03 -0700674EXPORT_SYMBOL_GPL(show_rcu_tasks_classic_gp_kthread);
675#endif // !defined(CONFIG_TINY_RCU)
Paul E. McKenneye21408c2020-03-16 11:01:55 -0700676
Paul E. McKenney25246fc2020-04-05 20:49:13 -0700677/* Do the srcu_read_lock() for the above synchronize_srcu(). */
678void exit_tasks_rcu_start(void) __acquires(&tasks_rcu_exit_srcu)
679{
680 preempt_disable();
681 current->rcu_tasks_idx = __srcu_read_lock(&tasks_rcu_exit_srcu);
682 preempt_enable();
683}
684
685/* Do the srcu_read_unlock() for the above synchronize_srcu(). */
686void exit_tasks_rcu_finish(void) __releases(&tasks_rcu_exit_srcu)
687{
688 struct task_struct *t = current;
689
690 preempt_disable();
691 __srcu_read_unlock(&tasks_rcu_exit_srcu, t->rcu_tasks_idx);
692 preempt_enable();
693 exit_tasks_rcu_finish_trace(t);
694}
695
Paul E. McKenneye21408c2020-03-16 11:01:55 -0700696#else /* #ifdef CONFIG_TASKS_RCU */
Paul E. McKenney25246fc2020-04-05 20:49:13 -0700697void exit_tasks_rcu_start(void) { }
698void exit_tasks_rcu_finish(void) { exit_tasks_rcu_finish_trace(current); }
Paul E. McKenneye21408c2020-03-16 11:01:55 -0700699#endif /* #else #ifdef CONFIG_TASKS_RCU */
Paul E. McKenneyc84aad72020-03-02 21:06:43 -0800700
701#ifdef CONFIG_TASKS_RUDE_RCU
702
703////////////////////////////////////////////////////////////////////////
704//
705// "Rude" variant of Tasks RCU, inspired by Steve Rostedt's trick of
706// passing an empty function to schedule_on_each_cpu(). This approach
Paul E. McKenneye4be1f42021-06-22 11:57:15 -0700707// provides an asynchronous call_rcu_tasks_rude() API and batching of
708// concurrent calls to the synchronous synchronize_rcu_tasks_rude() API.
Paul E. McKenney9fc98e32021-03-04 14:46:59 -0800709// This invokes schedule_on_each_cpu() in order to send IPIs far and wide
710// and induces otherwise unnecessary context switches on all online CPUs,
711// whether idle or not.
712//
713// Callback handling is provided by the rcu_tasks_kthread() function.
714//
715// Ordering is provided by the scheduler's context-switch code.
Paul E. McKenneyc84aad72020-03-02 21:06:43 -0800716
717// Empty function to allow workqueues to force a context switch.
718static void rcu_tasks_be_rude(struct work_struct *work)
719{
720}
721
722// Wait for one rude RCU-tasks grace period.
723static void rcu_tasks_rude_wait_gp(struct rcu_tasks *rtp)
724{
Paul E. McKenney238dbce2020-03-18 10:54:05 -0700725 rtp->n_ipis += cpumask_weight(cpu_online_mask);
Paul E. McKenneyc84aad72020-03-02 21:06:43 -0800726 schedule_on_each_cpu(rcu_tasks_be_rude);
727}
728
729void call_rcu_tasks_rude(struct rcu_head *rhp, rcu_callback_t func);
Paul E. McKenneyc97d12a2020-03-03 15:50:31 -0800730DEFINE_RCU_TASKS(rcu_tasks_rude, rcu_tasks_rude_wait_gp, call_rcu_tasks_rude,
731 "RCU Tasks Rude");
Paul E. McKenneyc84aad72020-03-02 21:06:43 -0800732
733/**
734 * call_rcu_tasks_rude() - Queue a callback rude task-based grace period
735 * @rhp: structure to be used for queueing the RCU updates.
736 * @func: actual callback function to be invoked after the grace period
737 *
738 * The callback function will be invoked some time after a full grace
739 * period elapses, in other words after all currently executing RCU
740 * read-side critical sections have completed. call_rcu_tasks_rude()
741 * assumes that the read-side critical sections end at context switch,
Paul E. McKenney8af9e2c2021-09-15 09:24:18 -0700742 * cond_resched_tasks_rcu_qs(), or transition to usermode execution (as
Neeraj Upadhyaya6517e92021-08-18 12:58:43 +0530743 * usermode execution is schedulable). As such, there are no read-side
744 * primitives analogous to rcu_read_lock() and rcu_read_unlock() because
745 * this primitive is intended to determine that all tasks have passed
746 * through a safe state, not so much for data-structure synchronization.
Paul E. McKenneyc84aad72020-03-02 21:06:43 -0800747 *
748 * See the description of call_rcu() for more detailed information on
749 * memory ordering guarantees.
750 */
751void call_rcu_tasks_rude(struct rcu_head *rhp, rcu_callback_t func)
752{
753 call_rcu_tasks_generic(rhp, func, &rcu_tasks_rude);
754}
755EXPORT_SYMBOL_GPL(call_rcu_tasks_rude);
756
757/**
758 * synchronize_rcu_tasks_rude - wait for a rude rcu-tasks grace period
759 *
760 * Control will return to the caller some time after a rude rcu-tasks
761 * grace period has elapsed, in other words after all currently
762 * executing rcu-tasks read-side critical sections have elapsed. These
763 * read-side critical sections are delimited by calls to schedule(),
Neeraj Upadhyaya6517e92021-08-18 12:58:43 +0530764 * cond_resched_tasks_rcu_qs(), userspace execution (which is a schedulable
765 * context), and (in theory, anyway) cond_resched().
Paul E. McKenneyc84aad72020-03-02 21:06:43 -0800766 *
767 * This is a very specialized primitive, intended only for a few uses in
768 * tracing and other situations requiring manipulation of function preambles
769 * and profiling hooks. The synchronize_rcu_tasks_rude() function is not
770 * (yet) intended for heavy use from multiple CPUs.
771 *
772 * See the description of synchronize_rcu() for more detailed information
773 * on memory ordering guarantees.
774 */
775void synchronize_rcu_tasks_rude(void)
776{
777 synchronize_rcu_tasks_generic(&rcu_tasks_rude);
778}
779EXPORT_SYMBOL_GPL(synchronize_rcu_tasks_rude);
780
781/**
782 * rcu_barrier_tasks_rude - Wait for in-flight call_rcu_tasks_rude() callbacks.
783 *
784 * Although the current implementation is guaranteed to wait, it is not
785 * obligated to, for example, if there are no pending callbacks.
786 */
787void rcu_barrier_tasks_rude(void)
788{
789 /* There is only one callback queue, so this is easy. ;-) */
790 synchronize_rcu_tasks_rude();
791}
792EXPORT_SYMBOL_GPL(rcu_barrier_tasks_rude);
793
794static int __init rcu_spawn_tasks_rude_kthread(void)
795{
Paul E. McKenneycafafd62021-11-05 21:52:00 -0700796 cblist_init_generic(&rcu_tasks_rude);
Paul E. McKenney4fe192d2020-09-09 22:05:41 -0700797 rcu_tasks_rude.gp_sleep = HZ / 10;
Paul E. McKenneyc84aad72020-03-02 21:06:43 -0800798 rcu_spawn_tasks_kthread_generic(&rcu_tasks_rude);
799 return 0;
800}
Paul E. McKenneyc84aad72020-03-02 21:06:43 -0800801
Paul E. McKenney27c0f142020-09-15 17:08:03 -0700802#if !defined(CONFIG_TINY_RCU)
803void show_rcu_tasks_rude_gp_kthread(void)
Paul E. McKenneye21408c2020-03-16 11:01:55 -0700804{
805 show_rcu_tasks_generic_gp_kthread(&rcu_tasks_rude, "");
806}
Paul E. McKenney27c0f142020-09-15 17:08:03 -0700807EXPORT_SYMBOL_GPL(show_rcu_tasks_rude_gp_kthread);
808#endif // !defined(CONFIG_TINY_RCU)
809#endif /* #ifdef CONFIG_TASKS_RUDE_RCU */
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -0700810
811////////////////////////////////////////////////////////////////////////
812//
813// Tracing variant of Tasks RCU. This variant is designed to be used
814// to protect tracing hooks, including those of BPF. This variant
815// therefore:
816//
817// 1. Has explicit read-side markers to allow finite grace periods
818// in the face of in-kernel loops for PREEMPT=n builds.
819//
820// 2. Protects code in the idle loop, exception entry/exit, and
821// CPU-hotplug code paths, similar to the capabilities of SRCU.
822//
Paul E. McKenneyc4f113a2021-08-05 09:54:45 -0700823// 3. Avoids expensive read-side instructions, having overhead similar
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -0700824// to that of Preemptible RCU.
825//
826// There are of course downsides. The grace-period code can send IPIs to
827// CPUs, even when those CPUs are in the idle loop or in nohz_full userspace.
828// It is necessary to scan the full tasklist, much as for Tasks RCU. There
829// is a single callback queue guarded by a single lock, again, much as for
830// Tasks RCU. If needed, these downsides can be at least partially remedied.
831//
832// Perhaps most important, this variant of RCU does not affect the vanilla
833// flavors, rcu_preempt and rcu_sched. The fact that RCU Tasks Trace
834// readers can operate from idle, offline, and exception entry/exit in no
835// way allows rcu_preempt and rcu_sched readers to also do so.
Paul E. McKenneya434dd12021-02-25 10:26:00 -0800836//
837// The implementation uses rcu_tasks_wait_gp(), which relies on function
838// pointers in the rcu_tasks structure. The rcu_spawn_tasks_trace_kthread()
839// function sets these function pointers up so that rcu_tasks_wait_gp()
840// invokes these functions in this order:
841//
842// rcu_tasks_trace_pregp_step():
843// Initialize the count of readers and block CPU-hotplug operations.
844// rcu_tasks_trace_pertask(), invoked on every non-idle task:
845// Initialize per-task state and attempt to identify an immediate
846// quiescent state for that task, or, failing that, attempt to
847// set that task's .need_qs flag so that task's next outermost
848// rcu_read_unlock_trace() will report the quiescent state (in which
849// case the count of readers is incremented). If both attempts fail,
Paul E. McKenney45f4b4a2021-05-24 11:26:53 -0700850// the task is added to a "holdout" list. Note that IPIs are used
851// to invoke trc_read_check_handler() in the context of running tasks
852// in order to avoid ordering overhead on common-case shared-variable
853// accessses.
Paul E. McKenneya434dd12021-02-25 10:26:00 -0800854// rcu_tasks_trace_postscan():
855// Initialize state and attempt to identify an immediate quiescent
856// state as above (but only for idle tasks), unblock CPU-hotplug
857// operations, and wait for an RCU grace period to avoid races with
858// tasks that are in the process of exiting.
859// check_all_holdout_tasks_trace(), repeatedly until holdout list is empty:
860// Scans the holdout list, attempting to identify a quiescent state
861// for each task on the list. If there is a quiescent state, the
862// corresponding task is removed from the holdout list.
863// rcu_tasks_trace_postgp():
864// Wait for the count of readers do drop to zero, reporting any stalls.
865// Also execute full memory barriers to maintain ordering with code
866// executing after the grace period.
867//
868// The exit_tasks_rcu_finish_trace() synchronizes with exiting tasks.
869//
870// Pre-grace-period update-side code is ordered before the grace
871// period via the ->cbs_lock and barriers in rcu_tasks_kthread().
872// Pre-grace-period read-side code is ordered before the grace period by
873// atomic_dec_and_test() of the count of readers (for IPIed readers) and by
874// scheduler context-switch ordering (for locked-down non-running readers).
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -0700875
876// The lockdep state must be outside of #ifdef to be useful.
877#ifdef CONFIG_DEBUG_LOCK_ALLOC
878static struct lock_class_key rcu_lock_trace_key;
879struct lockdep_map rcu_trace_lock_map =
880 STATIC_LOCKDEP_MAP_INIT("rcu_read_lock_trace", &rcu_lock_trace_key);
881EXPORT_SYMBOL_GPL(rcu_trace_lock_map);
882#endif /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
883
884#ifdef CONFIG_TASKS_TRACE_RCU
885
Paul E. McKenney30d8aa52020-06-09 09:24:51 -0700886static atomic_t trc_n_readers_need_end; // Number of waited-for readers.
887static DECLARE_WAIT_QUEUE_HEAD(trc_wait); // List of holdout tasks.
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -0700888
889// Record outstanding IPIs to each CPU. No point in sending two...
890static DEFINE_PER_CPU(bool, trc_ipi_to_cpu);
891
Paul E. McKenney40471502020-03-22 13:34:34 -0700892// The number of detections of task quiescent state relying on
893// heavyweight readers executing explicit memory barriers.
Paul E. McKenney6731da92020-09-09 14:14:34 -0700894static unsigned long n_heavy_reader_attempts;
895static unsigned long n_heavy_reader_updates;
896static unsigned long n_heavy_reader_ofl_updates;
Paul E. McKenney40471502020-03-22 13:34:34 -0700897
Paul E. McKenneyb0afa0f2020-03-17 11:39:26 -0700898void call_rcu_tasks_trace(struct rcu_head *rhp, rcu_callback_t func);
899DEFINE_RCU_TASKS(rcu_tasks_trace, rcu_tasks_wait_gp, call_rcu_tasks_trace,
900 "RCU Tasks Trace");
901
Paul E. McKenneyb38f57c2020-03-20 14:29:08 -0700902/*
903 * This irq_work handler allows rcu_read_unlock_trace() to be invoked
904 * while the scheduler locks are held.
905 */
906static void rcu_read_unlock_iw(struct irq_work *iwp)
907{
908 wake_up(&trc_wait);
909}
910static DEFINE_IRQ_WORK(rcu_tasks_trace_iw, rcu_read_unlock_iw);
911
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -0700912/* If we are the last reader, wake up the grace-period kthread. */
Paul E. McKenneya5c071c2021-07-28 12:28:27 -0700913void rcu_read_unlock_trace_special(struct task_struct *t)
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -0700914{
Paul E. McKenneyf8ab3fa2021-05-24 15:36:37 -0700915 int nq = READ_ONCE(t->trc_reader_special.b.need_qs);
Paul E. McKenney276c4102020-03-17 16:02:06 -0700916
Paul E. McKenney9ae58d72020-03-18 17:16:37 -0700917 if (IS_ENABLED(CONFIG_TASKS_TRACE_RCU_READ_MB) &&
918 t->trc_reader_special.b.need_mb)
Paul E. McKenney276c4102020-03-17 16:02:06 -0700919 smp_mb(); // Pairs with update-side barriers.
920 // Update .need_qs before ->trc_reader_nesting for irq/NMI handlers.
921 if (nq)
922 WRITE_ONCE(t->trc_reader_special.b.need_qs, false);
Paul E. McKenneya5c071c2021-07-28 12:28:27 -0700923 WRITE_ONCE(t->trc_reader_nesting, 0);
Paul E. McKenney276c4102020-03-17 16:02:06 -0700924 if (nq && atomic_dec_and_test(&trc_n_readers_need_end))
Paul E. McKenneyb38f57c2020-03-20 14:29:08 -0700925 irq_work_queue(&rcu_tasks_trace_iw);
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -0700926}
927EXPORT_SYMBOL_GPL(rcu_read_unlock_trace_special);
928
929/* Add a task to the holdout list, if it is not already on the list. */
930static void trc_add_holdout(struct task_struct *t, struct list_head *bhp)
931{
932 if (list_empty(&t->trc_holdout_list)) {
933 get_task_struct(t);
934 list_add(&t->trc_holdout_list, bhp);
935 }
936}
937
938/* Remove a task from the holdout list, if it is in fact present. */
939static void trc_del_holdout(struct task_struct *t)
940{
941 if (!list_empty(&t->trc_holdout_list)) {
942 list_del_init(&t->trc_holdout_list);
943 put_task_struct(t);
944 }
945}
946
947/* IPI handler to check task state. */
948static void trc_read_check_handler(void *t_in)
949{
950 struct task_struct *t = current;
951 struct task_struct *texp = t_in;
952
953 // If the task is no longer running on this CPU, leave.
954 if (unlikely(texp != t)) {
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -0700955 goto reset_ipi; // Already on holdout list, so will check later.
956 }
957
958 // If the task is not in a read-side critical section, and
959 // if this is the last reader, awaken the grace-period kthread.
Paul E. McKenneybdb0cca2021-05-24 12:48:18 -0700960 if (likely(!READ_ONCE(t->trc_reader_nesting))) {
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -0700961 WRITE_ONCE(t->trc_reader_checked, true);
962 goto reset_ipi;
963 }
Paul E. McKenneyba3a86e2020-09-14 15:44:37 -0700964 // If we are racing with an rcu_read_unlock_trace(), try again later.
Paul E. McKenney96017bf2021-07-28 10:53:41 -0700965 if (unlikely(READ_ONCE(t->trc_reader_nesting) < 0))
Paul E. McKenneyba3a86e2020-09-14 15:44:37 -0700966 goto reset_ipi;
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -0700967 WRITE_ONCE(t->trc_reader_checked, true);
968
969 // Get here if the task is in a read-side critical section. Set
970 // its state so that it will awaken the grace-period kthread upon
971 // exit from that critical section.
Paul E. McKenney96017bf2021-07-28 10:53:41 -0700972 atomic_inc(&trc_n_readers_need_end); // One more to wait on.
Paul E. McKenneyf8ab3fa2021-05-24 15:36:37 -0700973 WARN_ON_ONCE(READ_ONCE(t->trc_reader_special.b.need_qs));
Paul E. McKenney276c4102020-03-17 16:02:06 -0700974 WRITE_ONCE(t->trc_reader_special.b.need_qs, true);
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -0700975
976reset_ipi:
977 // Allow future IPIs to be sent on CPU and for task.
978 // Also order this IPI handler against any later manipulations of
979 // the intended task.
Liu Song8211e922021-06-30 22:08:02 +0800980 smp_store_release(per_cpu_ptr(&trc_ipi_to_cpu, smp_processor_id()), false); // ^^^
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -0700981 smp_store_release(&texp->trc_ipi_to_cpu, -1); // ^^^
982}
983
984/* Callback function for scheduler to check locked-down task. */
Peter Zijlstra9b3c4ab2021-09-21 21:54:32 +0200985static int trc_inspect_reader(struct task_struct *t, void *arg)
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -0700986{
Paul E. McKenney7d0c9c52020-03-19 15:33:12 -0700987 int cpu = task_cpu(t);
Paul E. McKenney18f08e72021-07-28 11:32:28 -0700988 int nesting;
Paul E. McKenney7e3b70e2020-03-22 11:24:58 -0700989 bool ofl = cpu_is_offline(cpu);
Paul E. McKenney7d0c9c52020-03-19 15:33:12 -0700990
991 if (task_curr(t)) {
Paul E. McKenney30d8aa52020-06-09 09:24:51 -0700992 WARN_ON_ONCE(ofl && !is_idle_task(t));
Paul E. McKenney7e3b70e2020-03-22 11:24:58 -0700993
Paul E. McKenney7d0c9c52020-03-19 15:33:12 -0700994 // If no chance of heavyweight readers, do it the hard way.
Paul E. McKenney7e3b70e2020-03-22 11:24:58 -0700995 if (!ofl && !IS_ENABLED(CONFIG_TASKS_TRACE_RCU_READ_MB))
Peter Zijlstra9b3c4ab2021-09-21 21:54:32 +0200996 return -EINVAL;
Paul E. McKenney7d0c9c52020-03-19 15:33:12 -0700997
998 // If heavyweight readers are enabled on the remote task,
999 // we can inspect its state despite its currently running.
1000 // However, we cannot safely change its state.
Paul E. McKenney40471502020-03-22 13:34:34 -07001001 n_heavy_reader_attempts++;
Paul E. McKenney7e3b70e2020-03-22 11:24:58 -07001002 if (!ofl && // Check for "running" idle tasks on offline CPUs.
1003 !rcu_dynticks_zero_in_eqs(cpu, &t->trc_reader_nesting))
Peter Zijlstra9b3c4ab2021-09-21 21:54:32 +02001004 return -EINVAL; // No quiescent state, do it the hard way.
Paul E. McKenney40471502020-03-22 13:34:34 -07001005 n_heavy_reader_updates++;
Paul E. McKenneyedf37752020-03-22 14:09:45 -07001006 if (ofl)
1007 n_heavy_reader_ofl_updates++;
Paul E. McKenney18f08e72021-07-28 11:32:28 -07001008 nesting = 0;
Paul E. McKenney7d0c9c52020-03-19 15:33:12 -07001009 } else {
Paul E. McKenneybdb0cca2021-05-24 12:48:18 -07001010 // The task is not running, so C-language access is safe.
Paul E. McKenney18f08e72021-07-28 11:32:28 -07001011 nesting = t->trc_reader_nesting;
Paul E. McKenney7d0c9c52020-03-19 15:33:12 -07001012 }
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001013
Paul E. McKenney18f08e72021-07-28 11:32:28 -07001014 // If not exiting a read-side critical section, mark as checked
1015 // so that the grace-period kthread will remove it from the
1016 // holdout list.
1017 t->trc_reader_checked = nesting >= 0;
1018 if (nesting <= 0)
Linus Torvalds6fedc282021-11-01 20:25:38 -07001019 return nesting ? -EINVAL : 0; // If in QS, done, otherwise try again later.
Paul E. McKenney7d0c9c52020-03-19 15:33:12 -07001020
1021 // The task is in a read-side critical section, so set up its
1022 // state so that it will awaken the grace-period kthread upon exit
1023 // from that critical section.
1024 atomic_inc(&trc_n_readers_need_end); // One more to wait on.
Paul E. McKenneyf8ab3fa2021-05-24 15:36:37 -07001025 WARN_ON_ONCE(READ_ONCE(t->trc_reader_special.b.need_qs));
Paul E. McKenney7d0c9c52020-03-19 15:33:12 -07001026 WRITE_ONCE(t->trc_reader_special.b.need_qs, true);
Peter Zijlstra9b3c4ab2021-09-21 21:54:32 +02001027 return 0;
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001028}
1029
1030/* Attempt to extract the state for the specified task. */
1031static void trc_wait_for_one_reader(struct task_struct *t,
1032 struct list_head *bhp)
1033{
1034 int cpu;
1035
1036 // If a previous IPI is still in flight, let it complete.
1037 if (smp_load_acquire(&t->trc_ipi_to_cpu) != -1) // Order IPI
1038 return;
1039
1040 // The current task had better be in a quiescent state.
1041 if (t == current) {
1042 t->trc_reader_checked = true;
Paul E. McKenneybdb0cca2021-05-24 12:48:18 -07001043 WARN_ON_ONCE(READ_ONCE(t->trc_reader_nesting));
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001044 return;
1045 }
1046
1047 // Attempt to nail down the task for inspection.
1048 get_task_struct(t);
Peter Zijlstra9b3c4ab2021-09-21 21:54:32 +02001049 if (!task_call_func(t, trc_inspect_reader, NULL)) {
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001050 put_task_struct(t);
1051 return;
1052 }
1053 put_task_struct(t);
1054
Paul E. McKenney45f4b4a2021-05-24 11:26:53 -07001055 // If this task is not yet on the holdout list, then we are in
1056 // an RCU read-side critical section. Otherwise, the invocation of
Neeraj Upadhyayd0a85852021-08-18 12:58:39 +05301057 // trc_add_holdout() that added it to the list did the necessary
Paul E. McKenney45f4b4a2021-05-24 11:26:53 -07001058 // get_task_struct(). Either way, the task cannot be freed out
1059 // from under this code.
1060
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001061 // If currently running, send an IPI, either way, add to list.
1062 trc_add_holdout(t, bhp);
Paul E. McKenney574de872020-09-09 21:51:09 -07001063 if (task_curr(t) &&
1064 time_after(jiffies + 1, rcu_tasks_trace.gp_start + rcu_task_ipi_delay)) {
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001065 // The task is currently running, so try IPIing it.
1066 cpu = task_cpu(t);
1067
1068 // If there is already an IPI outstanding, let it happen.
1069 if (per_cpu(trc_ipi_to_cpu, cpu) || t->trc_ipi_to_cpu >= 0)
1070 return;
1071
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001072 per_cpu(trc_ipi_to_cpu, cpu) = true;
1073 t->trc_ipi_to_cpu = cpu;
Paul E. McKenney238dbce2020-03-18 10:54:05 -07001074 rcu_tasks_trace.n_ipis++;
Paul E. McKenney96017bf2021-07-28 10:53:41 -07001075 if (smp_call_function_single(cpu, trc_read_check_handler, t, 0)) {
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001076 // Just in case there is some other reason for
1077 // failure than the target CPU being offline.
Neeraj Upadhyay46aa8862021-08-27 13:43:35 +05301078 WARN_ONCE(1, "%s(): smp_call_function_single() failed for CPU: %d\n",
1079 __func__, cpu);
Paul E. McKenney7e0669c2020-03-25 14:36:05 -07001080 rcu_tasks_trace.n_ipis_fails++;
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001081 per_cpu(trc_ipi_to_cpu, cpu) = false;
Neeraj Upadhyay46aa8862021-08-27 13:43:35 +05301082 t->trc_ipi_to_cpu = -1;
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001083 }
1084 }
1085}
1086
1087/* Initialize for a new RCU-tasks-trace grace period. */
1088static void rcu_tasks_trace_pregp_step(void)
1089{
1090 int cpu;
1091
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001092 // Allow for fast-acting IPIs.
1093 atomic_set(&trc_n_readers_need_end, 1);
1094
1095 // There shouldn't be any old IPIs, but...
1096 for_each_possible_cpu(cpu)
1097 WARN_ON_ONCE(per_cpu(trc_ipi_to_cpu, cpu));
Paul E. McKenney81b4a7b2020-03-22 10:10:07 -07001098
1099 // Disable CPU hotplug across the tasklist scan.
1100 // This also waits for all readers in CPU-hotplug code paths.
1101 cpus_read_lock();
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001102}
1103
1104/* Do first-round processing for the specified task. */
1105static void rcu_tasks_trace_pertask(struct task_struct *t,
1106 struct list_head *hop)
1107{
Uladzislau Rezki (Sony)1b04fa92020-12-09 21:27:31 +01001108 // During early boot when there is only the one boot CPU, there
1109 // is no idle task for the other CPUs. Just return.
1110 if (unlikely(t == NULL))
1111 return;
1112
Paul E. McKenney276c4102020-03-17 16:02:06 -07001113 WRITE_ONCE(t->trc_reader_special.b.need_qs, false);
Paul E. McKenney43766c32020-03-16 20:38:29 -07001114 WRITE_ONCE(t->trc_reader_checked, false);
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001115 t->trc_ipi_to_cpu = -1;
1116 trc_wait_for_one_reader(t, hop);
1117}
1118
Paul E. McKenney9796e1a2020-03-22 13:18:54 -07001119/*
1120 * Do intermediate processing between task and holdout scans and
1121 * pick up the idle tasks.
1122 */
1123static void rcu_tasks_trace_postscan(struct list_head *hop)
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001124{
Paul E. McKenney9796e1a2020-03-22 13:18:54 -07001125 int cpu;
1126
1127 for_each_possible_cpu(cpu)
1128 rcu_tasks_trace_pertask(idle_task(cpu), hop);
1129
Paul E. McKenney81b4a7b2020-03-22 10:10:07 -07001130 // Re-enable CPU hotplug now that the tasklist scan has completed.
1131 cpus_read_unlock();
1132
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001133 // Wait for late-stage exiting tasks to finish exiting.
1134 // These might have passed the call to exit_tasks_rcu_finish().
1135 synchronize_rcu();
1136 // Any tasks that exit after this point will set ->trc_reader_checked.
1137}
1138
Neeraj Upadhyay65b629e2021-11-09 16:52:14 +05301139/* Communicate task state back to the RCU tasks trace stall warning request. */
1140struct trc_stall_chk_rdr {
1141 int nesting;
1142 int ipi_to_cpu;
1143 u8 needqs;
1144};
1145
1146static int trc_check_slow_task(struct task_struct *t, void *arg)
1147{
1148 struct trc_stall_chk_rdr *trc_rdrp = arg;
1149
1150 if (task_curr(t))
1151 return false; // It is running, so decline to inspect it.
1152 trc_rdrp->nesting = READ_ONCE(t->trc_reader_nesting);
1153 trc_rdrp->ipi_to_cpu = READ_ONCE(t->trc_ipi_to_cpu);
1154 trc_rdrp->needqs = READ_ONCE(t->trc_reader_special.b.need_qs);
1155 return true;
1156}
1157
Paul E. McKenney4593e772020-03-10 12:13:53 -07001158/* Show the state of a task stalling the current RCU tasks trace GP. */
1159static void show_stalled_task_trace(struct task_struct *t, bool *firstreport)
1160{
1161 int cpu;
Neeraj Upadhyay65b629e2021-11-09 16:52:14 +05301162 struct trc_stall_chk_rdr trc_rdr;
1163 bool is_idle_tsk = is_idle_task(t);
Paul E. McKenney4593e772020-03-10 12:13:53 -07001164
1165 if (*firstreport) {
1166 pr_err("INFO: rcu_tasks_trace detected stalls on tasks:\n");
1167 *firstreport = false;
1168 }
Paul E. McKenney4593e772020-03-10 12:13:53 -07001169 cpu = task_cpu(t);
Neeraj Upadhyay65b629e2021-11-09 16:52:14 +05301170 if (!task_call_func(t, trc_check_slow_task, &trc_rdr))
1171 pr_alert("P%d: %c\n",
1172 t->pid,
1173 ".i"[is_idle_tsk]);
1174 else
1175 pr_alert("P%d: %c%c%c nesting: %d%c cpu: %d\n",
1176 t->pid,
1177 ".I"[trc_rdr.ipi_to_cpu >= 0],
1178 ".i"[is_idle_tsk],
1179 ".N"[cpu >= 0 && tick_nohz_full_cpu(cpu)],
1180 trc_rdr.nesting,
1181 " N"[!!trc_rdr.needqs],
1182 cpu);
Paul E. McKenney4593e772020-03-10 12:13:53 -07001183 sched_show_task(t);
1184}
1185
1186/* List stalled IPIs for RCU tasks trace. */
1187static void show_stalled_ipi_trace(void)
1188{
1189 int cpu;
1190
1191 for_each_possible_cpu(cpu)
1192 if (per_cpu(trc_ipi_to_cpu, cpu))
1193 pr_alert("\tIPI outstanding to CPU %d\n", cpu);
1194}
1195
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001196/* Do one scan of the holdout list. */
1197static void check_all_holdout_tasks_trace(struct list_head *hop,
Paul E. McKenney4593e772020-03-10 12:13:53 -07001198 bool needreport, bool *firstreport)
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001199{
1200 struct task_struct *g, *t;
1201
Paul E. McKenney81b4a7b2020-03-22 10:10:07 -07001202 // Disable CPU hotplug across the holdout list scan.
1203 cpus_read_lock();
1204
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001205 list_for_each_entry_safe(t, g, hop, trc_holdout_list) {
1206 // If safe and needed, try to check the current task.
1207 if (READ_ONCE(t->trc_ipi_to_cpu) == -1 &&
1208 !READ_ONCE(t->trc_reader_checked))
1209 trc_wait_for_one_reader(t, hop);
1210
1211 // If check succeeded, remove this task from the list.
Paul E. McKenneyf5dbc592021-09-18 20:40:48 -07001212 if (smp_load_acquire(&t->trc_ipi_to_cpu) == -1 &&
1213 READ_ONCE(t->trc_reader_checked))
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001214 trc_del_holdout(t);
Paul E. McKenney4593e772020-03-10 12:13:53 -07001215 else if (needreport)
1216 show_stalled_task_trace(t, firstreport);
1217 }
Paul E. McKenney81b4a7b2020-03-22 10:10:07 -07001218
1219 // Re-enable CPU hotplug now that the holdout list scan has completed.
1220 cpus_read_unlock();
1221
Paul E. McKenney4593e772020-03-10 12:13:53 -07001222 if (needreport) {
Neeraj Upadhyay89401172021-08-18 12:58:40 +05301223 if (*firstreport)
Paul E. McKenney4593e772020-03-10 12:13:53 -07001224 pr_err("INFO: rcu_tasks_trace detected stalls? (Late IPI?)\n");
1225 show_stalled_ipi_trace();
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001226 }
1227}
1228
Paul E. McKenneycbe0d8d2021-07-30 12:17:59 -07001229static void rcu_tasks_trace_empty_fn(void *unused)
1230{
1231}
1232
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001233/* Wait for grace period to complete and provide ordering. */
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -07001234static void rcu_tasks_trace_postgp(struct rcu_tasks *rtp)
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001235{
Paul E. McKenneycbe0d8d2021-07-30 12:17:59 -07001236 int cpu;
Paul E. McKenney4593e772020-03-10 12:13:53 -07001237 bool firstreport;
1238 struct task_struct *g, *t;
1239 LIST_HEAD(holdouts);
1240 long ret;
1241
Paul E. McKenneycbe0d8d2021-07-30 12:17:59 -07001242 // Wait for any lingering IPI handlers to complete. Note that
1243 // if a CPU has gone offline or transitioned to userspace in the
1244 // meantime, all IPI handlers should have been drained beforehand.
1245 // Yes, this assumes that CPUs process IPIs in order. If that ever
1246 // changes, there will need to be a recheck and/or timed wait.
1247 for_each_online_cpu(cpu)
Paul E. McKenneyf5dbc592021-09-18 20:40:48 -07001248 if (WARN_ON_ONCE(smp_load_acquire(per_cpu_ptr(&trc_ipi_to_cpu, cpu))))
Paul E. McKenneycbe0d8d2021-07-30 12:17:59 -07001249 smp_call_function_single(cpu, rcu_tasks_trace_empty_fn, NULL, 1);
1250
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001251 // Remove the safety count.
1252 smp_mb__before_atomic(); // Order vs. earlier atomics
1253 atomic_dec(&trc_n_readers_need_end);
1254 smp_mb__after_atomic(); // Order vs. later atomics
1255
1256 // Wait for readers.
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -07001257 set_tasks_gp_state(rtp, RTGS_WAIT_READERS);
Paul E. McKenney4593e772020-03-10 12:13:53 -07001258 for (;;) {
1259 ret = wait_event_idle_exclusive_timeout(
1260 trc_wait,
1261 atomic_read(&trc_n_readers_need_end) == 0,
1262 READ_ONCE(rcu_task_stall_timeout));
1263 if (ret)
1264 break; // Count reached zero.
Paul E. McKenneyaf051ca2020-03-16 12:13:33 -07001265 // Stall warning time, so make a list of the offenders.
Paul E. McKenneyf747c7e2020-09-15 14:27:38 -07001266 rcu_read_lock();
Paul E. McKenney4593e772020-03-10 12:13:53 -07001267 for_each_process_thread(g, t)
Paul E. McKenney276c4102020-03-17 16:02:06 -07001268 if (READ_ONCE(t->trc_reader_special.b.need_qs))
Paul E. McKenney4593e772020-03-10 12:13:53 -07001269 trc_add_holdout(t, &holdouts);
Paul E. McKenneyf747c7e2020-09-15 14:27:38 -07001270 rcu_read_unlock();
Paul E. McKenney4593e772020-03-10 12:13:53 -07001271 firstreport = true;
Paul E. McKenney592031c2020-09-15 14:03:34 -07001272 list_for_each_entry_safe(t, g, &holdouts, trc_holdout_list) {
1273 if (READ_ONCE(t->trc_reader_special.b.need_qs))
Paul E. McKenney4593e772020-03-10 12:13:53 -07001274 show_stalled_task_trace(t, &firstreport);
Paul E. McKenney592031c2020-09-15 14:03:34 -07001275 trc_del_holdout(t); // Release task_struct reference.
1276 }
Paul E. McKenney4593e772020-03-10 12:13:53 -07001277 if (firstreport)
1278 pr_err("INFO: rcu_tasks_trace detected stalls? (Counter/taskslist mismatch?)\n");
1279 show_stalled_ipi_trace();
1280 pr_err("\t%d holdouts\n", atomic_read(&trc_n_readers_need_end));
1281 }
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001282 smp_mb(); // Caller's code must be ordered after wakeup.
Paul E. McKenney43766c32020-03-16 20:38:29 -07001283 // Pairs with pretty much every ordering primitive.
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001284}
1285
1286/* Report any needed quiescent state for this exiting task. */
Paul E. McKenney25246fc2020-04-05 20:49:13 -07001287static void exit_tasks_rcu_finish_trace(struct task_struct *t)
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001288{
1289 WRITE_ONCE(t->trc_reader_checked, true);
Paul E. McKenneybdb0cca2021-05-24 12:48:18 -07001290 WARN_ON_ONCE(READ_ONCE(t->trc_reader_nesting));
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001291 WRITE_ONCE(t->trc_reader_nesting, 0);
Paul E. McKenney276c4102020-03-17 16:02:06 -07001292 if (WARN_ON_ONCE(READ_ONCE(t->trc_reader_special.b.need_qs)))
Paul E. McKenneya5c071c2021-07-28 12:28:27 -07001293 rcu_read_unlock_trace_special(t);
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001294}
1295
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001296/**
1297 * call_rcu_tasks_trace() - Queue a callback trace task-based grace period
1298 * @rhp: structure to be used for queueing the RCU updates.
1299 * @func: actual callback function to be invoked after the grace period
1300 *
Neeraj Upadhyayed42c382021-08-25 12:40:50 +05301301 * The callback function will be invoked some time after a trace rcu-tasks
1302 * grace period elapses, in other words after all currently executing
1303 * trace rcu-tasks read-side critical sections have completed. These
1304 * read-side critical sections are delimited by calls to rcu_read_lock_trace()
1305 * and rcu_read_unlock_trace().
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001306 *
1307 * See the description of call_rcu() for more detailed information on
1308 * memory ordering guarantees.
1309 */
1310void call_rcu_tasks_trace(struct rcu_head *rhp, rcu_callback_t func)
1311{
1312 call_rcu_tasks_generic(rhp, func, &rcu_tasks_trace);
1313}
1314EXPORT_SYMBOL_GPL(call_rcu_tasks_trace);
1315
1316/**
1317 * synchronize_rcu_tasks_trace - wait for a trace rcu-tasks grace period
1318 *
1319 * Control will return to the caller some time after a trace rcu-tasks
Paul E. McKenneyc7dcf812020-06-12 13:11:29 -07001320 * grace period has elapsed, in other words after all currently executing
Neeraj Upadhyayed42c382021-08-25 12:40:50 +05301321 * trace rcu-tasks read-side critical sections have elapsed. These read-side
Paul E. McKenneyc7dcf812020-06-12 13:11:29 -07001322 * critical sections are delimited by calls to rcu_read_lock_trace()
1323 * and rcu_read_unlock_trace().
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001324 *
1325 * This is a very specialized primitive, intended only for a few uses in
1326 * tracing and other situations requiring manipulation of function preambles
1327 * and profiling hooks. The synchronize_rcu_tasks_trace() function is not
1328 * (yet) intended for heavy use from multiple CPUs.
1329 *
1330 * See the description of synchronize_rcu() for more detailed information
1331 * on memory ordering guarantees.
1332 */
1333void synchronize_rcu_tasks_trace(void)
1334{
1335 RCU_LOCKDEP_WARN(lock_is_held(&rcu_trace_lock_map), "Illegal synchronize_rcu_tasks_trace() in RCU Tasks Trace read-side critical section");
1336 synchronize_rcu_tasks_generic(&rcu_tasks_trace);
1337}
1338EXPORT_SYMBOL_GPL(synchronize_rcu_tasks_trace);
1339
1340/**
1341 * rcu_barrier_tasks_trace - Wait for in-flight call_rcu_tasks_trace() callbacks.
1342 *
1343 * Although the current implementation is guaranteed to wait, it is not
1344 * obligated to, for example, if there are no pending callbacks.
1345 */
1346void rcu_barrier_tasks_trace(void)
1347{
1348 /* There is only one callback queue, so this is easy. ;-) */
1349 synchronize_rcu_tasks_trace();
1350}
1351EXPORT_SYMBOL_GPL(rcu_barrier_tasks_trace);
1352
1353static int __init rcu_spawn_tasks_trace_kthread(void)
1354{
Paul E. McKenneycafafd62021-11-05 21:52:00 -07001355 cblist_init_generic(&rcu_tasks_trace);
Paul E. McKenney2393a612020-09-09 21:36:34 -07001356 if (IS_ENABLED(CONFIG_TASKS_TRACE_RCU_READ_MB)) {
Paul E. McKenney4fe192d2020-09-09 22:05:41 -07001357 rcu_tasks_trace.gp_sleep = HZ / 10;
Paul E. McKenney75dc2da2020-09-17 16:17:17 -07001358 rcu_tasks_trace.init_fract = HZ / 10;
Paul E. McKenney2393a612020-09-09 21:36:34 -07001359 } else {
Paul E. McKenney4fe192d2020-09-09 22:05:41 -07001360 rcu_tasks_trace.gp_sleep = HZ / 200;
1361 if (rcu_tasks_trace.gp_sleep <= 0)
1362 rcu_tasks_trace.gp_sleep = 1;
Paul E. McKenney75dc2da2020-09-17 16:17:17 -07001363 rcu_tasks_trace.init_fract = HZ / 200;
Paul E. McKenney2393a612020-09-09 21:36:34 -07001364 if (rcu_tasks_trace.init_fract <= 0)
1365 rcu_tasks_trace.init_fract = 1;
1366 }
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001367 rcu_tasks_trace.pregp_func = rcu_tasks_trace_pregp_step;
1368 rcu_tasks_trace.pertask_func = rcu_tasks_trace_pertask;
1369 rcu_tasks_trace.postscan_func = rcu_tasks_trace_postscan;
1370 rcu_tasks_trace.holdouts_func = check_all_holdout_tasks_trace;
1371 rcu_tasks_trace.postgp_func = rcu_tasks_trace_postgp;
1372 rcu_spawn_tasks_kthread_generic(&rcu_tasks_trace);
1373 return 0;
1374}
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001375
Paul E. McKenney27c0f142020-09-15 17:08:03 -07001376#if !defined(CONFIG_TINY_RCU)
1377void show_rcu_tasks_trace_gp_kthread(void)
Paul E. McKenneye21408c2020-03-16 11:01:55 -07001378{
Paul E. McKenney40471502020-03-22 13:34:34 -07001379 char buf[64];
Paul E. McKenneye21408c2020-03-16 11:01:55 -07001380
Paul E. McKenneyedf37752020-03-22 14:09:45 -07001381 sprintf(buf, "N%d h:%lu/%lu/%lu", atomic_read(&trc_n_readers_need_end),
1382 data_race(n_heavy_reader_ofl_updates),
Paul E. McKenney40471502020-03-22 13:34:34 -07001383 data_race(n_heavy_reader_updates),
1384 data_race(n_heavy_reader_attempts));
Paul E. McKenneye21408c2020-03-16 11:01:55 -07001385 show_rcu_tasks_generic_gp_kthread(&rcu_tasks_trace, buf);
1386}
Paul E. McKenney27c0f142020-09-15 17:08:03 -07001387EXPORT_SYMBOL_GPL(show_rcu_tasks_trace_gp_kthread);
1388#endif // !defined(CONFIG_TINY_RCU)
Paul E. McKenneye21408c2020-03-16 11:01:55 -07001389
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001390#else /* #ifdef CONFIG_TASKS_TRACE_RCU */
Paul E. McKenney25246fc2020-04-05 20:49:13 -07001391static void exit_tasks_rcu_finish_trace(struct task_struct *t) { }
Paul E. McKenneyd5f177d2020-03-09 19:56:53 -07001392#endif /* #else #ifdef CONFIG_TASKS_TRACE_RCU */
Paul E. McKenney8fd8ca32020-03-15 14:51:20 -07001393
Paul E. McKenney83444962020-05-28 20:03:48 -07001394#ifndef CONFIG_TINY_RCU
Paul E. McKenneye21408c2020-03-16 11:01:55 -07001395void show_rcu_tasks_gp_kthreads(void)
1396{
1397 show_rcu_tasks_classic_gp_kthread();
1398 show_rcu_tasks_rude_gp_kthread();
1399 show_rcu_tasks_trace_gp_kthread();
1400}
Paul E. McKenney83444962020-05-28 20:03:48 -07001401#endif /* #ifndef CONFIG_TINY_RCU */
Paul E. McKenneye21408c2020-03-16 11:01:55 -07001402
Uladzislau Rezki (Sony)bfba7ed2020-12-09 21:27:32 +01001403#ifdef CONFIG_PROVE_RCU
1404struct rcu_tasks_test_desc {
1405 struct rcu_head rh;
1406 const char *name;
1407 bool notrun;
1408};
1409
1410static struct rcu_tasks_test_desc tests[] = {
1411 {
1412 .name = "call_rcu_tasks()",
1413 /* If not defined, the test is skipped. */
1414 .notrun = !IS_ENABLED(CONFIG_TASKS_RCU),
1415 },
1416 {
1417 .name = "call_rcu_tasks_rude()",
1418 /* If not defined, the test is skipped. */
1419 .notrun = !IS_ENABLED(CONFIG_TASKS_RUDE_RCU),
1420 },
1421 {
1422 .name = "call_rcu_tasks_trace()",
1423 /* If not defined, the test is skipped. */
1424 .notrun = !IS_ENABLED(CONFIG_TASKS_TRACE_RCU)
1425 }
1426};
1427
1428static void test_rcu_tasks_callback(struct rcu_head *rhp)
1429{
1430 struct rcu_tasks_test_desc *rttd =
1431 container_of(rhp, struct rcu_tasks_test_desc, rh);
1432
1433 pr_info("Callback from %s invoked.\n", rttd->name);
1434
1435 rttd->notrun = true;
1436}
1437
1438static void rcu_tasks_initiate_self_tests(void)
1439{
1440 pr_info("Running RCU-tasks wait API self tests\n");
1441#ifdef CONFIG_TASKS_RCU
1442 synchronize_rcu_tasks();
1443 call_rcu_tasks(&tests[0].rh, test_rcu_tasks_callback);
1444#endif
1445
1446#ifdef CONFIG_TASKS_RUDE_RCU
1447 synchronize_rcu_tasks_rude();
1448 call_rcu_tasks_rude(&tests[1].rh, test_rcu_tasks_callback);
1449#endif
1450
1451#ifdef CONFIG_TASKS_TRACE_RCU
1452 synchronize_rcu_tasks_trace();
1453 call_rcu_tasks_trace(&tests[2].rh, test_rcu_tasks_callback);
1454#endif
1455}
1456
1457static int rcu_tasks_verify_self_tests(void)
1458{
1459 int ret = 0;
1460 int i;
1461
1462 for (i = 0; i < ARRAY_SIZE(tests); i++) {
1463 if (!tests[i].notrun) { // still hanging.
1464 pr_err("%s has been failed.\n", tests[i].name);
1465 ret = -1;
1466 }
1467 }
1468
1469 if (ret)
1470 WARN_ON(1);
1471
1472 return ret;
1473}
1474late_initcall(rcu_tasks_verify_self_tests);
1475#else /* #ifdef CONFIG_PROVE_RCU */
1476static void rcu_tasks_initiate_self_tests(void) { }
1477#endif /* #else #ifdef CONFIG_PROVE_RCU */
1478
Uladzislau Rezki (Sony)1b04fa92020-12-09 21:27:31 +01001479void __init rcu_init_tasks_generic(void)
1480{
1481#ifdef CONFIG_TASKS_RCU
1482 rcu_spawn_tasks_kthread();
1483#endif
1484
1485#ifdef CONFIG_TASKS_RUDE_RCU
1486 rcu_spawn_tasks_rude_kthread();
1487#endif
1488
1489#ifdef CONFIG_TASKS_TRACE_RCU
1490 rcu_spawn_tasks_trace_kthread();
1491#endif
Uladzislau Rezki (Sony)bfba7ed2020-12-09 21:27:32 +01001492
1493 // Run the self-tests.
1494 rcu_tasks_initiate_self_tests();
Uladzislau Rezki (Sony)1b04fa92020-12-09 21:27:31 +01001495}
1496
Paul E. McKenney8fd8ca32020-03-15 14:51:20 -07001497#else /* #ifdef CONFIG_TASKS_RCU_GENERIC */
1498static inline void rcu_tasks_bootup_oddness(void) {}
1499#endif /* #else #ifdef CONFIG_TASKS_RCU_GENERIC */