1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <linux/delay.h>
28#include <linux/gfp.h>
29#include <linux/oom.h>
30#include <linux/smpboot.h>
31
32#define RCU_KTHREAD_PRIO 1
33
34#ifdef CONFIG_RCU_BOOST
35#define RCU_BOOST_PRIO CONFIG_RCU_BOOST_PRIO
36#else
37#define RCU_BOOST_PRIO RCU_KTHREAD_PRIO
38#endif
39
40#ifdef CONFIG_RCU_NOCB_CPU
41static cpumask_var_t rcu_nocb_mask;
42static bool have_rcu_nocb_mask;
43static bool __read_mostly rcu_nocb_poll;
44static char __initdata nocb_buf[NR_CPUS * 5];
45#endif
46
47
48
49
50
51
52static void __init rcu_bootup_announce_oddness(void)
53{
54#ifdef CONFIG_RCU_TRACE
55 printk(KERN_INFO "\tRCU debugfs-based tracing is enabled.\n");
56#endif
57#if (defined(CONFIG_64BIT) && CONFIG_RCU_FANOUT != 64) || (!defined(CONFIG_64BIT) && CONFIG_RCU_FANOUT != 32)
58 printk(KERN_INFO "\tCONFIG_RCU_FANOUT set to non-default value of %d\n",
59 CONFIG_RCU_FANOUT);
60#endif
61#ifdef CONFIG_RCU_FANOUT_EXACT
62 printk(KERN_INFO "\tHierarchical RCU autobalancing is disabled.\n");
63#endif
64#ifdef CONFIG_RCU_FAST_NO_HZ
65 printk(KERN_INFO
66 "\tRCU dyntick-idle grace-period acceleration is enabled.\n");
67#endif
68#ifdef CONFIG_PROVE_RCU
69 printk(KERN_INFO "\tRCU lockdep checking is enabled.\n");
70#endif
71#ifdef CONFIG_RCU_TORTURE_TEST_RUNNABLE
72 printk(KERN_INFO "\tRCU torture testing starts during boot.\n");
73#endif
74#if defined(CONFIG_TREE_PREEMPT_RCU) && !defined(CONFIG_RCU_CPU_STALL_VERBOSE)
75 printk(KERN_INFO "\tDump stacks of tasks blocking RCU-preempt GP.\n");
76#endif
77#if defined(CONFIG_RCU_CPU_STALL_INFO)
78 printk(KERN_INFO "\tAdditional per-CPU info printed with stalls.\n");
79#endif
80#if NUM_RCU_LVL_4 != 0
81 printk(KERN_INFO "\tFour-level hierarchy is enabled.\n");
82#endif
83 if (rcu_fanout_leaf != CONFIG_RCU_FANOUT_LEAF)
84 printk(KERN_INFO "\tExperimental boot-time adjustment of leaf fanout to %d.\n", rcu_fanout_leaf);
85 if (nr_cpu_ids != NR_CPUS)
86 printk(KERN_INFO "\tRCU restricting CPUs from NR_CPUS=%d to nr_cpu_ids=%d.\n", NR_CPUS, nr_cpu_ids);
87#ifdef CONFIG_RCU_NOCB_CPU
88 if (have_rcu_nocb_mask) {
89 if (cpumask_test_cpu(0, rcu_nocb_mask)) {
90 cpumask_clear_cpu(0, rcu_nocb_mask);
91 pr_info("\tCPU 0: illegal no-CBs CPU (cleared).\n");
92 }
93 cpulist_scnprintf(nocb_buf, sizeof(nocb_buf), rcu_nocb_mask);
94 pr_info("\tExperimental no-CBs CPUs: %s.\n", nocb_buf);
95 if (rcu_nocb_poll)
96 pr_info("\tExperimental polled no-CBs CPUs.\n");
97 }
98#endif
99}
100
101#ifdef CONFIG_TREE_PREEMPT_RCU
102
103struct rcu_state rcu_preempt_state =
104 RCU_STATE_INITIALIZER(rcu_preempt, call_rcu);
105DEFINE_PER_CPU(struct rcu_data, rcu_preempt_data);
106static struct rcu_state *rcu_state = &rcu_preempt_state;
107
108static int rcu_preempted_readers_exp(struct rcu_node *rnp);
109
110
111
112
113static void __init rcu_bootup_announce(void)
114{
115 printk(KERN_INFO "Preemptible hierarchical RCU implementation.\n");
116 rcu_bootup_announce_oddness();
117}
118
119
120
121
122
123long rcu_batches_completed_preempt(void)
124{
125 return rcu_preempt_state.completed;
126}
127EXPORT_SYMBOL_GPL(rcu_batches_completed_preempt);
128
129
130
131
132long rcu_batches_completed(void)
133{
134 return rcu_batches_completed_preempt();
135}
136EXPORT_SYMBOL_GPL(rcu_batches_completed);
137
138
139
140
141void rcu_force_quiescent_state(void)
142{
143 force_quiescent_state(&rcu_preempt_state);
144}
145EXPORT_SYMBOL_GPL(rcu_force_quiescent_state);
146
147
148
149
150
151
152
153
154
155
156
157static void rcu_preempt_qs(int cpu)
158{
159 struct rcu_data *rdp = &per_cpu(rcu_preempt_data, cpu);
160
161 if (rdp->passed_quiesce == 0)
162 trace_rcu_grace_period("rcu_preempt", rdp->gpnum, "cpuqs");
163 rdp->passed_quiesce = 1;
164 current->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_NEED_QS;
165}
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180static void rcu_preempt_note_context_switch(int cpu)
181{
182 struct task_struct *t = current;
183 unsigned long flags;
184 struct rcu_data *rdp;
185 struct rcu_node *rnp;
186
187 if (t->rcu_read_lock_nesting > 0 &&
188 (t->rcu_read_unlock_special & RCU_READ_UNLOCK_BLOCKED) == 0) {
189
190
191 rdp = per_cpu_ptr(rcu_preempt_state.rda, cpu);
192 rnp = rdp->mynode;
193 raw_spin_lock_irqsave(&rnp->lock, flags);
194 t->rcu_read_unlock_special |= RCU_READ_UNLOCK_BLOCKED;
195 t->rcu_blocked_node = rnp;
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215 WARN_ON_ONCE((rdp->grpmask & rnp->qsmaskinit) == 0);
216 WARN_ON_ONCE(!list_empty(&t->rcu_node_entry));
217 if ((rnp->qsmask & rdp->grpmask) && rnp->gp_tasks != NULL) {
218 list_add(&t->rcu_node_entry, rnp->gp_tasks->prev);
219 rnp->gp_tasks = &t->rcu_node_entry;
220#ifdef CONFIG_RCU_BOOST
221 if (rnp->boost_tasks != NULL)
222 rnp->boost_tasks = rnp->gp_tasks;
223#endif
224 } else {
225 list_add(&t->rcu_node_entry, &rnp->blkd_tasks);
226 if (rnp->qsmask & rdp->grpmask)
227 rnp->gp_tasks = &t->rcu_node_entry;
228 }
229 trace_rcu_preempt_task(rdp->rsp->name,
230 t->pid,
231 (rnp->qsmask & rdp->grpmask)
232 ? rnp->gpnum
233 : rnp->gpnum + 1);
234 raw_spin_unlock_irqrestore(&rnp->lock, flags);
235 } else if (t->rcu_read_lock_nesting < 0 &&
236 t->rcu_read_unlock_special) {
237
238
239
240
241
242 rcu_read_unlock_special(t);
243 }
244
245
246
247
248
249
250
251
252
253
254 local_irq_save(flags);
255 rcu_preempt_qs(cpu);
256 local_irq_restore(flags);
257}
258
259
260
261
262
263
264static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp)
265{
266 return rnp->gp_tasks != NULL;
267}
268
269
270
271
272
273
274
275
276static void rcu_report_unblock_qs_rnp(struct rcu_node *rnp, unsigned long flags)
277 __releases(rnp->lock)
278{
279 unsigned long mask;
280 struct rcu_node *rnp_p;
281
282 if (rnp->qsmask != 0 || rcu_preempt_blocked_readers_cgp(rnp)) {
283 raw_spin_unlock_irqrestore(&rnp->lock, flags);
284 return;
285 }
286
287 rnp_p = rnp->parent;
288 if (rnp_p == NULL) {
289
290
291
292
293
294 rcu_report_qs_rsp(&rcu_preempt_state, flags);
295 return;
296 }
297
298
299 mask = rnp->grpmask;
300 raw_spin_unlock(&rnp->lock);
301 raw_spin_lock(&rnp_p->lock);
302 rcu_report_qs_rnp(mask, &rcu_preempt_state, rnp_p, flags);
303}
304
305
306
307
308
309static struct list_head *rcu_next_node_entry(struct task_struct *t,
310 struct rcu_node *rnp)
311{
312 struct list_head *np;
313
314 np = t->rcu_node_entry.next;
315 if (np == &rnp->blkd_tasks)
316 np = NULL;
317 return np;
318}
319
320
321
322
323
324
325void rcu_read_unlock_special(struct task_struct *t)
326{
327 int empty;
328 int empty_exp;
329 int empty_exp_now;
330 unsigned long flags;
331 struct list_head *np;
332#ifdef CONFIG_RCU_BOOST
333 struct rt_mutex *rbmp = NULL;
334#endif
335 struct rcu_node *rnp;
336 int special;
337
338
339 if (in_nmi())
340 return;
341
342 local_irq_save(flags);
343
344
345
346
347
348 special = t->rcu_read_unlock_special;
349 if (special & RCU_READ_UNLOCK_NEED_QS) {
350 rcu_preempt_qs(smp_processor_id());
351 }
352
353
354 if (in_irq() || in_serving_softirq()) {
355 local_irq_restore(flags);
356 return;
357 }
358
359
360 if (special & RCU_READ_UNLOCK_BLOCKED) {
361 t->rcu_read_unlock_special &= ~RCU_READ_UNLOCK_BLOCKED;
362
363
364
365
366
367
368 for (;;) {
369 rnp = t->rcu_blocked_node;
370 raw_spin_lock(&rnp->lock);
371 if (rnp == t->rcu_blocked_node)
372 break;
373 raw_spin_unlock(&rnp->lock);
374 }
375 empty = !rcu_preempt_blocked_readers_cgp(rnp);
376 empty_exp = !rcu_preempted_readers_exp(rnp);
377 smp_mb();
378 np = rcu_next_node_entry(t, rnp);
379 list_del_init(&t->rcu_node_entry);
380 t->rcu_blocked_node = NULL;
381 trace_rcu_unlock_preempted_task("rcu_preempt",
382 rnp->gpnum, t->pid);
383 if (&t->rcu_node_entry == rnp->gp_tasks)
384 rnp->gp_tasks = np;
385 if (&t->rcu_node_entry == rnp->exp_tasks)
386 rnp->exp_tasks = np;
387#ifdef CONFIG_RCU_BOOST
388 if (&t->rcu_node_entry == rnp->boost_tasks)
389 rnp->boost_tasks = np;
390
391 if (t->rcu_boost_mutex) {
392 rbmp = t->rcu_boost_mutex;
393 t->rcu_boost_mutex = NULL;
394 }
395#endif
396
397
398
399
400
401
402
403 empty_exp_now = !rcu_preempted_readers_exp(rnp);
404 if (!empty && !rcu_preempt_blocked_readers_cgp(rnp)) {
405 trace_rcu_quiescent_state_report("preempt_rcu",
406 rnp->gpnum,
407 0, rnp->qsmask,
408 rnp->level,
409 rnp->grplo,
410 rnp->grphi,
411 !!rnp->gp_tasks);
412 rcu_report_unblock_qs_rnp(rnp, flags);
413 } else {
414 raw_spin_unlock_irqrestore(&rnp->lock, flags);
415 }
416
417#ifdef CONFIG_RCU_BOOST
418
419 if (rbmp)
420 rt_mutex_unlock(rbmp);
421#endif
422
423
424
425
426
427 if (!empty_exp && empty_exp_now)
428 rcu_report_exp_rnp(&rcu_preempt_state, rnp, true);
429 } else {
430 local_irq_restore(flags);
431 }
432}
433
434#ifdef CONFIG_RCU_CPU_STALL_VERBOSE
435
436
437
438
439
440static void rcu_print_detail_task_stall_rnp(struct rcu_node *rnp)
441{
442 unsigned long flags;
443 struct task_struct *t;
444
445 raw_spin_lock_irqsave(&rnp->lock, flags);
446 if (!rcu_preempt_blocked_readers_cgp(rnp)) {
447 raw_spin_unlock_irqrestore(&rnp->lock, flags);
448 return;
449 }
450 t = list_entry(rnp->gp_tasks,
451 struct task_struct, rcu_node_entry);
452 list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry)
453 sched_show_task(t);
454 raw_spin_unlock_irqrestore(&rnp->lock, flags);
455}
456
457
458
459
460
461static void rcu_print_detail_task_stall(struct rcu_state *rsp)
462{
463 struct rcu_node *rnp = rcu_get_root(rsp);
464
465 rcu_print_detail_task_stall_rnp(rnp);
466 rcu_for_each_leaf_node(rsp, rnp)
467 rcu_print_detail_task_stall_rnp(rnp);
468}
469
470#else
471
472static void rcu_print_detail_task_stall(struct rcu_state *rsp)
473{
474}
475
476#endif
477
478#ifdef CONFIG_RCU_CPU_STALL_INFO
479
480static void rcu_print_task_stall_begin(struct rcu_node *rnp)
481{
482 printk(KERN_ERR "\tTasks blocked on level-%d rcu_node (CPUs %d-%d):",
483 rnp->level, rnp->grplo, rnp->grphi);
484}
485
486static void rcu_print_task_stall_end(void)
487{
488 printk(KERN_CONT "\n");
489}
490
491#else
492
493static void rcu_print_task_stall_begin(struct rcu_node *rnp)
494{
495}
496
497static void rcu_print_task_stall_end(void)
498{
499}
500
501#endif
502
503
504
505
506
507static int rcu_print_task_stall(struct rcu_node *rnp)
508{
509 struct task_struct *t;
510 int ndetected = 0;
511
512 if (!rcu_preempt_blocked_readers_cgp(rnp))
513 return 0;
514 rcu_print_task_stall_begin(rnp);
515 t = list_entry(rnp->gp_tasks,
516 struct task_struct, rcu_node_entry);
517 list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry) {
518 printk(KERN_CONT " P%d", t->pid);
519 ndetected++;
520 }
521 rcu_print_task_stall_end();
522 return ndetected;
523}
524
525
526
527
528
529
530
531
532
533
534
535static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp)
536{
537 WARN_ON_ONCE(rcu_preempt_blocked_readers_cgp(rnp));
538 if (!list_empty(&rnp->blkd_tasks))
539 rnp->gp_tasks = rnp->blkd_tasks.next;
540 WARN_ON_ONCE(rnp->qsmask);
541}
542
543#ifdef CONFIG_HOTPLUG_CPU
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559static int rcu_preempt_offline_tasks(struct rcu_state *rsp,
560 struct rcu_node *rnp,
561 struct rcu_data *rdp)
562{
563 struct list_head *lp;
564 struct list_head *lp_root;
565 int retval = 0;
566 struct rcu_node *rnp_root = rcu_get_root(rsp);
567 struct task_struct *t;
568
569 if (rnp == rnp_root) {
570 WARN_ONCE(1, "Last CPU thought to be offlined?");
571 return 0;
572 }
573
574
575 WARN_ON_ONCE(rnp != rdp->mynode);
576
577
578
579
580
581
582
583
584
585
586 if (rcu_preempt_blocked_readers_cgp(rnp) && rnp->qsmask == 0)
587 retval |= RCU_OFL_TASKS_NORM_GP;
588 if (rcu_preempted_readers_exp(rnp))
589 retval |= RCU_OFL_TASKS_EXP_GP;
590 lp = &rnp->blkd_tasks;
591 lp_root = &rnp_root->blkd_tasks;
592 while (!list_empty(lp)) {
593 t = list_entry(lp->next, typeof(*t), rcu_node_entry);
594 raw_spin_lock(&rnp_root->lock);
595 list_del(&t->rcu_node_entry);
596 t->rcu_blocked_node = rnp_root;
597 list_add(&t->rcu_node_entry, lp_root);
598 if (&t->rcu_node_entry == rnp->gp_tasks)
599 rnp_root->gp_tasks = rnp->gp_tasks;
600 if (&t->rcu_node_entry == rnp->exp_tasks)
601 rnp_root->exp_tasks = rnp->exp_tasks;
602#ifdef CONFIG_RCU_BOOST
603 if (&t->rcu_node_entry == rnp->boost_tasks)
604 rnp_root->boost_tasks = rnp->boost_tasks;
605#endif
606 raw_spin_unlock(&rnp_root->lock);
607 }
608
609 rnp->gp_tasks = NULL;
610 rnp->exp_tasks = NULL;
611#ifdef CONFIG_RCU_BOOST
612 rnp->boost_tasks = NULL;
613
614
615
616
617
618 raw_spin_lock(&rnp_root->lock);
619 if (rnp_root->boost_tasks != NULL &&
620 rnp_root->boost_tasks != rnp_root->gp_tasks &&
621 rnp_root->boost_tasks != rnp_root->exp_tasks)
622 rnp_root->boost_tasks = rnp_root->gp_tasks;
623 raw_spin_unlock(&rnp_root->lock);
624#endif
625
626 return retval;
627}
628
629#endif
630
631
632
633
634
635
636
637
638static void rcu_preempt_check_callbacks(int cpu)
639{
640 struct task_struct *t = current;
641
642 if (t->rcu_read_lock_nesting == 0) {
643 rcu_preempt_qs(cpu);
644 return;
645 }
646 if (t->rcu_read_lock_nesting > 0 &&
647 per_cpu(rcu_preempt_data, cpu).qs_pending)
648 t->rcu_read_unlock_special |= RCU_READ_UNLOCK_NEED_QS;
649}
650
651#ifdef CONFIG_RCU_BOOST
652
653static void rcu_preempt_do_callbacks(void)
654{
655 rcu_do_batch(&rcu_preempt_state, &__get_cpu_var(rcu_preempt_data));
656}
657
658#endif
659
660
661
662
663void call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu))
664{
665 __call_rcu(head, func, &rcu_preempt_state, -1, 0);
666}
667EXPORT_SYMBOL_GPL(call_rcu);
668
669
670
671
672
673
674
675
676void kfree_call_rcu(struct rcu_head *head,
677 void (*func)(struct rcu_head *rcu))
678{
679 __call_rcu(head, func, &rcu_preempt_state, -1, 1);
680}
681EXPORT_SYMBOL_GPL(kfree_call_rcu);
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697void synchronize_rcu(void)
698{
699 rcu_lockdep_assert(!lock_is_held(&rcu_bh_lock_map) &&
700 !lock_is_held(&rcu_lock_map) &&
701 !lock_is_held(&rcu_sched_lock_map),
702 "Illegal synchronize_rcu() in RCU read-side critical section");
703 if (!rcu_scheduler_active)
704 return;
705 if (rcu_expedited)
706 synchronize_rcu_expedited();
707 else
708 wait_rcu_gp(call_rcu);
709}
710EXPORT_SYMBOL_GPL(synchronize_rcu);
711
712static DECLARE_WAIT_QUEUE_HEAD(sync_rcu_preempt_exp_wq);
713static unsigned long sync_rcu_preempt_exp_count;
714static DEFINE_MUTEX(sync_rcu_preempt_exp_mutex);
715
716
717
718
719
720
721
722static int rcu_preempted_readers_exp(struct rcu_node *rnp)
723{
724 return rnp->exp_tasks != NULL;
725}
726
727
728
729
730
731
732
733
734
735
736static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
737{
738 return !rcu_preempted_readers_exp(rnp) &&
739 ACCESS_ONCE(rnp->expmask) == 0;
740}
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp,
756 bool wake)
757{
758 unsigned long flags;
759 unsigned long mask;
760
761 raw_spin_lock_irqsave(&rnp->lock, flags);
762 for (;;) {
763 if (!sync_rcu_preempt_exp_done(rnp)) {
764 raw_spin_unlock_irqrestore(&rnp->lock, flags);
765 break;
766 }
767 if (rnp->parent == NULL) {
768 raw_spin_unlock_irqrestore(&rnp->lock, flags);
769 if (wake)
770 wake_up(&sync_rcu_preempt_exp_wq);
771 break;
772 }
773 mask = rnp->grpmask;
774 raw_spin_unlock(&rnp->lock);
775 rnp = rnp->parent;
776 raw_spin_lock(&rnp->lock);
777 rnp->expmask &= ~mask;
778 }
779}
780
781
782
783
784
785
786
787
788
789static void
790sync_rcu_preempt_exp_init(struct rcu_state *rsp, struct rcu_node *rnp)
791{
792 unsigned long flags;
793 int must_wait = 0;
794
795 raw_spin_lock_irqsave(&rnp->lock, flags);
796 if (list_empty(&rnp->blkd_tasks)) {
797 raw_spin_unlock_irqrestore(&rnp->lock, flags);
798 } else {
799 rnp->exp_tasks = rnp->blkd_tasks.next;
800 rcu_initiate_boost(rnp, flags);
801 must_wait = 1;
802 }
803 if (!must_wait)
804 rcu_report_exp_rnp(rsp, rnp, false);
805}
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824void synchronize_rcu_expedited(void)
825{
826 unsigned long flags;
827 struct rcu_node *rnp;
828 struct rcu_state *rsp = &rcu_preempt_state;
829 unsigned long snap;
830 int trycount = 0;
831
832 smp_mb();
833 snap = ACCESS_ONCE(sync_rcu_preempt_exp_count) + 1;
834 smp_mb();
835
836
837
838
839
840
841
842
843
844 get_online_cpus();
845
846
847
848
849
850
851 while (!mutex_trylock(&sync_rcu_preempt_exp_mutex)) {
852 if (ULONG_CMP_LT(snap,
853 ACCESS_ONCE(sync_rcu_preempt_exp_count))) {
854 put_online_cpus();
855 goto mb_ret;
856 }
857 if (trycount++ < 10) {
858 udelay(trycount * num_online_cpus());
859 } else {
860 put_online_cpus();
861 wait_rcu_gp(call_rcu);
862 return;
863 }
864 }
865 if (ULONG_CMP_LT(snap, ACCESS_ONCE(sync_rcu_preempt_exp_count))) {
866 put_online_cpus();
867 goto unlock_mb_ret;
868 }
869
870
871 synchronize_sched_expedited();
872
873
874 rcu_for_each_nonleaf_node_breadth_first(rsp, rnp) {
875 raw_spin_lock_irqsave(&rnp->lock, flags);
876 rnp->expmask = rnp->qsmaskinit;
877 raw_spin_unlock_irqrestore(&rnp->lock, flags);
878 }
879
880
881 rcu_for_each_leaf_node(rsp, rnp)
882 sync_rcu_preempt_exp_init(rsp, rnp);
883 if (NUM_RCU_NODES > 1)
884 sync_rcu_preempt_exp_init(rsp, rcu_get_root(rsp));
885
886 put_online_cpus();
887
888
889 rnp = rcu_get_root(rsp);
890 wait_event(sync_rcu_preempt_exp_wq,
891 sync_rcu_preempt_exp_done(rnp));
892
893
894 smp_mb();
895 ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
896unlock_mb_ret:
897 mutex_unlock(&sync_rcu_preempt_exp_mutex);
898mb_ret:
899 smp_mb();
900}
901EXPORT_SYMBOL_GPL(synchronize_rcu_expedited);
902
903
904
905
906
907
908
909
910
911void rcu_barrier(void)
912{
913 _rcu_barrier(&rcu_preempt_state);
914}
915EXPORT_SYMBOL_GPL(rcu_barrier);
916
917
918
919
920static void __init __rcu_init_preempt(void)
921{
922 rcu_init_one(&rcu_preempt_state, &rcu_preempt_data);
923}
924
925#else
926
927static struct rcu_state *rcu_state = &rcu_sched_state;
928
929
930
931
932static void __init rcu_bootup_announce(void)
933{
934 printk(KERN_INFO "Hierarchical RCU implementation.\n");
935 rcu_bootup_announce_oddness();
936}
937
938
939
940
941long rcu_batches_completed(void)
942{
943 return rcu_batches_completed_sched();
944}
945EXPORT_SYMBOL_GPL(rcu_batches_completed);
946
947
948
949
950
951void rcu_force_quiescent_state(void)
952{
953 rcu_sched_force_quiescent_state();
954}
955EXPORT_SYMBOL_GPL(rcu_force_quiescent_state);
956
957
958
959
960
961static void rcu_preempt_note_context_switch(int cpu)
962{
963}
964
965
966
967
968
969static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp)
970{
971 return 0;
972}
973
974#ifdef CONFIG_HOTPLUG_CPU
975
976
977static void rcu_report_unblock_qs_rnp(struct rcu_node *rnp, unsigned long flags)
978{
979 raw_spin_unlock_irqrestore(&rnp->lock, flags);
980}
981
982#endif
983
984
985
986
987
988static void rcu_print_detail_task_stall(struct rcu_state *rsp)
989{
990}
991
992
993
994
995
996static int rcu_print_task_stall(struct rcu_node *rnp)
997{
998 return 0;
999}
1000
1001
1002
1003
1004
1005
1006static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp)
1007{
1008 WARN_ON_ONCE(rnp->qsmask);
1009}
1010
1011#ifdef CONFIG_HOTPLUG_CPU
1012
1013
1014
1015
1016
1017
1018
1019static int rcu_preempt_offline_tasks(struct rcu_state *rsp,
1020 struct rcu_node *rnp,
1021 struct rcu_data *rdp)
1022{
1023 return 0;
1024}
1025
1026#endif
1027
1028
1029
1030
1031
1032static void rcu_preempt_check_callbacks(int cpu)
1033{
1034}
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045void kfree_call_rcu(struct rcu_head *head,
1046 void (*func)(struct rcu_head *rcu))
1047{
1048 __call_rcu(head, func, &rcu_sched_state, -1, 1);
1049}
1050EXPORT_SYMBOL_GPL(kfree_call_rcu);
1051
1052
1053
1054
1055
1056void synchronize_rcu_expedited(void)
1057{
1058 synchronize_sched_expedited();
1059}
1060EXPORT_SYMBOL_GPL(synchronize_rcu_expedited);
1061
1062#ifdef CONFIG_HOTPLUG_CPU
1063
1064
1065
1066
1067
1068
1069static void rcu_report_exp_rnp(struct rcu_state *rsp, struct rcu_node *rnp,
1070 bool wake)
1071{
1072}
1073
1074#endif
1075
1076
1077
1078
1079
1080void rcu_barrier(void)
1081{
1082 rcu_barrier_sched();
1083}
1084EXPORT_SYMBOL_GPL(rcu_barrier);
1085
1086
1087
1088
1089static void __init __rcu_init_preempt(void)
1090{
1091}
1092
1093#endif
1094
1095#ifdef CONFIG_RCU_BOOST
1096
1097#include "rtmutex_common.h"
1098
1099#ifdef CONFIG_RCU_TRACE
1100
1101static void rcu_initiate_boost_trace(struct rcu_node *rnp)
1102{
1103 if (list_empty(&rnp->blkd_tasks))
1104 rnp->n_balk_blkd_tasks++;
1105 else if (rnp->exp_tasks == NULL && rnp->gp_tasks == NULL)
1106 rnp->n_balk_exp_gp_tasks++;
1107 else if (rnp->gp_tasks != NULL && rnp->boost_tasks != NULL)
1108 rnp->n_balk_boost_tasks++;
1109 else if (rnp->gp_tasks != NULL && rnp->qsmask != 0)
1110 rnp->n_balk_notblocked++;
1111 else if (rnp->gp_tasks != NULL &&
1112 ULONG_CMP_LT(jiffies, rnp->boost_time))
1113 rnp->n_balk_notyet++;
1114 else
1115 rnp->n_balk_nos++;
1116}
1117
1118#else
1119
1120static void rcu_initiate_boost_trace(struct rcu_node *rnp)
1121{
1122}
1123
1124#endif
1125
1126static void rcu_wake_cond(struct task_struct *t, int status)
1127{
1128
1129
1130
1131
1132 if (status != RCU_KTHREAD_YIELDING || is_idle_task(current))
1133 wake_up_process(t);
1134}
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144static int rcu_boost(struct rcu_node *rnp)
1145{
1146 unsigned long flags;
1147 struct rt_mutex mtx;
1148 struct task_struct *t;
1149 struct list_head *tb;
1150
1151 if (rnp->exp_tasks == NULL && rnp->boost_tasks == NULL)
1152 return 0;
1153
1154 raw_spin_lock_irqsave(&rnp->lock, flags);
1155
1156
1157
1158
1159
1160 if (rnp->exp_tasks == NULL && rnp->boost_tasks == NULL) {
1161 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1162 return 0;
1163 }
1164
1165
1166
1167
1168
1169
1170
1171 if (rnp->exp_tasks != NULL) {
1172 tb = rnp->exp_tasks;
1173 rnp->n_exp_boosts++;
1174 } else {
1175 tb = rnp->boost_tasks;
1176 rnp->n_normal_boosts++;
1177 }
1178 rnp->n_tasks_boosted++;
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196 t = container_of(tb, struct task_struct, rcu_node_entry);
1197 rt_mutex_init_proxy_locked(&mtx, t);
1198 t->rcu_boost_mutex = &mtx;
1199 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1200 rt_mutex_lock(&mtx);
1201 rt_mutex_unlock(&mtx);
1202
1203 return ACCESS_ONCE(rnp->exp_tasks) != NULL ||
1204 ACCESS_ONCE(rnp->boost_tasks) != NULL;
1205}
1206
1207
1208
1209
1210
1211static int rcu_boost_kthread(void *arg)
1212{
1213 struct rcu_node *rnp = (struct rcu_node *)arg;
1214 int spincnt = 0;
1215 int more2boost;
1216
1217 trace_rcu_utilization("Start boost kthread@init");
1218 for (;;) {
1219 rnp->boost_kthread_status = RCU_KTHREAD_WAITING;
1220 trace_rcu_utilization("End boost kthread@rcu_wait");
1221 rcu_wait(rnp->boost_tasks || rnp->exp_tasks);
1222 trace_rcu_utilization("Start boost kthread@rcu_wait");
1223 rnp->boost_kthread_status = RCU_KTHREAD_RUNNING;
1224 more2boost = rcu_boost(rnp);
1225 if (more2boost)
1226 spincnt++;
1227 else
1228 spincnt = 0;
1229 if (spincnt > 10) {
1230 rnp->boost_kthread_status = RCU_KTHREAD_YIELDING;
1231 trace_rcu_utilization("End boost kthread@rcu_yield");
1232 schedule_timeout_interruptible(2);
1233 trace_rcu_utilization("Start boost kthread@rcu_yield");
1234 spincnt = 0;
1235 }
1236 }
1237
1238 trace_rcu_utilization("End boost kthread@notreached");
1239 return 0;
1240}
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags)
1253{
1254 struct task_struct *t;
1255
1256 if (!rcu_preempt_blocked_readers_cgp(rnp) && rnp->exp_tasks == NULL) {
1257 rnp->n_balk_exp_gp_tasks++;
1258 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1259 return;
1260 }
1261 if (rnp->exp_tasks != NULL ||
1262 (rnp->gp_tasks != NULL &&
1263 rnp->boost_tasks == NULL &&
1264 rnp->qsmask == 0 &&
1265 ULONG_CMP_GE(jiffies, rnp->boost_time))) {
1266 if (rnp->exp_tasks == NULL)
1267 rnp->boost_tasks = rnp->gp_tasks;
1268 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1269 t = rnp->boost_kthread_task;
1270 if (t)
1271 rcu_wake_cond(t, rnp->boost_kthread_status);
1272 } else {
1273 rcu_initiate_boost_trace(rnp);
1274 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1275 }
1276}
1277
1278
1279
1280
1281static void invoke_rcu_callbacks_kthread(void)
1282{
1283 unsigned long flags;
1284
1285 local_irq_save(flags);
1286 __this_cpu_write(rcu_cpu_has_work, 1);
1287 if (__this_cpu_read(rcu_cpu_kthread_task) != NULL &&
1288 current != __this_cpu_read(rcu_cpu_kthread_task)) {
1289 rcu_wake_cond(__this_cpu_read(rcu_cpu_kthread_task),
1290 __this_cpu_read(rcu_cpu_kthread_status));
1291 }
1292 local_irq_restore(flags);
1293}
1294
1295
1296
1297
1298
1299static bool rcu_is_callbacks_kthread(void)
1300{
1301 return __get_cpu_var(rcu_cpu_kthread_task) == current;
1302}
1303
1304#define RCU_BOOST_DELAY_JIFFIES DIV_ROUND_UP(CONFIG_RCU_BOOST_DELAY * HZ, 1000)
1305
1306
1307
1308
1309static void rcu_preempt_boost_start_gp(struct rcu_node *rnp)
1310{
1311 rnp->boost_time = jiffies + RCU_BOOST_DELAY_JIFFIES;
1312}
1313
1314
1315
1316
1317
1318
1319static int __cpuinit rcu_spawn_one_boost_kthread(struct rcu_state *rsp,
1320 struct rcu_node *rnp)
1321{
1322 int rnp_index = rnp - &rsp->node[0];
1323 unsigned long flags;
1324 struct sched_param sp;
1325 struct task_struct *t;
1326
1327 if (&rcu_preempt_state != rsp)
1328 return 0;
1329
1330 if (!rcu_scheduler_fully_active || rnp->qsmaskinit == 0)
1331 return 0;
1332
1333 rsp->boost = 1;
1334 if (rnp->boost_kthread_task != NULL)
1335 return 0;
1336 t = kthread_create(rcu_boost_kthread, (void *)rnp,
1337 "rcub/%d", rnp_index);
1338 if (IS_ERR(t))
1339 return PTR_ERR(t);
1340 raw_spin_lock_irqsave(&rnp->lock, flags);
1341 rnp->boost_kthread_task = t;
1342 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1343 sp.sched_priority = RCU_BOOST_PRIO;
1344 sched_setscheduler_nocheck(t, SCHED_FIFO, &sp);
1345 wake_up_process(t);
1346 return 0;
1347}
1348
1349static void rcu_kthread_do_work(void)
1350{
1351 rcu_do_batch(&rcu_sched_state, &__get_cpu_var(rcu_sched_data));
1352 rcu_do_batch(&rcu_bh_state, &__get_cpu_var(rcu_bh_data));
1353 rcu_preempt_do_callbacks();
1354}
1355
1356static void rcu_cpu_kthread_setup(unsigned int cpu)
1357{
1358 struct sched_param sp;
1359
1360 sp.sched_priority = RCU_KTHREAD_PRIO;
1361 sched_setscheduler_nocheck(current, SCHED_FIFO, &sp);
1362}
1363
1364static void rcu_cpu_kthread_park(unsigned int cpu)
1365{
1366 per_cpu(rcu_cpu_kthread_status, cpu) = RCU_KTHREAD_OFFCPU;
1367}
1368
1369static int rcu_cpu_kthread_should_run(unsigned int cpu)
1370{
1371 return __get_cpu_var(rcu_cpu_has_work);
1372}
1373
1374
1375
1376
1377
1378
1379static void rcu_cpu_kthread(unsigned int cpu)
1380{
1381 unsigned int *statusp = &__get_cpu_var(rcu_cpu_kthread_status);
1382 char work, *workp = &__get_cpu_var(rcu_cpu_has_work);
1383 int spincnt;
1384
1385 for (spincnt = 0; spincnt < 10; spincnt++) {
1386 trace_rcu_utilization("Start CPU kthread@rcu_wait");
1387 local_bh_disable();
1388 *statusp = RCU_KTHREAD_RUNNING;
1389 this_cpu_inc(rcu_cpu_kthread_loops);
1390 local_irq_disable();
1391 work = *workp;
1392 *workp = 0;
1393 local_irq_enable();
1394 if (work)
1395 rcu_kthread_do_work();
1396 local_bh_enable();
1397 if (*workp == 0) {
1398 trace_rcu_utilization("End CPU kthread@rcu_wait");
1399 *statusp = RCU_KTHREAD_WAITING;
1400 return;
1401 }
1402 }
1403 *statusp = RCU_KTHREAD_YIELDING;
1404 trace_rcu_utilization("Start CPU kthread@rcu_yield");
1405 schedule_timeout_interruptible(2);
1406 trace_rcu_utilization("End CPU kthread@rcu_yield");
1407 *statusp = RCU_KTHREAD_WAITING;
1408}
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
1420{
1421 struct task_struct *t = rnp->boost_kthread_task;
1422 unsigned long mask = rnp->qsmaskinit;
1423 cpumask_var_t cm;
1424 int cpu;
1425
1426 if (!t)
1427 return;
1428 if (!zalloc_cpumask_var(&cm, GFP_KERNEL))
1429 return;
1430 for (cpu = rnp->grplo; cpu <= rnp->grphi; cpu++, mask >>= 1)
1431 if ((mask & 0x1) && cpu != outgoingcpu)
1432 cpumask_set_cpu(cpu, cm);
1433 if (cpumask_weight(cm) == 0) {
1434 cpumask_setall(cm);
1435 for (cpu = rnp->grplo; cpu <= rnp->grphi; cpu++)
1436 cpumask_clear_cpu(cpu, cm);
1437 WARN_ON_ONCE(cpumask_weight(cm) == 0);
1438 }
1439 set_cpus_allowed_ptr(t, cm);
1440 free_cpumask_var(cm);
1441}
1442
1443static struct smp_hotplug_thread rcu_cpu_thread_spec = {
1444 .store = &rcu_cpu_kthread_task,
1445 .thread_should_run = rcu_cpu_kthread_should_run,
1446 .thread_fn = rcu_cpu_kthread,
1447 .thread_comm = "rcuc/%u",
1448 .setup = rcu_cpu_kthread_setup,
1449 .park = rcu_cpu_kthread_park,
1450};
1451
1452
1453
1454
1455static int __init rcu_spawn_kthreads(void)
1456{
1457 struct rcu_node *rnp;
1458 int cpu;
1459
1460 rcu_scheduler_fully_active = 1;
1461 for_each_possible_cpu(cpu)
1462 per_cpu(rcu_cpu_has_work, cpu) = 0;
1463 BUG_ON(smpboot_register_percpu_thread(&rcu_cpu_thread_spec));
1464 rnp = rcu_get_root(rcu_state);
1465 (void)rcu_spawn_one_boost_kthread(rcu_state, rnp);
1466 if (NUM_RCU_NODES > 1) {
1467 rcu_for_each_leaf_node(rcu_state, rnp)
1468 (void)rcu_spawn_one_boost_kthread(rcu_state, rnp);
1469 }
1470 return 0;
1471}
1472early_initcall(rcu_spawn_kthreads);
1473
1474static void __cpuinit rcu_prepare_kthreads(int cpu)
1475{
1476 struct rcu_data *rdp = per_cpu_ptr(rcu_state->rda, cpu);
1477 struct rcu_node *rnp = rdp->mynode;
1478
1479
1480 if (rcu_scheduler_fully_active)
1481 (void)rcu_spawn_one_boost_kthread(rcu_state, rnp);
1482}
1483
1484#else
1485
1486static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags)
1487{
1488 raw_spin_unlock_irqrestore(&rnp->lock, flags);
1489}
1490
1491static void invoke_rcu_callbacks_kthread(void)
1492{
1493 WARN_ON_ONCE(1);
1494}
1495
1496static bool rcu_is_callbacks_kthread(void)
1497{
1498 return false;
1499}
1500
1501static void rcu_preempt_boost_start_gp(struct rcu_node *rnp)
1502{
1503}
1504
1505static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
1506{
1507}
1508
1509static int __init rcu_scheduler_really_started(void)
1510{
1511 rcu_scheduler_fully_active = 1;
1512 return 0;
1513}
1514early_initcall(rcu_scheduler_really_started);
1515
1516static void __cpuinit rcu_prepare_kthreads(int cpu)
1517{
1518}
1519
1520#endif
1521
1522#if !defined(CONFIG_RCU_FAST_NO_HZ)
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533int rcu_needs_cpu(int cpu, unsigned long *delta_jiffies)
1534{
1535 *delta_jiffies = ULONG_MAX;
1536 return rcu_cpu_has_callbacks(cpu);
1537}
1538
1539
1540
1541
1542static void rcu_prepare_for_idle_init(int cpu)
1543{
1544}
1545
1546
1547
1548
1549
1550static void rcu_cleanup_after_idle(int cpu)
1551{
1552}
1553
1554
1555
1556
1557
1558static void rcu_prepare_for_idle(int cpu)
1559{
1560}
1561
1562
1563
1564
1565
1566static void rcu_idle_count_callbacks_posted(void)
1567{
1568}
1569
1570#else
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605#define RCU_IDLE_FLUSHES 5
1606#define RCU_IDLE_OPT_FLUSHES 3
1607#define RCU_IDLE_GP_DELAY 4
1608#define RCU_IDLE_LAZY_GP_DELAY (6 * HZ)
1609
1610extern int tick_nohz_enabled;
1611
1612
1613
1614
1615
1616
1617static bool __rcu_cpu_has_nonlazy_callbacks(struct rcu_data *rdp)
1618{
1619 return rdp->qlen != rdp->qlen_lazy;
1620}
1621
1622#ifdef CONFIG_TREE_PREEMPT_RCU
1623
1624
1625
1626
1627
1628static bool rcu_preempt_cpu_has_nonlazy_callbacks(int cpu)
1629{
1630 struct rcu_data *rdp = &per_cpu(rcu_preempt_data, cpu);
1631
1632 return __rcu_cpu_has_nonlazy_callbacks(rdp);
1633}
1634
1635#else
1636
1637static bool rcu_preempt_cpu_has_nonlazy_callbacks(int cpu)
1638{
1639 return 0;
1640}
1641
1642#endif
1643
1644
1645
1646
1647static bool rcu_cpu_has_nonlazy_callbacks(int cpu)
1648{
1649 return __rcu_cpu_has_nonlazy_callbacks(&per_cpu(rcu_sched_data, cpu)) ||
1650 __rcu_cpu_has_nonlazy_callbacks(&per_cpu(rcu_bh_data, cpu)) ||
1651 rcu_preempt_cpu_has_nonlazy_callbacks(cpu);
1652}
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671int rcu_needs_cpu(int cpu, unsigned long *delta_jiffies)
1672{
1673 struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu);
1674
1675
1676 rdtp->idle_first_pass = 1;
1677
1678 if (!rcu_cpu_has_callbacks(cpu)) {
1679 *delta_jiffies = ULONG_MAX;
1680 return 0;
1681 }
1682 if (rdtp->dyntick_holdoff == jiffies) {
1683
1684 *delta_jiffies = 1;
1685 return 1;
1686 }
1687
1688 if (rcu_cpu_has_nonlazy_callbacks(cpu)) {
1689 *delta_jiffies = round_up(RCU_IDLE_GP_DELAY + jiffies,
1690 RCU_IDLE_GP_DELAY) - jiffies;
1691 } else {
1692 *delta_jiffies = jiffies + RCU_IDLE_LAZY_GP_DELAY;
1693 *delta_jiffies = round_jiffies(*delta_jiffies) - jiffies;
1694 }
1695 return 0;
1696}
1697
1698
1699
1700
1701
1702void rcu_idle_demigrate(void *unused)
1703{
1704 trace_rcu_prep_idle("Demigrate");
1705}
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718static void rcu_idle_gp_timer_func(unsigned long cpu_in)
1719{
1720 int cpu = (int)cpu_in;
1721
1722 trace_rcu_prep_idle("Timer");
1723 if (cpu != smp_processor_id())
1724 smp_call_function_single(cpu, rcu_idle_demigrate, NULL, 0);
1725 else
1726 WARN_ON_ONCE(1);
1727}
1728
1729
1730
1731
1732static void rcu_prepare_for_idle_init(int cpu)
1733{
1734 struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu);
1735
1736 rdtp->dyntick_holdoff = jiffies - 1;
1737 setup_timer(&rdtp->idle_gp_timer, rcu_idle_gp_timer_func, cpu);
1738 rdtp->idle_gp_timer_expires = jiffies - 1;
1739 rdtp->idle_first_pass = 1;
1740}
1741
1742
1743
1744
1745
1746
1747static void rcu_cleanup_after_idle(int cpu)
1748{
1749 struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu);
1750
1751 del_timer(&rdtp->idle_gp_timer);
1752 trace_rcu_prep_idle("Cleanup after idle");
1753 rdtp->tick_nohz_enabled_snap = ACCESS_ONCE(tick_nohz_enabled);
1754}
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775static void rcu_prepare_for_idle(int cpu)
1776{
1777 struct timer_list *tp;
1778 struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu);
1779 int tne;
1780
1781
1782 tne = ACCESS_ONCE(tick_nohz_enabled);
1783 if (tne != rdtp->tick_nohz_enabled_snap) {
1784 if (rcu_cpu_has_callbacks(cpu))
1785 invoke_rcu_core();
1786 rdtp->tick_nohz_enabled_snap = tne;
1787 return;
1788 }
1789 if (!tne)
1790 return;
1791
1792
1793 if (!is_idle_task(current)) {
1794 rdtp->dyntick_holdoff = jiffies - 1;
1795 if (rcu_cpu_has_nonlazy_callbacks(cpu)) {
1796 trace_rcu_prep_idle("User dyntick with callbacks");
1797 rdtp->idle_gp_timer_expires =
1798 round_up(jiffies + RCU_IDLE_GP_DELAY,
1799 RCU_IDLE_GP_DELAY);
1800 } else if (rcu_cpu_has_callbacks(cpu)) {
1801 rdtp->idle_gp_timer_expires =
1802 round_jiffies(jiffies + RCU_IDLE_LAZY_GP_DELAY);
1803 trace_rcu_prep_idle("User dyntick with lazy callbacks");
1804 } else {
1805 return;
1806 }
1807 tp = &rdtp->idle_gp_timer;
1808 mod_timer_pinned(tp, rdtp->idle_gp_timer_expires);
1809 return;
1810 }
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820 if (!rdtp->idle_first_pass &&
1821 (rdtp->nonlazy_posted == rdtp->nonlazy_posted_snap)) {
1822 if (rcu_cpu_has_callbacks(cpu)) {
1823 tp = &rdtp->idle_gp_timer;
1824 mod_timer_pinned(tp, rdtp->idle_gp_timer_expires);
1825 }
1826 return;
1827 }
1828 rdtp->idle_first_pass = 0;
1829 rdtp->nonlazy_posted_snap = rdtp->nonlazy_posted - 1;
1830
1831
1832
1833
1834
1835 if (!rcu_cpu_has_callbacks(cpu)) {
1836 rdtp->dyntick_holdoff = jiffies - 1;
1837 rdtp->dyntick_drain = 0;
1838 trace_rcu_prep_idle("No callbacks");
1839 return;
1840 }
1841
1842
1843
1844
1845
1846 if (rdtp->dyntick_holdoff == jiffies) {
1847 trace_rcu_prep_idle("In holdoff");
1848 return;
1849 }
1850
1851
1852 if (rdtp->dyntick_drain <= 0) {
1853
1854 rdtp->dyntick_drain = RCU_IDLE_FLUSHES;
1855 } else if (rdtp->dyntick_drain <= RCU_IDLE_OPT_FLUSHES &&
1856 !rcu_pending(cpu) &&
1857 !local_softirq_pending()) {
1858
1859 rdtp->dyntick_drain = 0;
1860 rdtp->dyntick_holdoff = jiffies;
1861 if (rcu_cpu_has_nonlazy_callbacks(cpu)) {
1862 trace_rcu_prep_idle("Dyntick with callbacks");
1863 rdtp->idle_gp_timer_expires =
1864 round_up(jiffies + RCU_IDLE_GP_DELAY,
1865 RCU_IDLE_GP_DELAY);
1866 } else {
1867 rdtp->idle_gp_timer_expires =
1868 round_jiffies(jiffies + RCU_IDLE_LAZY_GP_DELAY);
1869 trace_rcu_prep_idle("Dyntick with lazy callbacks");
1870 }
1871 tp = &rdtp->idle_gp_timer;
1872 mod_timer_pinned(tp, rdtp->idle_gp_timer_expires);
1873 rdtp->nonlazy_posted_snap = rdtp->nonlazy_posted;
1874 return;
1875 } else if (--(rdtp->dyntick_drain) <= 0) {
1876
1877 rdtp->dyntick_holdoff = jiffies;
1878 trace_rcu_prep_idle("Begin holdoff");
1879 invoke_rcu_core();
1880 return;
1881 }
1882
1883
1884
1885
1886
1887#ifdef CONFIG_TREE_PREEMPT_RCU
1888 if (per_cpu(rcu_preempt_data, cpu).nxtlist) {
1889 rcu_preempt_qs(cpu);
1890 force_quiescent_state(&rcu_preempt_state);
1891 }
1892#endif
1893 if (per_cpu(rcu_sched_data, cpu).nxtlist) {
1894 rcu_sched_qs(cpu);
1895 force_quiescent_state(&rcu_sched_state);
1896 }
1897 if (per_cpu(rcu_bh_data, cpu).nxtlist) {
1898 rcu_bh_qs(cpu);
1899 force_quiescent_state(&rcu_bh_state);
1900 }
1901
1902
1903
1904
1905
1906 if (rcu_cpu_has_callbacks(cpu)) {
1907 trace_rcu_prep_idle("More callbacks");
1908 invoke_rcu_core();
1909 } else {
1910 trace_rcu_prep_idle("Callbacks drained");
1911 }
1912}
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922static void rcu_idle_count_callbacks_posted(void)
1923{
1924 __this_cpu_add(rcu_dynticks.nonlazy_posted, 1);
1925}
1926
1927
1928
1929
1930static atomic_t oom_callback_count;
1931static DECLARE_WAIT_QUEUE_HEAD(oom_callback_wq);
1932
1933
1934
1935
1936
1937static void rcu_oom_callback(struct rcu_head *rhp)
1938{
1939 if (atomic_dec_and_test(&oom_callback_count))
1940 wake_up(&oom_callback_wq);
1941}
1942
1943
1944
1945
1946
1947
1948
1949
1950static void rcu_oom_notify_cpu(void *unused)
1951{
1952 struct rcu_state *rsp;
1953 struct rcu_data *rdp;
1954
1955 for_each_rcu_flavor(rsp) {
1956 rdp = __this_cpu_ptr(rsp->rda);
1957 if (rdp->qlen_lazy != 0) {
1958 atomic_inc(&oom_callback_count);
1959 rsp->call(&rdp->oom_head, rcu_oom_callback);
1960 }
1961 }
1962}
1963
1964
1965
1966
1967
1968
1969
1970
1971static int rcu_oom_notify(struct notifier_block *self,
1972 unsigned long notused, void *nfreed)
1973{
1974 int cpu;
1975
1976
1977 wait_event(oom_callback_wq, atomic_read(&oom_callback_count) == 0);
1978
1979
1980
1981
1982
1983 atomic_set(&oom_callback_count, 1);
1984
1985 get_online_cpus();
1986 for_each_online_cpu(cpu) {
1987 smp_call_function_single(cpu, rcu_oom_notify_cpu, NULL, 1);
1988 cond_resched();
1989 }
1990 put_online_cpus();
1991
1992
1993 atomic_dec(&oom_callback_count);
1994
1995 return NOTIFY_OK;
1996}
1997
1998static struct notifier_block rcu_oom_nb = {
1999 .notifier_call = rcu_oom_notify
2000};
2001
2002static int __init rcu_register_oom_notifier(void)
2003{
2004 register_oom_notifier(&rcu_oom_nb);
2005 return 0;
2006}
2007early_initcall(rcu_register_oom_notifier);
2008
2009#endif
2010
2011#ifdef CONFIG_RCU_CPU_STALL_INFO
2012
2013#ifdef CONFIG_RCU_FAST_NO_HZ
2014
2015static void print_cpu_stall_fast_no_hz(char *cp, int cpu)
2016{
2017 struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu);
2018 struct timer_list *tltp = &rdtp->idle_gp_timer;
2019 char c;
2020
2021 c = rdtp->dyntick_holdoff == jiffies ? 'H' : '.';
2022 if (timer_pending(tltp))
2023 sprintf(cp, "drain=%d %c timer=%lu",
2024 rdtp->dyntick_drain, c, tltp->expires - jiffies);
2025 else
2026 sprintf(cp, "drain=%d %c timer not pending",
2027 rdtp->dyntick_drain, c);
2028}
2029
2030#else
2031
2032static void print_cpu_stall_fast_no_hz(char *cp, int cpu)
2033{
2034 *cp = '\0';
2035}
2036
2037#endif
2038
2039
2040static void print_cpu_stall_info_begin(void)
2041{
2042 printk(KERN_CONT "\n");
2043}
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
2058{
2059 char fast_no_hz[72];
2060 struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
2061 struct rcu_dynticks *rdtp = rdp->dynticks;
2062 char *ticks_title;
2063 unsigned long ticks_value;
2064
2065 if (rsp->gpnum == rdp->gpnum) {
2066 ticks_title = "ticks this GP";
2067 ticks_value = rdp->ticks_this_gp;
2068 } else {
2069 ticks_title = "GPs behind";
2070 ticks_value = rsp->gpnum - rdp->gpnum;
2071 }
2072 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
2073 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
2074 cpu, ticks_value, ticks_title,
2075 atomic_read(&rdtp->dynticks) & 0xfff,
2076 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
2077 fast_no_hz);
2078}
2079
2080
2081static void print_cpu_stall_info_end(void)
2082{
2083 printk(KERN_ERR "\t");
2084}
2085
2086
2087static void zero_cpu_stall_ticks(struct rcu_data *rdp)
2088{
2089 rdp->ticks_this_gp = 0;
2090}
2091
2092
2093static void increment_cpu_stall_ticks(void)
2094{
2095 struct rcu_state *rsp;
2096
2097 for_each_rcu_flavor(rsp)
2098 __this_cpu_ptr(rsp->rda)->ticks_this_gp++;
2099}
2100
2101#else
2102
2103static void print_cpu_stall_info_begin(void)
2104{
2105 printk(KERN_CONT " {");
2106}
2107
2108static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
2109{
2110 printk(KERN_CONT " %d", cpu);
2111}
2112
2113static void print_cpu_stall_info_end(void)
2114{
2115 printk(KERN_CONT "} ");
2116}
2117
2118static void zero_cpu_stall_ticks(struct rcu_data *rdp)
2119{
2120}
2121
2122static void increment_cpu_stall_ticks(void)
2123{
2124}
2125
2126#endif
2127
2128#ifdef CONFIG_RCU_NOCB_CPU
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152static int __init rcu_nocb_setup(char *str)
2153{
2154 alloc_bootmem_cpumask_var(&rcu_nocb_mask);
2155 have_rcu_nocb_mask = true;
2156 cpulist_parse(str, rcu_nocb_mask);
2157 return 1;
2158}
2159__setup("rcu_nocbs=", rcu_nocb_setup);
2160
2161static int __init parse_rcu_nocb_poll(char *arg)
2162{
2163 rcu_nocb_poll = 1;
2164 return 0;
2165}
2166early_param("rcu_nocb_poll", parse_rcu_nocb_poll);
2167
2168
2169static bool is_nocb_cpu(int cpu)
2170{
2171 if (have_rcu_nocb_mask)
2172 return cpumask_test_cpu(cpu, rcu_nocb_mask);
2173 return false;
2174}
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
2185 struct rcu_head *rhp,
2186 struct rcu_head **rhtp,
2187 int rhcount, int rhcount_lazy)
2188{
2189 int len;
2190 struct rcu_head **old_rhpp;
2191 struct task_struct *t;
2192
2193
2194 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
2195 ACCESS_ONCE(*old_rhpp) = rhp;
2196 atomic_long_add(rhcount, &rdp->nocb_q_count);
2197 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
2198
2199
2200 t = ACCESS_ONCE(rdp->nocb_kthread);
2201 if (rcu_nocb_poll | !t)
2202 return;
2203 len = atomic_long_read(&rdp->nocb_q_count);
2204 if (old_rhpp == &rdp->nocb_head) {
2205 wake_up(&rdp->nocb_wq);
2206 rdp->qlen_last_fqs_check = 0;
2207 } else if (len > rdp->qlen_last_fqs_check + qhimark) {
2208 wake_up_process(t);
2209 rdp->qlen_last_fqs_check = LONG_MAX / 2;
2210 }
2211 return;
2212}
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223static bool __call_rcu_nocb(struct rcu_data *rdp, struct rcu_head *rhp,
2224 bool lazy)
2225{
2226
2227 if (!is_nocb_cpu(rdp->cpu))
2228 return 0;
2229 __call_rcu_nocb_enqueue(rdp, rhp, &rhp->next, 1, lazy);
2230 return 1;
2231}
2232
2233
2234
2235
2236
2237static bool __maybe_unused rcu_nocb_adopt_orphan_cbs(struct rcu_state *rsp,
2238 struct rcu_data *rdp)
2239{
2240 long ql = rsp->qlen;
2241 long qll = rsp->qlen_lazy;
2242
2243
2244 if (!is_nocb_cpu(smp_processor_id()))
2245 return 0;
2246 rsp->qlen = 0;
2247 rsp->qlen_lazy = 0;
2248
2249
2250 if (rsp->orphan_donelist != NULL) {
2251 __call_rcu_nocb_enqueue(rdp, rsp->orphan_donelist,
2252 rsp->orphan_donetail, ql, qll);
2253 ql = qll = 0;
2254 rsp->orphan_donelist = NULL;
2255 rsp->orphan_donetail = &rsp->orphan_donelist;
2256 }
2257 if (rsp->orphan_nxtlist != NULL) {
2258 __call_rcu_nocb_enqueue(rdp, rsp->orphan_nxtlist,
2259 rsp->orphan_nxttail, ql, qll);
2260 ql = qll = 0;
2261 rsp->orphan_nxtlist = NULL;
2262 rsp->orphan_nxttail = &rsp->orphan_nxtlist;
2263 }
2264 return 1;
2265}
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275static bool nocb_cpu_expendable(int cpu)
2276{
2277 cpumask_var_t non_nocb_cpus;
2278 int ret;
2279
2280
2281
2282
2283
2284 if (!have_rcu_nocb_mask || is_nocb_cpu(cpu))
2285 return 1;
2286
2287
2288 if (!alloc_cpumask_var(&non_nocb_cpus, GFP_NOIO))
2289 return 0;
2290 cpumask_andnot(non_nocb_cpus, cpu_online_mask, rcu_nocb_mask);
2291 cpumask_clear_cpu(cpu, non_nocb_cpus);
2292 ret = !cpumask_empty(non_nocb_cpus);
2293 free_cpumask_var(non_nocb_cpus);
2294 return ret;
2295}
2296
2297
2298
2299
2300
2301
2302
2303struct rcu_head_remote {
2304 struct rcu_head *rhp;
2305 call_rcu_func_t *crf;
2306 void (*func)(struct rcu_head *rhp);
2307};
2308
2309
2310
2311
2312
2313static void call_rcu_local(void *arg)
2314{
2315 struct rcu_head_remote *rhrp =
2316 container_of(arg, struct rcu_head_remote, rhp);
2317
2318 rhrp->crf(rhrp->rhp, rhrp->func);
2319}
2320
2321
2322
2323
2324
2325
2326static void invoke_crf_remote(struct rcu_head *rhp,
2327 void (*func)(struct rcu_head *rhp),
2328 call_rcu_func_t crf)
2329{
2330 struct rcu_head_remote rhr;
2331
2332 rhr.rhp = rhp;
2333 rhr.crf = crf;
2334 rhr.func = func;
2335 smp_call_function_single(0, call_rcu_local, &rhr, 1);
2336}
2337
2338
2339
2340
2341
2342static void __maybe_unused
2343call_rcu_preempt_remote(struct rcu_head *rhp,
2344 void (*func)(struct rcu_head *rhp))
2345{
2346 invoke_crf_remote(rhp, func, call_rcu);
2347}
2348static void call_rcu_bh_remote(struct rcu_head *rhp,
2349 void (*func)(struct rcu_head *rhp))
2350{
2351 invoke_crf_remote(rhp, func, call_rcu_bh);
2352}
2353static void call_rcu_sched_remote(struct rcu_head *rhp,
2354 void (*func)(struct rcu_head *rhp))
2355{
2356 invoke_crf_remote(rhp, func, call_rcu_sched);
2357}
2358
2359
2360
2361
2362
2363static int rcu_nocb_kthread(void *arg)
2364{
2365 int c, cl;
2366 struct rcu_head *list;
2367 struct rcu_head *next;
2368 struct rcu_head **tail;
2369 struct rcu_data *rdp = arg;
2370
2371
2372 for (;;) {
2373
2374 if (!rcu_nocb_poll)
2375 wait_event_interruptible(rdp->nocb_wq, rdp->nocb_head);
2376 list = ACCESS_ONCE(rdp->nocb_head);
2377 if (!list) {
2378 schedule_timeout_interruptible(1);
2379 flush_signals(current);
2380 continue;
2381 }
2382
2383
2384
2385
2386
2387 ACCESS_ONCE(rdp->nocb_head) = NULL;
2388 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
2389 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
2390 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
2391 ACCESS_ONCE(rdp->nocb_p_count) += c;
2392 ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
2393 wait_rcu_gp(rdp->rsp->call_remote);
2394
2395
2396 trace_rcu_batch_start(rdp->rsp->name, cl, c, -1);
2397 c = cl = 0;
2398 while (list) {
2399 next = list->next;
2400
2401 while (next == NULL && &list->next != tail) {
2402 schedule_timeout_interruptible(1);
2403 next = list->next;
2404 }
2405 debug_rcu_head_unqueue(list);
2406 local_bh_disable();
2407 if (__rcu_reclaim(rdp->rsp->name, list))
2408 cl++;
2409 c++;
2410 local_bh_enable();
2411 list = next;
2412 }
2413 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
2414 ACCESS_ONCE(rdp->nocb_p_count) -= c;
2415 ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
2416 rdp->n_nocbs_invoked += c;
2417 }
2418 return 0;
2419}
2420
2421
2422static void __init rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp)
2423{
2424 rdp->nocb_tail = &rdp->nocb_head;
2425 init_waitqueue_head(&rdp->nocb_wq);
2426}
2427
2428
2429static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
2430{
2431 int cpu;
2432 struct rcu_data *rdp;
2433 struct task_struct *t;
2434
2435 if (rcu_nocb_mask == NULL)
2436 return;
2437 for_each_cpu(cpu, rcu_nocb_mask) {
2438 rdp = per_cpu_ptr(rsp->rda, cpu);
2439 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
2440 BUG_ON(IS_ERR(t));
2441 ACCESS_ONCE(rdp->nocb_kthread) = t;
2442 }
2443}
2444
2445
2446static void init_nocb_callback_list(struct rcu_data *rdp)
2447{
2448 if (rcu_nocb_mask == NULL ||
2449 !cpumask_test_cpu(rdp->cpu, rcu_nocb_mask))
2450 return;
2451 rdp->nxttail[RCU_NEXT_TAIL] = NULL;
2452}
2453
2454
2455static void __init rcu_init_nocb(void)
2456{
2457#ifdef CONFIG_PREEMPT_RCU
2458 rcu_preempt_state.call_remote = call_rcu_preempt_remote;
2459#endif
2460 rcu_bh_state.call_remote = call_rcu_bh_remote;
2461 rcu_sched_state.call_remote = call_rcu_sched_remote;
2462}
2463
2464#else
2465
2466static bool is_nocb_cpu(int cpu)
2467{
2468 return false;
2469}
2470
2471static bool __call_rcu_nocb(struct rcu_data *rdp, struct rcu_head *rhp,
2472 bool lazy)
2473{
2474 return 0;
2475}
2476
2477static bool __maybe_unused rcu_nocb_adopt_orphan_cbs(struct rcu_state *rsp,
2478 struct rcu_data *rdp)
2479{
2480 return 0;
2481}
2482
2483static bool nocb_cpu_expendable(int cpu)
2484{
2485 return 1;
2486}
2487
2488static void __init rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp)
2489{
2490}
2491
2492static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
2493{
2494}
2495
2496static void init_nocb_callback_list(struct rcu_data *rdp)
2497{
2498}
2499
2500static void __init rcu_init_nocb(void)
2501{
2502}
2503
2504#endif
2505