Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1622332 > unrolled thread

[PATCH tip/core/rcu 1/9] doc: Synchronous RCU grace periods are now legal throughout boot

Started by"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
First post2017-04-12 18:50 +0200
Last post2017-04-13 18:00 +0200
Articles 3 — 2 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH tip/core/rcu 1/9] doc: Synchronous RCU grace periods are now legal throughout boot "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-04-12 18:50 +0200
    Re: [PATCH tip/core/rcu 1/9] doc: Synchronous RCU grace periods are  now legal throughout boot Peter Zijlstra <peterz@infradead.org> - 2017-04-13 11:10 +0200
      Re: [PATCH tip/core/rcu 1/9] doc: Synchronous RCU grace periods are  now legal throughout boot "Paul E. McKenney" <paulmck@linux.vnet.ibm.com> - 2017-04-13 18:00 +0200

#1622332 — [PATCH tip/core/rcu 1/9] doc: Synchronous RCU grace periods are now legal throughout boot

From"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Date2017-04-12 18:50 +0200
Subject[PATCH tip/core/rcu 1/9] doc: Synchronous RCU grace periods are now legal throughout boot
Message-ID<tvtCW-6Qp-19@gated-at.bofh.it>
This commit updates the "Early Boot" section of the RCU requirements
to describe how synchronous RCU grace periods are now legal throughout
the boot process.

Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
---
 .../RCU/Design/Requirements/Requirements.html      | 81 +++++++++++++---------
 1 file changed, 47 insertions(+), 34 deletions(-)

diff --git a/Documentation/RCU/Design/Requirements/Requirements.html b/Documentation/RCU/Design/Requirements/Requirements.html
index 21593496aca6..999b3ed3444e 100644
--- a/Documentation/RCU/Design/Requirements/Requirements.html
+++ b/Documentation/RCU/Design/Requirements/Requirements.html
@@ -2154,7 +2154,8 @@ as will <tt>rcu_assign_pointer()</tt>.
 <p>
 Although <tt>call_rcu()</tt> may be invoked at any
 time during boot, callbacks are not guaranteed to be invoked until after
-the scheduler is fully up and running.
+all of RCU's kthreads have been spawned, which occurs at
+<tt>early_initcall()</tt> time.
 This delay in callback invocation is due to the fact that RCU does not
 invoke callbacks until it is fully initialized, and this full initialization
 cannot occur until after the scheduler has initialized itself to the
@@ -2167,8 +2168,10 @@ on what operations those callbacks could invoke.
 Perhaps surprisingly, <tt>synchronize_rcu()</tt>,
 <a href="#Bottom-Half Flavor"><tt>synchronize_rcu_bh()</tt></a>
 (<a href="#Bottom-Half Flavor">discussed below</a>),
-and
-<a href="#Sched Flavor"><tt>synchronize_sched()</tt></a>
+<a href="#Sched Flavor"><tt>synchronize_sched()</tt></a>,
+<tt>synchronize_rcu_expedited()</tt>,
+<tt>synchronize_rcu_bh_expedited()</tt>, and
+<tt>synchronize_sched_expedited()</tt>
 will all operate normally
 during very early boot, the reason being that there is only one CPU
 and preemption is disabled.
@@ -2178,45 +2181,55 @@ state and thus a grace period, so the early-boot implementation can
 be a no-op.
 
 <p>
-Both <tt>synchronize_rcu_bh()</tt> and <tt>synchronize_sched()</tt>
-continue to operate normally through the remainder of boot, courtesy
-of the fact that preemption is disabled across their RCU read-side
-critical sections and also courtesy of the fact that there is still
-only one CPU.
-However, once the scheduler starts initializing, preemption is enabled.
-There is still only a single CPU, but the fact that preemption is enabled
-means that the no-op implementation of <tt>synchronize_rcu()</tt> no
-longer works in <tt>CONFIG_PREEMPT=y</tt> kernels.
-Therefore, as soon as the scheduler starts initializing, the early-boot
-fastpath is disabled.
-This means that <tt>synchronize_rcu()</tt> switches to its runtime
-mode of operation where it posts callbacks, which in turn means that
-any call to <tt>synchronize_rcu()</tt> will block until the corresponding
-callback is invoked.
-Unfortunately, the callback cannot be invoked until RCU's runtime
-grace-period machinery is up and running, which cannot happen until
-the scheduler has initialized itself sufficiently to allow RCU's
-kthreads to be spawned.
-Therefore, invoking <tt>synchronize_rcu()</tt> during scheduler
-initialization can result in deadlock.
+However, once the scheduler has spawned its first kthread, this early
+boot trick fails for <tt>synchronize_rcu()</tt> (as well as for
+<tt>synchronize_rcu_expedited()</tt>) in <tt>CONFIG_PREEMPT=y</tt>
+kernels.
+The reason is that an RCU read-side critical section might be preempted,
+which means that a subsequent <tt>synchronize_rcu()</tt> really does have
+to wait for something, as opposed to simply returning immediately.
+Unfortunately, <tt>synchronize_rcu()</tt> can't do this until all of
+its kthreads are spawned, which doesn't happen until some time during
+<tt>early_initcalls()</tt> time.
+But this is no excuse:  RCU is nevertheless required to correctly handle
+synchronous grace periods during this time period, which it currently does.
+Once all of its kthreads are up and running, RCU starts running
+normally.
 
 <table>
 <tr><th>&nbsp;</th></tr>
 <tr><th align="left">Quick Quiz:</th></tr>
 <tr><td>
