Skip to content

Commit 94edf6f

Browse files
committed
Merge branch 'for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu into core/rcu
Pull RCU updates from Paul E. McKenney: - Removal of spin_unlock_wait() - SRCU updates - Torture-test updates - Documentation updates - Miscellaneous fixes - CPU-hotplug fixes - Miscellaneous non-RCU fixes Signed-off-by: Ingo Molnar <mingo@kernel.org>
2 parents d5da645 + 656e7c0 commit 94edf6f

84 files changed

Lines changed: 1207 additions & 1312 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/RCU/Design/Requirements/Requirements.html‎

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2080,6 +2080,8 @@ <h2><a name="Linux Kernel Complications">Linux Kernel Complications</a></h2>
20802080
<li> <a href="#Scheduler and RCU">Scheduler and RCU</a>.
20812081
<li> <a href="#Tracing and RCU">Tracing and RCU</a>.
20822082
<li> <a href="#Energy Efficiency">Energy Efficiency</a>.
2083+
<li> <a href="#Scheduling-Clock Interrupts and RCU">
2084+
Scheduling-Clock Interrupts and RCU</a>.
20832085
<li> <a href="#Memory Efficiency">Memory Efficiency</a>.
20842086
<li> <a href="#Performance, Scalability, Response Time, and Reliability">
20852087
Performance, Scalability, Response Time, and Reliability</a>.
@@ -2532,6 +2534,134 @@ <h3><a name="Energy Efficiency">Energy Efficiency</a></h3>
25322534
Flaming me on the Linux-kernel mailing list was apparently not
25332535
sufficient to fully vent their ire at RCU's energy-efficiency bugs!
25342536

