aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul E. McKenney <paulmck@linux.ibm.com>2019-01-11 19:57:41 -0500
committerPaul E. McKenney <paulmck@linux.ibm.com>2019-03-26 17:40:13 -0400
commit32255d51b6ed00de2b88970ceea8db0ec3bae6f8 (patch)
treea7b44bf44d9d9823204975e95a3aed9f1815d02d
parent3fc3d1709fc75995ee09ad4f35f160cf360b397b (diff)
rcu: Move RCU CPU stall-warning code out of tree.c
This commit completes the process of consolidating the code for RCU CPU stall warnings for normal grace periods by moving the remaining such code from kernel/rcu/tree.c to kernel/rcu/tree_stall.h. Signed-off-by: Paul E. McKenney <paulmck@linux.ibm.com>
-rw-r--r--kernel/rcu/tree.c291
-rw-r--r--kernel/rcu/tree.h10
-rw-r--r--kernel/rcu/tree_stall.h292
3 files changed, 299 insertions, 294 deletions
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 424d50ccf9e6..001dd05f6e38 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -102,8 +102,6 @@ int rcu_num_lvls __read_mostly = RCU_NUM_LVLS;
102/* Number of rcu_nodes at specified level. */ 102/* Number of rcu_nodes at specified level. */
103int num_rcu_lvl[] = NUM_RCU_LVL_INIT; 103int num_rcu_lvl[] = NUM_RCU_LVL_INIT;
104int rcu_num_nodes __read_mostly = NUM_RCU_NODES; /* Total # rcu_nodes in use. */ 104int rcu_num_nodes __read_mostly = NUM_RCU_NODES; /* Total # rcu_nodes in use. */
105/* panic() on RCU Stall sysctl. */
106int sysctl_panic_on_rcu_stall __read_mostly;
107/* Commandeer a sysrq key to dump RCU's tree. */ 105/* Commandeer a sysrq key to dump RCU's tree. */
108static bool sysrq_rcu; 106static bool sysrq_rcu;
109module_param(sysrq_rcu, bool, 0444); 107module_param(sysrq_rcu, bool, 0444);
@@ -1167,295 +1165,6 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
1167 return 0; 1165 return 0;
1168} 1166}
1169 1167
1170static void record_gp_stall_check_time(void)
1171{
1172 unsigned long j = jiffies;
1173 unsigned long j1;
1174
1175 rcu_state.gp_start = j;
1176 j1 = rcu_jiffies_till_stall_check();
1177 /* Record ->gp_start before ->jiffies_stall. */
1178 smp_store_release(&rcu_state.jiffies_stall, j + j1); /* ^^^ */
1179 rcu_state.jiffies_resched = j + j1 / 2;
1180 rcu_state.n_force_qs_gpstart = READ_ONCE(rcu_state.n_force_qs);
1181}
1182
1183/*
1184 * Complain about starvation of grace-period kthread.
1185 */
1186static void rcu_check_gp_kthread_starvation(void)
1187{
1188 struct task_struct *gpk = rcu_state.gp_kthread;
1189 unsigned long j;
1190
1191 j = jiffies - READ_ONCE(rcu_state.gp_activity);
1192 if (j > 2 * HZ) {
1193 pr_err("%s kthread starved for %ld jiffies! g%ld f%#x %s(%d) ->state=%#lx ->cpu=%d\n",
1194 rcu_state.name, j,
1195 (long)rcu_seq_current(&rcu_state.gp_seq),
1196 READ_ONCE(rcu_state.gp_flags),
1197 gp_state_getname(rcu_state.gp_state), rcu_state.gp_state,
1198 gpk ? gpk->state : ~0, gpk ? task_cpu(gpk) : -1);
1199 if (gpk) {
1200 pr_err("RCU grace-period kthread stack dump:\n");
1201 sched_show_task(gpk);
1202 wake_up_process(gpk);
1203 }
1204 }
1205}
1206
1207/*
1208 * Dump stacks of all tasks running on stalled CPUs. First try using
1209 * NMIs, but fall back to manual remote stack tracing on architectures
1210 * that don't support NMI-based stack dumps. The NMI-triggered stack
1211 * traces are more accurate because they are printed by the target CPU.
1212 */
1213static void rcu_dump_cpu_stacks(void)
1214{
1215 int cpu;
1216 unsigned long flags;
1217 struct rcu_node *rnp;
1218
1219 rcu_for_each_leaf_node(rnp) {
1220 raw_spin_lock_irqsave_rcu_node(rnp, flags);
1221 for_each_leaf_node_possible_cpu(rnp, cpu)
1222 if (rnp->qsmask & leaf_node_cpu_bit(rnp, cpu))
1223 if (!trigger_single_cpu_backtrace(cpu))
1224 dump_cpu_task(cpu);
1225 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
1226 }
1227}
1228
1229/*
1230 * If too much time has passed in the current grace period, and if
1231 * so configured, go kick the relevant kthreads.
1232 */
1233static void rcu_stall_kick_kthreads(void)
1234{
1235 unsigned long j;
1236
1237 if (!rcu_kick_kthreads)
1238 return;
1239 j = READ_ONCE(rcu_state.jiffies_kick_kthreads);
1240 if (time_after(jiffies, j) && rcu_state.gp_kthread &&
1241 (rcu_gp_in_progress() || READ_ONCE(rcu_state.gp_flags))) {
1242 WARN_ONCE(1, "Kicking %s grace-period kthread\n",
1243 rcu_state.name);
1244 rcu_ftrace_dump(DUMP_ALL);
1245 wake_up_process(rcu_state.gp_kthread);
1246 WRITE_ONCE(rcu_state.jiffies_kick_kthreads, j + HZ);
1247 }
1248}
1249
1250static void panic_on_rcu_stall(void)
1251{
1252 if (sysctl_panic_on_rcu_stall)
1253 panic("RCU Stall\n");
1254}
1255
1256static void print_other_cpu_stall(unsigned long gp_seq)
1257{
1258 int cpu;
1259 unsigned long flags;
1260 unsigned long gpa;
1261 unsigned long j;
1262 int ndetected = 0;
1263 struct rcu_node *rnp = rcu_get_root();
1264 long totqlen = 0;
1265
1266 /* Kick and suppress, if so configured. */
1267 rcu_stall_kick_kthreads();
1268 if (rcu_cpu_stall_suppress)
1269 return;
1270
1271 /*
1272 * OK, time to rat on our buddy...
1273 * See Documentation/RCU/stallwarn.txt for info on how to debug
1274 * RCU CPU stall warnings.
1275 */
1276 pr_err("INFO: %s detected stalls on CPUs/tasks:", rcu_state.name);
1277 print_cpu_stall_info_begin();
1278 rcu_for_each_leaf_node(rnp) {
1279 raw_spin_lock_irqsave_rcu_node(rnp, flags);
1280 ndetected += rcu_print_task_stall(rnp);
1281 if (rnp->qsmask != 0) {
1282 for_each_leaf_node_possible_cpu(rnp, cpu)
1283 if (rnp->qsmask & leaf_node_cpu_bit(rnp, cpu)) {
1284 print_cpu_stall_info(cpu);
1285 ndetected++;
1286 }
1287 }
1288 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
1289 }
1290
1291 print_cpu_stall_info_end();
1292 for_each_possible_cpu(cpu)
1293 totqlen += rcu_get_n_cbs_cpu(cpu);
1294 pr_cont("(detected by %d, t=%ld jiffies, g=%ld, q=%lu)\n",
1295 smp_processor_id(), (long)(jiffies - rcu_state.gp_start),
1296 (long)rcu_seq_current(&rcu_state.gp_seq), totqlen);
1297 if (ndetected) {
1298 rcu_dump_cpu_stacks();
1299
1300 /* Complain about tasks blocking the grace period. */
1301 rcu_print_detail_task_stall();
1302 } else {
1303 if (rcu_seq_current(&rcu_state.gp_seq) != gp_seq) {
1304 pr_err("INFO: Stall ended before state dump start\n");
1305 } else {
1306 j = jiffies;
1307 gpa = READ_ONCE(rcu_state.gp_activity);
1308 pr_err("All QSes seen, last %s kthread activity %ld (%ld-%ld), jiffies_till_next_fqs=%ld, root ->qsmask %#lx\n",
1309 rcu_state.name, j - gpa, j, gpa,
1310 READ_ONCE(jiffies_till_next_fqs),
1311 rcu_get_root()->qsmask);
1312 /* In this case, the current CPU might be at fault. */
1313 sched_show_task(current);
1314 }
1315 }
1316 /* Rewrite if needed in case of slow consoles. */
1317 if (ULONG_CMP_GE(jiffies, READ_ONCE(rcu_state.jiffies_stall)))
1318 WRITE_ONCE(rcu_state.jiffies_stall,
1319 jiffies + 3 * rcu_jiffies_till_stall_check() + 3);
1320
1321 rcu_check_gp_kthread_starvation();
1322
1323 panic_on_rcu_stall();
1324
1325 rcu_force_quiescent_state(); /* Kick them all. */
1326}
1327
1328static void print_cpu_stall(void)
1329{
1330 int cpu;
1331 unsigned long flags;
1332 struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
1333 struct rcu_node *rnp = rcu_get_root();
1334 long totqlen = 0;
1335
1336 /* Kick and suppress, if so configured. */
1337 rcu_stall_kick_kthreads();
1338 if (rcu_cpu_stall_suppress)
1339 return;
1340
1341 /*
1342 * OK, time to rat on ourselves...
1343 * See Documentation/RCU/stallwarn.txt for info on how to debug
1344 * RCU CPU stall warnings.
1345 */
1346 pr_err("INFO: %s self-detected stall on CPU", rcu_state.name);
1347 print_cpu_stall_info_begin();
1348 raw_spin_lock_irqsave_rcu_node(rdp->mynode, flags);
1349 print_cpu_stall_info(smp_processor_id());
1350 raw_spin_unlock_irqrestore_rcu_node(rdp->mynode, flags);
1351 print_cpu_stall_info_end();
1352 for_each_possible_cpu(cpu)
1353 totqlen += rcu_get_n_cbs_cpu(cpu);
1354 pr_cont(" (t=%lu jiffies g=%ld q=%lu)\n",
1355 jiffies - rcu_state.gp_start,
1356 (long)rcu_seq_current(&rcu_state.gp_seq), totqlen);
1357
1358 rcu_check_gp_kthread_starvation();
1359
1360 rcu_dump_cpu_stacks();
1361
1362 raw_spin_lock_irqsave_rcu_node(rnp, flags);
1363 /* Rewrite if needed in case of slow consoles. */
1364 if (ULONG_CMP_GE(jiffies, READ_ONCE(rcu_state.jiffies_stall)))
1365 WRITE_ONCE(rcu_state.jiffies_stall,
1366 jiffies + 3 * rcu_jiffies_till_stall_check() + 3);
1367 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
1368
1369 panic_on_rcu_stall();
1370
1371 /*
1372 * Attempt to revive the RCU machinery by forcing a context switch.
1373 *
1374 * A context switch would normally allow the RCU state machine to make
1375 * progress and it could be we're stuck in kernel space without context
1376 * switches for an entirely unreasonable amount of time.
1377 */
1378 set_tsk_need_resched(current);
1379 set_preempt_need_resched();
1380}
1381
1382static void check_cpu_stall(struct rcu_data *rdp)
1383{
1384 unsigned long gs1;
1385 unsigned long gs2;
1386 unsigned long gps;
1387 unsigned long j;
1388 unsigned long jn;
1389 unsigned long js;
1390 struct rcu_node *rnp;
1391
1392 if ((rcu_cpu_stall_suppress && !rcu_kick_kthreads) ||
1393 !rcu_gp_in_progress())
1394 return;
1395 rcu_stall_kick_kthreads();
1396 j = jiffies;
1397
1398 /*
1399 * Lots of memory barriers to reject false positives.
1400 *
1401 * The idea is to pick up rcu_state.gp_seq, then
1402 * rcu_state.jiffies_stall, then rcu_state.gp_start, and finally
1403 * another copy of rcu_state.gp_seq. These values are updated in
1404 * the opposite order with memory barriers (or equivalent) during
1405 * grace-period initialization and cleanup. Now, a false positive
1406 * can occur if we get an new value of rcu_state.gp_start and a old
1407 * value of rcu_state.jiffies_stall. But given the memory barriers,
1408 * the only way that this can happen is if one grace period ends
1409 * and another starts between these two fetches. This is detected
1410 * by comparing the second fetch of rcu_state.gp_seq with the
1411 * previous fetch from rcu_state.gp_seq.
1412 *
1413 * Given this check, comparisons of jiffies, rcu_state.jiffies_stall,
1414 * and rcu_state.gp_start suffice to forestall false positives.
1415 */
1416 gs1 = READ_ONCE(rcu_state.gp_seq);
1417 smp_rmb(); /* Pick up ->gp_seq first... */
1418 js = READ_ONCE(rcu_state.jiffies_stall);
1419 smp_rmb(); /* ...then ->jiffies_stall before the rest... */
1420 gps = READ_ONCE(rcu_state.gp_start);
1421 smp_rmb(); /* ...and finally ->gp_start before ->gp_seq again. */
1422 gs2 = READ_ONCE(rcu_state.gp_seq);
1423 if (gs1 != gs2 ||
1424 ULONG_CMP_LT(j, js) ||
1425 ULONG_CMP_GE(gps, js))
1426 return; /* No stall or GP completed since entering function. */
1427 rnp = rdp->mynode;
1428 jn = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
1429 if (rcu_gp_in_progress() &&
1430 (READ_ONCE(rnp->qsmask) & rdp->grpmask) &&
1431 cmpxchg(&rcu_state.jiffies_stall, js, jn) == js) {
1432
1433 /* We haven't checked in, so go dump stack. */
1434 print_cpu_stall();
1435
1436 } else if (rcu_gp_in_progress() &&
1437 ULONG_CMP_GE(j, js + RCU_STALL_RAT_DELAY) &&
1438 cmpxchg(&rcu_state.jiffies_stall, js, jn) == js) {
1439
1440 /* They had a few time units to dump stack, so complain. */
1441 print_other_cpu_stall(gs2);
1442 }
1443}
1444
1445/**
1446 * rcu_cpu_stall_reset - prevent further stall warnings in current grace period
1447 *
1448 * Set the stall-warning timeout way off into the future, thus preventing
1449 * any RCU CPU stall-warning messages from appearing in the current set of
1450 * RCU grace periods.
1451 *
1452 * The caller must disable hard irqs.
1453 */
1454void rcu_cpu_stall_reset(void)
1455{
1456 WRITE_ONCE(rcu_state.jiffies_stall, jiffies + ULONG_MAX / 2);
1457}
1458
1459/* Trace-event wrapper function for trace_rcu_future_grace_period. */ 1168/* Trace-event wrapper function for trace_rcu_future_grace_period. */
1460static void trace_rcu_this_gp(struct rcu_node *rnp, struct rcu_data *rdp, 1169static void trace_rcu_this_gp(struct rcu_node *rnp, struct rcu_data *rdp,
1461 unsigned long gp_seq_req, const char *s) 1170 unsigned long gp_seq_req, const char *s)
diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
index bb4f995f2d3f..3c4e26fff806 100644
--- a/kernel/rcu/tree.h
+++ b/kernel/rcu/tree.h
@@ -393,15 +393,13 @@ static const char *tp_rcu_varname __used __tracepoint_string = rcu_name;
393 393
394int rcu_dynticks_snap(struct rcu_data *rdp); 394int rcu_dynticks_snap(struct rcu_data *rdp);
395 395
396/* Forward declarations for rcutree_plugin.h */ 396/* Forward declarations for tree_plugin.h */
397static void rcu_bootup_announce(void); 397static void rcu_bootup_announce(void);
398static void rcu_qs(void); 398static void rcu_qs(void);
399static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp); 399static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp);
400#ifdef CONFIG_HOTPLUG_CPU 400#ifdef CONFIG_HOTPLUG_CPU
401static bool rcu_preempt_has_tasks(struct rcu_node *rnp); 401static bool rcu_preempt_has_tasks(struct rcu_node *rnp);
402#endif /* #ifdef CONFIG_HOTPLUG_CPU */ 402#endif /* #ifdef CONFIG_HOTPLUG_CPU */
403static void rcu_print_detail_task_stall(void);
404static int rcu_print_task_stall(struct rcu_node *rnp);
405static int rcu_print_task_exp_stall(struct rcu_node *rnp); 403static int rcu_print_task_exp_stall(struct rcu_node *rnp);
406static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp); 404static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp);
407static void rcu_flavor_sched_clock_irq(int user); 405static void rcu_flavor_sched_clock_irq(int user);
@@ -445,3 +443,9 @@ static void rcu_bind_gp_kthread(void);
445static bool rcu_nohz_full_cpu(void); 443static bool rcu_nohz_full_cpu(void);
446static void rcu_dynticks_task_enter(void); 444static void rcu_dynticks_task_enter(void);
447static void rcu_dynticks_task_exit(void); 445static void rcu_dynticks_task_exit(void);
446
447/* Forward declarations for tree_stall.h */
448static void rcu_print_detail_task_stall(void);
449static int rcu_print_task_stall(struct rcu_node *rnp);
450static void record_gp_stall_check_time(void);
451static void check_cpu_stall(struct rcu_data *rdp);
diff --git a/kernel/rcu/tree_stall.h b/kernel/rcu/tree_stall.h
index 6f5f94944f49..e0e73f493363 100644
--- a/kernel/rcu/tree_stall.h
+++ b/kernel/rcu/tree_stall.h
@@ -8,6 +8,9 @@
8 */ 8 */
9 9
10 10
11/* panic() on RCU Stall sysctl. */
12int sysctl_panic_on_rcu_stall __read_mostly;
13
11#ifdef CONFIG_PROVE_RCU 14#ifdef CONFIG_PROVE_RCU
12#define RCU_STALL_DELAY_DELTA (5 * HZ) 15#define RCU_STALL_DELAY_DELTA (5 * HZ)
13#else 16#else
@@ -156,3 +159,292 @@ static int rcu_print_task_stall(struct rcu_node *rnp)
156 return 0; 159 return 0;
157} 160}
158#endif /* #else #ifdef CONFIG_PREEMPT */ 161#endif /* #else #ifdef CONFIG_PREEMPT */
162
163static void record_gp_stall_check_time(void)
164{
165 unsigned long j = jiffies;
166 unsigned long j1;
167
168 rcu_state.gp_start = j;
169 j1 = rcu_jiffies_till_stall_check();
170 /* Record ->gp_start before ->jiffies_stall. */
171 smp_store_release(&rcu_state.jiffies_stall, j + j1); /* ^^^ */
172 rcu_state.jiffies_resched = j + j1 / 2;
173 rcu_state.n_force_qs_gpstart = READ_ONCE(rcu_state.n_force_qs);
174}
175
176/*
177 * Complain about starvation of grace-period kthread.
178 */
179static void rcu_check_gp_kthread_starvation(void)
180{
181 struct task_struct *gpk = rcu_state.gp_kthread;
182 unsigned long j;
183
184 j = jiffies - READ_ONCE(rcu_state.gp_activity);
185 if (j > 2 * HZ) {
186 pr_err("%s kthread starved for %ld jiffies! g%ld f%#x %s(%d) ->state=%#lx ->cpu=%d\n",
187 rcu_state.name, j,
188 (long)rcu_seq_current(&rcu_state.gp_seq),
189 READ_ONCE(rcu_state.gp_flags),
190 gp_state_getname(rcu_state.gp_state), rcu_state.gp_state,
191 gpk ? gpk->state : ~0, gpk ? task_cpu(gpk) : -1);
192 if (gpk) {
193 pr_err("RCU grace-period kthread stack dump:\n");
194 sched_show_task(gpk);
195 wake_up_process(gpk);
196 }
197 }
198}
199
200/*
201 * Dump stacks of all tasks running on stalled CPUs. First try using
202 * NMIs, but fall back to manual remote stack tracing on architectures
203 * that don't support NMI-based stack dumps. The NMI-triggered stack
204 * traces are more accurate because they are printed by the target CPU.
205 */
206static void rcu_dump_cpu_stacks(void)
207{
208 int cpu;
209 unsigned long flags;
210 struct rcu_node *rnp;
211
212 rcu_for_each_leaf_node(rnp) {
213 raw_spin_lock_irqsave_rcu_node(rnp, flags);
214 for_each_leaf_node_possible_cpu(rnp, cpu)
215 if (rnp->qsmask & leaf_node_cpu_bit(rnp, cpu))
216 if (!trigger_single_cpu_backtrace(cpu))
217 dump_cpu_task(cpu);
218 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
219 }
220}
221
222/*
223 * If too much time has passed in the current grace period, and if
224 * so configured, go kick the relevant kthreads.
225 */
226static void rcu_stall_kick_kthreads(void)
227{
228 unsigned long j;
229
230 if (!rcu_kick_kthreads)
231 return;
232 j = READ_ONCE(rcu_state.jiffies_kick_kthreads);
233 if (time_after(jiffies, j) && rcu_state.gp_kthread &&
234 (rcu_gp_in_progress() || READ_ONCE(rcu_state.gp_flags))) {
235 WARN_ONCE(1, "Kicking %s grace-period kthread\n",
236 rcu_state.name);
237 rcu_ftrace_dump(DUMP_ALL);
238 wake_up_process(rcu_state.gp_kthread);
239 WRITE_ONCE(rcu_state.jiffies_kick_kthreads, j + HZ);
240 }
241}
242
243static void panic_on_rcu_stall(void)
244{
245 if (sysctl_panic_on_rcu_stall)
246 panic("RCU Stall\n");
247}
248
249static void print_other_cpu_stall(unsigned long gp_seq)
250{
251 int cpu;
252 unsigned long flags;
253 unsigned long gpa;
254 unsigned long j;
255 int ndetected = 0;
256 struct rcu_node *rnp = rcu_get_root();
257 long totqlen = 0;
258
259 /* Kick and suppress, if so configured. */
260 rcu_stall_kick_kthreads();
261 if (rcu_cpu_stall_suppress)
262 return;
263
264 /*
265 * OK, time to rat on our buddy...
266 * See Documentation/RCU/stallwarn.txt for info on how to debug
267 * RCU CPU stall warnings.
268 */
269 pr_err("INFO: %s detected stalls on CPUs/tasks:", rcu_state.name);
270 print_cpu_stall_info_begin();
271 rcu_for_each_leaf_node(rnp) {
272 raw_spin_lock_irqsave_rcu_node(rnp, flags);
273 ndetected += rcu_print_task_stall(rnp);
274 if (rnp->qsmask != 0) {
275 for_each_leaf_node_possible_cpu(rnp, cpu)
276 if (rnp->qsmask & leaf_node_cpu_bit(rnp, cpu)) {
277 print_cpu_stall_info(cpu);
278 ndetected++;
279 }
280 }
281 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
282 }
283
284 print_cpu_stall_info_end();
285 for_each_possible_cpu(cpu)
286 totqlen += rcu_get_n_cbs_cpu(cpu);
287 pr_cont("(detected by %d, t=%ld jiffies, g=%ld, q=%lu)\n",
288 smp_processor_id(), (long)(jiffies - rcu_state.gp_start),
289 (long)rcu_seq_current(&rcu_state.gp_seq), totqlen);
290 if (ndetected) {
291 rcu_dump_cpu_stacks();
292
293 /* Complain about tasks blocking the grace period. */
294 rcu_print_detail_task_stall();
295 } else {
296 if (rcu_seq_current(&rcu_state.gp_seq) != gp_seq) {
297 pr_err("INFO: Stall ended before state dump start\n");
298 } else {
299 j = jiffies;
300 gpa = READ_ONCE(rcu_state.gp_activity);
301 pr_err("All QSes seen, last %s kthread activity %ld (%ld-%ld), jiffies_till_next_fqs=%ld, root ->qsmask %#lx\n",
302 rcu_state.name, j - gpa, j, gpa,
303 READ_ONCE(jiffies_till_next_fqs),
304 rcu_get_root()->qsmask);
305 /* In this case, the current CPU might be at fault. */
306 sched_show_task(current);
307 }
308 }
309 /* Rewrite if needed in case of slow consoles. */
310 if (ULONG_CMP_GE(jiffies, READ_ONCE(rcu_state.jiffies_stall)))
311 WRITE_ONCE(rcu_state.jiffies_stall,
312 jiffies + 3 * rcu_jiffies_till_stall_check() + 3);
313
314 rcu_check_gp_kthread_starvation();
315
316 panic_on_rcu_stall();
317
318 rcu_force_quiescent_state(); /* Kick them all. */
319}
320
321static void print_cpu_stall(void)
322{
323 int cpu;
324 unsigned long flags;
325 struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
326 struct rcu_node *rnp = rcu_get_root();
327 long totqlen = 0;
328
329 /* Kick and suppress, if so configured. */
330 rcu_stall_kick_kthreads();
331 if (rcu_cpu_stall_suppress)
332 return;
333
334 /*
335 * OK, time to rat on ourselves...
336 * See Documentation/RCU/stallwarn.txt for info on how to debug
337 * RCU CPU stall warnings.
338 */
339 pr_err("INFO: %s self-detected stall on CPU", rcu_state.name);
340 print_cpu_stall_info_begin();
341 raw_spin_lock_irqsave_rcu_node(rdp->mynode, flags);
342 print_cpu_stall_info(smp_processor_id());
343 raw_spin_unlock_irqrestore_rcu_node(rdp->mynode, flags);
344 print_cpu_stall_info_end();
345 for_each_possible_cpu(cpu)
346 totqlen += rcu_get_n_cbs_cpu(cpu);
347 pr_cont(" (t=%lu jiffies g=%ld q=%lu)\n",
348 jiffies - rcu_state.gp_start,
349 (long)rcu_seq_current(&rcu_state.gp_seq), totqlen);
350
351 rcu_check_gp_kthread_starvation();
352
353 rcu_dump_cpu_stacks();
354
355 raw_spin_lock_irqsave_rcu_node(rnp, flags);
356 /* Rewrite if needed in case of slow consoles. */
357 if (ULONG_CMP_GE(jiffies, READ_ONCE(rcu_state.jiffies_stall)))
358 WRITE_ONCE(rcu_state.jiffies_stall,
359 jiffies + 3 * rcu_jiffies_till_stall_check() + 3);
360 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
361
362 panic_on_rcu_stall();
363
364 /*
365 * Attempt to revive the RCU machinery by forcing a context switch.
366 *
367 * A context switch would normally allow the RCU state machine to make
368 * progress and it could be we're stuck in kernel space without context
369 * switches for an entirely unreasonable amount of time.
370 */
371 set_tsk_need_resched(current);
372 set_preempt_need_resched();
373}
374
375static void check_cpu_stall(struct rcu_data *rdp)
376{
377 unsigned long gs1;
378 unsigned long gs2;
379 unsigned long gps;
380 unsigned long j;
381 unsigned long jn;
382 unsigned long js;
383 struct rcu_node *rnp;
384
385 if ((rcu_cpu_stall_suppress && !rcu_kick_kthreads) ||
386 !rcu_gp_in_progress())
387 return;
388 rcu_stall_kick_kthreads();
389 j = jiffies;
390
391 /*
392 * Lots of memory barriers to reject false positives.
393 *
394 * The idea is to pick up rcu_state.gp_seq, then
395 * rcu_state.jiffies_stall, then rcu_state.gp_start, and finally
396 * another copy of rcu_state.gp_seq. These values are updated in
397 * the opposite order with memory barriers (or equivalent) during
398 * grace-period initialization and cleanup. Now, a false positive
399 * can occur if we get an new value of rcu_state.gp_start and a old
400 * value of rcu_state.jiffies_stall. But given the memory barriers,
401 * the only way that this can happen is if one grace period ends
402 * and another starts between these two fetches. This is detected
403 * by comparing the second fetch of rcu_state.gp_seq with the
404 * previous fetch from rcu_state.gp_seq.
405 *
406 * Given this check, comparisons of jiffies, rcu_state.jiffies_stall,
407 * and rcu_state.gp_start suffice to forestall false positives.
408 */
409 gs1 = READ_ONCE(rcu_state.gp_seq);
410 smp_rmb(); /* Pick up ->gp_seq first... */
411 js = READ_ONCE(rcu_state.jiffies_stall);
412 smp_rmb(); /* ...then ->jiffies_stall before the rest... */
413 gps = READ_ONCE(rcu_state.gp_start);
414 smp_rmb(); /* ...and finally ->gp_start before ->gp_seq again. */
415 gs2 = READ_ONCE(rcu_state.gp_seq);
416 if (gs1 != gs2 ||
417 ULONG_CMP_LT(j, js) ||
418 ULONG_CMP_GE(gps, js))
419 return; /* No stall or GP completed since entering function. */
420 rnp = rdp->mynode;
421 jn = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
422 if (rcu_gp_in_progress() &&
423 (READ_ONCE(rnp->qsmask) & rdp->grpmask) &&
424 cmpxchg(&rcu_state.jiffies_stall, js, jn) == js) {
425
426 /* We haven't checked in, so go dump stack. */
427 print_cpu_stall();
428
429 } else if (rcu_gp_in_progress() &&
430 ULONG_CMP_GE(j, js + RCU_STALL_RAT_DELAY) &&
431 cmpxchg(&rcu_state.jiffies_stall, js, jn) == js) {
432
433 /* They had a few time units to dump stack, so complain. */
434 print_other_cpu_stall(gs2);
435 }
436}
437
438/**
439 * rcu_cpu_stall_reset - prevent further stall warnings in current grace period
440 *
441 * Set the stall-warning timeout way off into the future, thus preventing
442 * any RCU CPU stall-warning messages from appearing in the current set of
443 * RCU grace periods.
444 *
445 * The caller must disable hard irqs.
446 */
447void rcu_cpu_stall_reset(void)
448{
449 WRITE_ONCE(rcu_state.jiffies_stall, jiffies + ULONG_MAX / 2);
450}