1
2
3
4
5
6
7
8
9
10
11
12 #include <linux/cache.h>
13 #include <linux/spinlock.h>
14 #include <linux/rtmutex.h>
15 #include <linux/threads.h>
16 #include <linux/cpumask.h>
17 #include <linux/seqlock.h>
18 #include <linux/swait.h>
19 #include <linux/stop_machine.h>
20 #include <linux/rcu_node_tree.h>
21
22 #include "rcu_segcblist.h"
23
24
25 struct rcu_exp_work {
26 unsigned long rew_s;
27 struct work_struct rew_work;
28 };
29
30
31 #define RCU_KTHREAD_STOPPED 0
32 #define RCU_KTHREAD_RUNNING 1
33 #define RCU_KTHREAD_WAITING 2
34 #define RCU_KTHREAD_OFFCPU 3
35 #define RCU_KTHREAD_YIELDING 4
36 #define RCU_KTHREAD_MAX 4
37
38
39
40
41 struct rcu_node {
42 raw_spinlock_t __private lock;
43
44
45 unsigned long gp_seq;
46 unsigned long gp_seq_needed;
47 unsigned long completedqs;
48 unsigned long qsmask;
49
50
51
52
53
54 unsigned long rcu_gp_init_mask;
55 unsigned long qsmaskinit;
56
57
58
59 unsigned long qsmaskinitnext;
60
61 unsigned long expmask;
62
63
64 unsigned long expmaskinit;
65
66
67
68 unsigned long expmaskinitnext;
69
70
71
72 unsigned long ffmask;
73 unsigned long grpmask;
74
75 int grplo;
76 int grphi;
77 u8 grpnum;
78 u8 level;
79 bool wait_blkd_tasks;
80
81
82
83 struct rcu_node *parent;
84 struct list_head blkd_tasks;
85
86
87
88 struct list_head *gp_tasks;
89
90
91
92 struct list_head *exp_tasks;
93
94
95
96
97
98 struct list_head *boost_tasks;
99
100
101
102
103
104
105
106 struct rt_mutex boost_mtx;
107
108
109 unsigned long boost_time;
110
111 struct task_struct *boost_kthread_task;
112
113
114 unsigned int boost_kthread_status;
115
116 #ifdef CONFIG_RCU_NOCB_CPU
117 struct swait_queue_head nocb_gp_wq[2];
118
119 #endif
120 raw_spinlock_t fqslock ____cacheline_internodealigned_in_smp;
121
122 spinlock_t exp_lock ____cacheline_internodealigned_in_smp;
123 unsigned long exp_seq_rq;
124 wait_queue_head_t exp_wq[4];
125 struct rcu_exp_work rew;
126 bool exp_need_flush;
127 } ____cacheline_internodealigned_in_smp;
128
129
130
131
132
133
134 #define leaf_node_cpu_bit(rnp, cpu) (BIT((cpu) - (rnp)->grplo))
135
136
137
138
139
140 union rcu_noqs {
141 struct {
142 u8 norm;
143 u8 exp;
144 } b;
145 u16 s;
146 };
147
148
149 struct rcu_data {
150
151 unsigned long gp_seq;
152 unsigned long gp_seq_needed;
153 union rcu_noqs cpu_no_qs;
154 bool core_needs_qs;
155 bool beenonline;
156 bool gpwrap;
157 bool exp_deferred_qs;
158 struct rcu_node *mynode;
159 unsigned long grpmask;
160 unsigned long ticks_this_gp;
161
162
163
164 struct irq_work defer_qs_iw;
165 bool defer_qs_iw_pending;
166
167
168 struct rcu_segcblist cblist;
169
170
171 long qlen_last_fqs_check;
172
173 unsigned long n_force_qs_snap;
174
175 long blimit;
176
177
178 int dynticks_snap;
179 long dynticks_nesting;
180 long dynticks_nmi_nesting;
181 atomic_t dynticks;
182 bool rcu_need_heavy_qs;
183 bool rcu_urgent_qs;
184 #ifdef CONFIG_RCU_FAST_NO_HZ
185 bool all_lazy;
186 unsigned long last_accelerate;
187 unsigned long last_advance_all;
188 int tick_nohz_enabled_snap;
189 #endif
190
191
192 struct rcu_head barrier_head;
193 int exp_dynticks_snap;
194
195
196 #ifdef CONFIG_RCU_NOCB_CPU
197 struct swait_queue_head nocb_cb_wq;
198 struct task_struct *nocb_gp_kthread;
199 raw_spinlock_t nocb_lock;
200 atomic_t nocb_lock_contended;
201 int nocb_defer_wakeup;
202 struct timer_list nocb_timer;
203 unsigned long nocb_gp_adv_time;
204
205
206 raw_spinlock_t nocb_bypass_lock ____cacheline_internodealigned_in_smp;
207 struct rcu_cblist nocb_bypass;
208 unsigned long nocb_bypass_first;
209 unsigned long nocb_nobypass_last;
210 int nocb_nobypass_count;
211
212
213 raw_spinlock_t nocb_gp_lock ____cacheline_internodealigned_in_smp;
214 struct timer_list nocb_bypass_timer;
215 u8 nocb_gp_sleep;
216 u8 nocb_gp_bypass;
217 u8 nocb_gp_gp;
218 unsigned long nocb_gp_seq;
219 unsigned long nocb_gp_loops;
220 struct swait_queue_head nocb_gp_wq;
221 bool nocb_cb_sleep;
222 struct task_struct *nocb_cb_kthread;
223 struct rcu_data *nocb_next_cb_rdp;
224
225
226
227 struct rcu_data *nocb_gp_rdp ____cacheline_internodealigned_in_smp;
228
229 #endif
230
231
232 struct task_struct *rcu_cpu_kthread_task;
233
234 unsigned int rcu_cpu_kthread_status;
235 char rcu_cpu_has_work;
236
237
238 unsigned int softirq_snap;
239
240 struct irq_work rcu_iw;
241 bool rcu_iw_pending;
242 unsigned long rcu_iw_gp_seq;
243 unsigned long rcu_ofl_gp_seq;
244 short rcu_ofl_gp_flags;
245 unsigned long rcu_onl_gp_seq;
246 short rcu_onl_gp_flags;
247 unsigned long last_fqs_resched;
248
249 int cpu;
250 };
251
252
253 #define RCU_NOCB_WAKE_NOT 0
254 #define RCU_NOCB_WAKE 1
255 #define RCU_NOCB_WAKE_FORCE 2
256
257 #define RCU_JIFFIES_TILL_FORCE_QS (1 + (HZ > 250) + (HZ > 500))
258
259
260
261 #define RCU_JIFFIES_FQS_DIV 256
262
263
264
265 #define RCU_STALL_RAT_DELAY 2
266
267
268
269 #define rcu_wait(cond) \
270 do { \
271 for (;;) { \
272 set_current_state(TASK_INTERRUPTIBLE); \
273 if (cond) \
274 break; \
275 schedule(); \
276 } \
277 __set_current_state(TASK_RUNNING); \
278 } while (0)
279
280
281
282
283
284
285
286
287
288
289
290 struct rcu_state {
291 struct rcu_node node[NUM_RCU_NODES];
292 struct rcu_node *level[RCU_NUM_LVLS + 1];
293
294
295 int ncpus;
296
297
298
299 u8 boost ____cacheline_internodealigned_in_smp;
300
301 unsigned long gp_seq;
302 struct task_struct *gp_kthread;
303 struct swait_queue_head gp_wq;
304 short gp_flags;
305 short gp_state;
306 unsigned long gp_wake_time;
307 unsigned long gp_wake_seq;
308
309
310
311 struct mutex barrier_mutex;
312 atomic_t barrier_cpu_count;
313 struct completion barrier_completion;
314 unsigned long barrier_sequence;
315
316
317
318 struct mutex exp_mutex;
319 struct mutex exp_wake_mutex;
320 unsigned long expedited_sequence;
321 atomic_t expedited_need_qs;
322 struct swait_queue_head expedited_wq;
323 int ncpus_snap;
324
325 unsigned long jiffies_force_qs;
326
327 unsigned long jiffies_kick_kthreads;
328
329 unsigned long n_force_qs;
330
331 unsigned long gp_start;
332
333 unsigned long gp_end;
334
335 unsigned long gp_activity;
336
337 unsigned long gp_req_activity;
338
339 unsigned long jiffies_stall;
340
341 unsigned long jiffies_resched;
342
343 unsigned long n_force_qs_gpstart;
344
345 unsigned long gp_max;
346
347 const char *name;
348 char abbr;
349
350 raw_spinlock_t ofl_lock ____cacheline_internodealigned_in_smp;
351
352
353 };
354
355
356 #define RCU_GP_FLAG_INIT 0x1
357 #define RCU_GP_FLAG_FQS 0x2
358
359
360 #define RCU_GP_IDLE 0
361 #define RCU_GP_WAIT_GPS 1
362 #define RCU_GP_DONE_GPS 2
363 #define RCU_GP_ONOFF 3
364 #define RCU_GP_INIT 4
365 #define RCU_GP_WAIT_FQS 5
366 #define RCU_GP_DOING_FQS 6
367 #define RCU_GP_CLEANUP 7
368 #define RCU_GP_CLEANED 8
369
370 static const char * const gp_state_names[] = {
371 "RCU_GP_IDLE",
372 "RCU_GP_WAIT_GPS",
373 "RCU_GP_DONE_GPS",
374 "RCU_GP_ONOFF",
375 "RCU_GP_INIT",
376 "RCU_GP_WAIT_FQS",
377 "RCU_GP_DOING_FQS",
378 "RCU_GP_CLEANUP",
379 "RCU_GP_CLEANED",
380 };
381
382
383
384
385
386
387
388
389
390 #ifdef CONFIG_PREEMPT_RCU
391 #define RCU_ABBR 'p'
392 #define RCU_NAME_RAW "rcu_preempt"
393 #else
394 #define RCU_ABBR 's'
395 #define RCU_NAME_RAW "rcu_sched"
396 #endif
397 #ifndef CONFIG_TRACING
398 #define RCU_NAME RCU_NAME_RAW
399 #else
400 static char rcu_name[] = RCU_NAME_RAW;
401 static const char *tp_rcu_varname __used __tracepoint_string = rcu_name;
402 #define RCU_NAME rcu_name
403 #endif
404
405 int rcu_dynticks_snap(struct rcu_data *rdp);
406
407
408 static void rcu_bootup_announce(void);
409 static void rcu_qs(void);
410 static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp);
411 #ifdef CONFIG_HOTPLUG_CPU
412 static bool rcu_preempt_has_tasks(struct rcu_node *rnp);
413 #endif
414 static int rcu_print_task_exp_stall(struct rcu_node *rnp);
415 static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp);
416 static void rcu_flavor_sched_clock_irq(int user);
417 void call_rcu(struct rcu_head *head, rcu_callback_t func);
418 static void dump_blkd_tasks(struct rcu_node *rnp, int ncheck);
419 static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags);
420 static void rcu_preempt_boost_start_gp(struct rcu_node *rnp);
421 static bool rcu_is_callbacks_kthread(void);
422 static void rcu_cpu_kthread_setup(unsigned int cpu);
423 static void __init rcu_spawn_boost_kthreads(void);
424 static void rcu_prepare_kthreads(int cpu);
425 static void rcu_cleanup_after_idle(void);
426 static void rcu_prepare_for_idle(void);
427 static bool rcu_preempt_has_tasks(struct rcu_node *rnp);
428 static bool rcu_preempt_need_deferred_qs(struct task_struct *t);
429 static void rcu_preempt_deferred_qs(struct task_struct *t);
430 static void zero_cpu_stall_ticks(struct rcu_data *rdp);
431 static struct swait_queue_head *rcu_nocb_gp_get(struct rcu_node *rnp);
432 static void rcu_nocb_gp_cleanup(struct swait_queue_head *sq);
433 static void rcu_init_one_nocb(struct rcu_node *rnp);
434 static bool rcu_nocb_flush_bypass(struct rcu_data *rdp, struct rcu_head *rhp,
435 unsigned long j);
436 static bool rcu_nocb_try_bypass(struct rcu_data *rdp, struct rcu_head *rhp,
437 bool *was_alldone, unsigned long flags);
438 static void __call_rcu_nocb_wake(struct rcu_data *rdp, bool was_empty,
439 unsigned long flags);
440 static int rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp);
441 static void do_nocb_deferred_wakeup(struct rcu_data *rdp);
442 static void rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp);
443 static void rcu_spawn_cpu_nocb_kthread(int cpu);
444 static void __init rcu_spawn_nocb_kthreads(void);
445 static void show_rcu_nocb_state(struct rcu_data *rdp);
446 static void rcu_nocb_lock(struct rcu_data *rdp);
447 static void rcu_nocb_unlock(struct rcu_data *rdp);
448 static void rcu_nocb_unlock_irqrestore(struct rcu_data *rdp,
449 unsigned long flags);
450 static void rcu_lockdep_assert_cblist_protected(struct rcu_data *rdp);
451 #ifdef CONFIG_RCU_NOCB_CPU
452 static void __init rcu_organize_nocb_kthreads(void);
453 #define rcu_nocb_lock_irqsave(rdp, flags) \
454 do { \
455 if (!rcu_segcblist_is_offloaded(&(rdp)->cblist)) \
456 local_irq_save(flags); \
457 else \
458 raw_spin_lock_irqsave(&(rdp)->nocb_lock, (flags)); \
459 } while (0)
460 #else
461 #define rcu_nocb_lock_irqsave(rdp, flags) local_irq_save(flags)
462 #endif
463
464 static void rcu_bind_gp_kthread(void);
465 static bool rcu_nohz_full_cpu(void);
466 static void rcu_dynticks_task_enter(void);
467 static void rcu_dynticks_task_exit(void);
468
469
470 static void record_gp_stall_check_time(void);
471 static void rcu_iw_handler(struct irq_work *iwp);
472 static void check_cpu_stall(struct rcu_data *rdp);
473 static void rcu_check_gp_start_stall(struct rcu_node *rnp, struct rcu_data *rdp,
474 const unsigned long gpssdelay);