2537+
<h3><a name="Scheduling-Clock Interrupts and RCU">
2538+
Scheduling-Clock Interrupts and RCU</a></h3>
2539+
2540+
<p>
2541+
The kernel transitions between in-kernel non-idle execution, userspace
2542+
execution, and the idle loop.
2543+
Depending on kernel configuration, RCU handles these states differently:
2544+
2545+
<table border=3>
2546+
<tr><th><tt>HZ</tt> Kconfig</th>
2547+
<th>In-Kernel</th>
2548+
<th>Usermode</th>
2549+
<th>Idle</th></tr>
2550+
<tr><th align="left"><tt>HZ_PERIODIC</tt></th>
2551+
<td>Can rely on scheduling-clock interrupt.</td>
2552+
<td>Can rely on scheduling-clock interrupt and its
2553+
detection of interrupt from usermode.</td>
2554+
<td>Can rely on RCU's dyntick-idle detection.</td></tr>
2555+
<tr><th align="left"><tt>NO_HZ_IDLE</tt></th>
2556+
<td>Can rely on scheduling-clock interrupt.</td>
2557+
<td>Can rely on scheduling-clock interrupt and its
2558+
detection of interrupt from usermode.</td>
2559+
<td>Can rely on RCU's dyntick-idle detection.</td></tr>
2560+
<tr><th align="left"><tt>NO_HZ_FULL</tt></th>
2561+
<td>Can only sometimes rely on scheduling-clock interrupt.
2562+
In other cases, it is necessary to bound kernel execution
2563+
times and/or use IPIs.</td>
2564+
<td>Can rely on RCU's dyntick-idle detection.</td>
2565+
<td>Can rely on RCU's dyntick-idle detection.</td></tr>
2566+
</table>
2567+
2568+
<table>
2569+
<tr><th>&nbsp;</th></tr>
2570+
<tr><th align="left">Quick Quiz:</th></tr>
2571+
<tr><td>
2572+
Why can't <tt>NO_HZ_FULL</tt> in-kernel execution rely on the
2573+
scheduling-clock interrupt, just like <tt>HZ_PERIODIC</tt>
2574+
and <tt>NO_HZ_IDLE</tt> do?
2575+
</td></tr>
2576+
<tr><th align="left">Answer:</th></tr>
2577+
<tr><td bgcolor="#ffffff"><font color="ffffff">
2578+
Because, as a performance optimization, <tt>NO_HZ_FULL</tt>
2579+
does not necessarily re-enable the scheduling-clock interrupt
2580+
on entry to each and every system call.
2581+
</font></td></tr>
2582+
<tr><td>&nbsp;</td></tr>
2583+
</table>
2584+
2585+
<p>
2586+
However, RCU must be reliably informed as to whether any given
2587+
CPU is currently in the idle loop, and, for <tt>NO_HZ_FULL</tt>,
2588+
also whether that CPU is executing in usermode, as discussed
2589+
<a href="#Energy Efficiency">earlier</a>.
2590+
It also requires that the scheduling-clock interrupt be enabled when
2591+
RCU needs it to be:
2592+
2593+
<ol>
2594+
<li> If a CPU is either idle or executing in usermode, and RCU believes
2595+
it is non-idle, the scheduling-clock tick had better be running.
2596+
Otherwise, you will get RCU CPU stall warnings. Or at best,
2597+
very long (11-second) grace periods, with a pointless IPI waking
2598+
the CPU from time to time.
2599+
<li> If a CPU is in a portion of the kernel that executes RCU read-side
2600+
critical sections, and RCU believes this CPU to be idle, you will get
2601+
random memory corruption. <b>DON'T DO THIS!!!</b>
2602+
2603+
<br>This is one reason to test with lockdep, which will complain
2604+
about this sort of thing.
2605+
<li> If a CPU is in a portion of the kernel that is absolutely
2606+
positively no-joking guaranteed to never execute any RCU read-side
2607+
critical sections, and RCU believes this CPU to to be idle,
2608+
no problem. This sort of thing is used by some architectures
2609+
for light-weight exception handlers, which can then avoid the
2610+
overhead of <tt>rcu_irq_enter()</tt> and <tt>rcu_irq_exit()</tt>
2611+
at exception entry and exit, respectively.
2612+
Some go further and avoid the entireties of <tt>irq_enter()</tt>
2613+
and <tt>irq_exit()</tt>.
2614+
2615+
<br>Just make very sure you are running some of your tests with
2616+
<tt>CONFIG_PROVE_RCU=y</tt>, just in case one of your code paths
2617+
was in fact joking about not doing RCU read-side critical sections.
2618+
<li> If a CPU is executing in the kernel with the scheduling-clock
2619+
interrupt disabled and RCU believes this CPU to be non-idle,
2620+
and if the CPU goes idle (from an RCU perspective) every few
2621+
jiffies, no problem. It is usually OK for there to be the
2622+
occasional gap between idle periods of up to a second or so.
2623+
2624+
<br>If the gap grows too long, you get RCU CPU stall warnings.
2625+
<li> If a CPU is either idle or executing in usermode, and RCU believes
2626+
it to be idle, of course no problem.
2627+
<li> If a CPU is executing in the kernel, the kernel code
2628+
path is passing through quiescent states at a reasonable
2629+
frequency (preferably about once per few jiffies, but the
2630+
occasional excursion to a second or so is usually OK) and the
2631+
scheduling-clock interrupt is enabled, of course no problem.
2632+
2633+
<br>If the gap between a successive pair of quiescent states grows
2634+
too long, you get RCU CPU stall warnings.
2635+
</ol>
2636+
2637+
<table>
2638+
<tr><th>&nbsp;</th></tr>
2639+
<tr><th align="left">Quick Quiz:</th></tr>
2640+
<tr><td>
2641+
But what if my driver has a hardware interrupt handler
2642+
that can run for many seconds?
2643+
I cannot invoke <tt>schedule()</tt> from an hardware
2644+
interrupt handler, after all!
2645+
</td></tr>
2646+
<tr><th align="left">Answer:</th></tr>
2647+
<tr><td bgcolor="#ffffff"><font color="ffffff">
2648+
One approach is to do <tt>rcu_irq_exit();rcu_irq_enter();</tt>
2649+
every so often.
2650+
But given that long-running interrupt handlers can cause
2651+
other problems, not least for response time, shouldn't you
2652+
work to keep your interrupt handler's runtime within reasonable
2653+
bounds?
2654+
</font></td></tr>
2655+
<tr><td>&nbsp;</td></tr>
2656+
</table>
2657+
2658+
<p>
2659+
But as long as RCU is properly informed of kernel state transitions between
2660+
in-kernel execution, usermode execution, and idle, and as long as the
2661+
scheduling-clock interrupt is enabled when RCU needs it to be, you
2662+
can rest assured that the bugs you encounter will be in some other
2663+
part of RCU or some other part of the kernel!
2664+
25352665
<h3><a name="Memory Efficiency">Memory Efficiency</a></h3>
25362666

