History

Merge branch 'core-rcu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip

Pull RCU updates from Ingo Molnar: "The RCU changes in this cycle were: - Expedited grace-period updates - kfree_rcu() updates - RCU list updates - Preemptible RCU updates - Torture-test updates - Miscellaneous fixes - Documentation updates" * 'core-rcu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (69 commits) rcu: Remove unused stop-machine #include powerpc: Remove comment about read_barrier_depends() .mailmap: Add entries for old paulmck@kernel.org addresses srcu: Apply *_ONCE() to ->srcu_last_gp_end rcu: Switch force_qs_rnp() to for_each_leaf_node_cpu_mask() rcu: Move rcu_{expedited,normal} definitions into rcupdate.h rcu: Move gp_state_names[] and gp_state_getname() to tree_stall.h rcu: Remove the declaration of call_rcu() in tree.h rcu: Fix tracepoint tracking RCU CPU kthread utilization rcu: Fix harmless omission of "CONFIG_" from #if condition rcu: Avoid tick_dep_set_cpu() misordering rcu: Provide wrappers for uses of ->rcu_read_lock_nesting rcu: Use READ_ONCE() for ->expmask in rcu_read_unlock_special() rcu: Clear ->rcu_read_unlock_special only once rcu: Clear .exp_hint only when deferred quiescent state has been reported rcu: Rename some instance of CONFIG_PREEMPTION to CONFIG_PREEMPT_RCU rcu: Remove kfree_call_rcu_nobatch() rcu: Remove kfree_rcu() special casing and lazy-callback handling rcu: Add support for debug_objects debugging for kfree_rcu() rcu: Add multiple in-flight batches of kfree_rcu() work ...

Linus Torvalds committed 6 years ago

Commit d99391e2 parents 8b56177 f8a4bb646 files · +1476 −851Browse files

Unified · Split

46 files
  1. .mailmap +4 −0
  2. Documentation/RCU/NMI-RCU.rst +28 −25
  3. Documentation/RCU/arrayRCU.rst +23 −11
  4. Documentation/RCU/index.rst +5 −0
  5. Documentation/RCU/lockdep-splat.txt +1 −1
  6. Documentation/RCU/rcu_dereference.rst +41 −34
  7. Documentation/RCU/rcubarrier.rst +125 −97
  8. Documentation/RCU/stallwarn.txt +3 −8
  9. Documentation/RCU/whatisRCU.rst +183 −108
  10. Documentation/admin-guide/kernel-parameters.txt +13 −0
  11. arch/powerpc/include/asm/barrier.h +0 −2
  12. drivers/net/wireless/mediatek/mt76/agg-rx.c +2 −2
  13. include/linux/list.h +112 −24
  14. include/linux/list_nulls.h +26 −4
  15. include/linux/rcu_segcblist.h +0 −2
  16. include/linux/rculist.h +24 −14
  17. include/linux/rculist_nulls.h +14 −6
  18. include/linux/rcupdate.h +8 −20
  19. include/linux/rcutiny.h +1 −0
  20. include/linux/rcutree.h +1 −0
  21. include/linux/tick.h +4 −1
  22. include/trace/events/rcu.h +16 −24
  23. kernel/rcu/Kconfig +9 −8
  24. kernel/rcu/Makefile +0 −1
  25. kernel/rcu/rcu.h +3 −30
  26. kernel/rcu/rcu_segcblist.c +3 −22
  27. kernel/rcu/rcu_segcblist.h +2 −23
  28. kernel/rcu/rcuperf.c +165 −8
  29. kernel/rcu/rcutorture.c +81 −60
  30. kernel/rcu/srcutiny.c +1 −1
  31. kernel/rcu/srcutree.c +6 −5
  32. kernel/rcu/tiny.c +27 −1
  33. kernel/rcu/tree.c +272 −52
  34. kernel/rcu/tree.h +1 −17
  35. kernel/rcu/tree_exp.h +91 −56
  36. kernel/rcu/tree_plugin.h +78 −90
  37. kernel/rcu/tree_stall.h +27 −7
  38. kernel/rcu/update.c +11 −3
  39. kernel/sysctl.c +1 −1
  40. net/tipc/crypto.c +1 −4
  41. tools/testing/selftests/rcutorture/bin/cpus2use.sh +9 −2
  42. tools/testing/selftests/rcutorture/bin/jitter.sh +22 −8
  43. tools/testing/selftests/rcutorture/bin/kvm-recheck-rcu.sh +2 −1
  44. tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh +6 −7
  45. tools/testing/selftests/rcutorture/bin/kvm.sh +21 −9
  46. tools/testing/selftests/rcutorture/bin/mkinitrd.sh +3 −52
