aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/rcu
diff options
context:
space:
mode:
Diffstat (limited to 'kernel/rcu')
-rw-r--r--kernel/rcu/rcutorture.c213
-rw-r--r--kernel/rcu/tiny.c8
-rw-r--r--kernel/rcu/tree.c46
-rw-r--r--kernel/rcu/tree.h16
-rw-r--r--kernel/rcu/tree_plugin.h316
-rw-r--r--kernel/rcu/update.c32
6 files changed, 440 insertions, 191 deletions
diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
index 948a7693748e..0bcd53adac73 100644
--- a/kernel/rcu/rcutorture.c
+++ b/kernel/rcu/rcutorture.c
@@ -49,11 +49,19 @@
49#include <linux/trace_clock.h> 49#include <linux/trace_clock.h>
50#include <asm/byteorder.h> 50#include <asm/byteorder.h>
51#include <linux/torture.h> 51#include <linux/torture.h>
52#include <linux/vmalloc.h>
52 53
53MODULE_LICENSE("GPL"); 54MODULE_LICENSE("GPL");
54MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and Josh Triplett <josh@joshtriplett.org>"); 55MODULE_AUTHOR("Paul E. McKenney <paulmck@us.ibm.com> and Josh Triplett <josh@joshtriplett.org>");
55 56
56 57
58torture_param(int, cbflood_inter_holdoff, HZ,
59 "Holdoff between floods (jiffies)");
60torture_param(int, cbflood_intra_holdoff, 1,
61 "Holdoff between bursts (jiffies)");
62torture_param(int, cbflood_n_burst, 3, "# bursts in flood, zero to disable");
63torture_param(int, cbflood_n_per_burst, 20000,
64 "# callbacks per burst in flood");
57torture_param(int, fqs_duration, 0, 65torture_param(int, fqs_duration, 0,
58 "Duration of fqs bursts (us), 0 to disable"); 66 "Duration of fqs bursts (us), 0 to disable");
59torture_param(int, fqs_holdoff, 0, "Holdoff time within fqs bursts (us)"); 67torture_param(int, fqs_holdoff, 0, "Holdoff time within fqs bursts (us)");
@@ -96,10 +104,12 @@ module_param(torture_type, charp, 0444);
96MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, ...)"); 104MODULE_PARM_DESC(torture_type, "Type of RCU to torture (rcu, rcu_bh, ...)");
97 105
98static int nrealreaders; 106static int nrealreaders;
107static int ncbflooders;
99static struct task_struct *writer_task; 108static struct task_struct *writer_task;
100static struct task_struct **fakewriter_tasks; 109static struct task_struct **fakewriter_tasks;
101static struct task_struct **reader_tasks; 110static struct task_struct **reader_tasks;
102static struct task_struct *stats_task; 111static struct task_struct *stats_task;
112static struct task_struct **cbflood_task;
103static struct task_struct *fqs_task; 113static struct task_struct *fqs_task;
104static struct task_struct *boost_tasks[NR_CPUS]; 114static struct task_struct *boost_tasks[NR_CPUS];
105static struct task_struct *stall_task; 115static struct task_struct *stall_task;
@@ -138,6 +148,7 @@ static long n_rcu_torture_boosts;
138static long n_rcu_torture_timers; 148static long n_rcu_torture_timers;
139static long n_barrier_attempts; 149static long n_barrier_attempts;
140static long n_barrier_successes; 150static long n_barrier_successes;
151static atomic_long_t n_cbfloods;
141static struct list_head rcu_torture_removed; 152static struct list_head rcu_torture_removed;
142 153
143static int rcu_torture_writer_state; 154static int rcu_torture_writer_state;
@@ -182,7 +193,7 @@ static u64 notrace rcu_trace_clock_local(void)
182#endif /* #else #ifdef CONFIG_RCU_TRACE */ 193#endif /* #else #ifdef CONFIG_RCU_TRACE */
183 194
184static unsigned long boost_starttime; /* jiffies of next boost test start. */ 195static unsigned long boost_starttime; /* jiffies of next boost test start. */
185DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */ 196static DEFINE_MUTEX(boost_mutex); /* protect setting boost_starttime */
186 /* and boost task create/destroy. */ 197 /* and boost task create/destroy. */
187static atomic_t barrier_cbs_count; /* Barrier callbacks registered. */ 198static atomic_t barrier_cbs_count; /* Barrier callbacks registered. */
188static bool barrier_phase; /* Test phase. */ 199static bool barrier_phase; /* Test phase. */
@@ -242,7 +253,7 @@ struct rcu_torture_ops {
242 void (*call)(struct rcu_head *head, void (*func)(struct rcu_head *rcu)); 253 void (*call)(struct rcu_head *head, void (*func)(struct rcu_head *rcu));
243 void (*cb_barrier)(void); 254 void (*cb_barrier)(void);
244 void (*fqs)(void); 255 void (*fqs)(void);
245 void (*stats)(char *page); 256 void (*stats)(void);
246 int irq_capable; 257 int irq_capable;
247 int can_boost; 258 int can_boost;
248 const char *name; 259 const char *name;
@@ -525,21 +536,21 @@ static void srcu_torture_barrier(void)
525 srcu_barrier(&srcu_ctl); 536 srcu_barrier(&srcu_ctl);
526} 537}
527 538
528static void srcu_torture_stats(char *page) 539static void srcu_torture_stats(void)
529{ 540{
530 int cpu; 541 int cpu;
531 int idx = srcu_ctl.completed & 0x1; 542 int idx = srcu_ctl.completed & 0x1;
532 543
533 page += sprintf(page, "%s%s per-CPU(idx=%d):", 544 pr_alert("%s%s per-CPU(idx=%d):",
534 torture_type, TORTURE_FLAG, idx); 545 torture_type, TORTURE_FLAG, idx);
535 for_each_possible_cpu(cpu) { 546 for_each_possible_cpu(cpu) {
536 long c0, c1; 547 long c0, c1;
537 548
538 c0 = (long)per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx]; 549 c0 = (long)per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[!idx];
539 c1 = (long)per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx]; 550 c1 = (long)per_cpu_ptr(srcu_ctl.per_cpu_ref, cpu)->c[idx];
540 page += sprintf(page, " %d(%ld,%ld)", cpu, c0, c1); 551 pr_cont(" %d(%ld,%ld)", cpu, c0, c1);
541 } 552 }
542 sprintf(page, "\n"); 553 pr_cont("\n");
543} 554}
544 555
545static void srcu_torture_synchronize_expedited(void) 556static void srcu_torture_synchronize_expedited(void)
@@ -707,6 +718,58 @@ checkwait: stutter_wait("rcu_torture_boost");
707 return 0; 718 return 0;
708} 719}
709 720
721static void rcu_torture_cbflood_cb(struct rcu_head *rhp)
722{
723}
724
725/*
726 * RCU torture callback-flood kthread. Repeatedly induces bursts of calls
727 * to call_rcu() or analogous, increasing the probability of occurrence
728 * of callback-overflow corner cases.
729 */
730static int
731rcu_torture_cbflood(void *arg)
732{
733 int err = 1;
734 int i;
735 int j;
736 struct rcu_head *rhp;
737
738 if (cbflood_n_per_burst > 0 &&
739 cbflood_inter_holdoff > 0 &&
740 cbflood_intra_holdoff > 0 &&
741 cur_ops->call &&
742 cur_ops->cb_barrier) {
743 rhp = vmalloc(sizeof(*rhp) *
744 cbflood_n_burst * cbflood_n_per_burst);
745 err = !rhp;
746 }
747 if (err) {
748 VERBOSE_TOROUT_STRING("rcu_torture_cbflood disabled: Bad args or OOM");
749 while (!torture_must_stop())
750 schedule_timeout_interruptible(HZ);
751 return 0;
752 }
753 VERBOSE_TOROUT_STRING("rcu_torture_cbflood task started");
754 do {
755 schedule_timeout_interruptible(cbflood_inter_holdoff);
756 atomic_long_inc(&n_cbfloods);
757 WARN_ON(signal_pending(current));
758 for (i = 0; i < cbflood_n_burst; i++) {
759 for (j = 0; j < cbflood_n_per_burst; j++) {
760 cur_ops->call(&rhp[i * cbflood_n_per_burst + j],
761 rcu_torture_cbflood_cb);
762 }
763 schedule_timeout_interruptible(cbflood_intra_holdoff);
764 WARN_ON(signal_pending(current));
765 }
766 cur_ops->cb_barrier();
767 stutter_wait("rcu_torture_cbflood");
768 } while (!torture_must_stop());
769 torture_kthread_stopping("rcu_torture_cbflood");
770 return 0;
771}
772
710/* 773/*
711 * RCU torture force-quiescent-state kthread. Repeatedly induces 774 * RCU torture force-quiescent-state kthread. Repeatedly induces
712 * bursts of calls to force_quiescent_state(), increasing the probability 775 * bursts of calls to force_quiescent_state(), increasing the probability
@@ -1031,10 +1094,15 @@ rcu_torture_reader(void *arg)
1031} 1094}
1032 1095
1033/* 1096/*
1034 * Create an RCU-torture statistics message in the specified buffer. 1097 * Print torture statistics. Caller must ensure that there is only
1098 * one call to this function at a given time!!! This is normally
1099 * accomplished by relying on the module system to only have one copy
1100 * of the module loaded, and then by giving the rcu_torture_stats
1101 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1102 * thread is not running).
1035 */ 1103 */
1036static void 1104static void
1037rcu_torture_printk(char *page) 1105rcu_torture_stats_print(void)
1038{ 1106{
1039 int cpu; 1107 int cpu;
1040 int i; 1108 int i;
@@ -1052,55 +1120,61 @@ rcu_torture_printk(char *page)
1052 if (pipesummary[i] != 0) 1120 if (pipesummary[i] != 0)
1053 break; 1121 break;
1054 } 1122 }
1055 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG); 1123
1056 page += sprintf(page, 1124 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
1057 "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ", 1125 pr_cont("rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
1058 rcu_torture_current, 1126 rcu_torture_current,
1059 rcu_torture_current_version, 1127 rcu_torture_current_version,
1060 list_empty(&rcu_torture_freelist), 1128 list_empty(&rcu_torture_freelist),
1061 atomic_read(&n_rcu_torture_alloc), 1129 atomic_read(&n_rcu_torture_alloc),
1062 atomic_read(&n_rcu_torture_alloc_fail), 1130 atomic_read(&n_rcu_torture_alloc_fail),
1063 atomic_read(&n_rcu_torture_free)); 1131 atomic_read(&n_rcu_torture_free));
1064 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ", 1132 pr_cont("rtmbe: %d rtbke: %ld rtbre: %ld ",
1065 atomic_read(&n_rcu_torture_mberror), 1133 atomic_read(&n_rcu_torture_mberror),
1066 n_rcu_torture_boost_ktrerror, 1134 n_rcu_torture_boost_ktrerror,
1067 n_rcu_torture_boost_rterror); 1135 n_rcu_torture_boost_rterror);
1068 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ", 1136 pr_cont("rtbf: %ld rtb: %ld nt: %ld ",
1069 n_rcu_torture_boost_failure, 1137 n_rcu_torture_boost_failure,
1070 n_rcu_torture_boosts, 1138 n_rcu_torture_boosts,
1071 n_rcu_torture_timers); 1139 n_rcu_torture_timers);
1072 page = torture_onoff_stats(page); 1140 torture_onoff_stats();
1073 page += sprintf(page, "barrier: %ld/%ld:%ld", 1141 pr_cont("barrier: %ld/%ld:%ld ",
1074 n_barrier_successes, 1142 n_barrier_successes,
1075 n_barrier_attempts, 1143 n_barrier_attempts,
1076 n_rcu_torture_barrier_error); 1144 n_rcu_torture_barrier_error);
1077 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG); 1145 pr_cont("cbflood: %ld\n", atomic_long_read(&n_cbfloods));
1146
1147 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
1078 if (atomic_read(&n_rcu_torture_mberror) != 0 || 1148 if (atomic_read(&n_rcu_torture_mberror) != 0 ||
1079 n_rcu_torture_barrier_error != 0 || 1149 n_rcu_torture_barrier_error != 0 ||
1080 n_rcu_torture_boost_ktrerror != 0 || 1150 n_rcu_torture_boost_ktrerror != 0 ||
1081 n_rcu_torture_boost_rterror != 0 || 1151 n_rcu_torture_boost_rterror != 0 ||
1082 n_rcu_torture_boost_failure != 0 || 1152 n_rcu_torture_boost_failure != 0 ||
1083 i > 1) { 1153 i > 1) {
1084 page += sprintf(page, "!!! "); 1154 pr_cont("%s", "!!! ");
1085 atomic_inc(&n_rcu_torture_error); 1155 atomic_inc(&n_rcu_torture_error);
1086 WARN_ON_ONCE(1); 1156 WARN_ON_ONCE(1);
1087 } 1157 }
1088 page += sprintf(page, "Reader Pipe: "); 1158 pr_cont("Reader Pipe: ");
1089 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) 1159 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1090 page += sprintf(page, " %ld", pipesummary[i]); 1160 pr_cont(" %ld", pipesummary[i]);
1091 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG); 1161 pr_cont("\n");
1092 page += sprintf(page, "Reader Batch: "); 1162
1163 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
1164 pr_cont("Reader Batch: ");
1093 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) 1165 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
1094 page += sprintf(page, " %ld", batchsummary[i]); 1166 pr_cont(" %ld", batchsummary[i]);
1095 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG); 1167 pr_cont("\n");
1096 page += sprintf(page, "Free-Block Circulation: "); 1168
1169 pr_alert("%s%s ", torture_type, TORTURE_FLAG);
1170 pr_cont("Free-Block Circulation: ");
1097 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) { 1171 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
1098 page += sprintf(page, " %d", 1172 pr_cont(" %d", atomic_read(&rcu_torture_wcount[i]));
1099 atomic_read(&rcu_torture_wcount[i]));
1100 } 1173 }
1101 page += sprintf(page, "\n"); 1174 pr_cont("\n");
1175
1102 if (cur_ops->stats) 1176 if (cur_ops->stats)
1103 cur_ops->stats(page); 1177 cur_ops->stats();
1104 if (rtcv_snap == rcu_torture_current_version && 1178 if (rtcv_snap == rcu_torture_current_version &&
1105 rcu_torture_current != NULL) { 1179 rcu_torture_current != NULL) {
1106 int __maybe_unused flags; 1180 int __maybe_unused flags;
@@ -1109,10 +1183,9 @@ rcu_torture_printk(char *page)
1109 1183
1110 rcutorture_get_gp_data(cur_ops->ttype, 1184 rcutorture_get_gp_data(cur_ops->ttype,
1111 &flags, &gpnum, &completed); 1185 &flags, &gpnum, &completed);
1112 page += sprintf(page, 1186 pr_alert("??? Writer stall state %d g%lu c%lu f%#x\n",
1113 "??? Writer stall state %d g%lu c%lu f%#x\n", 1187 rcu_torture_writer_state,
1114 rcu_torture_writer_state, 1188 gpnum, completed, flags);
1115 gpnum, completed, flags);
1116 show_rcu_gp_kthreads(); 1189 show_rcu_gp_kthreads();
1117 rcutorture_trace_dump(); 1190 rcutorture_trace_dump();
1118 } 1191 }
@@ -1120,30 +1193,6 @@ rcu_torture_printk(char *page)
1120} 1193}
1121 1194
1122/* 1195/*
1123 * Print torture statistics. Caller must ensure that there is only
1124 * one call to this function at a given time!!! This is normally
1125 * accomplished by relying on the module system to only have one copy
1126 * of the module loaded, and then by giving the rcu_torture_stats
1127 * kthread full control (or the init/cleanup functions when rcu_torture_stats
1128 * thread is not running).
1129 */
1130static void
1131rcu_torture_stats_print(void)
1132{
1133 int size = nr_cpu_ids * 200 + 8192;
1134 char *buf;
1135
1136 buf = kmalloc(size, GFP_KERNEL);
1137 if (!buf) {
1138 pr_err("rcu-torture: Out of memory, need: %d", size);
1139 return;
1140 }
1141 rcu_torture_printk(buf);
1142 pr_alert("%s", buf);
1143 kfree(buf);
1144}
1145
1146/*
1147 * Periodically prints torture statistics, if periodic statistics printing 1196 * Periodically prints torture statistics, if periodic statistics printing
1148 * was specified via the stat_interval module parameter. 1197 * was specified via the stat_interval module parameter.
1149 */ 1198 */
@@ -1447,6 +1496,8 @@ rcu_torture_cleanup(void)
1447 1496
1448 torture_stop_kthread(rcu_torture_stats, stats_task); 1497 torture_stop_kthread(rcu_torture_stats, stats_task);
1449 torture_stop_kthread(rcu_torture_fqs, fqs_task); 1498 torture_stop_kthread(rcu_torture_fqs, fqs_task);
1499 for (i = 0; i < ncbflooders; i++)
1500 torture_stop_kthread(rcu_torture_cbflood, cbflood_task[i]);
1450 if ((test_boost == 1 && cur_ops->can_boost) || 1501 if ((test_boost == 1 && cur_ops->can_boost) ||
1451 test_boost == 2) { 1502 test_boost == 2) {
1452 unregister_cpu_notifier(&rcutorture_cpu_nb); 1503 unregister_cpu_notifier(&rcutorture_cpu_nb);
@@ -1693,6 +1744,24 @@ rcu_torture_init(void)
1693 goto unwind; 1744 goto unwind;
1694 if (object_debug) 1745 if (object_debug)
1695 rcu_test_debug_objects(); 1746 rcu_test_debug_objects();
1747 if (cbflood_n_burst > 0) {
1748 /* Create the cbflood threads */
1749 ncbflooders = (num_online_cpus() + 3) / 4;
1750 cbflood_task = kcalloc(ncbflooders, sizeof(*cbflood_task),
1751 GFP_KERNEL);
1752 if (!cbflood_task) {
1753 VERBOSE_TOROUT_ERRSTRING("out of memory");
1754 firsterr = -ENOMEM;
1755 goto unwind;
1756 }
1757 for (i = 0; i < ncbflooders; i++) {
1758 firsterr = torture_create_kthread(rcu_torture_cbflood,
1759 NULL,
1760 cbflood_task[i]);
1761 if (firsterr)
1762 goto unwind;
1763 }
1764 }
1696 rcutorture_record_test_transition(); 1765 rcutorture_record_test_transition();
1697 torture_init_end(); 1766 torture_init_end();
1698 return 0; 1767 return 0;
diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
index d9efcc13008c..4a55a2416e3c 100644
--- a/kernel/rcu/tiny.c
+++ b/kernel/rcu/tiny.c
@@ -51,7 +51,7 @@ static long long rcu_dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
51 51
52#include "tiny_plugin.h" 52#include "tiny_plugin.h"
53 53
54/* Common code for rcu_idle_enter() and rcu_irq_exit(), see kernel/rcutree.c. */ 54/* Common code for rcu_idle_enter() and rcu_irq_exit(), see kernel/rcu/tree.c. */
55static void rcu_idle_enter_common(long long newval) 55static void rcu_idle_enter_common(long long newval)
56{ 56{
57 if (newval) { 57 if (newval) {
@@ -62,7 +62,7 @@ static void rcu_idle_enter_common(long long newval)
62 } 62 }
63 RCU_TRACE(trace_rcu_dyntick(TPS("Start"), 63 RCU_TRACE(trace_rcu_dyntick(TPS("Start"),
64 rcu_dynticks_nesting, newval)); 64 rcu_dynticks_nesting, newval));
65 if (!is_idle_task(current)) { 65 if (IS_ENABLED(CONFIG_RCU_TRACE) && !is_idle_task(current)) {
66 struct task_struct *idle __maybe_unused = idle_task(smp_processor_id()); 66 struct task_struct *idle __maybe_unused = idle_task(smp_processor_id());
67 67
68 RCU_TRACE(trace_rcu_dyntick(TPS("Entry error: not idle task"), 68 RCU_TRACE(trace_rcu_dyntick(TPS("Entry error: not idle task"),
@@ -114,7 +114,7 @@ void rcu_irq_exit(void)
114} 114}
115EXPORT_SYMBOL_GPL(rcu_irq_exit); 115EXPORT_SYMBOL_GPL(rcu_irq_exit);
116 116
117/* Common code for rcu_idle_exit() and rcu_irq_enter(), see kernel/rcutree.c. */ 117/* Common code for rcu_idle_exit() and rcu_irq_enter(), see kernel/rcu/tree.c. */
118static void rcu_idle_exit_common(long long oldval) 118static void rcu_idle_exit_common(long long oldval)
119{ 119{
120 if (oldval) { 120 if (oldval) {
@@ -123,7 +123,7 @@ static void rcu_idle_exit_common(long long oldval)
123 return; 123 return;
124 } 124 }
125 RCU_TRACE(trace_rcu_dyntick(TPS("End"), oldval, rcu_dynticks_nesting)); 125 RCU_TRACE(trace_rcu_dyntick(TPS("End"), oldval, rcu_dynticks_nesting));
126 if (!is_idle_task(current)) { 126 if (IS_ENABLED(CONFIG_RCU_TRACE) && !is_idle_task(current)) {
127 struct task_struct *idle __maybe_unused = idle_task(smp_processor_id()); 127 struct task_struct *idle __maybe_unused = idle_task(smp_processor_id());
128 128
129 RCU_TRACE(trace_rcu_dyntick(TPS("Exit error: not idle task"), 129 RCU_TRACE(trace_rcu_dyntick(TPS("Exit error: not idle task"),
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 1b70cb6fbe3c..be0d0a1b7129 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -79,9 +79,18 @@ static struct lock_class_key rcu_fqs_class[RCU_NUM_LVLS];
79 * the tracing userspace tools to be able to decipher the string 79 * the tracing userspace tools to be able to decipher the string
80 * address to the matching string. 80 * address to the matching string.
81 */ 81 */
82#define RCU_STATE_INITIALIZER(sname, sabbr, cr) \ 82#ifdef CONFIG_TRACING
83# define DEFINE_RCU_TPS(sname) \
83static char sname##_varname[] = #sname; \ 84static char sname##_varname[] = #sname; \
84static const char *tp_##sname##_varname __used __tracepoint_string = sname##_varname; \ 85static const char *tp_##sname##_varname __used __tracepoint_string = sname##_varname;
86# define RCU_STATE_NAME(sname) sname##_varname
87#else
88# define DEFINE_RCU_TPS(sname)
89# define RCU_STATE_NAME(sname) __stringify(sname)
90#endif
91
92#define RCU_STATE_INITIALIZER(sname, sabbr, cr) \
93DEFINE_RCU_TPS(sname) \
85struct rcu_state sname##_state = { \ 94struct rcu_state sname##_state = { \
86 .level = { &sname##_state.node[0] }, \ 95 .level = { &sname##_state.node[0] }, \
87 .call = cr, \ 96 .call = cr, \
@@ -93,7 +102,7 @@ struct rcu_state sname##_state = { \
93 .orphan_donetail = &sname##_state.orphan_donelist, \ 102 .orphan_donetail = &sname##_state.orphan_donelist, \
94 .barrier_mutex = __MUTEX_INITIALIZER(sname##_state.barrier_mutex), \ 103 .barrier_mutex = __MUTEX_INITIALIZER(sname##_state.barrier_mutex), \
95 .onoff_mutex = __MUTEX_INITIALIZER(sname##_state.onoff_mutex), \ 104 .onoff_mutex = __MUTEX_INITIALIZER(sname##_state.onoff_mutex), \
96 .name = sname##_varname, \ 105 .name = RCU_STATE_NAME(sname), \
97 .abbr = sabbr, \ 106 .abbr = sabbr, \
98}; \ 107}; \
99DEFINE_PER_CPU(struct rcu_data, sname##_data) 108DEFINE_PER_CPU(struct rcu_data, sname##_data)
@@ -819,7 +828,7 @@ bool notrace __rcu_is_watching(void)
819 */ 828 */
820bool notrace rcu_is_watching(void) 829bool notrace rcu_is_watching(void)
821{ 830{
822 int ret; 831 bool ret;
823 832
824 preempt_disable(); 833 preempt_disable();
825 ret = __rcu_is_watching(); 834 ret = __rcu_is_watching();
@@ -1668,7 +1677,7 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
1668 if (fqs_state == RCU_SAVE_DYNTICK) { 1677 if (fqs_state == RCU_SAVE_DYNTICK) {
1669 /* Collect dyntick-idle snapshots. */ 1678 /* Collect dyntick-idle snapshots. */
1670 if (is_sysidle_rcu_state(rsp)) { 1679 if (is_sysidle_rcu_state(rsp)) {
1671 isidle = 1; 1680 isidle = true;
1672 maxj = jiffies - ULONG_MAX / 4; 1681 maxj = jiffies - ULONG_MAX / 4;
1673 } 1682 }
1674 force_qs_rnp(rsp, dyntick_save_progress_counter, 1683 force_qs_rnp(rsp, dyntick_save_progress_counter,
@@ -1677,14 +1686,15 @@ static int rcu_gp_fqs(struct rcu_state *rsp, int fqs_state_in)
1677 fqs_state = RCU_FORCE_QS; 1686 fqs_state = RCU_FORCE_QS;
1678 } else { 1687 } else {
1679 /* Handle dyntick-idle and offline CPUs. */ 1688 /* Handle dyntick-idle and offline CPUs. */
1680 isidle = 0; 1689 isidle = false;
1681 force_qs_rnp(rsp, rcu_implicit_dynticks_qs, &isidle, &maxj); 1690 force_qs_rnp(rsp, rcu_implicit_dynticks_qs, &isidle, &maxj);
1682 } 1691 }
1683 /* Clear flag to prevent immediate re-entry. */ 1692 /* Clear flag to prevent immediate re-entry. */
1684 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) { 1693 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
1685 raw_spin_lock_irq(&rnp->lock); 1694 raw_spin_lock_irq(&rnp->lock);
1686 smp_mb__after_unlock_lock(); 1695 smp_mb__after_unlock_lock();
1687 ACCESS_ONCE(rsp->gp_flags) &= ~RCU_GP_FLAG_FQS; 1696 ACCESS_ONCE(rsp->gp_flags) =
1697 ACCESS_ONCE(rsp->gp_flags) & ~RCU_GP_FLAG_FQS;
1688 raw_spin_unlock_irq(&rnp->lock); 1698 raw_spin_unlock_irq(&rnp->lock);
1689 } 1699 }
1690 return fqs_state; 1700 return fqs_state;
@@ -1786,7 +1796,7 @@ static int __noreturn rcu_gp_kthread(void *arg)
1786 if (rcu_gp_init(rsp)) 1796 if (rcu_gp_init(rsp))
1787 break; 1797 break;
1788 cond_resched(); 1798 cond_resched();
1789 flush_signals(current); 1799 WARN_ON(signal_pending(current));
1790 trace_rcu_grace_period(rsp->name, 1800 trace_rcu_grace_period(rsp->name,
1791 ACCESS_ONCE(rsp->gpnum), 1801 ACCESS_ONCE(rsp->gpnum),
1792 TPS("reqwaitsig")); 1802 TPS("reqwaitsig"));
@@ -1832,7 +1842,7 @@ static int __noreturn rcu_gp_kthread(void *arg)
1832 } else { 1842 } else {
1833 /* Deal with stray signal. */ 1843 /* Deal with stray signal. */
1834 cond_resched(); 1844 cond_resched();
1835 flush_signals(current); 1845 WARN_ON(signal_pending(current));
1836 trace_rcu_grace_period(rsp->name, 1846 trace_rcu_grace_period(rsp->name,
1837 ACCESS_ONCE(rsp->gpnum), 1847 ACCESS_ONCE(rsp->gpnum),
1838 TPS("fqswaitsig")); 1848 TPS("fqswaitsig"));
@@ -1928,7 +1938,7 @@ static void rcu_report_qs_rsp(struct rcu_state *rsp, unsigned long flags)
1928{ 1938{
1929 WARN_ON_ONCE(!rcu_gp_in_progress(rsp)); 1939 WARN_ON_ONCE(!rcu_gp_in_progress(rsp));
1930 raw_spin_unlock_irqrestore(&rcu_get_root(rsp)->lock, flags); 1940 raw_spin_unlock_irqrestore(&rcu_get_root(rsp)->lock, flags);
1931 wake_up(&rsp->gp_wq); /* Memory barrier implied by wake_up() path. */ 1941 rcu_gp_kthread_wake(rsp);
1932} 1942}
1933 1943
1934/* 1944/*
@@ -2210,8 +2220,6 @@ static void rcu_cleanup_dead_cpu(int cpu, struct rcu_state *rsp)
2210 /* Adjust any no-longer-needed kthreads. */ 2220 /* Adjust any no-longer-needed kthreads. */
2211 rcu_boost_kthread_setaffinity(rnp, -1); 2221 rcu_boost_kthread_setaffinity(rnp, -1);
2212 2222
2213 /* Remove the dead CPU from the bitmasks in the rcu_node hierarchy. */
2214
2215 /* Exclude any attempts to start a new grace period. */ 2223 /* Exclude any attempts to start a new grace period. */
2216 mutex_lock(&rsp->onoff_mutex); 2224 mutex_lock(&rsp->onoff_mutex);
2217 raw_spin_lock_irqsave(&rsp->orphan_lock, flags); 2225 raw_spin_lock_irqsave(&rsp->orphan_lock, flags);
@@ -2449,7 +2457,7 @@ static void force_qs_rnp(struct rcu_state *rsp,
2449 for (; cpu <= rnp->grphi; cpu++, bit <<= 1) { 2457 for (; cpu <= rnp->grphi; cpu++, bit <<= 1) {
2450 if ((rnp->qsmask & bit) != 0) { 2458 if ((rnp->qsmask & bit) != 0) {
2451 if ((rnp->qsmaskinit & bit) != 0) 2459 if ((rnp->qsmaskinit & bit) != 0)
2452 *isidle = 0; 2460 *isidle = false;
2453 if (f(per_cpu_ptr(rsp->rda, cpu), isidle, maxj)) 2461 if (f(per_cpu_ptr(rsp->rda, cpu), isidle, maxj))
2454 mask |= bit; 2462 mask |= bit;
2455 } 2463 }
@@ -2505,9 +2513,10 @@ static void force_quiescent_state(struct rcu_state *rsp)
2505 raw_spin_unlock_irqrestore(&rnp_old->lock, flags); 2513 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
2506 return; /* Someone beat us to it. */ 2514 return; /* Someone beat us to it. */
2507 } 2515 }
2508 ACCESS_ONCE(rsp->gp_flags) |= RCU_GP_FLAG_FQS; 2516 ACCESS_ONCE(rsp->gp_flags) =
2517 ACCESS_ONCE(rsp->gp_flags) | RCU_GP_FLAG_FQS;
2509 raw_spin_unlock_irqrestore(&rnp_old->lock, flags); 2518 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
2510 wake_up(&rsp->gp_wq); /* Memory barrier implied by wake_up() path. */ 2519 rcu_gp_kthread_wake(rsp);
2511} 2520}
2512 2521
2513/* 2522/*
@@ -3442,6 +3451,7 @@ static int rcu_cpu_notify(struct notifier_block *self,
3442 case CPU_UP_PREPARE_FROZEN: 3451 case CPU_UP_PREPARE_FROZEN:
3443 rcu_prepare_cpu(cpu); 3452 rcu_prepare_cpu(cpu);
3444 rcu_prepare_kthreads(cpu); 3453 rcu_prepare_kthreads(cpu);
3454 rcu_spawn_all_nocb_kthreads(cpu);
3445 break; 3455 break;
3446 case CPU_ONLINE: 3456 case CPU_ONLINE:
3447 case CPU_DOWN_FAILED: 3457 case CPU_DOWN_FAILED:
@@ -3489,7 +3499,7 @@ static int rcu_pm_notify(struct notifier_block *self,
3489} 3499}
3490 3500
3491/* 3501/*
3492 * Spawn the kthread that handles this RCU flavor's grace periods. 3502 * Spawn the kthreads that handle each RCU flavor's grace periods.
3493 */ 3503 */
3494static int __init rcu_spawn_gp_kthread(void) 3504static int __init rcu_spawn_gp_kthread(void)
3495{ 3505{
@@ -3498,6 +3508,7 @@ static int __init rcu_spawn_gp_kthread(void)
3498 struct rcu_state *rsp; 3508 struct rcu_state *rsp;
3499 struct task_struct *t; 3509 struct task_struct *t;
3500 3510
3511 rcu_scheduler_fully_active = 1;
3501 for_each_rcu_flavor(rsp) { 3512 for_each_rcu_flavor(rsp) {
3502 t = kthread_run(rcu_gp_kthread, rsp, "%s", rsp->name); 3513 t = kthread_run(rcu_gp_kthread, rsp, "%s", rsp->name);
3503 BUG_ON(IS_ERR(t)); 3514 BUG_ON(IS_ERR(t));
@@ -3505,8 +3516,9 @@ static int __init rcu_spawn_gp_kthread(void)
3505 raw_spin_lock_irqsave(&rnp->lock, flags); 3516 raw_spin_lock_irqsave(&rnp->lock, flags);
3506 rsp->gp_kthread = t; 3517 rsp->gp_kthread = t;
3507 raw_spin_unlock_irqrestore(&rnp->lock, flags); 3518 raw_spin_unlock_irqrestore(&rnp->lock, flags);
3508 rcu_spawn_nocb_kthreads(rsp);
3509 } 3519 }
3520 rcu_spawn_nocb_kthreads();
3521 rcu_spawn_boost_kthreads();
3510 return 0; 3522 return 0;
3511} 3523}
3512early_initcall(rcu_spawn_gp_kthread); 3524early_initcall(rcu_spawn_gp_kthread);
diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
index 6a86eb7bac45..ffedcb9d42dc 100644
--- a/kernel/rcu/tree.h
+++ b/kernel/rcu/tree.h
@@ -350,7 +350,7 @@ struct rcu_data {
350 int nocb_p_count_lazy; /* (approximate). */ 350 int nocb_p_count_lazy; /* (approximate). */
351 wait_queue_head_t nocb_wq; /* For nocb kthreads to sleep on. */ 351 wait_queue_head_t nocb_wq; /* For nocb kthreads to sleep on. */
352 struct task_struct *nocb_kthread; 352 struct task_struct *nocb_kthread;
353 bool nocb_defer_wakeup; /* Defer wakeup of nocb_kthread. */ 353 int nocb_defer_wakeup; /* Defer wakeup of nocb_kthread. */
354 354
355 /* The following fields are used by the leader, hence own cacheline. */ 355 /* The following fields are used by the leader, hence own cacheline. */
356 struct rcu_head *nocb_gp_head ____cacheline_internodealigned_in_smp; 356 struct rcu_head *nocb_gp_head ____cacheline_internodealigned_in_smp;
@@ -383,6 +383,11 @@ struct rcu_data {
383#define RCU_FORCE_QS 3 /* Need to force quiescent state. */ 383#define RCU_FORCE_QS 3 /* Need to force quiescent state. */
384#define RCU_SIGNAL_INIT RCU_SAVE_DYNTICK 384#define RCU_SIGNAL_INIT RCU_SAVE_DYNTICK
385 385
386/* Values for nocb_defer_wakeup field in struct rcu_data. */
387#define RCU_NOGP_WAKE_NOT 0
388#define RCU_NOGP_WAKE 1
389#define RCU_NOGP_WAKE_FORCE 2
390
386#define RCU_JIFFIES_TILL_FORCE_QS (1 + (HZ > 250) + (HZ > 500)) 391#define RCU_JIFFIES_TILL_FORCE_QS (1 + (HZ > 250) + (HZ > 500))
387 /* For jiffies_till_first_fqs and */ 392 /* For jiffies_till_first_fqs and */
388 /* and jiffies_till_next_fqs. */ 393 /* and jiffies_till_next_fqs. */
@@ -572,6 +577,7 @@ static void rcu_preempt_do_callbacks(void);
572static int rcu_spawn_one_boost_kthread(struct rcu_state *rsp, 577static int rcu_spawn_one_boost_kthread(struct rcu_state *rsp,
573 struct rcu_node *rnp); 578 struct rcu_node *rnp);
574#endif /* #ifdef CONFIG_RCU_BOOST */ 579#endif /* #ifdef CONFIG_RCU_BOOST */
580static void __init rcu_spawn_boost_kthreads(void);
575static void rcu_prepare_kthreads(int cpu); 581static void rcu_prepare_kthreads(int cpu);
576static void rcu_cleanup_after_idle(int cpu); 582static void rcu_cleanup_after_idle(int cpu);
577static void rcu_prepare_for_idle(int cpu); 583static void rcu_prepare_for_idle(int cpu);
@@ -589,10 +595,14 @@ static bool __call_rcu_nocb(struct rcu_data *rdp, struct rcu_head *rhp,
589static bool rcu_nocb_adopt_orphan_cbs(struct rcu_state *rsp, 595static bool rcu_nocb_adopt_orphan_cbs(struct rcu_state *rsp,
590 struct rcu_data *rdp, 596 struct rcu_data *rdp,
591 unsigned long flags); 597 unsigned long flags);
592static bool rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp); 598static int rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp);
593static void do_nocb_deferred_wakeup(struct rcu_data *rdp); 599static void do_nocb_deferred_wakeup(struct rcu_data *rdp);
594static void rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp); 600static void rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp);
595static void rcu_spawn_nocb_kthreads(struct rcu_state *rsp); 601static void rcu_spawn_all_nocb_kthreads(int cpu);
602static void __init rcu_spawn_nocb_kthreads(void);
603#ifdef CONFIG_RCU_NOCB_CPU
604static void __init rcu_organize_nocb_kthreads(struct rcu_state *rsp);
605#endif /* #ifdef CONFIG_RCU_NOCB_CPU */
596static void __maybe_unused rcu_kick_nohz_cpu(int cpu); 606static void __maybe_unused rcu_kick_nohz_cpu(int cpu);
597static bool init_nocb_callback_list(struct rcu_data *rdp); 607static bool init_nocb_callback_list(struct rcu_data *rdp);
598static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq); 608static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq);
diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
index a7997e272564..59318ea32bc8 100644
--- a/kernel/rcu/tree_plugin.h
+++ b/kernel/rcu/tree_plugin.h
@@ -85,33 +85,6 @@ static void __init rcu_bootup_announce_oddness(void)
85 pr_info("\tBoot-time adjustment of leaf fanout to %d.\n", rcu_fanout_leaf); 85 pr_info("\tBoot-time adjustment of leaf fanout to %d.\n", rcu_fanout_leaf);
86 if (nr_cpu_ids != NR_CPUS) 86 if (nr_cpu_ids != NR_CPUS)
87 pr_info("\tRCU restricting CPUs from NR_CPUS=%d to nr_cpu_ids=%d.\n", NR_CPUS, nr_cpu_ids); 87 pr_info("\tRCU restricting CPUs from NR_CPUS=%d to nr_cpu_ids=%d.\n", NR_CPUS, nr_cpu_ids);
88#ifdef CONFIG_RCU_NOCB_CPU
89#ifndef CONFIG_RCU_NOCB_CPU_NONE
90 if (!have_rcu_nocb_mask) {
91 zalloc_cpumask_var(&rcu_nocb_mask, GFP_KERNEL);
92 have_rcu_nocb_mask = true;
93 }
94#ifdef CONFIG_RCU_NOCB_CPU_ZERO
95 pr_info("\tOffload RCU callbacks from CPU 0\n");
96 cpumask_set_cpu(0, rcu_nocb_mask);
97#endif /* #ifdef CONFIG_RCU_NOCB_CPU_ZERO */
98#ifdef CONFIG_RCU_NOCB_CPU_ALL
99 pr_info("\tOffload RCU callbacks from all CPUs\n");
100 cpumask_copy(rcu_nocb_mask, cpu_possible_mask);
101#endif /* #ifdef CONFIG_RCU_NOCB_CPU_ALL */
102#endif /* #ifndef CONFIG_RCU_NOCB_CPU_NONE */
103 if (have_rcu_nocb_mask) {
104 if (!cpumask_subset(rcu_nocb_mask, cpu_possible_mask)) {
105 pr_info("\tNote: kernel parameter 'rcu_nocbs=' contains nonexistent CPUs.\n");
106 cpumask_and(rcu_nocb_mask, cpu_possible_mask,
107 rcu_nocb_mask);
108 }
109 cpulist_scnprintf(nocb_buf, sizeof(nocb_buf), rcu_nocb_mask);
110 pr_info("\tOffload RCU callbacks from CPUs: %s.\n", nocb_buf);
111 if (rcu_nocb_poll)
112 pr_info("\tPoll for callbacks from no-CBs CPUs.\n");
113 }
114#endif /* #ifdef CONFIG_RCU_NOCB_CPU */
115} 88}
116 89
117#ifdef CONFIG_TREE_PREEMPT_RCU 90#ifdef CONFIG_TREE_PREEMPT_RCU
@@ -134,7 +107,7 @@ static void __init rcu_bootup_announce(void)
134 * Return the number of RCU-preempt batches processed thus far 107 * Return the number of RCU-preempt batches processed thus far
135 * for debug and statistics. 108 * for debug and statistics.
136 */ 109 */
137long rcu_batches_completed_preempt(void) 110static long rcu_batches_completed_preempt(void)
138{ 111{
139 return rcu_preempt_state.completed; 112 return rcu_preempt_state.completed;
140} 113}
@@ -897,7 +870,8 @@ void synchronize_rcu_expedited(void)
897 870
898 /* Clean up and exit. */ 871 /* Clean up and exit. */
899 smp_mb(); /* ensure expedited GP seen before counter increment. */ 872 smp_mb(); /* ensure expedited GP seen before counter increment. */
900 ACCESS_ONCE(sync_rcu_preempt_exp_count)++; 873 ACCESS_ONCE(sync_rcu_preempt_exp_count) =
874 sync_rcu_preempt_exp_count + 1;
901unlock_mb_ret: 875unlock_mb_ret:
902 mutex_unlock(&sync_rcu_preempt_exp_mutex); 876 mutex_unlock(&sync_rcu_preempt_exp_mutex);
903mb_ret: 877mb_ret:
@@ -1462,14 +1436,13 @@ static struct smp_hotplug_thread rcu_cpu_thread_spec = {
1462}; 1436};
1463 1437
1464/* 1438/*
1465 * Spawn all kthreads -- called as soon as the scheduler is running. 1439 * Spawn boost kthreads -- called as soon as the scheduler is running.
1466 */ 1440 */
1467static int __init rcu_spawn_kthreads(void) 1441static void __init rcu_spawn_boost_kthreads(void)
1468{ 1442{
1469 struct rcu_node *rnp; 1443 struct rcu_node *rnp;
1470 int cpu; 1444 int cpu;
1471 1445
1472 rcu_scheduler_fully_active = 1;
1473 for_each_possible_cpu(cpu) 1446 for_each_possible_cpu(cpu)
1474 per_cpu(rcu_cpu_has_work, cpu) = 0; 1447 per_cpu(rcu_cpu_has_work, cpu) = 0;
1475 BUG_ON(smpboot_register_percpu_thread(&rcu_cpu_thread_spec)); 1448 BUG_ON(smpboot_register_percpu_thread(&rcu_cpu_thread_spec));
@@ -1479,9 +1452,7 @@ static int __init rcu_spawn_kthreads(void)
1479 rcu_for_each_leaf_node(rcu_state_p, rnp) 1452 rcu_for_each_leaf_node(rcu_state_p, rnp)
1480 (void)rcu_spawn_one_boost_kthread(rcu_state_p, rnp); 1453 (void)rcu_spawn_one_boost_kthread(rcu_state_p, rnp);
1481 } 1454 }
1482 return 0;
1483} 1455}
1484early_initcall(rcu_spawn_kthreads);
1485 1456
1486static void rcu_prepare_kthreads(int cpu) 1457static void rcu_prepare_kthreads(int cpu)
1487{ 1458{
@@ -1519,12 +1490,9 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
1519{ 1490{
1520} 1491}
1521 1492
1522static int __init rcu_scheduler_really_started(void) 1493static void __init rcu_spawn_boost_kthreads(void)
1523{ 1494{
1524 rcu_scheduler_fully_active = 1;
1525 return 0;
1526} 1495}
1527early_initcall(rcu_scheduler_really_started);
1528 1496
1529static void rcu_prepare_kthreads(int cpu) 1497static void rcu_prepare_kthreads(int cpu)
1530{ 1498{
@@ -1625,7 +1593,7 @@ static bool __maybe_unused rcu_try_advance_all_cbs(void)
1625 1593
1626 /* Exit early if we advanced recently. */ 1594 /* Exit early if we advanced recently. */
1627 if (jiffies == rdtp->last_advance_all) 1595 if (jiffies == rdtp->last_advance_all)
1628 return 0; 1596 return false;
1629 rdtp->last_advance_all = jiffies; 1597 rdtp->last_advance_all = jiffies;
1630 1598
1631 for_each_rcu_flavor(rsp) { 1599 for_each_rcu_flavor(rsp) {
@@ -2075,7 +2043,7 @@ static void wake_nocb_leader(struct rcu_data *rdp, bool force)
2075 if (!ACCESS_ONCE(rdp_leader->nocb_kthread)) 2043 if (!ACCESS_ONCE(rdp_leader->nocb_kthread))
2076 return; 2044 return;
2077 if (ACCESS_ONCE(rdp_leader->nocb_leader_sleep) || force) { 2045 if (ACCESS_ONCE(rdp_leader->nocb_leader_sleep) || force) {
2078 /* Prior xchg orders against prior callback enqueue. */ 2046 /* Prior smp_mb__after_atomic() orders against prior enqueue. */
2079 ACCESS_ONCE(rdp_leader->nocb_leader_sleep) = false; 2047 ACCESS_ONCE(rdp_leader->nocb_leader_sleep) = false;
2080 wake_up(&rdp_leader->nocb_wq); 2048 wake_up(&rdp_leader->nocb_wq);
2081 } 2049 }
@@ -2104,6 +2072,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
2104 ACCESS_ONCE(*old_rhpp) = rhp; 2072 ACCESS_ONCE(*old_rhpp) = rhp;
2105 atomic_long_add(rhcount, &rdp->nocb_q_count); 2073 atomic_long_add(rhcount, &rdp->nocb_q_count);
2106 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy); 2074 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
2075 smp_mb__after_atomic(); /* Store *old_rhpp before _wake test. */
2107 2076
2108 /* If we are not being polled and there is a kthread, awaken it ... */ 2077 /* If we are not being polled and there is a kthread, awaken it ... */
2109 t = ACCESS_ONCE(rdp->nocb_kthread); 2078 t = ACCESS_ONCE(rdp->nocb_kthread);
@@ -2120,16 +2089,23 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
2120 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, 2089 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
2121 TPS("WakeEmpty")); 2090 TPS("WakeEmpty"));
2122 } else { 2091 } else {
2123 rdp->nocb_defer_wakeup = true; 2092 rdp->nocb_defer_wakeup = RCU_NOGP_WAKE;
2124 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, 2093 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
2125 TPS("WakeEmptyIsDeferred")); 2094 TPS("WakeEmptyIsDeferred"));
2126 } 2095 }
2127 rdp->qlen_last_fqs_check = 0; 2096 rdp->qlen_last_fqs_check = 0;
2128 } else if (len > rdp->qlen_last_fqs_check + qhimark) { 2097 } else if (len > rdp->qlen_last_fqs_check + qhimark) {
2129 /* ... or if many callbacks queued. */ 2098 /* ... or if many callbacks queued. */
2130 wake_nocb_leader(rdp, true); 2099 if (!irqs_disabled_flags(flags)) {
2100 wake_nocb_leader(rdp, true);
2101 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
2102 TPS("WakeOvf"));
2103 } else {
2104 rdp->nocb_defer_wakeup = RCU_NOGP_WAKE_FORCE;
2105 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
2106 TPS("WakeOvfIsDeferred"));
2107 }
2131 rdp->qlen_last_fqs_check = LONG_MAX / 2; 2108 rdp->qlen_last_fqs_check = LONG_MAX / 2;
2132 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("WakeOvf"));
2133 } else { 2109 } else {
2134 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("WakeNot")); 2110 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("WakeNot"));
2135 } 2111 }
@@ -2150,7 +2126,7 @@ static bool __call_rcu_nocb(struct rcu_data *rdp, struct rcu_head *rhp,
2150{ 2126{
2151 2127
2152 if (!rcu_is_nocb_cpu(rdp->cpu)) 2128 if (!rcu_is_nocb_cpu(rdp->cpu))
2153 return 0; 2129 return false;
2154 __call_rcu_nocb_enqueue(rdp, rhp, &rhp->next, 1, lazy, flags); 2130 __call_rcu_nocb_enqueue(rdp, rhp, &rhp->next, 1, lazy, flags);
2155 if (__is_kfree_rcu_offset((unsigned long)rhp->func)) 2131 if (__is_kfree_rcu_offset((unsigned long)rhp->func))
2156 trace_rcu_kfree_callback(rdp->rsp->name, rhp, 2132 trace_rcu_kfree_callback(rdp->rsp->name, rhp,
@@ -2161,7 +2137,18 @@ static bool __call_rcu_nocb(struct rcu_data *rdp, struct rcu_head *rhp,
2161 trace_rcu_callback(rdp->rsp->name, rhp, 2137 trace_rcu_callback(rdp->rsp->name, rhp,
2162 -atomic_long_read(&rdp->nocb_q_count_lazy), 2138 -atomic_long_read(&rdp->nocb_q_count_lazy),
2163 -atomic_long_read(&rdp->nocb_q_count)); 2139 -atomic_long_read(&rdp->nocb_q_count));
2164 return 1; 2140
2141 /*
2142 * If called from an extended quiescent state with interrupts
2143 * disabled, invoke the RCU core in order to allow the idle-entry
2144 * deferred-wakeup check to function.
2145 */
2146 if (irqs_disabled_flags(flags) &&
2147 !rcu_is_watching() &&
2148 cpu_online(smp_processor_id()))
2149 invoke_rcu_core();
2150
2151 return true;
2165} 2152}
2166 2153
2167/* 2154/*
@@ -2177,7 +2164,7 @@ static bool __maybe_unused rcu_nocb_adopt_orphan_cbs(struct rcu_state *rsp,
2177 2164
2178 /* If this is not a no-CBs CPU, tell the caller to do it the old way. */ 2165 /* If this is not a no-CBs CPU, tell the caller to do it the old way. */
2179 if (!rcu_is_nocb_cpu(smp_processor_id())) 2166 if (!rcu_is_nocb_cpu(smp_processor_id()))
2180 return 0; 2167 return false;
2181 rsp->qlen = 0; 2168 rsp->qlen = 0;
2182 rsp->qlen_lazy = 0; 2169 rsp->qlen_lazy = 0;
2183 2170
@@ -2196,7 +2183,7 @@ static bool __maybe_unused rcu_nocb_adopt_orphan_cbs(struct rcu_state *rsp,
2196 rsp->orphan_nxtlist = NULL; 2183 rsp->orphan_nxtlist = NULL;
2197 rsp->orphan_nxttail = &rsp->orphan_nxtlist; 2184 rsp->orphan_nxttail = &rsp->orphan_nxtlist;
2198 } 2185 }
2199 return 1; 2186 return true;
2200} 2187}
2201 2188
2202/* 2189/*
@@ -2229,7 +2216,7 @@ static void rcu_nocb_wait_gp(struct rcu_data *rdp)
2229 (d = ULONG_CMP_GE(ACCESS_ONCE(rnp->completed), c))); 2216 (d = ULONG_CMP_GE(ACCESS_ONCE(rnp->completed), c)));
2230 if (likely(d)) 2217 if (likely(d))
2231 break; 2218 break;
2232 flush_signals(current); 2219 WARN_ON(signal_pending(current));
2233 trace_rcu_future_gp(rnp, rdp, c, TPS("ResumeWait")); 2220 trace_rcu_future_gp(rnp, rdp, c, TPS("ResumeWait"));
2234 } 2221 }
2235 trace_rcu_future_gp(rnp, rdp, c, TPS("EndWait")); 2222 trace_rcu_future_gp(rnp, rdp, c, TPS("EndWait"));
@@ -2288,7 +2275,7 @@ wait_again:
2288 if (!rcu_nocb_poll) 2275 if (!rcu_nocb_poll)
2289 trace_rcu_nocb_wake(my_rdp->rsp->name, my_rdp->cpu, 2276 trace_rcu_nocb_wake(my_rdp->rsp->name, my_rdp->cpu,
2290 "WokeEmpty"); 2277 "WokeEmpty");
2291 flush_signals(current); 2278 WARN_ON(signal_pending(current));
2292 schedule_timeout_interruptible(1); 2279 schedule_timeout_interruptible(1);
2293 2280
2294 /* Rescan in case we were a victim of memory ordering. */ 2281 /* Rescan in case we were a victim of memory ordering. */
@@ -2327,6 +2314,7 @@ wait_again:
2327 atomic_long_add(rdp->nocb_gp_count, &rdp->nocb_follower_count); 2314 atomic_long_add(rdp->nocb_gp_count, &rdp->nocb_follower_count);
2328 atomic_long_add(rdp->nocb_gp_count_lazy, 2315 atomic_long_add(rdp->nocb_gp_count_lazy,
2329 &rdp->nocb_follower_count_lazy); 2316 &rdp->nocb_follower_count_lazy);
2317 smp_mb__after_atomic(); /* Store *tail before wakeup. */
2330 if (rdp != my_rdp && tail == &rdp->nocb_follower_head) { 2318 if (rdp != my_rdp && tail == &rdp->nocb_follower_head) {
2331 /* 2319 /*
2332 * List was empty, wake up the follower. 2320 * List was empty, wake up the follower.
@@ -2367,7 +2355,7 @@ static void nocb_follower_wait(struct rcu_data *rdp)
2367 if (!rcu_nocb_poll) 2355 if (!rcu_nocb_poll)
2368 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, 2356 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu,
2369 "WokeEmpty"); 2357 "WokeEmpty");
2370 flush_signals(current); 2358 WARN_ON(signal_pending(current));
2371 schedule_timeout_interruptible(1); 2359 schedule_timeout_interruptible(1);
2372 } 2360 }
2373} 2361}
@@ -2428,15 +2416,16 @@ static int rcu_nocb_kthread(void *arg)
2428 list = next; 2416 list = next;
2429 } 2417 }
2430 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1); 2418 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
2431 ACCESS_ONCE(rdp->nocb_p_count) -= c; 2419 ACCESS_ONCE(rdp->nocb_p_count) = rdp->nocb_p_count - c;
2432 ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl; 2420 ACCESS_ONCE(rdp->nocb_p_count_lazy) =
2421 rdp->nocb_p_count_lazy - cl;
2433 rdp->n_nocbs_invoked += c; 2422 rdp->n_nocbs_invoked += c;
2434 } 2423 }
2435 return 0; 2424 return 0;
2436} 2425}
2437 2426
2438/* Is a deferred wakeup of rcu_nocb_kthread() required? */ 2427/* Is a deferred wakeup of rcu_nocb_kthread() required? */
2439static bool rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp) 2428static int rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp)
2440{ 2429{
2441 return ACCESS_ONCE(rdp->nocb_defer_wakeup); 2430 return ACCESS_ONCE(rdp->nocb_defer_wakeup);
2442} 2431}
@@ -2444,11 +2433,79 @@ static bool rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp)
2444/* Do a deferred wakeup of rcu_nocb_kthread(). */ 2433/* Do a deferred wakeup of rcu_nocb_kthread(). */
2445static void do_nocb_deferred_wakeup(struct rcu_data *rdp) 2434static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
2446{ 2435{
2436 int ndw;
2437
2447 if (!rcu_nocb_need_deferred_wakeup(rdp)) 2438 if (!rcu_nocb_need_deferred_wakeup(rdp))
2448 return; 2439 return;
2449 ACCESS_ONCE(rdp->nocb_defer_wakeup) = false; 2440 ndw = ACCESS_ONCE(rdp->nocb_defer_wakeup);
2450 wake_nocb_leader(rdp, false); 2441 ACCESS_ONCE(rdp->nocb_defer_wakeup) = RCU_NOGP_WAKE_NOT;
2451 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty")); 2442 wake_nocb_leader(rdp, ndw == RCU_NOGP_WAKE_FORCE);
2443 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWake"));
2444}
2445
2446void __init rcu_init_nohz(void)
2447{
2448 int cpu;
2449 bool need_rcu_nocb_mask = true;
2450 struct rcu_state *rsp;
2451
2452#ifdef CONFIG_RCU_NOCB_CPU_NONE
2453 need_rcu_nocb_mask = false;
2454#endif /* #ifndef CONFIG_RCU_NOCB_CPU_NONE */
2455
2456#if defined(CONFIG_NO_HZ_FULL)
2457 if (tick_nohz_full_running && cpumask_weight(tick_nohz_full_mask))
2458 need_rcu_nocb_mask = true;
2459#endif /* #if defined(CONFIG_NO_HZ_FULL) */
2460
2461 if (!have_rcu_nocb_mask && need_rcu_nocb_mask) {
2462 if (!zalloc_cpumask_var(&rcu_nocb_mask, GFP_KERNEL)) {
2463 pr_info("rcu_nocb_mask allocation failed, callback offloading disabled.\n");
2464 return;
2465 }
2466 have_rcu_nocb_mask = true;
2467 }
2468 if (!have_rcu_nocb_mask)
2469 return;
2470
2471#ifdef CONFIG_RCU_NOCB_CPU_ZERO
2472 pr_info("\tOffload RCU callbacks from CPU 0\n");
2473 cpumask_set_cpu(0, rcu_nocb_mask);
2474#endif /* #ifdef CONFIG_RCU_NOCB_CPU_ZERO */
2475#ifdef CONFIG_RCU_NOCB_CPU_ALL
2476 pr_info("\tOffload RCU callbacks from all CPUs\n");
2477 cpumask_copy(rcu_nocb_mask, cpu_possible_mask);
2478#endif /* #ifdef CONFIG_RCU_NOCB_CPU_ALL */
2479#if defined(CONFIG_NO_HZ_FULL)
2480 if (tick_nohz_full_running)
2481 cpumask_or(rcu_nocb_mask, rcu_nocb_mask, tick_nohz_full_mask);
2482#endif /* #if defined(CONFIG_NO_HZ_FULL) */
2483
2484 if (!cpumask_subset(rcu_nocb_mask, cpu_possible_mask)) {
2485 pr_info("\tNote: kernel parameter 'rcu_nocbs=' contains nonexistent CPUs.\n");
2486 cpumask_and(rcu_nocb_mask, cpu_possible_mask,
2487 rcu_nocb_mask);
2488 }
2489 cpulist_scnprintf(nocb_buf, sizeof(nocb_buf), rcu_nocb_mask);
2490 pr_info("\tOffload RCU callbacks from CPUs: %s.\n", nocb_buf);
2491 if (rcu_nocb_poll)
2492 pr_info("\tPoll for callbacks from no-CBs CPUs.\n");
2493
2494 for_each_rcu_flavor(rsp) {
2495 for_each_cpu(cpu, rcu_nocb_mask) {
2496 struct rcu_data *rdp = per_cpu_ptr(rsp->rda, cpu);
2497
2498 /*
2499 * If there are early callbacks, they will need
2500 * to be moved to the nocb lists.
2501 */
2502 WARN_ON_ONCE(rdp->nxttail[RCU_NEXT_TAIL] !=
2503 &rdp->nxtlist &&
2504 rdp->nxttail[RCU_NEXT_TAIL] != NULL);
2505 init_nocb_callback_list(rdp);
2506 }
2507 rcu_organize_nocb_kthreads(rsp);
2508 }
2452} 2509}
2453 2510
2454/* Initialize per-rcu_data variables for no-CBs CPUs. */ 2511/* Initialize per-rcu_data variables for no-CBs CPUs. */
@@ -2459,15 +2516,85 @@ static void __init rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp)
2459 rdp->nocb_follower_tail = &rdp->nocb_follower_head; 2516 rdp->nocb_follower_tail = &rdp->nocb_follower_head;
2460} 2517}
2461 2518
2519/*
2520 * If the specified CPU is a no-CBs CPU that does not already have its
2521 * rcuo kthread for the specified RCU flavor, spawn it. If the CPUs are
2522 * brought online out of order, this can require re-organizing the
2523 * leader-follower relationships.
2524 */
2525static void rcu_spawn_one_nocb_kthread(struct rcu_state *rsp, int cpu)
2526{
2527 struct rcu_data *rdp;
2528 struct rcu_data *rdp_last;
2529 struct rcu_data *rdp_old_leader;
2530 struct rcu_data *rdp_spawn = per_cpu_ptr(rsp->rda, cpu);
2531 struct task_struct *t;
2532
2533 /*
2534 * If this isn't a no-CBs CPU or if it already has an rcuo kthread,
2535 * then nothing to do.
2536 */
2537 if (!rcu_is_nocb_cpu(cpu) || rdp_spawn->nocb_kthread)
2538 return;
2539
2540 /* If we didn't spawn the leader first, reorganize! */
2541 rdp_old_leader = rdp_spawn->nocb_leader;
2542 if (rdp_old_leader != rdp_spawn && !rdp_old_leader->nocb_kthread) {
2543 rdp_last = NULL;
2544 rdp = rdp_old_leader;
2545 do {
2546 rdp->nocb_leader = rdp_spawn;
2547 if (rdp_last && rdp != rdp_spawn)
2548 rdp_last->nocb_next_follower = rdp;
2549 rdp_last = rdp;
2550 rdp = rdp->nocb_next_follower;
2551 rdp_last->nocb_next_follower = NULL;
2552 } while (rdp);
2553 rdp_spawn->nocb_next_follower = rdp_old_leader;
2554 }
2555
2556 /* Spawn the kthread for this CPU and RCU flavor. */
2557 t = kthread_run(rcu_nocb_kthread, rdp_spawn,
2558 "rcuo%c/%d", rsp->abbr, cpu);
2559 BUG_ON(IS_ERR(t));
2560 ACCESS_ONCE(rdp_spawn->nocb_kthread) = t;
2561}
2562
2563/*
2564 * If the specified CPU is a no-CBs CPU that does not already have its
2565 * rcuo kthreads, spawn them.
2566 */
2567static void rcu_spawn_all_nocb_kthreads(int cpu)
2568{
2569 struct rcu_state *rsp;
2570
2571 if (rcu_scheduler_fully_active)
2572 for_each_rcu_flavor(rsp)
2573 rcu_spawn_one_nocb_kthread(rsp, cpu);
2574}
2575
2576/*
2577 * Once the scheduler is running, spawn rcuo kthreads for all online
2578 * no-CBs CPUs. This assumes that the early_initcall()s happen before
2579 * non-boot CPUs come online -- if this changes, we will need to add
2580 * some mutual exclusion.
2581 */
2582static void __init rcu_spawn_nocb_kthreads(void)
2583{
2584 int cpu;
2585
2586 for_each_online_cpu(cpu)
2587 rcu_spawn_all_nocb_kthreads(cpu);
2588}
2589
2462/* How many follower CPU IDs per leader? Default of -1 for sqrt(nr_cpu_ids). */ 2590/* How many follower CPU IDs per leader? Default of -1 for sqrt(nr_cpu_ids). */
2463static int rcu_nocb_leader_stride = -1; 2591static int rcu_nocb_leader_stride = -1;
2464module_param(rcu_nocb_leader_stride, int, 0444); 2592module_param(rcu_nocb_leader_stride, int, 0444);
2465 2593
2466/* 2594/*
2467 * Create a kthread for each RCU flavor for each no-CBs CPU. 2595 * Initialize leader-follower relationships for all no-CBs CPU.
2468 * Also initialize leader-follower relationships.
2469 */ 2596 */
2470static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp) 2597static void __init rcu_organize_nocb_kthreads(struct rcu_state *rsp)
2471{ 2598{
2472 int cpu; 2599 int cpu;
2473 int ls = rcu_nocb_leader_stride; 2600 int ls = rcu_nocb_leader_stride;
@@ -2475,14 +2602,9 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
2475 struct rcu_data *rdp; 2602 struct rcu_data *rdp;
2476 struct rcu_data *rdp_leader = NULL; /* Suppress misguided gcc warn. */ 2603 struct rcu_data *rdp_leader = NULL; /* Suppress misguided gcc warn. */
2477 struct rcu_data *rdp_prev = NULL; 2604 struct rcu_data *rdp_prev = NULL;
2478 struct task_struct *t;
2479 2605
2480 if (rcu_nocb_mask == NULL) 2606 if (!have_rcu_nocb_mask)
2481 return; 2607 return;
2482#if defined(CONFIG_NO_HZ_FULL) && !defined(CONFIG_NO_HZ_FULL_ALL)
2483 if (tick_nohz_full_running)
2484 cpumask_or(rcu_nocb_mask, rcu_nocb_mask, tick_nohz_full_mask);
2485#endif /* #if defined(CONFIG_NO_HZ_FULL) && !defined(CONFIG_NO_HZ_FULL_ALL) */
2486 if (ls == -1) { 2608 if (ls == -1) {
2487 ls = int_sqrt(nr_cpu_ids); 2609 ls = int_sqrt(nr_cpu_ids);
2488 rcu_nocb_leader_stride = ls; 2610 rcu_nocb_leader_stride = ls;
@@ -2505,21 +2627,15 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
2505 rdp_prev->nocb_next_follower = rdp; 2627 rdp_prev->nocb_next_follower = rdp;
2506 } 2628 }
2507 rdp_prev = rdp; 2629 rdp_prev = rdp;
2508
2509 /* Spawn the kthread for this CPU. */
2510 t = kthread_run(rcu_nocb_kthread, rdp,
2511 "rcuo%c/%d", rsp->abbr, cpu);
2512 BUG_ON(IS_ERR(t));
2513 ACCESS_ONCE(rdp->nocb_kthread) = t;
2514 } 2630 }
2515} 2631}
2516 2632
2517/* Prevent __call_rcu() from enqueuing callbacks on no-CBs CPUs */ 2633/* Prevent __call_rcu() from enqueuing callbacks on no-CBs CPUs */
2518static bool init_nocb_callback_list(struct rcu_data *rdp) 2634static bool init_nocb_callback_list(struct rcu_data *rdp)
2519{ 2635{
2520 if (rcu_nocb_mask == NULL || 2636 if (!rcu_is_nocb_cpu(rdp->cpu))
2521 !cpumask_test_cpu(rdp->cpu, rcu_nocb_mask))
2522 return false; 2637 return false;
2638
2523 rdp->nxttail[RCU_NEXT_TAIL] = NULL; 2639 rdp->nxttail[RCU_NEXT_TAIL] = NULL;
2524 return true; 2640 return true;
2525} 2641}
@@ -2541,21 +2657,21 @@ static void rcu_init_one_nocb(struct rcu_node *rnp)
2541static bool __call_rcu_nocb(struct rcu_data *rdp, struct rcu_head *rhp, 2657static bool __call_rcu_nocb(struct rcu_data *rdp, struct rcu_head *rhp,
2542 bool lazy, unsigned long flags) 2658 bool lazy, unsigned long flags)
2543{ 2659{
2544 return 0; 2660 return false;
2545} 2661}
2546 2662
2547static bool __maybe_unused rcu_nocb_adopt_orphan_cbs(struct rcu_state *rsp, 2663static bool __maybe_unused rcu_nocb_adopt_orphan_cbs(struct rcu_state *rsp,
2548 struct rcu_data *rdp, 2664 struct rcu_data *rdp,
2549 unsigned long flags) 2665 unsigned long flags)
2550{ 2666{
2551 return 0; 2667 return false;
2552} 2668}
2553 2669
2554static void __init rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp) 2670static void __init rcu_boot_init_nocb_percpu_data(struct rcu_data *rdp)
2555{ 2671{
2556} 2672}
2557 2673
2558static bool rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp) 2674static int rcu_nocb_need_deferred_wakeup(struct rcu_data *rdp)
2559{ 2675{
2560 return false; 2676 return false;
2561} 2677}
@@ -2564,7 +2680,11 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
2564{ 2680{
2565} 2681}
2566 2682
2567static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp) 2683static void rcu_spawn_all_nocb_kthreads(int cpu)
2684{
2685}
2686
2687static void __init rcu_spawn_nocb_kthreads(void)
2568{ 2688{
2569} 2689}
2570 2690
@@ -2595,16 +2715,6 @@ static void __maybe_unused rcu_kick_nohz_cpu(int cpu)
2595 2715
2596#ifdef CONFIG_NO_HZ_FULL_SYSIDLE 2716#ifdef CONFIG_NO_HZ_FULL_SYSIDLE
2597 2717
2598/*
2599 * Define RCU flavor that holds sysidle state. This needs to be the
2600 * most active flavor of RCU.
2601 */
2602#ifdef CONFIG_PREEMPT_RCU
2603static struct rcu_state *rcu_sysidle_state = &rcu_preempt_state;
2604#else /* #ifdef CONFIG_PREEMPT_RCU */
2605static struct rcu_state *rcu_sysidle_state = &rcu_sched_state;
2606#endif /* #else #ifdef CONFIG_PREEMPT_RCU */
2607
2608static int full_sysidle_state; /* Current system-idle state. */ 2718static int full_sysidle_state; /* Current system-idle state. */
2609#define RCU_SYSIDLE_NOT 0 /* Some CPU is not idle. */ 2719#define RCU_SYSIDLE_NOT 0 /* Some CPU is not idle. */
2610#define RCU_SYSIDLE_SHORT 1 /* All CPUs idle for brief period. */ 2720#define RCU_SYSIDLE_SHORT 1 /* All CPUs idle for brief period. */
@@ -2622,6 +2732,10 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
2622{ 2732{
2623 unsigned long j; 2733 unsigned long j;
2624 2734
2735 /* If there are no nohz_full= CPUs, no need to track this. */
2736 if (!tick_nohz_full_enabled())
2737 return;
2738
2625 /* Adjust nesting, check for fully idle. */ 2739 /* Adjust nesting, check for fully idle. */
2626 if (irq) { 2740 if (irq) {
2627 rdtp->dynticks_idle_nesting--; 2741 rdtp->dynticks_idle_nesting--;
@@ -2687,6 +2801,10 @@ void rcu_sysidle_force_exit(void)
2687 */ 2801 */
2688static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq) 2802static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
2689{ 2803{
2804 /* If there are no nohz_full= CPUs, no need to track this. */
2805 if (!tick_nohz_full_enabled())
2806 return;
2807
2690 /* Adjust nesting, check for already non-idle. */ 2808 /* Adjust nesting, check for already non-idle. */
2691 if (irq) { 2809 if (irq) {
2692 rdtp->dynticks_idle_nesting++; 2810 rdtp->dynticks_idle_nesting++;
@@ -2741,12 +2859,16 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
2741 unsigned long j; 2859 unsigned long j;
2742 struct rcu_dynticks *rdtp = rdp->dynticks; 2860 struct rcu_dynticks *rdtp = rdp->dynticks;
2743 2861
2862 /* If there are no nohz_full= CPUs, don't check system-wide idleness. */
2863 if (!tick_nohz_full_enabled())
2864 return;
2865
2744 /* 2866 /*
2745 * If some other CPU has already reported non-idle, if this is 2867 * If some other CPU has already reported non-idle, if this is
2746 * not the flavor of RCU that tracks sysidle state, or if this 2868 * not the flavor of RCU that tracks sysidle state, or if this
2747 * is an offline or the timekeeping CPU, nothing to do. 2869 * is an offline or the timekeeping CPU, nothing to do.
2748 */ 2870 */
2749 if (!*isidle || rdp->rsp != rcu_sysidle_state || 2871 if (!*isidle || rdp->rsp != rcu_state_p ||
2750 cpu_is_offline(rdp->cpu) || rdp->cpu == tick_do_timer_cpu) 2872 cpu_is_offline(rdp->cpu) || rdp->cpu == tick_do_timer_cpu)
2751 return; 2873 return;
2752 if (rcu_gp_in_progress(rdp->rsp)) 2874 if (rcu_gp_in_progress(rdp->rsp))
@@ -2772,7 +2894,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
2772 */ 2894 */
2773static bool is_sysidle_rcu_state(struct rcu_state *rsp) 2895static bool is_sysidle_rcu_state(struct rcu_state *rsp)
2774{ 2896{
2775 return rsp == rcu_sysidle_state; 2897 return rsp == rcu_state_p;
2776} 2898}
2777 2899
2778/* 2900/*
@@ -2850,7 +2972,7 @@ static void rcu_sysidle_cancel(void)
2850static void rcu_sysidle_report(struct rcu_state *rsp, int isidle, 2972static void rcu_sysidle_report(struct rcu_state *rsp, int isidle,
2851 unsigned long maxj, bool gpkt) 2973 unsigned long maxj, bool gpkt)
2852{ 2974{
2853 if (rsp != rcu_sysidle_state) 2975 if (rsp != rcu_state_p)
2854 return; /* Wrong flavor, ignore. */ 2976 return; /* Wrong flavor, ignore. */
2855 if (gpkt && nr_cpu_ids <= CONFIG_NO_HZ_FULL_SYSIDLE_SMALL) 2977 if (gpkt && nr_cpu_ids <= CONFIG_NO_HZ_FULL_SYSIDLE_SMALL)
2856 return; /* Running state machine from timekeeping CPU. */ 2978 return; /* Running state machine from timekeeping CPU. */
@@ -2867,6 +2989,10 @@ static void rcu_sysidle_report(struct rcu_state *rsp, int isidle,
2867static void rcu_sysidle_report_gp(struct rcu_state *rsp, int isidle, 2989static void rcu_sysidle_report_gp(struct rcu_state *rsp, int isidle,
2868 unsigned long maxj) 2990 unsigned long maxj)
2869{ 2991{
2992 /* If there are no nohz_full= CPUs, no need to track this. */
2993 if (!tick_nohz_full_enabled())
2994 return;
2995
2870 rcu_sysidle_report(rsp, isidle, maxj, true); 2996 rcu_sysidle_report(rsp, isidle, maxj, true);
2871} 2997}
2872 2998
@@ -2893,7 +3019,8 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
2893 3019
2894/* 3020/*
2895 * Check to see if the system is fully idle, other than the timekeeping CPU. 3021 * Check to see if the system is fully idle, other than the timekeeping CPU.
2896 * The caller must have disabled interrupts. 3022 * The caller must have disabled interrupts. This is not intended to be
3023 * called unless tick_nohz_full_enabled().
2897 */ 3024 */
2898bool rcu_sys_is_idle(void) 3025bool rcu_sys_is_idle(void)
2899{ 3026{
@@ -2919,13 +3046,12 @@ bool rcu_sys_is_idle(void)
2919 3046
2920 /* Scan all the CPUs looking for nonidle CPUs. */ 3047 /* Scan all the CPUs looking for nonidle CPUs. */
2921 for_each_possible_cpu(cpu) { 3048 for_each_possible_cpu(cpu) {
2922 rdp = per_cpu_ptr(rcu_sysidle_state->rda, cpu); 3049 rdp = per_cpu_ptr(rcu_state_p->rda, cpu);
2923 rcu_sysidle_check_cpu(rdp, &isidle, &maxj); 3050 rcu_sysidle_check_cpu(rdp, &isidle, &maxj);
2924 if (!isidle) 3051 if (!isidle)
2925 break; 3052 break;
2926 } 3053 }
2927 rcu_sysidle_report(rcu_sysidle_state, 3054 rcu_sysidle_report(rcu_state_p, isidle, maxj, false);
2928 isidle, maxj, false);
2929 oldrss = rss; 3055 oldrss = rss;
2930 rss = ACCESS_ONCE(full_sysidle_state); 3056 rss = ACCESS_ONCE(full_sysidle_state);
2931 } 3057 }
@@ -2952,7 +3078,7 @@ bool rcu_sys_is_idle(void)
2952 * provided by the memory allocator. 3078 * provided by the memory allocator.
2953 */ 3079 */
2954 if (nr_cpu_ids > CONFIG_NO_HZ_FULL_SYSIDLE_SMALL && 3080 if (nr_cpu_ids > CONFIG_NO_HZ_FULL_SYSIDLE_SMALL &&
2955 !rcu_gp_in_progress(rcu_sysidle_state) && 3081 !rcu_gp_in_progress(rcu_state_p) &&
2956 !rsh.inuse && xchg(&rsh.inuse, 1) == 0) 3082 !rsh.inuse && xchg(&rsh.inuse, 1) == 0)
2957 call_rcu(&rsh.rh, rcu_sysidle_cb); 3083 call_rcu(&rsh.rh, rcu_sysidle_cb);
2958 return false; 3084 return false;
diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
index 4056d7992a6c..ea8ea7b16e11 100644
--- a/kernel/rcu/update.c
+++ b/kernel/rcu/update.c
@@ -137,6 +137,38 @@ int notrace debug_lockdep_rcu_enabled(void)
137EXPORT_SYMBOL_GPL(debug_lockdep_rcu_enabled); 137EXPORT_SYMBOL_GPL(debug_lockdep_rcu_enabled);
138 138
139/** 139/**
140 * rcu_read_lock_held() - might we be in RCU read-side critical section?
141 *
142 * If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an RCU
143 * read-side critical section. In absence of CONFIG_DEBUG_LOCK_ALLOC,
144 * this assumes we are in an RCU read-side critical section unless it can
145 * prove otherwise. This is useful for debug checks in functions that
146 * require that they be called within an RCU read-side critical section.
147 *
148 * Checks debug_lockdep_rcu_enabled() to prevent false positives during boot
149 * and while lockdep is disabled.
150 *
151 * Note that rcu_read_lock() and the matching rcu_read_unlock() must
152 * occur in the same context, for example, it is illegal to invoke
153 * rcu_read_unlock() in process context if the matching rcu_read_lock()
154 * was invoked from within an irq handler.
155 *
156 * Note that rcu_read_lock() is disallowed if the CPU is either idle or
157 * offline from an RCU perspective, so check for those as well.
158 */
159int rcu_read_lock_held(void)
160{
161 if (!debug_lockdep_rcu_enabled())
162 return 1;
163 if (!rcu_is_watching())
164 return 0;
165 if (!rcu_lockdep_current_cpu_online())
166 return 0;
167 return lock_is_held(&rcu_lock_map);
168}
169EXPORT_SYMBOL_GPL(rcu_read_lock_held);
170
171/**
140 * rcu_read_lock_bh_held() - might we be in RCU-bh read-side critical section? 172 * rcu_read_lock_bh_held() - might we be in RCU-bh read-side critical section?
141 * 173 *
142 * Check for bottom half being disabled, which covers both the 174 * Check for bottom half being disabled, which covers both the