Commit 6c9fcaf2 authored by Ingo Molnar's avatar Ingo Molnar

Merge branch 'core/rcu' into core/rcu-for-linus

parents b9d2252c 199a9528
...@@ -93,6 +93,9 @@ Since NMI handlers disable preemption, synchronize_sched() is guaranteed ...@@ -93,6 +93,9 @@ Since NMI handlers disable preemption, synchronize_sched() is guaranteed
not to return until all ongoing NMI handlers exit. It is therefore safe not to return until all ongoing NMI handlers exit. It is therefore safe
to free up the handler's data as soon as synchronize_sched() returns. to free up the handler's data as soon as synchronize_sched() returns.
Important note: for this to work, the architecture in question must
invoke irq_enter() and irq_exit() on NMI entry and exit, respectively.
Answer to Quick Quiz Answer to Quick Quiz
......
...@@ -52,6 +52,10 @@ of each iteration. Unfortunately, chaotic relaxation requires highly ...@@ -52,6 +52,10 @@ of each iteration. Unfortunately, chaotic relaxation requires highly
structured data, such as the matrices used in scientific programs, and structured data, such as the matrices used in scientific programs, and
is thus inapplicable to most data structures in operating-system kernels. is thus inapplicable to most data structures in operating-system kernels.
In 1992, Henry (now Alexia) Massalin completed a dissertation advising
parallel programmers to defer processing when feasible to simplify
synchronization. RCU makes extremely heavy use of this advice.
In 1993, Jacobson [Jacobson93] verbally described what is perhaps the In 1993, Jacobson [Jacobson93] verbally described what is perhaps the
simplest deferred-free technique: simply waiting a fixed amount of time simplest deferred-free technique: simply waiting a fixed amount of time
before freeing blocks awaiting deferred free. Jacobson did not describe before freeing blocks awaiting deferred free. Jacobson did not describe
...@@ -138,6 +142,13 @@ blocking in read-side critical sections appeared [PaulEMcKenney2006c], ...@@ -138,6 +142,13 @@ blocking in read-side critical sections appeared [PaulEMcKenney2006c],
Robert Olsson described an RCU-protected trie-hash combination Robert Olsson described an RCU-protected trie-hash combination
[RobertOlsson2006a]. [RobertOlsson2006a].
2007 saw the journal version of the award-winning RCU paper from 2006
[ThomasEHart2007a], as well as a paper demonstrating use of Promela
and Spin to mechanically verify an optimization to Oleg Nesterov's
QRCU [PaulEMcKenney2007QRCUspin], a design document describing
preemptible RCU [PaulEMcKenney2007PreemptibleRCU], and the three-part
LWN "What is RCU?" series [PaulEMcKenney2007WhatIsRCUFundamentally,
PaulEMcKenney2008WhatIsRCUUsage, and PaulEMcKenney2008WhatIsRCUAPI].
Bibtex Entries Bibtex Entries
...@@ -202,6 +213,20 @@ Bibtex Entries ...@@ -202,6 +213,20 @@ Bibtex Entries
,Year="1991" ,Year="1991"
} }
@phdthesis{HMassalinPhD
,author="H. Massalin"
,title="Synthesis: An Efficient Implementation of Fundamental Operating
System Services"
,school="Columbia University"
,address="New York, NY"
,year="1992"
,annotation="
Mondo optimizing compiler.
Wait-free stuff.
Good advice: defer work to avoid synchronization.
"
}
@unpublished{Jacobson93 @unpublished{Jacobson93
,author="Van Jacobson" ,author="Van Jacobson"
,title="Avoid Read-Side Locking Via Delayed Free" ,title="Avoid Read-Side Locking Via Delayed Free"
...@@ -635,3 +660,86 @@ Revised: ...@@ -635,3 +660,86 @@ Revised:
" "
} }
@unpublished{PaulEMcKenney2007PreemptibleRCU
,Author="Paul E. McKenney"
,Title="The design of preemptible read-copy-update"
,month="October"
,day="8"
,year="2007"
,note="Available:
\url{http://lwn.net/Articles/253651/}
[Viewed October 25, 2007]"
,annotation="
LWN article describing the design of preemptible RCU.
"
}
########################################################################
#
# "What is RCU?" LWN series.
#
@unpublished{PaulEMcKenney2007WhatIsRCUFundamentally
,Author="Paul E. McKenney and Jonathan Walpole"
,Title="What is {RCU}, Fundamentally?"
,month="December"
,day="17"
,year="2007"
,note="Available:
\url{http://lwn.net/Articles/262464/}
[Viewed December 27, 2007]"
,annotation="
Lays out the three basic components of RCU: (1) publish-subscribe,
(2) wait for pre-existing readers to complete, and (2) maintain
multiple versions.
"
}
@unpublished{PaulEMcKenney2008WhatIsRCUUsage
,Author="Paul E. McKenney"
,Title="What is {RCU}? Part 2: Usage"
,month="January"
,day="4"
,year="2008"
,note="Available:
\url{http://lwn.net/Articles/263130/}
[Viewed January 4, 2008]"
,annotation="
Lays out six uses of RCU:
1. RCU is a Reader-Writer Lock Replacement
2. RCU is a Restricted Reference-Counting Mechanism
3. RCU is a Bulk Reference-Counting Mechanism
4. RCU is a Poor Man's Garbage Collector
5. RCU is a Way of Providing Existence Guarantees
6. RCU is a Way of Waiting for Things to Finish
"
}
@unpublished{PaulEMcKenney2008WhatIsRCUAPI
,Author="Paul E. McKenney"
,Title="{RCU} part 3: the {RCU} {API}"
,month="January"
,day="17"
,year="2008"
,note="Available:
\url{http://lwn.net/Articles/264090/}
[Viewed January 10, 2008]"
,annotation="
Gives an overview of the Linux-kernel RCU API and a brief annotated RCU
bibliography.
"
}
@article{DinakarGuniguntala2008IBMSysJ
,author="D. Guniguntala and P. E. McKenney and J. Triplett and J. Walpole"
,title="The read-copy-update mechanism for supporting real-time applications on shared-memory multiprocessor systems with {Linux}"
,Year="2008"
,Month="April"
,journal="IBM Systems Journal"
,volume="47"
,number="2"
,pages="@@-@@"
,annotation="
RCU, realtime RCU, sleepable RCU, performance.
"
}
...@@ -13,10 +13,13 @@ over a rather long period of time, but improvements are always welcome! ...@@ -13,10 +13,13 @@ over a rather long period of time, but improvements are always welcome!
detailed performance measurements show that RCU is nonetheless detailed performance measurements show that RCU is nonetheless
the right tool for the job. the right tool for the job.
The other exception would be where performance is not an issue, Another exception is where performance is not an issue, and RCU
and RCU provides a simpler implementation. An example of this provides a simpler implementation. An example of this situation
situation is the dynamic NMI code in the Linux 2.6 kernel, is the dynamic NMI code in the Linux 2.6 kernel, at least on
at least on architectures where NMIs are rare. architectures where NMIs are rare.
Yet another exception is where the low real-time latency of RCU's
read-side primitives is critically important.
1. Does the update code have proper mutual exclusion? 1. Does the update code have proper mutual exclusion?
...@@ -39,9 +42,10 @@ over a rather long period of time, but improvements are always welcome! ...@@ -39,9 +42,10 @@ over a rather long period of time, but improvements are always welcome!
2. Do the RCU read-side critical sections make proper use of 2. Do the RCU read-side critical sections make proper use of
rcu_read_lock() and friends? These primitives are needed rcu_read_lock() and friends? These primitives are needed
to suppress preemption (or bottom halves, in the case of to prevent grace periods from ending prematurely, which
rcu_read_lock_bh()) in the read-side critical sections, could result in data being unceremoniously freed out from
and are also an excellent aid to readability. under your read-side code, which can greatly increase the
actuarial risk of your kernel.
As a rough rule of thumb, any dereference of an RCU-protected As a rough rule of thumb, any dereference of an RCU-protected
pointer must be covered by rcu_read_lock() or rcu_read_lock_bh() pointer must be covered by rcu_read_lock() or rcu_read_lock_bh()
...@@ -54,15 +58,30 @@ over a rather long period of time, but improvements are always welcome! ...@@ -54,15 +58,30 @@ over a rather long period of time, but improvements are always welcome!
be running while updates are in progress. There are a number be running while updates are in progress. There are a number
of ways to handle this concurrency, depending on the situation: of ways to handle this concurrency, depending on the situation:
a. Make updates appear atomic to readers. For example, a. Use the RCU variants of the list and hlist update
primitives to add, remove, and replace elements on an
RCU-protected list. Alternatively, use the RCU-protected
trees that have been added to the Linux kernel.
This is almost always the best approach.
b. Proceed as in (a) above, but also maintain per-element
locks (that are acquired by both readers and writers)
that guard per-element state. Of course, fields that
the readers refrain from accessing can be guarded by the
update-side lock.
This works quite well, also.
c. Make updates appear atomic to readers. For example,
pointer updates to properly aligned fields will appear pointer updates to properly aligned fields will appear
atomic, as will individual atomic primitives. Operations atomic, as will individual atomic primitives. Operations
performed under a lock and sequences of multiple atomic performed under a lock and sequences of multiple atomic
primitives will -not- appear to be atomic. primitives will -not- appear to be atomic.
This is almost always the best approach. This can work, but is starting to get a bit tricky.
b. Carefully order the updates and the reads so that d. Carefully order the updates and the reads so that
readers see valid data at all phases of the update. readers see valid data at all phases of the update.
This is often more difficult than it sounds, especially This is often more difficult than it sounds, especially
given modern CPUs' tendency to reorder memory references. given modern CPUs' tendency to reorder memory references.
...@@ -123,18 +142,22 @@ over a rather long period of time, but improvements are always welcome! ...@@ -123,18 +142,22 @@ over a rather long period of time, but improvements are always welcome!
when publicizing a pointer to a structure that can when publicizing a pointer to a structure that can
be traversed by an RCU read-side critical section. be traversed by an RCU read-side critical section.
5. If call_rcu(), or a related primitive such as call_rcu_bh(), 5. If call_rcu(), or a related primitive such as call_rcu_bh() or
is used, the callback function must be written to be called call_rcu_sched(), is used, the callback function must be
from softirq context. In particular, it cannot block. written to be called from softirq context. In particular,
it cannot block.
6. Since synchronize_rcu() can block, it cannot be called from 6. Since synchronize_rcu() can block, it cannot be called from
any sort of irq context. any sort of irq context. Ditto for synchronize_sched() and
synchronize_srcu().
7. If the updater uses call_rcu(), then the corresponding readers 7. If the updater uses call_rcu(), then the corresponding readers
must use rcu_read_lock() and rcu_read_unlock(). If the updater must use rcu_read_lock() and rcu_read_unlock(). If the updater
uses call_rcu_bh(), then the corresponding readers must use uses call_rcu_bh(), then the corresponding readers must use
rcu_read_lock_bh() and rcu_read_unlock_bh(). Mixing things up rcu_read_lock_bh() and rcu_read_unlock_bh(). If the updater
will result in confusion and broken kernels. uses call_rcu_sched(), then the corresponding readers must
disable preemption. Mixing things up will result in confusion
and broken kernels.
One exception to this rule: rcu_read_lock() and rcu_read_unlock() One exception to this rule: rcu_read_lock() and rcu_read_unlock()
may be substituted for rcu_read_lock_bh() and rcu_read_unlock_bh() may be substituted for rcu_read_lock_bh() and rcu_read_unlock_bh()
...@@ -143,9 +166,9 @@ over a rather long period of time, but improvements are always welcome! ...@@ -143,9 +166,9 @@ over a rather long period of time, but improvements are always welcome!
such cases is a must, of course! And the jury is still out on such cases is a must, of course! And the jury is still out on
whether the increased speed is worth it. whether the increased speed is worth it.
8. Although synchronize_rcu() is a bit slower than is call_rcu(), 8. Although synchronize_rcu() is slower than is call_rcu(), it
it usually results in simpler code. So, unless update usually results in simpler code. So, unless update performance
performance is critically important or the updaters cannot block, is critically important or the updaters cannot block,
synchronize_rcu() should be used in preference to call_rcu(). synchronize_rcu() should be used in preference to call_rcu().
An especially important property of the synchronize_rcu() An especially important property of the synchronize_rcu()
...@@ -187,23 +210,23 @@ over a rather long period of time, but improvements are always welcome! ...@@ -187,23 +210,23 @@ over a rather long period of time, but improvements are always welcome!
number of updates per grace period. number of updates per grace period.
9. All RCU list-traversal primitives, which include 9. All RCU list-traversal primitives, which include
list_for_each_rcu(), list_for_each_entry_rcu(), rcu_dereference(), list_for_each_rcu(), list_for_each_entry_rcu(),
list_for_each_continue_rcu(), and list_for_each_safe_rcu(), list_for_each_continue_rcu(), and list_for_each_safe_rcu(),
must be within an RCU read-side critical section. RCU must be either within an RCU read-side critical section or
must be protected by appropriate update-side locks. RCU
read-side critical sections are delimited by rcu_read_lock() read-side critical sections are delimited by rcu_read_lock()
and rcu_read_unlock(), or by similar primitives such as and rcu_read_unlock(), or by similar primitives such as
rcu_read_lock_bh() and rcu_read_unlock_bh(). rcu_read_lock_bh() and rcu_read_unlock_bh().
Use of the _rcu() list-traversal primitives outside of an The reason that it is permissible to use RCU list-traversal
RCU read-side critical section causes no harm other than primitives when the update-side lock is held is that doing so
a slight performance degradation on Alpha CPUs. It can can be quite helpful in reducing code bloat when common code is
also be quite helpful in reducing code bloat when common shared between readers and updaters.
code is shared between readers and updaters.
10. Conversely, if you are in an RCU read-side critical section, 10. Conversely, if you are in an RCU read-side critical section,
you -must- use the "_rcu()" variants of the list macros. and you don't hold the appropriate update-side lock, you -must-
Failing to do so will break Alpha and confuse people reading use the "_rcu()" variants of the list macros. Failing to do so
your code. will break Alpha and confuse people reading your code.
11. Note that synchronize_rcu() -only- guarantees to wait until 11. Note that synchronize_rcu() -only- guarantees to wait until
all currently executing rcu_read_lock()-protected RCU read-side all currently executing rcu_read_lock()-protected RCU read-side
...@@ -230,6 +253,14 @@ over a rather long period of time, but improvements are always welcome! ...@@ -230,6 +253,14 @@ over a rather long period of time, but improvements are always welcome!
must use whatever locking or other synchronization is required must use whatever locking or other synchronization is required
to safely access and/or modify that data structure. to safely access and/or modify that data structure.
RCU callbacks are -usually- executed on the same CPU that executed
the corresponding call_rcu(), call_rcu_bh(), or call_rcu_sched(),
but are by -no- means guaranteed to be. For example, if a given
CPU goes offline while having an RCU callback pending, then that
RCU callback will execute on some surviving CPU. (If this was
not the case, a self-spawning RCU callback would prevent the
victim CPU from ever going offline.)
14. SRCU (srcu_read_lock(), srcu_read_unlock(), and synchronize_srcu()) 14. SRCU (srcu_read_lock(), srcu_read_unlock(), and synchronize_srcu())
may only be invoked from process context. Unlike other forms of may only be invoked from process context. Unlike other forms of
RCU, it -is- permissible to block in an SRCU read-side critical RCU, it -is- permissible to block in an SRCU read-side critical
......
...@@ -10,23 +10,30 @@ status messages via printk(), which can be examined via the dmesg ...@@ -10,23 +10,30 @@ status messages via printk(), which can be examined via the dmesg
command (perhaps grepping for "torture"). The test is started command (perhaps grepping for "torture"). The test is started
when the module is loaded, and stops when the module is unloaded. when the module is loaded, and stops when the module is unloaded.
However, actually setting this config option to "y" results in the system CONFIG_RCU_TORTURE_TEST_RUNNABLE
running the test immediately upon boot, and ending only when the system
is taken down. Normally, one will instead want to build the system It is also possible to specify CONFIG_RCU_TORTURE_TEST=y, which will
with CONFIG_RCU_TORTURE_TEST=m and to use modprobe and rmmod to control result in the tests being loaded into the base kernel. In this case,
the test, perhaps using a script similar to the one shown at the end of the CONFIG_RCU_TORTURE_TEST_RUNNABLE config option is used to specify
this document. Note that you will need CONFIG_MODULE_UNLOAD in order whether the RCU torture tests are to be started immediately during
to be able to end the test. boot or whether the /proc/sys/kernel/rcutorture_runnable file is used
to enable them. This /proc file can be used to repeatedly pause and
restart the tests, regardless of the initial state specified by the
CONFIG_RCU_TORTURE_TEST_RUNNABLE config option.
You will normally -not- want to start the RCU torture tests during boot
(and thus the default is CONFIG_RCU_TORTURE_TEST_RUNNABLE=n), but doing
this can sometimes be useful in finding boot-time bugs.
MODULE PARAMETERS MODULE PARAMETERS
This module has the following parameters: This module has the following parameters:
nreaders This is the number of RCU reading threads supported. irqreaders Says to invoke RCU readers from irq level. This is currently
The default is twice the number of CPUs. Why twice? done via timers. Defaults to "1" for variants of RCU that
To properly exercise RCU implementations with preemptible permit this. (Or, more accurately, variants of RCU that do
read-side critical sections. -not- permit this know to ignore this variable.)
nfakewriters This is the number of RCU fake writer threads to run. Fake nfakewriters This is the number of RCU fake writer threads to run. Fake
writer threads repeatedly use the synchronous "wait for writer threads repeatedly use the synchronous "wait for
...@@ -37,6 +44,16 @@ nfakewriters This is the number of RCU fake writer threads to run. Fake ...@@ -37,6 +44,16 @@ nfakewriters This is the number of RCU fake writer threads to run. Fake
to trigger special cases caused by multiple writers, such as to trigger special cases caused by multiple writers, such as
the synchronize_srcu() early return optimization. the synchronize_srcu() early return optimization.
nreaders This is the number of RCU reading threads supported.
The default is twice the number of CPUs. Why twice?
To properly exercise RCU implementations with preemptible
read-side critical sections.
shuffle_interval
The number of seconds to keep the test threads affinitied
to a particular subset of the CPUs, defaults to 3 seconds.
Used in conjunction with test_no_idle_hz.
stat_interval The number of seconds between output of torture stat_interval The number of seconds between output of torture
statistics (via printk()). Regardless of the interval, statistics (via printk()). Regardless of the interval,
statistics are printed when the module is unloaded. statistics are printed when the module is unloaded.
...@@ -44,10 +61,11 @@ stat_interval The number of seconds between output of torture ...@@ -44,10 +61,11 @@ stat_interval The number of seconds between output of torture
be printed -only- when the module is unloaded, and this be printed -only- when the module is unloaded, and this
is the default. is the default.
shuffle_interval stutter The length of time to run the test before pausing for this
The number of seconds to keep the test threads affinitied same period of time. Defaults to "stutter=5", so as
to a particular subset of the CPUs, defaults to 5 seconds. to run and pause for (roughly) five-second intervals.
Used in conjunction with test_no_idle_hz. Specifying "stutter=0" causes the test to run continuously
without pausing, which is the old default behavior.
test_no_idle_hz Whether or not to test the ability of RCU to operate in test_no_idle_hz Whether or not to test the ability of RCU to operate in
a kernel that disables the scheduling-clock interrupt to a kernel that disables the scheduling-clock interrupt to
......
Please note that the "What is RCU?" LWN series is an excellent place
to start learning about RCU:
1. What is RCU, Fundamentally? http://lwn.net/Articles/262464/
2. What is RCU? Part 2: Usage http://lwn.net/Articles/263130/
3. RCU part 3: the RCU API http://lwn.net/Articles/264090/
What is RCU? What is RCU?
RCU is a synchronization mechanism that was added to the Linux kernel RCU is a synchronization mechanism that was added to the Linux kernel
...@@ -772,26 +780,18 @@ Linux-kernel source code, but it helps to have a full list of the ...@@ -772,26 +780,18 @@ Linux-kernel source code, but it helps to have a full list of the
APIs, since there does not appear to be a way to categorize them APIs, since there does not appear to be a way to categorize them
in docbook. Here is the list, by category. in docbook. Here is the list, by category.
Markers for RCU read-side critical sections:
rcu_read_lock
rcu_read_unlock
rcu_read_lock_bh
rcu_read_unlock_bh
srcu_read_lock
srcu_read_unlock
RCU pointer/list traversal: RCU pointer/list traversal:
rcu_dereference rcu_dereference
list_for_each_entry_rcu
hlist_for_each_entry_rcu
list_for_each_rcu (to be deprecated in favor of list_for_each_rcu (to be deprecated in favor of
list_for_each_entry_rcu) list_for_each_entry_rcu)
list_for_each_entry_rcu
list_for_each_continue_rcu (to be deprecated in favor of new list_for_each_continue_rcu (to be deprecated in favor of new
list_for_each_entry_continue_rcu) list_for_each_entry_continue_rcu)
hlist_for_each_entry_rcu
RCU pointer update: RCU pointer/list update:
rcu_assign_pointer rcu_assign_pointer
list_add_rcu list_add_rcu
...@@ -799,16 +799,36 @@ RCU pointer update: ...@@ -799,16 +799,36 @@ RCU pointer update:
list_del_rcu list_del_rcu
list_replace_rcu list_replace_rcu
hlist_del_rcu hlist_del_rcu
hlist_add_after_rcu
hlist_add_before_rcu
hlist_add_head_rcu hlist_add_head_rcu
hlist_replace_rcu
list_splice_init_rcu()
RCU grace period: RCU: Critical sections Grace period Barrier
synchronize_net rcu_read_lock synchronize_net rcu_barrier
synchronize_sched rcu_read_unlock synchronize_rcu
synchronize_rcu
synchronize_srcu
call_rcu call_rcu
call_rcu_bh
bh: Critical sections Grace period Barrier
rcu_read_lock_bh call_rcu_bh rcu_barrier_bh
rcu_read_unlock_bh
sched: Critical sections Grace period Barrier
[preempt_disable] synchronize_sched rcu_barrier_sched
[and friends] call_rcu_sched
SRCU: Critical sections Grace period Barrier
srcu_read_lock synchronize_srcu N/A
srcu_read_unlock
See the comment headers in the source code (or the docbook generated See the comment headers in the source code (or the docbook generated
from them) for more information. from them) for more information.
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include <linux/irq.h> #include <linux/irq.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/rculist.h>
#include <asm/sn/addrs.h> #include <asm/sn/addrs.h>
#include <asm/sn/arch.h> #include <asm/sn/arch.h>
#include <asm/sn/intr.h> #include <asm/sn/intr.h>
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
* 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
* *
*/ */
#include <linux/rculist.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/async_tx.h> #include <linux/async_tx.h>
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <rdma/ib_user_verbs.h> #include <rdma/ib_user_verbs.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/utsname.h> #include <linux/utsname.h>
#include <linux/rculist.h>
#include "ipath_kernel.h" #include "ipath_kernel.h"
#include "ipath_verbs.h" #include "ipath_verbs.h"
......
...@@ -31,8 +31,7 @@ ...@@ -31,8 +31,7 @@
* SOFTWARE. * SOFTWARE.
*/ */
#include <linux/list.h> #include <linux/rculist.h>
#include <linux/rcupdate.h>
#include "ipath_verbs.h" #include "ipath_verbs.h"
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/list.h> #include <linux/rculist.h>
#include <linux/notifier.h> #include <linux/notifier.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/etherdevice.h> #include <linux/etherdevice.h>
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
#include <asm/atomic.h> #include <asm/atomic.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/rculist.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/cache.h> #include <linux/cache.h>
#include <linux/rcupdate.h> #include <linux/rcupdate.h>
......
This diff is collapsed.
...@@ -151,7 +151,10 @@ extern struct lockdep_map rcu_lock_map; ...@@ -151,7 +151,10 @@ extern struct lockdep_map rcu_lock_map;
#define __synchronize_sched() synchronize_rcu() #define __synchronize_sched() synchronize_rcu()
#define call_rcu_sched(head, func) call_rcu(head, func)
extern void __rcu_init(void); extern void __rcu_init(void);
#define rcu_init_sched() do { } while (0)
extern void rcu_check_callbacks(int cpu, int user); extern void rcu_check_callbacks(int cpu, int user);
extern void rcu_restart_cpu(int cpu); extern void rcu_restart_cpu(int cpu);
......
This diff is collapsed.
...@@ -40,6 +40,7 @@ ...@@ -40,6 +40,7 @@
#include <linux/cpumask.h> #include <linux/cpumask.h>
#include <linux/seqlock.h> #include <linux/seqlock.h>
#include <linux/lockdep.h> #include <linux/lockdep.h>
#include <linux/completion.h>
/** /**
* struct rcu_head - callback structure for use with RCU * struct rcu_head - callback structure for use with RCU
...@@ -168,6 +169,27 @@ struct rcu_head { ...@@ -168,6 +169,27 @@ struct rcu_head {
(p) = (v); \ (p) = (v); \
}) })
/* Infrastructure to implement the synchronize_() primitives. */
struct rcu_synchronize {
struct rcu_head head;
struct completion completion;
};
extern void wakeme_after_rcu(struct rcu_head *head);
#define synchronize_rcu_xxx(name, func) \
void name(void) \
{ \
struct rcu_synchronize rcu; \
\
init_completion(&rcu.completion); \
/* Will wake me after RCU finished. */ \
func(&rcu.head, wakeme_after_rcu); \
/* Wait for it. */ \
wait_for_completion(&rcu.completion); \
}
/** /**
* synchronize_sched - block until all CPUs have exited any non-preemptive * synchronize_sched - block until all CPUs have exited any non-preemptive
* kernel code sequences. * kernel code sequences.
...@@ -224,8 +246,8 @@ extern void call_rcu_bh(struct rcu_head *head, ...@@ -224,8 +246,8 @@ extern void call_rcu_bh(struct rcu_head *head,
/* Exported common interfaces */ /* Exported common interfaces */
extern void synchronize_rcu(void); extern void synchronize_rcu(void);
extern void rcu_barrier(void); extern void rcu_barrier(void);
extern long rcu_batches_completed(void); extern void rcu_barrier_bh(void);
extern long rcu_batches_completed_bh(void); extern void rcu_barrier_sched(void);
/* Internal to kernel */ /* Internal to kernel */
extern void rcu_init(void); extern void rcu_init(void);
......
...@@ -40,10 +40,39 @@ ...@@ -40,10 +40,39 @@
#include <linux/cpumask.h> #include <linux/cpumask.h>
#include <linux/seqlock.h> #include <linux/seqlock.h>
#define rcu_qsctr_inc(cpu) struct rcu_dyntick_sched {
int dynticks;
int dynticks_snap;
int sched_qs;
int sched_qs_snap;
int sched_dynticks_snap;
};
DECLARE_PER_CPU(struct rcu_dyntick_sched, rcu_dyntick_sched);
static inline void rcu_qsctr_inc(int cpu)
{
struct rcu_dyntick_sched *rdssp = &per_cpu(rcu_dyntick_sched, cpu);
rdssp->sched_qs++;
}
#define rcu_bh_qsctr_inc(cpu) #define rcu_bh_qsctr_inc(cpu)
#define call_rcu_bh(head, rcu) call_rcu(head, rcu) #define call_rcu_bh(head, rcu) call_rcu(head, rcu)
/**
* call_rcu_sched - Queue RCU callback for invocation after sched grace period.
* @head: structure to be used for queueing the RCU updates.
* @func: actual update function to be invoked after the grace period
*
* The update function will be invoked some time after a full
* synchronize_sched()-style grace period elapses, in other words after
* all currently executing preempt-disabled sections of code (including
* hardirq handlers, NMI handlers, and local_irq_save() blocks) have
* completed.
*/
extern void call_rcu_sched(struct rcu_head *head,
void (*func)(struct rcu_head *head));
extern void __rcu_read_lock(void) __acquires(RCU); extern void __rcu_read_lock(void) __acquires(RCU);
extern void __rcu_read_unlock(void) __releases(RCU); extern void __rcu_read_unlock(void) __releases(RCU);
extern int rcu_pending(int cpu); extern int rcu_pending(int cpu);
...@@ -55,6 +84,7 @@ extern int rcu_needs_cpu(int cpu); ...@@ -55,6 +84,7 @@ extern int rcu_needs_cpu(int cpu);
extern void __synchronize_sched(void); extern void __synchronize_sched(void);
extern void __rcu_init(void); extern void __rcu_init(void);
extern void rcu_init_sched(void);
extern void rcu_check_callbacks(int cpu, int user); extern void rcu_check_callbacks(int cpu, int user);
extern void rcu_restart_cpu(int cpu); extern void rcu_restart_cpu(int cpu);
extern long rcu_batches_completed(void); extern long rcu_batches_completed(void);
...@@ -81,20 +111,20 @@ extern struct rcupreempt_trace *rcupreempt_trace_cpu(int cpu); ...@@ -81,20 +111,20 @@ extern struct rcupreempt_trace *rcupreempt_trace_cpu(int cpu);
struct softirq_action; struct softirq_action;
#ifdef CONFIG_NO_HZ #ifdef CONFIG_NO_HZ
DECLARE_PER_CPU(long, dynticks_progress_counter); DECLARE_PER_CPU(struct rcu_dyntick_sched, rcu_dyntick_sched);
static inline void rcu_enter_nohz(void) static inline void rcu_enter_nohz(void)
{ {
smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */ smp_mb(); /* CPUs seeing ++ must see prior RCU read-side crit sects */
__get_cpu_var(dynticks_progress_counter)++; __get_cpu_var(rcu_dyntick_sched).dynticks++;
WARN_ON(__get_cpu_var(dynticks_progress_counter) & 0x1); WARN_ON(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1);
} }
static inline void rcu_exit_nohz(void) static inline void rcu_exit_nohz(void)
{ {
__get_cpu_var(dynticks_progress_counter)++;
smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */ smp_mb(); /* CPUs seeing ++ must see later RCU read-side crit sects */
WARN_ON(!(__get_cpu_var(dynticks_progress_counter) & 0x1)); __get_cpu_var(rcu_dyntick_sched).dynticks++;
WARN_ON(!(__get_cpu_var(rcu_dyntick_sched).dynticks & 0x1));
} }
#else /* CONFIG_NO_HZ */ #else /* CONFIG_NO_HZ */
......
...@@ -758,6 +758,7 @@ static void __init do_initcalls(void) ...@@ -758,6 +758,7 @@ static void __init do_initcalls(void)
*/ */
static void __init do_basic_setup(void) static void __init do_basic_setup(void)
{ {
rcu_init_sched(); /* needed by module_init stage. */
/* drivers will send hotplug events */ /* drivers will send hotplug events */
init_workqueues(); init_workqueues();
usermodehelper_init(); usermodehelper_init();
......
...@@ -30,6 +30,7 @@ ...@@ -30,6 +30,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/rculist.h>
#include <linux/bootmem.h> #include <linux/bootmem.h>
#include <linux/hash.h> #include <linux/hash.h>
#include <linux/pid_namespace.h> #include <linux/pid_namespace.h>
......
...@@ -387,6 +387,10 @@ static void __rcu_offline_cpu(struct rcu_data *this_rdp, ...@@ -387,6 +387,10 @@ static void __rcu_offline_cpu(struct rcu_data *this_rdp,
rcu_move_batch(this_rdp, rdp->donelist, rdp->donetail); rcu_move_batch(this_rdp, rdp->donelist, rdp->donetail);
rcu_move_batch(this_rdp, rdp->curlist, rdp->curtail); rcu_move_batch(this_rdp, rdp->curlist, rdp->curtail);
rcu_move_batch(this_rdp, rdp->nxtlist, rdp->nxttail); rcu_move_batch(this_rdp, rdp->nxtlist, rdp->nxttail);
local_irq_disable();
this_rdp->qlen += rdp->qlen;
local_irq_enable();
} }
static void rcu_offline_cpu(int cpu) static void rcu_offline_cpu(int cpu)
...@@ -516,10 +520,38 @@ void rcu_check_callbacks(int cpu, int user) ...@@ -516,10 +520,38 @@ void rcu_check_callbacks(int cpu, int user)
if (user || if (user ||
(idle_cpu(cpu) && !in_softirq() && (idle_cpu(cpu) && !in_softirq() &&
hardirq_count() <= (1 << HARDIRQ_SHIFT))) { hardirq_count() <= (1 << HARDIRQ_SHIFT))) {
/*
* Get here if this CPU took its interrupt from user
* mode or from the idle loop, and if this is not a
* nested interrupt. In this case, the CPU is in
* a quiescent state, so count it.
*
* Also do a memory barrier. This is needed to handle
* the case where writes from a preempt-disable section
* of code get reordered into schedule() by this CPU's
* write buffer. The memory barrier makes sure that
* the rcu_qsctr_inc() and rcu_bh_qsctr_inc() are see
* by other CPUs to happen after any such write.
*/
smp_mb(); /* See above block comment. */
rcu_qsctr_inc(cpu); rcu_qsctr_inc(cpu);
rcu_bh_qsctr_inc(cpu); rcu_bh_qsctr_inc(cpu);
} else if (!in_softirq())
} else if (!in_softirq()) {
/*
* Get here if this CPU did not take its interrupt from
* softirq, in other words, if it is not interrupting
* a rcu_bh read-side critical section. This is an _bh
* critical section, so count it. The memory barrier
* is needed for the same reason as is the above one.
*/
smp_mb(); /* See above block comment. */
rcu_bh_qsctr_inc(cpu); rcu_bh_qsctr_inc(cpu);
}
raise_rcu_softirq(); raise_rcu_softirq();
} }
......
...@@ -39,16 +39,16 @@ ...@@ -39,16 +39,16 @@
#include <linux/sched.h> #include <linux/sched.h>
#include <asm/atomic.h> #include <asm/atomic.h>
#include <linux/bitops.h> #include <linux/bitops.h>
#include <linux/completion.h>
#include <linux/percpu.h> #include <linux/percpu.h>
#include <linux/notifier.h> #include <linux/notifier.h>
#include <linux/cpu.h> #include <linux/cpu.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/module.h> #include <linux/module.h>
struct rcu_synchronize { enum rcu_barrier {
struct rcu_head head; RCU_BARRIER_STD,
struct completion completion; RCU_BARRIER_BH,
RCU_BARRIER_SCHED,
}; };
static DEFINE_PER_CPU(struct rcu_head, rcu_barrier_head) = {NULL}; static DEFINE_PER_CPU(struct rcu_head, rcu_barrier_head) = {NULL};
...@@ -60,7 +60,7 @@ static struct completion rcu_barrier_completion; ...@@ -60,7 +60,7 @@ static struct completion rcu_barrier_completion;
* Awaken the corresponding synchronize_rcu() instance now that a * Awaken the corresponding synchronize_rcu() instance now that a
* grace period has elapsed. * grace period has elapsed.
*/ */
static void wakeme_after_rcu(struct rcu_head *head) void wakeme_after_rcu(struct rcu_head *head)
{ {
struct rcu_synchronize *rcu; struct rcu_synchronize *rcu;
...@@ -77,17 +77,7 @@ static void wakeme_after_rcu(struct rcu_head *head) ...@@ -77,17 +77,7 @@ static void wakeme_after_rcu(struct rcu_head *head)
* sections are delimited by rcu_read_lock() and rcu_read_unlock(), * sections are delimited by rcu_read_lock() and rcu_read_unlock(),
* and may be nested. * and may be nested.
*/ */
void synchronize_rcu(void) synchronize_rcu_xxx(synchronize_rcu, call_rcu)
{
struct rcu_synchronize rcu;
init_completion(&rcu.completion);
/* Will wake me after RCU finished */
call_rcu(&rcu.head, wakeme_after_rcu);
/* Wait for it */
wait_for_completion(&rcu.completion);
}
EXPORT_SYMBOL_GPL(synchronize_rcu); EXPORT_SYMBOL_GPL(synchronize_rcu);
static void rcu_barrier_callback(struct rcu_head *notused) static void rcu_barrier_callback(struct rcu_head *notused)
...@@ -99,19 +89,30 @@ static void rcu_barrier_callback(struct rcu_head *notused) ...@@ -99,19 +89,30 @@ static void rcu_barrier_callback(struct rcu_head *notused)
/* /*
* Called with preemption disabled, and from cross-cpu IRQ context. * Called with preemption disabled, and from cross-cpu IRQ context.
*/ */
static void rcu_barrier_func(void *notused) static void rcu_barrier_func(void *type)
{ {
int cpu = smp_processor_id(); int cpu = smp_processor_id();
struct rcu_head *head = &per_cpu(rcu_barrier_head, cpu); struct rcu_head *head = &per_cpu(rcu_barrier_head, cpu);
atomic_inc(&rcu_barrier_cpu_count); atomic_inc(&rcu_barrier_cpu_count);
switch ((enum rcu_barrier)type) {
case RCU_BARRIER_STD:
call_rcu(head, rcu_barrier_callback); call_rcu(head, rcu_barrier_callback);
break;
case RCU_BARRIER_BH:
call_rcu_bh(head, rcu_barrier_callback);
break;
case RCU_BARRIER_SCHED:
call_rcu_sched(head, rcu_barrier_callback);
break;
}
} }
/** /*
* rcu_barrier - Wait until all the in-flight RCUs are complete. * Orchestrate the specified type of RCU barrier, waiting for all
* RCU callbacks of the specified type to complete.
*/ */
void rcu_barrier(void) static void _rcu_barrier(enum rcu_barrier type)
{ {
BUG_ON(in_interrupt()); BUG_ON(in_interrupt());
/* Take cpucontrol mutex to protect against CPU hotplug */ /* Take cpucontrol mutex to protect against CPU hotplug */
...@@ -127,13 +128,39 @@ void rcu_barrier(void) ...@@ -127,13 +128,39 @@ void rcu_barrier(void)
* until all the callbacks are queued. * until all the callbacks are queued.
*/ */
rcu_read_lock(); rcu_read_lock();
on_each_cpu(rcu_barrier_func, NULL, 0, 1); on_each_cpu(rcu_barrier_func, (void *)type, 0, 1);
rcu_read_unlock(); rcu_read_unlock();
wait_for_completion(&rcu_barrier_completion); wait_for_completion(&rcu_barrier_completion);
mutex_unlock(&rcu_barrier_mutex); mutex_unlock(&rcu_barrier_mutex);
} }
/**
* rcu_barrier - Wait until all in-flight call_rcu() callbacks complete.
*/
void rcu_barrier(void)
{
_rcu_barrier(RCU_BARRIER_STD);
}
EXPORT_SYMBOL_GPL(rcu_barrier); EXPORT_SYMBOL_GPL(rcu_barrier);
/**
* rcu_barrier_bh - Wait until all in-flight call_rcu_bh() callbacks complete.
*/
void rcu_barrier_bh(void)
{
_rcu_barrier(RCU_BARRIER_BH);
}
EXPORT_SYMBOL_GPL(rcu_barrier_bh);
/**
* rcu_barrier_sched - Wait for in-flight call_rcu_sched() callbacks.
*/
void rcu_barrier_sched(void)
{
_rcu_barrier(RCU_BARRIER_SCHED);
}
EXPORT_SYMBOL_GPL(rcu_barrier_sched);
void __init rcu_init(void) void __init rcu_init(void)
{ {
__rcu_init(); __rcu_init();
......
This diff is collapsed.
...@@ -38,7 +38,6 @@ ...@@ -38,7 +38,6 @@
#include <linux/moduleparam.h> #include <linux/moduleparam.h>
#include <linux/percpu.h> #include <linux/percpu.h>
#include <linux/notifier.h> #include <linux/notifier.h>
#include <linux/rcupdate.h>
#include <linux/cpu.h> #include <linux/cpu.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/rcupreempt_trace.h> #include <linux/rcupreempt_trace.h>
......
This diff is collapsed.
...@@ -83,6 +83,9 @@ extern int maps_protect; ...@@ -83,6 +83,9 @@ extern int maps_protect;
extern int sysctl_stat_interval; extern int sysctl_stat_interval;
extern int latencytop_enabled; extern int latencytop_enabled;
extern int sysctl_nr_open_min, sysctl_nr_open_max; extern int sysctl_nr_open_min, sysctl_nr_open_max;
#ifdef CONFIG_RCU_TORTURE_TEST
extern int rcutorture_runnable;
#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
/* Constants used for minimum and maximum */ /* Constants used for minimum and maximum */
#if defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM) #if defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM)
...@@ -820,6 +823,16 @@ static struct ctl_table kern_table[] = { ...@@ -820,6 +823,16 @@ static struct ctl_table kern_table[] = {
.child = key_sysctls, .child = key_sysctls,
}, },
#endif #endif
#ifdef CONFIG_RCU_TORTURE_TEST
{
.ctl_name = CTL_UNNUMBERED,
.procname = "rcutorture_runnable",
.data = &rcutorture_runnable,
.maxlen = sizeof(int),
.mode = 0644,
.proc_handler = &proc_dointvec,
},
#endif
/* /*
* NOTE: do not add new entries to this table unless you have read * NOTE: do not add new entries to this table unless you have read
* Documentation/sysctl/ctl_unnumbered.txt * Documentation/sysctl/ctl_unnumbered.txt
......
...@@ -530,16 +530,34 @@ config BOOT_PRINTK_DELAY ...@@ -530,16 +530,34 @@ config BOOT_PRINTK_DELAY
config RCU_TORTURE_TEST config RCU_TORTURE_TEST
tristate "torture tests for RCU" tristate "torture tests for RCU"
depends on DEBUG_KERNEL depends on DEBUG_KERNEL
depends on m
default n default n
help help
This option provides a kernel module that runs torture tests This option provides a kernel module that runs torture tests
on the RCU infrastructure. The kernel module may be built on the RCU infrastructure. The kernel module may be built
after the fact on the running kernel to be tested, if desired. after the fact on the running kernel to be tested, if desired.
Say Y here if you want RCU torture tests to be built into
the kernel.
Say M if you want the RCU torture tests to build as a module. Say M if you want the RCU torture tests to build as a module.
Say N if you are unsure. Say N if you are unsure.
config RCU_TORTURE_TEST_RUNNABLE
bool "torture tests for RCU runnable by default"
depends on RCU_TORTURE_TEST = y
default n
help
This option provides a way to build the RCU torture tests
directly into the kernel without them starting up at boot
time. You can use /proc/sys/kernel/rcutorture_runnable
to manually override this setting. This /proc file is
available only when the RCU torture tests have been built
into the kernel.
Say Y here if you want the RCU torture tests to start during
boot (you probably don't).
Say N here if you want the RCU torture tests to start only
after being manually enabled via /proc.
config KPROBES_SANITY_TEST config KPROBES_SANITY_TEST
bool "Kprobes sanity tests" bool "Kprobes sanity tests"
depends on DEBUG_KERNEL depends on DEBUG_KERNEL
......
...@@ -97,6 +97,7 @@ ...@@ -97,6 +97,7 @@
#include <linux/types.h> #include <linux/types.h>
#include <linux/string.h> #include <linux/string.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/rculist.h>
#include <linux/rcupdate.h> #include <linux/rcupdate.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/textsearch.h> #include <linux/textsearch.h>
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/in.h> #include <linux/in.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/rculist.h>
static LIST_HEAD(snap_list); static LIST_HEAD(snap_list);
static DEFINE_SPINLOCK(snap_lock); static DEFINE_SPINLOCK(snap_lock);
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include <linux/mm.h> #include <linux/mm.h>
#include <linux/in.h> #include <linux/in.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/rculist.h>
#include <net/p8022.h> #include <net/p8022.h>
#include <net/arp.h> #include <net/arp.h>
#include <linux/rtnetlink.h> #include <linux/rtnetlink.h>
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/rculist.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/times.h> #include <linux/times.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* 2 of the License, or (at your option) any later version. * 2 of the License, or (at your option) any later version.
*/ */
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/rculist.h>
#include "br_private.h" #include "br_private.h"
#include "br_private_stp.h" #include "br_private_stp.h"
......
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <linux/err.h> #include <linux/err.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/rculist.h>
#include <net/netfilter/nf_conntrack.h> #include <net/netfilter/nf_conntrack.h>
#include <net/netfilter/nf_conntrack_l3proto.h> #include <net/netfilter/nf_conntrack_l3proto.h>
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/rculist.h>
#include <linux/types.h> #include <linux/types.h>
#include <linux/timer.h> #include <linux/timer.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
......
...@@ -30,8 +30,7 @@ ...@@ -30,8 +30,7 @@
*/ */
#include <linux/types.h> #include <linux/types.h>
#include <linux/rcupdate.h> #include <linux/rculist.h>
#include <linux/list.h>
#include <linux/skbuff.h> #include <linux/skbuff.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/string.h> #include <linux/string.h>
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment