public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
To: Lai Jiangshan <laijs@cn.fujitsu.com>
Cc: linux-kernel@vger.kernel.org, mingo@elte.hu, dipankar@in.ibm.com,
	akpm@linux-foundation.org, mathieu.desnoyers@polymtl.ca,
	josh@joshtriplett.org, dvhltc@us.ibm.com, niv@us.ibm.com,
	tglx@linutronix.de, peterz@infradead.org, rostedt@goodmis.org,
	Valdis.Kletnieks@vt.edu, dhowells@redhat.com, avi@redhat.com,
	mtosatti@redhat.com, torvalds@linux-foundation.org
Subject: Re: [PATCH RFC tip/core/rcu 1/3] rcu: The Bloatwatch Edition, v7
Date: Tue, 13 Oct 2009 19:52:35 -0700	[thread overview]
Message-ID: <20091014025235.GB6840@linux.vnet.ibm.com> (raw)
In-Reply-To: <4AD531E5.6070103@cn.fujitsu.com>

On Wed, Oct 14, 2009 at 10:05:25AM +0800, Lai Jiangshan wrote:
> Paul E. McKenney wrote:
> > On Wed, Oct 14, 2009 at 08:37:18AM +0800, Lai Jiangshan wrote:
> >> Paul E. McKenney wrote:
> >>>> It's an old issue.
> >>>> It's not only about RCUTINY, it's also about other rcu implementations:
> >>>>
> >>>> rcu_enter_nohz()/rcu_exit_nohz() are not called in pairs.
> >>>>
> >>>> irq_exit() calls tick_nohz_stop_sched_tick() which calls rcu_enter_nohz(),
> >>>> where is the corresponding rcu_exit_nohz()?
> >>>> (or tick_nohz_restart_sched_tick())?
> >>> The tick_nohz_restart_sched_tick() function is called from the various
> >>> per-architecture cpu_idle() functions (or default_idle() or whatever
> >>> name that the architecture uses).  For example, in:
> >>>
> >>> 	arch/x86/kernel/process_64.c
> >>>
> >>> the cpu_idle() function invokes tick_nohz_restart_sched_tick() just
> >>> before invoking schedule() to exit the idle loop.
> >>>
> >>> And, as you say, tick_nohz_restart_sched_tick() invokes rcu_exit_nohz().
> >> These tick_nohz_restart_sched_tick() which are called from the various
> >> per-architecture cpu_idle() functions are not the opposite of
> >> the tick_nohz_stop_sched_tick() in *irq_exit()*. So I figure that 
> >> rcu_enter_nohz()/rcu_exit_nohz() are not called in pairs.
> > 
> > OK, let's start with rcu_enter_nohz(), which tells RCU that the running
> > CPU is going into dyntick-idle mode, and thus should be ignored by RCU.
> > Let's do the idle loop first:
> > 
> > o	Upon entry to the idle() loop (using cpu_idle() in
> > 	arch/x86/kernel/process_64.c for this exercise),
> > 	we invoke tick_nohz_stop_sched_tick(1), which says we
> > 	are in an idle loop.  (This is in contrast to the call
> > 	from irq_exit(), where we are not in the idle loop.)
> > 
> > o	tick_nohz_stop_sched_tick() invokes rcu_enter_nohz(),
> > 	does a bunch of timer checking, and returns.  If anything
> > 	indicated that entering dyntick-idle mode would be bad,
> > 	we raise TIMER_SOFTIRQ to kick us out of this mode.
> > 
> > 	Either way, we return to the idle loop.
> > 
> > o	The idle loops until need_resched().  Upon exit from the
> > 	idle loop, we call tick_nohz_restart_sched_tick(), which
> > 	invokes rcu_exit_nohz(), which tells RCU to start paying
> > 	attention to this CPU once more.
> > 
> > OK, now for interrupts.
> > 
> > o	The hardware interrupt handlers invoke irq_enter(), which in
> > 	turn invokes rcu_irq_enter().  This has no real effect (other
> > 	than incrementing a counter) if the interrupt did not come
> > 	from dyntick-idle mode.
> > 
> > 	Either way, RCU is now paying attention to RCU read-side
> > 	critical sections on this CPU.
> > 
> > o	Upon return from interrupt, the hardware interrupt handlers
> > 	invoke irq_exit(), which in turn invokes rcu_irq_exit().
> > 	This has no real effect (other than decrementing a counter)
> > 	if the interrupt is not returning to dyntick-idle mode.
> > 
> > 	However, if the interrupt -is- returning to dyntick-idle
> > 	mode, then RCU will stop paying attention to RCU read-side
> > 	critical sections on this CPU.
> 
> 
> You haven't explain the tick_nohz_stop_sched_tick() in *irq_exit()*.
> (tick_nohz_stop_sched_tick() calls rcu_enter_nohz())
> 
> void irq_exit(void)
> {
> 	....
> 	rcu_irq_exit(); /* This is OK, the opposite is in irq_enter() */
> 	if (idle_cpu(smp_processor_id()) && !in_interrupt() && !need_resched())
> 		tick_nohz_stop_sched_tick(0); /* where is the opposite ??? */
> 	....
> }
> 
> This means if the interrupt -is- returning to dyntick-idle mode,
> rcu_enter_nohz() is called again.
> 
> Take this flow as example:
> 
> cpu_idle():
> while(1) {
> 
>   tick_nohz_stop_sched_tick()
>      rcu_enter_nohz()                 *****

=== now RCU is in no_hz mode.

> ------->interrupt happen
>         irq_enter()

		rcu_irq_enter()

=== now RCU is no longer in no_hz mode.

>         irq_exit()

		rcu_irq_exit()

=== now RCU is in no_hz mode again.

>            tick_nohz_stop_sched_tick()

=== but tick_nohz_stop_sched_tick() is passed "0" as the argument.  
=== I might be missing something, but doesn't this prevent
=== rcu_enter_nohz() from being called at this point?

>               rcu_enter_nohz()       *****
> <-------interrupt returns
>   tick_nohz_restart_sched_tick()
>      rcu_exit_nohz()                  *****

=== now RCU is no longer in no_hz mode.

> } /* while(1) */
> 
> 
> You can see that rcu_enter_nohz() is called twice and
> rcu_exit_nohz() is only called once in this flow.
> 
> It's because tick_nohz_stop_sched_tick()/tick_nohz_restart_sched_tick()
> are not called in pairs, so rcu_enter_nohz() and rcu_exit_nohz()
> are not called in pairs either.