25372667
<p>

‎Documentation/RCU/checklist.txt‎

Lines changed: 85 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ over a rather long period of time, but improvements are always welcome!
2323
Yet another exception is where the low real-time latency of RCU's
2424
read-side primitives is critically important.
2525

26+
One final exception is where RCU readers are used to prevent
27+
the ABA problem (https://en.wikipedia.org/wiki/ABA_problem)
28+
for lockless updates. This does result in the mildly
29+
counter-intuitive situation where rcu_read_lock() and
30+
rcu_read_unlock() are used to protect updates, however, this
31+
approach provides the same potential simplifications that garbage
32+
collectors do.
33+
2634
1. Does the update code have proper mutual exclusion?
2735

2836
RCU does allow -readers- to run (almost) naked, but -writers- must
@@ -40,7 +48,9 @@ over a rather long period of time, but improvements are always welcome!
4048
explain how this single task does not become a major bottleneck on
4149
big multiprocessor machines (for example, if the task is updating
4250
information relating to itself that other tasks can read, there
43-
by definition can be no bottleneck).
51+
by definition can be no bottleneck). Note that the definition
52+
of "large" has changed significantly: Eight CPUs was "large"
53+
in the year 2000, but a hundred CPUs was unremarkable in 2017.
4454

4555
2. Do the RCU read-side critical sections make proper use of
4656
rcu_read_lock() and friends? These primitives are needed
@@ -55,6 +65,12 @@ over a rather long period of time, but improvements are always welcome!
5565
Disabling of preemption can serve as rcu_read_lock_sched(), but
5666
is less readable.
5767

68+
Letting RCU-protected pointers "leak" out of an RCU read-side
69+
critical section is every bid as bad as letting them leak out
70+
from under a lock. Unless, of course, you have arranged some
71+
other means of protection, such as a lock or a reference count
72+
-before- letting them out of the RCU read-side critical section.
73+
5874
3. Does the update code tolerate concurrent accesses?
5975

6076
The whole point of RCU is to permit readers to run without
@@ -78,10 +94,10 @@ over a rather long period of time, but improvements are always welcome!
7894

7995
This works quite well, also.
8096

81-
c. Make updates appear atomic to readers. For example,
97+
c. Make updates appear atomic to readers. For example,
8298
pointer updates to properly aligned fields will
8399
appear atomic, as will individual atomic primitives.
84-
Sequences of perations performed under a lock will -not-
100+
Sequences of operations performed under a lock will -not-
85101
appear to be atomic to RCU readers, nor will sequences
86102
of multiple atomic primitives.
87103

@@ -168,8 +184,8 @@ over a rather long period of time, but improvements are always welcome!
168184

169185
5. If call_rcu(), or a related primitive such as call_rcu_bh(),
170186
call_rcu_sched(), or call_srcu() is used, the callback function
171-
must be written to be called from softirq context. In particular,
172-
it cannot block.
187+
will be called from softirq context. In particular, it cannot
188+
block.
173189

174190
6. Since synchronize_rcu() can block, it cannot be called from
175191
any sort of irq context. The same rule applies for
@@ -178,11 +194,14 @@ over a rather long period of time, but improvements are always welcome!
178194
synchronize_sched_expedite(), and synchronize_srcu_expedited().
179195

