File Index
Files and directories
Sign in
FILE

tree_stall.h

File preview with syntax highlighting.

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