-	So what happens with <tt>synchronize_rcu()</tt> during
-	scheduler initialization for <tt>CONFIG_PREEMPT=n</tt>
-	kernels?
+	How can RCU possibly handle grace periods before all of its
+	kthreads have been spawned???
 </td></tr>
 <tr><th align="left">Answer:</th></tr>
 <tr><td bgcolor="#ffffff"><font color="ffffff">
-	In <tt>CONFIG_PREEMPT=n</tt> kernel, <tt>synchronize_rcu()</tt>
-	maps directly to <tt>synchronize_sched()</tt>.
-	Therefore, <tt>synchronize_rcu()</tt> works normally throughout
-	boot in <tt>CONFIG_PREEMPT=n</tt> kernels.
-	However, your code must also work in <tt>CONFIG_PREEMPT=y</tt> kernels,
-	so it is still necessary to avoid invoking <tt>synchronize_rcu()</tt>
-	during scheduler initialization.
+	Very carefully!
+
+	<p>During the &ldquo;dead zone&rdquo; between the time that the
+	scheduler spawns the first task and the time that all of RCU's
+	kthreads have been spawned, all synchronous grace periods are
+	handled by the expedited grace-period mechanism.
+	At runtime, this expedited mechanism relies on workqueues, but
+	during the dead zone the requesting task itself drives the
+	desired expedited grace period.
+	Because dead-zone execution takes place within task context,
+	everything works.
+	Once the dead zone ends, expedited grace periods go back to
+	using workqueues, as is required to avoid problems that would
+	otherwise occur when a user task received a POSIX signal while
+	driving an expedited grace period.
+
+	<p>And yes, this does mean that it is unhelpful to send POSIX
+	signals to random tasks between the time that the scheduler
+	spawns its first kthread and the time that RCU's kthreads
+	have all been spawned.
+	If there ever turns out to be a good reason for sending POSIX
+	signals during that time, appropriate adjustments will be made.
+	(If it turns out that POSIX signals are sent during this time for
+	no good reason, other adjustments will be made, appropriate
+	or otherwise.)
 </font></td></tr>
 <tr><td>&nbsp;</td></tr>
 </table>
-- 
2.5.2

[toc] | [next] | [standalone]


#1622834 — Re: [PATCH tip/core/rcu 1/9] doc: Synchronous RCU grace periods are now legal throughout boot

FromPeter Zijlstra <peterz@infradead.org>
Date2017-04-13 11:10 +0200
SubjectRe: [PATCH tip/core/rcu 1/9] doc: Synchronous RCU grace periods are now legal throughout boot
Message-ID<tvIVk-M6-9@gated-at.bofh.it>
In reply to#1622332
On Wed, Apr 12, 2017 at 09:40:14AM -0700, Paul E. McKenney wrote:
> This commit updates the "Early Boot" section of the RCU requirements
> to describe how synchronous RCU grace periods are now legal throughout
> the boot process.

You mean people would come an arrest you for doing it before? ;-)

[toc] | [prev] | [next] | [standalone]


#1623143 — Re: [PATCH tip/core/rcu 1/9] doc: Synchronous RCU grace periods are now legal throughout boot

From"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>
Date2017-04-13 18:00 +0200
SubjectRe: [PATCH tip/core/rcu 1/9] doc: Synchronous RCU grace periods are now legal throughout boot
Message-ID<tvPk6-514-37@gated-at.bofh.it>
In reply to#1622834
On Thu, Apr 13, 2017 at 11:07:54AM +0200, Peter Zijlstra wrote:
> On Wed, Apr 12, 2017 at 09:40:14AM -0700, Paul E. McKenney wrote:
> > This commit updates the "Early Boot" section of the RCU requirements
> > to describe how synchronous RCU grace periods are now legal throughout
> > the boot process.
> 
> You mean people would come an arrest you for doing it before? ;-)

In some of the more no-nonsense jurisdictions making use of the Linux
kernel for safety-critical application, maybe they would!  ;-)

But just for the record, and in case someone missed seeing the smiley at
the end of your sentence, Merriam-Webster's third definition of the word
"legal" is as follows:

	https://www.merriam-webster.com/dictionary/legal

	3:	conforming to or permitted by law or established rules

With this commit log's usage of "legal" taking the "established rules"
branch of that definition.

This diversion brought to you by Shakespeare's Henry VI, Part 2, Act 1,
Scene 2, in memory of the skin of those innocent lambs.  ;-)

							Thanx, Paul

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web