180196
The expedited forms of these primitives have the same semantics
181-
as the non-expedited forms, but expediting is both expensive
182-
and unfriendly to real-time workloads. Use of the expedited
183-
primitives should be restricted to rare configuration-change
184-
operations that would not normally be undertaken while a real-time
185-
workload is running.
197+
as the non-expedited forms, but expediting is both expensive and
198+
(with the exception of synchronize_srcu_expedited()) unfriendly
199+
to real-time workloads. Use of the expedited primitives should
200+
be restricted to rare configuration-change operations that would
201+
not normally be undertaken while a real-time workload is running.
202+
However, real-time workloads can use rcupdate.rcu_normal kernel
203+
boot parameter to completely disable expedited grace periods,
204+
though this might have performance implications.
186205

187206
In particular, if you find yourself invoking one of the expedited
188207
primitives repeatedly in a loop, please do everyone a favor:
@@ -193,11 +212,6 @@ over a rather long period of time, but improvements are always welcome!
193212
of the system, especially to real-time workloads running on
194213
the rest of the system.
195214

196-
In addition, it is illegal to call the expedited forms from
197-
a CPU-hotplug notifier, or while holding a lock that is acquired
198-
by a CPU-hotplug notifier. Failing to observe this restriction
199-
will result in deadlock.
200-
201215
7. If the updater uses call_rcu() or synchronize_rcu(), then the
202216
corresponding readers must use rcu_read_lock() and
203217
rcu_read_unlock(). If the updater uses call_rcu_bh() or
@@ -321,7 +335,7 @@ over a rather long period of time, but improvements are always welcome!
321335
Similarly, disabling preemption is not an acceptable substitute
322336
for rcu_read_lock(). Code that attempts to use preemption
323337
disabling where it should be using rcu_read_lock() will break
324-
in real-time kernel builds.
338+
in CONFIG_PREEMPT=y kernel builds.
325339

326340
If you want to wait for interrupt handlers, NMI handlers, and
327341
code under the influence of preempt_disable(), you instead
@@ -356,23 +370,22 @@ over a rather long period of time, but improvements are always welcome!
356370
not the case, a self-spawning RCU callback would prevent the
357371
victim CPU from ever going offline.)
358372

359-
14. SRCU (srcu_read_lock(), srcu_read_unlock(), srcu_dereference(),
360-
synchronize_srcu(), synchronize_srcu_expedited(), and call_srcu())
361-
may only be invoked from process context. Unlike other forms of
362-
RCU, it -is- permissible to block in an SRCU read-side critical
363-
section (demarked by srcu_read_lock() and srcu_read_unlock()),
364-
hence the "SRCU": "sleepable RCU". Please note that if you
365-
don't need to sleep in read-side critical sections, you should be
366-
using RCU rather than SRCU, because RCU is almost always faster
367-
and easier to use than is SRCU.
368-
369-
Also unlike other forms of RCU, explicit initialization
370-
and cleanup is required via init_srcu_struct() and
371-
cleanup_srcu_struct(). These are passed a "struct srcu_struct"
372-
that defines the scope of a given SRCU domain. Once initialized,
373-
the srcu_struct is passed to srcu_read_lock(), srcu_read_unlock()
374-
synchronize_srcu(), synchronize_srcu_expedited(), and call_srcu().
375-
A given synchronize_srcu() waits only for SRCU read-side critical
373+
14. Unlike other forms of RCU, it -is- permissible to block in an
374+
SRCU read-side critical section (demarked by srcu_read_lock()
375+
and srcu_read_unlock()), hence the "SRCU": "sleepable RCU".
376+
Please note that if you don't need to sleep in read-side critical
377+
sections, you should be using RCU rather than SRCU, because RCU
378+
is almost always faster and easier to use than is SRCU.
379+
380+
Also unlike other forms of RCU, explicit initialization and
381+
cleanup is required either at build time via DEFINE_SRCU()
382+
or DEFINE_STATIC_SRCU() or at runtime via init_srcu_struct()
383+
and cleanup_srcu_struct(). These last two are passed a
384+
"struct srcu_struct" that defines the scope of a given
385+
SRCU domain. Once initialized, the srcu_struct is passed
386+
to srcu_read_lock(), srcu_read_unlock() synchronize_srcu(),
387+
synchronize_srcu_expedited(), and call_srcu(). A given
388+
synchronize_srcu() waits only for SRCU read-side critical
376389
sections governed by srcu_read_lock() and srcu_read_unlock()
377390
calls that have been passed the same srcu_struct. This property
378391
is what makes sleeping read-side critical sections tolerable --
@@ -390,10 +403,16 @@ over a rather long period of time, but improvements are always welcome!
390403
Therefore, SRCU should be used in preference to rw_semaphore
391404
only in extremely read-intensive situations, or in situations
392405
requiring SRCU's read-side deadlock immunity or low read-side
393-
realtime latency.
406+
realtime latency. You should also consider percpu_rw_semaphore
407+
when you need lightweight readers.
394408

