tree_stall.h 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * RCU CPU stall warnings for normal RCU grace periods
  4. *
  5. * Copyright IBM Corporation, 2019
  6. *
  7. * Author: Paul E. McKenney <paulmck@linux.ibm.com>
  8. */
  9. #include <linux/console.h>
  10. #include <linux/kvm_para.h>
  11. #include <linux/rcu_notifier.h>
  12. #include <linux/smp.h>
  13. //////////////////////////////////////////////////////////////////////////////
  14. //
  15. // Controlling CPU stall warnings, including delay calculation.
  16. /* panic() on RCU Stall sysctl. */
  17. int sysctl_panic_on_rcu_stall __read_mostly;
  18. int sysctl_max_rcu_stall_to_panic __read_mostly;
  19. #ifdef CONFIG_PROVE_RCU
  20. #define RCU_STALL_DELAY_DELTA (5 * HZ)
  21. #else
  22. #define RCU_STALL_DELAY_DELTA 0
  23. #endif
  24. #define RCU_STALL_MIGHT_DIV 8
  25. #define RCU_STALL_MIGHT_MIN (2 * HZ)
  26. int rcu_exp_jiffies_till_stall_check(void)
  27. {
  28. int cpu_stall_timeout = READ_ONCE(rcu_exp_cpu_stall_timeout);
  29. int exp_stall_delay_delta = 0;
  30. int till_stall_check;
  31. // Zero says to use rcu_cpu_stall_timeout, but in milliseconds.
  32. if (!cpu_stall_timeout)
  33. cpu_stall_timeout = jiffies_to_msecs(rcu_jiffies_till_stall_check());
  34. // Limit check must be consistent with the Kconfig limits for
  35. // CONFIG_RCU_EXP_CPU_STALL_TIMEOUT, so check the allowed range.
  36. // The minimum clamped value is "2UL", because at least one full
  37. // tick has to be guaranteed.
  38. till_stall_check = clamp(msecs_to_jiffies(cpu_stall_timeout), 2UL, 300UL * HZ);
  39. if (cpu_stall_timeout && jiffies_to_msecs(till_stall_check) != cpu_stall_timeout)
  40. WRITE_ONCE(rcu_exp_cpu_stall_timeout, jiffies_to_msecs(till_stall_check));
  41. #ifdef CONFIG_PROVE_RCU
  42. /* Add extra ~25% out of till_stall_check. */
  43. exp_stall_delay_delta = ((till_stall_check * 25) / 100) + 1;
  44. #endif
  45. return till_stall_check + exp_stall_delay_delta;
  46. }
  47. EXPORT_SYMBOL_GPL(rcu_exp_jiffies_till_stall_check);
  48. /* Limit-check stall timeouts specified at boottime and runtime. */
  49. int rcu_jiffies_till_stall_check(void)
  50. {
  51. int till_stall_check = READ_ONCE(rcu_cpu_stall_timeout);
  52. /*
  53. * Limit check must be consistent with the Kconfig limits
  54. * for CONFIG_RCU_CPU_STALL_TIMEOUT.
  55. */
  56. if (till_stall_check < 3) {
  57. WRITE_ONCE(rcu_cpu_stall_timeout, 3);
  58. till_stall_check = 3;
  59. } else if (till_stall_check > 300) {
  60. WRITE_ONCE(rcu_cpu_stall_timeout, 300);
  61. till_stall_check = 300;
  62. }
  63. return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
  64. }
  65. EXPORT_SYMBOL_GPL(rcu_jiffies_till_stall_check);
  66. /**
  67. * rcu_gp_might_be_stalled - Is it likely that the grace period is stalled?
  68. *
  69. * Returns @true if the current grace period is sufficiently old that
  70. * it is reasonable to assume that it might be stalled. This can be
  71. * useful when deciding whether to allocate memory to enable RCU-mediated
  72. * freeing on the one hand or just invoking synchronize_rcu() on the other.
  73. * The latter is preferable when the grace period is stalled.
  74. *
  75. * Note that sampling of the .gp_start and .gp_seq fields must be done
  76. * carefully to avoid false positives at the beginnings and ends of
  77. * grace periods.
  78. */
  79. bool rcu_gp_might_be_stalled(void)
  80. {
  81. unsigned long d = rcu_jiffies_till_stall_check() / RCU_STALL_MIGHT_DIV;
  82. unsigned long j = jiffies;
  83. if (d < RCU_STALL_MIGHT_MIN)
  84. d = RCU_STALL_MIGHT_MIN;
  85. smp_mb(); // jiffies before .gp_seq to avoid false positives.
  86. if (!rcu_gp_in_progress())
  87. return false;
  88. // Long delays at this point avoids false positive, but a delay
  89. // of ULONG_MAX/4 jiffies voids your no-false-positive warranty.
  90. smp_mb(); // .gp_seq before second .gp_start
  91. // And ditto here.
  92. return !time_before(j, READ_ONCE(rcu_state.gp_start) + d);
  93. }
  94. /* Don't do RCU CPU stall warnings during long sysrq printouts. */
  95. void rcu_sysrq_start(void)
  96. {
  97. if (!rcu_cpu_stall_suppress)
  98. rcu_cpu_stall_suppress = 2;
  99. }
  100. void rcu_sysrq_end(void)
  101. {
  102. if (rcu_cpu_stall_suppress == 2)
  103. rcu_cpu_stall_suppress = 0;
  104. }
  105. /* Don't print RCU CPU stall warnings during a kernel panic. */
  106. static int rcu_panic(struct notifier_block *this, unsigned long ev, void *ptr)
  107. {
  108. rcu_cpu_stall_suppress = 1;
  109. return NOTIFY_DONE;
  110. }
  111. static struct notifier_block rcu_panic_block = {
  112. .notifier_call = rcu_panic,
  113. };
  114. static int __init check_cpu_stall_init(void)
  115. {
  116. atomic_notifier_chain_register(&panic_notifier_list, &rcu_panic_block);
  117. return 0;
  118. }
  119. early_initcall(check_cpu_stall_init);
  120. /* If so specified via sysctl, panic, yielding cleaner stall-warning output. */
  121. static void panic_on_rcu_stall(void)
  122. {
  123. static int cpu_stall;
  124. if (++cpu_stall < sysctl_max_rcu_stall_to_panic)
  125. return;
  126. if (sysctl_panic_on_rcu_stall)
  127. panic("RCU Stall\n");
  128. }
  129. /**
  130. * rcu_cpu_stall_reset - restart stall-warning timeout for current grace period
  131. *
  132. * To perform the reset request from the caller, disable stall detection until
  133. * 3 fqs loops have passed. This is required to ensure a fresh jiffies is
  134. * loaded. It should be safe to do from the fqs loop as enough timer
  135. * interrupts and context switches should have passed.
  136. *
  137. * The caller must disable hard irqs.
  138. */
  139. void rcu_cpu_stall_reset(void)
  140. {
  141. WRITE_ONCE(rcu_state.nr_fqs_jiffies_stall, 3);
  142. WRITE_ONCE(rcu_state.jiffies_stall, ULONG_MAX);
  143. }
  144. //////////////////////////////////////////////////////////////////////////////
  145. //
  146. // Interaction with RCU grace periods
  147. /* Start of new grace period, so record stall time (and forcing times). */
  148. static void record_gp_stall_check_time(void)
  149. {
  150. unsigned long j = jiffies;
  151. unsigned long j1;
  152. WRITE_ONCE(rcu_state.gp_start, j);
  153. j1 = rcu_jiffies_till_stall_check();
  154. smp_mb(); // ->gp_start before ->jiffies_stall and caller's ->gp_seq.
  155. WRITE_ONCE(rcu_state.nr_fqs_jiffies_stall, 0);
  156. WRITE_ONCE(rcu_state.jiffies_stall, j + j1);
  157. rcu_state.jiffies_resched = j + j1 / 2;
  158. rcu_state.n_force_qs_gpstart = READ_ONCE(rcu_state.n_force_qs);
  159. }
  160. /* Zero ->ticks_this_gp and snapshot the number of RCU softirq handlers. */
  161. static void zero_cpu_stall_ticks(struct rcu_data *rdp)
  162. {
  163. rdp->ticks_this_gp = 0;
  164. rdp->softirq_snap = kstat_softirqs_cpu(RCU_SOFTIRQ, smp_processor_id());
  165. WRITE_ONCE(rdp->last_fqs_resched, jiffies);
  166. }
  167. /*
  168. * If too much time has passed in the current grace period, and if
  169. * so configured, go kick the relevant kthreads.
  170. */
  171. static void rcu_stall_kick_kthreads(void)
  172. {
  173. unsigned long j;
  174. if (!READ_ONCE(rcu_kick_kthreads))
  175. return;
  176. j = READ_ONCE(rcu_state.jiffies_kick_kthreads);
  177. if (time_after(jiffies, j) && rcu_state.gp_kthread &&
  178. (rcu_gp_in_progress() || READ_ONCE(rcu_state.gp_flags))) {
  179. WARN_ONCE(1, "Kicking %s grace-period kthread\n",
  180. rcu_state.name);
  181. rcu_ftrace_dump(DUMP_ALL);
  182. wake_up_process(rcu_state.gp_kthread);
  183. WRITE_ONCE(rcu_state.jiffies_kick_kthreads, j + HZ);
  184. }
  185. }
  186. /*
  187. * Handler for the irq_work request posted about halfway into the RCU CPU
  188. * stall timeout, and used to detect excessive irq disabling. Set state
  189. * appropriately, but just complain if there is unexpected state on entry.
  190. */
  191. static void rcu_iw_handler(struct irq_work *iwp)
  192. {
  193. struct rcu_data *rdp;
  194. struct rcu_node *rnp;
  195. rdp = container_of(iwp, struct rcu_data, rcu_iw);
  196. rnp = rdp->mynode;
  197. raw_spin_lock_rcu_node(rnp);
  198. if (!WARN_ON_ONCE(!rdp->rcu_iw_pending)) {
  199. rdp->rcu_iw_gp_seq = rnp->gp_seq;
  200. rdp->rcu_iw_pending = false;
  201. }
  202. raw_spin_unlock_rcu_node(rnp);
  203. }
  204. //////////////////////////////////////////////////////////////////////////////
  205. //
  206. // Printing RCU CPU stall warnings
  207. #ifdef CONFIG_PREEMPT_RCU
  208. /*
  209. * Dump detailed information for all tasks blocking the current RCU
  210. * grace period on the specified rcu_node structure.
  211. */
  212. static void rcu_print_detail_task_stall_rnp(struct rcu_node *rnp)
  213. {
  214. unsigned long flags;
  215. struct task_struct *t;
  216. raw_spin_lock_irqsave_rcu_node(rnp, flags);
  217. if (!rcu_preempt_blocked_readers_cgp(rnp)) {
  218. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  219. return;
  220. }
  221. t = list_entry(rnp->gp_tasks->prev,
  222. struct task_struct, rcu_node_entry);
  223. list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry) {
  224. /*
  225. * We could be printing a lot while holding a spinlock.
  226. * Avoid triggering hard lockup.
  227. */
  228. touch_nmi_watchdog();
  229. sched_show_task(t);
  230. }
  231. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  232. }
  233. // Communicate task state back to the RCU CPU stall warning request.
  234. struct rcu_stall_chk_rdr {
  235. int nesting;
  236. union rcu_special rs;
  237. bool on_blkd_list;
  238. };
  239. /*
  240. * Report out the state of a not-running task that is stalling the
  241. * current RCU grace period.
  242. */
  243. static int check_slow_task(struct task_struct *t, void *arg)
  244. {
  245. struct rcu_stall_chk_rdr *rscrp = arg;
  246. if (task_curr(t))
  247. return -EBUSY; // It is running, so decline to inspect it.
  248. rscrp->nesting = t->rcu_read_lock_nesting;
  249. rscrp->rs = t->rcu_read_unlock_special;
  250. rscrp->on_blkd_list = !list_empty(&t->rcu_node_entry);
  251. return 0;
  252. }
  253. /*
  254. * Scan the current list of tasks blocked within RCU read-side critical
  255. * sections, printing out the tid of each of the first few of them.
  256. */
  257. static int rcu_print_task_stall(struct rcu_node *rnp, unsigned long flags)
  258. __releases(rnp->lock)
  259. {
  260. int i = 0;
  261. int ndetected = 0;
  262. struct rcu_stall_chk_rdr rscr;
  263. struct task_struct *t;
  264. struct task_struct *ts[8];
  265. lockdep_assert_irqs_disabled();
  266. if (!rcu_preempt_blocked_readers_cgp(rnp)) {
  267. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  268. return 0;
  269. }
  270. pr_err("\tTasks blocked on level-%d rcu_node (CPUs %d-%d):",
  271. rnp->level, rnp->grplo, rnp->grphi);
  272. t = list_entry(rnp->gp_tasks->prev,
  273. struct task_struct, rcu_node_entry);
  274. list_for_each_entry_continue(t, &rnp->blkd_tasks, rcu_node_entry) {
  275. get_task_struct(t);
  276. ts[i++] = t;
  277. if (i >= ARRAY_SIZE(ts))
  278. break;
  279. }
  280. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  281. while (i) {
  282. t = ts[--i];
  283. if (task_call_func(t, check_slow_task, &rscr))
  284. pr_cont(" P%d", t->pid);
  285. else
  286. pr_cont(" P%d/%d:%c%c%c%c",
  287. t->pid, rscr.nesting,
  288. ".b"[rscr.rs.b.blocked],
  289. ".q"[rscr.rs.b.need_qs],
  290. ".e"[rscr.rs.b.exp_hint],
  291. ".l"[rscr.on_blkd_list]);
  292. lockdep_assert_irqs_disabled();
  293. put_task_struct(t);
  294. ndetected++;
  295. }
  296. pr_cont("\n");
  297. return ndetected;
  298. }
  299. #else /* #ifdef CONFIG_PREEMPT_RCU */
  300. /*
  301. * Because preemptible RCU does not exist, we never have to check for
  302. * tasks blocked within RCU read-side critical sections.
  303. */
  304. static void rcu_print_detail_task_stall_rnp(struct rcu_node *rnp)
  305. {
  306. }
  307. /*
  308. * Because preemptible RCU does not exist, we never have to check for
  309. * tasks blocked within RCU read-side critical sections.
  310. */
  311. static int rcu_print_task_stall(struct rcu_node *rnp, unsigned long flags)
  312. __releases(rnp->lock)
  313. {
  314. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  315. return 0;
  316. }
  317. #endif /* #else #ifdef CONFIG_PREEMPT_RCU */
  318. /*
  319. * Dump stacks of all tasks running on stalled CPUs. First try using
  320. * NMIs, but fall back to manual remote stack tracing on architectures
  321. * that don't support NMI-based stack dumps. The NMI-triggered stack
  322. * traces are more accurate because they are printed by the target CPU.
  323. */
  324. static void rcu_dump_cpu_stacks(void)
  325. {
  326. int cpu;
  327. unsigned long flags;
  328. struct rcu_node *rnp;
  329. rcu_for_each_leaf_node(rnp) {
  330. printk_deferred_enter();
  331. raw_spin_lock_irqsave_rcu_node(rnp, flags);
  332. for_each_leaf_node_possible_cpu(rnp, cpu)
  333. if (rnp->qsmask & leaf_node_cpu_bit(rnp, cpu)) {
  334. if (cpu_is_offline(cpu))
  335. pr_err("Offline CPU %d blocking current GP.\n", cpu);
  336. else
  337. dump_cpu_task(cpu);
  338. }
  339. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  340. printk_deferred_exit();
  341. }
  342. }
  343. static const char * const gp_state_names[] = {
  344. [RCU_GP_IDLE] = "RCU_GP_IDLE",
  345. [RCU_GP_WAIT_GPS] = "RCU_GP_WAIT_GPS",
  346. [RCU_GP_DONE_GPS] = "RCU_GP_DONE_GPS",
  347. [RCU_GP_ONOFF] = "RCU_GP_ONOFF",
  348. [RCU_GP_INIT] = "RCU_GP_INIT",
  349. [RCU_GP_WAIT_FQS] = "RCU_GP_WAIT_FQS",
  350. [RCU_GP_DOING_FQS] = "RCU_GP_DOING_FQS",
  351. [RCU_GP_CLEANUP] = "RCU_GP_CLEANUP",
  352. [RCU_GP_CLEANED] = "RCU_GP_CLEANED",
  353. };
  354. /*
  355. * Convert a ->gp_state value to a character string.
  356. */
  357. static const char *gp_state_getname(short gs)
  358. {
  359. if (gs < 0 || gs >= ARRAY_SIZE(gp_state_names))
  360. return "???";
  361. return gp_state_names[gs];
  362. }
  363. /* Is the RCU grace-period kthread being starved of CPU time? */
  364. static bool rcu_is_gp_kthread_starving(unsigned long *jp)
  365. {
  366. unsigned long j = jiffies - READ_ONCE(rcu_state.gp_activity);
  367. if (jp)
  368. *jp = j;
  369. return j > 2 * HZ;
  370. }
  371. static bool rcu_is_rcuc_kthread_starving(struct rcu_data *rdp, unsigned long *jp)
  372. {
  373. int cpu;
  374. struct task_struct *rcuc;
  375. unsigned long j;
  376. rcuc = rdp->rcu_cpu_kthread_task;
  377. if (!rcuc)
  378. return false;
  379. cpu = task_cpu(rcuc);
  380. if (cpu_is_offline(cpu) || idle_cpu(cpu))
  381. return false;
  382. j = jiffies - READ_ONCE(rdp->rcuc_activity);
  383. if (jp)
  384. *jp = j;
  385. return j > 2 * HZ;
  386. }
  387. static void print_cpu_stat_info(int cpu)
  388. {
  389. struct rcu_snap_record rsr, *rsrp;
  390. struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
  391. struct kernel_cpustat *kcsp = &kcpustat_cpu(cpu);
  392. if (!rcu_cpu_stall_cputime)
  393. return;
  394. rsrp = &rdp->snap_record;
  395. if (rsrp->gp_seq != rdp->gp_seq)
  396. return;
  397. rsr.cputime_irq = kcpustat_field(kcsp, CPUTIME_IRQ, cpu);
  398. rsr.cputime_softirq = kcpustat_field(kcsp, CPUTIME_SOFTIRQ, cpu);
  399. rsr.cputime_system = kcpustat_field(kcsp, CPUTIME_SYSTEM, cpu);
  400. pr_err("\t hardirqs softirqs csw/system\n");
  401. pr_err("\t number: %8lld %10d %12lld\n",
  402. kstat_cpu_irqs_sum(cpu) + arch_irq_stat_cpu(cpu) - rsrp->nr_hardirqs,
  403. kstat_cpu_softirqs_sum(cpu) - rsrp->nr_softirqs,
  404. nr_context_switches_cpu(cpu) - rsrp->nr_csw);
  405. pr_err("\tcputime: %8lld %10lld %12lld ==> %d(ms)\n",
  406. div_u64(rsr.cputime_irq - rsrp->cputime_irq, NSEC_PER_MSEC),
  407. div_u64(rsr.cputime_softirq - rsrp->cputime_softirq, NSEC_PER_MSEC),
  408. div_u64(rsr.cputime_system - rsrp->cputime_system, NSEC_PER_MSEC),
  409. jiffies_to_msecs(jiffies - rsrp->jiffies));
  410. }
  411. /*
  412. * Print out diagnostic information for the specified stalled CPU.
  413. *
  414. * If the specified CPU is aware of the current RCU grace period, then
  415. * print the number of scheduling clock interrupts the CPU has taken
  416. * during the time that it has been aware. Otherwise, print the number
  417. * of RCU grace periods that this CPU is ignorant of, for example, "1"
  418. * if the CPU was aware of the previous grace period.
  419. *
  420. * Also print out idle info.
  421. */
  422. static void print_cpu_stall_info(int cpu)
  423. {
  424. unsigned long delta;
  425. bool falsepositive;
  426. struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
  427. char *ticks_title;
  428. unsigned long ticks_value;
  429. bool rcuc_starved;
  430. unsigned long j;
  431. char buf[32];
  432. /*
  433. * We could be printing a lot while holding a spinlock. Avoid
  434. * triggering hard lockup.
  435. */
  436. touch_nmi_watchdog();
  437. ticks_value = rcu_seq_ctr(rcu_state.gp_seq - rdp->gp_seq);
  438. if (ticks_value) {
  439. ticks_title = "GPs behind";
  440. } else {
  441. ticks_title = "ticks this GP";
  442. ticks_value = rdp->ticks_this_gp;
  443. }
  444. delta = rcu_seq_ctr(rdp->mynode->gp_seq - rdp->rcu_iw_gp_seq);
  445. falsepositive = rcu_is_gp_kthread_starving(NULL) &&
  446. rcu_watching_snap_in_eqs(ct_rcu_watching_cpu(cpu));
  447. rcuc_starved = rcu_is_rcuc_kthread_starving(rdp, &j);
  448. if (rcuc_starved)
  449. // Print signed value, as negative values indicate a probable bug.
  450. snprintf(buf, sizeof(buf), " rcuc=%ld jiffies(starved)", j);
  451. pr_err("\t%d-%c%c%c%c: (%lu %s) idle=%04x/%ld/%#lx softirq=%u/%u fqs=%ld%s%s\n",
  452. cpu,
  453. "O."[!!cpu_online(cpu)],
  454. "o."[!!(rdp->grpmask & rdp->mynode->qsmaskinit)],
  455. "N."[!!(rdp->grpmask & rdp->mynode->qsmaskinitnext)],
  456. !IS_ENABLED(CONFIG_IRQ_WORK) ? '?' :
  457. rdp->rcu_iw_pending ? (int)min(delta, 9UL) + '0' :
  458. "!."[!delta],
  459. ticks_value, ticks_title,
  460. ct_rcu_watching_cpu(cpu) & 0xffff,
  461. ct_nesting_cpu(cpu), ct_nmi_nesting_cpu(cpu),
  462. rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
  463. data_race(rcu_state.n_force_qs) - rcu_state.n_force_qs_gpstart,
  464. rcuc_starved ? buf : "",
  465. falsepositive ? " (false positive?)" : "");
  466. print_cpu_stat_info(cpu);
  467. }
  468. /* Complain about starvation of grace-period kthread. */
  469. static void rcu_check_gp_kthread_starvation(void)
  470. {
  471. int cpu;
  472. struct task_struct *gpk = rcu_state.gp_kthread;
  473. unsigned long j;
  474. if (rcu_is_gp_kthread_starving(&j)) {
  475. cpu = gpk ? task_cpu(gpk) : -1;
  476. pr_err("%s kthread starved for %ld jiffies! g%ld f%#x %s(%d) ->state=%#x ->cpu=%d\n",
  477. rcu_state.name, j,
  478. (long)rcu_seq_current(&rcu_state.gp_seq),
  479. data_race(READ_ONCE(rcu_state.gp_flags)),
  480. gp_state_getname(rcu_state.gp_state),
  481. data_race(READ_ONCE(rcu_state.gp_state)),
  482. gpk ? data_race(READ_ONCE(gpk->__state)) : ~0, cpu);
  483. if (gpk) {
  484. struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
  485. pr_err("\tUnless %s kthread gets sufficient CPU time, OOM is now expected behavior.\n", rcu_state.name);
  486. pr_err("RCU grace-period kthread stack dump:\n");
  487. sched_show_task(gpk);
  488. if (cpu_is_offline(cpu)) {
  489. pr_err("RCU GP kthread last ran on offline CPU %d.\n", cpu);
  490. } else if (!(data_race(READ_ONCE(rdp->mynode->qsmask)) & rdp->grpmask)) {
  491. pr_err("Stack dump where RCU GP kthread last ran:\n");
  492. dump_cpu_task(cpu);
  493. }
  494. wake_up_process(gpk);
  495. }
  496. }
  497. }
  498. /* Complain about missing wakeups from expired fqs wait timer */
  499. static void rcu_check_gp_kthread_expired_fqs_timer(void)
  500. {
  501. struct task_struct *gpk = rcu_state.gp_kthread;
  502. short gp_state;
  503. unsigned long jiffies_fqs;
  504. int cpu;
  505. /*
  506. * Order reads of .gp_state and .jiffies_force_qs.
  507. * Matching smp_wmb() is present in rcu_gp_fqs_loop().
  508. */
  509. gp_state = smp_load_acquire(&rcu_state.gp_state);
  510. jiffies_fqs = READ_ONCE(rcu_state.jiffies_force_qs);
  511. if (gp_state == RCU_GP_WAIT_FQS &&
  512. time_after(jiffies, jiffies_fqs + RCU_STALL_MIGHT_MIN) &&
  513. gpk && !READ_ONCE(gpk->on_rq)) {
  514. cpu = task_cpu(gpk);
  515. pr_err("%s kthread timer wakeup didn't happen for %ld jiffies! g%ld f%#x %s(%d) ->state=%#x\n",
  516. rcu_state.name, (jiffies - jiffies_fqs),
  517. (long)rcu_seq_current(&rcu_state.gp_seq),
  518. data_race(READ_ONCE(rcu_state.gp_flags)), // Diagnostic read
  519. gp_state_getname(RCU_GP_WAIT_FQS), RCU_GP_WAIT_FQS,
  520. data_race(READ_ONCE(gpk->__state)));
  521. pr_err("\tPossible timer handling issue on cpu=%d timer-softirq=%u\n",
  522. cpu, kstat_softirqs_cpu(TIMER_SOFTIRQ, cpu));
  523. }
  524. }
  525. static void print_other_cpu_stall(unsigned long gp_seq, unsigned long gps)
  526. {
  527. int cpu;
  528. unsigned long flags;
  529. unsigned long gpa;
  530. unsigned long j;
  531. int ndetected = 0;
  532. struct rcu_node *rnp;
  533. long totqlen = 0;
  534. lockdep_assert_irqs_disabled();
  535. /* Kick and suppress, if so configured. */
  536. rcu_stall_kick_kthreads();
  537. if (rcu_stall_is_suppressed())
  538. return;
  539. nbcon_cpu_emergency_enter();
  540. /*
  541. * OK, time to rat on our buddy...
  542. * See Documentation/RCU/stallwarn.rst for info on how to debug
  543. * RCU CPU stall warnings.
  544. */
  545. trace_rcu_stall_warning(rcu_state.name, TPS("StallDetected"));
  546. pr_err("INFO: %s detected stalls on CPUs/tasks:\n", rcu_state.name);
  547. rcu_for_each_leaf_node(rnp) {
  548. raw_spin_lock_irqsave_rcu_node(rnp, flags);
  549. if (rnp->qsmask != 0) {
  550. for_each_leaf_node_possible_cpu(rnp, cpu)
  551. if (rnp->qsmask & leaf_node_cpu_bit(rnp, cpu)) {
  552. print_cpu_stall_info(cpu);
  553. ndetected++;
  554. }
  555. }
  556. ndetected += rcu_print_task_stall(rnp, flags); // Releases rnp->lock.
  557. lockdep_assert_irqs_disabled();
  558. }
  559. for_each_possible_cpu(cpu)
  560. totqlen += rcu_get_n_cbs_cpu(cpu);
  561. pr_err("\t(detected by %d, t=%ld jiffies, g=%ld, q=%lu ncpus=%d)\n",
  562. smp_processor_id(), (long)(jiffies - gps),
  563. (long)rcu_seq_current(&rcu_state.gp_seq), totqlen,
  564. data_race(rcu_state.n_online_cpus)); // Diagnostic read
  565. if (ndetected) {
  566. rcu_dump_cpu_stacks();
  567. /* Complain about tasks blocking the grace period. */
  568. rcu_for_each_leaf_node(rnp)
  569. rcu_print_detail_task_stall_rnp(rnp);
  570. } else {
  571. if (rcu_seq_current(&rcu_state.gp_seq) != gp_seq) {
  572. pr_err("INFO: Stall ended before state dump start\n");
  573. } else {
  574. j = jiffies;
  575. gpa = data_race(READ_ONCE(rcu_state.gp_activity));
  576. pr_err("All QSes seen, last %s kthread activity %ld (%ld-%ld), jiffies_till_next_fqs=%ld, root ->qsmask %#lx\n",
  577. rcu_state.name, j - gpa, j, gpa,
  578. data_race(READ_ONCE(jiffies_till_next_fqs)),
  579. data_race(READ_ONCE(rcu_get_root()->qsmask)));
  580. }
  581. }
  582. /* Rewrite if needed in case of slow consoles. */
  583. if (ULONG_CMP_GE(jiffies, READ_ONCE(rcu_state.jiffies_stall)))
  584. WRITE_ONCE(rcu_state.jiffies_stall,
  585. jiffies + 3 * rcu_jiffies_till_stall_check() + 3);
  586. rcu_check_gp_kthread_expired_fqs_timer();
  587. rcu_check_gp_kthread_starvation();
  588. nbcon_cpu_emergency_exit();
  589. panic_on_rcu_stall();
  590. rcu_force_quiescent_state(); /* Kick them all. */
  591. }
  592. static void print_cpu_stall(unsigned long gps)
  593. {
  594. int cpu;
  595. unsigned long flags;
  596. struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
  597. struct rcu_node *rnp = rcu_get_root();
  598. long totqlen = 0;
  599. lockdep_assert_irqs_disabled();
  600. /* Kick and suppress, if so configured. */
  601. rcu_stall_kick_kthreads();
  602. if (rcu_stall_is_suppressed())
  603. return;
  604. nbcon_cpu_emergency_enter();
  605. /*
  606. * OK, time to rat on ourselves...
  607. * See Documentation/RCU/stallwarn.rst for info on how to debug
  608. * RCU CPU stall warnings.
  609. */
  610. trace_rcu_stall_warning(rcu_state.name, TPS("SelfDetected"));
  611. pr_err("INFO: %s self-detected stall on CPU\n", rcu_state.name);
  612. raw_spin_lock_irqsave_rcu_node(rdp->mynode, flags);
  613. print_cpu_stall_info(smp_processor_id());
  614. raw_spin_unlock_irqrestore_rcu_node(rdp->mynode, flags);
  615. for_each_possible_cpu(cpu)
  616. totqlen += rcu_get_n_cbs_cpu(cpu);
  617. pr_err("\t(t=%lu jiffies g=%ld q=%lu ncpus=%d)\n",
  618. jiffies - gps,
  619. (long)rcu_seq_current(&rcu_state.gp_seq), totqlen,
  620. data_race(rcu_state.n_online_cpus)); // Diagnostic read
  621. rcu_check_gp_kthread_expired_fqs_timer();
  622. rcu_check_gp_kthread_starvation();
  623. rcu_dump_cpu_stacks();
  624. raw_spin_lock_irqsave_rcu_node(rnp, flags);
  625. /* Rewrite if needed in case of slow consoles. */
  626. if (ULONG_CMP_GE(jiffies, READ_ONCE(rcu_state.jiffies_stall)))
  627. WRITE_ONCE(rcu_state.jiffies_stall,
  628. jiffies + 3 * rcu_jiffies_till_stall_check() + 3);
  629. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  630. nbcon_cpu_emergency_exit();
  631. panic_on_rcu_stall();
  632. /*
  633. * Attempt to revive the RCU machinery by forcing a context switch.
  634. *
  635. * A context switch would normally allow the RCU state machine to make
  636. * progress and it could be we're stuck in kernel space without context
  637. * switches for an entirely unreasonable amount of time.
  638. */
  639. set_tsk_need_resched(current);
  640. set_preempt_need_resched();
  641. }
  642. static bool csd_lock_suppress_rcu_stall;
  643. module_param(csd_lock_suppress_rcu_stall, bool, 0644);
  644. static void check_cpu_stall(struct rcu_data *rdp)
  645. {
  646. bool self_detected;
  647. unsigned long gs1;
  648. unsigned long gs2;
  649. unsigned long gps;
  650. unsigned long j;
  651. unsigned long jn;
  652. unsigned long js;
  653. struct rcu_node *rnp;
  654. lockdep_assert_irqs_disabled();
  655. if ((rcu_stall_is_suppressed() && !READ_ONCE(rcu_kick_kthreads)) ||
  656. !rcu_gp_in_progress())
  657. return;
  658. rcu_stall_kick_kthreads();
  659. /*
  660. * Check if it was requested (via rcu_cpu_stall_reset()) that the FQS
  661. * loop has to set jiffies to ensure a non-stale jiffies value. This
  662. * is required to have good jiffies value after coming out of long
  663. * breaks of jiffies updates. Not doing so can cause false positives.
  664. */
  665. if (READ_ONCE(rcu_state.nr_fqs_jiffies_stall) > 0)
  666. return;
  667. j = jiffies;
  668. /*
  669. * Lots of memory barriers to reject false positives.
  670. *
  671. * The idea is to pick up rcu_state.gp_seq, then
  672. * rcu_state.jiffies_stall, then rcu_state.gp_start, and finally
  673. * another copy of rcu_state.gp_seq. These values are updated in
  674. * the opposite order with memory barriers (or equivalent) during
  675. * grace-period initialization and cleanup. Now, a false positive
  676. * can occur if we get an new value of rcu_state.gp_start and a old
  677. * value of rcu_state.jiffies_stall. But given the memory barriers,
  678. * the only way that this can happen is if one grace period ends
  679. * and another starts between these two fetches. This is detected
  680. * by comparing the second fetch of rcu_state.gp_seq with the
  681. * previous fetch from rcu_state.gp_seq.
  682. *
  683. * Given this check, comparisons of jiffies, rcu_state.jiffies_stall,
  684. * and rcu_state.gp_start suffice to forestall false positives.
  685. */
  686. gs1 = READ_ONCE(rcu_state.gp_seq);
  687. smp_rmb(); /* Pick up ->gp_seq first... */
  688. js = READ_ONCE(rcu_state.jiffies_stall);
  689. smp_rmb(); /* ...then ->jiffies_stall before the rest... */
  690. gps = READ_ONCE(rcu_state.gp_start);
  691. smp_rmb(); /* ...and finally ->gp_start before ->gp_seq again. */
  692. gs2 = READ_ONCE(rcu_state.gp_seq);
  693. if (gs1 != gs2 ||
  694. ULONG_CMP_LT(j, js) ||
  695. ULONG_CMP_GE(gps, js))
  696. return; /* No stall or GP completed since entering function. */
  697. rnp = rdp->mynode;
  698. jn = jiffies + ULONG_MAX / 2;
  699. self_detected = READ_ONCE(rnp->qsmask) & rdp->grpmask;
  700. if (rcu_gp_in_progress() &&
  701. (self_detected || ULONG_CMP_GE(j, js + RCU_STALL_RAT_DELAY)) &&
  702. cmpxchg(&rcu_state.jiffies_stall, js, jn) == js) {
  703. /*
  704. * If a virtual machine is stopped by the host it can look to
  705. * the watchdog like an RCU stall. Check to see if the host
  706. * stopped the vm.
  707. */
  708. if (kvm_check_and_clear_guest_paused())
  709. return;
  710. rcu_stall_notifier_call_chain(RCU_STALL_NOTIFY_NORM, (void *)j - gps);
  711. if (READ_ONCE(csd_lock_suppress_rcu_stall) && csd_lock_is_stuck()) {
  712. pr_err("INFO: %s detected stall, but suppressed full report due to a stuck CSD-lock.\n", rcu_state.name);
  713. } else if (self_detected) {
  714. /* We haven't checked in, so go dump stack. */
  715. print_cpu_stall(gps);
  716. } else {
  717. /* They had a few time units to dump stack, so complain. */
  718. print_other_cpu_stall(gs2, gps);
  719. }
  720. if (READ_ONCE(rcu_cpu_stall_ftrace_dump))
  721. rcu_ftrace_dump(DUMP_ALL);
  722. if (READ_ONCE(rcu_state.jiffies_stall) == jn) {
  723. jn = jiffies + 3 * rcu_jiffies_till_stall_check() + 3;
  724. WRITE_ONCE(rcu_state.jiffies_stall, jn);
  725. }
  726. }
  727. }
  728. //////////////////////////////////////////////////////////////////////////////
  729. //
  730. // RCU forward-progress mechanisms, including for callback invocation.
  731. /*
  732. * Check to see if a failure to end RCU priority inversion was due to
  733. * a CPU not passing through a quiescent state. When this happens, there
  734. * is nothing that RCU priority boosting can do to help, so we shouldn't
  735. * count this as an RCU priority boosting failure. A return of true says
  736. * RCU priority boosting is to blame, and false says otherwise. If false
  737. * is returned, the first of the CPUs to blame is stored through cpup.
  738. * If there was no CPU blocking the current grace period, but also nothing
  739. * in need of being boosted, *cpup is set to -1. This can happen in case
  740. * of vCPU preemption while the last CPU is reporting its quiscent state,
  741. * for example.
  742. *
  743. * If cpup is NULL, then a lockless quick check is carried out, suitable
  744. * for high-rate usage. On the other hand, if cpup is non-NULL, each
  745. * rcu_node structure's ->lock is acquired, ruling out high-rate usage.
  746. */
  747. bool rcu_check_boost_fail(unsigned long gp_state, int *cpup)
  748. {
  749. bool atb = false;
  750. int cpu;
  751. unsigned long flags;
  752. struct rcu_node *rnp;
  753. rcu_for_each_leaf_node(rnp) {
  754. if (!cpup) {
  755. if (data_race(READ_ONCE(rnp->qsmask))) {
  756. return false;
  757. } else {
  758. if (READ_ONCE(rnp->gp_tasks))
  759. atb = true;
  760. continue;
  761. }
  762. }
  763. *cpup = -1;
  764. raw_spin_lock_irqsave_rcu_node(rnp, flags);
  765. if (rnp->gp_tasks)
  766. atb = true;
  767. if (!rnp->qsmask) {
  768. // No CPUs without quiescent states for this rnp.
  769. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  770. continue;
  771. }
  772. // Find the first holdout CPU.
  773. for_each_leaf_node_possible_cpu(rnp, cpu) {
  774. if (rnp->qsmask & (1UL << (cpu - rnp->grplo))) {
  775. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  776. *cpup = cpu;
  777. return false;
  778. }
  779. }
  780. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  781. }
  782. // Can't blame CPUs, so must blame RCU priority boosting.
  783. return atb;
  784. }
  785. EXPORT_SYMBOL_GPL(rcu_check_boost_fail);
  786. /*
  787. * Show the state of the grace-period kthreads.
  788. */
  789. void show_rcu_gp_kthreads(void)
  790. {
  791. unsigned long cbs = 0;
  792. int cpu;
  793. unsigned long j;
  794. unsigned long ja;
  795. unsigned long jr;
  796. unsigned long js;
  797. unsigned long jw;
  798. struct rcu_data *rdp;
  799. struct rcu_node *rnp;
  800. struct task_struct *t = READ_ONCE(rcu_state.gp_kthread);
  801. j = jiffies;
  802. ja = j - data_race(READ_ONCE(rcu_state.gp_activity));
  803. jr = j - data_race(READ_ONCE(rcu_state.gp_req_activity));
  804. js = j - data_race(READ_ONCE(rcu_state.gp_start));
  805. jw = j - data_race(READ_ONCE(rcu_state.gp_wake_time));
  806. pr_info("%s: wait state: %s(%d) ->state: %#x ->rt_priority %u delta ->gp_start %lu ->gp_activity %lu ->gp_req_activity %lu ->gp_wake_time %lu ->gp_wake_seq %ld ->gp_seq %ld ->gp_seq_needed %ld ->gp_max %lu ->gp_flags %#x\n",
  807. rcu_state.name, gp_state_getname(rcu_state.gp_state),
  808. data_race(READ_ONCE(rcu_state.gp_state)),
  809. t ? data_race(READ_ONCE(t->__state)) : 0x1ffff, t ? t->rt_priority : 0xffU,
  810. js, ja, jr, jw, (long)data_race(READ_ONCE(rcu_state.gp_wake_seq)),
  811. (long)data_race(READ_ONCE(rcu_state.gp_seq)),
  812. (long)data_race(READ_ONCE(rcu_get_root()->gp_seq_needed)),
  813. data_race(READ_ONCE(rcu_state.gp_max)),
  814. data_race(READ_ONCE(rcu_state.gp_flags)));
  815. rcu_for_each_node_breadth_first(rnp) {
  816. if (ULONG_CMP_GE(READ_ONCE(rcu_state.gp_seq), READ_ONCE(rnp->gp_seq_needed)) &&
  817. !data_race(READ_ONCE(rnp->qsmask)) && !data_race(READ_ONCE(rnp->boost_tasks)) &&
  818. !data_race(READ_ONCE(rnp->exp_tasks)) && !data_race(READ_ONCE(rnp->gp_tasks)))
  819. continue;
  820. pr_info("\trcu_node %d:%d ->gp_seq %ld ->gp_seq_needed %ld ->qsmask %#lx %c%c%c%c ->n_boosts %ld\n",
  821. rnp->grplo, rnp->grphi,
  822. (long)data_race(READ_ONCE(rnp->gp_seq)),
  823. (long)data_race(READ_ONCE(rnp->gp_seq_needed)),
  824. data_race(READ_ONCE(rnp->qsmask)),
  825. ".b"[!!data_race(READ_ONCE(rnp->boost_kthread_task))],
  826. ".B"[!!data_race(READ_ONCE(rnp->boost_tasks))],
  827. ".E"[!!data_race(READ_ONCE(rnp->exp_tasks))],
  828. ".G"[!!data_race(READ_ONCE(rnp->gp_tasks))],
  829. data_race(READ_ONCE(rnp->n_boosts)));
  830. if (!rcu_is_leaf_node(rnp))
  831. continue;
  832. for_each_leaf_node_possible_cpu(rnp, cpu) {
  833. rdp = per_cpu_ptr(&rcu_data, cpu);
  834. if (READ_ONCE(rdp->gpwrap) ||
  835. ULONG_CMP_GE(READ_ONCE(rcu_state.gp_seq),
  836. READ_ONCE(rdp->gp_seq_needed)))
  837. continue;
  838. pr_info("\tcpu %d ->gp_seq_needed %ld\n",
  839. cpu, (long)data_race(READ_ONCE(rdp->gp_seq_needed)));
  840. }
  841. }
  842. for_each_possible_cpu(cpu) {
  843. rdp = per_cpu_ptr(&rcu_data, cpu);
  844. cbs += data_race(READ_ONCE(rdp->n_cbs_invoked));
  845. if (rcu_segcblist_is_offloaded(&rdp->cblist))
  846. show_rcu_nocb_state(rdp);
  847. }
  848. pr_info("RCU callbacks invoked since boot: %lu\n", cbs);
  849. show_rcu_tasks_gp_kthreads();
  850. }
  851. EXPORT_SYMBOL_GPL(show_rcu_gp_kthreads);
  852. /*
  853. * This function checks for grace-period requests that fail to motivate
  854. * RCU to come out of its idle mode.
  855. */
  856. static void rcu_check_gp_start_stall(struct rcu_node *rnp, struct rcu_data *rdp,
  857. const unsigned long gpssdelay)
  858. {
  859. unsigned long flags;
  860. unsigned long j;
  861. struct rcu_node *rnp_root = rcu_get_root();
  862. static atomic_t warned = ATOMIC_INIT(0);
  863. if (!IS_ENABLED(CONFIG_PROVE_RCU) || rcu_gp_in_progress() ||
  864. ULONG_CMP_GE(READ_ONCE(rnp_root->gp_seq),
  865. READ_ONCE(rnp_root->gp_seq_needed)) ||
  866. !smp_load_acquire(&rcu_state.gp_kthread)) // Get stable kthread.
  867. return;
  868. j = jiffies; /* Expensive access, and in common case don't get here. */
  869. if (time_before(j, READ_ONCE(rcu_state.gp_req_activity) + gpssdelay) ||
  870. time_before(j, READ_ONCE(rcu_state.gp_activity) + gpssdelay) ||
  871. atomic_read(&warned))
  872. return;
  873. raw_spin_lock_irqsave_rcu_node(rnp, flags);
  874. j = jiffies;
  875. if (rcu_gp_in_progress() ||
  876. ULONG_CMP_GE(READ_ONCE(rnp_root->gp_seq),
  877. READ_ONCE(rnp_root->gp_seq_needed)) ||
  878. time_before(j, READ_ONCE(rcu_state.gp_req_activity) + gpssdelay) ||
  879. time_before(j, READ_ONCE(rcu_state.gp_activity) + gpssdelay) ||
  880. atomic_read(&warned)) {
  881. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  882. return;
  883. }
  884. /* Hold onto the leaf lock to make others see warned==1. */
  885. if (rnp_root != rnp)
  886. raw_spin_lock_rcu_node(rnp_root); /* irqs already disabled. */
  887. j = jiffies;
  888. if (rcu_gp_in_progress() ||
  889. ULONG_CMP_GE(READ_ONCE(rnp_root->gp_seq),
  890. READ_ONCE(rnp_root->gp_seq_needed)) ||
  891. time_before(j, READ_ONCE(rcu_state.gp_req_activity) + gpssdelay) ||
  892. time_before(j, READ_ONCE(rcu_state.gp_activity) + gpssdelay) ||
  893. atomic_xchg(&warned, 1)) {
  894. if (rnp_root != rnp)
  895. /* irqs remain disabled. */
  896. raw_spin_unlock_rcu_node(rnp_root);
  897. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  898. return;
  899. }
  900. WARN_ON(1);
  901. if (rnp_root != rnp)
  902. raw_spin_unlock_rcu_node(rnp_root);
  903. raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
  904. show_rcu_gp_kthreads();
  905. }
  906. /*
  907. * Do a forward-progress check for rcutorture. This is normally invoked
  908. * due to an OOM event. The argument "j" gives the time period during
  909. * which rcutorture would like progress to have been made.
  910. */
  911. void rcu_fwd_progress_check(unsigned long j)
  912. {
  913. unsigned long cbs;
  914. int cpu;
  915. unsigned long max_cbs = 0;
  916. int max_cpu = -1;
  917. struct rcu_data *rdp;
  918. if (rcu_gp_in_progress()) {
  919. pr_info("%s: GP age %lu jiffies\n",
  920. __func__, jiffies - data_race(READ_ONCE(rcu_state.gp_start)));
  921. show_rcu_gp_kthreads();
  922. } else {
  923. pr_info("%s: Last GP end %lu jiffies ago\n",
  924. __func__, jiffies - data_race(READ_ONCE(rcu_state.gp_end)));
  925. preempt_disable();
  926. rdp = this_cpu_ptr(&rcu_data);
  927. rcu_check_gp_start_stall(rdp->mynode, rdp, j);
  928. preempt_enable();
  929. }
  930. for_each_possible_cpu(cpu) {
  931. cbs = rcu_get_n_cbs_cpu(cpu);
  932. if (!cbs)
  933. continue;
  934. if (max_cpu < 0)
  935. pr_info("%s: callbacks", __func__);
  936. pr_cont(" %d: %lu", cpu, cbs);
  937. if (cbs <= max_cbs)
  938. continue;
  939. max_cbs = cbs;
  940. max_cpu = cpu;
  941. }
  942. if (max_cpu >= 0)
  943. pr_cont("\n");
  944. }
  945. EXPORT_SYMBOL_GPL(rcu_fwd_progress_check);
  946. /* Commandeer a sysrq key to dump RCU's tree. */
  947. static bool sysrq_rcu;
  948. module_param(sysrq_rcu, bool, 0444);
  949. /* Dump grace-period-request information due to commandeered sysrq. */
  950. static void sysrq_show_rcu(u8 key)
  951. {
  952. show_rcu_gp_kthreads();
  953. }
  954. static const struct sysrq_key_op sysrq_rcudump_op = {
  955. .handler = sysrq_show_rcu,
  956. .help_msg = "show-rcu(y)",
  957. .action_msg = "Show RCU tree",
  958. .enable_mask = SYSRQ_ENABLE_DUMP,
  959. };
  960. static int __init rcu_sysrq_init(void)
  961. {
  962. if (sysrq_rcu)
  963. return register_sysrq_key('y', &sysrq_rcudump_op);
  964. return 0;
  965. }
  966. early_initcall(rcu_sysrq_init);
  967. #ifdef CONFIG_RCU_CPU_STALL_NOTIFIER
  968. //////////////////////////////////////////////////////////////////////////////
  969. //
  970. // RCU CPU stall-warning notifiers
  971. static ATOMIC_NOTIFIER_HEAD(rcu_cpu_stall_notifier_list);
  972. /**
  973. * rcu_stall_chain_notifier_register - Add an RCU CPU stall notifier
  974. * @n: Entry to add.
  975. *
  976. * Adds an RCU CPU stall notifier to an atomic notifier chain.
  977. * The @action passed to a notifier will be @RCU_STALL_NOTIFY_NORM or
  978. * friends. The @data will be the duration of the stalled grace period,
  979. * in jiffies, coerced to a void* pointer.
  980. *
  981. * Returns 0 on success, %-EEXIST on error.
  982. */
  983. int rcu_stall_chain_notifier_register(struct notifier_block *n)
  984. {
  985. int rcsn = rcu_cpu_stall_notifiers;
  986. WARN(1, "Adding %pS() to RCU stall notifier list (%s).\n", n->notifier_call,
  987. rcsn ? "possibly suppressing RCU CPU stall warnings" : "failed, so all is well");
  988. if (rcsn)
  989. return atomic_notifier_chain_register(&rcu_cpu_stall_notifier_list, n);
  990. return -EEXIST;
  991. }
  992. EXPORT_SYMBOL_GPL(rcu_stall_chain_notifier_register);
  993. /**
  994. * rcu_stall_chain_notifier_unregister - Remove an RCU CPU stall notifier
  995. * @n: Entry to add.
  996. *
  997. * Removes an RCU CPU stall notifier from an atomic notifier chain.
  998. *
  999. * Returns zero on success, %-ENOENT on failure.
  1000. */
  1001. int rcu_stall_chain_notifier_unregister(struct notifier_block *n)
  1002. {
  1003. return atomic_notifier_chain_unregister(&rcu_cpu_stall_notifier_list, n);
  1004. }
  1005. EXPORT_SYMBOL_GPL(rcu_stall_chain_notifier_unregister);
  1006. /*
  1007. * rcu_stall_notifier_call_chain - Call functions in an RCU CPU stall notifier chain
  1008. * @val: Value passed unmodified to notifier function
  1009. * @v: Pointer passed unmodified to notifier function
  1010. *
  1011. * Calls each function in the RCU CPU stall notifier chain in turn, which
  1012. * is an atomic call chain. See atomic_notifier_call_chain() for more
  1013. * information.
  1014. *
  1015. * This is for use within RCU, hence the omission of the extra asterisk
  1016. * to indicate a non-kerneldoc format header comment.
  1017. */
  1018. int rcu_stall_notifier_call_chain(unsigned long val, void *v)
  1019. {
  1020. return atomic_notifier_call_chain(&rcu_cpu_stall_notifier_list, val, v);
  1021. }
  1022. #endif // #ifdef CONFIG_RCU_CPU_STALL_NOTIFIER