diff options
| author | Paul E. McKenney <paulmck@linux.vnet.ibm.com> | 2008-12-18 15:55:32 -0500 |
|---|---|---|
| committer | Ingo Molnar <mingo@elte.hu> | 2008-12-18 15:56:04 -0500 |
| commit | 64db4cfff99c04cd5f550357edcc8780f96b54a2 (patch) | |
| tree | 4856e788d21f0e31ed78a22b70b4521f7237705e | |
| parent | d110ec3a1e1f522e2e9dfceb9c36d6590c26d2d4 (diff) | |
"Tree RCU": scalable classic RCU implementation
This patch fixes a long-standing performance bug in classic RCU that
results in massive internal-to-RCU lock contention on systems with
more than a few hundred CPUs. Although this patch creates a separate
flavor of RCU for ease of review and patch maintenance, it is intended
to replace classic RCU.
This patch still handles stress better than does mainline, so I am still
calling it ready for inclusion. This patch is against the -tip tree.
Nevertheless, experience on an actual 1000+ CPU machine would still be
most welcome.
Most of the changes noted below were found while creating an rcutiny
(which should permit ejecting the current rcuclassic) and while doing
detailed line-by-line documentation.
Updates from v9 (http://lkml.org/lkml/2008/12/2/334):
o Fixes from remainder of line-by-line code walkthrough,
including comment spelling, initialization, undesirable
narrowing due to type conversion, removing redundant memory
barriers, removing redundant local-variable initialization,
and removing redundant local variables.
I do not believe that any of these fixes address the CPU-hotplug
issues that Andi Kleen was seeing, but please do give it a whirl
in case the machine is smarter than I am.
A writeup from the walkthrough may be found at the following
URL, in case you are suffering from terminal insomnia or
masochism:
http://www.kernel.org/pub/linux/kernel/people/paulmck/tmp/rcutree-walkthrough.2008.12.16a.pdf
o Made rcutree tracing use seq_file, as suggested some time
ago by Lai Jiangshan.
o Added a .csv variant of the rcudata debugfs trace file, to allow
people having thousands of CPUs to drop the data into
a spreadsheet. Tested with oocalc and gnumeric. Updated
documentation to suit.
Updates from v8 (http://lkml.org/lkml/2008/11/15/139):
o Fix a theoretical race between grace-period initialization and
force_quiescent_state() that could occur if more than three
jiffies were required to carry out the grace-period
initialization. Which it might, if you had enough CPUs.
o Apply Ingo's printk-standardization patch.
o Substitute local variables for repeated accesses to global
variables.
o Fix comment misspellings and redundant (but harmless) increments
of ->n_rcu_pending (this latter after having explicitly added it).
o Apply checkpatch fixes.
Updates from v7 (http://lkml.org/lkml/2008/10/10/291):
o Fixed a number of problems noted by Gautham Shenoy, including
the cpu-stall-detection bug that he was having difficulty
convincing me was real. ;-)
o Changed cpu-stall detection to wait for ten seconds rather than
three in order to reduce false positive, as suggested by Ingo
Molnar.
o Produced a design document (http://lwn.net/Articles/305782/).
The act of writing this document uncovered a number of both
theoretical and "here and now" bugs as noted below.
o Fix dynticks_nesting accounting confusion, simplify WARN_ON()
condition, fix kerneldoc comments, and add memory barriers
in dynticks interface functions.
o Add more data to tracing.
o Remove unused "rcu_barrier" field from rcu_data structure.
o Count calls to rcu_pending() from scheduling-clock interrupt
to use as a surrogate timebase should jiffies stop counting.
o Fix a theoretical race between force_quiescent_state() and
grace-period initialization. Yes, initialization does have to
go on for some jiffies for this race to occur, but given enough
CPUs...
Updates from v6 (http://lkml.org/lkml/2008/9/23/448):
o Fix a number of checkpatch.pl complaints.
o Apply review comments from Ingo Molnar and Lai Jiangshan
on the stall-detection code.
o Fix several bugs in !CONFIG_SMP builds.
o Fix a misspelled config-parameter name so that RCU now announces
at boot time if stall detection is configured.
o Run tests on numerous combinations of configurations parameters,
which after the fixes above, now build and run correctly.
Updates from v5 (http://lkml.org/lkml/2008/9/15/92, bad subject line):
o Fix a compiler error in the !CONFIG_FANOUT_EXACT case (blew a
changeset some time ago, and finally got around to retesting
this option).
o Fix some tracing bugs in rcupreempt that caused incorrect
totals to be printed.
o I now test with a more brutal random-selection online/offline
script (attached). Probably more brutal than it needs to be
on the people reading it as well, but so it goes.
o A number of optimizations and usability improvements:
o Make rcu_pending() ignore the grace-period timeout when
there is no grace period in progress.
o Make force_quiescent_state() avoid going for a global
lock in the case where there is no grace period in
progress.
o Rearrange struct fields to improve struct layout.
o Make call_rcu() initiate a grace period if RCU was
idle, rather than waiting for the next scheduling
clock interrupt.
o Invoke rcu_irq_enter() and rcu_irq_exit() only when
idle, as suggested by Andi Kleen. I still don't
completely trust this change, and might back it out.
o Make CONFIG_RCU_TRACE be the single config variable
manipulated for all forms of RCU, instead of the prior
confusion.
o Document tracing files and formats for both rcupreempt
and rcutree.
Updates from v4 for those missing v5 given its bad subject line:
o Separated dynticks interface so that NMIs and irqs call separate
functions, greatly simplifying it. In particular, this code
no longer requires a proof of correctness. ;-)
o Separated dynticks state out into its own per-CPU structure,
avoiding the duplicated accounting.
o The case where a dynticks-idle CPU runs an irq handler that
invokes call_rcu() is now correctly handled, forcing that CPU
out of dynticks-idle mode.
o Review comments have been applied (thank you all!!!).
For but one example, fixed the dynticks-ordering issue that
Manfred pointed out, saving me much debugging. ;-)
o Adjusted rcuclassic and rcupreempt to handle dynticks changes.
Attached is an updated patch to Classic RCU that applies a hierarchy,
greatly reducing the contention on the top-level lock for large machines.
This passes 10-hour concurrent rcutorture and online-offline testing on
128-CPU ppc64 without dynticks enabled, and exposes some timekeeping
bugs in presence of dynticks (exciting working on a system where
"sleep 1" hangs until interrupted...), which were fixed in the
2.6.27 kernel. It is getting more reliable than mainline by some
measures, so the next version will be against -tip for inclusion.
See also Manfred Spraul's recent patches (or his earlier work from
2004 at http://marc.info/?l=linux-kernel&m=108546384711797&w=2).
We will converge onto a common patch in the fullness of time, but are
currently exploring different regions of the design space. That said,
I have already gratefully stolen quite a few of Manfred's ideas.
This patch provides CONFIG_RCU_FANOUT, which controls the bushiness
of the RCU hierarchy. Defaults to 32 on 32-bit machines and 64 on
64-bit machines. If CONFIG_NR_CPUS is less than CONFIG_RCU_FANOUT,
there is no hierarchy. By default, the RCU initialization code will
adjust CONFIG_RCU_FANOUT to balance the hierarchy, so strongly NUMA
architectures may choose to set CONFIG_RCU_FANOUT_EXACT to disable
this balancing, allowing the hierarchy to be exactly aligned to the
underlying hardware. Up to two levels of hierarchy are permitted
(in addition to the root node), allowing up to 16,384 CPUs on 32-bit
systems and up to 262,144 CPUs on 64-bit systems. I just know that I
am going to regret saying this, but this seems more than sufficient
for the foreseeable future. (Some architectures might wish to set
CONFIG_RCU_FANOUT=4, which would limit such architectures to 64 CPUs.
If this becomes a real problem, additional levels can be added, but I
doubt that it will make a significant difference on real hardware.)
In the common case, a given CPU will manipulate its private rcu_data
structure and the rcu_node structure that it shares with its immediate
neighbors. This can reduce both lock and memory contention by multiple
orders of magnitude, which should eliminate the need for the strange
manipulations that are reported to be required when running Linux on
very large systems.
Some shortcomings:
o More bugs will probably surface as a result of an ongoing
line-by-line code inspection.
Patches will be provided as required.
o There are probably hangs, rcutorture failures, &c. Seems
quite stable on a 128-CPU machine, but that is kind of small
compared to 4096 CPUs. However, seems to do better than
mainline.
Patches will be provided as required.
o The memory footprint of this version is several KB larger
than rcuclassic.
A separate UP-only rcutiny patch will be provided, which will
reduce the memory footprint significantly, even compared
to the old rcuclassic. One such patch passes light testing,
and has a memory footprint smaller even than rcuclassic.
Initial reaction from various embedded guys was "it is not
worth it", so am putting it aside.
Credits:
o Manfred Spraul for ideas, review comments, and bugs spotted,
as well as some good friendly competition. ;-)
o Josh Triplett, Ingo Molnar, Peter Zijlstra, Mathieu Desnoyers,
Lai Jiangshan, Andi Kleen, Andy Whitcroft, and Andrew Morton
for reviews and comments.
o Thomas Gleixner for much-needed help with some timer issues
(see patches below).
o Jon M. Tollefson, Tim Pepper, Andrew Theurer, Jose R. Santos,
Andy Whitcroft, Darrick Wong, Nishanth Aravamudan, Anton
Blanchard, Dave Kleikamp, and Nathan Lynch for keeping machines
alive despite my heavy abuse^Wtesting.
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
| -rw-r--r-- | Documentation/RCU/00-INDEX | 2 | ||||
| -rw-r--r-- | Documentation/RCU/trace.txt | 413 | ||||
| -rw-r--r-- | arch/powerpc/platforms/pseries/rtasd.c | 4 | ||||
| -rw-r--r-- | include/linux/hardirq.h | 14 | ||||
| -rw-r--r-- | include/linux/rcupdate.h | 10 | ||||
| -rw-r--r-- | include/linux/rcutree.h | 329 | ||||
| -rw-r--r-- | init/Kconfig | 18 | ||||
| -rw-r--r-- | kernel/Kconfig.preempt | 62 | ||||
| -rw-r--r-- | kernel/Makefile | 6 | ||||
| -rw-r--r-- | kernel/rcupreempt.c | 10 | ||||
| -rw-r--r-- | kernel/rcupreempt_trace.c | 10 | ||||
| -rw-r--r-- | kernel/rcutree.c | 1535 | ||||
| -rw-r--r-- | kernel/rcutree_trace.c | 271 | ||||
| -rw-r--r-- | kernel/softirq.c | 5 | ||||
| -rw-r--r-- | lib/Kconfig.debug | 13 |
15 files changed, 2671 insertions, 31 deletions
diff --git a/Documentation/RCU/00-INDEX b/Documentation/RCU/00-INDEX index 461481dfb7c3..7dc0695a8f90 100644 --- a/Documentation/RCU/00-INDEX +++ b/Documentation/RCU/00-INDEX | |||
| @@ -16,6 +16,8 @@ RTFP.txt | |||
| 16 | - List of RCU papers (bibliography) going back to 1980. | 16 | - List of RCU papers (bibliography) going back to 1980. |
| 17 | torture.txt | 17 | torture.txt |
| 18 | - RCU Torture Test Operation (CONFIG_RCU_TORTURE_TEST) | 18 | - RCU Torture Test Operation (CONFIG_RCU_TORTURE_TEST) |
| 19 | trace.txt | ||
| 20 | - CONFIG_RCU_TRACE debugfs files and formats | ||
| 19 | UP.txt | 21 | UP.txt |
| 20 | - RCU on Uniprocessor Systems | 22 | - RCU on Uniprocessor Systems |
| 21 | whatisRCU.txt | 23 | whatisRCU.txt |
diff --git a/Documentation/RCU/trace.txt b/Documentation/RCU/trace.txt new file mode 100644 index 000000000000..068848240a8b --- /dev/null +++ b/Documentation/RCU/trace.txt | |||
| @@ -0,0 +1,413 @@ | |||
| 1 | CONFIG_RCU_TRACE debugfs Files and Formats | ||
| 2 | |||
| 3 | |||
| 4 | The rcupreempt and rcutree implementations of RCU provide debugfs trace | ||
| 5 | output that summarizes counters and state. This information is useful for | ||
| 6 | debugging RCU itself, and can sometimes also help to debug abuses of RCU. | ||
| 7 | Note that the rcuclassic implementation of RCU does not provide debugfs | ||
| 8 | trace output. | ||
| 9 | |||
| 10 | The following sections describe the debugfs files and formats for | ||
| 11 | preemptable RCU (rcupreempt) and hierarchical RCU (rcutree). | ||
| 12 | |||
| 13 | |||
| 14 | Preemptable RCU debugfs Files and Formats | ||
| 15 | |||
| 16 | This implementation of RCU provides three debugfs files under the | ||
| 17 | top-level directory RCU: rcu/rcuctrs (which displays the per-CPU | ||
| 18 | counters used by preemptable RCU) rcu/rcugp (which displays grace-period | ||
| 19 | counters), and rcu/rcustats (which internal counters for debugging RCU). | ||
| 20 | |||
| 21 | The output of "cat rcu/rcuctrs" looks as follows: | ||
| 22 | |||
| 23 | CPU last cur F M | ||
| 24 | 0 5 -5 0 0 | ||
| 25 | 1 -1 0 0 0 | ||
| 26 | 2 0 1 0 0 | ||
| 27 | 3 0 1 0 0 | ||
| 28 | 4 0 1 0 0 | ||
| 29 | 5 0 1 0 0 | ||
| 30 | 6 0 2 0 0 | ||
| 31 | 7 0 -1 0 0 | ||
| 32 | 8 0 1 0 0 | ||
| 33 | ggp = 26226, state = waitzero | ||
| 34 | |||
| 35 | The per-CPU fields are as follows: | ||
| 36 | |||
| 37 | o "CPU" gives the CPU number. Offline CPUs are not displayed. | ||
| 38 | |||
| 39 | o "last" gives the value of the counter that is being decremented | ||
| 40 | for the current grace period phase. In the example above, | ||
| 41 | the counters sum to 4, indicating that there are still four | ||
| 42 | RCU read-side critical sections still running that started | ||
| 43 | before the last counter flip. | ||
| 44 | |||
| 45 | o "cur" gives the value of the counter that is currently being | ||
| 46 | both incremented (by rcu_read_lock()) and decremented (by | ||
| 47 | rcu_read_unlock()). In the example above, the counters sum to | ||
| 48 | 1, indicating that there is only one RCU read-side critical section | ||
| 49 | still running that started after the last counter flip. | ||
| 50 | |||
| 51 | o "F" indicates whether RCU is waiting for this CPU to acknowledge | ||
| 52 | a counter flip. In the above example, RCU is not waiting on any, | ||
| 53 | which is consistent with the state being "waitzero" rather than | ||
| 54 | "waitack". | ||
| 55 | |||
| 56 | o "M" indicates whether RCU is waiting for this CPU to execute a | ||
| 57 | memory barrier. In the above example, RCU is not waiting on any, | ||
| 58 | which is consistent with the state being "waitzero" rather than | ||
| 59 | "waitmb". | ||
| 60 | |||
| 61 | o "ggp" is the global grace-period counter. | ||
| 62 | |||
| 63 | o "state" is the RCU state, which can be one of the following: | ||
| 64 | |||
| 65 | o "idle": there is no grace period in progress. | ||
| 66 | |||
| 67 | o "waitack": RCU just incremented the global grace-period | ||
| 68 | counter, which has the effect of reversing the roles of | ||
| 69 | the "last" and "cur" counters above, and is waiting for | ||
| 70 | all the CPUs to acknowledge the flip. Once the flip has | ||
| 71 | been acknowledged, CPUs will no longer be incrementing | ||
| 72 | what are now the "last" counters, so that their sum will | ||
| 73 | decrease monotonically down to zero. | ||
| 74 | |||
| 75 | o "waitzero": RCU is waiting for the sum of the "last" counters | ||
| 76 | to decrease to zero. | ||
| 77 | |||
| 78 | o "waitmb": RCU is waiting for each CPU to execute a memory | ||
| 79 | barrier, which ensures that instructions from a given CPU's | ||
| 80 | last RCU read-side critical section cannot be reordered | ||
| 81 | with instructions following the memory-barrier instruction. | ||
| 82 | |||
| 83 | The output of "cat rcu/rcugp" looks as follows: | ||
| 84 | |||
| 85 | oldggp=48870 newggp=48873 | ||
| 86 | |||
| 87 | Note that reading from this file provokes a synchronize_rcu(). The | ||
| 88 | "oldggp" value is that of "ggp" from rcu/rcuctrs above, taken before | ||
| 89 | executing the synchronize_rcu(), and the "newggp" value is also the | ||
| 90 | "ggp" value, but taken after the synchronize_rcu() command returns. | ||
| 91 | |||
| 92 | |||
| 93 | The output of "cat rcu/rcugp" looks as follows: | ||
| 94 | |||
| 95 | na=1337955 nl=40 wa=1337915 wl=44 da=1337871 dl=0 dr=1337871 di=1337871 | ||
| 96 | 1=50989 e1=6138 i1=49722 ie1=82 g1=49640 a1=315203 ae1=265563 a2=49640 | ||
| 97 | z1=1401244 ze1=1351605 z2=49639 m1=5661253 me1=5611614 m2=49639 | ||
| 98 | |||
| 99 | These are counters tracking internal preemptable-RCU events, however, | ||
| 100 | some of them may be useful for debugging algorithms using RCU. In | ||
| 101 | particular, the "nl", "wl", and "dl" values track the number of RCU | ||
| 102 | callbacks in various states. The fields are as follows: | ||
| 103 | |||
| 104 | o "na" is the total number of RCU callbacks that have been enqueued | ||
| 105 | since boot. | ||
| 106 | |||
| 107 | o "nl" is the number of RCU callbacks waiting for the previous | ||
| 108 | grace period to end so that they can start waiting on the next | ||
| 109 | grace period. | ||
| 110 | |||
| 111 | o "wa" is the total number of RCU callbacks that have started waiting | ||
| 112 | for a grace period since boot. "na" should be roughly equal to | ||
| 113 | "nl" plus "wa". | ||
| 114 | |||
| 115 | o "wl" is the number of RCU callbacks currently waiting for their | ||
| 116 | grace period to end. | ||
| 117 | |||
| 118 | o "da" is the total number of RCU callbacks whose grace periods | ||
| 119 | have completed since boot. "wa" should be roughly equal to | ||
| 120 | "wl" plus "da". | ||
| 121 | |||