395-
Note that, rcu_assign_pointer() relates to SRCU just as it does
396-
to other forms of RCU.
409+
SRCU's expedited primitive (synchronize_srcu_expedited())
410+
never sends IPIs to other CPUs, so it is easier on
411+
real-time workloads than is synchronize_rcu_expedited(),
412+
synchronize_rcu_bh_expedited() or synchronize_sched_expedited().
413+
414+
Note that rcu_dereference() and rcu_assign_pointer() relate to
415+
SRCU just as they do to other forms of RCU.
397416

398417
15. The whole point of call_rcu(), synchronize_rcu(), and friends
399418
is to wait until all pre-existing readers have finished before
@@ -435,3 +454,33 @@ over a rather long period of time, but improvements are always welcome!
435454

436455
These debugging aids can help you find problems that are
437456
otherwise extremely difficult to spot.
457+
458+
18. If you register a callback using call_rcu(), call_rcu_bh(),
459+
call_rcu_sched(), or call_srcu(), and pass in a function defined
460+
within a loadable module, then it in necessary to wait for
461+
all pending callbacks to be invoked after the last invocation
462+
and before unloading that module. Note that it is absolutely
463+
-not- sufficient to wait for a grace period! The current (say)
464+
synchronize_rcu() implementation waits only for all previous
465+
callbacks registered on the CPU that synchronize_rcu() is running
466+
on, but it is -not- guaranteed to wait for callbacks registered
467+
on other CPUs.
468+
469+
You instead need to use one of the barrier functions:
470+
471+
o call_rcu() -> rcu_barrier()
472+
o call_rcu_bh() -> rcu_barrier_bh()
473+
o call_rcu_sched() -> rcu_barrier_sched()
474+
o call_srcu() -> srcu_barrier()
475+
476+
However, these barrier functions are absolutely -not- guaranteed
477+
to wait for a grace period. In fact, if there are no call_rcu()
478+
callbacks waiting anywhere in the system, rcu_barrier() is within
479+
its rights to return immediately.
480+
481+
So if you need to wait for both an RCU grace period and for
482+
all pre-existing call_rcu() callbacks, you will need to execute
483+
both rcu_barrier() and synchronize_rcu(), if necessary, using
484+
something like workqueues to to execute them concurrently.
485+
486+
See rcubarrier.txt for more information.

‎Documentation/RCU/rcu.txt‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,12 @@ o I hear that RCU is patented? What is with that?
7676
Of these, one was allowed to lapse by the assignee, and the
7777
others have been contributed to the Linux kernel under GPL.
7878
There are now also LGPL implementations of user-level RCU
79-
available (http://lttng.org/?q=node/18).
79+
available (http://liburcu.org/).
8080

8181
o I hear that RCU needs work in order to support realtime kernels?
8282

83-
This work is largely completed. Realtime-friendly RCU can be
84-
enabled via the CONFIG_PREEMPT_RCU kernel configuration
85-
parameter. However, work is in progress for enabling priority
86-
boosting of preempted RCU read-side critical sections. This is
87-
needed if you have CPU-bound realtime threads.
83+
Realtime-friendly RCU can be enabled via the CONFIG_PREEMPT_RCU
84+
kernel configuration parameter.
8885

8986
o Where can I find more information on RCU?
9087

0 commit comments

Comments
 (0)