Skip to content

Commit 5648d65

Browse files
committed
rcu: Don't flag non-starting GPs before GP kthread is running
Currently rcu_check_gp_start_stall() complains if a grace period takes too long to start, where "too long" is roughly one RCU CPU stall-warning interval. This has worked well, but there are some debugging Kconfig options (such as CONFIG_EFI_PGT_DUMP=y) that can make booting take a very long time, so much so that the stall-warning interval has expired before RCU's grace-period kthread has even been spawned. This commit therefore resets the rcu_state.gp_req_activity and rcu_state.gp_activity timestamps just before the grace-period kthread is spawned, and modifies the checks and adds ordering to ensure that if rcu_check_gp_start_stall() sees that the grace-period kthread has been spawned, that it will also see the resets applied to the rcu_state.gp_req_activity and rcu_state.gp_activity timestamps. Reported-by: Qian Cai <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]> [ paulmck: Fix whitespace issues reported by Qian Cai. ] Tested-by: Qian Cai <[email protected]> [ paulmck: Simplify grace-period wakeup check per Steve Rostedt feedback. ]
1 parent 4dfd5cd commit 5648d65

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

kernel/rcu/tree.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ static bool rcu_start_this_gp(struct rcu_node *rnp_start, struct rcu_data *rdp,
12021202
trace_rcu_this_gp(rnp, rdp, gp_seq_req, TPS("Startedroot"));
12031203
WRITE_ONCE(rcu_state.gp_flags, rcu_state.gp_flags | RCU_GP_FLAG_INIT);
12041204
WRITE_ONCE(rcu_state.gp_req_activity, jiffies);
1205-
if (!rcu_state.gp_kthread) {
1205+
if (!READ_ONCE(rcu_state.gp_kthread)) {
12061206
trace_rcu_this_gp(rnp, rdp, gp_seq_req, TPS("NoGPkthread"));
12071207
goto unlock_out;
12081208
}
@@ -1237,12 +1237,13 @@ static bool rcu_future_gp_cleanup(struct rcu_node *rnp)
12371237
}
12381238

12391239
/*
1240-
* Awaken the grace-period kthread. Don't do a self-awaken (unless in
1241-
* an interrupt or softirq handler), and don't bother awakening when there
1242-
* is nothing for the grace-period kthread to do (as in several CPUs raced
1243-
* to awaken, and we lost), and finally don't try to awaken a kthread that
1244-
* has not yet been created. If all those checks are passed, track some
1245-
* debug information and awaken.
1240+
* Awaken the grace-period kthread. Don't do a self-awaken (unless in an
1241+
* interrupt or softirq handler, in which case we just might immediately
1242+
* sleep upon return, resulting in a grace-period hang), and don't bother
1243+
* awakening when there is nothing for the grace-period kthread to do
1244+
* (as in several CPUs raced to awaken, we lost), and finally don't try
1245+
* to awaken a kthread that has not yet been created. If all those checks
1246+
* are passed, track some debug information and awaken.
12461247
*
12471248
* So why do the self-wakeup when in an interrupt or softirq handler
12481249
* in the grace-period kthread's context? Because the kthread might have
@@ -1252,10 +1253,10 @@ static bool rcu_future_gp_cleanup(struct rcu_node *rnp)
12521253
*/
12531254
static void rcu_gp_kthread_wake(void)
12541255
{
1255-
if ((current == rcu_state.gp_kthread &&
1256-
!in_irq() && !in_serving_softirq()) ||
1257-
!READ_ONCE(rcu_state.gp_flags) ||
1258-
!rcu_state.gp_kthread)
1256+
struct task_struct *t = READ_ONCE(rcu_state.gp_kthread);
1257+
1258+
if ((current == t && !in_irq() && !in_serving_softirq()) ||
1259+
!READ_ONCE(rcu_state.gp_flags) || !t)
12591260
return;
12601261
WRITE_ONCE(rcu_state.gp_wake_time, jiffies);
12611262
WRITE_ONCE(rcu_state.gp_wake_seq, READ_ONCE(rcu_state.gp_seq));
@@ -3554,7 +3555,10 @@ static int __init rcu_spawn_gp_kthread(void)
35543555
}
35553556
rnp = rcu_get_root();
35563557
raw_spin_lock_irqsave_rcu_node(rnp, flags);
3557-
rcu_state.gp_kthread = t;
3558+
WRITE_ONCE(rcu_state.gp_activity, jiffies);
3559+
WRITE_ONCE(rcu_state.gp_req_activity, jiffies);
3560+
// Reset .gp_activity and .gp_req_activity before setting .gp_kthread.
3561+
smp_store_release(&rcu_state.gp_kthread, t); /* ^^^ */
35583562
raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
35593563
wake_up_process(t);
35603564
rcu_spawn_nocb_kthreads();

kernel/rcu/tree_stall.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -578,15 +578,15 @@ void show_rcu_gp_kthreads(void)
578578
unsigned long jw;
579579
struct rcu_data *rdp;
580580
struct rcu_node *rnp;
581+
struct task_struct *t = READ_ONCE(rcu_state.gp_kthread);
581582

582583
j = jiffies;
583584
ja = j - READ_ONCE(rcu_state.gp_activity);
584585
jr = j - READ_ONCE(rcu_state.gp_req_activity);
585586
jw = j - READ_ONCE(rcu_state.gp_wake_time);
586587
pr_info("%s: wait state: %s(%d) ->state: %#lx delta ->gp_activity %lu ->gp_req_activity %lu ->gp_wake_time %lu ->gp_wake_seq %ld ->gp_seq %ld ->gp_seq_needed %ld ->gp_flags %#x\n",
587588
rcu_state.name, gp_state_getname(rcu_state.gp_state),
588-
rcu_state.gp_state,
589-
rcu_state.gp_kthread ? rcu_state.gp_kthread->state : 0x1ffffL,
589+
rcu_state.gp_state, t ? t->state : 0x1ffffL,
590590
ja, jr, jw, (long)READ_ONCE(rcu_state.gp_wake_seq),
591591
(long)READ_ONCE(rcu_state.gp_seq),
592592
(long)READ_ONCE(rcu_get_root()->gp_seq_needed),
@@ -633,7 +633,8 @@ static void rcu_check_gp_start_stall(struct rcu_node *rnp, struct rcu_data *rdp,
633633

634634
if (!IS_ENABLED(CONFIG_PROVE_RCU) || rcu_gp_in_progress() ||
635635
ULONG_CMP_GE(READ_ONCE(rnp_root->gp_seq),
636-
READ_ONCE(rnp_root->gp_seq_needed)))
636+
READ_ONCE(rnp_root->gp_seq_needed)) ||
637+
!smp_load_acquire(&rcu_state.gp_kthread)) // Get stable kthread.
637638
return;
638639
j = jiffies; /* Expensive access, and in common case don't get here. */
639640
if (time_before(j, READ_ONCE(rcu_state.gp_req_activity) + gpssdelay) ||

0 commit comments

Comments
 (0)