I believe that the checks in tick_nohz_stop_sched_tick() prevent this
scenario from happening, but could easily be mistaken.  I am not seeing
the WARN_ON_RATELIMIT() in rcu_exit_nohz(), however.

							Thanx, Paul

> Lai
> 
> > 
> > So I do believe that rcu_enter_nohz() and rcu_exit_nohz() are in fact
> > invoked in pairs.  One strange thing about this is that the idle loop
> > first invokes rcu_enter_nohz(), then invokes rcu_exit_nohz(), while
> > an interrupt handler first invokes rcu_irq_enter() and then invokes
> > rcu_irq_exit().  So the idle loop enters dyntick-idle mode and then
> > leaves it, while an interrupt handler might leave dyntick-idle mode and
> > then re-enter it.
> > 
> > Or am I still missing something here?
> > 
> > 							Thanx, Paul
> > 
> > 
> 

  parent reply	other threads:[~2009-10-14  2:53 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-09 22:49 [PATCH RFC tip/core/rcu 0/3] Tiny RCU and expedited SRCU Paul E. McKenney
2009-10-09 22:50 ` [PATCH RFC tip/core/rcu 1/3] rcu: The Bloatwatch Edition, v7 Paul E. McKenney
2009-10-12  9:29   ` Lai Jiangshan
2009-10-12 16:40     ` Linus Torvalds
2009-10-12 17:30     ` Paul E. McKenney
2009-10-13  6:05       ` Lai Jiangshan
2009-10-13  7:44   ` Lai Jiangshan
2009-10-13 17:00     ` Paul E. McKenney
2009-10-14  0:37       ` Lai Jiangshan
2009-10-14  1:09         ` Paul E. McKenney
2009-10-14  2:05           ` Lai Jiangshan
2009-10-14  2:49             ` Steven Rostedt
2009-10-27  7:26               ` Lai Jiangshan
2009-10-27 19:56                 ` Steven Rostedt
2009-10-14  2:52             ` Paul E. McKenney [this message]
2009-10-09 22:50 ` [PATCH RFC tip/core/rcu 2/3] rcu: Add synchronize_srcu_expedited() Paul E. McKenney
2009-10-09 22:50 ` [PATCH RFC tip/core/rcu 3/3] rcu: add synchronize_srcu_expedited() to the rcutorture test suite Paul E. McKenney
2009-10-10  3:47 ` [PATCH RFC tip/core/rcu 0/3] Tiny RCU and expedited SRCU Josh Triplett

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091014025235.GB6840@linux.vnet.ibm.com \
    --to=paulmck@linux.vnet.ibm.com \
    --cc=Valdis.Kletnieks@vt.edu \
    --cc=akpm@linux-foundation.org \
    --cc=avi@redhat.com \
    --cc=dhowells@redhat.com \
    --cc=dipankar@in.ibm.com \
    --cc=dvhltc@us.ibm.com \
    --cc=josh@joshtriplett.org \
    --cc=laijs@cn.fujitsu.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mathieu.desnoyers@polymtl.ca \
    --cc=mingo@elte.hu \
    --cc=mtosatti@redhat.com \
    --cc=niv@us.ibm.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox