Skip to content

Commit ac3caf8

Browse files
committed
rcu: Add comments marking transitions between RCU watching and not
It is not as clear as it might be just where in RCU's idle entry/exit code RCU stops and starts watching the current CPU. This commit therefore adds comments calling out the transitions. Reported-by: Thomas Gleixner <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]>
1 parent 52b1fc3 commit ac3caf8

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

kernel/rcu/tree.c

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,9 @@ void rcu_softirq_qs(void)
238238

239239
/*
240240
* Record entry into an extended quiescent state. This is only to be
241-
* called when not already in an extended quiescent state.
241+
* called when not already in an extended quiescent state, that is,
242+
* RCU is watching prior to the call to this function and is no longer
243+
* watching upon return.
242244
*/
243245
static void rcu_dynticks_eqs_enter(void)
244246
{
@@ -251,7 +253,7 @@ static void rcu_dynticks_eqs_enter(void)
251253
* next idle sojourn.
252254
*/
253255
seq = atomic_add_return(RCU_DYNTICK_CTRL_CTR, &rdp->dynticks);
254-
/* Better be in an extended quiescent state! */
256+
// RCU is no longer watching. Better be in extended quiescent state!
255257
WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) &&
256258
(seq & RCU_DYNTICK_CTRL_CTR));
257259
/* Better not have special action (TLB flush) pending! */
@@ -261,7 +263,8 @@ static void rcu_dynticks_eqs_enter(void)
261263

262264
/*
263265
* Record exit from an extended quiescent state. This is only to be
264-
* called from an extended quiescent state.
266+
* called from an extended quiescent state, that is, RCU is not watching
267+
* prior to the call to this function and is watching upon return.
265268
*/
266269
static void rcu_dynticks_eqs_exit(void)
267270
{
@@ -274,6 +277,7 @@ static void rcu_dynticks_eqs_exit(void)
274277
* critical section.
275278
*/
276279
seq = atomic_add_return(RCU_DYNTICK_CTRL_CTR, &rdp->dynticks);
280+
// RCU is now watching. Better not be in an extended quiescent state!
277281
WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) &&
278282
!(seq & RCU_DYNTICK_CTRL_CTR));
279283
if (seq & RCU_DYNTICK_CTRL_MASK) {
@@ -584,6 +588,7 @@ static void rcu_eqs_enter(bool user)
584588
WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) &&
585589
rdp->dynticks_nesting == 0);
586590
if (rdp->dynticks_nesting != 1) {
591+
// RCU will still be watching, so just do accounting and leave.
587592
rdp->dynticks_nesting--;
588593
return;
589594
}
@@ -596,7 +601,9 @@ static void rcu_eqs_enter(bool user)
596601
rcu_prepare_for_idle();
597602
rcu_preempt_deferred_qs(current);
598603
WRITE_ONCE(rdp->dynticks_nesting, 0); /* Avoid irq-access tearing. */
604+
// RCU is watching here ...
599605
rcu_dynticks_eqs_enter();
606+
// ... but is no longer watching here.
600607
rcu_dynticks_task_enter();
601608
}
602609

@@ -676,7 +683,9 @@ static __always_inline void rcu_nmi_exit_common(bool irq)
676683
if (irq)
677684
rcu_prepare_for_idle();
678685

686+
// RCU is watching here ...
679687
rcu_dynticks_eqs_enter();
688+
// ... but is no longer watching here.
680689

681690
if (irq)
682691
rcu_dynticks_task_enter();
@@ -751,11 +760,14 @@ static void rcu_eqs_exit(bool user)
751760
oldval = rdp->dynticks_nesting;
752761
WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && oldval < 0);
753762
if (oldval) {
763+
// RCU was already watching, so just do accounting and leave.
754764
rdp->dynticks_nesting++;
755765
return;
756766
}
757767
rcu_dynticks_task_exit();
768+
// RCU is not watching here ...
758769
rcu_dynticks_eqs_exit();
770+
// ... but is watching here.
759771
rcu_cleanup_after_idle();
760772
trace_rcu_dyntick(TPS("End"), rdp->dynticks_nesting, 1, atomic_read(&rdp->dynticks));
761773
WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && !user && !is_idle_task(current));
@@ -832,7 +844,9 @@ static __always_inline void rcu_nmi_enter_common(bool irq)
832844
if (irq)
833845
rcu_dynticks_task_exit();
834846

847+
// RCU is not watching here ...
835848
rcu_dynticks_eqs_exit();
849+
// ... but is watching here.
836850

837851
if (irq)
838852
rcu_cleanup_after_idle();
@@ -842,9 +856,16 @@ static __always_inline void rcu_nmi_enter_common(bool irq)
842856
rdp->dynticks_nmi_nesting == DYNTICK_IRQ_NONIDLE &&
843857
READ_ONCE(rdp->rcu_urgent_qs) &&
844858
!READ_ONCE(rdp->rcu_forced_tick)) {
859+
// We get here only if we had already exited the extended
860+
// quiescent state and this was an interrupt (not an NMI).
861+
// Therefore, (1) RCU is already watching and (2) The fact
862+
// that we are in an interrupt handler and that the rcu_node
863+
// lock is an irq-disabled lock prevents self-deadlock.
864+
// So we can safely recheck under the lock.
845865
raw_spin_lock_rcu_node(rdp->mynode);
846-
// Recheck under lock.
847866
if (rdp->rcu_urgent_qs && !rdp->rcu_forced_tick) {
867+
// A nohz_full CPU is in the kernel and RCU
868+
// needs a quiescent state. Turn on the tick!
848869
WRITE_ONCE(rdp->rcu_forced_tick, true);
849870
tick_dep_set_cpu(rdp->cpu, TICK_DEP_BIT_RCU);
850871
}

0 commit comments

Comments
 (0)