.mailmap+4−0
@@ -210,6 +210,10 @@ Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it> · 209 unmodified lines
210210 Patrick Mochel <mochel@digitalimplant.org>
211211 Paul Burton <paulburton@kernel.org> <paul.burton@imgtec.com>
212212 Paul Burton <paulburton@kernel.org> <paul.burton@mips.com>
213+Paul E. McKenney <paulmck@kernel.org> <paulmck@linux.ibm.com>
214+Paul E. McKenney <paulmck@kernel.org> <paulmck@linux.vnet.ibm.com>
215+Paul E. McKenney <paulmck@kernel.org> <paul.mckenney@linaro.org>
216+Paul E. McKenney <paulmck@kernel.org> <paulmck@us.ibm.com>
213217 Peter A Jonsson <pj@ludd.ltu.se>
214218 Peter Oruba <peter@oruba.de>
215219 Peter Oruba <peter.oruba@amd.com>
Documentation/RCU/NMI-RCU.rstrenamed from Documentation/RCU/NMI-RCU.txt+28−25
@@ -1,4 +1,7 @@
1+.. _NMI_rcu_doc:
2+
13 Using RCU to Protect Dynamic NMI Handlers
4+=========================================
25
36
47 Although RCU is usually used to protect read-mostly data structures,
@@ -9,7 +12,7 @@ work in "arch/x86/oprofile/nmi_timer_int.c" and in · 4 unmodified lines
912 "arch/x86/kernel/traps.c".
1013
1114 The relevant pieces of code are listed below, each followed by a
12−brief explanation.
15+brief explanation::
1316
1417 static int dummy_nmi_callback(struct pt_regs *regs, int cpu)
1518 {
@@ -18,12 +21,12 @@ brief explanation. · 2 unmodified lines
1821
1922 The dummy_nmi_callback() function is a "dummy" NMI handler that does
2023 nothing, but returns zero, thus saying that it did nothing, allowing
21−the NMI handler to take the default machine-specific action.
24+the NMI handler to take the default machine-specific action::
2225
2326 static nmi_callback_t nmi_callback = dummy_nmi_callback;
2427
2528 This nmi_callback variable is a global function pointer to the current
26−NMI handler.
29+NMI handler::
2730
2831 void do_nmi(struct pt_regs * regs, long error_code)
2932 {
@@ -53,11 +56,12 @@ anyway. However, in practice it is a good documentation aid, particularly · 23 unmodified lines
5356 for anyone attempting to do something similar on Alpha or on systems
5457 with aggressive optimizing compilers.
5558
56−Quick Quiz: Why might the rcu_dereference_sched() be necessary on Alpha,
57− given that the code referenced by the pointer is read-only?
59+Quick Quiz:
60+ Why might the rcu_dereference_sched() be necessary on Alpha, given that the code referenced by the pointer is read-only?
5861
62+:ref:`Answer to Quick Quiz <answer_quick_quiz_NMI>`
5963
60−Back to the discussion of NMI and RCU...
64+Back to the discussion of NMI and RCU::
6165
6266 void set_nmi_callback(nmi_callback_t callback)
6367 {
@@ -68,7 +72,7 @@ The set_nmi_callback() function registers an NMI handler. Note that any · 4 unmodified lines
6872 data that is to be used by the callback must be initialized up -before-
6973 the call to set_nmi_callback(). On architectures that do not order
7074 writes, the rcu_assign_pointer() ensures that the NMI handler sees the
71−initialized values.
75+initialized values::
7276
7377 void unset_nmi_callback(void)
7478 {
@@ -82,7 +86,7 @@ up any data structures used by the old NMI handler until execution · 7 unmodified lines
8286 of it completes on all other CPUs.
8387
8488 One way to accomplish this is via synchronize_rcu(), perhaps as
85−follows:
89+follows::
8690
8791 unset_nmi_callback();
8892 synchronize_rcu();
@@ -98,24 +102,23 @@ to free up the handler's data as soon as synchronize_rcu() returns. · 9 unmodified lines
98102 Important note: for this to work, the architecture in question must
99103 invoke nmi_enter() and nmi_exit() on NMI entry and exit, respectively.
100104
105+.. _answer_quick_quiz_NMI:
101106
102−Answer to Quick Quiz
103−
104− Why might the rcu_dereference_sched() be necessary on Alpha, given
105− that the code referenced by the pointer is read-only?
107+Answer to Quick Quiz:
108+ Why might the rcu_dereference_sched() be necessary on Alpha, given that the code referenced by the pointer is read-only?
106109
107− Answer: The caller to set_nmi_callback() might well have
108− initialized some data that is to be used by the new NMI
109− handler. In this case, the rcu_dereference_sched() would
110− be needed, because otherwise a CPU that received an NMI
111− just after the new handler was set might see the pointer
112− to the new NMI handler, but the old pre-initialized
113− version of the handler's data.
110+ The caller to set_nmi_callback() might well have
111+ initialized some data that is to be used by the new NMI
112+ handler. In this case, the rcu_dereference_sched() would
113+ be needed, because otherwise a CPU that received an NMI
114+ just after the new handler was set might see the pointer
115+ to the new NMI handler, but the old pre-initialized
116+ version of the handler's data.
114117
115− This same sad story can happen on other CPUs when using
116− a compiler with aggressive pointer-value speculation
117− optimizations.
118+ This same sad story can happen on other CPUs when using
119+ a compiler with aggressive pointer-value speculation
120+ optimizations.
118121
119− More important, the rcu_dereference_sched() makes it
120− clear to someone reading the code that the pointer is
121− being protected by RCU-sched.
122+ More important, the rcu_dereference_sched() makes it
123+ clear to someone reading the code that the pointer is
124+ being protected by RCU-sched.
Documentation/RCU/arrayRCU.rstrenamed from Documentation/RCU/arrayRCU.txt+23−11
@@ -1,19 +1,21 @@
1−Using RCU to Protect Read-Mostly Arrays
1+.. _array_rcu_doc:
22
3+Using RCU to Protect Read-Mostly Arrays
4+=======================================
35
46 Although RCU is more commonly used to protect linked lists, it can
57 also be used to protect arrays. Three situations are as follows:
68
7−1. Hash Tables
9+1. :ref:`Hash Tables <hash_tables>`
810
9−2. Static Arrays
11+2. :ref:`Static Arrays <static_arrays>`
1012
11−3. Resizeable Arrays
13+3. :ref:`Resizable Arrays <resizable_arrays>`
1214
1315 Each of these three situations involves an RCU-protected pointer to an
1416 array that is separately indexed. It might be tempting to consider use
1517 of RCU to instead protect the index into an array, however, this use
16−case is -not- supported. The problem with RCU-protected indexes into
18+case is **not** supported. The problem with RCU-protected indexes into
1719 arrays is that compilers can play way too many optimization games with
1820 integers, which means that the rules governing handling of these indexes
1921 are far more trouble than they are worth. If RCU-protected indexes into
@@ -24,16 +26,20 @@ to be safely used. · 4 unmodified lines
2426 That aside, each of the three RCU-protected pointer situations are
2527 described in the following sections.
2628
29+.. _hash_tables:
2730
2831 Situation 1: Hash Tables
32+------------------------
2933
3034 Hash tables are often implemented as an array, where each array entry
3135 has a linked-list hash chain. Each hash chain can be protected by RCU
3236 as described in the listRCU.txt document. This approach also applies
3337 to other array-of-list situations, such as radix trees.
3438
39+.. _static_arrays:
3540
3641 Situation 2: Static Arrays
42+--------------------------
3743
3844 Static arrays, where the data (rather than a pointer to the data) is
3945 located in each array element, and where the array is never resized,
@@ -41,13 +47,17 @@ have not been used with RCU. Rik van Riel recommends using seqlock in · 1 unmodified line
4147 this situation, which would also have minimal read-side overhead as long
4248 as updates are rare.
4349
44−Quick Quiz: Why is it so important that updates be rare when
45− using seqlock?
50+Quick Quiz:
51+ Why is it so important that updates be rare when using seqlock?
52+
53+:ref:`Answer to Quick Quiz <answer_quick_quiz_seqlock>`
4654
55+.. _resizable_arrays:
4756
48−Situation 3: Resizeable Arrays
57+Situation 3: Resizable Arrays
58+------------------------------
4959
50−Use of RCU for resizeable arrays is demonstrated by the grow_ary()
60+Use of RCU for resizable arrays is demonstrated by the grow_ary()
5161 function formerly used by the System V IPC code. The array is used
5262 to map from semaphore, message-queue, and shared-memory IDs to the data
5363 structure that represents the corresponding IPC construct. The grow_ary()
@@ -60,7 +70,7 @@ the remainder of the new, updates the ids->entries pointer to point to · 6 unmodified lines
6070 the new array, and invokes ipc_rcu_putref() to free up the old array.
6171 Note that rcu_assign_pointer() is used to update the ids->entries pointer,
6272 which includes any memory barriers required on whatever architecture
63−you are running on.
73+you are running on::
6474
6575 static int grow_ary(struct ipc_ids* ids, int newsize)
6676 {
@@ -112,7 +122,7 @@ a simple check suffices. The pointer to the structure corresponding · 45 unmodified lines
112122 to the desired IPC object is placed in "out", with NULL indicating
113123 a non-existent entry. After acquiring "out->lock", the "out->deleted"
114124 flag indicates whether the IPC object is in the process of being
115−deleted, and, if not, the pointer is returned.
125+deleted, and, if not, the pointer is returned::
116126
117127 struct kern_ipc_perm* ipc_lock(struct ipc_ids* ids, int id)
118128 {
@@ -144,8 +154,10 @@ deleted, and, if not, the pointer is returned. · 25 unmodified lines
144154 return out;
145155 }
146156
157+.. _answer_quick_quiz_seqlock:
147158
148159 Answer to Quick Quiz:
160+ Why is it so important that updates be rare when using seqlock?
149161
150162 The reason that it is important that updates be rare when
151163 using seqlock is that frequent updates can livelock readers.
Documentation/RCU/index.rst+5−0
@@ -7,8 +7,13 @@ RCU concepts · 6 unmodified lines
77 .. toctree::
88 :maxdepth: 3
99
10+ arrayRCU
11+ rcubarrier
12+ rcu_dereference
13+ whatisRCU
1014 rcu
1115 listRCU
16+ NMI-RCU
1217 UP
1318
1419 Design/Memory-Ordering/Tree-RCU-Memory-Ordering
Documentation/RCU/lockdep-splat.txt+1−1
@@ -99,7 +99,7 @@ With this change, the rcu_dereference() is always within an RCU · 98 unmodified lines
9999 read-side critical section, which again would have suppressed the
100100 above lockdep-RCU splat.
101101
102−But in this particular case, we don't actually deference the pointer
102+But in this particular case, we don't actually dereference the pointer
103103 returned from rcu_dereference(). Instead, that pointer is just compared
104104 to the cic pointer, which means that the rcu_dereference() can be replaced
105105 by rcu_access_pointer() as follows:
Documentation/RCU/rcu_dereference.rstrenamed from Documentation/RCU/rcu_dereference.txt+41−34
@@ -1,4 +1,7 @@
1+.. _rcu_dereference_doc:
2+
13 PROPER CARE AND FEEDING OF RETURN VALUES FROM rcu_dereference()
4+===============================================================
25
36 Most of the time, you can use values from rcu_dereference() or one of
47 the similar primitives without worries. Dereferencing (prefix "*"),
@@ -8,7 +11,7 @@ subtraction of constants, and casts all work quite naturally and safely. · 3 unmodified lines
811 It is nevertheless possible to get into trouble with other operations.
912 Follow these rules to keep your RCU code working properly:
1013
11−o You must use one of the rcu_dereference() family of primitives
14+- You must use one of the rcu_dereference() family of primitives
1215 to load an RCU-protected pointer, otherwise CONFIG_PROVE_RCU
1316 will complain. Worse yet, your code can see random memory-corruption
1417 bugs due to games that compilers and DEC Alpha can play.
@@ -25,24 +28,24 @@ o You must use one of the rcu_dereference() family of primitives · 10 unmodified lines
2528 for an example where the compiler can in fact deduce the exact
2629 value of the pointer, and thus cause misordering.
2730
28−o You are only permitted to use rcu_dereference on pointer values.
31+- You are only permitted to use rcu_dereference on pointer values.
2932 The compiler simply knows too much about integral values to
3033 trust it to carry dependencies through integer operations.
3134 There are a very few exceptions, namely that you can temporarily
3235 cast the pointer to uintptr_t in order to:
3336
34− o Set bits and clear bits down in the must-be-zero low-order
37+ - Set bits and clear bits down in the must-be-zero low-order
3538 bits of that pointer. This clearly means that the pointer
3639 must have alignment constraints, for example, this does
3740 -not- work in general for char* pointers.
3841
39− o XOR bits to translate pointers, as is done in some
42+ - XOR bits to translate pointers, as is done in some
4043 classic buddy-allocator algorithms.
4144
4245 It is important to cast the value back to pointer before
4346 doing much of anything else with it.
4447
45−o Avoid cancellation when using the "+" and "-" infix arithmetic
48+- Avoid cancellation when using the "+" and "-" infix arithmetic
4649 operators. For example, for a given variable "x", avoid
4750 "(x-(uintptr_t)x)" for char* pointers. The compiler is within its
4851 rights to substitute zero for this sort of expression, so that
@@ -54,16 +57,16 @@ o Avoid cancellation when using the "+" and "-" infix arithmetic · 5 unmodified lines
5457 "p+a-b" is safe because its value still necessarily depends on
5558 the rcu_dereference(), thus maintaining proper ordering.
5659
57−o If you are using RCU to protect JITed functions, so that the
60+- If you are using RCU to protect JITed functions, so that the
5861 "()" function-invocation operator is applied to a value obtained
5962 (directly or indirectly) from rcu_dereference(), you may need to
6063 interact directly with the hardware to flush instruction caches.
6164 This issue arises on some systems when a newly JITed function is
6265 using the same memory that was used by an earlier JITed function.
6366
64−o Do not use the results from relational operators ("==", "!=",
67+- Do not use the results from relational operators ("==", "!=",
6568 ">", ">=", "<", or "<=") when dereferencing. For example,
66− the following (quite strange) code is buggy:
69+ the following (quite strange) code is buggy::
6770
6871 int *p;
6972 int *q;
@@ -81,11 +84,11 @@ o Do not use the results from relational operators ("==", "!=", · 11 unmodified lines
8184 after such branches, but can speculate loads, which can again
8285 result in misordering bugs.
8386
84−o Be very careful about comparing pointers obtained from
87+- Be very careful about comparing pointers obtained from
8588 rcu_dereference() against non-NULL values. As Linus Torvalds
8689 explained, if the two pointers are equal, the compiler could
8790 substitute the pointer you are comparing against for the pointer
88− obtained from rcu_dereference(). For example:
91+ obtained from rcu_dereference(). For example::
8992
9093 p = rcu_dereference(gp);
9194 if (p == &default_struct)
@@ -93,7 +96,7 @@ o Be very careful about comparing pointers obtained from · 1 unmodified line
9396
9497 Because the compiler now knows that the value of "p" is exactly
9598 the address of the variable "default_struct", it is free to
96− transform this code into the following:
99+ transform this code into the following::
97100
98101 p = rcu_dereference(gp);
99102 if (p == &default_struct)
@@ -105,14 +108,14 @@ o Be very careful about comparing pointers obtained from · 5 unmodified lines
105108
106109 However, comparisons are OK in the following cases:
107110
108− o The comparison was against the NULL pointer. If the
111+ - The comparison was against the NULL pointer. If the
109112 compiler knows that the pointer is NULL, you had better
110113 not be dereferencing it anyway. If the comparison is
111114 non-equal, the compiler is none the wiser. Therefore,
112115 it is safe to compare pointers from rcu_dereference()
113116 against NULL pointers.
114117
115− o The pointer is never dereferenced after being compared.
118+ - The pointer is never dereferenced after being compared.
116119 Since there are no subsequent dereferences, the compiler
117120 cannot use anything it learned from the comparison
118121 to reorder the non-existent subsequent dereferences.
@@ -124,31 +127,31 @@ o Be very careful about comparing pointers obtained from · 5 unmodified lines
124127 dereferenced, rcu_access_pointer() should be used in place
125128 of rcu_dereference().
126129
127− o The comparison is against a pointer that references memory
130+ - The comparison is against a pointer that references memory
128131 that was initialized "a long time ago." The reason
129132 this is safe is that even if misordering occurs, the
130133 misordering will not affect the accesses that follow
131134 the comparison. So exactly how long ago is "a long
132135 time ago"? Here are some possibilities:
133136
134− o Compile time.
137+ - Compile time.
135138
136− o Boot time.
139+ - Boot time.
137140
138− o Module-init time for module code.
141+ - Module-init time for module code.
139142
140− o Prior to kthread creation for kthread code.
143+ - Prior to kthread creation for kthread code.
141144
142− o During some prior acquisition of the lock that
145+ - During some prior acquisition of the lock that
143146 we now hold.
144147
145− o Before mod_timer() time for a timer handler.
148+ - Before mod_timer() time for a timer handler.
146149
147150 There are many other possibilities involving the Linux
148151 kernel's wide array of primitives that cause code to
149152 be invoked at a later time.
150153
151− o The pointer being compared against also came from
154+ - The pointer being compared against also came from
152155 rcu_dereference(). In this case, both pointers depend
153156 on one rcu_dereference() or another, so you get proper
154157 ordering either way.
@@ -159,13 +162,13 @@ o Be very careful about comparing pointers obtained from · 4 unmodified lines
159162 of such an RCU usage bug is shown in the section titled
160163 "EXAMPLE OF AMPLIFIED RCU-USAGE BUG".
161164
162− o All of the accesses following the comparison are stores,
165+ - All of the accesses following the comparison are stores,
163166 so that a control dependency preserves the needed ordering.
164167 That said, it is easy to get control dependencies wrong.
165168 Please see the "CONTROL DEPENDENCIES" section of
166169 Documentation/memory-barriers.txt for more details.
167170
168− o The pointers are not equal -and- the compiler does
171+ - The pointers are not equal -and- the compiler does
169172 not have enough information to deduce the value of the
170173 pointer. Note that the volatile cast in rcu_dereference()
171174 will normally prevent the compiler from knowing too much.
@@ -175,7 +178,7 @@ o Be very careful about comparing pointers obtained from · 3 unmodified lines
175178 comparison will provide exactly the information that the
176179 compiler needs to deduce the value of the pointer.
177180
178−o Disable any value-speculation optimizations that your compiler
181+- Disable any value-speculation optimizations that your compiler
179182 might provide, especially if you are making use of feedback-based
180183 optimizations that take data collected from prior runs. Such
181184 value-speculation optimizations reorder operations by design.
@@ -188,11 +191,12 @@ o Disable any value-speculation optimizations that your compiler · 6 unmodified lines
188191
189192
190193 EXAMPLE OF AMPLIFIED RCU-USAGE BUG
194+----------------------------------
191195
192196 Because updaters can run concurrently with RCU readers, RCU readers can
193197 see stale and/or inconsistent values. If RCU readers need fresh or
194198 consistent values, which they sometimes do, they need to take proper
195−precautions. To see this, consider the following code fragment:
199+precautions. To see this, consider the following code fragment::
196200
197201 struct foo {
198202 int a;
@@ -244,7 +248,7 @@ to some reordering from the compiler and CPUs is beside the point. · 45 unmodified lines
244248
245249 But suppose that the reader needs a consistent view?
246250
247−Then one approach is to use locking, for example, as follows:
251+Then one approach is to use locking, for example, as follows::
248252
249253 struct foo {
250254 int a;
@@ -299,6 +303,7 @@ As always, use the right tool for the job! · 48 unmodified lines
299303
300304
301305 EXAMPLE WHERE THE COMPILER KNOWS TOO MUCH
306+-----------------------------------------
302307
303308 If a pointer obtained from rcu_dereference() compares not-equal to some
304309 other pointer, the compiler normally has no clue what the value of the
@@ -308,7 +313,7 @@ guarantees that RCU depends on. And the volatile cast in rcu_dereference() · 3 unmodified lines
308313 should prevent the compiler from guessing the value.
309314
310315 But without rcu_dereference(), the compiler knows more than you might
311−expect. Consider the following code fragment:
316+expect. Consider the following code fragment::
312317
313318 struct foo {
314319 int a;
@@ -354,6 +359,7 @@ dereference the resulting pointer. · 39 unmodified lines
354359
355360
356361 WHICH MEMBER OF THE rcu_dereference() FAMILY SHOULD YOU USE?
362+------------------------------------------------------------
357363
358364 First, please avoid using rcu_dereference_raw() and also please avoid
359365 using rcu_dereference_check() and rcu_dereference_protected() with a
@@ -370,7 +376,7 @@ member of the rcu_dereference() to use in various situations: · 10 unmodified lines
370376
371377 2. If the access might be within an RCU read-side critical section
372378 on the one hand, or protected by (say) my_lock on the other,
373− use rcu_dereference_check(), for example:
379+ use rcu_dereference_check(), for example::
374380
375381 p1 = rcu_dereference_check(p->rcu_protected_pointer,
376382 lockdep_is_held(&my_lock));
@@ -378,14 +384,14 @@ member of the rcu_dereference() to use in various situations: · 1 unmodified line
378384
379385 3. If the access might be within an RCU read-side critical section
380386 on the one hand, or protected by either my_lock or your_lock on
381− the other, again use rcu_dereference_check(), for example:
387+ the other, again use rcu_dereference_check(), for example::
382388
383389 p1 = rcu_dereference_check(p->rcu_protected_pointer,
384390 lockdep_is_held(&my_lock) ||
385391 lockdep_is_held(&your_lock));
386392
387393 4. If the access is on the update side, so that it is always protected
388− by my_lock, use rcu_dereference_protected():
394+ by my_lock, use rcu_dereference_protected()::
389395
390396 p1 = rcu_dereference_protected(p->rcu_protected_pointer,
391397 lockdep_is_held(&my_lock));
@@ -410,18 +416,19 @@ member of the rcu_dereference() to use in various situations: · 18 unmodified lines
410416
411417
412418 SPARSE CHECKING OF RCU-PROTECTED POINTERS
419+-----------------------------------------
413420
414421 The sparse static-analysis tool checks for direct access to RCU-protected
415422 pointers, which can result in "interesting" bugs due to compiler
416423 optimizations involving invented loads and perhaps also load tearing.
417−For example, suppose someone mistakenly does something like this:
424+For example, suppose someone mistakenly does something like this::
418425
419426 p = q->rcu_protected_pointer;
420427 do_something_with(p->a);
421428 do_something_else_with(p->b);
422429
423430 If register pressure is high, the compiler might optimize "p" out
424−of existence, transforming the code to something like this:
431+of existence, transforming the code to something like this::
425432
426433 do_something_with(q->rcu_protected_pointer->a);
427434 do_something_else_with(q->rcu_protected_pointer->b);
@@ -435,7 +442,7 @@ Load tearing could of course result in dereferencing a mashup of a pair · 7 unmodified lines
435442 of pointers, which also might fatally disappoint your code.
436443
437444 These problems could have been avoided simply by making the code instead
438−read as follows:
445+read as follows::
439446
440447 p = rcu_dereference(q->rcu_protected_pointer);
441448 do_something_with(p->a);
@@ -448,7 +455,7 @@ or as a formal parameter, with "__rcu", which tells sparse to complain if · 6 unmodified lines
448455 this pointer is accessed directly. It will also cause sparse to complain
449456 if a pointer not marked with "__rcu" is accessed using rcu_dereference()
450457 and friends. For example, ->rcu_protected_pointer might be declared as
451−follows:
458+follows::
452459
453460 struct foo __rcu *rcu_protected_pointer;
454461
Documentation/RCU/rcubarrier.rstrenamed from Documentation/RCU/rcubarrier.txt+125−97
@@ -1,4 +1,7 @@
1+.. _rcu_barrier:
2+
13 RCU and Unloadable Modules
4+==========================
25
36 [Originally published in LWN Jan. 14, 2007: http://lwn.net/Articles/217484/]
47
@@ -21,7 +24,7 @@ given that readers might well leave absolutely no trace of their · 16 unmodified lines
2124 presence? There is a synchronize_rcu() primitive that blocks until all
2225 pre-existing readers have completed. An updater wishing to delete an
2326 element p from a linked list might do the following, while holding an
24−appropriate lock, of course:
27+appropriate lock, of course::
2528
2629 list_del_rcu(p);
2730 synchronize_rcu();
@@ -32,13 +35,13 @@ primitive must be used instead. This primitive takes a pointer to an · 4 unmodified lines
3235 rcu_head struct placed within the RCU-protected data structure and
3336 another pointer to a function that may be invoked later to free that
3437 structure. Code to delete an element p from the linked list from IRQ
35−context might then be as follows:
38+context might then be as follows::
3639
3740 list_del_rcu(p);
3841 call_rcu(&p->rcu, p_callback);
3942
4043 Since call_rcu() never blocks, this code can safely be used from within
41−IRQ context. The function p_callback() might be defined as follows:
44+IRQ context. The function p_callback() might be defined as follows::
4245
4346 static void p_callback(struct rcu_head *rp)
4447 {
@@ -49,6 +52,7 @@ IRQ context. The function p_callback() might be defined as follows: · 4 unmodified lines
4952
5053
5154 Unloading Modules That Use call_rcu()
55+-------------------------------------
5256
5357 But what if p_callback is defined in an unloadable module?
5458
@@ -69,10 +73,11 @@ in realtime kernels in order to avoid excessive scheduling latencies. · 14 unmodified lines
6973
7074
7175 rcu_barrier()
76+-------------
7277
7378 We instead need the rcu_barrier() primitive. Rather than waiting for
7479 a grace period to elapse, rcu_barrier() waits for all outstanding RCU
75−callbacks to complete. Please note that rcu_barrier() does -not- imply
80+callbacks to complete. Please note that rcu_barrier() does **not** imply
7681 synchronize_rcu(), in particular, if there are no RCU callbacks queued
7782 anywhere, rcu_barrier() is within its rights to return immediately,
7883 without waiting for a grace period to elapse.
@@ -88,79 +93,79 @@ must match the flavor of rcu_barrier() with that of call_rcu(). If your · 9 unmodified lines
8893 module uses multiple flavors of call_rcu(), then it must also use multiple
8994 flavors of rcu_barrier() when unloading that module. For example, if
9095 it uses call_rcu(), call_srcu() on srcu_struct_1, and call_srcu() on
91−srcu_struct_2(), then the following three lines of code will be required
92−when unloading:
96+srcu_struct_2, then the following three lines of code will be required
97+when unloading::
9398
9499 1 rcu_barrier();
95100 2 srcu_barrier(&srcu_struct_1);
96101 3 srcu_barrier(&srcu_struct_2);
97102
98103 The rcutorture module makes use of rcu_barrier() in its exit function
99−as follows:
104+as follows::
100105
101− 1 static void
102− 2 rcu_torture_cleanup(void)
103− 3 {
104− 4 int i;
106+ 1 static void
107+ 2 rcu_torture_cleanup(void)
108+ 3 {
109+ 4 int i;
105110 5
106− 6 fullstop = 1;
107− 7 if (shuffler_task != NULL) {
111+ 6 fullstop = 1;
112+ 7 if (shuffler_task != NULL) {
108113 8 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
109114 9 kthread_stop(shuffler_task);
110−10 }
111−11 shuffler_task = NULL;
112−12
113−13 if (writer_task != NULL) {
114−14 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
115−15 kthread_stop(writer_task);
116−16 }
117−17 writer_task = NULL;
118−18
119−19 if (reader_tasks != NULL) {
120−20 for (i = 0; i < nrealreaders; i++) {
121−21 if (reader_tasks[i] != NULL) {
122−22 VERBOSE_PRINTK_STRING(
123−23 "Stopping rcu_torture_reader task");
124−24 kthread_stop(reader_tasks[i]);
125−25 }
126−26 reader_tasks[i] = NULL;
127−27 }
128−28 kfree(reader_tasks);
129−29 reader_tasks = NULL;
130−30 }
131−31 rcu_torture_current = NULL;
132−32
133−33 if (fakewriter_tasks != NULL) {
134−34 for (i = 0; i < nfakewriters; i++) {
135−35 if (fakewriter_tasks[i] != NULL) {
136−36 VERBOSE_PRINTK_STRING(
137−37 "Stopping rcu_torture_fakewriter task");
138−38 kthread_stop(fakewriter_tasks[i]);
139−39 }
140−40 fakewriter_tasks[i] = NULL;
141−41 }
142−42 kfree(fakewriter_tasks);
143−43 fakewriter_tasks = NULL;
144−44 }
145−45
146−46 if (stats_task != NULL) {
147−47 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
148−48 kthread_stop(stats_task);
149−49 }
150−50 stats_task = NULL;
151−51
152−52 /* Wait for all RCU callbacks to fire. */
153−53 rcu_barrier();
154−54
155−55 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
156−56
157−57 if (cur_ops->cleanup != NULL)
158−58 cur_ops->cleanup();
159−59 if (atomic_read(&n_rcu_torture_error))
160−60 rcu_torture_print_module_parms("End of test: FAILURE");
161−61 else
162−62 rcu_torture_print_module_parms("End of test: SUCCESS");
163−63 }
115+ 10 }
116+ 11 shuffler_task = NULL;
117+ 12
118+ 13 if (writer_task != NULL) {
119+ 14 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
120+ 15 kthread_stop(writer_task);
121+ 16 }
122+ 17 writer_task = NULL;
123+ 18
124+ 19 if (reader_tasks != NULL) {
125+ 20 for (i = 0; i < nrealreaders; i++) {
126+ 21 if (reader_tasks[i] != NULL) {
127+ 22 VERBOSE_PRINTK_STRING(
128+ 23 "Stopping rcu_torture_reader task");
129+ 24 kthread_stop(reader_tasks[i]);
130+ 25 }
131+ 26 reader_tasks[i] = NULL;
132+ 27 }
133+ 28 kfree(reader_tasks);
134+ 29 reader_tasks = NULL;
135+ 30 }
136+ 31 rcu_torture_current = NULL;
137+ 32
138+ 33 if (fakewriter_tasks != NULL) {
139+ 34 for (i = 0; i < nfakewriters; i++) {
140+ 35 if (fakewriter_tasks[i] != NULL) {
141+ 36 VERBOSE_PRINTK_STRING(
142+ 37 "Stopping rcu_torture_fakewriter task");
143+ 38 kthread_stop(fakewriter_tasks[i]);
144+ 39 }
145+ 40 fakewriter_tasks[i] = NULL;
146+ 41 }
147+ 42 kfree(fakewriter_tasks);
148+ 43 fakewriter_tasks = NULL;
149+ 44 }
150+ 45
151+ 46 if (stats_task != NULL) {
152+ 47 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
153+ 48 kthread_stop(stats_task);
154+ 49 }
155+ 50 stats_task = NULL;
156+ 51
157+ 52 /* Wait for all RCU callbacks to fire. */
158+ 53 rcu_barrier();
159+ 54
160+ 55 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
161+ 56
162+ 57 if (cur_ops->cleanup != NULL)
163+ 58 cur_ops->cleanup();
164+ 59 if (atomic_read(&n_rcu_torture_error))
165+ 60 rcu_torture_print_module_parms("End of test: FAILURE");
166+ 61 else
167+ 62 rcu_torture_print_module_parms("End of test: SUCCESS");
168+ 63 }
164169
165170 Line 6 sets a global variable that prevents any RCU callbacks from
166171 re-posting themselves. This will not be necessary in most cases, since
@@ -176,9 +181,14 @@ for any pre-existing callbacks to complete. · 9 unmodified lines
176181 Then lines 55-62 print status and do operation-specific cleanup, and
177182 then return, permitting the module-unload operation to be completed.
178183
179−Quick Quiz #1: Is there any other situation where rcu_barrier() might
184+.. _rcubarrier_quiz_1:
185+
186+Quick Quiz #1:
187+ Is there any other situation where rcu_barrier() might
180188 be required?
181189
190+:ref:`Answer to Quick Quiz #1 <answer_rcubarrier_quiz_1>`
191+
182192 Your module might have additional complications. For example, if your
183193 module invokes call_rcu() from timers, you will need to first cancel all
184194 the timers, and only then invoke rcu_barrier() to wait for any remaining
@@ -188,11 +198,12 @@ Of course, if you module uses call_rcu(), you will need to invoke · 3 unmodified lines
188198 rcu_barrier() before unloading. Similarly, if your module uses
189199 call_srcu(), you will need to invoke srcu_barrier() before unloading,
190200 and on the same srcu_struct structure. If your module uses call_rcu()
191−-and- call_srcu(), then you will need to invoke rcu_barrier() -and-
201+**and** call_srcu(), then you will need to invoke rcu_barrier() **and**
192202 srcu_barrier().
193203
194204
195205 Implementing rcu_barrier()
206+--------------------------
196207
197208 Dipankar Sarma's implementation of rcu_barrier() makes use of the fact
198209 that RCU callbacks are never reordered once queued on one of the per-CPU
@@ -200,19 +211,19 @@ queues. His implementation queues an RCU callback on each of the per-CPU · 1 unmodified line
200211 callback queues, and then waits until they have all started executing, at
201212 which point, all earlier RCU callbacks are guaranteed to have completed.
202213
203−The original code for rcu_barrier() was as follows:
214+The original code for rcu_barrier() was as follows::
204215
205− 1 void rcu_barrier(void)
206− 2 {
207− 3 BUG_ON(in_interrupt());
208− 4 /* Take cpucontrol mutex to protect against CPU hotplug */
209− 5 mutex_lock(&rcu_barrier_mutex);
210− 6 init_completion(&rcu_barrier_completion);
211− 7 atomic_set(&rcu_barrier_cpu_count, 0);
212− 8 on_each_cpu(rcu_barrier_func, NULL, 0, 1);
213− 9 wait_for_completion(&rcu_barrier_completion);
214−10 mutex_unlock(&rcu_barrier_mutex);
215−11 }
216+ 1 void rcu_barrier(void)
217+ 2 {
218+ 3 BUG_ON(in_interrupt());
219+ 4 /* Take cpucontrol mutex to protect against CPU hotplug */
220+ 5 mutex_lock(&rcu_barrier_mutex);
221+ 6 init_completion(&rcu_barrier_completion);
222+ 7 atomic_set(&rcu_barrier_cpu_count, 0);
223+ 8 on_each_cpu(rcu_barrier_func, NULL, 0, 1);
224+ 9 wait_for_completion(&rcu_barrier_completion);
225+ 10 mutex_unlock(&rcu_barrier_mutex);
226+ 11 }
216227
217228 Line 3 verifies that the caller is in process context, and lines 5 and 10
218229 use rcu_barrier_mutex to ensure that only one rcu_barrier() is using the
@@ -226,18 +237,18 @@ This code was rewritten in 2008 and several times thereafter, but this · 7 unmodified lines
226237 still gives the general idea.
227238
228239 The rcu_barrier_func() runs on each CPU, where it invokes call_rcu()
229−to post an RCU callback, as follows:
240+to post an RCU callback, as follows::
230241
231− 1 static void rcu_barrier_func(void *notused)
232− 2 {
233− 3 int cpu = smp_processor_id();
234− 4 struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
235− 5 struct rcu_head *head;
242+ 1 static void rcu_barrier_func(void *notused)
243+ 2 {
244+ 3 int cpu = smp_processor_id();
245+ 4 struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
246+ 5 struct rcu_head *head;
236247 6
237− 7 head = &rdp->barrier;
238− 8 atomic_inc(&rcu_barrier_cpu_count);
239− 9 call_rcu(head, rcu_barrier_callback);
240−10 }
248+ 7 head = &rdp->barrier;
249+ 8 atomic_inc(&rcu_barrier_cpu_count);
250+ 9 call_rcu(head, rcu_barrier_callback);
251+ 10 }
241252
242253 Lines 3 and 4 locate RCU's internal per-CPU rcu_data structure,
243254 which contains the struct rcu_head that needed for the later call to
@@ -248,20 +259,25 @@ the current CPU's queue. · 4 unmodified lines
248259
249260 The rcu_barrier_callback() function simply atomically decrements the
250261 rcu_barrier_cpu_count variable and finalizes the completion when it
251−reaches zero, as follows:
262+reaches zero, as follows::
252263
253264 1 static void rcu_barrier_callback(struct rcu_head *notused)
254265 2 {
255− 3 if (atomic_dec_and_test(&rcu_barrier_cpu_count))
256− 4 complete(&rcu_barrier_completion);
266+ 3 if (atomic_dec_and_test(&rcu_barrier_cpu_count))
267+ 4 complete(&rcu_barrier_completion);
257268 5 }
258269
259−Quick Quiz #2: What happens if CPU 0's rcu_barrier_func() executes
270+.. _rcubarrier_quiz_2:
271+
272+Quick Quiz #2:
273+ What happens if CPU 0's rcu_barrier_func() executes
260274 immediately (thus incrementing rcu_barrier_cpu_count to the
261275 value one), but the other CPU's rcu_barrier_func() invocations
262276 are delayed for a full grace period? Couldn't this result in
263277 rcu_barrier() returning prematurely?
264278
279+:ref:`Answer to Quick Quiz #2 <answer_rcubarrier_quiz_2>`
280+
265281 The current rcu_barrier() implementation is more complex, due to the need
266282 to avoid disturbing idle CPUs (especially on battery-powered systems)
267283 and the need to minimally disturb non-idle CPUs in real-time systems.
@@ -269,6 +285,7 @@ However, the code above illustrates the concepts. · 1 unmodified line
269285
270286
271287 rcu_barrier() Summary
288+---------------------
272289
273290 The rcu_barrier() primitive has seen relatively little use, since most
274291 code using RCU is in the core kernel rather than in modules. However, if
@@ -277,8 +294,12 @@ so that your module may be safely unloaded. · 2 unmodified lines
277294
278295
279296 Answers to Quick Quizzes
297+------------------------
298+
299+.. _answer_rcubarrier_quiz_1:
280300
281−Quick Quiz #1: Is there any other situation where rcu_barrier() might
301+Quick Quiz #1:
302+ Is there any other situation where rcu_barrier() might
282303 be required?
283304
284305 Answer: Interestingly enough, rcu_barrier() was not originally
@@ -292,7 +313,12 @@ Answer: Interestingly enough, rcu_barrier() was not originally · 7 unmodified lines
292313 implementing rcutorture, and found that rcu_barrier() solves
293314 this problem as well.
294315
295−Quick Quiz #2: What happens if CPU 0's rcu_barrier_func() executes
316+:ref:`Back to Quick Quiz #1 <rcubarrier_quiz_1>`
317+
318+.. _answer_rcubarrier_quiz_2:
319+
320+Quick Quiz #2:
321+ What happens if CPU 0's rcu_barrier_func() executes
296322 immediately (thus incrementing rcu_barrier_cpu_count to the
297323 value one), but the other CPU's rcu_barrier_func() invocations
298324 are delayed for a full grace period? Couldn't this result in
@@ -323,3 +349,5 @@ Answer: This cannot happen. The reason is that on_each_cpu() has its last · 24 unmodified lines
323349 is to add an rcu_read_lock() before line 8 of rcu_barrier()
324350 and an rcu_read_unlock() after line 8 of this same function. If
325351 you can think of a better change, please let me know!
352+
353+:ref:`Back to Quick Quiz #2 <rcubarrier_quiz_2>`
Documentation/RCU/stallwarn.txt+3−8
@@ -225,18 +225,13 @@ an estimate of the total number of RCU callbacks queued across all CPUs · 224 unmodified lines
225225 In kernels with CONFIG_RCU_FAST_NO_HZ, more information is printed
226226 for each CPU:
227227
228− 0: (64628 ticks this GP) idle=dd5/3fffffffffffffff/0 softirq=82/543 last_accelerate: a345/d342 Nonlazy posted: ..D
228+ 0: (64628 ticks this GP) idle=dd5/3fffffffffffffff/0 softirq=82/543 last_accelerate: a345/d342 dyntick_enabled: 1
229229
230230 The "last_accelerate:" prints the low-order 16 bits (in hex) of the
231231 jiffies counter when this CPU last invoked rcu_try_advance_all_cbs()
232232 from rcu_needs_cpu() or last invoked rcu_accelerate_cbs() from
233−rcu_prepare_for_idle(). The "Nonlazy posted:" indicates lazy-callback
234−status, so that an "l" indicates that all callbacks were lazy at the start
235−of the last idle period and an "L" indicates that there are currently
236−no non-lazy callbacks (in both cases, "." is printed otherwise, as
237−shown above) and "D" indicates that dyntick-idle processing is enabled
238−("." is printed otherwise, for example, if disabled via the "nohz="
239−kernel boot parameter).
233+rcu_prepare_for_idle(). "dyntick_enabled: 1" indicates that dyntick-idle
234+processing is enabled.
240235
241236 If the grace period ends just as the stall warning starts printing,
242237 there will be a spurious stall-warning message, which will include
Documentation/RCU/whatisRCU.rstrenamed from Documentation/RCU/whatisRCU.txt+183−108
@@ -1,15 +1,18 @@
1+.. _whatisrcu_doc:
2+
13 What is RCU? -- "Read, Copy, Update"
4+======================================
25
36 Please note that the "What is RCU?" LWN series is an excellent place
47 to start learning about RCU:
58
6−1. What is RCU, Fundamentally? http://lwn.net/Articles/262464/
7−2. What is RCU? Part 2: Usage http://lwn.net/Articles/263130/
8−3. RCU part 3: the RCU API http://lwn.net/Articles/264090/
9−4. The RCU API, 2010 Edition http://lwn.net/Articles/418853/
10− 2010 Big API Table http://lwn.net/Articles/419086/
11−5. The RCU API, 2014 Edition http://lwn.net/Articles/609904/
12− 2014 Big API Table http://lwn.net/Articles/609973/
9+| 1. What is RCU, Fundamentally? http://lwn.net/Articles/262464/
10+| 2. What is RCU? Part 2: Usage http://lwn.net/Articles/263130/
11+| 3. RCU part 3: the RCU API http://lwn.net/Articles/264090/
12+| 4. The RCU API, 2010 Edition http://lwn.net/Articles/418853/
13+| 2010 Big API Table http://lwn.net/Articles/419086/
14+| 5. The RCU API, 2014 Edition http://lwn.net/Articles/609904/
15+| 2014 Big API Table http://lwn.net/Articles/609973/
1316
1417
1518 What is RCU?
@@ -24,14 +27,21 @@ the experience has been that different people must take different paths · 8 unmodified lines
2427 to arrive at an understanding of RCU. This document provides several
2528 different paths, as follows:
2629
27−1. RCU OVERVIEW
28−2. WHAT IS RCU'S CORE API?
29−3. WHAT ARE SOME EXAMPLE USES OF CORE RCU API?
30−4. WHAT IF MY UPDATING THREAD CANNOT BLOCK?
31−5. WHAT ARE SOME SIMPLE IMPLEMENTATIONS OF RCU?
32−6. ANALOGY WITH READER-WRITER LOCKING
33−7. FULL LIST OF RCU APIs
34−8. ANSWERS TO QUICK QUIZZES
30+:ref:`1. RCU OVERVIEW <1_whatisRCU>`
31+
32+:ref:`2. WHAT IS RCU'S CORE API? <2_whatisRCU>`
33+
34+:ref:`3. WHAT ARE SOME EXAMPLE USES OF CORE RCU API? <3_whatisRCU>`
35+
36+:ref:`4. WHAT IF MY UPDATING THREAD CANNOT BLOCK? <4_whatisRCU>`
37+
38+:ref:`5. WHAT ARE SOME SIMPLE IMPLEMENTATIONS OF RCU? <5_whatisRCU>`
39+
40+:ref:`6. ANALOGY WITH READER-WRITER LOCKING <6_whatisRCU>`
41+
42+:ref:`7. FULL LIST OF RCU APIs <7_whatisRCU>`
43+
44+:ref:`8. ANSWERS TO QUICK QUIZZES <8_whatisRCU>`
3545
3646 People who prefer starting with a conceptual overview should focus on
3747 Section 1, though most readers will profit by reading this section at
@@ -49,8 +59,10 @@ everything, feel free to read the whole thing -- but if you are really · 11 unmodified lines
4959 that type of person, you have perused the source code and will therefore
5060 never need this document anyway. ;-)
5161
62+.. _1_whatisRCU:
5263
5364 1. RCU OVERVIEW
65+----------------
5466
5567 The basic idea behind RCU is to split updates into "removal" and
5668 "reclamation" phases. The removal phase removes references to data items
@@ -116,8 +128,10 @@ So how the heck can a reclaimer tell when a reader is done, given · 59 unmodified lines
116128 that readers are not doing any sort of synchronization operations???
117129 Read on to learn about how RCU's API makes this easy.
118130
131+.. _2_whatisRCU:
119132
120133 2. WHAT IS RCU'S CORE API?
134+---------------------------
121135
122136 The core RCU API is quite small:
123137
@@ -136,7 +150,7 @@ later. See the kernel docbook documentation for more info, or look directly · 12 unmodified lines
136150 at the function header comments.
137151
138152 rcu_read_lock()
139−
153+^^^^^^^^^^^^^^^
140154 void rcu_read_lock(void);
141155
142156 Used by a reader to inform the reclaimer that the reader is
@@ -150,7 +164,7 @@ rcu_read_lock() · 7 unmodified lines
150164 longer-term references to data structures.
151165
152166 rcu_read_unlock()
153−
167+^^^^^^^^^^^^^^^^^
154168 void rcu_read_unlock(void);
155169
156170 Used by a reader to inform the reclaimer that the reader is
@@ -158,15 +172,15 @@ rcu_read_unlock() · 1 unmodified line
158172 read-side critical sections may be nested and/or overlapping.
159173
160174 synchronize_rcu()
161−
175+^^^^^^^^^^^^^^^^^
162176 void synchronize_rcu(void);
163177
164178 Marks the end of updater code and the beginning of reclaimer
165179 code. It does this by blocking until all pre-existing RCU
166180 read-side critical sections on all CPUs have completed.
167− Note that synchronize_rcu() will -not- necessarily wait for
181+ Note that synchronize_rcu() will **not** necessarily wait for
168182 any subsequent RCU read-side critical sections to complete.
169− For example, consider the following sequence of events:
183+ For example, consider the following sequence of events::
170184
171185 CPU 0 CPU 1 CPU 2
172186 ----------------- ------------------------- ---------------
@@ -182,7 +196,7 @@ synchronize_rcu() · 9 unmodified lines
182196 any that begin after synchronize_rcu() is invoked.
183197
184198 Of course, synchronize_rcu() does not necessarily return
185− -immediately- after the last pre-existing RCU read-side critical
199+ **immediately** after the last pre-existing RCU read-side critical
186200 section completes. For one thing, there might well be scheduling
187201 delays. For another thing, many RCU implementations process
188202 requests in batches in order to improve efficiencies, which can
@@ -211,10 +225,10 @@ synchronize_rcu() · 22 unmodified lines
211225 checklist.txt for some approaches to limiting the update rate.
212226
213227 rcu_assign_pointer()
214−
228+^^^^^^^^^^^^^^^^^^^^
215229 void rcu_assign_pointer(p, typeof(p) v);
216230
217− Yes, rcu_assign_pointer() -is- implemented as a macro, though it
231+ Yes, rcu_assign_pointer() **is** implemented as a macro, though it
218232 would be cool to be able to declare a function in this manner.
219233 (Compiler experts will no doubt disagree.)
220234
@@ -231,7 +245,7 @@ rcu_assign_pointer() · 10 unmodified lines
231245 the _rcu list-manipulation primitives such as list_add_rcu().
232246
233247 rcu_dereference()
234−
248+^^^^^^^^^^^^^^^^^
235249 typeof(p) rcu_dereference(p);
236250
237251 Like rcu_assign_pointer(), rcu_dereference() must be implemented
@@ -248,13 +262,13 @@ rcu_dereference() · 10 unmodified lines
248262
249263 Common coding practice uses rcu_dereference() to copy an
250264 RCU-protected pointer to a local variable, then dereferences
251− this local variable, for example as follows:
265+ this local variable, for example as follows::
252266
253267 p = rcu_dereference(head.next);
254268 return p->data;
255269
256270 However, in this case, one could just as easily combine these
257− into one statement:
271+ into one statement::
258272
259273 return rcu_dereference(head.next)->data;
260274
@@ -266,8 +280,8 @@ rcu_dereference() · 5 unmodified lines
266280 unnecessary overhead on Alpha CPUs.
267281
268282 Note that the value returned by rcu_dereference() is valid
269− only within the enclosing RCU read-side critical section [1].
270− For example, the following is -not- legal:
283+ only within the enclosing RCU read-side critical section [1]_.
284+ For example, the following is **not** legal::
271285
272286 rcu_read_lock();
273287 p = rcu_dereference(head.next);
@@ -290,9 +304,9 @@ rcu_dereference() · 16 unmodified lines
290304 at any time, including immediately after the rcu_dereference().
291305 And, again like rcu_assign_pointer(), rcu_dereference() is
292306 typically used indirectly, via the _rcu list-manipulation
293− primitives, such as list_for_each_entry_rcu() [2].
307+ primitives, such as list_for_each_entry_rcu() [2]_.
294308
295− [1] The variant rcu_dereference_protected() can be used outside
309+.. [1] The variant rcu_dereference_protected() can be used outside
296310 of an RCU read-side critical section as long as the usage is
297311 protected by locks acquired by the update-side code. This variant
298312 avoids the lockdep warning that would happen when using (for
@@ -305,7 +319,7 @@ rcu_dereference() · 6 unmodified lines
305319 a lockdep splat is emitted. See Documentation/RCU/Design/Requirements/Requirements.rst
306320 and the API's code comments for more details and example usage.
307321
308− [2] If the list_for_each_entry_rcu() instance might be used by
322+.. [2] If the list_for_each_entry_rcu() instance might be used by
309323 update-side code as well as by RCU readers, then an additional
310324 lockdep expression can be added to its list of arguments.
311325 For example, given an additional "lock_is_held(&mylock)" argument,
@@ -315,6 +329,7 @@ rcu_dereference() · 3 unmodified lines
315329
316330 The following diagram shows how each API communicates among the
317331 reader, updater, and reclaimer.
332+::
318333
319334
320335 rcu_assign_pointer()
@@ -375,12 +390,16 @@ c. RCU applied to scheduler and interrupt/NMI-handler tasks. · 54 unmodified lines
375390 Again, most uses will be of (a). The (b) and (c) cases are important
376391 for specialized uses, but are relatively uncommon.
377392
393+.. _3_whatisRCU:
378394
379395 3. WHAT ARE SOME EXAMPLE USES OF CORE RCU API?
396+-----------------------------------------------
380397
381398 This section shows a simple use of the core RCU API to protect a
382399 global pointer to a dynamically allocated structure. More-typical
383−uses of RCU may be found in listRCU.txt, arrayRCU.txt, and NMI-RCU.txt.
400+uses of RCU may be found in :ref:`listRCU.rst <list_rcu_doc>`,
401+:ref:`arrayRCU.rst <array_rcu_doc>`, and :ref:`NMI-RCU.rst <NMI_rcu_doc>`.
402+::
384403
385404 struct foo {
386405 int a;
@@ -440,40 +459,43 @@ uses of RCU may be found in listRCU.txt, arrayRCU.txt, and NMI-RCU.txt. · 53 unmodified lines
440459
441460 So, to sum up:
442461
443−o Use rcu_read_lock() and rcu_read_unlock() to guard RCU
462+- Use rcu_read_lock() and rcu_read_unlock() to guard RCU
444463 read-side critical sections.
445464
446−o Within an RCU read-side critical section, use rcu_dereference()
465+- Within an RCU read-side critical section, use rcu_dereference()
447466 to dereference RCU-protected pointers.
448467
449−o Use some solid scheme (such as locks or semaphores) to
468+- Use some solid scheme (such as locks or semaphores) to
450469 keep concurrent updates from interfering with each other.
451470
452−o Use rcu_assign_pointer() to update an RCU-protected pointer.
471+- Use rcu_assign_pointer() to update an RCU-protected pointer.
453472 This primitive protects concurrent readers from the updater,
454− -not- concurrent updates from each other! You therefore still
473+ **not** concurrent updates from each other! You therefore still
455474 need to use locking (or something similar) to keep concurrent
456475 rcu_assign_pointer() primitives from interfering with each other.
457476
458−o Use synchronize_rcu() -after- removing a data element from an
459− RCU-protected data structure, but -before- reclaiming/freeing
477+- Use synchronize_rcu() **after** removing a data element from an
478+ RCU-protected data structure, but **before** reclaiming/freeing
460479 the data element, in order to wait for the completion of all
461480 RCU read-side critical sections that might be referencing that
462481 data item.
463482
464483 See checklist.txt for additional rules to follow when using RCU.
465−And again, more-typical uses of RCU may be found in listRCU.txt,
466−arrayRCU.txt, and NMI-RCU.txt.
484+And again, more-typical uses of RCU may be found in :ref:`listRCU.rst
485+<list_rcu_doc>`, :ref:`arrayRCU.rst <array_rcu_doc>`, and :ref:`NMI-RCU.rst
486+<NMI_rcu_doc>`.
467487
488+.. _4_whatisRCU:
468489
469490 4. WHAT IF MY UPDATING THREAD CANNOT BLOCK?
491+--------------------------------------------
470492
471493 In the example above, foo_update_a() blocks until a grace period elapses.
472494 This is quite simple, but in some cases one cannot afford to wait so
473495 long -- there might be other high-priority work to be done.
474496
475497 In such cases, one uses call_rcu() rather than synchronize_rcu().
476−The call_rcu() API is as follows:
498+The call_rcu() API is as follows::
477499
478500 void call_rcu(struct rcu_head * head,
479501 void (*func)(struct rcu_head *head));
@@ -481,7 +503,7 @@ The call_rcu() API is as follows: · 1 unmodified line
481503 This function invokes func(head) after a grace period has elapsed.
482504 This invocation might happen from either softirq or process context,
483505 so the function is not permitted to block. The foo struct needs to
484−have an rcu_head structure added, perhaps as follows:
506+have an rcu_head structure added, perhaps as follows::
485507
486508 struct foo {
487509 int a;
@@ -490,7 +512,7 @@ have an rcu_head structure added, perhaps as follows: · 2 unmodified lines
490512 struct rcu_head rcu;
491513 };
492514
493−The foo_update_a() function might then be written as follows:
515+The foo_update_a() function might then be written as follows::
494516
495517 /*
496518 * Create a new struct foo that is the same as the one currently
@@ -520,7 +542,7 @@ The foo_update_a() function might then be written as follows: · 23 unmodified lines
520542 call_rcu(&old_fp->rcu, foo_reclaim);
521543 }
522544
523−The foo_reclaim() function might appear as follows:
545+The foo_reclaim() function might appear as follows::
524546
525547 void foo_reclaim(struct rcu_head *rp)
526548 {
@@ -544,7 +566,7 @@ namely foo_reclaim(). · 17 unmodified lines
544566 The summary of advice is the same as for the previous section, except
545567 that we are now using call_rcu() rather than synchronize_rcu():
546568
547−o Use call_rcu() -after- removing a data element from an
569+- Use call_rcu() **after** removing a data element from an
548570 RCU-protected data structure in order to register a callback
549571 function that will be invoked after the completion of all RCU
550572 read-side critical sections that might be referencing that
@@ -552,14 +574,16 @@ o Use call_rcu() -after- removing a data element from an · 1 unmodified line
552574
553575 If the callback for call_rcu() is not doing anything more than calling
554576 kfree() on the structure, you can use kfree_rcu() instead of call_rcu()
555−to avoid having to write your own callback:
577+to avoid having to write your own callback::
556578
557579 kfree_rcu(old_fp, rcu);
558580
559581 Again, see checklist.txt for additional rules governing the use of RCU.
560582
583+.. _5_whatisRCU:
561584
562585 5. WHAT ARE SOME SIMPLE IMPLEMENTATIONS OF RCU?
586+------------------------------------------------
563587
564588 One of the nice things about RCU is that it has extremely simple "toy"
565589 implementations that are a good first step towards understanding the
@@ -579,7 +603,7 @@ more details on the current implementation as of early 2004. · 13 unmodified lines
579603
580604
581605 5A. "TOY" IMPLEMENTATION #1: LOCKING
582−
606+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
583607 This section presents a "toy" RCU implementation that is based on
584608 familiar locking primitives. Its overhead makes it a non-starter for
585609 real-life use, as does its lack of scalability. It is also unsuitable
@@ -591,7 +615,7 @@ you allow nested rcu_read_lock() calls, you can deadlock. · 5 unmodified lines
591615 However, it is probably the easiest implementation to relate to, so is
592616 a good starting point.
593617
594−It is extremely simple:
618+It is extremely simple::
595619
596620 static DEFINE_RWLOCK(rcu_gp_mutex);
597621
@@ -614,7 +638,7 @@ It is extremely simple: · 16 unmodified lines
614638
615639 [You can ignore rcu_assign_pointer() and rcu_dereference() without missing
616640 much. But here are simplified versions anyway. And whatever you do,
617−don't forget about them when submitting patches making use of RCU!]
641+don't forget about them when submitting patches making use of RCU!]::
618642
619643 #define rcu_assign_pointer(p, v) \
620644 ({ \
@@ -647,18 +671,23 @@ that the only thing that can block rcu_read_lock() is a synchronize_rcu(). · 26 unmodified lines
647671 But synchronize_rcu() does not acquire any locks while holding rcu_gp_mutex,
648672 so there can be no deadlock cycle.
649673
650−Quick Quiz #1: Why is this argument naive? How could a deadlock
674+.. _quiz_1:
675+
676+Quick Quiz #1:
677+ Why is this argument naive? How could a deadlock
651678 occur when using this algorithm in a real-world Linux
652679 kernel? How could this deadlock be avoided?
653680
681+:ref:`Answers to Quick Quiz <8_whatisRCU>`
654682
655683 5B. "TOY" EXAMPLE #2: CLASSIC RCU
656−
684+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
657685 This section presents a "toy" RCU implementation that is based on
658686 "classic RCU". It is also short on performance (but only for updates) and
659687 on features such as hotplug CPU and the ability to run in CONFIG_PREEMPT
660688 kernels. The definitions of rcu_dereference() and rcu_assign_pointer()
661689 are the same as those shown in the preceding section, so they are omitted.
690+::
662691
663692 void rcu_read_lock(void) { }
664693
@@ -683,14 +712,14 @@ CPU in turn. The run_on() primitive can be implemented straightforwardly · 18 unmodified lines
683712 in terms of the sched_setaffinity() primitive. Of course, a somewhat less
684713 "toy" implementation would restore the affinity upon completion rather
685714 than just leaving all tasks running on the last CPU, but when I said
686−"toy", I meant -toy-!
715+"toy", I meant **toy**!
687716
688717 So how the heck is this supposed to work???
689718
690719 Remember that it is illegal to block while in an RCU read-side critical
691720 section. Therefore, if a given CPU executes a context switch, we know
692721 that it must have completed all preceding RCU read-side critical sections.
693−Once -all- CPUs have executed a context switch, then -all- preceding
722+Once **all** CPUs have executed a context switch, then **all** preceding
694723 RCU read-side critical sections will have completed.
695724
696725 So, suppose that we remove a data item from its structure and then invoke
@@ -698,19 +727,32 @@ synchronize_rcu(). Once synchronize_rcu() returns, we are guaranteed · 1 unmodified line
698727 that there are no RCU read-side critical sections holding a reference
699728 to that data item, so we can safely reclaim it.
700729
701−Quick Quiz #2: Give an example where Classic RCU's read-side
702− overhead is -negative-.
730+.. _quiz_2:
731+
732+Quick Quiz #2:
733+ Give an example where Classic RCU's read-side
734+ overhead is **negative**.
735+
736+:ref:`Answers to Quick Quiz <8_whatisRCU>`
703737
704−Quick Quiz #3: If it is illegal to block in an RCU read-side
738+.. _quiz_3:
739+
740+Quick Quiz #3:
741+ If it is illegal to block in an RCU read-side
705742 critical section, what the heck do you do in
706743 PREEMPT_RT, where normal spinlocks can block???
707744
745+:ref:`Answers to Quick Quiz <8_whatisRCU>`
746+
747+.. _6_whatisRCU:
708748
709749 6. ANALOGY WITH READER-WRITER LOCKING
750+--------------------------------------
710751
711752 Although RCU can be used in many different ways, a very common use of
712753 RCU is analogous to reader-writer locking. The following unified
713754 diff shows how closely related RCU and reader-writer locking can be.
755+::
714756
715757 @@ -5,5 +5,5 @@ struct el {
716758 int data;
@@ -762,7 +804,7 @@ diff shows how closely related RCU and reader-writer locking can be. · 45 unmodified lines
762804 return 0;
763805 }
764806
765−Or, for those who prefer a side-by-side listing:
807+Or, for those who prefer a side-by-side listing::
766808
767809 1 struct el { 1 struct el {
768810 2 struct list_head list; 2 struct list_head list;
@@ -774,40 +816,44 @@ Or, for those who prefer a side-by-side listing: · 5 unmodified lines
774816 8 rwlock_t listmutex; 8 spinlock_t listmutex;
775817 9 struct el head; 9 struct el head;
776818
777− 1 int search(long key, int *result) 1 int search(long key, int *result)
778− 2 { 2 {
779− 3 struct list_head *lp; 3 struct list_head *lp;
780− 4 struct el *p; 4 struct el *p;
781− 5 5
782− 6 read_lock(&listmutex); 6 rcu_read_lock();
783− 7 list_for_each_entry(p, head, lp) { 7 list_for_each_entry_rcu(p, head, lp) {
784− 8 if (p->key == key) { 8 if (p->key == key) {
785− 9 *result = p->data; 9 *result = p->data;
786−10 read_unlock(&listmutex); 10 rcu_read_unlock();
787−11 return 1; 11 return 1;
788−12 } 12 }
789−13 } 13 }
790−14 read_unlock(&listmutex); 14 rcu_read_unlock();
791−15 return 0; 15 return 0;
792−16 } 16 }
793−
794− 1 int delete(long key) 1 int delete(long key)
795− 2 { 2 {
796− 3 struct el *p; 3 struct el *p;
797− 4 4
798− 5 write_lock(&listmutex); 5 spin_lock(&listmutex);
799− 6 list_for_each_entry(p, head, lp) { 6 list_for_each_entry(p, head, lp) {
800− 7 if (p->key == key) { 7 if (p->key == key) {
801− 8 list_del(&p->list); 8 list_del_rcu(&p->list);
802− 9 write_unlock(&listmutex); 9 spin_unlock(&listmutex);
803− 10 synchronize_rcu();
804−10 kfree(p); 11 kfree(p);
805−11 return 1; 12 return 1;
806−12 } 13 }
807−13 } 14 }
808−14 write_unlock(&listmutex); 15 spin_unlock(&listmutex);
809−15 return 0; 16 return 0;
810−16 } 17 }
819+::
820+
821+ 1 int search(long key, int *result) 1 int search(long key, int *result)
822+ 2 { 2 {
823+ 3 struct list_head *lp; 3 struct list_head *lp;
824+ 4 struct el *p; 4 struct el *p;
825+ 5 5
826+ 6 read_lock(&listmutex); 6 rcu_read_lock();
827+ 7 list_for_each_entry(p, head, lp) { 7 list_for_each_entry_rcu(p, head, lp) {
828+ 8 if (p->key == key) { 8 if (p->key == key) {
829+ 9 *result = p->data; 9 *result = p->data;
830+ 10 read_unlock(&listmutex); 10 rcu_read_unlock();
831+ 11 return 1; 11 return 1;
832+ 12 } 12 }
833+ 13 } 13 }
834+ 14 read_unlock(&listmutex); 14 rcu_read_unlock();
835+ 15 return 0; 15 return 0;
836+ 16 } 16 }
837+
838+::
839+
840+ 1 int delete(long key) 1 int delete(long key)
841+ 2 { 2 {
842+ 3 struct el *p; 3 struct el *p;
843+ 4 4
844+ 5 write_lock(&listmutex); 5 spin_lock(&listmutex);
845+ 6 list_for_each_entry(p, head, lp) { 6 list_for_each_entry(p, head, lp) {
846+ 7 if (p->key == key) { 7 if (p->key == key) {
847+ 8 list_del(&p->list); 8 list_del_rcu(&p->list);
848+ 9 write_unlock(&listmutex); 9 spin_unlock(&listmutex);
849+ 10 synchronize_rcu();
850+ 10 kfree(p); 11 kfree(p);
851+ 11 return 1; 12 return 1;
852+ 12 } 13 }
853+ 13 } 14 }
854+ 14 write_unlock(&listmutex); 15 spin_unlock(&listmutex);
855+ 15 return 0; 16 return 0;
856+ 16 } 17 }
811857
812858 Either way, the differences are quite small. Read-side locking moves
813859 to rcu_read_lock() and rcu_read_unlock, update-side locking moves from
@@ -825,22 +871,27 @@ delete() can now block. If this is a problem, there is a callback-based · 11 unmodified lines
825871 mechanism that never blocks, namely call_rcu() or kfree_rcu(), that can
826872 be used in place of synchronize_rcu().
827873
874+.. _7_whatisRCU:
828875
829876 7. FULL LIST OF RCU APIs
877+-------------------------
830878
831879 The RCU APIs are documented in docbook-format header comments in the
832880 Linux-kernel source code, but it helps to have a full list of the
833881 APIs, since there does not appear to be a way to categorize them
834882 in docbook. Here is the list, by category.
835883
836−RCU list traversal:
884+RCU list traversal::
837885
838886 list_entry_rcu
887+ list_entry_lockless
839888 list_first_entry_rcu
840889 list_next_rcu
841890 list_for_each_entry_rcu
842891 list_for_each_entry_continue_rcu
843892 list_for_each_entry_from_rcu
893+ list_first_or_null_rcu
894+ list_next_or_null_rcu
844895 hlist_first_rcu
845896 hlist_next_rcu
846897 hlist_pprev_rcu
@@ -854,7 +905,7 @@ RCU list traversal: · 7 unmodified lines
854905 hlist_bl_first_rcu
855906 hlist_bl_for_each_entry_rcu
856907
857−RCU pointer/list update:
908+RCU pointer/list update::
858909
859910 rcu_assign_pointer
860911 list_add_rcu
@@ -864,10 +915,12 @@ RCU pointer/list update: · 3 unmodified lines
864915 hlist_add_behind_rcu
865916 hlist_add_before_rcu
866917 hlist_add_head_rcu
918+ hlist_add_tail_rcu
867919 hlist_del_rcu
868920 hlist_del_init_rcu
869921 hlist_replace_rcu
870− list_splice_init_rcu()
922+ list_splice_init_rcu
923+ list_splice_tail_init_rcu
871924 hlist_nulls_del_init_rcu
872925 hlist_nulls_del_rcu
873926 hlist_nulls_add_head_rcu
@@ -876,7 +929,9 @@ RCU pointer/list update: · 2 unmodified lines
876929 hlist_bl_del_rcu
877930 hlist_bl_set_first_rcu
878931
879−RCU: Critical sections Grace period Barrier
932+RCU::
933+
934+ Critical sections Grace period Barrier
880935
881936 rcu_read_lock synchronize_net rcu_barrier
882937 rcu_read_unlock synchronize_rcu
@@ -885,7 +940,9 @@ RCU: Critical sections Grace period Barrier · 2 unmodified lines
885940 rcu_dereference_check kfree_rcu
886941 rcu_dereference_protected
887942
888−bh: Critical sections Grace period Barrier
943+bh::
944+
945+ Critical sections Grace period Barrier
889946
890947 rcu_read_lock_bh call_rcu rcu_barrier
891948 rcu_read_unlock_bh synchronize_rcu
@@ -896,7 +953,9 @@ bh: Critical sections Grace period Barrier · 4 unmodified lines
896953 rcu_dereference_bh_protected
897954 rcu_read_lock_bh_held
898955
899−sched: Critical sections Grace period Barrier
956+sched::
957+
958+ Critical sections Grace period Barrier
900959
901960 rcu_read_lock_sched call_rcu rcu_barrier
902961 rcu_read_unlock_sched synchronize_rcu
@@ -910,7 +969,9 @@ sched: Critical sections Grace period Barrier · 7 unmodified lines
910969 rcu_read_lock_sched_held
911970
912971
913−SRCU: Critical sections Grace period Barrier
972+SRCU::
973+
974+ Critical sections Grace period Barrier
914975
915976 srcu_read_lock call_srcu srcu_barrier
916977 srcu_read_unlock synchronize_srcu
@@ -918,13 +979,14 @@ SRCU: Critical sections Grace period Barrier · 1 unmodified line
918979 srcu_dereference_check
919980 srcu_read_lock_held
920981
921−SRCU: Initialization/cleanup
982+SRCU: Initialization/cleanup::
983+
922984 DEFINE_SRCU
923985 DEFINE_STATIC_SRCU
924986 init_srcu_struct
925987 cleanup_srcu_struct
926988
927−All: lockdep-checked RCU-protected pointer access
989+All: lockdep-checked RCU-protected pointer access::
928990
929991 rcu_access_pointer
930992 rcu_dereference_raw
@@ -974,15 +1036,19 @@ g. Otherwise, use RCU. · 43 unmodified lines
9741036 Of course, this all assumes that you have determined that RCU is in fact
9751037 the right tool for your job.
9761038
1039+.. _8_whatisRCU:
9771040
9781041 8. ANSWERS TO QUICK QUIZZES
1042+----------------------------
9791043
980−Quick Quiz #1: Why is this argument naive? How could a deadlock
1044+Quick Quiz #1:
1045+ Why is this argument naive? How could a deadlock
9811046 occur when using this algorithm in a real-world Linux
9821047 kernel? [Referring to the lock-based "toy" RCU
9831048 algorithm.]
9841049
985−Answer: Consider the following sequence of events:
1050+Answer:
1051+ Consider the following sequence of events:
9861052
9871053 1. CPU 0 acquires some unrelated lock, call it
9881054 "problematic_lock", disabling irq via
@@ -1021,10 +1087,14 @@ Answer: Consider the following sequence of events: · 32 unmodified lines
10211087 approach where tasks in RCU read-side critical sections
10221088 cannot be blocked by tasks executing synchronize_rcu().
10231089
1024−Quick Quiz #2: Give an example where Classic RCU's read-side
1025− overhead is -negative-.
1090+:ref:`Back to Quick Quiz #1 <quiz_1>`
1091+
1092+Quick Quiz #2:
1093+ Give an example where Classic RCU's read-side
1094+ overhead is **negative**.
10261095
1027−Answer: Imagine a single-CPU system with a non-CONFIG_PREEMPT
1096+Answer:
1097+ Imagine a single-CPU system with a non-CONFIG_PREEMPT
10281098 kernel where a routing table is used by process-context
10291099 code, but can be updated by irq-context code (for example,
10301100 by an "ICMP REDIRECT" packet). The usual way of handling
@@ -1046,11 +1116,15 @@ Answer: Imagine a single-CPU system with a non-CONFIG_PREEMPT · 15 unmodified lines
10461116 even the theoretical possibility of negative overhead for
10471117 a synchronization primitive is a bit unexpected. ;-)
10481118
1049−Quick Quiz #3: If it is illegal to block in an RCU read-side
1119+:ref:`Back to Quick Quiz #2 <quiz_2>`
1120+
1121+Quick Quiz #3:
1122+ If it is illegal to block in an RCU read-side
10501123 critical section, what the heck do you do in
10511124 PREEMPT_RT, where normal spinlocks can block???
10521125
1053−Answer: Just as PREEMPT_RT permits preemption of spinlock
1126+Answer:
1127+ Just as PREEMPT_RT permits preemption of spinlock
10541128 critical sections, it permits preemption of RCU
10551129 read-side critical sections. It also permits
10561130 spinlocks blocking while in RCU read-side critical
@@ -1069,6 +1143,7 @@ Answer: Just as PREEMPT_RT permits preemption of spinlock · 12 unmodified lines
10691143 Besides, how does the computer know what pizza parlor
10701144 the human being went to???
10711145
1146+:ref:`Back to Quick Quiz #3 <quiz_3>`
10721147
10731148 ACKNOWLEDGEMENTS
10741149
Documentation/admin-guide/kernel-parameters.txt+13−0
@@ -4001,6 +4001,19 @@ · 4000 unmodified lines
40014001 test until boot completes in order to avoid
40024002 interference.
40034003
4004+ rcuperf.kfree_rcu_test= [KNL]
4005+ Set to measure performance of kfree_rcu() flooding.
4006+
4007+ rcuperf.kfree_nthreads= [KNL]
4008+ The number of threads running loops of kfree_rcu().
4009+
4010+ rcuperf.kfree_alloc_num= [KNL]
4011+ Number of allocations and frees done in an iteration.
4012+
4013+ rcuperf.kfree_loops= [KNL]
4014+ Number of loops doing rcuperf.kfree_alloc_num number
4015+ of allocations and frees.
4016+
40044017 rcuperf.nreaders= [KNL]
40054018 Set number of RCU readers. The value -1 selects
40064019 N, where N is the number of CPUs. A value
arch/powerpc/include/asm/barrier.h+0−2
@@ -18,8 +18,6 @@ · 17 unmodified lines
1818 * mb() prevents loads and stores being reordered across this point.
1919 * rmb() prevents loads being reordered across this point.
2020 * wmb() prevents stores being reordered across this point.
21− * read_barrier_depends() prevents data-dependent loads being reordered
22− * across this point (nop on PPC).
2321 *
2422 * *mb() variants without smp_ prefix must order all types of memory
2523 * operations with one another. sync is the only instruction sufficient
drivers/net/wireless/mediatek/mt76/agg-rx.c+2−2
@@ -281,8 +281,8 @@ void mt76_rx_aggr_stop(struct mt76_dev *dev, struct mt76_wcid *wcid, u8 tidno) · 280 unmodified lines
281281 {
282282 struct mt76_rx_tid *tid = NULL;
283283
284− rcu_swap_protected(wcid->aggr[tidno], tid,
285− lockdep_is_held(&dev->mutex));
284+ tid = rcu_replace_pointer(wcid->aggr[tidno], tid,
285+ lockdep_is_held(&dev->mutex));
286286 if (tid) {
287287 mt76_rx_aggr_shutdown(dev, tid);
288288 kfree_rcu(tid, rcu_head);
include/linux/list.h+112−24
@@ -23,6 +23,13 @@ · 22 unmodified lines
2323 #define LIST_HEAD(name) \
2424 struct list_head name = LIST_HEAD_INIT(name)
2525
26+/**
27+ * INIT_LIST_HEAD - Initialize a list_head structure
28+ * @list: list_head structure to be initialized.
29+ *
30+ * Initializes the list_head to point to itself. If it is a list header,
31+ * the result is an empty list.
32+ */
2633 static inline void INIT_LIST_HEAD(struct list_head *list)
2734 {
2835 WRITE_ONCE(list->next, list);
@@ -120,12 +127,6 @@ static inline void __list_del_clearprev(struct list_head *entry) · 91 unmodified lines
120127 entry->prev = NULL;
121128 }
122129
123−/**
124− * list_del - deletes entry from list.
125− * @entry: the element to delete from the list.
126− * Note: list_empty() on entry does not return true after this, the entry is
127− * in an undefined state.
128− */
129130 static inline void __list_del_entry(struct list_head *entry)
130131 {
131132 if (!__list_del_entry_valid(entry))
@@ -134,6 +135,12 @@ static inline void __list_del_entry(struct list_head *entry) · 2 unmodified lines
134135 __list_del(entry->prev, entry->next);
135136 }
136137
138+/**
139+ * list_del - deletes entry from list.
140+ * @entry: the element to delete from the list.
141+ * Note: list_empty() on entry does not return true after this, the entry is
142+ * in an undefined state.
143+ */
137144 static inline void list_del(struct list_head *entry)
138145 {
139146 __list_del_entry(entry);
@@ -157,8 +164,15 @@ static inline void list_replace(struct list_head *old, · 17 unmodified lines
157164 new->prev->next = new;
158165 }
159166
167+/**
168+ * list_replace_init - replace old entry by new one and initialize the old one
169+ * @old : the element to be replaced
170+ * @new : the new element to insert
171+ *
172+ * If @old was empty, it will be overwritten.
173+ */
160174 static inline void list_replace_init(struct list_head *old,
161− struct list_head *new)
175+ struct list_head *new)
162176 {
163177 list_replace(old, new);
164178 INIT_LIST_HEAD(old);
@@ -754,11 +768,36 @@ static inline void INIT_HLIST_NODE(struct hlist_node *h) · 589 unmodified lines
754768 h->pprev = NULL;
755769 }
756770
771+/**
772+ * hlist_unhashed - Has node been removed from list and reinitialized?
773+ * @h: Node to be checked
774+ *
775+ * Not that not all removal functions will leave a node in unhashed
776+ * state. For example, hlist_nulls_del_init_rcu() does leave the
777+ * node in unhashed state, but hlist_nulls_del() does not.
778+ */
757779 static inline int hlist_unhashed(const struct hlist_node *h)
758780 {
759781 return !h->pprev;
760782 }
761783
784+/**
785+ * hlist_unhashed_lockless - Version of hlist_unhashed for lockless use
786+ * @h: Node to be checked
787+ *
788+ * This variant of hlist_unhashed() must be used in lockless contexts
789+ * to avoid potential load-tearing. The READ_ONCE() is paired with the
790+ * various WRITE_ONCE() in hlist helpers that are defined below.
791+ */
792+static inline int hlist_unhashed_lockless(const struct hlist_node *h)
793+{
794+ return !READ_ONCE(h->pprev);
795+}
796+
797+/**
798+ * hlist_empty - Is the specified hlist_head structure an empty hlist?
799+ * @h: Structure to check.
800+ */
762801 static inline int hlist_empty(const struct hlist_head *h)
763802 {
764803 return !READ_ONCE(h->first);
@@ -771,9 +810,16 @@ static inline void __hlist_del(struct hlist_node *n) · 6 unmodified lines
771810
772811 WRITE_ONCE(*pprev, next);
773812 if (next)
774− next->pprev = pprev;
813+ WRITE_ONCE(next->pprev, pprev);
775814 }
776815
816+/**
817+ * hlist_del - Delete the specified hlist_node from its list
818+ * @n: Node to delete.
819+ *
820+ * Note that this function leaves the node in hashed state. Use
821+ * hlist_del_init() or similar instead to unhash @n.
822+ */
777823 static inline void hlist_del(struct hlist_node *n)
778824 {
779825 __hlist_del(n);
@@ -781,6 +827,12 @@ static inline void hlist_del(struct hlist_node *n) · 1 unmodified line
781827 n->pprev = LIST_POISON2;
782828 }
783829
830+/**
831+ * hlist_del_init - Delete the specified hlist_node from its list and initialize
832+ * @n: Node to delete.
833+ *
834+ * Note that this function leaves the node in unhashed state.
835+ */
784836 static inline void hlist_del_init(struct hlist_node *n)
785837 {
786838 if (!hlist_unhashed(n)) {
@@ -789,51 +841,83 @@ static inline void hlist_del_init(struct hlist_node *n) · 2 unmodified lines
789841 }
790842 }
791843
844+/**
845+ * hlist_add_head - add a new entry at the beginning of the hlist
846+ * @n: new entry to be added
847+ * @h: hlist head to add it after
848+ *
849+ * Insert a new entry after the specified head.
850+ * This is good for implementing stacks.
851+ */
792852 static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
793853 {
794854 struct hlist_node *first = h->first;
795− n->next = first;
855+ WRITE_ONCE(n->next, first);
796856 if (first)
797− first->pprev = &n->next;
857+ WRITE_ONCE(first->pprev, &n->next);
798858 WRITE_ONCE(h->first, n);
799− n->pprev = &h->first;
859+ WRITE_ONCE(n->pprev, &h->first);
800860 }
801861
802−/* next must be != NULL */
862+/**
863+ * hlist_add_before - add a new entry before the one specified
864+ * @n: new entry to be added
865+ * @next: hlist node to add it before, which must be non-NULL
866+ */
803867 static inline void hlist_add_before(struct hlist_node *n,
804− struct hlist_node *next)
868+ struct hlist_node *next)
805869 {
806− n->pprev = next->pprev;
807− n->next = next;
808− next->pprev = &n->next;
870+ WRITE_ONCE(n->pprev, next->pprev);
871+ WRITE_ONCE(n->next, next);
872+ WRITE_ONCE(next->pprev, &n->next);
809873 WRITE_ONCE(*(n->pprev), n);
810874 }
811875
876+/**
877+ * hlist_add_behing - add a new entry after the one specified
878+ * @n: new entry to be added
879+ * @prev: hlist node to add it after, which must be non-NULL
880+ */
812881 static inline void hlist_add_behind(struct hlist_node *n,
813882 struct hlist_node *prev)
814883 {
815− n->next = prev->next;
816− prev->next = n;
817− n->pprev = &prev->next;
884+ WRITE_ONCE(n->next, prev->next);
885+ WRITE_ONCE(prev->next, n);
886+ WRITE_ONCE(n->pprev, &prev->next);
818887
819888 if (n->next)
820− n->next->pprev = &n->next;
889+ WRITE_ONCE(n->next->pprev, &n->next);
821890 }
822891
823−/* after that we'll appear to be on some hlist and hlist_del will work */
892+/**
893+ * hlist_add_fake - create a fake hlist consisting of a single headless node
894+ * @n: Node to make a fake list out of
895+ *
896+ * This makes @n appear to be its own predecessor on a headless hlist.
897+ * The point of this is to allow things like hlist_del() to work correctly
898+ * in cases where there is no list.
899+ */
824900 static inline void hlist_add_fake(struct hlist_node *n)
825901 {
826902 n->pprev = &n->next;
827903 }
828904
905+/**
906+ * hlist_fake: Is this node a fake hlist?
907+ * @h: Node to check for being a self-referential fake hlist.
908+ */
829909 static inline bool hlist_fake(struct hlist_node *h)
830910 {
831911 return h->pprev == &h->next;
832912 }
833913
834−/*
914+/**
915+ * hlist_is_singular_node - is node the only element of the specified hlist?
916+ * @n: Node to check for singularity.
917+ * @h: Header for potentially singular list.
918+ *
835919 * Check whether the node is the only node of the head without
836− * accessing head:
920+ * accessing head, thus avoiding unnecessary cache misses.
837921 */
838922 static inline bool
839923 hlist_is_singular_node(struct hlist_node *n, struct hlist_head *h)
@@ -841,7 +925,11 @@ hlist_is_singular_node(struct hlist_node *n, struct hlist_head *h) · 1 unmodified line
841925 return !n->next && n->pprev == &h->first;
842926 }
843927
844−/*
928+/**
929+ * hlist_move_list - Move an hlist
930+ * @old: hlist_head for old list.
931+ * @new: hlist_head for new list.
932+ *
845933 * Move a list from one list head to another. Fixup the pprev
846934 * reference of the first entry if it exists.
847935 */
include/linux/list_nulls.h+26−4
@@ -56,11 +56,33 @@ static inline unsigned long get_nulls_value(const struct hlist_nulls_node *ptr) · 55 unmodified lines
5656 return ((unsigned long)ptr) >> 1;
5757 }
5858
59+/**
60+ * hlist_nulls_unhashed - Has node been removed and reinitialized?
61+ * @h: Node to be checked
62+ *
63+ * Not that not all removal functions will leave a node in unhashed state.
64+ * For example, hlist_del_init_rcu() leaves the node in unhashed state,
65+ * but hlist_nulls_del() does not.
66+ */
5967 static inline int hlist_nulls_unhashed(const struct hlist_nulls_node *h)
6068 {
6169 return !h->pprev;
6270 }
6371
72+/**
73+ * hlist_nulls_unhashed_lockless - Has node been removed and reinitialized?
74+ * @h: Node to be checked
75+ *
76+ * Not that not all removal functions will leave a node in unhashed state.
77+ * For example, hlist_del_init_rcu() leaves the node in unhashed state,
78+ * but hlist_nulls_del() does not. Unlike hlist_nulls_unhashed(), this
79+ * function may be used locklessly.
80+ */
81+static inline int hlist_nulls_unhashed_lockless(const struct hlist_nulls_node *h)
82+{
83+ return !READ_ONCE(h->pprev);
84+}
85+
6486 static inline int hlist_nulls_empty(const struct hlist_nulls_head *h)
6587 {
6688 return is_a_nulls(READ_ONCE(h->first));
@@ -72,10 +94,10 @@ static inline void hlist_nulls_add_head(struct hlist_nulls_node *n, · 5 unmodified lines
7294 struct hlist_nulls_node *first = h->first;
7395
7496 n->next = first;
75− n->pprev = &h->first;
97+ WRITE_ONCE(n->pprev, &h->first);
7698 h->first = n;
7799 if (!is_a_nulls(first))
78− first->pprev = &n->next;
100+ WRITE_ONCE(first->pprev, &n->next);
79101 }
80102
81103 static inline void __hlist_nulls_del(struct hlist_nulls_node *n)
@@ -85,13 +107,13 @@ static inline void __hlist_nulls_del(struct hlist_nulls_node *n) · 3 unmodified lines
85107
86108 WRITE_ONCE(*pprev, next);
87109 if (!is_a_nulls(next))
88− next->pprev = pprev;
110+ WRITE_ONCE(next->pprev, pprev);
89111 }
90112
91113 static inline void hlist_nulls_del(struct hlist_nulls_node *n)
92114 {
93115 __hlist_nulls_del(n);
94− n->pprev = LIST_POISON2;
116+ WRITE_ONCE(n->pprev, LIST_POISON2);
95117 }
96118
97119 /**
include/linux/rcu_segcblist.h+0−2
@@ -22,7 +22,6 @@ struct rcu_cblist { · 21 unmodified lines
2222 struct rcu_head *head;
2323 struct rcu_head **tail;
2424 long len;
25− long len_lazy;
2625 };
2726
2827 #define RCU_CBLIST_INITIALIZER(n) { .head = NULL, .tail = &n.head }
@@ -73,7 +72,6 @@ struct rcu_segcblist { · 44 unmodified lines
7372 #else
7473 long len;
7574 #endif
76− long len_lazy;
7775 u8 enabled;
7876 u8 offloaded;
7977 };
include/linux/rculist.h+24−14
@@ -40,6 +40,16 @@ static inline void INIT_LIST_HEAD_RCU(struct list_head *list) · 39 unmodified lines
4040 */
4141 #define list_next_rcu(list) (*((struct list_head __rcu **)(&(list)->next)))
4242
43+/**
44+ * list_tail_rcu - returns the prev pointer of the head of the list
45+ * @head: the head of the list
46+ *
47+ * Note: This should only be used with the list header, and even then
48+ * only if list_del() and similar primitives are not also used on the
49+ * list header.
50+ */
51+#define list_tail_rcu(head) (*((struct list_head __rcu **)(&(head)->prev)))
52+
4353 /*
4454 * Check during list traversal that we are within an RCU reader
4555 */
@@ -173,7 +183,7 @@ static inline void hlist_del_init_rcu(struct hlist_node *n) · 127 unmodified lines
173183 {
174184 if (!hlist_unhashed(n)) {
175185 __hlist_del(n);
176− n->pprev = NULL;
186+ WRITE_ONCE(n->pprev, NULL);
177187 }
178188 }
179189
@@ -361,7 +371,7 @@ static inline void list_splice_tail_init_rcu(struct list_head *list, · 181 unmodified lines
361371 * @pos: the type * to use as a loop cursor.
362372 * @head: the head for your list.
363373 * @member: the name of the list_head within the struct.
364− * @cond: optional lockdep expression if called from non-RCU protection.
374+ * @cond...: optional lockdep expression if called from non-RCU protection.
365375 *
366376 * This list-traversal primitive may safely run concurrently with
367377 * the _rcu list-mutation primitives such as list_add_rcu()
@@ -473,7 +483,7 @@ static inline void list_splice_tail_init_rcu(struct list_head *list, · 105 unmodified lines
473483 static inline void hlist_del_rcu(struct hlist_node *n)
474484 {
475485 __hlist_del(n);
476− n->pprev = LIST_POISON2;
486+ WRITE_ONCE(n->pprev, LIST_POISON2);
477487 }
478488
479489 /**
@@ -489,11 +499,11 @@ static inline void hlist_replace_rcu(struct hlist_node *old, · 9 unmodified lines
489499 struct hlist_node *next = old->next;
490500
491501 new->next = next;
492− new->pprev = old->pprev;
502+ WRITE_ONCE(new->pprev, old->pprev);
493503 rcu_assign_pointer(*(struct hlist_node __rcu **)new->pprev, new);
494504 if (next)
495− new->next->pprev = &new->next;
496− old->pprev = LIST_POISON2;
505+ WRITE_ONCE(new->next->pprev, &new->next);
506+ WRITE_ONCE(old->pprev, LIST_POISON2);
497507 }
498508
499509 /*
@@ -528,10 +538,10 @@ static inline void hlist_add_head_rcu(struct hlist_node *n, · 28 unmodified lines
528538 struct hlist_node *first = h->first;
529539
530540 n->next = first;
531− n->pprev = &h->first;
541+ WRITE_ONCE(n->pprev, &h->first);
532542 rcu_assign_pointer(hlist_first_rcu(h), n);
533543 if (first)
534− first->pprev = &n->next;
544+ WRITE_ONCE(first->pprev, &n->next);
535545 }
536546
537547 /**
@@ -564,7 +574,7 @@ static inline void hlist_add_tail_rcu(struct hlist_node *n, · 26 unmodified lines
564574
565575 if (last) {
566576 n->next = last->next;
567− n->pprev = &last->next;
577+ WRITE_ONCE(n->pprev, &last->next);
568578 rcu_assign_pointer(hlist_next_rcu(last), n);
569579 } else {
570580 hlist_add_head_rcu(n, h);
@@ -592,10 +602,10 @@ static inline void hlist_add_tail_rcu(struct hlist_node *n, · 21 unmodified lines
592602 static inline void hlist_add_before_rcu(struct hlist_node *n,
593603 struct hlist_node *next)
594604 {
595− n->pprev = next->pprev;
605+ WRITE_ONCE(n->pprev, next->pprev);
596606 n->next = next;
597607 rcu_assign_pointer(hlist_pprev_rcu(n), n);
598− next->pprev = &n->next;
608+ WRITE_ONCE(next->pprev, &n->next);
599609 }
600610
601611 /**
@@ -620,10 +630,10 @@ static inline void hlist_add_behind_rcu(struct hlist_node *n, · 18 unmodified lines
620630 struct hlist_node *prev)
621631 {
622632 n->next = prev->next;
623− n->pprev = &prev->next;
633+ WRITE_ONCE(n->pprev, &prev->next);
624634 rcu_assign_pointer(hlist_next_rcu(prev), n);
625635 if (n->next)
626− n->next->pprev = &n->next;
636+ WRITE_ONCE(n->next->pprev, &n->next);
627637 }
628638
629639 #define __hlist_for_each_rcu(pos, head) \
@@ -636,7 +646,7 @@ static inline void hlist_add_behind_rcu(struct hlist_node *n, · 6 unmodified lines
636646 * @pos: the type * to use as a loop cursor.
637647 * @head: the head for your list.
638648 * @member: the name of the hlist_node within the struct.
639− * @cond: optional lockdep expression if called from non-RCU protection.
649+ * @cond...: optional lockdep expression if called from non-RCU protection.
640650 *
641651 * This list-traversal primitive may safely run concurrently with
642652 * the _rcu list-mutation primitives such as hlist_add_head_rcu()
include/linux/rculist_nulls.h+14−6
@@ -34,13 +34,21 @@ static inline void hlist_nulls_del_init_rcu(struct hlist_nulls_node *n) · 33 unmodified lines
3434 {
3535 if (!hlist_nulls_unhashed(n)) {
3636 __hlist_nulls_del(n);
37− n->pprev = NULL;
37+ WRITE_ONCE(n->pprev, NULL);
3838 }
3939 }
4040
41+/**
42+ * hlist_nulls_first_rcu - returns the first element of the hash list.
43+ * @head: the head of the list.
44+ */
4145 #define hlist_nulls_first_rcu(head) \
4246 (*((struct hlist_nulls_node __rcu __force **)&(head)->first))
4347
48+/**
49+ * hlist_nulls_next_rcu - returns the element of the list after @node.
50+ * @node: element of the list.
51+ */
4452 #define hlist_nulls_next_rcu(node) \
4553 (*((struct hlist_nulls_node __rcu __force **)&(node)->next))
4654
@@ -66,7 +74,7 @@ static inline void hlist_nulls_del_init_rcu(struct hlist_nulls_node *n) · 19 unmodified lines
6674 static inline void hlist_nulls_del_rcu(struct hlist_nulls_node *n)
6775 {
6876 __hlist_nulls_del(n);
69− n->pprev = LIST_POISON2;
77+ WRITE_ONCE(n->pprev, LIST_POISON2);
7078 }
7179
7280 /**
@@ -94,10 +102,10 @@ static inline void hlist_nulls_add_head_rcu(struct hlist_nulls_node *n, · 21 unmodified lines
94102 struct hlist_nulls_node *first = h->first;
95103
96104 n->next = first;
97− n->pprev = &h->first;
105+ WRITE_ONCE(n->pprev, &h->first);
98106 rcu_assign_pointer(hlist_nulls_first_rcu(h), n);
99107 if (!is_a_nulls(first))
100− first->pprev = &n->next;
108+ WRITE_ONCE(first->pprev, &n->next);
101109 }
102110
103111 /**
@@ -141,7 +149,7 @@ static inline void hlist_nulls_add_tail_rcu(struct hlist_nulls_node *n, · 37 unmodified lines
141149 * hlist_nulls_for_each_entry_rcu - iterate over rcu list of given type
142150 * @tpos: the type * to use as a loop cursor.
143151 * @pos: the &struct hlist_nulls_node to use as a loop cursor.
144− * @head: the head for your list.
152+ * @head: the head of the list.
145153 * @member: the name of the hlist_nulls_node within the struct.
146154 *
147155 * The barrier() is needed to make sure compiler doesn't cache first element [1],
@@ -161,7 +169,7 @@ static inline void hlist_nulls_add_tail_rcu(struct hlist_nulls_node *n, · 13 unmodified lines
161169 * iterate over list of given type safe against removal of list entry
162170 * @tpos: the type * to use as a loop cursor.
163171 * @pos: the &struct hlist_nulls_node to use as a loop cursor.
164− * @head: the head for your list.
172+ * @head: the head of the list.
165173 * @member: the name of the hlist_nulls_node within the struct.
166174 */
167175 #define hlist_nulls_for_each_entry_safe(tpos, pos, head, member) \
include/linux/rcupdate.h+8−20
@@ -154,7 +154,7 @@ static inline void exit_tasks_rcu_finish(void) { } · 153 unmodified lines
154154 *
155155 * This macro resembles cond_resched(), except that it is defined to
156156 * report potential quiescent states to RCU-tasks even if the cond_resched()
157− * machinery were to be shut off, as some advocate for PREEMPT kernels.
157+ * machinery were to be shut off, as some advocate for PREEMPTION kernels.
158158 */
159159 #define cond_resched_tasks_rcu_qs() \
160160 do { \
@@ -167,7 +167,7 @@ do { \ · 6 unmodified lines
167167 * TREE_RCU and rcu_barrier_() primitives in TINY_RCU.
168168 */
169169
170−#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
170+#if defined(CONFIG_TREE_RCU)
171171 #include <linux/rcutree.h>
172172 #elif defined(CONFIG_TINY_RCU)
173173 #include <linux/rcutiny.h>
@@ -400,22 +400,6 @@ do { \ · 226 unmodified lines
400400 __tmp; \
401401 })
402402
403−/**
404− * rcu_swap_protected() - swap an RCU and a regular pointer
405− * @rcu_ptr: RCU pointer
406− * @ptr: regular pointer
407− * @c: the conditions under which the dereference will take place
408− *
409− * Perform swap(@rcu_ptr, @ptr) where @rcu_ptr is an RCU-annotated pointer and
410− * @c is the argument that is passed to the rcu_dereference_protected() call
411− * used to read that pointer.
412− */
413−#define rcu_swap_protected(rcu_ptr, ptr, c) do { \
414− typeof(ptr) __tmp = rcu_dereference_protected((rcu_ptr), (c)); \
415− rcu_assign_pointer((rcu_ptr), (ptr)); \
416− (ptr) = __tmp; \
417−} while (0)
418−
419403 /**
420404 * rcu_access_pointer() - fetch RCU pointer with no dereferencing
421405 * @p: The pointer to read
@@ -598,10 +582,10 @@ do { \ · 176 unmodified lines
598582 *
599583 * You can avoid reading and understanding the next paragraph by
600584 * following this rule: don't put anything in an rcu_read_lock() RCU
601− * read-side critical section that would block in a !PREEMPT kernel.
585+ * read-side critical section that would block in a !PREEMPTION kernel.
602586 * But if you want the full story, read on!
603587 *
604− * In non-preemptible RCU implementations (TREE_RCU and TINY_RCU),
588+ * In non-preemptible RCU implementations (pure TREE_RCU and TINY_RCU),
605589 * it is illegal to block while in an RCU read-side critical section.
606590 * In preemptible RCU implementations (PREEMPT_RCU) in CONFIG_PREEMPTION
607591 * kernel builds, RCU read-side critical sections may be preempted,
@@ -912,4 +896,8 @@ rcu_head_after_call_rcu(struct rcu_head *rhp, rcu_callback_t f) · 304 unmodified lines
912896 return false;
913897 }
914898
899+/* kernel/ksysfs.c definitions */
900+extern int rcu_expedited;
901+extern int rcu_normal;
902+
915903 #endif /* __LINUX_RCUPDATE_H */
include/linux/rcutiny.h+1−0
@@ -85,6 +85,7 @@ static inline void rcu_scheduler_starting(void) { } · 84 unmodified lines
8585 static inline void rcu_end_inkernel_boot(void) { }
8686 static inline bool rcu_is_watching(void) { return true; }
8787 static inline void rcu_momentary_dyntick_idle(void) { }
88+static inline void kfree_rcu_scheduler_running(void) { }
8889
8990 /* Avoid RCU read-side critical sections leaking across. */
9091 static inline void rcu_all_qs(void) { barrier(); }
include/linux/rcutree.h+1−0
@@ -38,6 +38,7 @@ void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func); · 37 unmodified lines
3838 void rcu_barrier(void);
3939 bool rcu_eqs_special_set(int cpu);
4040 void rcu_momentary_dyntick_idle(void);
41+void kfree_rcu_scheduler_running(void);
4142 unsigned long get_state_synchronize_rcu(void);
4243 void cond_synchronize_rcu(unsigned long oldstate);
4344
include/linux/tick.h+4−1
@@ -109,8 +109,10 @@ enum tick_dep_bits { · 108 unmodified lines
109109 TICK_DEP_BIT_PERF_EVENTS = 1,
110110 TICK_DEP_BIT_SCHED = 2,
111111 TICK_DEP_BIT_CLOCK_UNSTABLE = 3,
112− TICK_DEP_BIT_RCU = 4
112+ TICK_DEP_BIT_RCU = 4,
113+ TICK_DEP_BIT_RCU_EXP = 5
113114 };
115+#define TICK_DEP_BIT_MAX TICK_DEP_BIT_RCU_EXP
114116
115117 #define TICK_DEP_MASK_NONE 0
116118 #define TICK_DEP_MASK_POSIX_TIMER (1 << TICK_DEP_BIT_POSIX_TIMER)
@@ -118,6 +120,7 @@ enum tick_dep_bits { · 1 unmodified line
118120 #define TICK_DEP_MASK_SCHED (1 << TICK_DEP_BIT_SCHED)
119121 #define TICK_DEP_MASK_CLOCK_UNSTABLE (1 << TICK_DEP_BIT_CLOCK_UNSTABLE)
120122 #define TICK_DEP_MASK_RCU (1 << TICK_DEP_BIT_RCU)
123+#define TICK_DEP_MASK_RCU_EXP (1 << TICK_DEP_BIT_RCU_EXP)
121124
122125 #ifdef CONFIG_NO_HZ_COMMON
123126 extern bool tick_nohz_enabled;
include/trace/events/rcu.h+16−24
@@ -41,7 +41,7 @@ TRACE_EVENT(rcu_utilization, · 40 unmodified lines
4141 TP_printk("%s", __entry->s)
4242 );
4343
44−#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
44+#if defined(CONFIG_TREE_RCU)
4545
4646 /*
4747 * Tracepoint for grace-period events. Takes a string identifying the
@@ -432,7 +432,7 @@ TRACE_EVENT_RCU(rcu_fqs, · 384 unmodified lines
432432 __entry->cpu, __entry->qsevent)
433433 );
434434
435−#endif /* #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU) */
435+#endif /* #if defined(CONFIG_TREE_RCU) */
436436
437437 /*
438438 * Tracepoint for dyntick-idle entry/exit events. These take a string
@@ -449,7 +449,7 @@ TRACE_EVENT_RCU(rcu_fqs, · 10 unmodified lines
449449 */
450450 TRACE_EVENT_RCU(rcu_dyntick,
451451
452− TP_PROTO(const char *polarity, long oldnesting, long newnesting, atomic_t dynticks),
452+ TP_PROTO(const char *polarity, long oldnesting, long newnesting, int dynticks),
453453
454454 TP_ARGS(polarity, oldnesting, newnesting, dynticks),
455455
@@ -464,7 +464,7 @@ TRACE_EVENT_RCU(rcu_dyntick, · 8 unmodified lines
464464 __entry->polarity = polarity;
465465 __entry->oldnesting = oldnesting;
466466 __entry->newnesting = newnesting;
467− __entry->dynticks = atomic_read(&dynticks);
467+ __entry->dynticks = dynticks;
468468 ),
469469
470470 TP_printk("%s %lx %lx %#3x", __entry->polarity,
@@ -481,16 +481,14 @@ TRACE_EVENT_RCU(rcu_dyntick, · 10 unmodified lines
481481 */
482482 TRACE_EVENT_RCU(rcu_callback,
483483
484− TP_PROTO(const char *rcuname, struct rcu_head *rhp, long qlen_lazy,
485− long qlen),
484+ TP_PROTO(const char *rcuname, struct rcu_head *rhp, long qlen),
486485
487− TP_ARGS(rcuname, rhp, qlen_lazy, qlen),
486+ TP_ARGS(rcuname, rhp, qlen),
488487
489488 TP_STRUCT__entry(
490489 __field(const char *, rcuname)
491490 __field(void *, rhp)
492491 __field(void *, func)
493− __field(long, qlen_lazy)
494492 __field(long, qlen)
495493 ),
496494
@@ -498,13 +496,12 @@ TRACE_EVENT_RCU(rcu_callback, · 1 unmodified line
498496 __entry->rcuname = rcuname;
499497 __entry->rhp = rhp;
500498 __entry->func = rhp->func;
501− __entry->qlen_lazy = qlen_lazy;
502499 __entry->qlen = qlen;
503500 ),
504501
505− TP_printk("%s rhp=%p func=%ps %ld/%ld",
502+ TP_printk("%s rhp=%p func=%ps %ld",
506503 __entry->rcuname, __entry->rhp, __entry->func,
507− __entry->qlen_lazy, __entry->qlen)
504+ __entry->qlen)
508505 );
509506
510507 /*
@@ -518,15 +515,14 @@ TRACE_EVENT_RCU(rcu_callback, · 7 unmodified lines
518515 TRACE_EVENT_RCU(rcu_kfree_callback,
519516
520517 TP_PROTO(const char *rcuname, struct rcu_head *rhp, unsigned long offset,
521− long qlen_lazy, long qlen),
518+ long qlen),
522519
523− TP_ARGS(rcuname, rhp, offset, qlen_lazy, qlen),
520+ TP_ARGS(rcuname, rhp, offset, qlen),
524521
525522 TP_STRUCT__entry(
526523 __field(const char *, rcuname)
527524 __field(void *, rhp)
528525 __field(unsigned long, offset)
529− __field(long, qlen_lazy)
530526 __field(long, qlen)
531527 ),
532528
@@ -534,13 +530,12 @@ TRACE_EVENT_RCU(rcu_kfree_callback, · 1 unmodified line
534530 __entry->rcuname = rcuname;
535531 __entry->rhp = rhp;
536532 __entry->offset = offset;
537− __entry->qlen_lazy = qlen_lazy;
538533 __entry->qlen = qlen;
539534 ),
540535
541− TP_printk("%s rhp=%p func=%ld %ld/%ld",
536+ TP_printk("%s rhp=%p func=%ld %ld",
542537 __entry->rcuname, __entry->rhp, __entry->offset,
543− __entry->qlen_lazy, __entry->qlen)
538+ __entry->qlen)
544539 );
545540
546541 /*
@@ -552,27 +547,24 @@ TRACE_EVENT_RCU(rcu_kfree_callback, · 5 unmodified lines
552547 */
553548 TRACE_EVENT_RCU(rcu_batch_start,
554549
555− TP_PROTO(const char *rcuname, long qlen_lazy, long qlen, long blimit),
550+ TP_PROTO(const char *rcuname, long qlen, long blimit),
556551
557− TP_ARGS(rcuname, qlen_lazy, qlen, blimit),
552+ TP_ARGS(rcuname, qlen, blimit),
558553
559554 TP_STRUCT__entry(
560555 __field(const char *, rcuname)
561− __field(long, qlen_lazy)
562556 __field(long, qlen)
563557 __field(long, blimit)
564558 ),
565559
566560 TP_fast_assign(
567561 __entry->rcuname = rcuname;
568− __entry->qlen_lazy = qlen_lazy;
569562 __entry->qlen = qlen;
570563 __entry->blimit = blimit;
571564 ),
572565
573− TP_printk("%s CBs=%ld/%ld bl=%ld",
574− __entry->rcuname, __entry->qlen_lazy, __entry->qlen,
575− __entry->blimit)
566+ TP_printk("%s CBs=%ld bl=%ld",
567+ __entry->rcuname, __entry->qlen, __entry->blimit)
576568 );
577569
578570 /*
kernel/rcu/Kconfig+9−8
@@ -7,7 +7,7 @@ menu "RCU Subsystem" · 6 unmodified lines
77
88 config TREE_RCU
99 bool
10− default y if !PREEMPTION && SMP
10+ default y if SMP
1111 help
1212 This option selects the RCU implementation that is
1313 designed for very large SMP system with hundreds or
@@ -17,6 +17,7 @@ config TREE_RCU · 3 unmodified lines
1717 config PREEMPT_RCU
1818 bool
1919 default y if PREEMPTION
20+ select TREE_RCU
2021 help
2122 This option selects the RCU implementation that is
2223 designed for very large SMP systems with hundreds or
@@ -78,7 +79,7 @@ config TASKS_RCU · 55 unmodified lines
7879 user-mode execution as quiescent states.
7980
8081 config RCU_STALL_COMMON
81− def_bool ( TREE_RCU || PREEMPT_RCU )
82+ def_bool TREE_RCU
8283 help
8384 This option enables RCU CPU stall code that is common between
8485 the TINY and TREE variants of RCU. The purpose is to allow
@@ -86,13 +87,13 @@ config RCU_STALL_COMMON · 1 unmodified line
8687 making these warnings mandatory for the tree variants.
8788
8889 config RCU_NEED_SEGCBLIST
89− def_bool ( TREE_RCU || PREEMPT_RCU || TREE_SRCU )
90+ def_bool ( TREE_RCU || TREE_SRCU )
9091
9192 config RCU_FANOUT
9293 int "Tree-based hierarchical RCU fanout value"
9394 range 2 64 if 64BIT
9495 range 2 32 if !64BIT
95− depends on (TREE_RCU || PREEMPT_RCU) && RCU_EXPERT
96+ depends on TREE_RCU && RCU_EXPERT
9697 default 64 if 64BIT
9798 default 32 if !64BIT
9899 help
@@ -112,7 +113,7 @@ config RCU_FANOUT_LEAF · 13 unmodified lines
112113 int "Tree-based hierarchical RCU leaf-level fanout value"
113114 range 2 64 if 64BIT
114115 range 2 32 if !64BIT
115− depends on (TREE_RCU || PREEMPT_RCU) && RCU_EXPERT
116+ depends on TREE_RCU && RCU_EXPERT
116117 default 16
117118 help
118119 This option controls the leaf-level fanout of hierarchical
@@ -187,7 +188,7 @@ config RCU_BOOST_DELAY · 68 unmodified lines
187188
188189 config RCU_NOCB_CPU
189190 bool "Offload RCU callback processing from boot-selected CPUs"
190− depends on TREE_RCU || PREEMPT_RCU
191+ depends on TREE_RCU
191192 depends on RCU_EXPERT || NO_HZ_FULL
192193 default n
193194 help
@@ -200,8 +201,8 @@ config RCU_NOCB_CPU · 6 unmodified lines
200201 specified at boot time by the rcu_nocbs parameter. For each
201202 such CPU, a kthread ("rcuox/N") will be created to invoke
202203 callbacks, where the "N" is the CPU being offloaded, and where
203− the "p" for RCU-preempt (PREEMPT kernels) and "s" for RCU-sched
204− (!PREEMPT kernels). Nothing prevents this kthread from running
204+ the "p" for RCU-preempt (PREEMPTION kernels) and "s" for RCU-sched
205+ (!PREEMPTION kernels). Nothing prevents this kthread from running
205206 on the specified CPUs, but (1) the kthreads may be preempted
206207 between each callback, and (2) affinity or cgroups can be used
207208 to force the kthreads to run on whatever set of CPUs is desired.
kernel/rcu/Makefile+0−1
@@ -9,6 +9,5 @@ obj-$(CONFIG_TINY_SRCU) += srcutiny.o · 8 unmodified lines
99 obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o
1010 obj-$(CONFIG_RCU_PERF_TEST) += rcuperf.o
1111 obj-$(CONFIG_TREE_RCU) += tree.o
12−obj-$(CONFIG_PREEMPT_RCU) += tree.o
1312 obj-$(CONFIG_TINY_RCU) += tiny.o
1413 obj-$(CONFIG_RCU_NEED_SEGCBLIST) += rcu_segcblist.o
kernel/rcu/rcu.h+3−30
@@ -198,33 +198,6 @@ static inline void debug_rcu_head_unqueue(struct rcu_head *head) · 197 unmodified lines
198198 }
199199 #endif /* #else !CONFIG_DEBUG_OBJECTS_RCU_HEAD */
200200
201−void kfree(const void *);
202−
203−/*
204− * Reclaim the specified callback, either by invoking it (non-lazy case)
205− * or freeing it directly (lazy case). Return true if lazy, false otherwise.
206− */
207−static inline bool __rcu_reclaim(const char *rn, struct rcu_head *head)
208−{
209− rcu_callback_t f;
210− unsigned long offset = (unsigned long)head->func;
211−
212− rcu_lock_acquire(&rcu_callback_map);
213− if (__is_kfree_rcu_offset(offset)) {
214− trace_rcu_invoke_kfree_callback(rn, head, offset);
215− kfree((void *)head - offset);
216− rcu_lock_release(&rcu_callback_map);
217− return true;
218− } else {
219− trace_rcu_invoke_callback(rn, head);
220− f = head->func;
221− WRITE_ONCE(head->func, (rcu_callback_t)0L);
222− f(head);
223− rcu_lock_release(&rcu_callback_map);
224− return false;
225− }
226−}
227−
228201 #ifdef CONFIG_RCU_STALL_COMMON
229202
230203 extern int rcu_cpu_stall_ftrace_dump;
@@ -281,7 +254,7 @@ void rcu_test_sync_prims(void); · 50 unmodified lines
281254 */
282255 extern void resched_cpu(int cpu);
283256
284−#if defined(SRCU) || !defined(TINY_RCU)
257+#if defined(CONFIG_SRCU) || !defined(CONFIG_TINY_RCU)
285258
286259 #include <linux/rcu_node_tree.h>
287260
@@ -418,7 +391,7 @@ do { \ · 130 unmodified lines
418391 #define raw_lockdep_assert_held_rcu_node(p) \
419392 lockdep_assert_held(&ACCESS_PRIVATE(p, lock))
420393
421−#endif /* #if defined(SRCU) || !defined(TINY_RCU) */
394+#endif /* #if defined(CONFIG_SRCU) || !defined(CONFIG_TINY_RCU) */
422395
423396 #ifdef CONFIG_SRCU
424397 void srcu_init(void);
@@ -454,7 +427,7 @@ enum rcutorture_type { · 29 unmodified lines
454427 INVALID_RCU_FLAVOR
455428 };
456429
457−#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
430+#if defined(CONFIG_TREE_RCU)
458431 void rcutorture_get_gp_data(enum rcutorture_type test_type, int *flags,
459432 unsigned long *gp_seq);
460433 void do_trace_rcu_torture_read(const char *rcutorturename,
kernel/rcu/rcu_segcblist.c+3−22
@@ -20,14 +20,10 @@ void rcu_cblist_init(struct rcu_cblist *rclp) · 19 unmodified lines
2020 rclp->head = NULL;
2121 rclp->tail = &rclp->head;
2222 rclp->len = 0;
23− rclp->len_lazy = 0;
2423 }
2524
2625 /*
2726 * Enqueue an rcu_head structure onto the specified callback list.
28− * This function assumes that the callback is non-lazy because it
29− * is intended for use by no-CBs CPUs, which do not distinguish
30− * between lazy and non-lazy RCU callbacks.
3127 */
3228 void rcu_cblist_enqueue(struct rcu_cblist *rclp, struct rcu_head *rhp)
3329 {
@@ -54,7 +50,6 @@ void rcu_cblist_flush_enqueue(struct rcu_cblist *drclp, · 20 unmodified lines
5450 else
5551 drclp->tail = &drclp->head;
5652 drclp->len = srclp->len;
57− drclp->len_lazy = srclp->len_lazy;
5853 if (!rhp) {
5954 rcu_cblist_init(srclp);
6055 } else {
@@ -62,16 +57,12 @@ void rcu_cblist_flush_enqueue(struct rcu_cblist *drclp, · 1 unmodified line
6257 srclp->head = rhp;
6358 srclp->tail = &rhp->next;
6459 WRITE_ONCE(srclp->len, 1);
65− srclp->len_lazy = 0;
6660 }
6761 }
6862
6963 /*
7064 * Dequeue the oldest rcu_head structure from the specified callback
71− * list. This function assumes that the callback is non-lazy, but
72− * the caller can later invoke rcu_cblist_dequeued_lazy() if it
73− * finds otherwise (and if it cares about laziness). This allows
74− * different users to have different ways of determining laziness.
65+ * list.
7566 */
7667 struct rcu_head *rcu_cblist_dequeue(struct rcu_cblist *rclp)
7768 {
@@ -161,7 +152,6 @@ void rcu_segcblist_init(struct rcu_segcblist *rsclp) · 83 unmodified lines
161152 for (i = 0; i < RCU_CBLIST_NSEGS; i++)
162153 rsclp->tails[i] = &rsclp->head;
163154 rcu_segcblist_set_len(rsclp, 0);
164− rsclp->len_lazy = 0;
165155 rsclp->enabled = 1;
166156 }
167157
@@ -173,7 +163,6 @@ void rcu_segcblist_disable(struct rcu_segcblist *rsclp) · 5 unmodified lines
173163 {
174164 WARN_ON_ONCE(!rcu_segcblist_empty(rsclp));
175165 WARN_ON_ONCE(rcu_segcblist_n_cbs(rsclp));
176− WARN_ON_ONCE(rcu_segcblist_n_lazy_cbs(rsclp));
177166 rsclp->enabled = 0;
178167 }
179168
@@ -253,11 +242,9 @@ bool rcu_segcblist_nextgp(struct rcu_segcblist *rsclp, unsigned long *lp) · 73 unmodified lines
253242 * absolutely not OK for it to ever miss posting a callback.
254243 */
255244 void rcu_segcblist_enqueue(struct rcu_segcblist *rsclp,
256− struct rcu_head *rhp, bool lazy)
245+ struct rcu_head *rhp)
257246 {
258247 rcu_segcblist_inc_len(rsclp);
259− if (lazy)
260− rsclp->len_lazy++;
261248 smp_mb(); /* Ensure counts are updated before callback is enqueued. */
262249 rhp->next = NULL;
263250 WRITE_ONCE(*rsclp->tails[RCU_NEXT_TAIL], rhp);
@@ -275,15 +262,13 @@ void rcu_segcblist_enqueue(struct rcu_segcblist *rsclp, · 11 unmodified lines
275262 * period. You have been warned.
276263 */
277264 bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp,
278− struct rcu_head *rhp, bool lazy)
265+ struct rcu_head *rhp)
279266 {
280267 int i;
281268
282269 if (rcu_segcblist_n_cbs(rsclp) == 0)
283270 return false;
284271 rcu_segcblist_inc_len(rsclp);
285− if (lazy)
286− rsclp->len_lazy++;
287272 smp_mb(); /* Ensure counts are updated before callback is entrained. */
288273 rhp->next = NULL;
289274 for (i = RCU_NEXT_TAIL; i > RCU_DONE_TAIL; i--)
@@ -307,8 +292,6 @@ bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp, · 17 unmodified lines
307292 void rcu_segcblist_extract_count(struct rcu_segcblist *rsclp,
308293 struct rcu_cblist *rclp)
309294 {
310− rclp->len_lazy += rsclp->len_lazy;
311− rsclp->len_lazy = 0;
312295 rclp->len = rcu_segcblist_xchg_len(rsclp, 0);
313296 }
314297
@@ -361,9 +344,7 @@ void rcu_segcblist_extract_pend_cbs(struct rcu_segcblist *rsclp, · 46 unmodified lines
361344 void rcu_segcblist_insert_count(struct rcu_segcblist *rsclp,
362345 struct rcu_cblist *rclp)
363346 {
364− rsclp->len_lazy += rclp->len_lazy;
365347 rcu_segcblist_add_len(rsclp, rclp->len);
366− rclp->len_lazy = 0;
367348 rclp->len = 0;
368349 }
369350
kernel/rcu/rcu_segcblist.h+2−23
@@ -15,15 +15,6 @@ static inline long rcu_cblist_n_cbs(struct rcu_cblist *rclp) · 14 unmodified lines
1515 return READ_ONCE(rclp->len);
1616 }
1717
18−/*
19− * Account for the fact that a previously dequeued callback turned out
20− * to be marked as lazy.
21− */
22−static inline void rcu_cblist_dequeued_lazy(struct rcu_cblist *rclp)
23−{
24− rclp->len_lazy--;
25−}
26−
2718 void rcu_cblist_init(struct rcu_cblist *rclp);
2819 void rcu_cblist_enqueue(struct rcu_cblist *rclp, struct rcu_head *rhp);
2920 void rcu_cblist_flush_enqueue(struct rcu_cblist *drclp,
@@ -59,18 +50,6 @@ static inline long rcu_segcblist_n_cbs(struct rcu_segcblist *rsclp) · 29 unmodified lines
5950 #endif
6051 }
6152
62−/* Return number of lazy callbacks in segmented callback list. */
63−static inline long rcu_segcblist_n_lazy_cbs(struct rcu_segcblist *rsclp)
64−{
65− return rsclp->len_lazy;
66−}
67−
68−/* Return number of lazy callbacks in segmented callback list. */
69−static inline long rcu_segcblist_n_nonlazy_cbs(struct rcu_segcblist *rsclp)
70−{
71− return rcu_segcblist_n_cbs(rsclp) - rsclp->len_lazy;
72−}
73−
7453 /*
7554 * Is the specified rcu_segcblist enabled, for example, not corresponding
7655 * to an offline CPU?
@@ -106,9 +85,9 @@ struct rcu_head *rcu_segcblist_first_cb(struct rcu_segcblist *rsclp); · 29 unmodified lines
10685 struct rcu_head *rcu_segcblist_first_pend_cb(struct rcu_segcblist *rsclp);
10786 bool rcu_segcblist_nextgp(struct rcu_segcblist *rsclp, unsigned long *lp);
10887 void rcu_segcblist_enqueue(struct rcu_segcblist *rsclp,
109− struct rcu_head *rhp, bool lazy);
88+ struct rcu_head *rhp);
11089 bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp,
111− struct rcu_head *rhp, bool lazy);
90+ struct rcu_head *rhp);
11291 void rcu_segcblist_extract_count(struct rcu_segcblist *rsclp,
11392 struct rcu_cblist *rclp);
11493 void rcu_segcblist_extract_done_cbs(struct rcu_segcblist *rsclp,
kernel/rcu/rcuperf.c+165−8
@@ -86,6 +86,7 @@ torture_param(bool, shutdown, RCUPERF_SHUTDOWN, · 85 unmodified lines
8686 "Shutdown at end of performance tests.");
8787 torture_param(int, verbose, 1, "Enable verbose debugging printk()s");
8888 torture_param(int, writer_holdoff, 0, "Holdoff (us) between GPs, zero to disable");
89+torture_param(int, kfree_rcu_test, 0, "Do we run a kfree_rcu() perf test?");
8990
9091 static char *perf_type = "rcu";
9192 module_param(perf_type, charp, 0444);
@@ -105,8 +106,8 @@ static atomic_t n_rcu_perf_writer_finished; · 13 unmodified lines
105106 static wait_queue_head_t shutdown_wq;
106107 static u64 t_rcu_perf_writer_started;
107108 static u64 t_rcu_perf_writer_finished;
108−static unsigned long b_rcu_perf_writer_started;
109−static unsigned long b_rcu_perf_writer_finished;
109+static unsigned long b_rcu_gp_test_started;
110+static unsigned long b_rcu_gp_test_finished;
110111 static DEFINE_PER_CPU(atomic_t, n_async_inflight);
111112
112113 #define MAX_MEAS 10000
@@ -378,10 +379,10 @@ rcu_perf_writer(void *arg) · 265 unmodified lines
378379 if (atomic_inc_return(&n_rcu_perf_writer_started) >= nrealwriters) {
379380 t_rcu_perf_writer_started = t;
380381 if (gp_exp) {
381− b_rcu_perf_writer_started =
382+ b_rcu_gp_test_started =
382383 cur_ops->exp_completed() / 2;
383384 } else {
384− b_rcu_perf_writer_started = cur_ops->get_gp_seq();
385+ b_rcu_gp_test_started = cur_ops->get_gp_seq();
385386 }
386387 }
387388
@@ -429,10 +430,10 @@ retry: · 41 unmodified lines
429430 PERFOUT_STRING("Test complete");
430431 t_rcu_perf_writer_finished = t;
431432 if (gp_exp) {
432− b_rcu_perf_writer_finished =
433+ b_rcu_gp_test_finished =
433434 cur_ops->exp_completed() / 2;
434435 } else {
435− b_rcu_perf_writer_finished =
436+ b_rcu_gp_test_finished =
436437 cur_ops->get_gp_seq();
437438 }
438439 if (shutdown) {
@@ -515,8 +516,8 @@ rcu_perf_cleanup(void) · 76 unmodified lines
515516 t_rcu_perf_writer_finished -
516517 t_rcu_perf_writer_started,
517518 ngps,
518− rcuperf_seq_diff(b_rcu_perf_writer_finished,
519− b_rcu_perf_writer_started));
519+ rcuperf_seq_diff(b_rcu_gp_test_finished,
520+ b_rcu_gp_test_started));
520521 for (i = 0; i < nrealwriters; i++) {
521522 if (!writer_durations)
522523 break;
@@ -584,6 +585,159 @@ rcu_perf_shutdown(void *arg) · 61 unmodified lines
584585 return -EINVAL;
585586 }
586587
588+/*
589+ * kfree_rcu() performance tests: Start a kfree_rcu() loop on all CPUs for number
590+ * of iterations and measure total time and number of GP for all iterations to complete.
591+ */
592+
593+torture_param(int, kfree_nthreads, -1, "Number of threads running loops of kfree_rcu().");
594+torture_param(int, kfree_alloc_num, 8000, "Number of allocations and frees done in an iteration.");
595+torture_param(int, kfree_loops, 10, "Number of loops doing kfree_alloc_num allocations and frees.");
596+
597+static struct task_struct **kfree_reader_tasks;
598+static int kfree_nrealthreads;
599+static atomic_t n_kfree_perf_thread_started;
600+static atomic_t n_kfree_perf_thread_ended;
601+
602+struct kfree_obj {
603+ char kfree_obj[8];
604+ struct rcu_head rh;
605+};
606+
607+static int
608+kfree_perf_thread(void *arg)
609+{
610+ int i, loop = 0;
611+ long me = (long)arg;
612+ struct kfree_obj *alloc_ptr;
613+ u64 start_time, end_time;
614+
615+ VERBOSE_PERFOUT_STRING("kfree_perf_thread task started");
616+ set_cpus_allowed_ptr(current, cpumask_of(me % nr_cpu_ids));
617+ set_user_nice(current, MAX_NICE);
618+
619+ start_time = ktime_get_mono_fast_ns();
620+
621+ if (atomic_inc_return(&n_kfree_perf_thread_started) >= kfree_nrealthreads) {
622+ if (gp_exp)
623+ b_rcu_gp_test_started = cur_ops->exp_completed() / 2;
624+ else
625+ b_rcu_gp_test_started = cur_ops->get_gp_seq();
626+ }
627+
628+ do {
629+ for (i = 0; i < kfree_alloc_num; i++) {
630+ alloc_ptr = kmalloc(sizeof(struct kfree_obj), GFP_KERNEL);
631+ if (!alloc_ptr)
632+ return -ENOMEM;
633+
634+ kfree_rcu(alloc_ptr, rh);
635+ }
636+
637+ cond_resched();
638+ } while (!torture_must_stop() && ++loop < kfree_loops);
639+
640+ if (atomic_inc_return(&n_kfree_perf_thread_ended) >= kfree_nrealthreads) {
641+ end_time = ktime_get_mono_fast_ns();
642+
643+ if (gp_exp)
644+ b_rcu_gp_test_finished = cur_ops->exp_completed() / 2;
645+ else
646+ b_rcu_gp_test_finished = cur_ops->get_gp_seq();
647+
648+ pr_alert("Total time taken by all kfree'ers: %llu ns, loops: %d, batches: %ld\n",
649+ (unsigned long long)(end_time - start_time), kfree_loops,
650+ rcuperf_seq_diff(b_rcu_gp_test_finished, b_rcu_gp_test_started));
651+ if (shutdown) {
652+ smp_mb(); /* Assign before wake. */
653+ wake_up(&shutdown_wq);
654+ }
655+ }
656+
657+ torture_kthread_stopping("kfree_perf_thread");
658+ return 0;
659+}
660+
661+static void
662+kfree_perf_cleanup(void)
663+{
664+ int i;
665+
666+ if (torture_cleanup_begin())
667+ return;
668+
669+ if (kfree_reader_tasks) {
670+ for (i = 0; i < kfree_nrealthreads; i++)
671+ torture_stop_kthread(kfree_perf_thread,
672+ kfree_reader_tasks[i]);
673+ kfree(kfree_reader_tasks);
674+ }
675+
676+ torture_cleanup_end();
677+}
678+
679+/*
680+ * shutdown kthread. Just waits to be awakened, then shuts down system.
681+ */
682+static int
683+kfree_perf_shutdown(void *arg)
684+{
685+ do {
686+ wait_event(shutdown_wq,
687+ atomic_read(&n_kfree_perf_thread_ended) >=
688+ kfree_nrealthreads);
689+ } while (atomic_read(&n_kfree_perf_thread_ended) < kfree_nrealthreads);
690+
691+ smp_mb(); /* Wake before output. */
692+
693+ kfree_perf_cleanup();
694+ kernel_power_off();
695+ return -EINVAL;
696+}
697+
698+static int __init
699+kfree_perf_init(void)
700+{
701+ long i;
702+ int firsterr = 0;
703+
704+ kfree_nrealthreads = compute_real(kfree_nthreads);
705+ /* Start up the kthreads. */
706+ if (shutdown) {
707+ init_waitqueue_head(&shutdown_wq);
708+ firsterr = torture_create_kthread(kfree_perf_shutdown, NULL,
709+ shutdown_task);
710+ if (firsterr)
711+ goto unwind;
712+ schedule_timeout_uninterruptible(1);
713+ }
714+
715+ kfree_reader_tasks = kcalloc(kfree_nrealthreads, sizeof(kfree_reader_tasks[0]),
716+ GFP_KERNEL);
717+ if (kfree_reader_tasks == NULL) {
718+ firsterr = -ENOMEM;
719+ goto unwind;
720+ }
721+
722+ for (i = 0; i < kfree_nrealthreads; i++) {
723+ firsterr = torture_create_kthread(kfree_perf_thread, (void *)i,
724+ kfree_reader_tasks[i]);
725+ if (firsterr)
726+ goto unwind;
727+ }
728+
729+ while (atomic_read(&n_kfree_perf_thread_started) < kfree_nrealthreads)
730+ schedule_timeout_uninterruptible(1);
731+
732+ torture_init_end();
733+ return 0;
734+
735+unwind:
736+ torture_init_end();
737+ kfree_perf_cleanup();
738+ return firsterr;
739+}
740+
587741 static int __init
588742 rcu_perf_init(void)
589743 {
@@ -616,6 +770,9 @@ rcu_perf_init(void) · 26 unmodified lines
616770 if (cur_ops->init)
617771 cur_ops->init();
618772
773+ if (kfree_rcu_test)
774+ return kfree_perf_init();
775+
619776 nrealwriters = compute_real(nwriters);
620777 nrealreaders = compute_real(nreaders);
621778 atomic_set(&n_rcu_perf_reader_started, 0);
kernel/rcu/rcutorture.c+81−60
@@ -1661,43 +1661,52 @@ static void rcu_torture_fwd_prog_cb(struct rcu_head *rhp) · 1660 unmodified lines
16611661 struct rcu_fwd_cb {
16621662 struct rcu_head rh;
16631663 struct rcu_fwd_cb *rfc_next;
1664+ struct rcu_fwd *rfc_rfp;
16641665 int rfc_gps;
16651666 };
1666−static DEFINE_SPINLOCK(rcu_fwd_lock);
1667−static struct rcu_fwd_cb *rcu_fwd_cb_head;
1668−static struct rcu_fwd_cb **rcu_fwd_cb_tail = &rcu_fwd_cb_head;
1669−static long n_launders_cb;
1670−static unsigned long rcu_fwd_startat;
1671−static bool rcu_fwd_emergency_stop;
1667+
16721668 #define MAX_FWD_CB_JIFFIES (8 * HZ) /* Maximum CB test duration. */
16731669 #define MIN_FWD_CB_LAUNDERS 3 /* This many CB invocations to count. */
16741670 #define MIN_FWD_CBS_LAUNDERED 100 /* Number of counted CBs. */
16751671 #define FWD_CBS_HIST_DIV 10 /* Histogram buckets/second. */
1672+#define N_LAUNDERS_HIST (2 * MAX_FWD_CB_JIFFIES / (HZ / FWD_CBS_HIST_DIV))
1673+
16761674 struct rcu_launder_hist {
16771675 long n_launders;
16781676 unsigned long launder_gp_seq;
16791677 };
1680−#define N_LAUNDERS_HIST (2 * MAX_FWD_CB_JIFFIES / (HZ / FWD_CBS_HIST_DIV))
1681−static struct rcu_launder_hist n_launders_hist[N_LAUNDERS_HIST];
1682−static unsigned long rcu_launder_gp_seq_start;
16831678
1684−static void rcu_torture_fwd_cb_hist(void)
1679+struct rcu_fwd {
1680+ spinlock_t rcu_fwd_lock;
1681+ struct rcu_fwd_cb *rcu_fwd_cb_head;
1682+ struct rcu_fwd_cb **rcu_fwd_cb_tail;
1683+ long n_launders_cb;
1684+ unsigned long rcu_fwd_startat;
1685+ struct rcu_launder_hist n_launders_hist[N_LAUNDERS_HIST];
1686+ unsigned long rcu_launder_gp_seq_start;
1687+};
1688+
1689+struct rcu_fwd *rcu_fwds;
1690+bool rcu_fwd_emergency_stop;
1691+
1692+static void rcu_torture_fwd_cb_hist(struct rcu_fwd *rfp)
16851693 {
16861694 unsigned long gps;
16871695 unsigned long gps_old;
16881696 int i;
16891697 int j;
16901698
1691− for (i = ARRAY_SIZE(n_launders_hist) - 1; i > 0; i--)
1692− if (n_launders_hist[i].n_launders > 0)
1699+ for (i = ARRAY_SIZE(rfp->n_launders_hist) - 1; i > 0; i--)
1700+ if (rfp->n_launders_hist[i].n_launders > 0)
16931701 break;
16941702 pr_alert("%s: Callback-invocation histogram (duration %lu jiffies):",
1695− __func__, jiffies - rcu_fwd_startat);
1696− gps_old = rcu_launder_gp_seq_start;
1703+ __func__, jiffies - rfp->rcu_fwd_startat);
1704+ gps_old = rfp->rcu_launder_gp_seq_start;
16971705 for (j = 0; j <= i; j++) {
1698− gps = n_launders_hist[j].launder_gp_seq;
1706+ gps = rfp->n_launders_hist[j].launder_gp_seq;
16991707 pr_cont(" %ds/%d: %ld:%ld",
1700− j + 1, FWD_CBS_HIST_DIV, n_launders_hist[j].n_launders,
1708+ j + 1, FWD_CBS_HIST_DIV,
1709+ rfp->n_launders_hist[j].n_launders,
17011710 rcutorture_seq_diff(gps, gps_old));
17021711 gps_old = gps;
17031712 }
@@ -1711,26 +1720,27 @@ static void rcu_torture_fwd_cb_cr(struct rcu_head *rhp) · 7 unmodified lines
17111720 int i;
17121721 struct rcu_fwd_cb *rfcp = container_of(rhp, struct rcu_fwd_cb, rh);
17131722 struct rcu_fwd_cb **rfcpp;
1723+ struct rcu_fwd *rfp = rfcp->rfc_rfp;
17141724
17151725 rfcp->rfc_next = NULL;
17161726 rfcp->rfc_gps++;
1717− spin_lock_irqsave(&rcu_fwd_lock, flags);
1718− rfcpp = rcu_fwd_cb_tail;
1719− rcu_fwd_cb_tail = &rfcp->rfc_next;
1727+ spin_lock_irqsave(&rfp->rcu_fwd_lock, flags);
1728+ rfcpp = rfp->rcu_fwd_cb_tail;
1729+ rfp->rcu_fwd_cb_tail = &rfcp->rfc_next;
17201730 WRITE_ONCE(*rfcpp, rfcp);
1721− WRITE_ONCE(n_launders_cb, n_launders_cb + 1);
1722− i = ((jiffies - rcu_fwd_startat) / (HZ / FWD_CBS_HIST_DIV));
1723− if (i >= ARRAY_SIZE(n_launders_hist))
1724− i = ARRAY_SIZE(n_launders_hist) - 1;
1725− n_launders_hist[i].n_launders++;
1726− n_launders_hist[i].launder_gp_seq = cur_ops->get_gp_seq();
1727− spin_unlock_irqrestore(&rcu_fwd_lock, flags);
1731+ WRITE_ONCE(rfp->n_launders_cb, rfp->n_launders_cb + 1);
1732+ i = ((jiffies - rfp->rcu_fwd_startat) / (HZ / FWD_CBS_HIST_DIV));
1733+ if (i >= ARRAY_SIZE(rfp->n_launders_hist))
1734+ i = ARRAY_SIZE(rfp->n_launders_hist) - 1;
1735+ rfp->n_launders_hist[i].n_launders++;
1736+ rfp->n_launders_hist[i].launder_gp_seq = cur_ops->get_gp_seq();
1737+ spin_unlock_irqrestore(&rfp->rcu_fwd_lock, flags);
17281738 }
17291739
17301740 // Give the scheduler a chance, even on nohz_full CPUs.
17311741 static void rcu_torture_fwd_prog_cond_resched(unsigned long iter)
17321742 {
1733− if (IS_ENABLED(CONFIG_PREEMPT) && IS_ENABLED(CONFIG_NO_HZ_FULL)) {
1743+ if (IS_ENABLED(CONFIG_PREEMPTION) && IS_ENABLED(CONFIG_NO_HZ_FULL)) {
17341744 // Real call_rcu() floods hit userspace, so emulate that.
17351745 if (need_resched() || (iter & 0xfff))
17361746 schedule();
@@ -1744,23 +1754,23 @@ static void rcu_torture_fwd_prog_cond_resched(unsigned long iter) · 7 unmodified lines
17441754 * Free all callbacks on the rcu_fwd_cb_head list, either because the
17451755 * test is over or because we hit an OOM event.
17461756 */
1747−static unsigned long rcu_torture_fwd_prog_cbfree(void)
1757+static unsigned long rcu_torture_fwd_prog_cbfree(struct rcu_fwd *rfp)
17481758 {
17491759 unsigned long flags;
17501760 unsigned long freed = 0;
17511761 struct rcu_fwd_cb *rfcp;
17521762
17531763 for (;;) {
1754− spin_lock_irqsave(&rcu_fwd_lock, flags);
1755− rfcp = rcu_fwd_cb_head;
1764+ spin_lock_irqsave(&rfp->rcu_fwd_lock, flags);
1765+ rfcp = rfp->rcu_fwd_cb_head;
17561766 if (!rfcp) {
1757− spin_unlock_irqrestore(&rcu_fwd_lock, flags);
1767+ spin_unlock_irqrestore(&rfp->rcu_fwd_lock, flags);
17581768 break;
17591769 }
1760− rcu_fwd_cb_head = rfcp->rfc_next;
1761− if (!rcu_fwd_cb_head)
1762− rcu_fwd_cb_tail = &rcu_fwd_cb_head;
1763− spin_unlock_irqrestore(&rcu_fwd_lock, flags);
1770+ rfp->rcu_fwd_cb_head = rfcp->rfc_next;
1771+ if (!rfp->rcu_fwd_cb_head)
1772+ rfp->rcu_fwd_cb_tail = &rfp->rcu_fwd_cb_head;
1773+ spin_unlock_irqrestore(&rfp->rcu_fwd_lock, flags);
17641774 kfree(rfcp);
17651775 freed++;
17661776 rcu_torture_fwd_prog_cond_resched(freed);
@@ -1774,7 +1784,8 @@ static unsigned long rcu_torture_fwd_prog_cbfree(void) · 7 unmodified lines
17741784 }
17751785
17761786 /* Carry out need_resched()/cond_resched() forward-progress testing. */
1777−static void rcu_torture_fwd_prog_nr(int *tested, int *tested_tries)
1787+static void rcu_torture_fwd_prog_nr(struct rcu_fwd *rfp,
1788+ int *tested, int *tested_tries)
17781789 {
17791790 unsigned long cver;
17801791 unsigned long dur;
@@ -1804,8 +1815,8 @@ static void rcu_torture_fwd_prog_nr(int *tested, int *tested_tries) · 23 unmodified lines
18041815 sd = cur_ops->stall_dur() + 1;
18051816 sd4 = (sd + fwd_progress_div - 1) / fwd_progress_div;
18061817 dur = sd4 + torture_random(&trs) % (sd - sd4);
1807− WRITE_ONCE(rcu_fwd_startat, jiffies);
1808− stopat = rcu_fwd_startat + dur;
1818+ WRITE_ONCE(rfp->rcu_fwd_startat, jiffies);
1819+ stopat = rfp->rcu_fwd_startat + dur;
18091820 while (time_before(jiffies, stopat) &&
18101821 !shutdown_time_arrived() &&
18111822 !READ_ONCE(rcu_fwd_emergency_stop) && !torture_must_stop()) {
@@ -1840,7 +1851,7 @@ static void rcu_torture_fwd_prog_nr(int *tested, int *tested_tries) · 28 unmodified lines
18401851 }
18411852
18421853 /* Carry out call_rcu() forward-progress testing. */
1843−static void rcu_torture_fwd_prog_cr(void)
1854+static void rcu_torture_fwd_prog_cr(struct rcu_fwd *rfp)
18441855 {
18451856 unsigned long cver;
18461857 unsigned long flags;
@@ -1864,23 +1875,23 @@ static void rcu_torture_fwd_prog_cr(void) · 17 unmodified lines
18641875 /* Loop continuously posting RCU callbacks. */
18651876 WRITE_ONCE(rcu_fwd_cb_nodelay, true);
18661877 cur_ops->sync(); /* Later readers see above write. */
1867− WRITE_ONCE(rcu_fwd_startat, jiffies);
1868− stopat = rcu_fwd_startat + MAX_FWD_CB_JIFFIES;
1878+ WRITE_ONCE(rfp->rcu_fwd_startat, jiffies);
1879+ stopat = rfp->rcu_fwd_startat + MAX_FWD_CB_JIFFIES;
18691880 n_launders = 0;
1870− n_launders_cb = 0;
1881+ rfp->n_launders_cb = 0; // Hoist initialization for multi-kthread
18711882 n_launders_sa = 0;
18721883 n_max_cbs = 0;
18731884 n_max_gps = 0;
1874− for (i = 0; i < ARRAY_SIZE(n_launders_hist); i++)
1875− n_launders_hist[i].n_launders = 0;
1885+ for (i = 0; i < ARRAY_SIZE(rfp->n_launders_hist); i++)
1886+ rfp->n_launders_hist[i].n_launders = 0;
18761887 cver = READ_ONCE(rcu_torture_current_version);
18771888 gps = cur_ops->get_gp_seq();
1878− rcu_launder_gp_seq_start = gps;
1889+ rfp->rcu_launder_gp_seq_start = gps;
18791890 tick_dep_set_task(current, TICK_DEP_BIT_RCU);
18801891 while (time_before(jiffies, stopat) &&
18811892 !shutdown_time_arrived() &&
18821893 !READ_ONCE(rcu_fwd_emergency_stop) && !torture_must_stop()) {
1883− rfcp = READ_ONCE(rcu_fwd_cb_head);
1894+ rfcp = READ_ONCE(rfp->rcu_fwd_cb_head);
18841895 rfcpn = NULL;
18851896 if (rfcp)
18861897 rfcpn = READ_ONCE(rfcp->rfc_next);
@@ -1888,7 +1899,7 @@ static void rcu_torture_fwd_prog_cr(void) · 1 unmodified line
18881899 if (rfcp->rfc_gps >= MIN_FWD_CB_LAUNDERS &&
18891900 ++n_max_gps >= MIN_FWD_CBS_LAUNDERED)
18901901 break;
1891− rcu_fwd_cb_head = rfcpn;
1902+ rfp->rcu_fwd_cb_head = rfcpn;
18921903 n_launders++;
18931904 n_launders_sa++;
18941905 } else {
@@ -1900,6 +1911,7 @@ static void rcu_torture_fwd_prog_cr(void) · 5 unmodified lines
19001911 n_max_cbs++;
19011912 n_launders_sa = 0;
19021913 rfcp->rfc_gps = 0;
1914+ rfcp->rfc_rfp = rfp;
19031915 }
19041916 cur_ops->call(&rfcp->rh, rcu_torture_fwd_cb_cr);
19051917 rcu_torture_fwd_prog_cond_resched(n_launders + n_max_cbs);
@@ -1910,22 +1922,22 @@ static void rcu_torture_fwd_prog_cr(void) · 4 unmodified lines
19101922 }
19111923 }
19121924 stoppedat = jiffies;
1913− n_launders_cb_snap = READ_ONCE(n_launders_cb);
1925+ n_launders_cb_snap = READ_ONCE(rfp->n_launders_cb);
19141926 cver = READ_ONCE(rcu_torture_current_version) - cver;
19151927 gps = rcutorture_seq_diff(cur_ops->get_gp_seq(), gps);
19161928 cur_ops->cb_barrier(); /* Wait for callbacks to be invoked. */
1917− (void)rcu_torture_fwd_prog_cbfree();
1929+ (void)rcu_torture_fwd_prog_cbfree(rfp);
19181930
19191931 if (!torture_must_stop() && !READ_ONCE(rcu_fwd_emergency_stop) &&
19201932 !shutdown_time_arrived()) {
19211933 WARN_ON(n_max_gps < MIN_FWD_CBS_LAUNDERED);
19221934 pr_alert("%s Duration %lu barrier: %lu pending %ld n_launders: %ld n_launders_sa: %ld n_max_gps: %ld n_max_cbs: %ld cver %ld gps %ld\n",
19231935 __func__,
1924− stoppedat - rcu_fwd_startat, jiffies - stoppedat,
1936+ stoppedat - rfp->rcu_fwd_startat, jiffies - stoppedat,
19251937 n_launders + n_max_cbs - n_launders_cb_snap,
19261938 n_launders, n_launders_sa,
19271939 n_max_gps, n_max_cbs, cver, gps);
1928− rcu_torture_fwd_cb_hist();
1940+ rcu_torture_fwd_cb_hist(rfp);
19291941 }
19301942 schedule_timeout_uninterruptible(HZ); /* Let CBs drain. */
19311943 tick_dep_clear_task(current, TICK_DEP_BIT_RCU);
@@ -1940,20 +1952,22 @@ static void rcu_torture_fwd_prog_cr(void) · 8 unmodified lines
19401952 static int rcutorture_oom_notify(struct notifier_block *self,
19411953 unsigned long notused, void *nfreed)
19421954 {
1955+ struct rcu_fwd *rfp = rcu_fwds;
1956+
19431957 WARN(1, "%s invoked upon OOM during forward-progress testing.\n",
19441958 __func__);
1945− rcu_torture_fwd_cb_hist();
1946− rcu_fwd_progress_check(1 + (jiffies - READ_ONCE(rcu_fwd_startat)) / 2);
1959+ rcu_torture_fwd_cb_hist(rfp);
1960+ rcu_fwd_progress_check(1 + (jiffies - READ_ONCE(rfp->rcu_fwd_startat)) / 2);
19471961 WRITE_ONCE(rcu_fwd_emergency_stop, true);
19481962 smp_mb(); /* Emergency stop before free and wait to avoid hangs. */
19491963 pr_info("%s: Freed %lu RCU callbacks.\n",
1950− __func__, rcu_torture_fwd_prog_cbfree());
1964+ __func__, rcu_torture_fwd_prog_cbfree(rfp));
19511965 rcu_barrier();
19521966 pr_info("%s: Freed %lu RCU callbacks.\n",
1953− __func__, rcu_torture_fwd_prog_cbfree());
1967+ __func__, rcu_torture_fwd_prog_cbfree(rfp));
19541968 rcu_barrier();
19551969 pr_info("%s: Freed %lu RCU callbacks.\n",
1956− __func__, rcu_torture_fwd_prog_cbfree());
1970+ __func__, rcu_torture_fwd_prog_cbfree(rfp));
19571971 smp_mb(); /* Frees before return to avoid redoing OOM. */
19581972 (*(unsigned long *)nfreed)++; /* Forward progress CBs freed! */
19591973 pr_info("%s returning after OOM processing.\n", __func__);
@@ -1967,6 +1981,7 @@ static struct notifier_block rcutorture_oom_nb = { · 7 unmodified lines
19671981 /* Carry out grace-period forward-progress testing. */
19681982 static int rcu_torture_fwd_prog(void *args)
19691983 {
1984+ struct rcu_fwd *rfp = args;
19701985 int tested = 0;
19711986 int tested_tries = 0;
19721987
@@ -1978,8 +1993,8 @@ static int rcu_torture_fwd_prog(void *args) · 5 unmodified lines
19781993 schedule_timeout_interruptible(fwd_progress_holdoff * HZ);
19791994 WRITE_ONCE(rcu_fwd_emergency_stop, false);
19801995 register_oom_notifier(&rcutorture_oom_nb);
1981− rcu_torture_fwd_prog_nr(&tested, &tested_tries);
1982− rcu_torture_fwd_prog_cr();
1996+ rcu_torture_fwd_prog_nr(rfp, &tested, &tested_tries);
1997+ rcu_torture_fwd_prog_cr(rfp);
19831998 unregister_oom_notifier(&rcutorture_oom_nb);
19841999
19852000 /* Avoid slow periods, better to test when busy. */
@@ -1995,6 +2010,8 @@ static int rcu_torture_fwd_prog(void *args) · 9 unmodified lines
19952010 /* If forward-progress checking is requested and feasible, spawn the thread. */
19962011 static int __init rcu_torture_fwd_prog_init(void)
19972012 {
2013+ struct rcu_fwd *rfp;
2014+
19982015 if (!fwd_progress)
19992016 return 0; /* Not requested, so don't do it. */
20002017 if (!cur_ops->stall_dur || cur_ops->stall_dur() <= 0 ||
@@ -2013,8 +2030,12 @@ static int __init rcu_torture_fwd_prog_init(void) · 12 unmodified lines
20132030 fwd_progress_holdoff = 1;
20142031 if (fwd_progress_div <= 0)
20152032 fwd_progress_div = 4;
2016− return torture_create_kthread(rcu_torture_fwd_prog,
2017− NULL, fwd_prog_task);
2033+ rfp = kzalloc(sizeof(*rfp), GFP_KERNEL);
2034+ if (!rfp)
2035+ return -ENOMEM;
2036+ spin_lock_init(&rfp->rcu_fwd_lock);
2037+ rfp->rcu_fwd_cb_tail = &rfp->rcu_fwd_cb_head;
2038+ return torture_create_kthread(rcu_torture_fwd_prog, rfp, fwd_prog_task);
20182039 }
20192040
20202041 /* Callback function for RCU barrier testing. */
kernel/rcu/srcutiny.c+1−1
@@ -103,7 +103,7 @@ EXPORT_SYMBOL_GPL(__srcu_read_unlock); · 102 unmodified lines
103103
104104 /*
105105 * Workqueue handler to drive one grace period and invoke any callbacks
106− * that become ready as a result. Single-CPU and !PREEMPT operation
106+ * that become ready as a result. Single-CPU and !PREEMPTION operation
107107 * means that we get away with murder on synchronization. ;-)
108108 */
109109 void srcu_drive_gp(struct work_struct *wp)
kernel/rcu/srcutree.c+6−5
@@ -530,7 +530,7 @@ static void srcu_gp_end(struct srcu_struct *ssp) · 529 unmodified lines
530530 idx = rcu_seq_state(ssp->srcu_gp_seq);
531531 WARN_ON_ONCE(idx != SRCU_STATE_SCAN2);
532532 cbdelay = srcu_get_delay(ssp);
533− ssp->srcu_last_gp_end = ktime_get_mono_fast_ns();
533+ WRITE_ONCE(ssp->srcu_last_gp_end, ktime_get_mono_fast_ns());
534534 rcu_seq_end(&ssp->srcu_gp_seq);
535535 gpseq = rcu_seq_current(&ssp->srcu_gp_seq);
536536 if (ULONG_CMP_LT(ssp->srcu_gp_seq_needed_exp, gpseq))
@@ -762,6 +762,7 @@ static bool srcu_might_be_idle(struct srcu_struct *ssp) · 225 unmodified lines
762762 unsigned long flags;
763763 struct srcu_data *sdp;
764764 unsigned long t;
765+ unsigned long tlast;
765766
766767 /* If the local srcu_data structure has callbacks, not idle. */
767768 local_irq_save(flags);
@@ -780,9 +781,9 @@ static bool srcu_might_be_idle(struct srcu_struct *ssp) · 12 unmodified lines
780781
781782 /* First, see if enough time has passed since the last GP. */
782783 t = ktime_get_mono_fast_ns();
784+ tlast = READ_ONCE(ssp->srcu_last_gp_end);
783785 if (exp_holdoff == 0 ||
784− time_in_range_open(t, ssp->srcu_last_gp_end,
785− ssp->srcu_last_gp_end + exp_holdoff))
786+ time_in_range_open(t, tlast, tlast + exp_holdoff))
786787 return false; /* Too soon after last GP. */
787788
788789 /* Next, check for probable idleness. */
@@ -853,7 +854,7 @@ static void __call_srcu(struct srcu_struct *ssp, struct rcu_head *rhp, · 64 unmodified lines
853854 local_irq_save(flags);
854855 sdp = this_cpu_ptr(ssp->sda);
855856 spin_lock_rcu_node(sdp);
856− rcu_segcblist_enqueue(&sdp->srcu_cblist, rhp, false);
857+ rcu_segcblist_enqueue(&sdp->srcu_cblist, rhp);
857858 rcu_segcblist_advance(&sdp->srcu_cblist,
858859 rcu_seq_current(&ssp->srcu_gp_seq));
859860 s = rcu_seq_snap(&ssp->srcu_gp_seq);
@@ -1052,7 +1053,7 @@ void srcu_barrier(struct srcu_struct *ssp) · 192 unmodified lines
10521053 sdp->srcu_barrier_head.func = srcu_barrier_cb;
10531054 debug_rcu_head_queue(&sdp->srcu_barrier_head);
10541055 if (!rcu_segcblist_entrain(&sdp->srcu_cblist,
1055− &sdp->srcu_barrier_head, 0)) {
1056+ &sdp->srcu_barrier_head)) {
10561057 debug_rcu_head_unqueue(&sdp->srcu_barrier_head);
10571058 atomic_dec(&ssp->srcu_barrier_cpu_cnt);
10581059 }
kernel/rcu/tiny.c+27−1
@@ -22,6 +22,7 @@ · 21 unmodified lines
2222 #include <linux/time.h>
2323 #include <linux/cpu.h>
2424 #include <linux/prefetch.h>
25+#include <linux/slab.h>
2526
2627 #include "rcu.h"
2728
@@ -73,6 +74,31 @@ void rcu_sched_clock_irq(int user) · 45 unmodified lines
7374 }
7475 }
7576
77+/*
78+ * Reclaim the specified callback, either by invoking it for non-kfree cases or
79+ * freeing it directly (for kfree). Return true if kfreeing, false otherwise.
80+ */
81+static inline bool rcu_reclaim_tiny(struct rcu_head *head)
82+{
83+ rcu_callback_t f;
84+ unsigned long offset = (unsigned long)head->func;
85+
86+ rcu_lock_acquire(&rcu_callback_map);
87+ if (__is_kfree_rcu_offset(offset)) {
88+ trace_rcu_invoke_kfree_callback("", head, offset);
89+ kfree((void *)head - offset);
90+ rcu_lock_release(&rcu_callback_map);
91+ return true;
92+ }
93+
94+ trace_rcu_invoke_callback("", head);
95+ f = head->func;
96+ WRITE_ONCE(head->func, (rcu_callback_t)0L);
97+ f(head);
98+ rcu_lock_release(&rcu_callback_map);
99+ return false;
100+}
101+
76102 /* Invoke the RCU callbacks whose grace period has elapsed. */
77103 static __latent_entropy void rcu_process_callbacks(struct softirq_action *unused)
78104 {
@@ -100,7 +126,7 @@ static __latent_entropy void rcu_process_callbacks(struct softirq_action *unused · 21 unmodified lines
100126 prefetch(next);
101127 debug_rcu_head_unqueue(list);
102128 local_bh_disable();
103− __rcu_reclaim("", list);
129+ rcu_reclaim_tiny(list);
104130 local_bh_enable();
105131 list = next;
106132 }
kernel/rcu/tree.c+272−52
@@ -43,7 +43,6 @@ · 42 unmodified lines
4343 #include <uapi/linux/sched/types.h>
4444 #include <linux/prefetch.h>
4545 #include <linux/delay.h>
46−#include <linux/stop_machine.h>
4746 #include <linux/random.h>
4847 #include <linux/trace_events.h>
4948 #include <linux/suspend.h>
@@ -55,6 +54,7 @@ · 5 unmodified lines
5554 #include <linux/oom.h>
5655 #include <linux/smpboot.h>
5756 #include <linux/jiffies.h>
57+#include <linux/slab.h>
5858 #include <linux/sched/isolation.h>
5959 #include <linux/sched/clock.h>
6060 #include "../time/tick-internal.h"
@@ -84,7 +84,7 @@ static DEFINE_PER_CPU_SHARED_ALIGNED(struct rcu_data, rcu_data) = { · 23 unmodified lines
8484 .dynticks_nmi_nesting = DYNTICK_IRQ_NONIDLE,
8585 .dynticks = ATOMIC_INIT(RCU_DYNTICK_CTRL_CTR),
8686 };
87−struct rcu_state rcu_state = {
87+static struct rcu_state rcu_state = {
8888 .level = { &rcu_state.node[0] },
8989 .gp_state = RCU_GP_IDLE,
9090 .gp_seq = (0UL - 300UL) << RCU_SEQ_CTR_SHIFT,
@@ -188,7 +188,7 @@ EXPORT_SYMBOL_GPL(rcu_get_gp_kthreads_prio); · 97 unmodified lines
188188 * held, but the bit corresponding to the current CPU will be stable
189189 * in most contexts.
190190 */
191−unsigned long rcu_rnp_online_cpus(struct rcu_node *rnp)
191+static unsigned long rcu_rnp_online_cpus(struct rcu_node *rnp)
192192 {
193193 return READ_ONCE(rnp->qsmaskinitnext);
194194 }
@@ -294,7 +294,7 @@ static void rcu_dynticks_eqs_online(void) · 99 unmodified lines
294294 *
295295 * No ordering, as we are sampling CPU-local information.
296296 */
297−bool rcu_dynticks_curr_cpu_in_eqs(void)
297+static bool rcu_dynticks_curr_cpu_in_eqs(void)
298298 {
299299 struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
300300
@@ -305,7 +305,7 @@ bool rcu_dynticks_curr_cpu_in_eqs(void) · 4 unmodified lines
305305 * Snapshot the ->dynticks counter with full ordering so as to allow
306306 * stable comparison of this counter with past and future snapshots.
307307 */
308−int rcu_dynticks_snap(struct rcu_data *rdp)
308+static int rcu_dynticks_snap(struct rcu_data *rdp)
309309 {
310310 int snap = atomic_add_return(0, &rdp->dynticks);
311311
@@ -528,16 +528,6 @@ static struct rcu_node *rcu_get_root(void) · 216 unmodified lines
528528 return &rcu_state.node[0];
529529 }
530530
531−/*
532− * Convert a ->gp_state value to a character string.
533− */
534−static const char *gp_state_getname(short gs)
535−{
536− if (gs < 0 || gs >= ARRAY_SIZE(gp_state_names))
537− return "???";
538− return gp_state_names[gs];
539−}
540−
541531 /*
542532 * Send along grace-period-related data for rcutorture diagnostics.
543533 */
@@ -577,7 +567,7 @@ static void rcu_eqs_enter(bool user) · 33 unmodified lines
577567 }
578568
579569 lockdep_assert_irqs_disabled();
580− trace_rcu_dyntick(TPS("Start"), rdp->dynticks_nesting, 0, rdp->dynticks);
570+ trace_rcu_dyntick(TPS("Start"), rdp->dynticks_nesting, 0, atomic_read(&rdp->dynticks));
581571 WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && !user && !is_idle_task(current));
582572 rdp = this_cpu_ptr(&rcu_data);
583573 do_nocb_deferred_wakeup(rdp);
@@ -650,14 +640,15 @@ static __always_inline void rcu_nmi_exit_common(bool irq) · 66 unmodified lines
650640 * leave it in non-RCU-idle state.
651641 */
652642 if (rdp->dynticks_nmi_nesting != 1) {
653− trace_rcu_dyntick(TPS("--="), rdp->dynticks_nmi_nesting, rdp->dynticks_nmi_nesting - 2, rdp->dynticks);
643+ trace_rcu_dyntick(TPS("--="), rdp->dynticks_nmi_nesting, rdp->dynticks_nmi_nesting - 2,
644+ atomic_read(&rdp->dynticks));
654645 WRITE_ONCE(rdp->dynticks_nmi_nesting, /* No store tearing. */
655646 rdp->dynticks_nmi_nesting - 2);
656647 return;
657648 }
658649
659650 /* This NMI interrupted an RCU-idle CPU, restore RCU-idleness. */
660− trace_rcu_dyntick(TPS("Startirq"), rdp->dynticks_nmi_nesting, 0, rdp->dynticks);
651+ trace_rcu_dyntick(TPS("Startirq"), rdp->dynticks_nmi_nesting, 0, atomic_read(&rdp->dynticks));
661652 WRITE_ONCE(rdp->dynticks_nmi_nesting, 0); /* Avoid store tearing. */
662653
663654 if (irq)
@@ -744,7 +735,7 @@ static void rcu_eqs_exit(bool user) · 80 unmodified lines
744735 rcu_dynticks_task_exit();
745736 rcu_dynticks_eqs_exit();
746737 rcu_cleanup_after_idle();
747− trace_rcu_dyntick(TPS("End"), rdp->dynticks_nesting, 1, rdp->dynticks);
738+ trace_rcu_dyntick(TPS("End"), rdp->dynticks_nesting, 1, atomic_read(&rdp->dynticks));
748739 WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && !user && !is_idle_task(current));
749740 WRITE_ONCE(rdp->dynticks_nesting, 1);
750741 WARN_ON_ONCE(rdp->dynticks_nmi_nesting);
@@ -800,8 +791,8 @@ void rcu_user_exit(void) · 49 unmodified lines
800791 */
801792 static __always_inline void rcu_nmi_enter_common(bool irq)
802793 {
803− struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
804794 long incby = 2;
795+ struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
805796
806797 /* Complain about underflow. */
807798 WARN_ON_ONCE(rdp->dynticks_nmi_nesting < 0);
@@ -828,12 +819,17 @@ static __always_inline void rcu_nmi_enter_common(bool irq) · 20 unmodified lines
828819 } else if (tick_nohz_full_cpu(rdp->cpu) &&
829820 rdp->dynticks_nmi_nesting == DYNTICK_IRQ_NONIDLE &&
830821 READ_ONCE(rdp->rcu_urgent_qs) && !rdp->rcu_forced_tick) {
831− rdp->rcu_forced_tick = true;
832− tick_dep_set_cpu(rdp->cpu, TICK_DEP_BIT_RCU);
822+ raw_spin_lock_rcu_node(rdp->mynode);
823+ // Recheck under lock.
824+ if (rdp->rcu_urgent_qs && !rdp->rcu_forced_tick) {
825+ rdp->rcu_forced_tick = true;
826+ tick_dep_set_cpu(rdp->cpu, TICK_DEP_BIT_RCU);
827+ }
828+ raw_spin_unlock_rcu_node(rdp->mynode);
833829 }
834830 trace_rcu_dyntick(incby == 1 ? TPS("Endirq") : TPS("++="),
835831 rdp->dynticks_nmi_nesting,
836− rdp->dynticks_nmi_nesting + incby, rdp->dynticks);
832+ rdp->dynticks_nmi_nesting + incby, atomic_read(&rdp->dynticks));
837833 WRITE_ONCE(rdp->dynticks_nmi_nesting, /* Prevent store tearing. */
838834 rdp->dynticks_nmi_nesting + incby);
839835 barrier();
@@ -898,6 +894,7 @@ void rcu_irq_enter_irqson(void) · 58 unmodified lines
898894 */
899895 static void rcu_disable_urgency_upon_qs(struct rcu_data *rdp)
900896 {
897+ raw_lockdep_assert_held_rcu_node(rdp->mynode);
901898 WRITE_ONCE(rdp->rcu_urgent_qs, false);
902899 WRITE_ONCE(rdp->rcu_need_heavy_qs, false);
903900 if (tick_nohz_full_cpu(rdp->cpu) && rdp->rcu_forced_tick) {
@@ -1934,7 +1931,7 @@ rcu_report_unblock_qs_rnp(struct rcu_node *rnp, unsigned long flags) · 1030 unmodified lines
19341931 struct rcu_node *rnp_p;
19351932
19361933 raw_lockdep_assert_held_rcu_node(rnp);
1937− if (WARN_ON_ONCE(!IS_ENABLED(CONFIG_PREEMPTION)) ||
1934+ if (WARN_ON_ONCE(!IS_ENABLED(CONFIG_PREEMPT_RCU)) ||
19381935 WARN_ON_ONCE(rcu_preempt_blocked_readers_cgp(rnp)) ||
19391936 rnp->qsmask != 0) {
19401937 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
@@ -2146,7 +2143,6 @@ static void rcu_do_batch(struct rcu_data *rdp) · 205 unmodified lines
21462143 /* If no callbacks are ready, just return. */
21472144 if (!rcu_segcblist_ready_cbs(&rdp->cblist)) {
21482145 trace_rcu_batch_start(rcu_state.name,
2149− rcu_segcblist_n_lazy_cbs(&rdp->cblist),
21502146 rcu_segcblist_n_cbs(&rdp->cblist), 0);
21512147 trace_rcu_batch_end(rcu_state.name, 0,
21522148 !rcu_segcblist_empty(&rdp->cblist),
@@ -2168,7 +2164,6 @@ static void rcu_do_batch(struct rcu_data *rdp) · 15 unmodified lines
21682164 if (unlikely(bl > 100))
21692165 tlimit = local_clock() + rcu_resched_ns;
21702166 trace_rcu_batch_start(rcu_state.name,
2171− rcu_segcblist_n_lazy_cbs(&rdp->cblist),
21722167 rcu_segcblist_n_cbs(&rdp->cblist), bl);
21732168 rcu_segcblist_extract_done_cbs(&rdp->cblist, &rcl);
21742169 if (offloaded)
@@ -2179,9 +2174,19 @@ static void rcu_do_batch(struct rcu_data *rdp) · 4 unmodified lines
21792174 tick_dep_set_task(current, TICK_DEP_BIT_RCU);
21802175 rhp = rcu_cblist_dequeue(&rcl);
21812176 for (; rhp; rhp = rcu_cblist_dequeue(&rcl)) {
2177+ rcu_callback_t f;
2178+
21822179 debug_rcu_head_unqueue(rhp);
2183− if (__rcu_reclaim(rcu_state.name, rhp))
2184− rcu_cblist_dequeued_lazy(&rcl);
2180+
2181+ rcu_lock_acquire(&rcu_callback_map);
2182+ trace_rcu_invoke_callback(rcu_state.name, rhp);
2183+
2184+ f = rhp->func;
2185+ WRITE_ONCE(rhp->func, (rcu_callback_t)0L);
2186+ f(rhp);
2187+
2188+ rcu_lock_release(&rcu_callback_map);
2189+
21852190 /*
21862191 * Stop only if limit reached and CPU has something to do.
21872192 * Note: The rcl structure counts down from zero.
@@ -2294,7 +2299,7 @@ static void force_qs_rnp(int (*f)(struct rcu_data *rdp)) · 106 unmodified lines
22942299 mask = 0;
22952300 raw_spin_lock_irqsave_rcu_node(rnp, flags);
22962301 if (rnp->qsmask == 0) {
2297− if (!IS_ENABLED(CONFIG_PREEMPTION) ||
2302+ if (!IS_ENABLED(CONFIG_PREEMPT_RCU) ||
22982303 rcu_preempt_blocked_readers_cgp(rnp)) {
22992304 /*
23002305 * No point in scanning bits because they
@@ -2308,14 +2313,11 @@ static void force_qs_rnp(int (*f)(struct rcu_data *rdp)) · 7 unmodified lines
23082313 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
23092314 continue;
23102315 }
2311− for_each_leaf_node_possible_cpu(rnp, cpu) {
2312− unsigned long bit = leaf_node_cpu_bit(rnp, cpu);
2313− if ((rnp->qsmask & bit) != 0) {
2314− rdp = per_cpu_ptr(&rcu_data, cpu);
2315− if (f(rdp)) {
2316− mask |= bit;
2317− rcu_disable_urgency_upon_qs(rdp);
2318− }
2316+ for_each_leaf_node_cpu_mask(rnp, cpu, rnp->qsmask) {
2317+ rdp = per_cpu_ptr(&rcu_data, cpu);
2318+ if (f(rdp)) {
2319+ mask |= rdp->grpmask;
2320+ rcu_disable_urgency_upon_qs(rdp);
23192321 }
23202322 }
23212323 if (mask != 0) {
@@ -2474,8 +2476,8 @@ static void rcu_cpu_kthread(unsigned int cpu) · 152 unmodified lines
24742476 char work, *workp = this_cpu_ptr(&rcu_data.rcu_cpu_has_work);
24752477 int spincnt;
24762478
2479+ trace_rcu_utilization(TPS("Start CPU kthread@rcu_run"));
24772480 for (spincnt = 0; spincnt < 10; spincnt++) {
2478− trace_rcu_utilization(TPS("Start CPU kthread@rcu_wait"));
24792481 local_bh_disable();
24802482 *statusp = RCU_KTHREAD_RUNNING;
24812483 local_irq_disable();
@@ -2583,7 +2585,7 @@ static void rcu_leak_callback(struct rcu_head *rhp) · 101 unmodified lines
25832585 * is expected to specify a CPU.
25842586 */
25852587 static void
2586−__call_rcu(struct rcu_head *head, rcu_callback_t func, bool lazy)
2588+__call_rcu(struct rcu_head *head, rcu_callback_t func)
25872589 {
25882590 unsigned long flags;
25892591 struct rcu_data *rdp;
@@ -2618,18 +2620,17 @@ __call_rcu(struct rcu_head *head, rcu_callback_t func, bool lazy) · 28 unmodified lines
26182620 if (rcu_segcblist_empty(&rdp->cblist))
26192621 rcu_segcblist_init(&rdp->cblist);
26202622 }
2623+
26212624 if (rcu_nocb_try_bypass(rdp, head, &was_alldone, flags))
26222625 return; // Enqueued onto ->nocb_bypass, so just leave.
26232626 /* If we get here, rcu_nocb_try_bypass() acquired ->nocb_lock. */
2624− rcu_segcblist_enqueue(&rdp->cblist, head, lazy);
2627+ rcu_segcblist_enqueue(&rdp->cblist, head);
26252628 if (__is_kfree_rcu_offset((unsigned long)func))
26262629 trace_rcu_kfree_callback(rcu_state.name, head,
26272630 (unsigned long)func,
2628− rcu_segcblist_n_lazy_cbs(&rdp->cblist),
26292631 rcu_segcblist_n_cbs(&rdp->cblist));
26302632 else
26312633 trace_rcu_callback(rcu_state.name, head,
2632− rcu_segcblist_n_lazy_cbs(&rdp->cblist),
26332634 rcu_segcblist_n_cbs(&rdp->cblist));
26342635
26352636 /* Go handle any RCU core processing required. */
@@ -2679,28 +2680,230 @@ __call_rcu(struct rcu_head *head, rcu_callback_t func, bool lazy) · 43 unmodified lines
26792680 */
26802681 void call_rcu(struct rcu_head *head, rcu_callback_t func)
26812682 {
2682− __call_rcu(head, func, 0);
2683+ __call_rcu(head, func);
26832684 }
26842685 EXPORT_SYMBOL_GPL(call_rcu);
26852686
2687+
2688+/* Maximum number of jiffies to wait before draining a batch. */
2689+#define KFREE_DRAIN_JIFFIES (HZ / 50)
2690+#define KFREE_N_BATCHES 2
2691+
2692+/**
2693+ * struct kfree_rcu_cpu_work - single batch of kfree_rcu() requests
2694+ * @rcu_work: Let queue_rcu_work() invoke workqueue handler after grace period
2695+ * @head_free: List of kfree_rcu() objects waiting for a grace period
2696+ * @krcp: Pointer to @kfree_rcu_cpu structure
2697+ */
2698+
2699+struct kfree_rcu_cpu_work {
2700+ struct rcu_work rcu_work;
2701+ struct rcu_head *head_free;
2702+ struct kfree_rcu_cpu *krcp;
2703+};
2704+
2705+/**
2706+ * struct kfree_rcu_cpu - batch up kfree_rcu() requests for RCU grace period
2707+ * @head: List of kfree_rcu() objects not yet waiting for a grace period
2708+ * @krw_arr: Array of batches of kfree_rcu() objects waiting for a grace period
2709+ * @lock: Synchronize access to this structure
2710+ * @monitor_work: Promote @head to @head_free after KFREE_DRAIN_JIFFIES
2711+ * @monitor_todo: Tracks whether a @monitor_work delayed work is pending
2712+ * @initialized: The @lock and @rcu_work fields have been initialized
2713+ *
2714+ * This is a per-CPU structure. The reason that it is not included in
2715+ * the rcu_data structure is to permit this code to be extracted from
2716+ * the RCU files. Such extraction could allow further optimization of
2717+ * the interactions with the slab allocators.
2718+ */
2719+struct kfree_rcu_cpu {
2720+ struct rcu_head *head;
2721+ struct kfree_rcu_cpu_work krw_arr[KFREE_N_BATCHES];
2722+ spinlock_t lock;
2723+ struct delayed_work monitor_work;
2724+ bool monitor_todo;
2725+ bool initialized;
2726+};
2727+
2728+static DEFINE_PER_CPU(struct kfree_rcu_cpu, krc);
2729+
2730+/*
2731+ * This function is invoked in workqueue context after a grace period.
2732+ * It frees all the objects queued on ->head_free.
2733+ */
2734+static void kfree_rcu_work(struct work_struct *work)
2735+{
2736+ unsigned long flags;
2737+ struct rcu_head *head, *next;
2738+ struct kfree_rcu_cpu *krcp;
2739+ struct kfree_rcu_cpu_work *krwp;
2740+
2741+ krwp = container_of(to_rcu_work(work),
2742+ struct kfree_rcu_cpu_work, rcu_work);
2743+ krcp = krwp->krcp;
2744+ spin_lock_irqsave(&krcp->lock, flags);
2745+ head = krwp->head_free;
2746+ krwp->head_free = NULL;
2747+ spin_unlock_irqrestore(&krcp->lock, flags);
2748+
2749+ // List "head" is now private, so traverse locklessly.
2750+ for (; head; head = next) {
2751+ unsigned long offset = (unsigned long)head->func;
2752+
2753+ next = head->next;
2754+ // Potentially optimize with kfree_bulk in future.
2755+ debug_rcu_head_unqueue(head);
2756+ rcu_lock_acquire(&rcu_callback_map);
2757+ trace_rcu_invoke_kfree_callback(rcu_state.name, head, offset);
2758+
2759+ if (!WARN_ON_ONCE(!__is_kfree_rcu_offset(offset))) {
2760+ /* Could be optimized with kfree_bulk() in future. */
2761+ kfree((void *)head - offset);
2762+ }
2763+
2764+ rcu_lock_release(&rcu_callback_map);
2765+ cond_resched_tasks_rcu_qs();
2766+ }
2767+}
2768+
26862769 /*
2687− * Queue an RCU callback for lazy invocation after a grace period.
2688− * This will likely be later named something like "call_rcu_lazy()",
2689− * but this change will require some way of tagging the lazy RCU
2690− * callbacks in the list of pending callbacks. Until then, this
2691− * function may only be called from __kfree_rcu().
2770+ * Schedule the kfree batch RCU work to run in workqueue context after a GP.
2771+ *
2772+ * This function is invoked by kfree_rcu_monitor() when the KFREE_DRAIN_JIFFIES
2773+ * timeout has been reached.
2774+ */
2775+static inline bool queue_kfree_rcu_work(struct kfree_rcu_cpu *krcp)
2776+{
2777+ int i;
2778+ struct kfree_rcu_cpu_work *krwp = NULL;
2779+
2780+ lockdep_assert_held(&krcp->lock);
2781+ for (i = 0; i < KFREE_N_BATCHES; i++)
2782+ if (!krcp->krw_arr[i].head_free) {
2783+ krwp = &(krcp->krw_arr[i]);
2784+ break;
2785+ }
2786+
2787+ // If a previous RCU batch is in progress, we cannot immediately
2788+ // queue another one, so return false to tell caller to retry.
2789+ if (!krwp)
2790+ return false;
2791+
2792+ krwp->head_free = krcp->head;
2793+ krcp->head = NULL;
2794+ INIT_RCU_WORK(&krwp->rcu_work, kfree_rcu_work);
2795+ queue_rcu_work(system_wq, &krwp->rcu_work);
2796+ return true;
2797+}
2798+
2799+static inline void kfree_rcu_drain_unlock(struct kfree_rcu_cpu *krcp,
2800+ unsigned long flags)
2801+{
2802+ // Attempt to start a new batch.
2803+ krcp->monitor_todo = false;
2804+ if (queue_kfree_rcu_work(krcp)) {
2805+ // Success! Our job is done here.
2806+ spin_unlock_irqrestore(&krcp->lock, flags);
2807+ return;
2808+ }
2809+
2810+ // Previous RCU batch still in progress, try again later.
2811+ krcp->monitor_todo = true;
2812+ schedule_delayed_work(&krcp->monitor_work, KFREE_DRAIN_JIFFIES);
2813+ spin_unlock_irqrestore(&krcp->lock, flags);
2814+}
2815+
2816+/*
2817+ * This function is invoked after the KFREE_DRAIN_JIFFIES timeout.
2818+ * It invokes kfree_rcu_drain_unlock() to attempt to start another batch.
2819+ */
2820+static void kfree_rcu_monitor(struct work_struct *work)
2821+{
2822+ unsigned long flags;
2823+ struct kfree_rcu_cpu *krcp = container_of(work, struct kfree_rcu_cpu,
2824+ monitor_work.work);
2825+
2826+ spin_lock_irqsave(&krcp->lock, flags);
2827+ if (krcp->monitor_todo)
2828+ kfree_rcu_drain_unlock(krcp, flags);
2829+ else
2830+ spin_unlock_irqrestore(&krcp->lock, flags);
2831+}
2832+
2833+/*
2834+ * Queue a request for lazy invocation of kfree() after a grace period.
2835+ *
2836+ * Each kfree_call_rcu() request is added to a batch. The batch will be drained
2837+ * every KFREE_DRAIN_JIFFIES number of jiffies. All the objects in the batch
2838+ * will be kfree'd in workqueue context. This allows us to:
2839+ *
2840+ * 1. Batch requests together to reduce the number of grace periods during
2841+ * heavy kfree_rcu() load.
2842+ *
2843+ * 2. It makes it possible to use kfree_bulk() on a large number of
2844+ * kfree_rcu() requests thus reducing cache misses and the per-object
2845+ * overhead of kfree().
26922846 */
26932847 void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func)
26942848 {
2695− __call_rcu(head, func, 1);
2849+ unsigned long flags;
2850+ struct kfree_rcu_cpu *krcp;
2851+
2852+ local_irq_save(flags); // For safely calling this_cpu_ptr().
2853+ krcp = this_cpu_ptr(&krc);
2854+ if (krcp->initialized)
2855+ spin_lock(&krcp->lock);
2856+
2857+ // Queue the object but don't yet schedule the batch.
2858+ if (debug_rcu_head_queue(head)) {
2859+ // Probable double kfree_rcu(), just leak.
2860+ WARN_ONCE(1, "%s(): Double-freed call. rcu_head %p\n",
2861+ __func__, head);
2862+ goto unlock_return;
2863+ }
2864+ head->func = func;
2865+ head->next = krcp->head;
2866+ krcp->head = head;
2867+
2868+ // Set timer to drain after KFREE_DRAIN_JIFFIES.
2869+ if (rcu_scheduler_active == RCU_SCHEDULER_RUNNING &&
2870+ !krcp->monitor_todo) {
2871+ krcp->monitor_todo = true;
2872+ schedule_delayed_work(&krcp->monitor_work, KFREE_DRAIN_JIFFIES);
2873+ }
2874+
2875+unlock_return:
2876+ if (krcp->initialized)
2877+ spin_unlock(&krcp->lock);
2878+ local_irq_restore(flags);
26962879 }
26972880 EXPORT_SYMBOL_GPL(kfree_call_rcu);
26982881
2882+void __init kfree_rcu_scheduler_running(void)
2883+{
2884+ int cpu;
2885+ unsigned long flags;
2886+
2887+ for_each_online_cpu(cpu) {
2888+ struct kfree_rcu_cpu *krcp = per_cpu_ptr(&krc, cpu);
2889+
2890+ spin_lock_irqsave(&krcp->lock, flags);
2891+ if (!krcp->head || krcp->monitor_todo) {
2892+ spin_unlock_irqrestore(&krcp->lock, flags);
2893+ continue;
2894+ }
2895+ krcp->monitor_todo = true;
2896+ schedule_delayed_work_on(cpu, &krcp->monitor_work,
2897+ KFREE_DRAIN_JIFFIES);
2898+ spin_unlock_irqrestore(&krcp->lock, flags);
2899+ }
2900+}
2901+
26992902 /*
27002903 * During early boot, any blocking grace-period wait automatically
2701− * implies a grace period. Later on, this is never the case for PREEMPT.
2904+ * implies a grace period. Later on, this is never the case for PREEMPTION.
27022905 *
2703− * Howevr, because a context switch is a grace period for !PREEMPT, any
2906+ * Howevr, because a context switch is a grace period for !PREEMPTION, any
27042907 * blocking grace-period wait automatically implies a grace period if
27052908 * there is only one CPU online at any point time during execution of
27062909 * either synchronize_rcu() or synchronize_rcu_expedited(). It is OK to
@@ -2896,7 +3099,7 @@ static void rcu_barrier_func(void *unused) · 189 unmodified lines
28963099 debug_rcu_head_queue(&rdp->barrier_head);
28973100 rcu_nocb_lock(rdp);
28983101 WARN_ON_ONCE(!rcu_nocb_flush_bypass(rdp, NULL, jiffies));
2899− if (rcu_segcblist_entrain(&rdp->cblist, &rdp->barrier_head, 0)) {
3102+ if (rcu_segcblist_entrain(&rdp->cblist, &rdp->barrier_head)) {
29003103 atomic_inc(&rcu_state.barrier_cpu_count);
29013104 } else {
29023105 debug_rcu_head_unqueue(&rdp->barrier_head);
@@ -3557,12 +3760,29 @@ static void __init rcu_dump_rcu_node_tree(void) · 654 unmodified lines
35573760 struct workqueue_struct *rcu_gp_wq;
35583761 struct workqueue_struct *rcu_par_gp_wq;
35593762
3763+static void __init kfree_rcu_batch_init(void)
3764+{
3765+ int cpu;
3766+ int i;
3767+
3768+ for_each_possible_cpu(cpu) {
3769+ struct kfree_rcu_cpu *krcp = per_cpu_ptr(&krc, cpu);
3770+
3771+ spin_lock_init(&krcp->lock);
3772+ for (i = 0; i < KFREE_N_BATCHES; i++)
3773+ krcp->krw_arr[i].krcp = krcp;
3774+ INIT_DELAYED_WORK(&krcp->monitor_work, kfree_rcu_monitor);
3775+ krcp->initialized = true;
3776+ }
3777+}
3778+
35603779 void __init rcu_init(void)
35613780 {
35623781 int cpu;
35633782
35643783 rcu_early_boot_tests();
35653784
3785+ kfree_rcu_batch_init();
35663786 rcu_bootup_announce();
35673787 rcu_init_geometry();
35683788 rcu_init_one();
kernel/rcu/tree.h+1−17
@@ -16,7 +16,6 @@ · 15 unmodified lines
1616 #include <linux/cpumask.h>
1717 #include <linux/seqlock.h>
1818 #include <linux/swait.h>
19−#include <linux/stop_machine.h>
2019 #include <linux/rcu_node_tree.h>
2120
2221 #include "rcu_segcblist.h"
@@ -182,8 +181,8 @@ struct rcu_data { · 159 unmodified lines
182181 bool rcu_need_heavy_qs; /* GP old, so heavy quiescent state! */
183182 bool rcu_urgent_qs; /* GP old need light quiescent state. */
184183 bool rcu_forced_tick; /* Forced tick to provide QS. */
184+ bool rcu_forced_tick_exp; /* ... provide QS to expedited GP. */
185185 #ifdef CONFIG_RCU_FAST_NO_HZ
186− bool all_lazy; /* All CPU's CBs lazy at idle start? */
187186 unsigned long last_accelerate; /* Last jiffy CBs were accelerated. */
188187 unsigned long last_advance_all; /* Last jiffy CBs were all advanced. */
189188 int tick_nohz_enabled_snap; /* Previously seen value from sysfs. */
@@ -368,18 +367,6 @@ struct rcu_state { · 178 unmodified lines
368367 #define RCU_GP_CLEANUP 7 /* Grace-period cleanup started. */
369368 #define RCU_GP_CLEANED 8 /* Grace-period cleanup complete. */
370369
371−static const char * const gp_state_names[] = {
372− "RCU_GP_IDLE",
373− "RCU_GP_WAIT_GPS",
374− "RCU_GP_DONE_GPS",
375− "RCU_GP_ONOFF",
376− "RCU_GP_INIT",
377− "RCU_GP_WAIT_FQS",
378− "RCU_GP_DOING_FQS",
379− "RCU_GP_CLEANUP",
380− "RCU_GP_CLEANED",
381−};
382−
383370 /*
384371 * In order to export the rcu_state name to the tracing tools, it
385372 * needs to be added in the __tracepoint_string section.
@@ -403,8 +390,6 @@ static const char *tp_rcu_varname __used __tracepoint_string = rcu_name; · 17 unmodified lines
403390 #define RCU_NAME rcu_name
404391 #endif /* #else #ifdef CONFIG_TRACING */
405392
406−int rcu_dynticks_snap(struct rcu_data *rdp);
407−
408393 /* Forward declarations for tree_plugin.h */
409394 static void rcu_bootup_announce(void);
410395 static void rcu_qs(void);
@@ -415,7 +400,6 @@ static bool rcu_preempt_has_tasks(struct rcu_node *rnp); · 4 unmodified lines
415400 static int rcu_print_task_exp_stall(struct rcu_node *rnp);
416401 static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp);
417402 static void rcu_flavor_sched_clock_irq(int user);
418−void call_rcu(struct rcu_head *head, rcu_callback_t func);
419403 static void dump_blkd_tasks(struct rcu_node *rnp, int ncheck);
420404 static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags);
421405 static void rcu_preempt_boost_start_gp(struct rcu_node *rnp);
kernel/rcu/tree_exp.h+91−56
@@ -21,7 +21,7 @@ static void rcu_exp_gp_seq_start(void) · 20 unmodified lines
2121 }
2222
2323 /*
24− * Return then value that expedited-grace-period counter will have
24+ * Return the value that the expedited-grace-period counter will have
2525 * at the end of the current grace period.
2626 */
2727 static __maybe_unused unsigned long rcu_exp_gp_seq_endval(void)
@@ -39,7 +39,9 @@ static void rcu_exp_gp_seq_end(void) · 11 unmodified lines
3939 }
4040
4141 /*
42− * Take a snapshot of the expedited-grace-period counter.
42+ * Take a snapshot of the expedited-grace-period counter, which is the
43+ * earliest value that will indicate that a full grace period has
44+ * elapsed since the current time.
4345 */
4446 static unsigned long rcu_exp_gp_seq_snap(void)
4547 {
@@ -134,7 +136,7 @@ static void __maybe_unused sync_exp_reset_tree(void) · 88 unmodified lines
134136 rcu_for_each_node_breadth_first(rnp) {
135137 raw_spin_lock_irqsave_rcu_node(rnp, flags);
136138 WARN_ON_ONCE(rnp->expmask);
137− rnp->expmask = rnp->expmaskinit;
139+ WRITE_ONCE(rnp->expmask, rnp->expmaskinit);
138140 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
139141 }
140142 }
@@ -143,31 +145,26 @@ static void __maybe_unused sync_exp_reset_tree(void) · 2 unmodified lines
143145 * Return non-zero if there is no RCU expedited grace period in progress
144146 * for the specified rcu_node structure, in other words, if all CPUs and
145147 * tasks covered by the specified rcu_node structure have done their bit
146− * for the current expedited grace period. Works only for preemptible
147− * RCU -- other RCU implementation use other means.
148− *
149− * Caller must hold the specificed rcu_node structure's ->lock
148+ * for the current expedited grace period.
150149 */
151−static bool sync_rcu_preempt_exp_done(struct rcu_node *rnp)
150+static bool sync_rcu_exp_done(struct rcu_node *rnp)
152151 {
153152 raw_lockdep_assert_held_rcu_node(rnp);
154−
155153 return rnp->exp_tasks == NULL &&
156154 READ_ONCE(rnp->expmask) == 0;
157155 }
158156
159157 /*
160− * Like sync_rcu_preempt_exp_done(), but this function assumes the caller
161− * doesn't hold the rcu_node's ->lock, and will acquire and release the lock
162− * itself
158+ * Like sync_rcu_exp_done(), but where the caller does not hold the
159+ * rcu_node's ->lock.
163160 */
164−static bool sync_rcu_preempt_exp_done_unlocked(struct rcu_node *rnp)
161+static bool sync_rcu_exp_done_unlocked(struct rcu_node *rnp)
165162 {
166163 unsigned long flags;
167164 bool ret;
168165
169166 raw_spin_lock_irqsave_rcu_node(rnp, flags);
170− ret = sync_rcu_preempt_exp_done(rnp);
167+ ret = sync_rcu_exp_done(rnp);
171168 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
172169
173170 return ret;
@@ -181,8 +178,6 @@ static bool sync_rcu_preempt_exp_done_unlocked(struct rcu_node *rnp) · 7 unmodified lines
181178 * which the task was queued or to one of that rcu_node structure's ancestors,
182179 * recursively up the tree. (Calm down, calm down, we do the recursion
183180 * iteratively!)
184− *
185− * Caller must hold the specified rcu_node structure's ->lock.
186181 */
187182 static void __rcu_report_exp_rnp(struct rcu_node *rnp,
188183 bool wake, unsigned long flags)
@@ -190,8 +185,9 @@ static void __rcu_report_exp_rnp(struct rcu_node *rnp, · 1 unmodified line
190185 {
191186 unsigned long mask;
192187
188+ raw_lockdep_assert_held_rcu_node(rnp);
193189 for (;;) {
194− if (!sync_rcu_preempt_exp_done(rnp)) {
190+ if (!sync_rcu_exp_done(rnp)) {
195191 if (!rnp->expmask)
196192 rcu_initiate_boost(rnp, flags);
197193 else
@@ -211,7 +207,7 @@ static void __rcu_report_exp_rnp(struct rcu_node *rnp, · 13 unmodified lines
211207 rnp = rnp->parent;
212208 raw_spin_lock_rcu_node(rnp); /* irqs already disabled */
213209 WARN_ON_ONCE(!(rnp->expmask & mask));
214− rnp->expmask &= ~mask;
210+ WRITE_ONCE(rnp->expmask, rnp->expmask & ~mask);
215211 }
216212 }
217213
@@ -234,14 +230,23 @@ static void __maybe_unused rcu_report_exp_rnp(struct rcu_node *rnp, bool wake) · 16 unmodified lines
234230 static void rcu_report_exp_cpu_mult(struct rcu_node *rnp,
235231 unsigned long mask, bool wake)
236232 {
233+ int cpu;
237234 unsigned long flags;
235+ struct rcu_data *rdp;
238236
239237 raw_spin_lock_irqsave_rcu_node(rnp, flags);
240238 if (!(rnp->expmask & mask)) {
241239 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
242240 return;
243241 }
244− rnp->expmask &= ~mask;
242+ WRITE_ONCE(rnp->expmask, rnp->expmask & ~mask);
243+ for_each_leaf_node_cpu_mask(rnp, cpu, mask) {
244+ rdp = per_cpu_ptr(&rcu_data, cpu);
245+ if (!IS_ENABLED(CONFIG_NO_HZ_FULL) || !rdp->rcu_forced_tick_exp)
246+ continue;
247+ rdp->rcu_forced_tick_exp = false;
248+ tick_dep_clear_cpu(cpu, TICK_DEP_BIT_RCU_EXP);
249+ }
245250 __rcu_report_exp_rnp(rnp, wake, flags); /* Releases rnp->lock. */
246251 }
247252
@@ -345,8 +350,8 @@ static void sync_rcu_exp_select_node_cpus(struct work_struct *wp) · 97 unmodified lines
345350 /* Each pass checks a CPU for identity, offline, and idle. */
346351 mask_ofl_test = 0;
347352 for_each_leaf_node_cpu_mask(rnp, cpu, rnp->expmask) {
348− unsigned long mask = leaf_node_cpu_bit(rnp, cpu);
349353 struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
354+ unsigned long mask = rdp->grpmask;
350355 int snap;
351356
352357 if (raw_smp_processor_id() == cpu ||
@@ -372,12 +377,10 @@ static void sync_rcu_exp_select_node_cpus(struct work_struct *wp) · 19 unmodified lines
372377 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
373378
374379 /* IPI the remaining CPUs for expedited quiescent state. */
375− for_each_leaf_node_cpu_mask(rnp, cpu, rnp->expmask) {
376− unsigned long mask = leaf_node_cpu_bit(rnp, cpu);
380+ for_each_leaf_node_cpu_mask(rnp, cpu, mask_ofl_ipi) {
377381 struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
382+ unsigned long mask = rdp->grpmask;
378383
379− if (!(mask_ofl_ipi & mask))
380− continue;
381384 retry_ipi:
382385 if (rcu_dynticks_in_eqs_since(rdp, rdp->exp_dynticks_snap)) {
383386 mask_ofl_test |= mask;
@@ -389,10 +392,10 @@ retry_ipi: · 5 unmodified lines
389392 }
390393 ret = smp_call_function_single(cpu, rcu_exp_handler, NULL, 0);
391394 put_cpu();
392− if (!ret) {
393− mask_ofl_ipi &= ~mask;
395+ /* The CPU will report the QS in response to the IPI. */
396+ if (!ret)
394397 continue;
395− }
398+
396399 /* Failed, raced with CPU hotplug operation. */
397400 raw_spin_lock_irqsave_rcu_node(rnp, flags);
398401 if ((rnp->qsmaskinitnext & mask) &&
@@ -403,13 +406,12 @@ retry_ipi: · 4 unmodified lines
403406 schedule_timeout_uninterruptible(1);
404407 goto retry_ipi;
405408 }
406− /* CPU really is offline, so we can ignore it. */
407− if (!(rnp->expmask & mask))
408− mask_ofl_ipi &= ~mask;
409+ /* CPU really is offline, so we must report its QS. */
410+ if (rnp->expmask & mask)
411+ mask_ofl_test |= mask;
409412 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
410413 }
411414 /* Report quiescent states for those that went offline. */
412− mask_ofl_test |= mask_ofl_ipi;
413415 if (mask_ofl_test)
414416 rcu_report_exp_cpu_mult(rnp, mask_ofl_test, false);
415417 }
@@ -456,29 +458,62 @@ static void sync_rcu_exp_select_cpus(void) · 40 unmodified lines
456458 flush_work(&rnp->rew.rew_work);
457459 }
458460
459−static void synchronize_sched_expedited_wait(void)
461+/*
462+ * Wait for the expedited grace period to elapse, within time limit.
463+ * If the time limit is exceeded without the grace period elapsing,
464+ * return false, otherwise return true.
465+ */
466+static bool synchronize_rcu_expedited_wait_once(long tlimit)
467+{
468+ int t;
469+ struct rcu_node *rnp_root = rcu_get_root();
470+
471+ t = swait_event_timeout_exclusive(rcu_state.expedited_wq,
472+ sync_rcu_exp_done_unlocked(rnp_root),
473+ tlimit);
474+ // Workqueues should not be signaled.
475+ if (t > 0 || sync_rcu_exp_done_unlocked(rnp_root))
476+ return true;
477+ WARN_ON(t < 0); /* workqueues should not be signaled. */
478+ return false;
479+}
480+
481+/*
482+ * Wait for the expedited grace period to elapse, issuing any needed
483+ * RCU CPU stall warnings along the way.
484+ */
485+static void synchronize_rcu_expedited_wait(void)
460486 {
461487 int cpu;
462488 unsigned long jiffies_stall;
463489 unsigned long jiffies_start;
464490 unsigned long mask;
465491 int ndetected;
492+ struct rcu_data *rdp;
466493 struct rcu_node *rnp;
467494 struct rcu_node *rnp_root = rcu_get_root();
468− int ret;
469495
470496 trace_rcu_exp_grace_period(rcu_state.name, rcu_exp_gp_seq_endval(), TPS("startwait"));
471497 jiffies_stall = rcu_jiffies_till_stall_check();
472498 jiffies_start = jiffies;
499+ if (IS_ENABLED(CONFIG_NO_HZ_FULL)) {
500+ if (synchronize_rcu_expedited_wait_once(1))
501+ return;
502+ rcu_for_each_leaf_node(rnp) {
503+ for_each_leaf_node_cpu_mask(rnp, cpu, rnp->expmask) {
504+ rdp = per_cpu_ptr(&rcu_data, cpu);
505+ if (rdp->rcu_forced_tick_exp)
506+ continue;
507+ rdp->rcu_forced_tick_exp = true;
508+ tick_dep_set_cpu(cpu, TICK_DEP_BIT_RCU_EXP);
509+ }
510+ }
511+ WARN_ON_ONCE(1);
512+ }
473513
474514 for (;;) {
475− ret = swait_event_timeout_exclusive(
476− rcu_state.expedited_wq,
477− sync_rcu_preempt_exp_done_unlocked(rnp_root),
478− jiffies_stall);
479− if (ret > 0 || sync_rcu_preempt_exp_done_unlocked(rnp_root))
515+ if (synchronize_rcu_expedited_wait_once(jiffies_stall))
480516 return;
481− WARN_ON(ret < 0); /* workqueues should not be signaled. */
482517 if (rcu_cpu_stall_suppress)
483518 continue;
484519 panic_on_rcu_stall();
@@ -491,7 +526,7 @@ static void synchronize_sched_expedited_wait(void) · 6 unmodified lines
491526 struct rcu_data *rdp;
492527
493528 mask = leaf_node_cpu_bit(rnp, cpu);
494− if (!(rnp->expmask & mask))
529+ if (!(READ_ONCE(rnp->expmask) & mask))
495530 continue;
496531 ndetected++;
497532 rdp = per_cpu_ptr(&rcu_data, cpu);
@@ -503,17 +538,18 @@ static void synchronize_sched_expedited_wait(void) · 5 unmodified lines
503538 }
504539 pr_cont(" } %lu jiffies s: %lu root: %#lx/%c\n",
505540 jiffies - jiffies_start, rcu_state.expedited_sequence,
506− rnp_root->expmask, ".T"[!!rnp_root->exp_tasks]);
541+ READ_ONCE(rnp_root->expmask),
542+ ".T"[!!rnp_root->exp_tasks]);
507543 if (ndetected) {
508544 pr_err("blocking rcu_node structures:");
509545 rcu_for_each_node_breadth_first(rnp) {
510546 if (rnp == rnp_root)
511547 continue; /* printed unconditionally */
512− if (sync_rcu_preempt_exp_done_unlocked(rnp))
548+ if (sync_rcu_exp_done_unlocked(rnp))
513549 continue;
514550 pr_cont(" l=%u:%d-%d:%#lx/%c",
515551 rnp->level, rnp->grplo, rnp->grphi,
516− rnp->expmask,
552+ READ_ONCE(rnp->expmask),
517553 ".T"[!!rnp->exp_tasks]);
518554 }
519555 pr_cont("\n");
@@ -521,7 +557,7 @@ static void synchronize_sched_expedited_wait(void) · 1 unmodified line
521557 rcu_for_each_leaf_node(rnp) {
522558 for_each_leaf_node_possible_cpu(rnp, cpu) {
523559 mask = leaf_node_cpu_bit(rnp, cpu);
524− if (!(rnp->expmask & mask))
560+ if (!(READ_ONCE(rnp->expmask) & mask))
525561 continue;
526562 dump_cpu_task(cpu);
527563 }
@@ -540,15 +576,14 @@ static void rcu_exp_wait_wake(unsigned long s) · 12 unmodified lines
540576 {
541577 struct rcu_node *rnp;
542578
543− synchronize_sched_expedited_wait();
544− rcu_exp_gp_seq_end();
545− trace_rcu_exp_grace_period(rcu_state.name, s, TPS("end"));
579+ synchronize_rcu_expedited_wait();
546580
547− /*
548− * Switch over to wakeup mode, allowing the next GP, but -only- the
549− * next GP, to proceed.
550− */
581+ // Switch over to wakeup mode, allowing the next GP to proceed.
582+ // End the previous grace period only after acquiring the mutex
583+ // to ensure that only one GP runs concurrently with wakeups.
551584 mutex_lock(&rcu_state.exp_wake_mutex);
585+ rcu_exp_gp_seq_end();
586+ trace_rcu_exp_grace_period(rcu_state.name, s, TPS("end"));
552587
553588 rcu_for_each_node_breadth_first(rnp) {
554589 if (ULONG_CMP_LT(READ_ONCE(rnp->exp_seq_rq), s)) {
@@ -559,7 +594,7 @@ static void rcu_exp_wait_wake(unsigned long s) · 4 unmodified lines
559594 spin_unlock(&rnp->exp_lock);
560595 }
561596 smp_mb(); /* All above changes before wakeup. */
562− wake_up_all(&rnp->exp_wq[rcu_seq_ctr(rcu_state.expedited_sequence) & 0x3]);
597+ wake_up_all(&rnp->exp_wq[rcu_seq_ctr(s) & 0x3]);
563598 }
564599 trace_rcu_exp_grace_period(rcu_state.name, s, TPS("endwake"));
565600 mutex_unlock(&rcu_state.exp_wake_mutex);
@@ -610,7 +645,7 @@ static void rcu_exp_handler(void *unused) · 44 unmodified lines
610645 * critical section. If also enabled or idle, immediately
611646 * report the quiescent state, otherwise defer.
612647 */
613− if (!t->rcu_read_lock_nesting) {
648+ if (!rcu_preempt_depth()) {
614649 if (!(preempt_count() & (PREEMPT_MASK | SOFTIRQ_MASK)) ||
615650 rcu_dynticks_curr_cpu_in_eqs()) {
616651 rcu_report_exp_rdp(rdp);
@@ -634,7 +669,7 @@ static void rcu_exp_handler(void *unused) · 17 unmodified lines
634669 * can have caused this quiescent state to already have been
635670 * reported, so we really do need to check ->expmask.
636671 */
637− if (t->rcu_read_lock_nesting > 0) {
672+ if (rcu_preempt_depth() > 0) {
638673 raw_spin_lock_irqsave_rcu_node(rnp, flags);
639674 if (rnp->expmask & rdp->grpmask) {
640675 rdp->exp_deferred_qs = true;
@@ -670,7 +705,7 @@ static void rcu_exp_handler(void *unused) · 29 unmodified lines
670705 }
671706 }
672707
673−/* PREEMPT=y, so no PREEMPT=n expedited grace period to clean up after. */
708+/* PREEMPTION=y, so no PREEMPTION=n expedited grace period to clean up after. */
674709 static void sync_sched_exp_online_cleanup(int cpu)
675710 {
676711 }
@@ -785,7 +820,7 @@ static int rcu_print_task_exp_stall(struct rcu_node *rnp) · 108 unmodified lines
785820 * implementations, it is still unfriendly to real-time workloads, so is
786821 * thus not recommended for any sort of common-case code. In fact, if
787822 * you are using synchronize_rcu_expedited() in a loop, please restructure
788− * your code to batch your updates, and then Use a single synchronize_rcu()
823+ * your code to batch your updates, and then use a single synchronize_rcu()
789824 * instead.
790825 *
791826 * This has the same semantics as (but is more brutal than) synchronize_rcu().
kernel/rcu/tree_plugin.h+78−90
@@ -220,7 +220,7 @@ static void rcu_preempt_ctxt_queue(struct rcu_node *rnp, struct rcu_data *rdp) · 219 unmodified lines
220220 * blocked tasks.
221221 */
222222 if (!rnp->gp_tasks && (blkd_state & RCU_GP_BLKD)) {
223− rnp->gp_tasks = &t->rcu_node_entry;
223+ WRITE_ONCE(rnp->gp_tasks, &t->rcu_node_entry);
224224 WARN_ON_ONCE(rnp->completedqs == rnp->gp_seq);
225225 }
226226 if (!rnp->exp_tasks && (blkd_state & RCU_EXP_BLKD))
@@ -290,8 +290,8 @@ void rcu_note_context_switch(bool preempt) · 63 unmodified lines
290290
291291 trace_rcu_utilization(TPS("Start context switch"));
292292 lockdep_assert_irqs_disabled();
293− WARN_ON_ONCE(!preempt && t->rcu_read_lock_nesting > 0);
294− if (t->rcu_read_lock_nesting > 0 &&
293+ WARN_ON_ONCE(!preempt && rcu_preempt_depth() > 0);
294+ if (rcu_preempt_depth() > 0 &&
295295 !t->rcu_read_unlock_special.b.blocked) {
296296
297297 /* Possibly blocking in an RCU read-side critical section. */
@@ -340,7 +340,7 @@ EXPORT_SYMBOL_GPL(rcu_note_context_switch); · 42 unmodified lines
340340 */
341341 static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp)
342342 {
343− return rnp->gp_tasks != NULL;
343+ return READ_ONCE(rnp->gp_tasks) != NULL;
344344 }
345345
346346 /* Bias and limit values for ->rcu_read_lock_nesting. */
@@ -348,6 +348,21 @@ static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp) · 1 unmodified line
348348 #define RCU_NEST_NMAX (-INT_MAX / 2)
349349 #define RCU_NEST_PMAX (INT_MAX / 2)
350350
351+static void rcu_preempt_read_enter(void)
352+{
353+ current->rcu_read_lock_nesting++;
354+}
355+
356+static void rcu_preempt_read_exit(void)
357+{
358+ current->rcu_read_lock_nesting--;
359+}
360+
361+static void rcu_preempt_depth_set(int val)
362+{
363+ current->rcu_read_lock_nesting = val;
364+}
365+
351366 /*
352367 * Preemptible RCU implementation for rcu_read_lock().
353368 * Just increment ->rcu_read_lock_nesting, shared state will be updated
@@ -355,9 +370,9 @@ static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp) · 1 unmodified line
355370 */
356371 void __rcu_read_lock(void)
357372 {
358− current->rcu_read_lock_nesting++;
373+ rcu_preempt_read_enter();
359374 if (IS_ENABLED(CONFIG_PROVE_LOCKING))
360− WARN_ON_ONCE(current->rcu_read_lock_nesting > RCU_NEST_PMAX);
375+ WARN_ON_ONCE(rcu_preempt_depth() > RCU_NEST_PMAX);
361376 barrier(); /* critical section after entry code. */
362377 }
363378 EXPORT_SYMBOL_GPL(__rcu_read_lock);
@@ -373,19 +388,19 @@ void __rcu_read_unlock(void) · 9 unmodified lines
373388 {
374389 struct task_struct *t = current;
375390
376− if (t->rcu_read_lock_nesting != 1) {
377− --t->rcu_read_lock_nesting;
391+ if (rcu_preempt_depth() != 1) {
392+ rcu_preempt_read_exit();
378393 } else {
379394 barrier(); /* critical section before exit code. */
380− t->rcu_read_lock_nesting = -RCU_NEST_BIAS;
395+ rcu_preempt_depth_set(-RCU_NEST_BIAS);
381396 barrier(); /* assign before ->rcu_read_unlock_special load */
382397 if (unlikely(READ_ONCE(t->rcu_read_unlock_special.s)))
383398 rcu_read_unlock_special(t);
384399 barrier(); /* ->rcu_read_unlock_special load before assign */
385− t->rcu_read_lock_nesting = 0;
400+ rcu_preempt_depth_set(0);
386401 }
387402 if (IS_ENABLED(CONFIG_PROVE_LOCKING)) {
388− int rrln = t->rcu_read_lock_nesting;
403+ int rrln = rcu_preempt_depth();
389404
390405 WARN_ON_ONCE(rrln < 0 && rrln > RCU_NEST_NMAX);
391406 }
@@ -444,15 +459,9 @@ rcu_preempt_deferred_qs_irqrestore(struct task_struct *t, unsigned long flags) · 52 unmodified lines
444459 local_irq_restore(flags);
445460 return;
446461 }
447− t->rcu_read_unlock_special.b.deferred_qs = false;
448− if (special.b.need_qs) {
462+ t->rcu_read_unlock_special.s = 0;
463+ if (special.b.need_qs)
449464 rcu_qs();
450− t->rcu_read_unlock_special.b.need_qs = false;
451− if (!t->rcu_read_unlock_special.s && !rdp->exp_deferred_qs) {
452− local_irq_restore(flags);
453− return;
454− }
455− }
456465
457466 /*
458467 * Respond to a request by an expedited grace period for a
@@ -460,17 +469,11 @@ rcu_preempt_deferred_qs_irqrestore(struct task_struct *t, unsigned long flags) · 1 unmodified line
460469 * tasks are handled when removing the task from the
461470 * blocked-tasks list below.
462471 */
463− if (rdp->exp_deferred_qs) {
472+ if (rdp->exp_deferred_qs)
464473 rcu_report_exp_rdp(rdp);
465− if (!t->rcu_read_unlock_special.s) {
466− local_irq_restore(flags);
467− return;
468− }
469− }
470474
471475 /* Clean up if blocked during RCU read-side critical section. */
472476 if (special.b.blocked) {
473− t->rcu_read_unlock_special.b.blocked = false;
474477
475478 /*
476479 * Remove this task from the list it blocked on. The task
@@ -485,7 +488,7 @@ rcu_preempt_deferred_qs_irqrestore(struct task_struct *t, unsigned long flags) · 8 unmodified lines
485488 empty_norm = !rcu_preempt_blocked_readers_cgp(rnp);
486489 WARN_ON_ONCE(rnp->completedqs == rnp->gp_seq &&
487490 (!empty_norm || rnp->qsmask));
488− empty_exp = sync_rcu_preempt_exp_done(rnp);
491+ empty_exp = sync_rcu_exp_done(rnp);
489492 smp_mb(); /* ensure expedited fastpath sees end of RCU c-s. */
490493 np = rcu_next_node_entry(t, rnp);
491494 list_del_init(&t->rcu_node_entry);
@@ -493,7 +496,7 @@ rcu_preempt_deferred_qs_irqrestore(struct task_struct *t, unsigned long flags) · 1 unmodified line
493496 trace_rcu_unlock_preempted_task(TPS("rcu_preempt"),
494497 rnp->gp_seq, t->pid);
495498 if (&t->rcu_node_entry == rnp->gp_tasks)
496− rnp->gp_tasks = np;
499+ WRITE_ONCE(rnp->gp_tasks, np);
497500 if (&t->rcu_node_entry == rnp->exp_tasks)
498501 rnp->exp_tasks = np;
499502 if (IS_ENABLED(CONFIG_RCU_BOOST)) {
@@ -509,7 +512,7 @@ rcu_preempt_deferred_qs_irqrestore(struct task_struct *t, unsigned long flags) · 9 unmodified lines
509512 * Note that rcu_report_unblock_qs_rnp() releases rnp->lock,
510513 * so we must take a snapshot of the expedited state.
511514 */
512− empty_exp_now = sync_rcu_preempt_exp_done(rnp);
515+ empty_exp_now = sync_rcu_exp_done(rnp);
513516 if (!empty_norm && !rcu_preempt_blocked_readers_cgp(rnp)) {
514517 trace_rcu_quiescent_state_report(TPS("preempt_rcu"),
515518 rnp->gp_seq,
@@ -551,7 +554,7 @@ static bool rcu_preempt_need_deferred_qs(struct task_struct *t) · 35 unmodified lines
551554 {
552555 return (__this_cpu_read(rcu_data.exp_deferred_qs) ||
553556 READ_ONCE(t->rcu_read_unlock_special.s)) &&
554− t->rcu_read_lock_nesting <= 0;
557+ rcu_preempt_depth() <= 0;
555558 }
556559
557560 /*
@@ -564,16 +567,16 @@ static bool rcu_preempt_need_deferred_qs(struct task_struct *t) · 6 unmodified lines
564567 static void rcu_preempt_deferred_qs(struct task_struct *t)
565568 {
566569 unsigned long flags;
567− bool couldrecurse = t->rcu_read_lock_nesting >= 0;
570+ bool couldrecurse = rcu_preempt_depth() >= 0;
568571
569572 if (!rcu_preempt_need_deferred_qs(t))
570573 return;
571574 if (couldrecurse)
572− t->rcu_read_lock_nesting -= RCU_NEST_BIAS;
575+ rcu_preempt_depth_set(rcu_preempt_depth() - RCU_NEST_BIAS);
573576 local_irq_save(flags);
574577 rcu_preempt_deferred_qs_irqrestore(t, flags);
575578 if (couldrecurse)
576− t->rcu_read_lock_nesting += RCU_NEST_BIAS;
579+ rcu_preempt_depth_set(rcu_preempt_depth() + RCU_NEST_BIAS);
577580 }
578581
579582 /*
@@ -610,9 +613,8 @@ static void rcu_read_unlock_special(struct task_struct *t) · 30 unmodified lines
610613 struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
611614 struct rcu_node *rnp = rdp->mynode;
612615
613− t->rcu_read_unlock_special.b.exp_hint = false;
614616 exp = (t->rcu_blocked_node && t->rcu_blocked_node->exp_tasks) ||
615− (rdp->grpmask & rnp->expmask) ||
617+ (rdp->grpmask & READ_ONCE(rnp->expmask)) ||
616618 tick_nohz_full_cpu(rdp->cpu);
617619 // Need to defer quiescent state until everything is enabled.
618620 if (irqs_were_disabled && use_softirq &&
@@ -640,7 +642,6 @@ static void rcu_read_unlock_special(struct task_struct *t) · 21 unmodified lines
640642 local_irq_restore(flags);
641643 return;
642644 }
643− WRITE_ONCE(t->rcu_read_unlock_special.b.exp_hint, false);
644645 rcu_preempt_deferred_qs_irqrestore(t, flags);
645646 }
646647
@@ -648,8 +649,7 @@ static void rcu_read_unlock_special(struct task_struct *t) · 1 unmodified line
648649 * Check that the list of blocked tasks for the newly completed grace
649650 * period is in fact empty. It is a serious bug to complete a grace
650651 * period that still has RCU readers blocked! This function must be
651− * invoked -before- updating this rnp's ->gp_seq, and the rnp's ->lock
652− * must be held by the caller.
652+ * invoked -before- updating this rnp's ->gp_seq.
653653 *
654654 * Also, if there are blocked tasks on the list, they automatically
655655 * block the newly created grace period, so set up ->gp_tasks accordingly.
@@ -659,11 +659,12 @@ static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp) · 3 unmodified lines
659659 struct task_struct *t;
660660
661661 RCU_LOCKDEP_WARN(preemptible(), "rcu_preempt_check_blocked_tasks() invoked with preemption enabled!!!\n");
662+ raw_lockdep_assert_held_rcu_node(rnp);
662663 if (WARN_ON_ONCE(rcu_preempt_blocked_readers_cgp(rnp)))
663664 dump_blkd_tasks(rnp, 10);
664665 if (rcu_preempt_has_tasks(rnp) &&
665666 (rnp->qsmaskinit || rnp->wait_blkd_tasks)) {
666− rnp->gp_tasks = rnp->blkd_tasks.next;
667+ WRITE_ONCE(rnp->gp_tasks, rnp->blkd_tasks.next);
667668 t = container_of(rnp->gp_tasks, struct task_struct,
668669 rcu_node_entry);
669670 trace_rcu_unlock_preempted_task(TPS("rcu_preempt-GPS"),
@@ -686,7 +687,7 @@ static void rcu_flavor_sched_clock_irq(int user) · 16 unmodified lines
686687 if (user || rcu_is_cpu_rrupt_from_idle()) {
687688 rcu_note_voluntary_context_switch(current);
688689 }
689− if (t->rcu_read_lock_nesting > 0 ||
690+ if (rcu_preempt_depth() > 0 ||
690691 (preempt_count() & (PREEMPT_MASK | SOFTIRQ_MASK))) {
691692 /* No QS, force context switch if deferred. */
692693 if (rcu_preempt_need_deferred_qs(t)) {
@@ -696,13 +697,13 @@ static void rcu_flavor_sched_clock_irq(int user) · 3 unmodified lines
696697 } else if (rcu_preempt_need_deferred_qs(t)) {
697698 rcu_preempt_deferred_qs(t); /* Report deferred QS. */
698699 return;
699− } else if (!t->rcu_read_lock_nesting) {
700+ } else if (!rcu_preempt_depth()) {
700701 rcu_qs(); /* Report immediate QS. */
701702 return;
702703 }
703704
704705 /* If GP is oldish, ask for help from rcu_read_unlock_special(). */
705− if (t->rcu_read_lock_nesting > 0 &&
706+ if (rcu_preempt_depth() > 0 &&
706707 __this_cpu_read(rcu_data.core_needs_qs) &&
707708 __this_cpu_read(rcu_data.cpu_no_qs.b.norm) &&
708709 !t->rcu_read_unlock_special.b.need_qs &&
@@ -723,11 +724,11 @@ void exit_rcu(void) · 14 unmodified lines
723724 struct task_struct *t = current;
724725
725726 if (unlikely(!list_empty(&current->rcu_node_entry))) {
726− t->rcu_read_lock_nesting = 1;
727+ rcu_preempt_depth_set(1);
727728 barrier();
728729 WRITE_ONCE(t->rcu_read_unlock_special.b.blocked, true);
729− } else if (unlikely(t->rcu_read_lock_nesting)) {
730− t->rcu_read_lock_nesting = 1;
730+ } else if (unlikely(rcu_preempt_depth())) {
731+ rcu_preempt_depth_set(1);
731732 } else {
732733 return;
733734 }
@@ -757,7 +758,8 @@ dump_blkd_tasks(struct rcu_node *rnp, int ncheck) · 23 unmodified lines
757758 pr_info("%s: %d:%d ->qsmask %#lx ->qsmaskinit %#lx ->qsmaskinitnext %#lx\n",
758759 __func__, rnp1->grplo, rnp1->grphi, rnp1->qsmask, rnp1->qsmaskinit, rnp1->qsmaskinitnext);
759760 pr_info("%s: ->gp_tasks %p ->boost_tasks %p ->exp_tasks %p\n",
760− __func__, rnp->gp_tasks, rnp->boost_tasks, rnp->exp_tasks);
761+ __func__, READ_ONCE(rnp->gp_tasks), rnp->boost_tasks,
762+ rnp->exp_tasks);
761763 pr_info("%s: ->blkd_tasks", __func__);
762764 i = 0;
763765 list_for_each(lhp, &rnp->blkd_tasks) {
@@ -788,7 +790,7 @@ static void __init rcu_bootup_announce(void) · 24 unmodified lines
788790 }
789791
790792 /*
791− * Note a quiescent state for PREEMPT=n. Because we do not need to know
793+ * Note a quiescent state for PREEMPTION=n. Because we do not need to know
792794 * how many quiescent states passed, just if there was at least one since
793795 * the start of the grace period, this just sets a flag. The caller must
794796 * have disabled preemption.
@@ -838,7 +840,7 @@ void rcu_all_qs(void) · 43 unmodified lines
838840 EXPORT_SYMBOL_GPL(rcu_all_qs);
839841
840842 /*
841− * Note a PREEMPT=n context switch. The caller must have disabled interrupts.
843+ * Note a PREEMPTION=n context switch. The caller must have disabled interrupts.
842844 */
843845 void rcu_note_context_switch(bool preempt)
844846 {
@@ -1262,10 +1264,9 @@ static void rcu_prepare_for_idle(void) · 417 unmodified lines
12621264 /*
12631265 * This code is invoked when a CPU goes idle, at which point we want
12641266 * to have the CPU do everything required for RCU so that it can enter
1265− * the energy-efficient dyntick-idle mode. This is handled by a
1266− * state machine implemented by rcu_prepare_for_idle() below.
1267+ * the energy-efficient dyntick-idle mode.
12671268 *
1268− * The following three proprocessor symbols control this state machine:
1269+ * The following preprocessor symbol controls this:
12691270 *
12701271 * RCU_IDLE_GP_DELAY gives the number of jiffies that a CPU is permitted
12711272 * to sleep in dyntick-idle mode with RCU callbacks pending. This
@@ -1274,21 +1275,15 @@ static void rcu_prepare_for_idle(void) · 2 unmodified lines
12741275 * number, be warned: Setting RCU_IDLE_GP_DELAY too high can hang your
12751276 * system. And if you are -that- concerned about energy efficiency,
12761277 * just power the system down and be done with it!
1277− * RCU_IDLE_LAZY_GP_DELAY gives the number of jiffies that a CPU is
1278− * permitted to sleep in dyntick-idle mode with only lazy RCU
1279− * callbacks pending. Setting this too high can OOM your system.
12801278 *
1281− * The values below work well in practice. If future workloads require
1279+ * The value below works well in practice. If future workloads require
12821280 * adjustment, they can be converted into kernel config parameters, though
12831281 * making the state machine smarter might be a better option.
12841282 */
12851283 #define RCU_IDLE_GP_DELAY 4 /* Roughly one grace period. */
1286−#define RCU_IDLE_LAZY_GP_DELAY (6 * HZ) /* Roughly six seconds. */
12871284
12881285 static int rcu_idle_gp_delay = RCU_IDLE_GP_DELAY;
12891286 module_param(rcu_idle_gp_delay, int, 0644);
1290−static int rcu_idle_lazy_gp_delay = RCU_IDLE_LAZY_GP_DELAY;
1291−module_param(rcu_idle_lazy_gp_delay, int, 0644);
12921287
12931288 /*
12941289 * Try to advance callbacks on the current CPU, but only if it has been
@@ -1327,8 +1322,7 @@ static bool __maybe_unused rcu_try_advance_all_cbs(void) · 32 unmodified lines
13271322 /*
13281323 * Allow the CPU to enter dyntick-idle mode unless it has callbacks ready
13291324 * to invoke. If the CPU has callbacks, try to advance them. Tell the
1330− * caller to set the timeout based on whether or not there are non-lazy
1331− * callbacks.
1325+ * caller about what to set the timeout.
13321326 *
13331327 * The caller must have disabled interrupts.
13341328 */
@@ -1354,25 +1348,18 @@ int rcu_needs_cpu(u64 basemono, u64 *nextevt) · 19 unmodified lines
13541348 }
13551349 rdp->last_accelerate = jiffies;
13561350
1357− /* Request timer delay depending on laziness, and round. */
1358− rdp->all_lazy = !rcu_segcblist_n_nonlazy_cbs(&rdp->cblist);
1359− if (rdp->all_lazy) {
1360− dj = round_jiffies(rcu_idle_lazy_gp_delay + jiffies) - jiffies;
1361− } else {
1362− dj = round_up(rcu_idle_gp_delay + jiffies,
1363− rcu_idle_gp_delay) - jiffies;
1364− }
1351+ /* Request timer and round. */
1352+ dj = round_up(rcu_idle_gp_delay + jiffies, rcu_idle_gp_delay) - jiffies;
1353+
13651354 *nextevt = basemono + dj * TICK_NSEC;
13661355 return 0;
13671356 }
13681357
13691358 /*
1370− * Prepare a CPU for idle from an RCU perspective. The first major task
1371− * is to sense whether nohz mode has been enabled or disabled via sysfs.
1372− * The second major task is to check to see if a non-lazy callback has
1373− * arrived at a CPU that previously had only lazy callbacks. The third
1374− * major task is to accelerate (that is, assign grace-period numbers to)
1375− * any recently arrived callbacks.
1359+ * Prepare a CPU for idle from an RCU perspective. The first major task is to
1360+ * sense whether nohz mode has been enabled or disabled via sysfs. The second
1361+ * major task is to accelerate (that is, assign grace-period numbers to) any
1362+ * recently arrived callbacks.
13761363 *
13771364 * The caller must have disabled interrupts.
13781365 */
@@ -1398,17 +1385,6 @@ static void rcu_prepare_for_idle(void) · 19 unmodified lines
13981385 if (!tne)
13991386 return;
14001387
1401− /*
1402− * If a non-lazy callback arrived at a CPU having only lazy
1403− * callbacks, invoke RCU core for the side-effect of recalculating
1404− * idle duration on re-entry to idle.
1405− */
1406− if (rdp->all_lazy && rcu_segcblist_n_nonlazy_cbs(&rdp->cblist)) {
1407− rdp->all_lazy = false;
1408− invoke_rcu_core();
1409− return;
1410− }
1411−
14121388 /*
14131389 * If we have not yet accelerated this jiffy, accelerate all
14141390 * callbacks on this CPU.
@@ -2321,6 +2297,8 @@ static void __init rcu_organize_nocb_kthreads(void) · 906 unmodified lines
23212297 {
23222298 int cpu;
23232299 bool firsttime = true;
2300+ bool gotnocbs = false;
2301+ bool gotnocbscbs = true;
23242302 int ls = rcu_nocb_gp_stride;
23252303 int nl = 0; /* Next GP kthread. */
23262304 struct rcu_data *rdp;
@@ -2343,21 +2321,31 @@ static void __init rcu_organize_nocb_kthreads(void) · 16 unmodified lines
23432321 rdp = per_cpu_ptr(&rcu_data, cpu);
23442322 if (rdp->cpu >= nl) {
23452323 /* New GP kthread, set up for CBs & next GP. */
2324+ gotnocbs = true;
23462325 nl = DIV_ROUND_UP(rdp->cpu + 1, ls) * ls;
23472326 rdp->nocb_gp_rdp = rdp;
23482327 rdp_gp = rdp;
2349− if (!firsttime && dump_tree)
2350− pr_cont("\n");
2351− firsttime = false;
2352− pr_alert("%s: No-CB GP kthread CPU %d:", __func__, cpu);
2328+ if (dump_tree) {
2329+ if (!firsttime)
2330+ pr_cont("%s\n", gotnocbscbs
2331+ ? "" : " (self only)");
2332+ gotnocbscbs = false;
2333+ firsttime = false;
2334+ pr_alert("%s: No-CB GP kthread CPU %d:",
2335+ __func__, cpu);
2336+ }
23532337 } else {
23542338 /* Another CB kthread, link to previous GP kthread. */
2339+ gotnocbscbs = true;
23552340 rdp->nocb_gp_rdp = rdp_gp;
23562341 rdp_prev->nocb_next_cb_rdp = rdp;
2357− pr_alert(" %d", cpu);
2342+ if (dump_tree)
2343+ pr_cont(" %d", cpu);
23582344 }
23592345 rdp_prev = rdp;
23602346 }
2347+ if (gotnocbs && dump_tree)
2348+ pr_cont("%s\n", gotnocbscbs ? "" : " (self only)");
23612349 }
23622350
23632351 /*
kernel/rcu/tree_stall.h+27−7
@@ -163,7 +163,7 @@ static void rcu_iw_handler(struct irq_work *iwp) · 162 unmodified lines
163163 //
164164 // Printing RCU CPU stall warnings
165165
166−#ifdef CONFIG_PREEMPTION
166+#ifdef CONFIG_PREEMPT_RCU
167167
168168 /*
169169 * Dump detailed information for all tasks blocking the current RCU
@@ -215,7 +215,7 @@ static int rcu_print_task_stall(struct rcu_node *rnp) · 45 unmodified lines
215215 return ndetected;
216216 }
217217
218−#else /* #ifdef CONFIG_PREEMPTION */
218+#else /* #ifdef CONFIG_PREEMPT_RCU */
219219
220220 /*
221221 * Because preemptible RCU does not exist, we never have to check for
@@ -233,7 +233,7 @@ static int rcu_print_task_stall(struct rcu_node *rnp) · 11 unmodified lines
233233 {
234234 return 0;
235235 }
236−#endif /* #else #ifdef CONFIG_PREEMPTION */
236+#endif /* #else #ifdef CONFIG_PREEMPT_RCU */
237237
238238 /*
239239 * Dump stacks of all tasks running on stalled CPUs. First try using
@@ -263,11 +263,9 @@ static void print_cpu_stall_fast_no_hz(char *cp, int cpu) · 23 unmodified lines
263263 {
264264 struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
265265
266− sprintf(cp, "last_accelerate: %04lx/%04lx, Nonlazy posted: %c%c%c",
266+ sprintf(cp, "last_accelerate: %04lx/%04lx dyntick_enabled: %d",
267267 rdp->last_accelerate & 0xffff, jiffies & 0xffff,
268− ".l"[rdp->all_lazy],
269− ".L"[!rcu_segcblist_n_nonlazy_cbs(&rdp->cblist)],
270− ".D"[!!rdp->tick_nohz_enabled_snap]);
268+ !!rdp->tick_nohz_enabled_snap);
271269 }
272270
273271 #else /* #ifdef CONFIG_RCU_FAST_NO_HZ */
@@ -279,6 +277,28 @@ static void print_cpu_stall_fast_no_hz(char *cp, int cpu) · 5 unmodified lines
279277
280278 #endif /* #else #ifdef CONFIG_RCU_FAST_NO_HZ */
281279
280+static const char * const gp_state_names[] = {
281+ [RCU_GP_IDLE] = "RCU_GP_IDLE",
282+ [RCU_GP_WAIT_GPS] = "RCU_GP_WAIT_GPS",
283+ [RCU_GP_DONE_GPS] = "RCU_GP_DONE_GPS",
284+ [RCU_GP_ONOFF] = "RCU_GP_ONOFF",
285+ [RCU_GP_INIT] = "RCU_GP_INIT",
286+ [RCU_GP_WAIT_FQS] = "RCU_GP_WAIT_FQS",
287+ [RCU_GP_DOING_FQS] = "RCU_GP_DOING_FQS",
288+ [RCU_GP_CLEANUP] = "RCU_GP_CLEANUP",
289+ [RCU_GP_CLEANED] = "RCU_GP_CLEANED",
290+};
291+
292+/*
293+ * Convert a ->gp_state value to a character string.
294+ */
295+static const char *gp_state_getname(short gs)
296+{
297+ if (gs < 0 || gs >= ARRAY_SIZE(gp_state_names))
298+ return "???";
299+ return gp_state_names[gs];
300+}
301+
282302 /*
283303 * Print out diagnostic information for the specified stalled CPU.
284304 *
kernel/rcu/update.c+11−3
@@ -40,6 +40,7 @@ · 39 unmodified lines
4040 #include <linux/rcupdate_wait.h>
4141 #include <linux/sched/isolation.h>
4242 #include <linux/kprobes.h>
43+#include <linux/slab.h>
4344
4445 #define CREATE_TRACE_POINTS
4546
@@ -51,9 +52,7 @@ · 5 unmodified lines
5152 #define MODULE_PARAM_PREFIX "rcupdate."
5253
5354 #ifndef CONFIG_TINY_RCU
54−extern int rcu_expedited; /* from sysctl */
5555 module_param(rcu_expedited, int, 0);
56−extern int rcu_normal; /* from sysctl */
5756 module_param(rcu_normal, int, 0);
5857 static int rcu_normal_after_boot;
5958 module_param(rcu_normal_after_boot, int, 0);
@@ -218,6 +217,7 @@ static int __init rcu_set_runtime_mode(void) · 158 unmodified lines
218217 {
219218 rcu_test_sync_prims();
220219 rcu_scheduler_active = RCU_SCHEDULER_RUNNING;
220+ kfree_rcu_scheduler_running();
221221 rcu_test_sync_prims();
222222 return 0;
223223 }
@@ -435,7 +435,7 @@ struct debug_obj_descr rcuhead_debug_descr = { · 211 unmodified lines
435435 EXPORT_SYMBOL_GPL(rcuhead_debug_descr);
436436 #endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
437437
438−#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU) || defined(CONFIG_RCU_TRACE)
438+#if defined(CONFIG_TREE_RCU) || defined(CONFIG_RCU_TRACE)
439439 void do_trace_rcu_torture_read(const char *rcutorturename, struct rcu_head *rhp,
440440 unsigned long secs,
441441 unsigned long c_old, unsigned long c)
@@ -853,14 +853,22 @@ static void test_callback(struct rcu_head *r) · 411 unmodified lines
853853
854854 DEFINE_STATIC_SRCU(early_srcu);
855855
856+struct early_boot_kfree_rcu {
857+ struct rcu_head rh;
858+};
859+
856860 static void early_boot_test_call_rcu(void)
857861 {
858862 static struct rcu_head head;
859863 static struct rcu_head shead;
864+ struct early_boot_kfree_rcu *rhp;
860865
861866 call_rcu(&head, test_callback);
862867 if (IS_ENABLED(CONFIG_SRCU))
863868 call_srcu(&early_srcu, &shead, test_callback);
869+ rhp = kmalloc(sizeof(*rhp), GFP_KERNEL);
870+ if (!WARN_ON_ONCE(!rhp))
871+ kfree_rcu(rhp, rh);
864872 }
865873
866874 void rcu_early_boot_tests(void)
kernel/sysctl.c+1−1
@@ -1268,7 +1268,7 @@ static struct ctl_table kern_table[] = { · 1267 unmodified lines
12681268 .proc_handler = proc_do_static_key,
12691269 },
12701270 #endif
1271−#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)
1271+#if defined(CONFIG_TREE_RCU)
12721272 {
12731273 .procname = "panic_on_rcu_stall",
12741274 .data = &sysctl_panic_on_rcu_stall,
net/tipc/crypto.c+1−4
@@ -257,9 +257,6 @@ static char *tipc_key_change_dump(struct tipc_key old, struct tipc_key new, · 256 unmodified lines
257257 #define tipc_aead_rcu_ptr(rcu_ptr, lock) \
258258 rcu_dereference_protected((rcu_ptr), lockdep_is_held(lock))
259259
260−#define tipc_aead_rcu_swap(rcu_ptr, ptr, lock) \
261− rcu_swap_protected((rcu_ptr), (ptr), lockdep_is_held(lock))
262−
263260 #define tipc_aead_rcu_replace(rcu_ptr, ptr, lock) \
264261 do { \
265262 typeof(rcu_ptr) __tmp = rcu_dereference_protected((rcu_ptr), \
@@ -1189,7 +1186,7 @@ static bool tipc_crypto_key_try_align(struct tipc_crypto *rx, u8 new_pending) · 923 unmodified lines
11891186
11901187 /* Move passive key if any */
11911188 if (key.passive) {
1192− tipc_aead_rcu_swap(rx->aead[key.passive], tmp2, &rx->lock);
1189+ tmp2 = rcu_replace_pointer(rx->aead[key.passive], tmp2, lockdep_is_held(&rx->lock));
11931190 x = (key.passive - key.pending + new_pending) % KEY_MAX;
11941191 new_passive = (x <= 0) ? x + KEY_MAX : x;
11951192 }
tools/testing/selftests/rcutorture/bin/cpus2use.sh+9−2
@@ -15,8 +15,15 @@ then · 14 unmodified lines
1515 exit 0
1616 fi
1717 ncpus=`grep '^processor' /proc/cpuinfo | wc -l`
18−idlecpus=`mpstat | tail -1 | \
19− awk -v ncpus=$ncpus '{ print ncpus * ($7 + $NF) / 100 }'`
18+if mpstat -V > /dev/null 2>&1
19+then
20+ idlecpus=`mpstat | tail -1 | \
21+ awk -v ncpus=$ncpus '{ print ncpus * ($7 + $NF) / 100 }'`
22+else
23+ # No mpstat command, so use all available CPUs.
24+ echo The mpstat command is not available, so greedily using all CPUs.
25+ idlecpus=$ncpus
26+fi
2027 awk -v ncpus=$ncpus -v idlecpus=$idlecpus < /dev/null '
2128 BEGIN {
2229 cpus2use = idlecpus;
tools/testing/selftests/rcutorture/bin/jitter.sh+22−8
@@ -23,25 +23,39 @@ spinmax=${4-1000} · 22 unmodified lines
2323
2424 n=1
2525
26−starttime=`awk 'BEGIN { print systime(); }' < /dev/null`
26+starttime=`gawk 'BEGIN { print systime(); }' < /dev/null`
27+
28+nohotplugcpus=
29+for i in /sys/devices/system/cpu/cpu[0-9]*
30+do
31+ if test -f $i/online
32+ then
33+ :
34+ else
35+ curcpu=`echo $i | sed -e 's/^[^0-9]*//'`
36+ nohotplugcpus="$nohotplugcpus $curcpu"
37+ fi
38+done
2739
2840 while :
2941 do
3042 # Check for done.
31− t=`awk -v s=$starttime 'BEGIN { print systime() - s; }' < /dev/null`
43+ t=`gawk -v s=$starttime 'BEGIN { print systime() - s; }' < /dev/null`
3244 if test "$t" -gt "$duration"
3345 then
3446 exit 0;
3547 fi
3648
3749 # Set affinity to randomly selected online CPU
38− cpus=`grep 1 /sys/devices/system/cpu/*/online |
39− sed -e 's,/[^/]*$,,' -e 's/^[^0-9]*//'`
40−
41− # Do not leave out poor old cpu0 which may not be hot-pluggable
42− if [ ! -f "/sys/devices/system/cpu/cpu0/online" ]; then
43− cpus="0 $cpus"
50+ if cpus=`grep 1 /sys/devices/system/cpu/*/online 2>&1 |
51+ sed -e 's,/[^/]*$,,' -e 's/^[^0-9]*//'`
52+ then
53+ :
54+ else
55+ cpus=
4456 fi
57+ # Do not leave out non-hot-pluggable CPUs
58+ cpus="$cpus $nohotplugcpus"
4559
4660 cpumask=`awk -v cpus="$cpus" -v me=$me -v n=$n 'BEGIN {
4761 srand(n + me + systime());
tools/testing/selftests/rcutorture/bin/kvm-recheck-rcu.sh+2−1
@@ -25,6 +25,7 @@ stopstate="`grep 'End-test grace-period state: g' $i/console.log 2> /dev/null | · 24 unmodified lines
2525 tail -1 | sed -e 's/^\[[ 0-9.]*] //' |
2626 awk '{ print \"[\" $1 \" \" $5 \" \" $6 \" \" $7 \"]\"; }' |
2727 tr -d '\012\015'`"
28+fwdprog="`grep 'rcu_torture_fwd_prog_cr Duration' $i/console.log 2> /dev/null | sed -e 's/^\[[^]]*] //' | sort -k15nr | head -1 | awk '{ print $14 " " $15 }'`"
2829 if test -z "$ngps"
2930 then
3031 echo "$configfile ------- " $stopstate
@@ -39,7 +40,7 @@ else · 8 unmodified lines
3940 BEGIN { print ngps / dur }' < /dev/null`
4041 title="$title ($ngpsps/s)"
4142 fi
42− echo $title $stopstate
43+ echo $title $stopstate $fwdprog
4344 nclosecalls=`grep --binary-files=text 'torture: Reader Batch' $i/console.log | tail -1 | awk '{for (i=NF-8;i<=NF;i++) sum+=$i; } END {print sum}'`
4445 if test -z "$nclosecalls"
4546 then
tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh+6−7
@@ -123,7 +123,7 @@ qemu_args=$5 · 122 unmodified lines
123123 boot_args=$6
124124
125125 cd $KVM
126−kstarttime=`awk 'BEGIN { print systime() }' < /dev/null`
126+kstarttime=`gawk 'BEGIN { print systime() }' < /dev/null`
127127 if test -z "$TORTURE_BUILDONLY"
128128 then
129129 echo ' ---' `date`: Starting kernel
@@ -133,11 +133,10 @@ fi · 3 unmodified lines
133133 qemu_args="-enable-kvm -nographic $qemu_args"
134134 cpu_count=`configNR_CPUS.sh $resdir/ConfigFragment`
135135 cpu_count=`configfrag_boot_cpus "$boot_args" "$config_template" "$cpu_count"`
136−vcpus=`identify_qemu_vcpus`
137−if test $cpu_count -gt $vcpus
136+if test "$cpu_count" -gt "$TORTURE_ALLOTED_CPUS"
138137 then
139− echo CPU count limited from $cpu_count to $vcpus | tee -a $resdir/Warnings
140− cpu_count=$vcpus
138+ echo CPU count limited from $cpu_count to $TORTURE_ALLOTED_CPUS | tee -a $resdir/Warnings
139+ cpu_count=$TORTURE_ALLOTED_CPUS
141140 fi
142141 qemu_args="`specify_qemu_cpus "$QEMU" "$qemu_args" "$cpu_count"`"
143142
@@ -177,7 +176,7 @@ do · 33 unmodified lines
177176 then
178177 qemu_pid=`cat "$resdir/qemu_pid"`
179178 fi
180− kruntime=`awk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
179+ kruntime=`gawk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
181180 if test -z "$qemu_pid" || kill -0 "$qemu_pid" > /dev/null 2>&1
182181 then
183182 if test $kruntime -ge $seconds
@@ -213,7 +212,7 @@ then · 29 unmodified lines
213212 oldline="`tail $resdir/console.log`"
214213 while :
215214 do
216− kruntime=`awk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
215+ kruntime=`gawk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
217216 if kill -0 $qemu_pid > /dev/null 2>&1
218217 then
219218 :
tools/testing/selftests/rcutorture/bin/kvm.sh+21−9
@@ -24,7 +24,9 @@ dur=$((30*60)) · 23 unmodified lines
2424 dryrun=""
2525 KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM
2626 PATH=${KVM}/bin:$PATH; export PATH
27−TORTURE_ALLOTED_CPUS=""
27+. functions.sh
28+
29+TORTURE_ALLOTED_CPUS="`identify_qemu_vcpus`"
2830 TORTURE_DEFCONFIG=defconfig
2931 TORTURE_BOOT_IMAGE=""
3032 TORTURE_INITRD="$KVM/initrd"; export TORTURE_INITRD
@@ -40,8 +42,6 @@ cpus=0 · 9 unmodified lines
4042 ds=`date +%Y.%m.%d-%H:%M:%S`
4143 jitter="-1"
4244
43−. functions.sh
44−
4545 usage () {
4646 echo "Usage: $scriptname optional arguments:"
4747 echo " --bootargs kernel-boot-arguments"
@@ -93,6 +93,11 @@ do · 45 unmodified lines
9393 checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
9494 cpus=$2
9595 TORTURE_ALLOTED_CPUS="$2"
96+ max_cpus="`identify_qemu_vcpus`"
97+ if test "$TORTURE_ALLOTED_CPUS" -gt "$max_cpus"
98+ then
99+ TORTURE_ALLOTED_CPUS=$max_cpus
100+ fi
96101 shift
97102 ;;
98103 --datestamp)
@@ -198,9 +203,10 @@ fi · 99 unmodified lines
198203
199204 CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG
200205
206+defaultconfigs="`tr '\012' ' ' < $CONFIGFRAG/CFLIST`"
201207 if test -z "$configs"
202208 then
203− configs="`cat $CONFIGFRAG/CFLIST`"
209+ configs=$defaultconfigs
204210 fi
205211
206212 if test -z "$resdir"
@@ -209,7 +215,7 @@ then · 2 unmodified lines
209215 fi
210216
211217 # Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
212−touch $T/cfgcpu
218+configs_derep=
213219 for CF in $configs
214220 do
215221 case $CF in
@@ -222,15 +228,21 @@ do · 6 unmodified lines
222228 CF1=$CF
223229 ;;
224230 esac
231+ for ((cur_rep=0;cur_rep<$config_reps;cur_rep++))
232+ do
233+ configs_derep="$configs_derep $CF1"
234+ done
235+done
236+touch $T/cfgcpu
237+configs_derep="`echo $configs_derep | sed -e "s/\<CFLIST\>/$defaultconfigs/g"`"
238+for CF1 in $configs_derep
239+do
225240 if test -f "$CONFIGFRAG/$CF1"
226241 then
227242 cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
228243 cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
229244 cpu_count=`configfrag_boot_maxcpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
230− for ((cur_rep=0;cur_rep<$config_reps;cur_rep++))
231− do
232− echo $CF1 $cpu_count >> $T/cfgcpu
233− done
245+ echo $CF1 $cpu_count >> $T/cfgcpu
234246 else
235247 echo "The --configs file $CF1 does not exist, terminating."
236248 exit 1
tools/testing/selftests/rcutorture/bin/mkinitrd.sh+3−52
@@ -20,58 +20,9 @@ if [ -s "$D/initrd/init" ]; then · 19 unmodified lines
2020 exit 0
2121 fi
2222
23−T=${TMPDIR-/tmp}/mkinitrd.sh.$$
24−trap 'rm -rf $T' 0 2
25−mkdir $T
26−
27−cat > $T/init << '__EOF___'
28−#!/bin/sh
29−# Run in userspace a few milliseconds every second. This helps to
30−# exercise the NO_HZ_FULL portions of RCU. The 192 instances of "a" was
31−# empirically shown to give a nice multi-millisecond burst of user-mode
32−# execution on a 2GHz CPU, as desired. Modern CPUs will vary from a
33−# couple of milliseconds up to perhaps 100 milliseconds, which is an
34−# acceptable range.
35−#
36−# Why not calibrate an exact delay? Because within this initrd, we
37−# are restricted to Bourne-shell builtins, which as far as I know do not
38−# provide any means of obtaining a fine-grained timestamp.
39−
40−a4="a a a a"
41−a16="$a4 $a4 $a4 $a4"
42−a64="$a16 $a16 $a16 $a16"
43−a192="$a64 $a64 $a64"
44−while :
45−do
46− q=
47− for i in $a192
48− do
49− q="$q $i"
50− done
51− sleep 1
52−done
53−__EOF___
54−
55−# Try using dracut to create initrd
56−if command -v dracut >/dev/null 2>&1
57−then
58− echo Creating $D/initrd using dracut.
59− # Filesystem creation
60− dracut --force --no-hostonly --no-hostonly-cmdline --module "base" $T/initramfs.img
61− cd $D
62− mkdir -p initrd
63− cd initrd
64− zcat $T/initramfs.img | cpio -id
65− cp $T/init init
66− chmod +x init
67− echo Done creating $D/initrd using dracut
68− exit 0
69−fi
70−
71−# No dracut, so create a C-language initrd/init program and statically
72−# link it. This results in a very small initrd, but might be a bit less
73−# future-proof than dracut.
74−echo "Could not find dracut, attempting C initrd"
23+# Create a C-language initrd/init infinite-loop program and statically
24+# link it. This results in a very small initrd.
25+echo "Creating a statically linked C-language initrd"
7526 cd $D
7627 mkdir -p initrd
7728 cd initrd