History

Merge branch 'for-mingo' of git://git.kernel.org/pub/scm/linux/kernel/git/paulmck/linux-rcu into core/rcu

Pull RCU updates from Paul E. McKenney: - Expedited grace-period updates - kfree_rcu() updates - RCU list updates - Preemptible RCU updates - Torture-test updates - Miscellaneous fixes - Documentation updates

Ingo Molnar committed 6 years ago

Commit f8a4bb62 parents 4703d91 0e2473846 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
@@ -209,6 +209,10 @@ Paolo 'Blaisorblade' Giarrusso <blaisorblade@yahoo.it> · 208 unmodified lines
209Patrick Mochel <mochel@digitalimplant.org>209Patrick Mochel <mochel@digitalimplant.org>
210Paul Burton <paulburton@kernel.org> <paul.burton@imgtec.com>210Paul Burton <paulburton@kernel.org> <paul.burton@imgtec.com>
211Paul Burton <paulburton@kernel.org> <paul.burton@mips.com>211Paul Burton <paulburton@kernel.org> <paul.burton@mips.com>
212Paul E. McKenney <paulmck@kernel.org> <paulmck@linux.ibm.com>
213Paul E. McKenney <paulmck@kernel.org> <paulmck@linux.vnet.ibm.com>
214Paul E. McKenney <paulmck@kernel.org> <paul.mckenney@linaro.org>
215Paul E. McKenney <paulmck@kernel.org> <paulmck@us.ibm.com>
212Peter A Jonsson <pj@ludd.ltu.se>216Peter A Jonsson <pj@ludd.ltu.se>
213Peter Oruba <peter@oruba.de>217Peter Oruba <peter@oruba.de>
214Peter Oruba <peter.oruba@amd.com>218Peter 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
1Using RCU to Protect Dynamic NMI Handlers3Using RCU to Protect Dynamic NMI Handlers
4=========================================
2 5
3 6
4Although RCU is usually used to protect read-mostly data structures,7Although 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
9"arch/x86/kernel/traps.c".12"arch/x86/kernel/traps.c".
10 13
11The relevant pieces of code are listed below, each followed by a14The relevant pieces of code are listed below, each followed by a
12brief explanation.15brief explanation::
13 16
14 static int dummy_nmi_callback(struct pt_regs *regs, int cpu)17 static int dummy_nmi_callback(struct pt_regs *regs, int cpu)
15 {18 {
@@ -18,12 +21,12 @@ brief explanation. · 2 unmodified lines
18 21
19The dummy_nmi_callback() function is a "dummy" NMI handler that does22The dummy_nmi_callback() function is a "dummy" NMI handler that does
20nothing, but returns zero, thus saying that it did nothing, allowing23nothing, but returns zero, thus saying that it did nothing, allowing
21the NMI handler to take the default machine-specific action.24the NMI handler to take the default machine-specific action::
22 25
23 static nmi_callback_t nmi_callback = dummy_nmi_callback;26 static nmi_callback_t nmi_callback = dummy_nmi_callback;
24 27
25This nmi_callback variable is a global function pointer to the current28This nmi_callback variable is a global function pointer to the current
26NMI handler.29NMI handler::
27 30
28 void do_nmi(struct pt_regs * regs, long error_code)31 void do_nmi(struct pt_regs * regs, long error_code)
29 {32 {
@@ -53,11 +56,12 @@ anyway. However, in practice it is a good documentation aid, particularly · 23 unmodified lines
53for anyone attempting to do something similar on Alpha or on systems56for anyone attempting to do something similar on Alpha or on systems
54with aggressive optimizing compilers.57with aggressive optimizing compilers.
55 58
56Quick Quiz: Why might the rcu_dereference_sched() be necessary on Alpha,59Quick Quiz:
57 given that the code referenced by the pointer is read-only?60 Why might the rcu_dereference_sched() be necessary on Alpha, given that the code referenced by the pointer is read-only?
58 61
62:ref:`Answer to Quick Quiz <answer_quick_quiz_NMI>`
59 63
60Back to the discussion of NMI and RCU...64Back to the discussion of NMI and RCU::
61 65
62 void set_nmi_callback(nmi_callback_t callback)66 void set_nmi_callback(nmi_callback_t callback)
63 {67 {
@@ -68,7 +72,7 @@ The set_nmi_callback() function registers an NMI handler. Note that any · 4 unmodified lines
68data that is to be used by the callback must be initialized up -before-72data that is to be used by the callback must be initialized up -before-
69the call to set_nmi_callback(). On architectures that do not order73the call to set_nmi_callback(). On architectures that do not order
70writes, the rcu_assign_pointer() ensures that the NMI handler sees the74writes, the rcu_assign_pointer() ensures that the NMI handler sees the
71initialized values.75initialized values::
72 76
73 void unset_nmi_callback(void)77 void unset_nmi_callback(void)
74 {78 {
@@ -82,7 +86,7 @@ up any data structures used by the old NMI handler until execution · 7 unmodified lines
82of it completes on all other CPUs.86of it completes on all other CPUs.
83 87
84One way to accomplish this is via synchronize_rcu(), perhaps as88One way to accomplish this is via synchronize_rcu(), perhaps as
85follows:89follows::
86 90
87 unset_nmi_callback();91 unset_nmi_callback();
88 synchronize_rcu();92 synchronize_rcu();
@@ -98,24 +102,23 @@ to free up the handler's data as soon as synchronize_rcu() returns. · 9 unmodified lines
98Important note: for this to work, the architecture in question must102Important note: for this to work, the architecture in question must
99invoke nmi_enter() and nmi_exit() on NMI entry and exit, respectively.103invoke nmi_enter() and nmi_exit() on NMI entry and exit, respectively.
100 104
105.. _answer_quick_quiz_NMI:
101 106
102Answer to Quick Quiz107Answer to Quick Quiz:
103 108 Why might the rcu_dereference_sched() be necessary on Alpha, given that the code referenced by the pointer is read-only?
104 Why might the rcu_dereference_sched() be necessary on Alpha, given
105 that the code referenced by the pointer is read-only?
106 109
107 Answer: The caller to set_nmi_callback() might well have110 The caller to set_nmi_callback() might well have
108 initialized some data that is to be used by the new NMI111 initialized some data that is to be used by the new NMI
109 handler. In this case, the rcu_dereference_sched() would112 handler. In this case, the rcu_dereference_sched() would
110 be needed, because otherwise a CPU that received an NMI113 be needed, because otherwise a CPU that received an NMI
111 just after the new handler was set might see the pointer114 just after the new handler was set might see the pointer
112 to the new NMI handler, but the old pre-initialized115 to the new NMI handler, but the old pre-initialized
113 version of the handler's data.116 version of the handler's data.
114 117
115 This same sad story can happen on other CPUs when using118 This same sad story can happen on other CPUs when using
116 a compiler with aggressive pointer-value speculation119 a compiler with aggressive pointer-value speculation
117 optimizations.120 optimizations.
118 121
119 More important, the rcu_dereference_sched() makes it122 More important, the rcu_dereference_sched() makes it
120 clear to someone reading the code that the pointer is123 clear to someone reading the code that the pointer is
121 being protected by RCU-sched.124 being protected by RCU-sched.
Documentation/RCU/arrayRCU.rstrenamed from Documentation/RCU/arrayRCU.txt+23−11
@@ -1,19 +1,21 @@
1Using RCU to Protect Read-Mostly Arrays1.. _array_rcu_doc:
2 2
3Using RCU to Protect Read-Mostly Arrays
4=======================================
3 5
4Although RCU is more commonly used to protect linked lists, it can6Although RCU is more commonly used to protect linked lists, it can
5also be used to protect arrays. Three situations are as follows:7also be used to protect arrays. Three situations are as follows:
6 8
71. Hash Tables91. :ref:`Hash Tables <hash_tables>`
8 10
92. Static Arrays112. :ref:`Static Arrays <static_arrays>`
10 12
113. Resizeable Arrays133. :ref:`Resizable Arrays <resizable_arrays>`
12 14
13Each of these three situations involves an RCU-protected pointer to an15Each of these three situations involves an RCU-protected pointer to an
14array that is separately indexed. It might be tempting to consider use16array that is separately indexed. It might be tempting to consider use
15of RCU to instead protect the index into an array, however, this use17of RCU to instead protect the index into an array, however, this use
16case is -not- supported. The problem with RCU-protected indexes into18case is **not** supported. The problem with RCU-protected indexes into
17arrays is that compilers can play way too many optimization games with19arrays is that compilers can play way too many optimization games with
18integers, which means that the rules governing handling of these indexes20integers, which means that the rules governing handling of these indexes
19are far more trouble than they are worth. If RCU-protected indexes into21are far more trouble than they are worth. If RCU-protected indexes into
@@ -24,16 +26,20 @@ to be safely used. · 4 unmodified lines
24That aside, each of the three RCU-protected pointer situations are26That aside, each of the three RCU-protected pointer situations are
25described in the following sections.27described in the following sections.
26 28
29.. _hash_tables:
27 30
28Situation 1: Hash Tables31Situation 1: Hash Tables
32------------------------
29 33
30Hash tables are often implemented as an array, where each array entry34Hash tables are often implemented as an array, where each array entry
31has a linked-list hash chain. Each hash chain can be protected by RCU35has a linked-list hash chain. Each hash chain can be protected by RCU
32as described in the listRCU.txt document. This approach also applies36as described in the listRCU.txt document. This approach also applies
33to other array-of-list situations, such as radix trees.37to other array-of-list situations, such as radix trees.
34 38
39.. _static_arrays:
35 40
36Situation 2: Static Arrays41Situation 2: Static Arrays
42--------------------------
37 43
38Static arrays, where the data (rather than a pointer to the data) is44Static arrays, where the data (rather than a pointer to the data) is
39located in each array element, and where the array is never resized,45located 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
41this situation, which would also have minimal read-side overhead as long47this situation, which would also have minimal read-side overhead as long
42as updates are rare.48as updates are rare.
43 49
44Quick Quiz: Why is it so important that updates be rare when50Quick Quiz:
45 using seqlock?51 Why is it so important that updates be rare when using seqlock?
52
53:ref:`Answer to Quick Quiz <answer_quick_quiz_seqlock>`
46 54
55.. _resizable_arrays:
47 56
48Situation 3: Resizeable Arrays57Situation 3: Resizable Arrays
58------------------------------
49 59
50Use of RCU for resizeable arrays is demonstrated by the grow_ary()60Use of RCU for resizable arrays is demonstrated by the grow_ary()
51function formerly used by the System V IPC code. The array is used61function formerly used by the System V IPC code. The array is used
52to map from semaphore, message-queue, and shared-memory IDs to the data62to map from semaphore, message-queue, and shared-memory IDs to the data
53structure that represents the corresponding IPC construct. The grow_ary()63structure 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
60the new array, and invokes ipc_rcu_putref() to free up the old array.70the new array, and invokes ipc_rcu_putref() to free up the old array.
61Note that rcu_assign_pointer() is used to update the ids->entries pointer,71Note that rcu_assign_pointer() is used to update the ids->entries pointer,
62which includes any memory barriers required on whatever architecture72which includes any memory barriers required on whatever architecture
63you are running on.73you are running on::
64 74
65 static int grow_ary(struct ipc_ids* ids, int newsize)75 static int grow_ary(struct ipc_ids* ids, int newsize)
66 {76 {
@@ -112,7 +122,7 @@ a simple check suffices. The pointer to the structure corresponding · 45 unmodified lines
112to the desired IPC object is placed in "out", with NULL indicating122to the desired IPC object is placed in "out", with NULL indicating
113a non-existent entry. After acquiring "out->lock", the "out->deleted"123a non-existent entry. After acquiring "out->lock", the "out->deleted"
114flag indicates whether the IPC object is in the process of being124flag indicates whether the IPC object is in the process of being
115deleted, and, if not, the pointer is returned.125deleted, and, if not, the pointer is returned::
116 126
117 struct kern_ipc_perm* ipc_lock(struct ipc_ids* ids, int id)127 struct kern_ipc_perm* ipc_lock(struct ipc_ids* ids, int id)
118 {128 {
@@ -144,8 +154,10 @@ deleted, and, if not, the pointer is returned. · 25 unmodified lines
144 return out;154 return out;
145 }155 }
146 156
157.. _answer_quick_quiz_seqlock:
147 158
148Answer to Quick Quiz:159Answer to Quick Quiz:
160 Why is it so important that updates be rare when using seqlock?
149 161
150 The reason that it is important that updates be rare when162 The reason that it is important that updates be rare when
151 using seqlock is that frequent updates can livelock readers.163 using seqlock is that frequent updates can livelock readers.
Documentation/RCU/index.rst+5−0
@@ -7,8 +7,13 @@ RCU concepts · 6 unmodified lines
7.. toctree::7.. toctree::
8 :maxdepth: 38 :maxdepth: 3
9 9
10 arrayRCU
11 rcubarrier
12 rcu_dereference
13 whatisRCU
10 rcu14 rcu
11 listRCU15 listRCU
16 NMI-RCU
12 UP17 UP
13 18
14 Design/Memory-Ordering/Tree-RCU-Memory-Ordering19 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
99read-side critical section, which again would have suppressed the99read-side critical section, which again would have suppressed the
100above lockdep-RCU splat.100above lockdep-RCU splat.
101 101
102But in this particular case, we don't actually deference the pointer102But in this particular case, we don't actually dereference the pointer
103returned from rcu_dereference(). Instead, that pointer is just compared103returned from rcu_dereference(). Instead, that pointer is just compared
104to the cic pointer, which means that the rcu_dereference() can be replaced104to the cic pointer, which means that the rcu_dereference() can be replaced
105by rcu_access_pointer() as follows:105by 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
1PROPER CARE AND FEEDING OF RETURN VALUES FROM rcu_dereference()3PROPER CARE AND FEEDING OF RETURN VALUES FROM rcu_dereference()
4===============================================================
2 5
3Most of the time, you can use values from rcu_dereference() or one of6Most of the time, you can use values from rcu_dereference() or one of
4the similar primitives without worries. Dereferencing (prefix "*"),7the similar primitives without worries. Dereferencing (prefix "*"),
@@ -8,7 +11,7 @@ subtraction of constants, and casts all work quite naturally and safely. · 3 unmodified lines
8It is nevertheless possible to get into trouble with other operations.11It is nevertheless possible to get into trouble with other operations.
9Follow these rules to keep your RCU code working properly:12Follow these rules to keep your RCU code working properly:
10 13
11o You must use one of the rcu_dereference() family of primitives14- You must use one of the rcu_dereference() family of primitives
12 to load an RCU-protected pointer, otherwise CONFIG_PROVE_RCU15 to load an RCU-protected pointer, otherwise CONFIG_PROVE_RCU
13 will complain. Worse yet, your code can see random memory-corruption16 will complain. Worse yet, your code can see random memory-corruption
14 bugs due to games that compilers and DEC Alpha can play.17 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
25 for an example where the compiler can in fact deduce the exact28 for an example where the compiler can in fact deduce the exact
26 value of the pointer, and thus cause misordering.29 value of the pointer, and thus cause misordering.
27 30
28o You are only permitted to use rcu_dereference on pointer values.31- You are only permitted to use rcu_dereference on pointer values.
29 The compiler simply knows too much about integral values to32 The compiler simply knows too much about integral values to
30 trust it to carry dependencies through integer operations.33 trust it to carry dependencies through integer operations.
31 There are a very few exceptions, namely that you can temporarily34 There are a very few exceptions, namely that you can temporarily
32 cast the pointer to uintptr_t in order to:35 cast the pointer to uintptr_t in order to:
33 36
34 o Set bits and clear bits down in the must-be-zero low-order37 - Set bits and clear bits down in the must-be-zero low-order
35 bits of that pointer. This clearly means that the pointer38 bits of that pointer. This clearly means that the pointer
36 must have alignment constraints, for example, this does39 must have alignment constraints, for example, this does
37 -not- work in general for char* pointers.40 -not- work in general for char* pointers.
38 41
39 o XOR bits to translate pointers, as is done in some42 - XOR bits to translate pointers, as is done in some
40 classic buddy-allocator algorithms.43 classic buddy-allocator algorithms.
41 44
42 It is important to cast the value back to pointer before45 It is important to cast the value back to pointer before
43 doing much of anything else with it.46 doing much of anything else with it.
44 47
45o Avoid cancellation when using the "+" and "-" infix arithmetic48- Avoid cancellation when using the "+" and "-" infix arithmetic
46 operators. For example, for a given variable "x", avoid49 operators. For example, for a given variable "x", avoid
47 "(x-(uintptr_t)x)" for char* pointers. The compiler is within its50 "(x-(uintptr_t)x)" for char* pointers. The compiler is within its
48 rights to substitute zero for this sort of expression, so that51 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
54 "p+a-b" is safe because its value still necessarily depends on57 "p+a-b" is safe because its value still necessarily depends on
55 the rcu_dereference(), thus maintaining proper ordering.58 the rcu_dereference(), thus maintaining proper ordering.
56 59
57o If you are using RCU to protect JITed functions, so that the60- If you are using RCU to protect JITed functions, so that the
58 "()" function-invocation operator is applied to a value obtained61 "()" function-invocation operator is applied to a value obtained
59 (directly or indirectly) from rcu_dereference(), you may need to62 (directly or indirectly) from rcu_dereference(), you may need to
60 interact directly with the hardware to flush instruction caches.63 interact directly with the hardware to flush instruction caches.
61 This issue arises on some systems when a newly JITed function is64 This issue arises on some systems when a newly JITed function is
62 using the same memory that was used by an earlier JITed function.65 using the same memory that was used by an earlier JITed function.
63 66
64o Do not use the results from relational operators ("==", "!=",67- Do not use the results from relational operators ("==", "!=",
65 ">", ">=", "<", or "<=") when dereferencing. For example,68 ">", ">=", "<", or "<=") when dereferencing. For example,
66 the following (quite strange) code is buggy:69 the following (quite strange) code is buggy::
67 70
68 int *p;71 int *p;
69 int *q;72 int *q;
@@ -81,11 +84,11 @@ o Do not use the results from relational operators ("==", "!=", · 11 unmodified lines
81 after such branches, but can speculate loads, which can again84 after such branches, but can speculate loads, which can again
82 result in misordering bugs.85 result in misordering bugs.
83 86
84o Be very careful about comparing pointers obtained from87- Be very careful about comparing pointers obtained from
85 rcu_dereference() against non-NULL values. As Linus Torvalds88 rcu_dereference() against non-NULL values. As Linus Torvalds
86 explained, if the two pointers are equal, the compiler could89 explained, if the two pointers are equal, the compiler could
87 substitute the pointer you are comparing against for the pointer90 substitute the pointer you are comparing against for the pointer
88 obtained from rcu_dereference(). For example:91 obtained from rcu_dereference(). For example::
89 92
90 p = rcu_dereference(gp);93 p = rcu_dereference(gp);
91 if (p == &default_struct)94 if (p == &default_struct)
@@ -93,7 +96,7 @@ o Be very careful about comparing pointers obtained from · 1 unmodified line
93 96
94 Because the compiler now knows that the value of "p" is exactly97 Because the compiler now knows that the value of "p" is exactly
95 the address of the variable "default_struct", it is free to98 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::
97 100
98 p = rcu_dereference(gp);101 p = rcu_dereference(gp);
99 if (p == &default_struct)102 if (p == &default_struct)
@@ -105,14 +108,14 @@ o Be very careful about comparing pointers obtained from · 5 unmodified lines
105 108
106 However, comparisons are OK in the following cases:109 However, comparisons are OK in the following cases:
107 110
108 o The comparison was against the NULL pointer. If the111 - The comparison was against the NULL pointer. If the
109 compiler knows that the pointer is NULL, you had better112 compiler knows that the pointer is NULL, you had better
110 not be dereferencing it anyway. If the comparison is113 not be dereferencing it anyway. If the comparison is
111 non-equal, the compiler is none the wiser. Therefore,114 non-equal, the compiler is none the wiser. Therefore,
112 it is safe to compare pointers from rcu_dereference()115 it is safe to compare pointers from rcu_dereference()
113 against NULL pointers.116 against NULL pointers.
114 117
115 o The pointer is never dereferenced after being compared.118 - The pointer is never dereferenced after being compared.
116 Since there are no subsequent dereferences, the compiler119 Since there are no subsequent dereferences, the compiler
117 cannot use anything it learned from the comparison120 cannot use anything it learned from the comparison
118 to reorder the non-existent subsequent dereferences.121 to reorder the non-existent subsequent dereferences.
@@ -124,31 +127,31 @@ o Be very careful about comparing pointers obtained from · 5 unmodified lines
124 dereferenced, rcu_access_pointer() should be used in place127 dereferenced, rcu_access_pointer() should be used in place
125 of rcu_dereference().128 of rcu_dereference().
126 129
127 o The comparison is against a pointer that references memory130 - The comparison is against a pointer that references memory
128 that was initialized "a long time ago." The reason131 that was initialized "a long time ago." The reason
129 this is safe is that even if misordering occurs, the132 this is safe is that even if misordering occurs, the
130 misordering will not affect the accesses that follow133 misordering will not affect the accesses that follow
131 the comparison. So exactly how long ago is "a long134 the comparison. So exactly how long ago is "a long
132 time ago"? Here are some possibilities:135 time ago"? Here are some possibilities:
133 136
134 o Compile time.137 - Compile time.
135 138
136 o Boot time.139 - Boot time.
137 140
138 o Module-init time for module code.141 - Module-init time for module code.
139 142
140 o Prior to kthread creation for kthread code.143 - Prior to kthread creation for kthread code.
141 144
142 o During some prior acquisition of the lock that145 - During some prior acquisition of the lock that
143 we now hold.146 we now hold.
144 147
145 o Before mod_timer() time for a timer handler.148 - Before mod_timer() time for a timer handler.
146 149
147 There are many other possibilities involving the Linux150 There are many other possibilities involving the Linux
148 kernel's wide array of primitives that cause code to151 kernel's wide array of primitives that cause code to
149 be invoked at a later time.152 be invoked at a later time.
150 153
151 o The pointer being compared against also came from154 - The pointer being compared against also came from
152 rcu_dereference(). In this case, both pointers depend155 rcu_dereference(). In this case, both pointers depend
153 on one rcu_dereference() or another, so you get proper156 on one rcu_dereference() or another, so you get proper
154 ordering either way.157 ordering either way.
@@ -159,13 +162,13 @@ o Be very careful about comparing pointers obtained from · 4 unmodified lines
159 of such an RCU usage bug is shown in the section titled162 of such an RCU usage bug is shown in the section titled
160 "EXAMPLE OF AMPLIFIED RCU-USAGE BUG".163 "EXAMPLE OF AMPLIFIED RCU-USAGE BUG".
161 164
162 o All of the accesses following the comparison are stores,165 - All of the accesses following the comparison are stores,
163 so that a control dependency preserves the needed ordering.166 so that a control dependency preserves the needed ordering.
164 That said, it is easy to get control dependencies wrong.167 That said, it is easy to get control dependencies wrong.
165 Please see the "CONTROL DEPENDENCIES" section of168 Please see the "CONTROL DEPENDENCIES" section of
166 Documentation/memory-barriers.txt for more details.169 Documentation/memory-barriers.txt for more details.
167 170
168 o The pointers are not equal -and- the compiler does171 - The pointers are not equal -and- the compiler does
169 not have enough information to deduce the value of the172 not have enough information to deduce the value of the
170 pointer. Note that the volatile cast in rcu_dereference()173 pointer. Note that the volatile cast in rcu_dereference()
171 will normally prevent the compiler from knowing too much.174 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
175 comparison will provide exactly the information that the178 comparison will provide exactly the information that the
176 compiler needs to deduce the value of the pointer.179 compiler needs to deduce the value of the pointer.
177 180
178o Disable any value-speculation optimizations that your compiler181- Disable any value-speculation optimizations that your compiler
179 might provide, especially if you are making use of feedback-based182 might provide, especially if you are making use of feedback-based
180 optimizations that take data collected from prior runs. Such183 optimizations that take data collected from prior runs. Such
181 value-speculation optimizations reorder operations by design.184 value-speculation optimizations reorder operations by design.
@@ -188,11 +191,12 @@ o Disable any value-speculation optimizations that your compiler · 6 unmodified lines
188 191
189 192
190EXAMPLE OF AMPLIFIED RCU-USAGE BUG193EXAMPLE OF AMPLIFIED RCU-USAGE BUG
194----------------------------------
191 195
192Because updaters can run concurrently with RCU readers, RCU readers can196Because updaters can run concurrently with RCU readers, RCU readers can
193see stale and/or inconsistent values. If RCU readers need fresh or197see stale and/or inconsistent values. If RCU readers need fresh or
194consistent values, which they sometimes do, they need to take proper198consistent values, which they sometimes do, they need to take proper
195precautions. To see this, consider the following code fragment:199precautions. To see this, consider the following code fragment::
196 200
197 struct foo {201 struct foo {
198 int a;202 int a;
@@ -244,7 +248,7 @@ to some reordering from the compiler and CPUs is beside the point. · 45 unmodified lines
244 248
245But suppose that the reader needs a consistent view?249But suppose that the reader needs a consistent view?
246 250
247Then one approach is to use locking, for example, as follows:251Then one approach is to use locking, for example, as follows::
248 252
249 struct foo {253 struct foo {
250 int a;254 int a;
@@ -299,6 +303,7 @@ As always, use the right tool for the job! · 48 unmodified lines
299 303
300 304
301EXAMPLE WHERE THE COMPILER KNOWS TOO MUCH305EXAMPLE WHERE THE COMPILER KNOWS TOO MUCH
306-----------------------------------------
302 307
303If a pointer obtained from rcu_dereference() compares not-equal to some308If a pointer obtained from rcu_dereference() compares not-equal to some
304other pointer, the compiler normally has no clue what the value of the309other 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
308should prevent the compiler from guessing the value.313should prevent the compiler from guessing the value.
309 314
310But without rcu_dereference(), the compiler knows more than you might315But without rcu_dereference(), the compiler knows more than you might
311expect. Consider the following code fragment:316expect. Consider the following code fragment::
312 317
313 struct foo {318 struct foo {
314 int a;319 int a;
@@ -354,6 +359,7 @@ dereference the resulting pointer. · 39 unmodified lines
354 359
355 360
356WHICH MEMBER OF THE rcu_dereference() FAMILY SHOULD YOU USE?361WHICH MEMBER OF THE rcu_dereference() FAMILY SHOULD YOU USE?
362------------------------------------------------------------
357 363
358First, please avoid using rcu_dereference_raw() and also please avoid364First, please avoid using rcu_dereference_raw() and also please avoid
359using rcu_dereference_check() and rcu_dereference_protected() with a365using 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
370 376
3712. If the access might be within an RCU read-side critical section3772. If the access might be within an RCU read-side critical section
372 on the one hand, or protected by (say) my_lock on the other,378 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::
374 380
375 p1 = rcu_dereference_check(p->rcu_protected_pointer,381 p1 = rcu_dereference_check(p->rcu_protected_pointer,
376 lockdep_is_held(&my_lock));382 lockdep_is_held(&my_lock));
@@ -378,14 +384,14 @@ member of the rcu_dereference() to use in various situations: · 1 unmodified line
378 384
3793. If the access might be within an RCU read-side critical section3853. If the access might be within an RCU read-side critical section
380 on the one hand, or protected by either my_lock or your_lock on386 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::
382 388
383 p1 = rcu_dereference_check(p->rcu_protected_pointer,389 p1 = rcu_dereference_check(p->rcu_protected_pointer,
384 lockdep_is_held(&my_lock) ||390 lockdep_is_held(&my_lock) ||
385 lockdep_is_held(&your_lock));391 lockdep_is_held(&your_lock));
386 392
3874. If the access is on the update side, so that it is always protected3934. 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()::
389 395
390 p1 = rcu_dereference_protected(p->rcu_protected_pointer,396 p1 = rcu_dereference_protected(p->rcu_protected_pointer,
391 lockdep_is_held(&my_lock));397 lockdep_is_held(&my_lock));
@@ -410,18 +416,19 @@ member of the rcu_dereference() to use in various situations: · 18 unmodified lines
410 416
411 417
412SPARSE CHECKING OF RCU-PROTECTED POINTERS418SPARSE CHECKING OF RCU-PROTECTED POINTERS
419-----------------------------------------
413 420
414The sparse static-analysis tool checks for direct access to RCU-protected421The sparse static-analysis tool checks for direct access to RCU-protected
415pointers, which can result in "interesting" bugs due to compiler422pointers, which can result in "interesting" bugs due to compiler
416optimizations involving invented loads and perhaps also load tearing.423optimizations involving invented loads and perhaps also load tearing.
417For example, suppose someone mistakenly does something like this:424For example, suppose someone mistakenly does something like this::
418 425
419 p = q->rcu_protected_pointer;426 p = q->rcu_protected_pointer;
420 do_something_with(p->a);427 do_something_with(p->a);
421 do_something_else_with(p->b);428 do_something_else_with(p->b);
422 429
423If register pressure is high, the compiler might optimize "p" out430If register pressure is high, the compiler might optimize "p" out
424of existence, transforming the code to something like this:431of existence, transforming the code to something like this::
425 432
426 do_something_with(q->rcu_protected_pointer->a);433 do_something_with(q->rcu_protected_pointer->a);
427 do_something_else_with(q->rcu_protected_pointer->b);434 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
435of pointers, which also might fatally disappoint your code.442of pointers, which also might fatally disappoint your code.
436 443
437These problems could have been avoided simply by making the code instead444These problems could have been avoided simply by making the code instead
438read as follows:445read as follows::
439 446
440 p = rcu_dereference(q->rcu_protected_pointer);447 p = rcu_dereference(q->rcu_protected_pointer);
441 do_something_with(p->a);448 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
448this pointer is accessed directly. It will also cause sparse to complain455this pointer is accessed directly. It will also cause sparse to complain
449if a pointer not marked with "__rcu" is accessed using rcu_dereference()456if a pointer not marked with "__rcu" is accessed using rcu_dereference()
450and friends. For example, ->rcu_protected_pointer might be declared as457and friends. For example, ->rcu_protected_pointer might be declared as
451follows:458follows::
452 459
453 struct foo __rcu *rcu_protected_pointer;460 struct foo __rcu *rcu_protected_pointer;
454 461
Documentation/RCU/rcubarrier.rstrenamed from Documentation/RCU/rcubarrier.txt+125−97
@@ -1,4 +1,7 @@
1.. _rcu_barrier:
2
1RCU and Unloadable Modules3RCU and Unloadable Modules
4==========================
2 5
3[Originally published in LWN Jan. 14, 2007: http://lwn.net/Articles/217484/]6[Originally published in LWN Jan. 14, 2007: http://lwn.net/Articles/217484/]
4 7
@@ -21,7 +24,7 @@ given that readers might well leave absolutely no trace of their · 16 unmodified lines
21presence? There is a synchronize_rcu() primitive that blocks until all24presence? There is a synchronize_rcu() primitive that blocks until all
22pre-existing readers have completed. An updater wishing to delete an25pre-existing readers have completed. An updater wishing to delete an
23element p from a linked list might do the following, while holding an26element p from a linked list might do the following, while holding an
24appropriate lock, of course:27appropriate lock, of course::
25 28
26 list_del_rcu(p);29 list_del_rcu(p);
27 synchronize_rcu();30 synchronize_rcu();
@@ -32,13 +35,13 @@ primitive must be used instead. This primitive takes a pointer to an · 4 unmodified lines
32rcu_head struct placed within the RCU-protected data structure and35rcu_head struct placed within the RCU-protected data structure and
33another pointer to a function that may be invoked later to free that36another pointer to a function that may be invoked later to free that
34structure. Code to delete an element p from the linked list from IRQ37structure. Code to delete an element p from the linked list from IRQ
35context might then be as follows:38context might then be as follows::
36 39
37 list_del_rcu(p);40 list_del_rcu(p);
38 call_rcu(&p->rcu, p_callback);41 call_rcu(&p->rcu, p_callback);
39 42
40Since call_rcu() never blocks, this code can safely be used from within43Since call_rcu() never blocks, this code can safely be used from within
41IRQ context. The function p_callback() might be defined as follows:44IRQ context. The function p_callback() might be defined as follows::
42 45
43 static void p_callback(struct rcu_head *rp)46 static void p_callback(struct rcu_head *rp)
44 {47 {
@@ -49,6 +52,7 @@ IRQ context. The function p_callback() might be defined as follows: · 4 unmodified lines
49 52
50 53
51Unloading Modules That Use call_rcu()54Unloading Modules That Use call_rcu()
55-------------------------------------
52 56
53But what if p_callback is defined in an unloadable module?57But what if p_callback is defined in an unloadable module?
54 58
@@ -69,10 +73,11 @@ in realtime kernels in order to avoid excessive scheduling latencies. · 14 unmodified lines
69 73
70 74
71rcu_barrier()75rcu_barrier()
76-------------
72 77
73We instead need the rcu_barrier() primitive. Rather than waiting for78We instead need the rcu_barrier() primitive. Rather than waiting for
74a grace period to elapse, rcu_barrier() waits for all outstanding RCU79a grace period to elapse, rcu_barrier() waits for all outstanding RCU
75callbacks to complete. Please note that rcu_barrier() does -not- imply80callbacks to complete. Please note that rcu_barrier() does **not** imply
76synchronize_rcu(), in particular, if there are no RCU callbacks queued81synchronize_rcu(), in particular, if there are no RCU callbacks queued
77anywhere, rcu_barrier() is within its rights to return immediately,82anywhere, rcu_barrier() is within its rights to return immediately,
78without waiting for a grace period to elapse.83without 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
88module uses multiple flavors of call_rcu(), then it must also use multiple93module uses multiple flavors of call_rcu(), then it must also use multiple
89flavors of rcu_barrier() when unloading that module. For example, if94flavors of rcu_barrier() when unloading that module. For example, if
90it uses call_rcu(), call_srcu() on srcu_struct_1, and call_srcu() on95it uses call_rcu(), call_srcu() on srcu_struct_1, and call_srcu() on
91srcu_struct_2(), then the following three lines of code will be required96srcu_struct_2, then the following three lines of code will be required
92when unloading:97when unloading::
93 98
94 1 rcu_barrier();99 1 rcu_barrier();
95 2 srcu_barrier(&srcu_struct_1);100 2 srcu_barrier(&srcu_struct_1);
96 3 srcu_barrier(&srcu_struct_2);101 3 srcu_barrier(&srcu_struct_2);
97 102
98The rcutorture module makes use of rcu_barrier() in its exit function103The rcutorture module makes use of rcu_barrier() in its exit function
99as follows:104as follows::
100 105
101 1 static void106 1 static void
102 2 rcu_torture_cleanup(void)107 2 rcu_torture_cleanup(void)
103 3 {108 3 {
104 4 int i;109 4 int i;
105 5110 5
106 6 fullstop = 1;111 6 fullstop = 1;
107 7 if (shuffler_task != NULL) {112 7 if (shuffler_task != NULL) {
108 8 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");113 8 VERBOSE_PRINTK_STRING("Stopping rcu_torture_shuffle task");
109 9 kthread_stop(shuffler_task);114 9 kthread_stop(shuffler_task);
11010 }115 10 }
11111 shuffler_task = NULL;116 11 shuffler_task = NULL;
11212117 12
11313 if (writer_task != NULL) {118 13 if (writer_task != NULL) {
11414 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");119 14 VERBOSE_PRINTK_STRING("Stopping rcu_torture_writer task");
11515 kthread_stop(writer_task);120 15 kthread_stop(writer_task);
11616 }121 16 }
11717 writer_task = NULL;122 17 writer_task = NULL;
11818123 18
11919 if (reader_tasks != NULL) {124 19 if (reader_tasks != NULL) {
12020 for (i = 0; i < nrealreaders; i++) {125 20 for (i = 0; i < nrealreaders; i++) {
12121 if (reader_tasks[i] != NULL) {126 21 if (reader_tasks[i] != NULL) {
12222 VERBOSE_PRINTK_STRING(127 22 VERBOSE_PRINTK_STRING(
12323 "Stopping rcu_torture_reader task");128 23 "Stopping rcu_torture_reader task");
12424 kthread_stop(reader_tasks[i]);129 24 kthread_stop(reader_tasks[i]);
12525 }130 25 }
12626 reader_tasks[i] = NULL;131 26 reader_tasks[i] = NULL;
12727 }132 27 }
12828 kfree(reader_tasks);133 28 kfree(reader_tasks);
12929 reader_tasks = NULL;134 29 reader_tasks = NULL;
13030 }135 30 }
13131 rcu_torture_current = NULL;136 31 rcu_torture_current = NULL;
13232137 32
13333 if (fakewriter_tasks != NULL) {138 33 if (fakewriter_tasks != NULL) {
13434 for (i = 0; i < nfakewriters; i++) {139 34 for (i = 0; i < nfakewriters; i++) {
13535 if (fakewriter_tasks[i] != NULL) {140 35 if (fakewriter_tasks[i] != NULL) {
13636 VERBOSE_PRINTK_STRING(141 36 VERBOSE_PRINTK_STRING(
13737 "Stopping rcu_torture_fakewriter task");142 37 "Stopping rcu_torture_fakewriter task");
13838 kthread_stop(fakewriter_tasks[i]);143 38 kthread_stop(fakewriter_tasks[i]);
13939 }144 39 }
14040 fakewriter_tasks[i] = NULL;145 40 fakewriter_tasks[i] = NULL;
14141 }146 41 }
14242 kfree(fakewriter_tasks);147 42 kfree(fakewriter_tasks);
14343 fakewriter_tasks = NULL;148 43 fakewriter_tasks = NULL;
14444 }149 44 }
14545150 45
14646 if (stats_task != NULL) {151 46 if (stats_task != NULL) {
14747 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");152 47 VERBOSE_PRINTK_STRING("Stopping rcu_torture_stats task");
14848 kthread_stop(stats_task);153 48 kthread_stop(stats_task);
14949 }154 49 }
15050 stats_task = NULL;155 50 stats_task = NULL;
15151156 51
15252 /* Wait for all RCU callbacks to fire. */157 52 /* Wait for all RCU callbacks to fire. */
15353 rcu_barrier();158 53 rcu_barrier();
15454159 54
15555 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */160 55 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
15656161 56
15757 if (cur_ops->cleanup != NULL)162 57 if (cur_ops->cleanup != NULL)
15858 cur_ops->cleanup();163 58 cur_ops->cleanup();
15959 if (atomic_read(&n_rcu_torture_error))164 59 if (atomic_read(&n_rcu_torture_error))
16060 rcu_torture_print_module_parms("End of test: FAILURE");165 60 rcu_torture_print_module_parms("End of test: FAILURE");
16161 else166 61 else
16262 rcu_torture_print_module_parms("End of test: SUCCESS");167 62 rcu_torture_print_module_parms("End of test: SUCCESS");
16363 }168 63 }
164 169
165Line 6 sets a global variable that prevents any RCU callbacks from170Line 6 sets a global variable that prevents any RCU callbacks from
166re-posting themselves. This will not be necessary in most cases, since171re-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
176Then lines 55-62 print status and do operation-specific cleanup, and181Then lines 55-62 print status and do operation-specific cleanup, and
177then return, permitting the module-unload operation to be completed.182then return, permitting the module-unload operation to be completed.
178 183
179Quick Quiz #1: Is there any other situation where rcu_barrier() might184.. _rcubarrier_quiz_1:
185
186Quick Quiz #1:
187 Is there any other situation where rcu_barrier() might
180 be required?188 be required?
181 189
190:ref:`Answer to Quick Quiz #1 <answer_rcubarrier_quiz_1>`
191
182Your module might have additional complications. For example, if your192Your module might have additional complications. For example, if your
183module invokes call_rcu() from timers, you will need to first cancel all193module invokes call_rcu() from timers, you will need to first cancel all
184the timers, and only then invoke rcu_barrier() to wait for any remaining194the 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
188rcu_barrier() before unloading. Similarly, if your module uses198rcu_barrier() before unloading. Similarly, if your module uses
189call_srcu(), you will need to invoke srcu_barrier() before unloading,199call_srcu(), you will need to invoke srcu_barrier() before unloading,
190and on the same srcu_struct structure. If your module uses call_rcu()200and 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**
192srcu_barrier().202srcu_barrier().
193 203
194 204
195Implementing rcu_barrier()205Implementing rcu_barrier()
206--------------------------
196 207
197Dipankar Sarma's implementation of rcu_barrier() makes use of the fact208Dipankar Sarma's implementation of rcu_barrier() makes use of the fact
198that RCU callbacks are never reordered once queued on one of the per-CPU209that 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
200callback queues, and then waits until they have all started executing, at211callback queues, and then waits until they have all started executing, at
201which point, all earlier RCU callbacks are guaranteed to have completed.212which point, all earlier RCU callbacks are guaranteed to have completed.
202 213
203The original code for rcu_barrier() was as follows:214The original code for rcu_barrier() was as follows::
204 215
205 1 void rcu_barrier(void)216 1 void rcu_barrier(void)
206 2 {217 2 {
207 3 BUG_ON(in_interrupt());218 3 BUG_ON(in_interrupt());
208 4 /* Take cpucontrol mutex to protect against CPU hotplug */219 4 /* Take cpucontrol mutex to protect against CPU hotplug */
209 5 mutex_lock(&rcu_barrier_mutex);220 5 mutex_lock(&rcu_barrier_mutex);
210 6 init_completion(&rcu_barrier_completion);221 6 init_completion(&rcu_barrier_completion);
211 7 atomic_set(&rcu_barrier_cpu_count, 0);222 7 atomic_set(&rcu_barrier_cpu_count, 0);
212 8 on_each_cpu(rcu_barrier_func, NULL, 0, 1);223 8 on_each_cpu(rcu_barrier_func, NULL, 0, 1);
213 9 wait_for_completion(&rcu_barrier_completion);224 9 wait_for_completion(&rcu_barrier_completion);
21410 mutex_unlock(&rcu_barrier_mutex);225 10 mutex_unlock(&rcu_barrier_mutex);
21511 }226 11 }
216 227
217Line 3 verifies that the caller is in process context, and lines 5 and 10228Line 3 verifies that the caller is in process context, and lines 5 and 10
218use rcu_barrier_mutex to ensure that only one rcu_barrier() is using the229use 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
226still gives the general idea.237still gives the general idea.
227 238
228The rcu_barrier_func() runs on each CPU, where it invokes call_rcu()239The rcu_barrier_func() runs on each CPU, where it invokes call_rcu()
229to post an RCU callback, as follows:240to post an RCU callback, as follows::
230 241
231 1 static void rcu_barrier_func(void *notused)242 1 static void rcu_barrier_func(void *notused)
232 2 {243 2 {
233 3 int cpu = smp_processor_id();244 3 int cpu = smp_processor_id();
234 4 struct rcu_data *rdp = &per_cpu(rcu_data, cpu);245 4 struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
235 5 struct rcu_head *head;246 5 struct rcu_head *head;
236 6247 6
237 7 head = &rdp->barrier;248 7 head = &rdp->barrier;
238 8 atomic_inc(&rcu_barrier_cpu_count);249 8 atomic_inc(&rcu_barrier_cpu_count);
239 9 call_rcu(head, rcu_barrier_callback);250 9 call_rcu(head, rcu_barrier_callback);
24010 }251 10 }
241 252
242Lines 3 and 4 locate RCU's internal per-CPU rcu_data structure,253Lines 3 and 4 locate RCU's internal per-CPU rcu_data structure,
243which contains the struct rcu_head that needed for the later call to254which contains the struct rcu_head that needed for the later call to
@@ -248,20 +259,25 @@ the current CPU's queue. · 4 unmodified lines
248 259
249The rcu_barrier_callback() function simply atomically decrements the260The rcu_barrier_callback() function simply atomically decrements the
250rcu_barrier_cpu_count variable and finalizes the completion when it261rcu_barrier_cpu_count variable and finalizes the completion when it
251reaches zero, as follows:262reaches zero, as follows::
252 263
253 1 static void rcu_barrier_callback(struct rcu_head *notused)264 1 static void rcu_barrier_callback(struct rcu_head *notused)
254 2 {265 2 {
255 3 if (atomic_dec_and_test(&rcu_barrier_cpu_count))266 3 if (atomic_dec_and_test(&rcu_barrier_cpu_count))
256 4 complete(&rcu_barrier_completion);267 4 complete(&rcu_barrier_completion);
257 5 }268 5 }
258 269
259Quick Quiz #2: What happens if CPU 0's rcu_barrier_func() executes270.. _rcubarrier_quiz_2:
271
272Quick Quiz #2:
273 What happens if CPU 0's rcu_barrier_func() executes
260 immediately (thus incrementing rcu_barrier_cpu_count to the274 immediately (thus incrementing rcu_barrier_cpu_count to the
261 value one), but the other CPU's rcu_barrier_func() invocations275 value one), but the other CPU's rcu_barrier_func() invocations
262 are delayed for a full grace period? Couldn't this result in276 are delayed for a full grace period? Couldn't this result in
263 rcu_barrier() returning prematurely?277 rcu_barrier() returning prematurely?
264 278
279:ref:`Answer to Quick Quiz #2 <answer_rcubarrier_quiz_2>`
280
265The current rcu_barrier() implementation is more complex, due to the need281The current rcu_barrier() implementation is more complex, due to the need
266to avoid disturbing idle CPUs (especially on battery-powered systems)282to avoid disturbing idle CPUs (especially on battery-powered systems)
267and the need to minimally disturb non-idle CPUs in real-time systems.283and 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
269 285
270 286
271rcu_barrier() Summary287rcu_barrier() Summary
288---------------------
272 289
273The rcu_barrier() primitive has seen relatively little use, since most290The rcu_barrier() primitive has seen relatively little use, since most
274code using RCU is in the core kernel rather than in modules. However, if291code 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
277 294
278 295
279Answers to Quick Quizzes296Answers to Quick Quizzes
297------------------------
298
299.. _answer_rcubarrier_quiz_1:
280 300
281Quick Quiz #1: Is there any other situation where rcu_barrier() might301Quick Quiz #1:
302 Is there any other situation where rcu_barrier() might
282 be required?303 be required?
283 304
284Answer: Interestingly enough, rcu_barrier() was not originally305Answer: Interestingly enough, rcu_barrier() was not originally
@@ -292,7 +313,12 @@ Answer: Interestingly enough, rcu_barrier() was not originally · 7 unmodified lines
292 implementing rcutorture, and found that rcu_barrier() solves313 implementing rcutorture, and found that rcu_barrier() solves
293 this problem as well.314 this problem as well.
294 315
295Quick Quiz #2: What happens if CPU 0's rcu_barrier_func() executes316:ref:`Back to Quick Quiz #1 <rcubarrier_quiz_1>`
317
318.. _answer_rcubarrier_quiz_2:
319
320Quick Quiz #2:
321 What happens if CPU 0's rcu_barrier_func() executes
296 immediately (thus incrementing rcu_barrier_cpu_count to the322 immediately (thus incrementing rcu_barrier_cpu_count to the
297 value one), but the other CPU's rcu_barrier_func() invocations323 value one), but the other CPU's rcu_barrier_func() invocations
298 are delayed for a full grace period? Couldn't this result in324 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
323 is to add an rcu_read_lock() before line 8 of rcu_barrier()349 is to add an rcu_read_lock() before line 8 of rcu_barrier()
324 and an rcu_read_unlock() after line 8 of this same function. If350 and an rcu_read_unlock() after line 8 of this same function. If
325 you can think of a better change, please let me know!351 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
225In kernels with CONFIG_RCU_FAST_NO_HZ, more information is printed225In kernels with CONFIG_RCU_FAST_NO_HZ, more information is printed
226for each CPU:226for each CPU:
227 227
228 0: (64628 ticks this GP) idle=dd5/3fffffffffffffff/0 softirq=82/543 last_accelerate: a345/d342 Nonlazy posted: ..D228 0: (64628 ticks this GP) idle=dd5/3fffffffffffffff/0 softirq=82/543 last_accelerate: a345/d342 dyntick_enabled: 1
229 229
230The "last_accelerate:" prints the low-order 16 bits (in hex) of the230The "last_accelerate:" prints the low-order 16 bits (in hex) of the
231jiffies counter when this CPU last invoked rcu_try_advance_all_cbs()231jiffies counter when this CPU last invoked rcu_try_advance_all_cbs()
232from rcu_needs_cpu() or last invoked rcu_accelerate_cbs() from232from rcu_needs_cpu() or last invoked rcu_accelerate_cbs() from
233rcu_prepare_for_idle(). The "Nonlazy posted:" indicates lazy-callback233rcu_prepare_for_idle(). "dyntick_enabled: 1" indicates that dyntick-idle
234status, so that an "l" indicates that all callbacks were lazy at the start234processing is enabled.
235of the last idle period and an "L" indicates that there are currently
236no non-lazy callbacks (in both cases, "." is printed otherwise, as
237shown above) and "D" indicates that dyntick-idle processing is enabled
238("." is printed otherwise, for example, if disabled via the "nohz="
239kernel boot parameter).
240 235
241If the grace period ends just as the stall warning starts printing,236If the grace period ends just as the stall warning starts printing,
242there will be a spurious stall-warning message, which will include237there 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
1What is RCU? -- "Read, Copy, Update"3What is RCU? -- "Read, Copy, Update"
4======================================
2 5
3Please note that the "What is RCU?" LWN series is an excellent place6Please note that the "What is RCU?" LWN series is an excellent place
4to start learning about RCU:7to start learning about RCU:
5 8
61. What is RCU, Fundamentally? http://lwn.net/Articles/262464/9| 1. What is RCU, Fundamentally? http://lwn.net/Articles/262464/
72. What is RCU? Part 2: Usage http://lwn.net/Articles/263130/10| 2. What is RCU? Part 2: Usage http://lwn.net/Articles/263130/
83. RCU part 3: the RCU API http://lwn.net/Articles/264090/11| 3. RCU part 3: the RCU API http://lwn.net/Articles/264090/
94. The RCU API, 2010 Edition http://lwn.net/Articles/418853/12| 4. The RCU API, 2010 Edition http://lwn.net/Articles/418853/
10 2010 Big API Table http://lwn.net/Articles/419086/13| 2010 Big API Table http://lwn.net/Articles/419086/
115. The RCU API, 2014 Edition http://lwn.net/Articles/609904/14| 5. The RCU API, 2014 Edition http://lwn.net/Articles/609904/
12 2014 Big API Table http://lwn.net/Articles/609973/15| 2014 Big API Table http://lwn.net/Articles/609973/
13 16
14 17
15What is RCU?18What is RCU?
@@ -24,14 +27,21 @@ the experience has been that different people must take different paths · 8 unmodified lines
24to arrive at an understanding of RCU. This document provides several27to arrive at an understanding of RCU. This document provides several
25different paths, as follows:28different paths, as follows:
26 29
271. RCU OVERVIEW30:ref:`1. RCU OVERVIEW <1_whatisRCU>`
282. WHAT IS RCU'S CORE API?31
293. WHAT ARE SOME EXAMPLE USES OF CORE RCU API?32:ref:`2. WHAT IS RCU'S CORE API? <2_whatisRCU>`
304. WHAT IF MY UPDATING THREAD CANNOT BLOCK?33
315. WHAT ARE SOME SIMPLE IMPLEMENTATIONS OF RCU?34:ref:`3. WHAT ARE SOME EXAMPLE USES OF CORE RCU API? <3_whatisRCU>`
326. ANALOGY WITH READER-WRITER LOCKING35
337. FULL LIST OF RCU APIs36:ref:`4. WHAT IF MY UPDATING THREAD CANNOT BLOCK? <4_whatisRCU>`
348. ANSWERS TO QUICK QUIZZES37
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>`
35 45
36People who prefer starting with a conceptual overview should focus on46People who prefer starting with a conceptual overview should focus on
37Section 1, though most readers will profit by reading this section at47Section 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
49that type of person, you have perused the source code and will therefore59that type of person, you have perused the source code and will therefore
50never need this document anyway. ;-)60never need this document anyway. ;-)
51 61
62.. _1_whatisRCU:
52 63
531. RCU OVERVIEW641. RCU OVERVIEW
65----------------
54 66
55The basic idea behind RCU is to split updates into "removal" and67The basic idea behind RCU is to split updates into "removal" and
56"reclamation" phases. The removal phase removes references to data items68"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
116that readers are not doing any sort of synchronization operations???128that readers are not doing any sort of synchronization operations???
117Read on to learn about how RCU's API makes this easy.129Read on to learn about how RCU's API makes this easy.
118 130
131.. _2_whatisRCU:
119 132
1202. WHAT IS RCU'S CORE API?1332. WHAT IS RCU'S CORE API?
134---------------------------
121 135
122The core RCU API is quite small:136The core RCU API is quite small:
123 137
@@ -136,7 +150,7 @@ later. See the kernel docbook documentation for more info, or look directly · 12 unmodified lines
136at the function header comments.150at the function header comments.
137 151
138rcu_read_lock()152rcu_read_lock()
139 153^^^^^^^^^^^^^^^
140 void rcu_read_lock(void);154 void rcu_read_lock(void);
141 155
142 Used by a reader to inform the reclaimer that the reader is156 Used by a reader to inform the reclaimer that the reader is
@@ -150,7 +164,7 @@ rcu_read_lock() · 7 unmodified lines
150 longer-term references to data structures.164 longer-term references to data structures.
151 165
152rcu_read_unlock()166rcu_read_unlock()
153 167^^^^^^^^^^^^^^^^^
154 void rcu_read_unlock(void);168 void rcu_read_unlock(void);
155 169
156 Used by a reader to inform the reclaimer that the reader is170 Used by a reader to inform the reclaimer that the reader is
@@ -158,15 +172,15 @@ rcu_read_unlock() · 1 unmodified line
158 read-side critical sections may be nested and/or overlapping.172 read-side critical sections may be nested and/or overlapping.
159 173
160synchronize_rcu()174synchronize_rcu()
161 175^^^^^^^^^^^^^^^^^
162 void synchronize_rcu(void);176 void synchronize_rcu(void);
163 177
164 Marks the end of updater code and the beginning of reclaimer178 Marks the end of updater code and the beginning of reclaimer
165 code. It does this by blocking until all pre-existing RCU179 code. It does this by blocking until all pre-existing RCU
166 read-side critical sections on all CPUs have completed.180 read-side critical sections on all CPUs have completed.
167 Note that synchronize_rcu() will -not- necessarily wait for181 Note that synchronize_rcu() will **not** necessarily wait for
168 any subsequent RCU read-side critical sections to complete.182 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::
170 184
171 CPU 0 CPU 1 CPU 2185 CPU 0 CPU 1 CPU 2
172 ----------------- ------------------------- ---------------186 ----------------- ------------------------- ---------------
@@ -182,7 +196,7 @@ synchronize_rcu() · 9 unmodified lines
182 any that begin after synchronize_rcu() is invoked.196 any that begin after synchronize_rcu() is invoked.
183 197
184 Of course, synchronize_rcu() does not necessarily return198 Of course, synchronize_rcu() does not necessarily return
185 -immediately- after the last pre-existing RCU read-side critical199 **immediately** after the last pre-existing RCU read-side critical
186 section completes. For one thing, there might well be scheduling200 section completes. For one thing, there might well be scheduling
187 delays. For another thing, many RCU implementations process201 delays. For another thing, many RCU implementations process
188 requests in batches in order to improve efficiencies, which can202 requests in batches in order to improve efficiencies, which can
@@ -211,10 +225,10 @@ synchronize_rcu() · 22 unmodified lines
211 checklist.txt for some approaches to limiting the update rate.225 checklist.txt for some approaches to limiting the update rate.
212 226
213rcu_assign_pointer()227rcu_assign_pointer()
214 228^^^^^^^^^^^^^^^^^^^^
215 void rcu_assign_pointer(p, typeof(p) v);229 void rcu_assign_pointer(p, typeof(p) v);
216 230
217 Yes, rcu_assign_pointer() -is- implemented as a macro, though it231 Yes, rcu_assign_pointer() **is** implemented as a macro, though it
218 would be cool to be able to declare a function in this manner.232 would be cool to be able to declare a function in this manner.
219 (Compiler experts will no doubt disagree.)233 (Compiler experts will no doubt disagree.)
220 234
@@ -231,7 +245,7 @@ rcu_assign_pointer() · 10 unmodified lines
231 the _rcu list-manipulation primitives such as list_add_rcu().245 the _rcu list-manipulation primitives such as list_add_rcu().
232 246
233rcu_dereference()247rcu_dereference()
234 248^^^^^^^^^^^^^^^^^
235 typeof(p) rcu_dereference(p);249 typeof(p) rcu_dereference(p);
236 250
237 Like rcu_assign_pointer(), rcu_dereference() must be implemented251 Like rcu_assign_pointer(), rcu_dereference() must be implemented
@@ -248,13 +262,13 @@ rcu_dereference() · 10 unmodified lines
248 262
249 Common coding practice uses rcu_dereference() to copy an263 Common coding practice uses rcu_dereference() to copy an
250 RCU-protected pointer to a local variable, then dereferences264 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::
252 266
253 p = rcu_dereference(head.next);267 p = rcu_dereference(head.next);
254 return p->data;268 return p->data;
255 269
256 However, in this case, one could just as easily combine these270 However, in this case, one could just as easily combine these
257 into one statement:271 into one statement::
258 272
259 return rcu_dereference(head.next)->data;273 return rcu_dereference(head.next)->data;
260 274
@@ -266,8 +280,8 @@ rcu_dereference() · 5 unmodified lines
266 unnecessary overhead on Alpha CPUs.280 unnecessary overhead on Alpha CPUs.
267 281
268 Note that the value returned by rcu_dereference() is valid282 Note that the value returned by rcu_dereference() is valid
269 only within the enclosing RCU read-side critical section [1].283 only within the enclosing RCU read-side critical section [1]_.
270 For example, the following is -not- legal:284 For example, the following is **not** legal::
271 285
272 rcu_read_lock();286 rcu_read_lock();
273 p = rcu_dereference(head.next);287 p = rcu_dereference(head.next);
@@ -290,9 +304,9 @@ rcu_dereference() · 16 unmodified lines
290 at any time, including immediately after the rcu_dereference().304 at any time, including immediately after the rcu_dereference().
291 And, again like rcu_assign_pointer(), rcu_dereference() is305 And, again like rcu_assign_pointer(), rcu_dereference() is
292 typically used indirectly, via the _rcu list-manipulation306 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]_.
294 308
295 [1] The variant rcu_dereference_protected() can be used outside309.. [1] The variant rcu_dereference_protected() can be used outside
296 of an RCU read-side critical section as long as the usage is310 of an RCU read-side critical section as long as the usage is
297 protected by locks acquired by the update-side code. This variant311 protected by locks acquired by the update-side code. This variant
298 avoids the lockdep warning that would happen when using (for312 avoids the lockdep warning that would happen when using (for
@@ -305,7 +319,7 @@ rcu_dereference() · 6 unmodified lines
305 a lockdep splat is emitted. See Documentation/RCU/Design/Requirements/Requirements.rst319 a lockdep splat is emitted. See Documentation/RCU/Design/Requirements/Requirements.rst
306 and the API's code comments for more details and example usage.320 and the API's code comments for more details and example usage.
307 321
308 [2] If the list_for_each_entry_rcu() instance might be used by322.. [2] If the list_for_each_entry_rcu() instance might be used by
309 update-side code as well as by RCU readers, then an additional323 update-side code as well as by RCU readers, then an additional
310 lockdep expression can be added to its list of arguments.324 lockdep expression can be added to its list of arguments.
311 For example, given an additional "lock_is_held(&mylock)" argument,325 For example, given an additional "lock_is_held(&mylock)" argument,
@@ -315,6 +329,7 @@ rcu_dereference() · 3 unmodified lines
315 329
316The following diagram shows how each API communicates among the330The following diagram shows how each API communicates among the
317reader, updater, and reclaimer.331reader, updater, and reclaimer.
332::
318 333
319 334
320 rcu_assign_pointer()335 rcu_assign_pointer()
@@ -375,12 +390,16 @@ c. RCU applied to scheduler and interrupt/NMI-handler tasks. · 54 unmodified lines
375Again, most uses will be of (a). The (b) and (c) cases are important390Again, most uses will be of (a). The (b) and (c) cases are important
376for specialized uses, but are relatively uncommon.391for specialized uses, but are relatively uncommon.
377 392
393.. _3_whatisRCU:
378 394
3793. WHAT ARE SOME EXAMPLE USES OF CORE RCU API?3953. WHAT ARE SOME EXAMPLE USES OF CORE RCU API?
396-----------------------------------------------
380 397
381This section shows a simple use of the core RCU API to protect a398This section shows a simple use of the core RCU API to protect a
382global pointer to a dynamically allocated structure. More-typical399global pointer to a dynamically allocated structure. More-typical
383uses of RCU may be found in listRCU.txt, arrayRCU.txt, and NMI-RCU.txt.400uses 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::
384 403
385 struct foo {404 struct foo {
386 int a;405 int a;
@@ -440,40 +459,43 @@ uses of RCU may be found in listRCU.txt, arrayRCU.txt, and NMI-RCU.txt. · 53 unmodified lines
440 459
441So, to sum up:460So, to sum up:
442 461
443o Use rcu_read_lock() and rcu_read_unlock() to guard RCU462- Use rcu_read_lock() and rcu_read_unlock() to guard RCU
444 read-side critical sections.463 read-side critical sections.
445 464
446o Within an RCU read-side critical section, use rcu_dereference()465- Within an RCU read-side critical section, use rcu_dereference()
447 to dereference RCU-protected pointers.466 to dereference RCU-protected pointers.
448 467
449o Use some solid scheme (such as locks or semaphores) to468- Use some solid scheme (such as locks or semaphores) to
450 keep concurrent updates from interfering with each other.469 keep concurrent updates from interfering with each other.
451 470
452o Use rcu_assign_pointer() to update an RCU-protected pointer.471- Use rcu_assign_pointer() to update an RCU-protected pointer.
453 This primitive protects concurrent readers from the updater,472 This primitive protects concurrent readers from the updater,
454 -not- concurrent updates from each other! You therefore still473 **not** concurrent updates from each other! You therefore still
455 need to use locking (or something similar) to keep concurrent474 need to use locking (or something similar) to keep concurrent
456 rcu_assign_pointer() primitives from interfering with each other.475 rcu_assign_pointer() primitives from interfering with each other.
457 476
458o Use synchronize_rcu() -after- removing a data element from an477- Use synchronize_rcu() **after** removing a data element from an
459 RCU-protected data structure, but -before- reclaiming/freeing478 RCU-protected data structure, but **before** reclaiming/freeing
460 the data element, in order to wait for the completion of all479 the data element, in order to wait for the completion of all
461 RCU read-side critical sections that might be referencing that480 RCU read-side critical sections that might be referencing that
462 data item.481 data item.
463 482
464See checklist.txt for additional rules to follow when using RCU.483See checklist.txt for additional rules to follow when using RCU.
465And again, more-typical uses of RCU may be found in listRCU.txt,484And again, more-typical uses of RCU may be found in :ref:`listRCU.rst
466arrayRCU.txt, and NMI-RCU.txt.485<list_rcu_doc>`, :ref:`arrayRCU.rst <array_rcu_doc>`, and :ref:`NMI-RCU.rst
486<NMI_rcu_doc>`.
467 487
488.. _4_whatisRCU:
468 489
4694. WHAT IF MY UPDATING THREAD CANNOT BLOCK?4904. WHAT IF MY UPDATING THREAD CANNOT BLOCK?
491--------------------------------------------
470 492
471In the example above, foo_update_a() blocks until a grace period elapses.493In the example above, foo_update_a() blocks until a grace period elapses.
472This is quite simple, but in some cases one cannot afford to wait so494This is quite simple, but in some cases one cannot afford to wait so
473long -- there might be other high-priority work to be done.495long -- there might be other high-priority work to be done.
474 496
475In such cases, one uses call_rcu() rather than synchronize_rcu().497In such cases, one uses call_rcu() rather than synchronize_rcu().
476The call_rcu() API is as follows:498The call_rcu() API is as follows::
477 499
478 void call_rcu(struct rcu_head * head,500 void call_rcu(struct rcu_head * head,
479 void (*func)(struct rcu_head *head));501 void (*func)(struct rcu_head *head));
@@ -481,7 +503,7 @@ The call_rcu() API is as follows: · 1 unmodified line
481This function invokes func(head) after a grace period has elapsed.503This function invokes func(head) after a grace period has elapsed.
482This invocation might happen from either softirq or process context,504This invocation might happen from either softirq or process context,
483so the function is not permitted to block. The foo struct needs to505so the function is not permitted to block. The foo struct needs to
484have an rcu_head structure added, perhaps as follows:506have an rcu_head structure added, perhaps as follows::
485 507
486 struct foo {508 struct foo {
487 int a;509 int a;
@@ -490,7 +512,7 @@ have an rcu_head structure added, perhaps as follows: · 2 unmodified lines
490 struct rcu_head rcu;512 struct rcu_head rcu;
491 };513 };
492 514
493The foo_update_a() function might then be written as follows:515The foo_update_a() function might then be written as follows::
494 516
495 /*517 /*
496 * Create a new struct foo that is the same as the one currently518 * 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
520 call_rcu(&old_fp->rcu, foo_reclaim);542 call_rcu(&old_fp->rcu, foo_reclaim);
521 }543 }
522 544
523The foo_reclaim() function might appear as follows:545The foo_reclaim() function might appear as follows::
524 546
525 void foo_reclaim(struct rcu_head *rp)547 void foo_reclaim(struct rcu_head *rp)
526 {548 {
@@ -544,7 +566,7 @@ namely foo_reclaim(). · 17 unmodified lines
544The summary of advice is the same as for the previous section, except566The summary of advice is the same as for the previous section, except
545that we are now using call_rcu() rather than synchronize_rcu():567that we are now using call_rcu() rather than synchronize_rcu():
546 568
547o Use call_rcu() -after- removing a data element from an569- Use call_rcu() **after** removing a data element from an
548 RCU-protected data structure in order to register a callback570 RCU-protected data structure in order to register a callback
549 function that will be invoked after the completion of all RCU571 function that will be invoked after the completion of all RCU
550 read-side critical sections that might be referencing that572 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
552 574
553If the callback for call_rcu() is not doing anything more than calling575If the callback for call_rcu() is not doing anything more than calling
554kfree() on the structure, you can use kfree_rcu() instead of call_rcu()576kfree() on the structure, you can use kfree_rcu() instead of call_rcu()
555to avoid having to write your own callback:577to avoid having to write your own callback::
556 578
557 kfree_rcu(old_fp, rcu);579 kfree_rcu(old_fp, rcu);
558 580
559Again, see checklist.txt for additional rules governing the use of RCU.581Again, see checklist.txt for additional rules governing the use of RCU.
560 582
583.. _5_whatisRCU:
561 584
5625. WHAT ARE SOME SIMPLE IMPLEMENTATIONS OF RCU?5855. WHAT ARE SOME SIMPLE IMPLEMENTATIONS OF RCU?
586------------------------------------------------
563 587
564One of the nice things about RCU is that it has extremely simple "toy"588One of the nice things about RCU is that it has extremely simple "toy"
565implementations that are a good first step towards understanding the589implementations 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
579 603
580 604
5815A. "TOY" IMPLEMENTATION #1: LOCKING6055A. "TOY" IMPLEMENTATION #1: LOCKING
582 606^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
583This section presents a "toy" RCU implementation that is based on607This section presents a "toy" RCU implementation that is based on
584familiar locking primitives. Its overhead makes it a non-starter for608familiar locking primitives. Its overhead makes it a non-starter for
585real-life use, as does its lack of scalability. It is also unsuitable609real-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
591However, it is probably the easiest implementation to relate to, so is615However, it is probably the easiest implementation to relate to, so is
592a good starting point.616a good starting point.
593 617
594It is extremely simple:618It is extremely simple::
595 619
596 static DEFINE_RWLOCK(rcu_gp_mutex);620 static DEFINE_RWLOCK(rcu_gp_mutex);
597 621
@@ -614,7 +638,7 @@ It is extremely simple: · 16 unmodified lines
614 638
615[You can ignore rcu_assign_pointer() and rcu_dereference() without missing639[You can ignore rcu_assign_pointer() and rcu_dereference() without missing
616much. But here are simplified versions anyway. And whatever you do,640much. But here are simplified versions anyway. And whatever you do,
617don't forget about them when submitting patches making use of RCU!]641don't forget about them when submitting patches making use of RCU!]::
618 642
619 #define rcu_assign_pointer(p, v) \643 #define rcu_assign_pointer(p, v) \
620 ({ \644 ({ \
@@ -647,18 +671,23 @@ that the only thing that can block rcu_read_lock() is a synchronize_rcu(). · 26 unmodified lines
647But synchronize_rcu() does not acquire any locks while holding rcu_gp_mutex,671But synchronize_rcu() does not acquire any locks while holding rcu_gp_mutex,
648so there can be no deadlock cycle.672so there can be no deadlock cycle.
649 673
650Quick Quiz #1: Why is this argument naive? How could a deadlock674.. _quiz_1:
675
676Quick Quiz #1:
677 Why is this argument naive? How could a deadlock
651 occur when using this algorithm in a real-world Linux678 occur when using this algorithm in a real-world Linux
652 kernel? How could this deadlock be avoided?679 kernel? How could this deadlock be avoided?
653 680
681:ref:`Answers to Quick Quiz <8_whatisRCU>`
654 682
6555B. "TOY" EXAMPLE #2: CLASSIC RCU6835B. "TOY" EXAMPLE #2: CLASSIC RCU
656 684^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
657This section presents a "toy" RCU implementation that is based on685This section presents a "toy" RCU implementation that is based on
658"classic RCU". It is also short on performance (but only for updates) and686"classic RCU". It is also short on performance (but only for updates) and
659on features such as hotplug CPU and the ability to run in CONFIG_PREEMPT687on features such as hotplug CPU and the ability to run in CONFIG_PREEMPT
660kernels. The definitions of rcu_dereference() and rcu_assign_pointer()688kernels. The definitions of rcu_dereference() and rcu_assign_pointer()
661are the same as those shown in the preceding section, so they are omitted.689are the same as those shown in the preceding section, so they are omitted.
690::
662 691
663 void rcu_read_lock(void) { }692 void rcu_read_lock(void) { }
664 693
@@ -683,14 +712,14 @@ CPU in turn. The run_on() primitive can be implemented straightforwardly · 18 unmodified lines
683in terms of the sched_setaffinity() primitive. Of course, a somewhat less712in terms of the sched_setaffinity() primitive. Of course, a somewhat less
684"toy" implementation would restore the affinity upon completion rather713"toy" implementation would restore the affinity upon completion rather
685than just leaving all tasks running on the last CPU, but when I said714than just leaving all tasks running on the last CPU, but when I said
686"toy", I meant -toy-!715"toy", I meant **toy**!
687 716
688So how the heck is this supposed to work???717So how the heck is this supposed to work???
689 718
690Remember that it is illegal to block while in an RCU read-side critical719Remember that it is illegal to block while in an RCU read-side critical
691section. Therefore, if a given CPU executes a context switch, we know720section. Therefore, if a given CPU executes a context switch, we know
692that it must have completed all preceding RCU read-side critical sections.721that it must have completed all preceding RCU read-side critical sections.
693Once -all- CPUs have executed a context switch, then -all- preceding722Once **all** CPUs have executed a context switch, then **all** preceding
694RCU read-side critical sections will have completed.723RCU read-side critical sections will have completed.
695 724
696So, suppose that we remove a data item from its structure and then invoke725So, 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
698that there are no RCU read-side critical sections holding a reference727that there are no RCU read-side critical sections holding a reference
699to that data item, so we can safely reclaim it.728to that data item, so we can safely reclaim it.
700 729
701Quick Quiz #2: Give an example where Classic RCU's read-side730.. _quiz_2:
702 overhead is -negative-.731
732Quick 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>`
703 737
704Quick Quiz #3: If it is illegal to block in an RCU read-side738.. _quiz_3:
739
740Quick Quiz #3:
741 If it is illegal to block in an RCU read-side
705 critical section, what the heck do you do in742 critical section, what the heck do you do in
706 PREEMPT_RT, where normal spinlocks can block???743 PREEMPT_RT, where normal spinlocks can block???
707 744
745:ref:`Answers to Quick Quiz <8_whatisRCU>`
746
747.. _6_whatisRCU:
708 748
7096. ANALOGY WITH READER-WRITER LOCKING7496. ANALOGY WITH READER-WRITER LOCKING
750--------------------------------------
710 751
711Although RCU can be used in many different ways, a very common use of752Although RCU can be used in many different ways, a very common use of
712RCU is analogous to reader-writer locking. The following unified753RCU is analogous to reader-writer locking. The following unified
713diff shows how closely related RCU and reader-writer locking can be.754diff shows how closely related RCU and reader-writer locking can be.
755::
714 756
715 @@ -5,5 +5,5 @@ struct el {757 @@ -5,5 +5,5 @@ struct el {
716 int data;758 int data;
@@ -762,7 +804,7 @@ diff shows how closely related RCU and reader-writer locking can be. · 45 unmodified lines
762 return 0;804 return 0;
763 }805 }
764 806
765Or, for those who prefer a side-by-side listing:807Or, for those who prefer a side-by-side listing::
766 808
767 1 struct el { 1 struct el {809 1 struct el { 1 struct el {
768 2 struct list_head list; 2 struct list_head list;810 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
774 8 rwlock_t listmutex; 8 spinlock_t listmutex;816 8 rwlock_t listmutex; 8 spinlock_t listmutex;
775 9 struct el head; 9 struct el head;817 9 struct el head; 9 struct el head;
776 818
777 1 int search(long key, int *result) 1 int search(long key, int *result)819::
778 2 { 2 {820
779 3 struct list_head *lp; 3 struct list_head *lp;821 1 int search(long key, int *result) 1 int search(long key, int *result)
780 4 struct el *p; 4 struct el *p;822 2 { 2 {
781 5 5823 3 struct list_head *lp; 3 struct list_head *lp;
782 6 read_lock(&listmutex); 6 rcu_read_lock();824 4 struct el *p; 4 struct el *p;
783 7 list_for_each_entry(p, head, lp) { 7 list_for_each_entry_rcu(p, head, lp) {825 5 5
784 8 if (p->key == key) { 8 if (p->key == key) {826 6 read_lock(&listmutex); 6 rcu_read_lock();
785 9 *result = p->data; 9 *result = p->data;827 7 list_for_each_entry(p, head, lp) { 7 list_for_each_entry_rcu(p, head, lp) {
78610 read_unlock(&listmutex); 10 rcu_read_unlock();828 8 if (p->key == key) { 8 if (p->key == key) {
78711 return 1; 11 return 1;829 9 *result = p->data; 9 *result = p->data;
78812 } 12 }830 10 read_unlock(&listmutex); 10 rcu_read_unlock();
78913 } 13 }831 11 return 1; 11 return 1;
79014 read_unlock(&listmutex); 14 rcu_read_unlock();832 12 } 12 }
79115 return 0; 15 return 0;833 13 } 13 }
79216 } 16 }834 14 read_unlock(&listmutex); 14 rcu_read_unlock();
793 835 15 return 0; 15 return 0;
794 1 int delete(long key) 1 int delete(long key)836 16 } 16 }
795 2 { 2 {837
796 3 struct el *p; 3 struct el *p;838::
797 4 4839
798 5 write_lock(&listmutex); 5 spin_lock(&listmutex);840 1 int delete(long key) 1 int delete(long key)
799 6 list_for_each_entry(p, head, lp) { 6 list_for_each_entry(p, head, lp) {841 2 { 2 {
800 7 if (p->key == key) { 7 if (p->key == key) {842 3 struct el *p; 3 struct el *p;
801 8 list_del(&p->list); 8 list_del_rcu(&p->list);843 4 4
802 9 write_unlock(&listmutex); 9 spin_unlock(&listmutex);844 5 write_lock(&listmutex); 5 spin_lock(&listmutex);
803 10 synchronize_rcu();845 6 list_for_each_entry(p, head, lp) { 6 list_for_each_entry(p, head, lp) {
80410 kfree(p); 11 kfree(p);846 7 if (p->key == key) { 7 if (p->key == key) {
80511 return 1; 12 return 1;847 8 list_del(&p->list); 8 list_del_rcu(&p->list);
80612 } 13 }848 9 write_unlock(&listmutex); 9 spin_unlock(&listmutex);
80713 } 14 }849 10 synchronize_rcu();
80814 write_unlock(&listmutex); 15 spin_unlock(&listmutex);850 10 kfree(p); 11 kfree(p);
80915 return 0; 16 return 0;851 11 return 1; 12 return 1;
81016 } 17 }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 }
811 857
812Either way, the differences are quite small. Read-side locking moves858Either way, the differences are quite small. Read-side locking moves
813to rcu_read_lock() and rcu_read_unlock, update-side locking moves from859to 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
825mechanism that never blocks, namely call_rcu() or kfree_rcu(), that can871mechanism that never blocks, namely call_rcu() or kfree_rcu(), that can
826be used in place of synchronize_rcu().872be used in place of synchronize_rcu().
827 873
874.. _7_whatisRCU:
828 875
8297. FULL LIST OF RCU APIs8767. FULL LIST OF RCU APIs
877-------------------------
830 878
831The RCU APIs are documented in docbook-format header comments in the879The RCU APIs are documented in docbook-format header comments in the
832Linux-kernel source code, but it helps to have a full list of the880Linux-kernel source code, but it helps to have a full list of the
833APIs, since there does not appear to be a way to categorize them881APIs, since there does not appear to be a way to categorize them
834in docbook. Here is the list, by category.882in docbook. Here is the list, by category.
835 883
836RCU list traversal:884RCU list traversal::
837 885
838 list_entry_rcu886 list_entry_rcu
887 list_entry_lockless
839 list_first_entry_rcu888 list_first_entry_rcu
840 list_next_rcu889 list_next_rcu
841 list_for_each_entry_rcu890 list_for_each_entry_rcu
842 list_for_each_entry_continue_rcu891 list_for_each_entry_continue_rcu
843 list_for_each_entry_from_rcu892 list_for_each_entry_from_rcu
893 list_first_or_null_rcu
894 list_next_or_null_rcu
844 hlist_first_rcu895 hlist_first_rcu
845 hlist_next_rcu896 hlist_next_rcu
846 hlist_pprev_rcu897 hlist_pprev_rcu
@@ -854,7 +905,7 @@ RCU list traversal: · 7 unmodified lines
854 hlist_bl_first_rcu905 hlist_bl_first_rcu
855 hlist_bl_for_each_entry_rcu906 hlist_bl_for_each_entry_rcu
856 907
857RCU pointer/list update:908RCU pointer/list update::
858 909
859 rcu_assign_pointer910 rcu_assign_pointer
860 list_add_rcu911 list_add_rcu
@@ -864,10 +915,12 @@ RCU pointer/list update: · 3 unmodified lines
864 hlist_add_behind_rcu915 hlist_add_behind_rcu
865 hlist_add_before_rcu916 hlist_add_before_rcu
866 hlist_add_head_rcu917 hlist_add_head_rcu
918 hlist_add_tail_rcu
867 hlist_del_rcu919 hlist_del_rcu
868 hlist_del_init_rcu920 hlist_del_init_rcu
869 hlist_replace_rcu921 hlist_replace_rcu
870 list_splice_init_rcu()922 list_splice_init_rcu
923 list_splice_tail_init_rcu
871 hlist_nulls_del_init_rcu924 hlist_nulls_del_init_rcu
872 hlist_nulls_del_rcu925 hlist_nulls_del_rcu
873 hlist_nulls_add_head_rcu926 hlist_nulls_add_head_rcu
@@ -876,7 +929,9 @@ RCU pointer/list update: · 2 unmodified lines
876 hlist_bl_del_rcu929 hlist_bl_del_rcu
877 hlist_bl_set_first_rcu930 hlist_bl_set_first_rcu
878 931
879RCU: Critical sections Grace period Barrier932RCU::
933
934 Critical sections Grace period Barrier
880 935
881 rcu_read_lock synchronize_net rcu_barrier936 rcu_read_lock synchronize_net rcu_barrier
882 rcu_read_unlock synchronize_rcu937 rcu_read_unlock synchronize_rcu
@@ -885,7 +940,9 @@ RCU: Critical sections Grace period Barrier · 2 unmodified lines
885 rcu_dereference_check kfree_rcu940 rcu_dereference_check kfree_rcu
886 rcu_dereference_protected941 rcu_dereference_protected
887 942
888bh: Critical sections Grace period Barrier943bh::
944
945 Critical sections Grace period Barrier
889 946
890 rcu_read_lock_bh call_rcu rcu_barrier947 rcu_read_lock_bh call_rcu rcu_barrier
891 rcu_read_unlock_bh synchronize_rcu948 rcu_read_unlock_bh synchronize_rcu
@@ -896,7 +953,9 @@ bh: Critical sections Grace period Barrier · 4 unmodified lines
896 rcu_dereference_bh_protected953 rcu_dereference_bh_protected
897 rcu_read_lock_bh_held954 rcu_read_lock_bh_held
898 955
899sched: Critical sections Grace period Barrier956sched::
957
958 Critical sections Grace period Barrier
900 959
901 rcu_read_lock_sched call_rcu rcu_barrier960 rcu_read_lock_sched call_rcu rcu_barrier
902 rcu_read_unlock_sched synchronize_rcu961 rcu_read_unlock_sched synchronize_rcu
@@ -910,7 +969,9 @@ sched: Critical sections Grace period Barrier · 7 unmodified lines
910 rcu_read_lock_sched_held969 rcu_read_lock_sched_held
911 970
912 971
913SRCU: Critical sections Grace period Barrier972SRCU::
973
974 Critical sections Grace period Barrier
914 975
915 srcu_read_lock call_srcu srcu_barrier976 srcu_read_lock call_srcu srcu_barrier
916 srcu_read_unlock synchronize_srcu977 srcu_read_unlock synchronize_srcu
@@ -918,13 +979,14 @@ SRCU: Critical sections Grace period Barrier · 1 unmodified line
918 srcu_dereference_check979 srcu_dereference_check
919 srcu_read_lock_held980 srcu_read_lock_held
920 981
921SRCU: Initialization/cleanup982SRCU: Initialization/cleanup::
983
922 DEFINE_SRCU984 DEFINE_SRCU
923 DEFINE_STATIC_SRCU985 DEFINE_STATIC_SRCU
924 init_srcu_struct986 init_srcu_struct
925 cleanup_srcu_struct987 cleanup_srcu_struct
926 988
927All: lockdep-checked RCU-protected pointer access989All: lockdep-checked RCU-protected pointer access::
928 990
929 rcu_access_pointer991 rcu_access_pointer
930 rcu_dereference_raw992 rcu_dereference_raw
@@ -974,15 +1036,19 @@ g. Otherwise, use RCU. · 43 unmodified lines
974Of course, this all assumes that you have determined that RCU is in fact1036Of course, this all assumes that you have determined that RCU is in fact
975the right tool for your job.1037the right tool for your job.
976 1038
1039.. _8_whatisRCU:
977 1040
9788. ANSWERS TO QUICK QUIZZES10418. ANSWERS TO QUICK QUIZZES
1042----------------------------
979 1043
980Quick Quiz #1: Why is this argument naive? How could a deadlock1044Quick Quiz #1:
1045 Why is this argument naive? How could a deadlock
981 occur when using this algorithm in a real-world Linux1046 occur when using this algorithm in a real-world Linux
982 kernel? [Referring to the lock-based "toy" RCU1047 kernel? [Referring to the lock-based "toy" RCU
983 algorithm.]1048 algorithm.]
984 1049
985Answer: Consider the following sequence of events:1050Answer:
1051 Consider the following sequence of events:
986 1052
987 1. CPU 0 acquires some unrelated lock, call it1053 1. CPU 0 acquires some unrelated lock, call it
988 "problematic_lock", disabling irq via1054 "problematic_lock", disabling irq via
@@ -1021,10 +1087,14 @@ Answer: Consider the following sequence of events: · 32 unmodified lines
1021 approach where tasks in RCU read-side critical sections1087 approach where tasks in RCU read-side critical sections
1022 cannot be blocked by tasks executing synchronize_rcu().1088 cannot be blocked by tasks executing synchronize_rcu().
1023 1089
1024Quick Quiz #2: Give an example where Classic RCU's read-side1090:ref:`Back to Quick Quiz #1 <quiz_1>`
1025 overhead is -negative-.1091
1092Quick Quiz #2:
1093 Give an example where Classic RCU's read-side
1094 overhead is **negative**.
1026 1095
1027Answer: Imagine a single-CPU system with a non-CONFIG_PREEMPT1096Answer:
1097 Imagine a single-CPU system with a non-CONFIG_PREEMPT
1028 kernel where a routing table is used by process-context1098 kernel where a routing table is used by process-context
1029 code, but can be updated by irq-context code (for example,1099 code, but can be updated by irq-context code (for example,
1030 by an "ICMP REDIRECT" packet). The usual way of handling1100 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
1046 even the theoretical possibility of negative overhead for1116 even the theoretical possibility of negative overhead for
1047 a synchronization primitive is a bit unexpected. ;-)1117 a synchronization primitive is a bit unexpected. ;-)
1048 1118
1049Quick Quiz #3: If it is illegal to block in an RCU read-side1119:ref:`Back to Quick Quiz #2 <quiz_2>`
1120
1121Quick Quiz #3:
1122 If it is illegal to block in an RCU read-side
1050 critical section, what the heck do you do in1123 critical section, what the heck do you do in
1051 PREEMPT_RT, where normal spinlocks can block???1124 PREEMPT_RT, where normal spinlocks can block???
1052 1125
1053Answer: Just as PREEMPT_RT permits preemption of spinlock1126Answer:
1127 Just as PREEMPT_RT permits preemption of spinlock
1054 critical sections, it permits preemption of RCU1128 critical sections, it permits preemption of RCU
1055 read-side critical sections. It also permits1129 read-side critical sections. It also permits
1056 spinlocks blocking while in RCU read-side critical1130 spinlocks blocking while in RCU read-side critical
@@ -1069,6 +1143,7 @@ Answer: Just as PREEMPT_RT permits preemption of spinlock · 12 unmodified lines
1069 Besides, how does the computer know what pizza parlor1143 Besides, how does the computer know what pizza parlor
1070 the human being went to???1144 the human being went to???
1071 1145
1146:ref:`Back to Quick Quiz #3 <quiz_3>`
1072 1147
1073ACKNOWLEDGEMENTS1148ACKNOWLEDGEMENTS
1074 1149
Documentation/admin-guide/kernel-parameters.txt+13−0
@@ -3978,6 +3978,19 @@ · 3977 unmodified lines
3978 test until boot completes in order to avoid3978 test until boot completes in order to avoid
3979 interference.3979 interference.
3980 3980
3981 rcuperf.kfree_rcu_test= [KNL]
3982 Set to measure performance of kfree_rcu() flooding.
3983
3984 rcuperf.kfree_nthreads= [KNL]
3985 The number of threads running loops of kfree_rcu().
3986
3987 rcuperf.kfree_alloc_num= [KNL]
3988 Number of allocations and frees done in an iteration.
3989
3990 rcuperf.kfree_loops= [KNL]
3991 Number of loops doing rcuperf.kfree_alloc_num number
3992 of allocations and frees.
3993
3981 rcuperf.nreaders= [KNL]3994 rcuperf.nreaders= [KNL]
3982 Set number of RCU readers. The value -1 selects3995 Set number of RCU readers. The value -1 selects
3983 N, where N is the number of CPUs. A value3996 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
18 * mb() prevents loads and stores being reordered across this point.18 * mb() prevents loads and stores being reordered across this point.
19 * rmb() prevents loads being reordered across this point.19 * rmb() prevents loads being reordered across this point.
20 * wmb() prevents stores being reordered across this point.20 * 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).
23 *21 *
24 * *mb() variants without smp_ prefix must order all types of memory22 * *mb() variants without smp_ prefix must order all types of memory
25 * operations with one another. sync is the only instruction sufficient23 * 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
281{281{
282 struct mt76_rx_tid *tid = NULL;282 struct mt76_rx_tid *tid = NULL;
283 283
284 rcu_swap_protected(wcid->aggr[tidno], tid,284 tid = rcu_replace_pointer(wcid->aggr[tidno], tid,
285 lockdep_is_held(&dev->mutex));285 lockdep_is_held(&dev->mutex));
286 if (tid) {286 if (tid) {
287 mt76_rx_aggr_shutdown(dev, tid);287 mt76_rx_aggr_shutdown(dev, tid);
288 kfree_rcu(tid, rcu_head);288 kfree_rcu(tid, rcu_head);
include/linux/list.h+112−24
@@ -23,6 +23,13 @@ · 22 unmodified lines
23#define LIST_HEAD(name) \23#define LIST_HEAD(name) \
24 struct list_head name = LIST_HEAD_INIT(name)24 struct list_head name = LIST_HEAD_INIT(name)
25 25
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 */
26static inline void INIT_LIST_HEAD(struct list_head *list)33static inline void INIT_LIST_HEAD(struct list_head *list)
27{34{
28 WRITE_ONCE(list->next, list);35 WRITE_ONCE(list->next, list);
@@ -120,12 +127,6 @@ static inline void __list_del_clearprev(struct list_head *entry) · 91 unmodified lines
120 entry->prev = NULL;127 entry->prev = NULL;
121}128}
122 129
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 */
129static inline void __list_del_entry(struct list_head *entry)130static inline void __list_del_entry(struct list_head *entry)
130{131{
131 if (!__list_del_entry_valid(entry))132 if (!__list_del_entry_valid(entry))
@@ -134,6 +135,12 @@ static inline void __list_del_entry(struct list_head *entry) · 2 unmodified lines
134 __list_del(entry->prev, entry->next);135 __list_del(entry->prev, entry->next);
135}136}
136 137
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 */
137static inline void list_del(struct list_head *entry)144static inline void list_del(struct list_head *entry)
138{145{
139 __list_del_entry(entry);146 __list_del_entry(entry);
@@ -157,8 +164,15 @@ static inline void list_replace(struct list_head *old, · 17 unmodified lines
157 new->prev->next = new;164 new->prev->next = new;
158}165}
159 166
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 */
160static inline void list_replace_init(struct list_head *old,174static inline void list_replace_init(struct list_head *old,
161 struct list_head *new)175 struct list_head *new)
162{176{
163 list_replace(old, new);177 list_replace(old, new);
164 INIT_LIST_HEAD(old);178 INIT_LIST_HEAD(old);
@@ -744,11 +758,36 @@ static inline void INIT_HLIST_NODE(struct hlist_node *h) · 579 unmodified lines
744 h->pprev = NULL;758 h->pprev = NULL;
745}759}
746 760
761/**
762 * hlist_unhashed - Has node been removed from list and reinitialized?
763 * @h: Node to be checked
764 *
765 * Not that not all removal functions will leave a node in unhashed
766 * state. For example, hlist_nulls_del_init_rcu() does leave the
767 * node in unhashed state, but hlist_nulls_del() does not.
768 */
747static inline int hlist_unhashed(const struct hlist_node *h)769static inline int hlist_unhashed(const struct hlist_node *h)
748{770{
749 return !h->pprev;771 return !h->pprev;
750}772}
751 773
774/**
775 * hlist_unhashed_lockless - Version of hlist_unhashed for lockless use
776 * @h: Node to be checked
777 *
778 * This variant of hlist_unhashed() must be used in lockless contexts
779 * to avoid potential load-tearing. The READ_ONCE() is paired with the
780 * various WRITE_ONCE() in hlist helpers that are defined below.
781 */
782static inline int hlist_unhashed_lockless(const struct hlist_node *h)
783{
784 return !READ_ONCE(h->pprev);
785}
786
787/**
788 * hlist_empty - Is the specified hlist_head structure an empty hlist?
789 * @h: Structure to check.
790 */
752static inline int hlist_empty(const struct hlist_head *h)791static inline int hlist_empty(const struct hlist_head *h)
753{792{
754 return !READ_ONCE(h->first);793 return !READ_ONCE(h->first);
@@ -761,9 +800,16 @@ static inline void __hlist_del(struct hlist_node *n) · 6 unmodified lines
761 800
762 WRITE_ONCE(*pprev, next);801 WRITE_ONCE(*pprev, next);
763 if (next)802 if (next)
764 next->pprev = pprev;803 WRITE_ONCE(next->pprev, pprev);
765}804}
766 805
806/**
807 * hlist_del - Delete the specified hlist_node from its list
808 * @n: Node to delete.
809 *
810 * Note that this function leaves the node in hashed state. Use
811 * hlist_del_init() or similar instead to unhash @n.
812 */
767static inline void hlist_del(struct hlist_node *n)813static inline void hlist_del(struct hlist_node *n)
768{814{
769 __hlist_del(n);815 __hlist_del(n);
@@ -771,6 +817,12 @@ static inline void hlist_del(struct hlist_node *n) · 1 unmodified line
771 n->pprev = LIST_POISON2;817 n->pprev = LIST_POISON2;
772}818}
773 819
820/**
821 * hlist_del_init - Delete the specified hlist_node from its list and initialize
822 * @n: Node to delete.
823 *
824 * Note that this function leaves the node in unhashed state.
825 */
774static inline void hlist_del_init(struct hlist_node *n)826static inline void hlist_del_init(struct hlist_node *n)
775{827{
776 if (!hlist_unhashed(n)) {828 if (!hlist_unhashed(n)) {
@@ -779,51 +831,83 @@ static inline void hlist_del_init(struct hlist_node *n) · 2 unmodified lines
779 }831 }
780}832}
781 833
834/**
835 * hlist_add_head - add a new entry at the beginning of the hlist
836 * @n: new entry to be added
837 * @h: hlist head to add it after
838 *
839 * Insert a new entry after the specified head.
840 * This is good for implementing stacks.
841 */
782static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)842static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
783{843{
784 struct hlist_node *first = h->first;844 struct hlist_node *first = h->first;
785 n->next = first;845 WRITE_ONCE(n->next, first);
786 if (first)846 if (first)
787 first->pprev = &n->next;847 WRITE_ONCE(first->pprev, &n->next);
788 WRITE_ONCE(h->first, n);848 WRITE_ONCE(h->first, n);
789 n->pprev = &h->first;849 WRITE_ONCE(n->pprev, &h->first);
790}850}
791 851
792/* next must be != NULL */852/**
853 * hlist_add_before - add a new entry before the one specified
854 * @n: new entry to be added
855 * @next: hlist node to add it before, which must be non-NULL
856 */
793static inline void hlist_add_before(struct hlist_node *n,857static inline void hlist_add_before(struct hlist_node *n,
794 struct hlist_node *next)858 struct hlist_node *next)
795{859{
796 n->pprev = next->pprev;860 WRITE_ONCE(n->pprev, next->pprev);
797 n->next = next;861 WRITE_ONCE(n->next, next);
798 next->pprev = &n->next;862 WRITE_ONCE(next->pprev, &n->next);
799 WRITE_ONCE(*(n->pprev), n);863 WRITE_ONCE(*(n->pprev), n);
800}864}
801 865
866/**
867 * hlist_add_behing - add a new entry after the one specified
868 * @n: new entry to be added
869 * @prev: hlist node to add it after, which must be non-NULL
870 */
802static inline void hlist_add_behind(struct hlist_node *n,871static inline void hlist_add_behind(struct hlist_node *n,
803 struct hlist_node *prev)872 struct hlist_node *prev)
804{873{
805 n->next = prev->next;874 WRITE_ONCE(n->next, prev->next);
806 prev->next = n;875 WRITE_ONCE(prev->next, n);
807 n->pprev = &prev->next;876 WRITE_ONCE(n->pprev, &prev->next);
808 877
809 if (n->next)878 if (n->next)
810 n->next->pprev = &n->next;879 WRITE_ONCE(n->next->pprev, &n->next);
811}880}
812 881
813/* after that we'll appear to be on some hlist and hlist_del will work */882/**
883 * hlist_add_fake - create a fake hlist consisting of a single headless node
884 * @n: Node to make a fake list out of
885 *
886 * This makes @n appear to be its own predecessor on a headless hlist.
887 * The point of this is to allow things like hlist_del() to work correctly
888 * in cases where there is no list.
889 */
814static inline void hlist_add_fake(struct hlist_node *n)890static inline void hlist_add_fake(struct hlist_node *n)
815{891{
816 n->pprev = &n->next;892 n->pprev = &n->next;
817}893}
818 894
895/**
896 * hlist_fake: Is this node a fake hlist?
897 * @h: Node to check for being a self-referential fake hlist.
898 */
819static inline bool hlist_fake(struct hlist_node *h)899static inline bool hlist_fake(struct hlist_node *h)
820{900{
821 return h->pprev == &h->next;901 return h->pprev == &h->next;
822}902}
823 903
824/*904/**
905 * hlist_is_singular_node - is node the only element of the specified hlist?
906 * @n: Node to check for singularity.
907 * @h: Header for potentially singular list.
908 *
825 * Check whether the node is the only node of the head without909 * Check whether the node is the only node of the head without
826 * accessing head:910 * accessing head, thus avoiding unnecessary cache misses.
827 */911 */
828static inline bool912static inline bool
829hlist_is_singular_node(struct hlist_node *n, struct hlist_head *h)913hlist_is_singular_node(struct hlist_node *n, struct hlist_head *h)
@@ -831,7 +915,11 @@ hlist_is_singular_node(struct hlist_node *n, struct hlist_head *h) · 1 unmodified line
831 return !n->next && n->pprev == &h->first;915 return !n->next && n->pprev == &h->first;
832}916}
833 917
834/*918/**
919 * hlist_move_list - Move an hlist
920 * @old: hlist_head for old list.
921 * @new: hlist_head for new list.
922 *
835 * Move a list from one list head to another. Fixup the pprev923 * Move a list from one list head to another. Fixup the pprev
836 * reference of the first entry if it exists.924 * reference of the first entry if it exists.
837 */925 */
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
56 return ((unsigned long)ptr) >> 1;56 return ((unsigned long)ptr) >> 1;
57}57}
58 58
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 */
59static inline int hlist_nulls_unhashed(const struct hlist_nulls_node *h)67static inline int hlist_nulls_unhashed(const struct hlist_nulls_node *h)
60{68{
61 return !h->pprev;69 return !h->pprev;
62}70}
63 71
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 */
81static inline int hlist_nulls_unhashed_lockless(const struct hlist_nulls_node *h)
82{
83 return !READ_ONCE(h->pprev);
84}
85
64static inline int hlist_nulls_empty(const struct hlist_nulls_head *h)86static inline int hlist_nulls_empty(const struct hlist_nulls_head *h)
65{87{
66 return is_a_nulls(READ_ONCE(h->first));88 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
72 struct hlist_nulls_node *first = h->first;94 struct hlist_nulls_node *first = h->first;
73 95
74 n->next = first;96 n->next = first;
75 n->pprev = &h->first;97 WRITE_ONCE(n->pprev, &h->first);
76 h->first = n;98 h->first = n;
77 if (!is_a_nulls(first))99 if (!is_a_nulls(first))
78 first->pprev = &n->next;100 WRITE_ONCE(first->pprev, &n->next);
79}101}
80 102
81static inline void __hlist_nulls_del(struct hlist_nulls_node *n)103static 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
85 107
86 WRITE_ONCE(*pprev, next);108 WRITE_ONCE(*pprev, next);
87 if (!is_a_nulls(next))109 if (!is_a_nulls(next))
88 next->pprev = pprev;110 WRITE_ONCE(next->pprev, pprev);
89}111}
90 112
91static inline void hlist_nulls_del(struct hlist_nulls_node *n)113static inline void hlist_nulls_del(struct hlist_nulls_node *n)
92{114{
93 __hlist_nulls_del(n);115 __hlist_nulls_del(n);
94 n->pprev = LIST_POISON2;116 WRITE_ONCE(n->pprev, LIST_POISON2);
95}117}
96 118
97/**119/**
include/linux/rcu_segcblist.h+0−2
@@ -22,7 +22,6 @@ struct rcu_cblist { · 21 unmodified lines
22 struct rcu_head *head;22 struct rcu_head *head;
23 struct rcu_head **tail;23 struct rcu_head **tail;
24 long len;24 long len;
25 long len_lazy;
26};25};
27 26
28#define RCU_CBLIST_INITIALIZER(n) { .head = NULL, .tail = &n.head }27#define RCU_CBLIST_INITIALIZER(n) { .head = NULL, .tail = &n.head }
@@ -73,7 +72,6 @@ struct rcu_segcblist { · 44 unmodified lines
73#else72#else
74 long len;73 long len;
75#endif74#endif
76 long len_lazy;
77 u8 enabled;75 u8 enabled;
78 u8 offloaded;76 u8 offloaded;
79};77};
include/linux/rculist.h+24−14
@@ -40,6 +40,16 @@ static inline void INIT_LIST_HEAD_RCU(struct list_head *list) · 39 unmodified lines
40 */40 */
41#define list_next_rcu(list) (*((struct list_head __rcu **)(&(list)->next)))41#define list_next_rcu(list) (*((struct list_head __rcu **)(&(list)->next)))
42 42
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
43/*53/*
44 * Check during list traversal that we are within an RCU reader54 * Check during list traversal that we are within an RCU reader
45 */55 */
@@ -173,7 +183,7 @@ static inline void hlist_del_init_rcu(struct hlist_node *n) · 127 unmodified lines
173{183{
174 if (!hlist_unhashed(n)) {184 if (!hlist_unhashed(n)) {
175 __hlist_del(n);185 __hlist_del(n);
176 n->pprev = NULL;186 WRITE_ONCE(n->pprev, NULL);
177 }187 }
178}188}
179 189
@@ -361,7 +371,7 @@ static inline void list_splice_tail_init_rcu(struct list_head *list, · 181 unmodified lines
361 * @pos: the type * to use as a loop cursor.371 * @pos: the type * to use as a loop cursor.
362 * @head: the head for your list.372 * @head: the head for your list.
363 * @member: the name of the list_head within the struct.373 * @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.
365 *375 *
366 * This list-traversal primitive may safely run concurrently with376 * This list-traversal primitive may safely run concurrently with
367 * the _rcu list-mutation primitives such as list_add_rcu()377 * 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
473static inline void hlist_del_rcu(struct hlist_node *n)483static inline void hlist_del_rcu(struct hlist_node *n)
474{484{
475 __hlist_del(n);485 __hlist_del(n);
476 n->pprev = LIST_POISON2;486 WRITE_ONCE(n->pprev, LIST_POISON2);
477}487}
478 488
479/**489/**
@@ -489,11 +499,11 @@ static inline void hlist_replace_rcu(struct hlist_node *old, · 9 unmodified lines
489 struct hlist_node *next = old->next;499 struct hlist_node *next = old->next;
490 500
491 new->next = next;501 new->next = next;
492 new->pprev = old->pprev;502 WRITE_ONCE(new->pprev, old->pprev);
493 rcu_assign_pointer(*(struct hlist_node __rcu **)new->pprev, new);503 rcu_assign_pointer(*(struct hlist_node __rcu **)new->pprev, new);
494 if (next)504 if (next)
495 new->next->pprev = &new->next;505 WRITE_ONCE(new->next->pprev, &new->next);
496 old->pprev = LIST_POISON2;506 WRITE_ONCE(old->pprev, LIST_POISON2);
497}507}
498 508
499/*509/*
@@ -528,10 +538,10 @@ static inline void hlist_add_head_rcu(struct hlist_node *n, · 28 unmodified lines
528 struct hlist_node *first = h->first;538 struct hlist_node *first = h->first;
529 539
530 n->next = first;540 n->next = first;
531 n->pprev = &h->first;541 WRITE_ONCE(n->pprev, &h->first);
532 rcu_assign_pointer(hlist_first_rcu(h), n);542 rcu_assign_pointer(hlist_first_rcu(h), n);
533 if (first)543 if (first)
534 first->pprev = &n->next;544 WRITE_ONCE(first->pprev, &n->next);
535}545}
536 546
537/**547/**
@@ -564,7 +574,7 @@ static inline void hlist_add_tail_rcu(struct hlist_node *n, · 26 unmodified lines
564 574
565 if (last) {575 if (last) {
566 n->next = last->next;576 n->next = last->next;
567 n->pprev = &last->next;577 WRITE_ONCE(n->pprev, &last->next);
568 rcu_assign_pointer(hlist_next_rcu(last), n);578 rcu_assign_pointer(hlist_next_rcu(last), n);
569 } else {579 } else {
570 hlist_add_head_rcu(n, h);580 hlist_add_head_rcu(n, h);
@@ -592,10 +602,10 @@ static inline void hlist_add_tail_rcu(struct hlist_node *n, · 21 unmodified lines
592static inline void hlist_add_before_rcu(struct hlist_node *n,602static inline void hlist_add_before_rcu(struct hlist_node *n,
593 struct hlist_node *next)603 struct hlist_node *next)
594{604{
595 n->pprev = next->pprev;605 WRITE_ONCE(n->pprev, next->pprev);
596 n->next = next;606 n->next = next;
597 rcu_assign_pointer(hlist_pprev_rcu(n), n);607 rcu_assign_pointer(hlist_pprev_rcu(n), n);
598 next->pprev = &n->next;608 WRITE_ONCE(next->pprev, &n->next);
599}609}
600 610
601/**611/**
@@ -620,10 +630,10 @@ static inline void hlist_add_behind_rcu(struct hlist_node *n, · 18 unmodified lines
620 struct hlist_node *prev)630 struct hlist_node *prev)
621{631{
622 n->next = prev->next;632 n->next = prev->next;
623 n->pprev = &prev->next;633 WRITE_ONCE(n->pprev, &prev->next);
624 rcu_assign_pointer(hlist_next_rcu(prev), n);634 rcu_assign_pointer(hlist_next_rcu(prev), n);
625 if (n->next)635 if (n->next)
626 n->next->pprev = &n->next;636 WRITE_ONCE(n->next->pprev, &n->next);
627}637}
628 638
629#define __hlist_for_each_rcu(pos, head) \639#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
636 * @pos: the type * to use as a loop cursor.646 * @pos: the type * to use as a loop cursor.
637 * @head: the head for your list.647 * @head: the head for your list.
638 * @member: the name of the hlist_node within the struct.648 * @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.
640 *650 *
641 * This list-traversal primitive may safely run concurrently with651 * This list-traversal primitive may safely run concurrently with
642 * the _rcu list-mutation primitives such as hlist_add_head_rcu()652 * 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
34{34{
35 if (!hlist_nulls_unhashed(n)) {35 if (!hlist_nulls_unhashed(n)) {
36 __hlist_nulls_del(n);36 __hlist_nulls_del(n);
37 n->pprev = NULL;37 WRITE_ONCE(n->pprev, NULL);
38 }38 }
39}39}
40 40
41/**
42 * hlist_nulls_first_rcu - returns the first element of the hash list.
43 * @head: the head of the list.
44 */
41#define hlist_nulls_first_rcu(head) \45#define hlist_nulls_first_rcu(head) \
42 (*((struct hlist_nulls_node __rcu __force **)&(head)->first))46 (*((struct hlist_nulls_node __rcu __force **)&(head)->first))
43 47
48/**
49 * hlist_nulls_next_rcu - returns the element of the list after @node.
50 * @node: element of the list.
51 */
44#define hlist_nulls_next_rcu(node) \52#define hlist_nulls_next_rcu(node) \
45 (*((struct hlist_nulls_node __rcu __force **)&(node)->next))53 (*((struct hlist_nulls_node __rcu __force **)&(node)->next))
46 54
@@ -66,7 +74,7 @@ static inline void hlist_nulls_del_init_rcu(struct hlist_nulls_node *n) · 19 unmodified lines
66static inline void hlist_nulls_del_rcu(struct hlist_nulls_node *n)74static inline void hlist_nulls_del_rcu(struct hlist_nulls_node *n)
67{75{
68 __hlist_nulls_del(n);76 __hlist_nulls_del(n);
69 n->pprev = LIST_POISON2;77 WRITE_ONCE(n->pprev, LIST_POISON2);
70}78}
71 79
72/**80/**
@@ -94,10 +102,10 @@ static inline void hlist_nulls_add_head_rcu(struct hlist_nulls_node *n, · 21 unmodified lines
94 struct hlist_nulls_node *first = h->first;102 struct hlist_nulls_node *first = h->first;
95 103
96 n->next = first;104 n->next = first;
97 n->pprev = &h->first;105 WRITE_ONCE(n->pprev, &h->first);
98 rcu_assign_pointer(hlist_nulls_first_rcu(h), n);106 rcu_assign_pointer(hlist_nulls_first_rcu(h), n);
99 if (!is_a_nulls(first))107 if (!is_a_nulls(first))
100 first->pprev = &n->next;108 WRITE_ONCE(first->pprev, &n->next);
101}109}
102 110
103/**111/**
@@ -141,7 +149,7 @@ static inline void hlist_nulls_add_tail_rcu(struct hlist_nulls_node *n, · 37 unmodified lines
141 * hlist_nulls_for_each_entry_rcu - iterate over rcu list of given type149 * hlist_nulls_for_each_entry_rcu - iterate over rcu list of given type
142 * @tpos: the type * to use as a loop cursor.150 * @tpos: the type * to use as a loop cursor.
143 * @pos: the &struct hlist_nulls_node to use as a loop cursor.151 * @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.
145 * @member: the name of the hlist_nulls_node within the struct.153 * @member: the name of the hlist_nulls_node within the struct.
146 *154 *
147 * The barrier() is needed to make sure compiler doesn't cache first element [1],155 * 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
161 * iterate over list of given type safe against removal of list entry169 * iterate over list of given type safe against removal of list entry
162 * @tpos: the type * to use as a loop cursor.170 * @tpos: the type * to use as a loop cursor.
163 * @pos: the &struct hlist_nulls_node to use as a loop cursor.171 * @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.
165 * @member: the name of the hlist_nulls_node within the struct.173 * @member: the name of the hlist_nulls_node within the struct.
166 */174 */
167#define hlist_nulls_for_each_entry_safe(tpos, pos, head, member) \175#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
154 *154 *
155 * This macro resembles cond_resched(), except that it is defined to155 * This macro resembles cond_resched(), except that it is defined to
156 * report potential quiescent states to RCU-tasks even if the cond_resched()156 * 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.
158 */158 */
159#define cond_resched_tasks_rcu_qs() \159#define cond_resched_tasks_rcu_qs() \
160do { \160do { \
@@ -167,7 +167,7 @@ do { \ · 6 unmodified lines
167 * TREE_RCU and rcu_barrier_() primitives in TINY_RCU.167 * TREE_RCU and rcu_barrier_() primitives in TINY_RCU.
168 */168 */
169 169
170#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)170#if defined(CONFIG_TREE_RCU)
171#include <linux/rcutree.h>171#include <linux/rcutree.h>
172#elif defined(CONFIG_TINY_RCU)172#elif defined(CONFIG_TINY_RCU)
173#include <linux/rcutiny.h>173#include <linux/rcutiny.h>
@@ -400,22 +400,6 @@ do { \ · 226 unmodified lines
400 __tmp; \400 __tmp; \
401})401})
402 402
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
419/**403/**
420 * rcu_access_pointer() - fetch RCU pointer with no dereferencing404 * rcu_access_pointer() - fetch RCU pointer with no dereferencing
421 * @p: The pointer to read405 * @p: The pointer to read
@@ -598,10 +582,10 @@ do { \ · 176 unmodified lines
598 *582 *
599 * You can avoid reading and understanding the next paragraph by583 * You can avoid reading and understanding the next paragraph by
600 * following this rule: don't put anything in an rcu_read_lock() RCU584 * 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.
602 * But if you want the full story, read on!586 * But if you want the full story, read on!
603 *587 *
604 * In non-preemptible RCU implementations (TREE_RCU and TINY_RCU),588 * In non-preemptible RCU implementations (pure TREE_RCU and TINY_RCU),
605 * it is illegal to block while in an RCU read-side critical section.589 * it is illegal to block while in an RCU read-side critical section.
606 * In preemptible RCU implementations (PREEMPT_RCU) in CONFIG_PREEMPTION590 * In preemptible RCU implementations (PREEMPT_RCU) in CONFIG_PREEMPTION
607 * kernel builds, RCU read-side critical sections may be preempted,591 * 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
912 return false;896 return false;
913}897}
914 898
899/* kernel/ksysfs.c definitions */
900extern int rcu_expedited;
901extern int rcu_normal;
902
915#endif /* __LINUX_RCUPDATE_H */903#endif /* __LINUX_RCUPDATE_H */
include/linux/rcutiny.h+1−0
@@ -85,6 +85,7 @@ static inline void rcu_scheduler_starting(void) { } · 84 unmodified lines
85static inline void rcu_end_inkernel_boot(void) { }85static inline void rcu_end_inkernel_boot(void) { }
86static inline bool rcu_is_watching(void) { return true; }86static inline bool rcu_is_watching(void) { return true; }
87static inline void rcu_momentary_dyntick_idle(void) { }87static inline void rcu_momentary_dyntick_idle(void) { }
88static inline void kfree_rcu_scheduler_running(void) { }
88 89
89/* Avoid RCU read-side critical sections leaking across. */90/* Avoid RCU read-side critical sections leaking across. */
90static inline void rcu_all_qs(void) { barrier(); }91static 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
38void rcu_barrier(void);38void rcu_barrier(void);
39bool rcu_eqs_special_set(int cpu);39bool rcu_eqs_special_set(int cpu);
40void rcu_momentary_dyntick_idle(void);40void rcu_momentary_dyntick_idle(void);
41void kfree_rcu_scheduler_running(void);
41unsigned long get_state_synchronize_rcu(void);42unsigned long get_state_synchronize_rcu(void);
42void cond_synchronize_rcu(unsigned long oldstate);43void cond_synchronize_rcu(unsigned long oldstate);
43 44
include/linux/tick.h+4−1
@@ -109,8 +109,10 @@ enum tick_dep_bits { · 108 unmodified lines
109 TICK_DEP_BIT_PERF_EVENTS = 1,109 TICK_DEP_BIT_PERF_EVENTS = 1,
110 TICK_DEP_BIT_SCHED = 2,110 TICK_DEP_BIT_SCHED = 2,
111 TICK_DEP_BIT_CLOCK_UNSTABLE = 3,111 TICK_DEP_BIT_CLOCK_UNSTABLE = 3,
112 TICK_DEP_BIT_RCU = 4112 TICK_DEP_BIT_RCU = 4,
113 TICK_DEP_BIT_RCU_EXP = 5
113};114};
115#define TICK_DEP_BIT_MAX TICK_DEP_BIT_RCU_EXP
114 116
115#define TICK_DEP_MASK_NONE 0117#define TICK_DEP_MASK_NONE 0
116#define TICK_DEP_MASK_POSIX_TIMER (1 << TICK_DEP_BIT_POSIX_TIMER)118#define TICK_DEP_MASK_POSIX_TIMER (1 << TICK_DEP_BIT_POSIX_TIMER)
@@ -118,6 +120,7 @@ enum tick_dep_bits { · 1 unmodified line
118#define TICK_DEP_MASK_SCHED (1 << TICK_DEP_BIT_SCHED)120#define TICK_DEP_MASK_SCHED (1 << TICK_DEP_BIT_SCHED)
119#define TICK_DEP_MASK_CLOCK_UNSTABLE (1 << TICK_DEP_BIT_CLOCK_UNSTABLE)121#define TICK_DEP_MASK_CLOCK_UNSTABLE (1 << TICK_DEP_BIT_CLOCK_UNSTABLE)
120#define TICK_DEP_MASK_RCU (1 << TICK_DEP_BIT_RCU)122#define TICK_DEP_MASK_RCU (1 << TICK_DEP_BIT_RCU)
123#define TICK_DEP_MASK_RCU_EXP (1 << TICK_DEP_BIT_RCU_EXP)
121 124
122#ifdef CONFIG_NO_HZ_COMMON125#ifdef CONFIG_NO_HZ_COMMON
123extern bool tick_nohz_enabled;126extern bool tick_nohz_enabled;
include/trace/events/rcu.h+16−24
@@ -41,7 +41,7 @@ TRACE_EVENT(rcu_utilization, · 40 unmodified lines
41 TP_printk("%s", __entry->s)41 TP_printk("%s", __entry->s)
42);42);
43 43
44#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)44#if defined(CONFIG_TREE_RCU)
45 45
46/*46/*
47 * Tracepoint for grace-period events. Takes a string identifying the47 * Tracepoint for grace-period events. Takes a string identifying the
@@ -432,7 +432,7 @@ TRACE_EVENT_RCU(rcu_fqs, · 384 unmodified lines
432 __entry->cpu, __entry->qsevent)432 __entry->cpu, __entry->qsevent)
433);433);
434 434
435#endif /* #if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU) */435#endif /* #if defined(CONFIG_TREE_RCU) */
436 436
437/*437/*
438 * Tracepoint for dyntick-idle entry/exit events. These take a string438 * Tracepoint for dyntick-idle entry/exit events. These take a string
@@ -449,7 +449,7 @@ TRACE_EVENT_RCU(rcu_fqs, · 10 unmodified lines
449 */449 */
450TRACE_EVENT_RCU(rcu_dyntick,450TRACE_EVENT_RCU(rcu_dyntick,
451 451
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),
453 453
454 TP_ARGS(polarity, oldnesting, newnesting, dynticks),454 TP_ARGS(polarity, oldnesting, newnesting, dynticks),
455 455
@@ -464,7 +464,7 @@ TRACE_EVENT_RCU(rcu_dyntick, · 8 unmodified lines
464 __entry->polarity = polarity;464 __entry->polarity = polarity;
465 __entry->oldnesting = oldnesting;465 __entry->oldnesting = oldnesting;
466 __entry->newnesting = newnesting;466 __entry->newnesting = newnesting;
467 __entry->dynticks = atomic_read(&dynticks);467 __entry->dynticks = dynticks;
468 ),468 ),
469 469
470 TP_printk("%s %lx %lx %#3x", __entry->polarity,470 TP_printk("%s %lx %lx %#3x", __entry->polarity,
@@ -481,16 +481,14 @@ TRACE_EVENT_RCU(rcu_dyntick, · 10 unmodified lines
481 */481 */
482TRACE_EVENT_RCU(rcu_callback,482TRACE_EVENT_RCU(rcu_callback,
483 483
484 TP_PROTO(const char *rcuname, struct rcu_head *rhp, long qlen_lazy,484 TP_PROTO(const char *rcuname, struct rcu_head *rhp, long qlen),
485 long qlen),
486 485
487 TP_ARGS(rcuname, rhp, qlen_lazy, qlen),486 TP_ARGS(rcuname, rhp, qlen),
488 487
489 TP_STRUCT__entry(488 TP_STRUCT__entry(
490 __field(const char *, rcuname)489 __field(const char *, rcuname)
491 __field(void *, rhp)490 __field(void *, rhp)
492 __field(void *, func)491 __field(void *, func)
493 __field(long, qlen_lazy)
494 __field(long, qlen)492 __field(long, qlen)
495 ),493 ),
496 494
@@ -498,13 +496,12 @@ TRACE_EVENT_RCU(rcu_callback, · 1 unmodified line
498 __entry->rcuname = rcuname;496 __entry->rcuname = rcuname;
499 __entry->rhp = rhp;497 __entry->rhp = rhp;
500 __entry->func = rhp->func;498 __entry->func = rhp->func;
501 __entry->qlen_lazy = qlen_lazy;
502 __entry->qlen = qlen;499 __entry->qlen = qlen;
503 ),500 ),
504 501
505 TP_printk("%s rhp=%p func=%ps %ld/%ld",502 TP_printk("%s rhp=%p func=%ps %ld",
506 __entry->rcuname, __entry->rhp, __entry->func,503 __entry->rcuname, __entry->rhp, __entry->func,
507 __entry->qlen_lazy, __entry->qlen)504 __entry->qlen)
508);505);
509 506
510/*507/*
@@ -518,15 +515,14 @@ TRACE_EVENT_RCU(rcu_callback, · 7 unmodified lines
518TRACE_EVENT_RCU(rcu_kfree_callback,515TRACE_EVENT_RCU(rcu_kfree_callback,
519 516
520 TP_PROTO(const char *rcuname, struct rcu_head *rhp, unsigned long offset,517 TP_PROTO(const char *rcuname, struct rcu_head *rhp, unsigned long offset,
521 long qlen_lazy, long qlen),518 long qlen),
522 519
523 TP_ARGS(rcuname, rhp, offset, qlen_lazy, qlen),520 TP_ARGS(rcuname, rhp, offset, qlen),
524 521
525 TP_STRUCT__entry(522 TP_STRUCT__entry(
526 __field(const char *, rcuname)523 __field(const char *, rcuname)
527 __field(void *, rhp)524 __field(void *, rhp)
528 __field(unsigned long, offset)525 __field(unsigned long, offset)
529 __field(long, qlen_lazy)
530 __field(long, qlen)526 __field(long, qlen)
531 ),527 ),
532 528
@@ -534,13 +530,12 @@ TRACE_EVENT_RCU(rcu_kfree_callback, · 1 unmodified line
534 __entry->rcuname = rcuname;530 __entry->rcuname = rcuname;
535 __entry->rhp = rhp;531 __entry->rhp = rhp;
536 __entry->offset = offset;532 __entry->offset = offset;
537 __entry->qlen_lazy = qlen_lazy;
538 __entry->qlen = qlen;533 __entry->qlen = qlen;
539 ),534 ),
540 535
541 TP_printk("%s rhp=%p func=%ld %ld/%ld",536 TP_printk("%s rhp=%p func=%ld %ld",
542 __entry->rcuname, __entry->rhp, __entry->offset,537 __entry->rcuname, __entry->rhp, __entry->offset,
543 __entry->qlen_lazy, __entry->qlen)538 __entry->qlen)
544);539);
545 540
546/*541/*
@@ -552,27 +547,24 @@ TRACE_EVENT_RCU(rcu_kfree_callback, · 5 unmodified lines
552 */547 */
553TRACE_EVENT_RCU(rcu_batch_start,548TRACE_EVENT_RCU(rcu_batch_start,
554 549
555 TP_PROTO(const char *rcuname, long qlen_lazy, long qlen, long blimit),550 TP_PROTO(const char *rcuname, long qlen, long blimit),
556 551
557 TP_ARGS(rcuname, qlen_lazy, qlen, blimit),552 TP_ARGS(rcuname, qlen, blimit),
558 553
559 TP_STRUCT__entry(554 TP_STRUCT__entry(
560 __field(const char *, rcuname)555 __field(const char *, rcuname)
561 __field(long, qlen_lazy)
562 __field(long, qlen)556 __field(long, qlen)
563 __field(long, blimit)557 __field(long, blimit)
564 ),558 ),
565 559
566 TP_fast_assign(560 TP_fast_assign(
567 __entry->rcuname = rcuname;561 __entry->rcuname = rcuname;
568 __entry->qlen_lazy = qlen_lazy;
569 __entry->qlen = qlen;562 __entry->qlen = qlen;
570 __entry->blimit = blimit;563 __entry->blimit = blimit;
571 ),564 ),
572 565
573 TP_printk("%s CBs=%ld/%ld bl=%ld",566 TP_printk("%s CBs=%ld bl=%ld",
574 __entry->rcuname, __entry->qlen_lazy, __entry->qlen,567 __entry->rcuname, __entry->qlen, __entry->blimit)
575 __entry->blimit)
576);568);
577 569
578/*570/*
kernel/rcu/Kconfig+9−8
@@ -7,7 +7,7 @@ menu "RCU Subsystem" · 6 unmodified lines
7 7
8config TREE_RCU8config TREE_RCU
9 bool9 bool
10 default y if !PREEMPTION && SMP10 default y if SMP
11 help11 help
12 This option selects the RCU implementation that is12 This option selects the RCU implementation that is
13 designed for very large SMP system with hundreds or13 designed for very large SMP system with hundreds or
@@ -17,6 +17,7 @@ config TREE_RCU · 3 unmodified lines
17config PREEMPT_RCU17config PREEMPT_RCU
18 bool18 bool
19 default y if PREEMPTION19 default y if PREEMPTION
20 select TREE_RCU
20 help21 help
21 This option selects the RCU implementation that is22 This option selects the RCU implementation that is
22 designed for very large SMP systems with hundreds or23 designed for very large SMP systems with hundreds or
@@ -78,7 +79,7 @@ config TASKS_RCU · 55 unmodified lines
78 user-mode execution as quiescent states.79 user-mode execution as quiescent states.
79 80
80config RCU_STALL_COMMON81config RCU_STALL_COMMON
81 def_bool ( TREE_RCU || PREEMPT_RCU )82 def_bool TREE_RCU
82 help83 help
83 This option enables RCU CPU stall code that is common between84 This option enables RCU CPU stall code that is common between
84 the TINY and TREE variants of RCU. The purpose is to allow85 the TINY and TREE variants of RCU. The purpose is to allow
@@ -86,13 +87,13 @@ config RCU_STALL_COMMON · 1 unmodified line
86 making these warnings mandatory for the tree variants.87 making these warnings mandatory for the tree variants.
87 88
88config RCU_NEED_SEGCBLIST89config RCU_NEED_SEGCBLIST
89 def_bool ( TREE_RCU || PREEMPT_RCU || TREE_SRCU )90 def_bool ( TREE_RCU || TREE_SRCU )
90 91
91config RCU_FANOUT92config RCU_FANOUT
92 int "Tree-based hierarchical RCU fanout value"93 int "Tree-based hierarchical RCU fanout value"
93 range 2 64 if 64BIT94 range 2 64 if 64BIT
94 range 2 32 if !64BIT95 range 2 32 if !64BIT
95 depends on (TREE_RCU || PREEMPT_RCU) && RCU_EXPERT96 depends on TREE_RCU && RCU_EXPERT
96 default 64 if 64BIT97 default 64 if 64BIT
97 default 32 if !64BIT98 default 32 if !64BIT
98 help99 help
@@ -112,7 +113,7 @@ config RCU_FANOUT_LEAF · 13 unmodified lines
112 int "Tree-based hierarchical RCU leaf-level fanout value"113 int "Tree-based hierarchical RCU leaf-level fanout value"
113 range 2 64 if 64BIT114 range 2 64 if 64BIT
114 range 2 32 if !64BIT115 range 2 32 if !64BIT
115 depends on (TREE_RCU || PREEMPT_RCU) && RCU_EXPERT116 depends on TREE_RCU && RCU_EXPERT
116 default 16117 default 16
117 help118 help
118 This option controls the leaf-level fanout of hierarchical119 This option controls the leaf-level fanout of hierarchical
@@ -187,7 +188,7 @@ config RCU_BOOST_DELAY · 68 unmodified lines
187 188
188config RCU_NOCB_CPU189config RCU_NOCB_CPU
189 bool "Offload RCU callback processing from boot-selected CPUs"190 bool "Offload RCU callback processing from boot-selected CPUs"
190 depends on TREE_RCU || PREEMPT_RCU191 depends on TREE_RCU
191 depends on RCU_EXPERT || NO_HZ_FULL192 depends on RCU_EXPERT || NO_HZ_FULL
192 default n193 default n
193 help194 help
@@ -200,8 +201,8 @@ config RCU_NOCB_CPU · 6 unmodified lines
200 specified at boot time by the rcu_nocbs parameter. For each201 specified at boot time by the rcu_nocbs parameter. For each
201 such CPU, a kthread ("rcuox/N") will be created to invoke202 such CPU, a kthread ("rcuox/N") will be created to invoke
202 callbacks, where the "N" is the CPU being offloaded, and where203 callbacks, where the "N" is the CPU being offloaded, and where
203 the "p" for RCU-preempt (PREEMPT kernels) and "s" for RCU-sched204 the "p" for RCU-preempt (PREEMPTION kernels) and "s" for RCU-sched
204 (!PREEMPT kernels). Nothing prevents this kthread from running205 (!PREEMPTION kernels). Nothing prevents this kthread from running
205 on the specified CPUs, but (1) the kthreads may be preempted206 on the specified CPUs, but (1) the kthreads may be preempted
206 between each callback, and (2) affinity or cgroups can be used207 between each callback, and (2) affinity or cgroups can be used
207 to force the kthreads to run on whatever set of CPUs is desired.208 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
9obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o9obj-$(CONFIG_RCU_TORTURE_TEST) += rcutorture.o
10obj-$(CONFIG_RCU_PERF_TEST) += rcuperf.o10obj-$(CONFIG_RCU_PERF_TEST) += rcuperf.o
11obj-$(CONFIG_TREE_RCU) += tree.o11obj-$(CONFIG_TREE_RCU) += tree.o
12obj-$(CONFIG_PREEMPT_RCU) += tree.o
13obj-$(CONFIG_TINY_RCU) += tiny.o12obj-$(CONFIG_TINY_RCU) += tiny.o
14obj-$(CONFIG_RCU_NEED_SEGCBLIST) += rcu_segcblist.o13obj-$(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
198}198}
199#endif /* #else !CONFIG_DEBUG_OBJECTS_RCU_HEAD */199#endif /* #else !CONFIG_DEBUG_OBJECTS_RCU_HEAD */
200 200
201void 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 */
207static 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
228#ifdef CONFIG_RCU_STALL_COMMON201#ifdef CONFIG_RCU_STALL_COMMON
229 202
230extern int rcu_cpu_stall_ftrace_dump;203extern int rcu_cpu_stall_ftrace_dump;
@@ -281,7 +254,7 @@ void rcu_test_sync_prims(void); · 50 unmodified lines
281 */254 */
282extern void resched_cpu(int cpu);255extern void resched_cpu(int cpu);
283 256
284#if defined(SRCU) || !defined(TINY_RCU)257#if defined(CONFIG_SRCU) || !defined(CONFIG_TINY_RCU)
285 258
286#include <linux/rcu_node_tree.h>259#include <linux/rcu_node_tree.h>
287 260
@@ -418,7 +391,7 @@ do { \ · 130 unmodified lines
418#define raw_lockdep_assert_held_rcu_node(p) \391#define raw_lockdep_assert_held_rcu_node(p) \
419 lockdep_assert_held(&ACCESS_PRIVATE(p, lock))392 lockdep_assert_held(&ACCESS_PRIVATE(p, lock))
420 393
421#endif /* #if defined(SRCU) || !defined(TINY_RCU) */394#endif /* #if defined(CONFIG_SRCU) || !defined(CONFIG_TINY_RCU) */
422 395
423#ifdef CONFIG_SRCU396#ifdef CONFIG_SRCU
424void srcu_init(void);397void srcu_init(void);
@@ -454,7 +427,7 @@ enum rcutorture_type { · 29 unmodified lines
454 INVALID_RCU_FLAVOR427 INVALID_RCU_FLAVOR
455};428};
456 429
457#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)430#if defined(CONFIG_TREE_RCU)
458void rcutorture_get_gp_data(enum rcutorture_type test_type, int *flags,431void rcutorture_get_gp_data(enum rcutorture_type test_type, int *flags,
459 unsigned long *gp_seq);432 unsigned long *gp_seq);
460void do_trace_rcu_torture_read(const char *rcutorturename,433void 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
20 rclp->head = NULL;20 rclp->head = NULL;
21 rclp->tail = &rclp->head;21 rclp->tail = &rclp->head;
22 rclp->len = 0;22 rclp->len = 0;
23 rclp->len_lazy = 0;
24}23}
25 24
26/*25/*
27 * Enqueue an rcu_head structure onto the specified callback list.26 * 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.
31 */27 */
32void rcu_cblist_enqueue(struct rcu_cblist *rclp, struct rcu_head *rhp)28void rcu_cblist_enqueue(struct rcu_cblist *rclp, struct rcu_head *rhp)
33{29{
@@ -54,7 +50,6 @@ void rcu_cblist_flush_enqueue(struct rcu_cblist *drclp, · 20 unmodified lines
54 else50 else
55 drclp->tail = &drclp->head;51 drclp->tail = &drclp->head;
56 drclp->len = srclp->len;52 drclp->len = srclp->len;
57 drclp->len_lazy = srclp->len_lazy;
58 if (!rhp) {53 if (!rhp) {
59 rcu_cblist_init(srclp);54 rcu_cblist_init(srclp);
60 } else {55 } else {
@@ -62,16 +57,12 @@ void rcu_cblist_flush_enqueue(struct rcu_cblist *drclp, · 1 unmodified line
62 srclp->head = rhp;57 srclp->head = rhp;
63 srclp->tail = &rhp->next;58 srclp->tail = &rhp->next;
64 WRITE_ONCE(srclp->len, 1);59 WRITE_ONCE(srclp->len, 1);
65 srclp->len_lazy = 0;
66 }60 }
67}61}
68 62
69/*63/*
70 * Dequeue the oldest rcu_head structure from the specified callback64 * Dequeue the oldest rcu_head structure from the specified callback
71 * list. This function assumes that the callback is non-lazy, but65 * list.
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.
75 */66 */
76struct rcu_head *rcu_cblist_dequeue(struct rcu_cblist *rclp)67struct rcu_head *rcu_cblist_dequeue(struct rcu_cblist *rclp)
77{68{
@@ -161,7 +152,6 @@ void rcu_segcblist_init(struct rcu_segcblist *rsclp) · 83 unmodified lines
161 for (i = 0; i < RCU_CBLIST_NSEGS; i++)152 for (i = 0; i < RCU_CBLIST_NSEGS; i++)
162 rsclp->tails[i] = &rsclp->head;153 rsclp->tails[i] = &rsclp->head;
163 rcu_segcblist_set_len(rsclp, 0);154 rcu_segcblist_set_len(rsclp, 0);
164 rsclp->len_lazy = 0;
165 rsclp->enabled = 1;155 rsclp->enabled = 1;
166}156}
167 157
@@ -173,7 +163,6 @@ void rcu_segcblist_disable(struct rcu_segcblist *rsclp) · 5 unmodified lines
173{163{
174 WARN_ON_ONCE(!rcu_segcblist_empty(rsclp));164 WARN_ON_ONCE(!rcu_segcblist_empty(rsclp));
175 WARN_ON_ONCE(rcu_segcblist_n_cbs(rsclp));165 WARN_ON_ONCE(rcu_segcblist_n_cbs(rsclp));
176 WARN_ON_ONCE(rcu_segcblist_n_lazy_cbs(rsclp));
177 rsclp->enabled = 0;166 rsclp->enabled = 0;
178}167}
179 168
@@ -253,11 +242,9 @@ bool rcu_segcblist_nextgp(struct rcu_segcblist *rsclp, unsigned long *lp) · 73 unmodified lines
253 * absolutely not OK for it to ever miss posting a callback.242 * absolutely not OK for it to ever miss posting a callback.
254 */243 */
255void rcu_segcblist_enqueue(struct rcu_segcblist *rsclp,244void rcu_segcblist_enqueue(struct rcu_segcblist *rsclp,
256 struct rcu_head *rhp, bool lazy)245 struct rcu_head *rhp)
257{246{
258 rcu_segcblist_inc_len(rsclp);247 rcu_segcblist_inc_len(rsclp);
259 if (lazy)
260 rsclp->len_lazy++;
261 smp_mb(); /* Ensure counts are updated before callback is enqueued. */248 smp_mb(); /* Ensure counts are updated before callback is enqueued. */
262 rhp->next = NULL;249 rhp->next = NULL;
263 WRITE_ONCE(*rsclp->tails[RCU_NEXT_TAIL], rhp);250 WRITE_ONCE(*rsclp->tails[RCU_NEXT_TAIL], rhp);
@@ -275,15 +262,13 @@ void rcu_segcblist_enqueue(struct rcu_segcblist *rsclp, · 11 unmodified lines
275 * period. You have been warned.262 * period. You have been warned.
276 */263 */
277bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp,264bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp,
278 struct rcu_head *rhp, bool lazy)265 struct rcu_head *rhp)
279{266{
280 int i;267 int i;
281 268
282 if (rcu_segcblist_n_cbs(rsclp) == 0)269 if (rcu_segcblist_n_cbs(rsclp) == 0)
283 return false;270 return false;
284 rcu_segcblist_inc_len(rsclp);271 rcu_segcblist_inc_len(rsclp);
285 if (lazy)
286 rsclp->len_lazy++;
287 smp_mb(); /* Ensure counts are updated before callback is entrained. */272 smp_mb(); /* Ensure counts are updated before callback is entrained. */
288 rhp->next = NULL;273 rhp->next = NULL;
289 for (i = RCU_NEXT_TAIL; i > RCU_DONE_TAIL; i--)274 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
307void rcu_segcblist_extract_count(struct rcu_segcblist *rsclp,292void rcu_segcblist_extract_count(struct rcu_segcblist *rsclp,
308 struct rcu_cblist *rclp)293 struct rcu_cblist *rclp)
309{294{
310 rclp->len_lazy += rsclp->len_lazy;
311 rsclp->len_lazy = 0;
312 rclp->len = rcu_segcblist_xchg_len(rsclp, 0);295 rclp->len = rcu_segcblist_xchg_len(rsclp, 0);
313}296}
314 297
@@ -361,9 +344,7 @@ void rcu_segcblist_extract_pend_cbs(struct rcu_segcblist *rsclp, · 46 unmodified lines
361void rcu_segcblist_insert_count(struct rcu_segcblist *rsclp,344void rcu_segcblist_insert_count(struct rcu_segcblist *rsclp,
362 struct rcu_cblist *rclp)345 struct rcu_cblist *rclp)
363{346{
364 rsclp->len_lazy += rclp->len_lazy;
365 rcu_segcblist_add_len(rsclp, rclp->len);347 rcu_segcblist_add_len(rsclp, rclp->len);
366 rclp->len_lazy = 0;
367 rclp->len = 0;348 rclp->len = 0;
368}349}
369 350
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
15 return READ_ONCE(rclp->len);15 return READ_ONCE(rclp->len);
16}16}
17 17
18/*
19 * Account for the fact that a previously dequeued callback turned out
20 * to be marked as lazy.
21 */
22static inline void rcu_cblist_dequeued_lazy(struct rcu_cblist *rclp)
23{
24 rclp->len_lazy--;
25}
26
27void rcu_cblist_init(struct rcu_cblist *rclp);18void rcu_cblist_init(struct rcu_cblist *rclp);
28void rcu_cblist_enqueue(struct rcu_cblist *rclp, struct rcu_head *rhp);19void rcu_cblist_enqueue(struct rcu_cblist *rclp, struct rcu_head *rhp);
29void rcu_cblist_flush_enqueue(struct rcu_cblist *drclp,20void 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
59#endif50#endif
60}51}
61 52
62/* Return number of lazy callbacks in segmented callback list. */
63static 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. */
69static inline long rcu_segcblist_n_nonlazy_cbs(struct rcu_segcblist *rsclp)
70{
71 return rcu_segcblist_n_cbs(rsclp) - rsclp->len_lazy;
72}
73
74/*53/*
75 * Is the specified rcu_segcblist enabled, for example, not corresponding54 * Is the specified rcu_segcblist enabled, for example, not corresponding
76 * to an offline CPU?55 * to an offline CPU?
@@ -106,9 +85,9 @@ struct rcu_head *rcu_segcblist_first_cb(struct rcu_segcblist *rsclp); · 29 unmodified lines
106struct rcu_head *rcu_segcblist_first_pend_cb(struct rcu_segcblist *rsclp);85struct rcu_head *rcu_segcblist_first_pend_cb(struct rcu_segcblist *rsclp);
107bool rcu_segcblist_nextgp(struct rcu_segcblist *rsclp, unsigned long *lp);86bool rcu_segcblist_nextgp(struct rcu_segcblist *rsclp, unsigned long *lp);
108void rcu_segcblist_enqueue(struct rcu_segcblist *rsclp,87void rcu_segcblist_enqueue(struct rcu_segcblist *rsclp,
109 struct rcu_head *rhp, bool lazy);88 struct rcu_head *rhp);
110bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp,89bool rcu_segcblist_entrain(struct rcu_segcblist *rsclp,
111 struct rcu_head *rhp, bool lazy);90 struct rcu_head *rhp);
112void rcu_segcblist_extract_count(struct rcu_segcblist *rsclp,91void rcu_segcblist_extract_count(struct rcu_segcblist *rsclp,
113 struct rcu_cblist *rclp);92 struct rcu_cblist *rclp);
114void rcu_segcblist_extract_done_cbs(struct rcu_segcblist *rsclp,93void 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
86 "Shutdown at end of performance tests.");86 "Shutdown at end of performance tests.");
87torture_param(int, verbose, 1, "Enable verbose debugging printk()s");87torture_param(int, verbose, 1, "Enable verbose debugging printk()s");
88torture_param(int, writer_holdoff, 0, "Holdoff (us) between GPs, zero to disable");88torture_param(int, writer_holdoff, 0, "Holdoff (us) between GPs, zero to disable");
89torture_param(int, kfree_rcu_test, 0, "Do we run a kfree_rcu() perf test?");
89 90
90static char *perf_type = "rcu";91static char *perf_type = "rcu";
91module_param(perf_type, charp, 0444);92module_param(perf_type, charp, 0444);
@@ -105,8 +106,8 @@ static atomic_t n_rcu_perf_writer_finished; · 13 unmodified lines
105static wait_queue_head_t shutdown_wq;106static wait_queue_head_t shutdown_wq;
106static u64 t_rcu_perf_writer_started;107static u64 t_rcu_perf_writer_started;
107static u64 t_rcu_perf_writer_finished;108static u64 t_rcu_perf_writer_finished;
108static unsigned long b_rcu_perf_writer_started;109static unsigned long b_rcu_gp_test_started;
109static unsigned long b_rcu_perf_writer_finished;110static unsigned long b_rcu_gp_test_finished;
110static DEFINE_PER_CPU(atomic_t, n_async_inflight);111static DEFINE_PER_CPU(atomic_t, n_async_inflight);
111 112
112#define MAX_MEAS 10000113#define MAX_MEAS 10000
@@ -378,10 +379,10 @@ rcu_perf_writer(void *arg) · 265 unmodified lines
378 if (atomic_inc_return(&n_rcu_perf_writer_started) >= nrealwriters) {379 if (atomic_inc_return(&n_rcu_perf_writer_started) >= nrealwriters) {
379 t_rcu_perf_writer_started = t;380 t_rcu_perf_writer_started = t;
380 if (gp_exp) {381 if (gp_exp) {
381 b_rcu_perf_writer_started =382 b_rcu_gp_test_started =
382 cur_ops->exp_completed() / 2;383 cur_ops->exp_completed() / 2;
383 } else {384 } else {
384 b_rcu_perf_writer_started = cur_ops->get_gp_seq();385 b_rcu_gp_test_started = cur_ops->get_gp_seq();
385 }386 }
386 }387 }
387 388
@@ -429,10 +430,10 @@ retry: · 41 unmodified lines
429 PERFOUT_STRING("Test complete");430 PERFOUT_STRING("Test complete");
430 t_rcu_perf_writer_finished = t;431 t_rcu_perf_writer_finished = t;
431 if (gp_exp) {432 if (gp_exp) {
432 b_rcu_perf_writer_finished =433 b_rcu_gp_test_finished =
433 cur_ops->exp_completed() / 2;434 cur_ops->exp_completed() / 2;
434 } else {435 } else {
435 b_rcu_perf_writer_finished =436 b_rcu_gp_test_finished =
436 cur_ops->get_gp_seq();437 cur_ops->get_gp_seq();
437 }438 }
438 if (shutdown) {439 if (shutdown) {
@@ -515,8 +516,8 @@ rcu_perf_cleanup(void) · 76 unmodified lines
515 t_rcu_perf_writer_finished -516 t_rcu_perf_writer_finished -
516 t_rcu_perf_writer_started,517 t_rcu_perf_writer_started,
517 ngps,518 ngps,
518 rcuperf_seq_diff(b_rcu_perf_writer_finished,519 rcuperf_seq_diff(b_rcu_gp_test_finished,
519 b_rcu_perf_writer_started));520 b_rcu_gp_test_started));
520 for (i = 0; i < nrealwriters; i++) {521 for (i = 0; i < nrealwriters; i++) {
521 if (!writer_durations)522 if (!writer_durations)
522 break;523 break;
@@ -584,6 +585,159 @@ rcu_perf_shutdown(void *arg) · 61 unmodified lines
584 return -EINVAL;585 return -EINVAL;
585}586}
586 587
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
593torture_param(int, kfree_nthreads, -1, "Number of threads running loops of kfree_rcu().");
594torture_param(int, kfree_alloc_num, 8000, "Number of allocations and frees done in an iteration.");
595torture_param(int, kfree_loops, 10, "Number of loops doing kfree_alloc_num allocations and frees.");
596
597static struct task_struct **kfree_reader_tasks;
598static int kfree_nrealthreads;
599static atomic_t n_kfree_perf_thread_started;
600static atomic_t n_kfree_perf_thread_ended;
601
602struct kfree_obj {
603 char kfree_obj[8];
604 struct rcu_head rh;
605};
606
607static int
608kfree_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
661static void
662kfree_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 */
682static int
683kfree_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
698static int __init
699kfree_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
735unwind:
736 torture_init_end();
737 kfree_perf_cleanup();
738 return firsterr;
739}
740
587static int __init741static int __init
588rcu_perf_init(void)742rcu_perf_init(void)
589{743{
@@ -616,6 +770,9 @@ rcu_perf_init(void) · 26 unmodified lines
616 if (cur_ops->init)770 if (cur_ops->init)
617 cur_ops->init();771 cur_ops->init();
618 772
773 if (kfree_rcu_test)
774 return kfree_perf_init();
775
619 nrealwriters = compute_real(nwriters);776 nrealwriters = compute_real(nwriters);
620 nrealreaders = compute_real(nreaders);777 nrealreaders = compute_real(nreaders);
621 atomic_set(&n_rcu_perf_reader_started, 0);778 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
1661struct rcu_fwd_cb {1661struct rcu_fwd_cb {
1662 struct rcu_head rh;1662 struct rcu_head rh;
1663 struct rcu_fwd_cb *rfc_next;1663 struct rcu_fwd_cb *rfc_next;
1664 struct rcu_fwd *rfc_rfp;
1664 int rfc_gps;1665 int rfc_gps;
1665};1666};
1666static DEFINE_SPINLOCK(rcu_fwd_lock);1667
1667static struct rcu_fwd_cb *rcu_fwd_cb_head;
1668static struct rcu_fwd_cb **rcu_fwd_cb_tail = &rcu_fwd_cb_head;
1669static long n_launders_cb;
1670static unsigned long rcu_fwd_startat;
1671static bool rcu_fwd_emergency_stop;
1672#define MAX_FWD_CB_JIFFIES (8 * HZ) /* Maximum CB test duration. */1668#define MAX_FWD_CB_JIFFIES (8 * HZ) /* Maximum CB test duration. */
1673#define MIN_FWD_CB_LAUNDERS 3 /* This many CB invocations to count. */1669#define MIN_FWD_CB_LAUNDERS 3 /* This many CB invocations to count. */
1674#define MIN_FWD_CBS_LAUNDERED 100 /* Number of counted CBs. */1670#define MIN_FWD_CBS_LAUNDERED 100 /* Number of counted CBs. */
1675#define FWD_CBS_HIST_DIV 10 /* Histogram buckets/second. */1671#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
1676struct rcu_launder_hist {1674struct rcu_launder_hist {
1677 long n_launders;1675 long n_launders;
1678 unsigned long launder_gp_seq;1676 unsigned long launder_gp_seq;
1679};1677};
1680#define N_LAUNDERS_HIST (2 * MAX_FWD_CB_JIFFIES / (HZ / FWD_CBS_HIST_DIV))
1681static struct rcu_launder_hist n_launders_hist[N_LAUNDERS_HIST];
1682static unsigned long rcu_launder_gp_seq_start;
1683 1678
1684static void rcu_torture_fwd_cb_hist(void)1679struct 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
1689struct rcu_fwd *rcu_fwds;
1690bool rcu_fwd_emergency_stop;
1691
1692static void rcu_torture_fwd_cb_hist(struct rcu_fwd *rfp)
1685{1693{
1686 unsigned long gps;1694 unsigned long gps;
1687 unsigned long gps_old;1695 unsigned long gps_old;
1688 int i;1696 int i;
1689 int j;1697 int j;
1690 1698
1691 for (i = ARRAY_SIZE(n_launders_hist) - 1; i > 0; i--)1699 for (i = ARRAY_SIZE(rfp->n_launders_hist) - 1; i > 0; i--)
1692 if (n_launders_hist[i].n_launders > 0)1700 if (rfp->n_launders_hist[i].n_launders > 0)
1693 break;1701 break;
1694 pr_alert("%s: Callback-invocation histogram (duration %lu jiffies):",1702 pr_alert("%s: Callback-invocation histogram (duration %lu jiffies):",
1695 __func__, jiffies - rcu_fwd_startat);1703 __func__, jiffies - rfp->rcu_fwd_startat);
1696 gps_old = rcu_launder_gp_seq_start;1704 gps_old = rfp->rcu_launder_gp_seq_start;
1697 for (j = 0; j <= i; j++) {1705 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;
1699 pr_cont(" %ds/%d: %ld:%ld",1707 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,
1701 rcutorture_seq_diff(gps, gps_old));1710 rcutorture_seq_diff(gps, gps_old));
1702 gps_old = gps;1711 gps_old = gps;
1703 }1712 }
@@ -1711,26 +1720,27 @@ static void rcu_torture_fwd_cb_cr(struct rcu_head *rhp) · 7 unmodified lines
1711 int i;1720 int i;
1712 struct rcu_fwd_cb *rfcp = container_of(rhp, struct rcu_fwd_cb, rh);1721 struct rcu_fwd_cb *rfcp = container_of(rhp, struct rcu_fwd_cb, rh);
1713 struct rcu_fwd_cb **rfcpp;1722 struct rcu_fwd_cb **rfcpp;
1723 struct rcu_fwd *rfp = rfcp->rfc_rfp;
1714 1724
1715 rfcp->rfc_next = NULL;1725 rfcp->rfc_next = NULL;
1716 rfcp->rfc_gps++;1726 rfcp->rfc_gps++;
1717 spin_lock_irqsave(&rcu_fwd_lock, flags);1727 spin_lock_irqsave(&rfp->rcu_fwd_lock, flags);
1718 rfcpp = rcu_fwd_cb_tail;1728 rfcpp = rfp->rcu_fwd_cb_tail;
1719 rcu_fwd_cb_tail = &rfcp->rfc_next;1729 rfp->rcu_fwd_cb_tail = &rfcp->rfc_next;
1720 WRITE_ONCE(*rfcpp, rfcp);1730 WRITE_ONCE(*rfcpp, rfcp);
1721 WRITE_ONCE(n_launders_cb, n_launders_cb + 1);1731 WRITE_ONCE(rfp->n_launders_cb, rfp->n_launders_cb + 1);
1722 i = ((jiffies - rcu_fwd_startat) / (HZ / FWD_CBS_HIST_DIV));1732 i = ((jiffies - rfp->rcu_fwd_startat) / (HZ / FWD_CBS_HIST_DIV));
1723 if (i >= ARRAY_SIZE(n_launders_hist))1733 if (i >= ARRAY_SIZE(rfp->n_launders_hist))
1724 i = ARRAY_SIZE(n_launders_hist) - 1;1734 i = ARRAY_SIZE(rfp->n_launders_hist) - 1;
1725 n_launders_hist[i].n_launders++;1735 rfp->n_launders_hist[i].n_launders++;
1726 n_launders_hist[i].launder_gp_seq = cur_ops->get_gp_seq();1736 rfp->n_launders_hist[i].launder_gp_seq = cur_ops->get_gp_seq();
1727 spin_unlock_irqrestore(&rcu_fwd_lock, flags);1737 spin_unlock_irqrestore(&rfp->rcu_fwd_lock, flags);
1728}1738}
1729 1739
1730// Give the scheduler a chance, even on nohz_full CPUs.1740// Give the scheduler a chance, even on nohz_full CPUs.
1731static void rcu_torture_fwd_prog_cond_resched(unsigned long iter)1741static void rcu_torture_fwd_prog_cond_resched(unsigned long iter)
1732{1742{
1733 if (IS_ENABLED(CONFIG_PREEMPT) && IS_ENABLED(CONFIG_NO_HZ_FULL)) {1743 if (IS_ENABLED(CONFIG_PREEMPTION) && IS_ENABLED(CONFIG_NO_HZ_FULL)) {
1734 // Real call_rcu() floods hit userspace, so emulate that.1744 // Real call_rcu() floods hit userspace, so emulate that.
1735 if (need_resched() || (iter & 0xfff))1745 if (need_resched() || (iter & 0xfff))
1736 schedule();1746 schedule();
@@ -1744,23 +1754,23 @@ static void rcu_torture_fwd_prog_cond_resched(unsigned long iter) · 7 unmodified lines
1744 * Free all callbacks on the rcu_fwd_cb_head list, either because the1754 * Free all callbacks on the rcu_fwd_cb_head list, either because the
1745 * test is over or because we hit an OOM event.1755 * test is over or because we hit an OOM event.
1746 */1756 */
1747static unsigned long rcu_torture_fwd_prog_cbfree(void)1757static unsigned long rcu_torture_fwd_prog_cbfree(struct rcu_fwd *rfp)
1748{1758{
1749 unsigned long flags;1759 unsigned long flags;
1750 unsigned long freed = 0;1760 unsigned long freed = 0;
1751 struct rcu_fwd_cb *rfcp;1761 struct rcu_fwd_cb *rfcp;
1752 1762
1753 for (;;) {1763 for (;;) {
1754 spin_lock_irqsave(&rcu_fwd_lock, flags);1764 spin_lock_irqsave(&rfp->rcu_fwd_lock, flags);
1755 rfcp = rcu_fwd_cb_head;1765 rfcp = rfp->rcu_fwd_cb_head;
1756 if (!rfcp) {1766 if (!rfcp) {
1757 spin_unlock_irqrestore(&rcu_fwd_lock, flags);1767 spin_unlock_irqrestore(&rfp->rcu_fwd_lock, flags);
1758 break;1768 break;
1759 }1769 }
1760 rcu_fwd_cb_head = rfcp->rfc_next;1770 rfp->rcu_fwd_cb_head = rfcp->rfc_next;
1761 if (!rcu_fwd_cb_head)1771 if (!rfp->rcu_fwd_cb_head)
1762 rcu_fwd_cb_tail = &rcu_fwd_cb_head;1772 rfp->rcu_fwd_cb_tail = &rfp->rcu_fwd_cb_head;
1763 spin_unlock_irqrestore(&rcu_fwd_lock, flags);1773 spin_unlock_irqrestore(&rfp->rcu_fwd_lock, flags);
1764 kfree(rfcp);1774 kfree(rfcp);
1765 freed++;1775 freed++;
1766 rcu_torture_fwd_prog_cond_resched(freed);1776 rcu_torture_fwd_prog_cond_resched(freed);
@@ -1774,7 +1784,8 @@ static unsigned long rcu_torture_fwd_prog_cbfree(void) · 7 unmodified lines
1774}1784}
1775 1785
1776/* Carry out need_resched()/cond_resched() forward-progress testing. */1786/* Carry out need_resched()/cond_resched() forward-progress testing. */
1777static void rcu_torture_fwd_prog_nr(int *tested, int *tested_tries)1787static void rcu_torture_fwd_prog_nr(struct rcu_fwd *rfp,
1788 int *tested, int *tested_tries)
1778{1789{
1779 unsigned long cver;1790 unsigned long cver;
1780 unsigned long dur;1791 unsigned long dur;
@@ -1804,8 +1815,8 @@ static void rcu_torture_fwd_prog_nr(int *tested, int *tested_tries) · 23 unmodified lines
1804 sd = cur_ops->stall_dur() + 1;1815 sd = cur_ops->stall_dur() + 1;
1805 sd4 = (sd + fwd_progress_div - 1) / fwd_progress_div;1816 sd4 = (sd + fwd_progress_div - 1) / fwd_progress_div;
1806 dur = sd4 + torture_random(&trs) % (sd - sd4);1817 dur = sd4 + torture_random(&trs) % (sd - sd4);
1807 WRITE_ONCE(rcu_fwd_startat, jiffies);1818 WRITE_ONCE(rfp->rcu_fwd_startat, jiffies);
1808 stopat = rcu_fwd_startat + dur;1819 stopat = rfp->rcu_fwd_startat + dur;
1809 while (time_before(jiffies, stopat) &&1820 while (time_before(jiffies, stopat) &&
1810 !shutdown_time_arrived() &&1821 !shutdown_time_arrived() &&
1811 !READ_ONCE(rcu_fwd_emergency_stop) && !torture_must_stop()) {1822 !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
1840}1851}
1841 1852
1842/* Carry out call_rcu() forward-progress testing. */1853/* Carry out call_rcu() forward-progress testing. */
1843static void rcu_torture_fwd_prog_cr(void)1854static void rcu_torture_fwd_prog_cr(struct rcu_fwd *rfp)
1844{1855{
1845 unsigned long cver;1856 unsigned long cver;
1846 unsigned long flags;1857 unsigned long flags;
@@ -1864,23 +1875,23 @@ static void rcu_torture_fwd_prog_cr(void) · 17 unmodified lines
1864 /* Loop continuously posting RCU callbacks. */1875 /* Loop continuously posting RCU callbacks. */
1865 WRITE_ONCE(rcu_fwd_cb_nodelay, true);1876 WRITE_ONCE(rcu_fwd_cb_nodelay, true);
1866 cur_ops->sync(); /* Later readers see above write. */1877 cur_ops->sync(); /* Later readers see above write. */
1867 WRITE_ONCE(rcu_fwd_startat, jiffies);1878 WRITE_ONCE(rfp->rcu_fwd_startat, jiffies);
1868 stopat = rcu_fwd_startat + MAX_FWD_CB_JIFFIES;1879 stopat = rfp->rcu_fwd_startat + MAX_FWD_CB_JIFFIES;
1869 n_launders = 0;1880 n_launders = 0;
1870 n_launders_cb = 0;1881 rfp->n_launders_cb = 0; // Hoist initialization for multi-kthread
1871 n_launders_sa = 0;1882 n_launders_sa = 0;
1872 n_max_cbs = 0;1883 n_max_cbs = 0;
1873 n_max_gps = 0;1884 n_max_gps = 0;
1874 for (i = 0; i < ARRAY_SIZE(n_launders_hist); i++)1885 for (i = 0; i < ARRAY_SIZE(rfp->n_launders_hist); i++)
1875 n_launders_hist[i].n_launders = 0;1886 rfp->n_launders_hist[i].n_launders = 0;
1876 cver = READ_ONCE(rcu_torture_current_version);1887 cver = READ_ONCE(rcu_torture_current_version);
1877 gps = cur_ops->get_gp_seq();1888 gps = cur_ops->get_gp_seq();
1878 rcu_launder_gp_seq_start = gps;1889 rfp->rcu_launder_gp_seq_start = gps;
1879 tick_dep_set_task(current, TICK_DEP_BIT_RCU);1890 tick_dep_set_task(current, TICK_DEP_BIT_RCU);
1880 while (time_before(jiffies, stopat) &&1891 while (time_before(jiffies, stopat) &&
1881 !shutdown_time_arrived() &&1892 !shutdown_time_arrived() &&
1882 !READ_ONCE(rcu_fwd_emergency_stop) && !torture_must_stop()) {1893 !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);
1884 rfcpn = NULL;1895 rfcpn = NULL;
1885 if (rfcp)1896 if (rfcp)
1886 rfcpn = READ_ONCE(rfcp->rfc_next);1897 rfcpn = READ_ONCE(rfcp->rfc_next);
@@ -1888,7 +1899,7 @@ static void rcu_torture_fwd_prog_cr(void) · 1 unmodified line
1888 if (rfcp->rfc_gps >= MIN_FWD_CB_LAUNDERS &&1899 if (rfcp->rfc_gps >= MIN_FWD_CB_LAUNDERS &&
1889 ++n_max_gps >= MIN_FWD_CBS_LAUNDERED)1900 ++n_max_gps >= MIN_FWD_CBS_LAUNDERED)
1890 break;1901 break;
1891 rcu_fwd_cb_head = rfcpn;1902 rfp->rcu_fwd_cb_head = rfcpn;
1892 n_launders++;1903 n_launders++;
1893 n_launders_sa++;1904 n_launders_sa++;
1894 } else {1905 } else {
@@ -1900,6 +1911,7 @@ static void rcu_torture_fwd_prog_cr(void) · 5 unmodified lines
1900 n_max_cbs++;1911 n_max_cbs++;
1901 n_launders_sa = 0;1912 n_launders_sa = 0;
1902 rfcp->rfc_gps = 0;1913 rfcp->rfc_gps = 0;
1914 rfcp->rfc_rfp = rfp;
1903 }1915 }
1904 cur_ops->call(&rfcp->rh, rcu_torture_fwd_cb_cr);1916 cur_ops->call(&rfcp->rh, rcu_torture_fwd_cb_cr);
1905 rcu_torture_fwd_prog_cond_resched(n_launders + n_max_cbs);1917 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
1910 }1922 }
1911 }1923 }
1912 stoppedat = jiffies;1924 stoppedat = jiffies;
1913 n_launders_cb_snap = READ_ONCE(n_launders_cb);1925 n_launders_cb_snap = READ_ONCE(rfp->n_launders_cb);
1914 cver = READ_ONCE(rcu_torture_current_version) - cver;1926 cver = READ_ONCE(rcu_torture_current_version) - cver;
1915 gps = rcutorture_seq_diff(cur_ops->get_gp_seq(), gps);1927 gps = rcutorture_seq_diff(cur_ops->get_gp_seq(), gps);
1916 cur_ops->cb_barrier(); /* Wait for callbacks to be invoked. */1928 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);
1918 1930
1919 if (!torture_must_stop() && !READ_ONCE(rcu_fwd_emergency_stop) &&1931 if (!torture_must_stop() && !READ_ONCE(rcu_fwd_emergency_stop) &&
1920 !shutdown_time_arrived()) {1932 !shutdown_time_arrived()) {
1921 WARN_ON(n_max_gps < MIN_FWD_CBS_LAUNDERED);1933 WARN_ON(n_max_gps < MIN_FWD_CBS_LAUNDERED);
1922 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",1934 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",
1923 __func__,1935 __func__,
1924 stoppedat - rcu_fwd_startat, jiffies - stoppedat,1936 stoppedat - rfp->rcu_fwd_startat, jiffies - stoppedat,
1925 n_launders + n_max_cbs - n_launders_cb_snap,1937 n_launders + n_max_cbs - n_launders_cb_snap,
1926 n_launders, n_launders_sa,1938 n_launders, n_launders_sa,
1927 n_max_gps, n_max_cbs, cver, gps);1939 n_max_gps, n_max_cbs, cver, gps);
1928 rcu_torture_fwd_cb_hist();1940 rcu_torture_fwd_cb_hist(rfp);
1929 }1941 }
1930 schedule_timeout_uninterruptible(HZ); /* Let CBs drain. */1942 schedule_timeout_uninterruptible(HZ); /* Let CBs drain. */
1931 tick_dep_clear_task(current, TICK_DEP_BIT_RCU);1943 tick_dep_clear_task(current, TICK_DEP_BIT_RCU);
@@ -1940,20 +1952,22 @@ static void rcu_torture_fwd_prog_cr(void) · 8 unmodified lines
1940static int rcutorture_oom_notify(struct notifier_block *self,1952static int rcutorture_oom_notify(struct notifier_block *self,
1941 unsigned long notused, void *nfreed)1953 unsigned long notused, void *nfreed)
1942{1954{
1955 struct rcu_fwd *rfp = rcu_fwds;
1956
1943 WARN(1, "%s invoked upon OOM during forward-progress testing.\n",1957 WARN(1, "%s invoked upon OOM during forward-progress testing.\n",
1944 __func__);1958 __func__);
1945 rcu_torture_fwd_cb_hist();1959 rcu_torture_fwd_cb_hist(rfp);
1946 rcu_fwd_progress_check(1 + (jiffies - READ_ONCE(rcu_fwd_startat)) / 2);1960 rcu_fwd_progress_check(1 + (jiffies - READ_ONCE(rfp->rcu_fwd_startat)) / 2);
1947 WRITE_ONCE(rcu_fwd_emergency_stop, true);1961 WRITE_ONCE(rcu_fwd_emergency_stop, true);
1948 smp_mb(); /* Emergency stop before free and wait to avoid hangs. */1962 smp_mb(); /* Emergency stop before free and wait to avoid hangs. */
1949 pr_info("%s: Freed %lu RCU callbacks.\n",1963 pr_info("%s: Freed %lu RCU callbacks.\n",
1950 __func__, rcu_torture_fwd_prog_cbfree());1964 __func__, rcu_torture_fwd_prog_cbfree(rfp));
1951 rcu_barrier();1965 rcu_barrier();
1952 pr_info("%s: Freed %lu RCU callbacks.\n",1966 pr_info("%s: Freed %lu RCU callbacks.\n",
1953 __func__, rcu_torture_fwd_prog_cbfree());1967 __func__, rcu_torture_fwd_prog_cbfree(rfp));
1954 rcu_barrier();1968 rcu_barrier();
1955 pr_info("%s: Freed %lu RCU callbacks.\n",1969 pr_info("%s: Freed %lu RCU callbacks.\n",
1956 __func__, rcu_torture_fwd_prog_cbfree());1970 __func__, rcu_torture_fwd_prog_cbfree(rfp));
1957 smp_mb(); /* Frees before return to avoid redoing OOM. */1971 smp_mb(); /* Frees before return to avoid redoing OOM. */
1958 (*(unsigned long *)nfreed)++; /* Forward progress CBs freed! */1972 (*(unsigned long *)nfreed)++; /* Forward progress CBs freed! */
1959 pr_info("%s returning after OOM processing.\n", __func__);1973 pr_info("%s returning after OOM processing.\n", __func__);
@@ -1967,6 +1981,7 @@ static struct notifier_block rcutorture_oom_nb = { · 7 unmodified lines
1967/* Carry out grace-period forward-progress testing. */1981/* Carry out grace-period forward-progress testing. */
1968static int rcu_torture_fwd_prog(void *args)1982static int rcu_torture_fwd_prog(void *args)
1969{1983{
1984 struct rcu_fwd *rfp = args;
1970 int tested = 0;1985 int tested = 0;
1971 int tested_tries = 0;1986 int tested_tries = 0;
1972 1987
@@ -1978,8 +1993,8 @@ static int rcu_torture_fwd_prog(void *args) · 5 unmodified lines
1978 schedule_timeout_interruptible(fwd_progress_holdoff * HZ);1993 schedule_timeout_interruptible(fwd_progress_holdoff * HZ);
1979 WRITE_ONCE(rcu_fwd_emergency_stop, false);1994 WRITE_ONCE(rcu_fwd_emergency_stop, false);
1980 register_oom_notifier(&rcutorture_oom_nb);1995 register_oom_notifier(&rcutorture_oom_nb);
1981 rcu_torture_fwd_prog_nr(&tested, &tested_tries);1996 rcu_torture_fwd_prog_nr(rfp, &tested, &tested_tries);
1982 rcu_torture_fwd_prog_cr();1997 rcu_torture_fwd_prog_cr(rfp);
1983 unregister_oom_notifier(&rcutorture_oom_nb);1998 unregister_oom_notifier(&rcutorture_oom_nb);
1984 1999
1985 /* Avoid slow periods, better to test when busy. */2000 /* Avoid slow periods, better to test when busy. */
@@ -1995,6 +2010,8 @@ static int rcu_torture_fwd_prog(void *args) · 9 unmodified lines
1995/* If forward-progress checking is requested and feasible, spawn the thread. */2010/* If forward-progress checking is requested and feasible, spawn the thread. */
1996static int __init rcu_torture_fwd_prog_init(void)2011static int __init rcu_torture_fwd_prog_init(void)
1997{2012{
2013 struct rcu_fwd *rfp;
2014
1998 if (!fwd_progress)2015 if (!fwd_progress)
1999 return 0; /* Not requested, so don't do it. */2016 return 0; /* Not requested, so don't do it. */
2000 if (!cur_ops->stall_dur || cur_ops->stall_dur() <= 0 ||2017 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
2013 fwd_progress_holdoff = 1;2030 fwd_progress_holdoff = 1;
2014 if (fwd_progress_div <= 0)2031 if (fwd_progress_div <= 0)
2015 fwd_progress_div = 4;2032 fwd_progress_div = 4;
2016 return torture_create_kthread(rcu_torture_fwd_prog,2033 rfp = kzalloc(sizeof(*rfp), GFP_KERNEL);
2017 NULL, fwd_prog_task);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);
2018}2039}
2019 2040
2020/* Callback function for RCU barrier testing. */2041/* 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
103 103
104/*104/*
105 * Workqueue handler to drive one grace period and invoke any callbacks105 * Workqueue handler to drive one grace period and invoke any callbacks
106 * that become ready as a result. Single-CPU and !PREEMPT operation106 * that become ready as a result. Single-CPU and !PREEMPTION operation
107 * means that we get away with murder on synchronization. ;-)107 * means that we get away with murder on synchronization. ;-)
108 */108 */
109void srcu_drive_gp(struct work_struct *wp)109void 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
530 idx = rcu_seq_state(ssp->srcu_gp_seq);530 idx = rcu_seq_state(ssp->srcu_gp_seq);
531 WARN_ON_ONCE(idx != SRCU_STATE_SCAN2);531 WARN_ON_ONCE(idx != SRCU_STATE_SCAN2);
532 cbdelay = srcu_get_delay(ssp);532 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());
534 rcu_seq_end(&ssp->srcu_gp_seq);534 rcu_seq_end(&ssp->srcu_gp_seq);
535 gpseq = rcu_seq_current(&ssp->srcu_gp_seq);535 gpseq = rcu_seq_current(&ssp->srcu_gp_seq);
536 if (ULONG_CMP_LT(ssp->srcu_gp_seq_needed_exp, gpseq))536 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
762 unsigned long flags;762 unsigned long flags;
763 struct srcu_data *sdp;763 struct srcu_data *sdp;
764 unsigned long t;764 unsigned long t;
765 unsigned long tlast;
765 766
766 /* If the local srcu_data structure has callbacks, not idle. */767 /* If the local srcu_data structure has callbacks, not idle. */
767 local_irq_save(flags);768 local_irq_save(flags);
@@ -780,9 +781,9 @@ static bool srcu_might_be_idle(struct srcu_struct *ssp) · 12 unmodified lines
780 781
781 /* First, see if enough time has passed since the last GP. */782 /* First, see if enough time has passed since the last GP. */
782 t = ktime_get_mono_fast_ns();783 t = ktime_get_mono_fast_ns();
784 tlast = READ_ONCE(ssp->srcu_last_gp_end);
783 if (exp_holdoff == 0 ||785 if (exp_holdoff == 0 ||
784 time_in_range_open(t, ssp->srcu_last_gp_end,786 time_in_range_open(t, tlast, tlast + exp_holdoff))
785 ssp->srcu_last_gp_end + exp_holdoff))
786 return false; /* Too soon after last GP. */787 return false; /* Too soon after last GP. */
787 788
788 /* Next, check for probable idleness. */789 /* Next, check for probable idleness. */
@@ -853,7 +854,7 @@ static void __call_srcu(struct srcu_struct *ssp, struct rcu_head *rhp, · 64 unmodified lines
853 local_irq_save(flags);854 local_irq_save(flags);
854 sdp = this_cpu_ptr(ssp->sda);855 sdp = this_cpu_ptr(ssp->sda);
855 spin_lock_rcu_node(sdp);856 spin_lock_rcu_node(sdp);
856 rcu_segcblist_enqueue(&sdp->srcu_cblist, rhp, false);857 rcu_segcblist_enqueue(&sdp->srcu_cblist, rhp);
857 rcu_segcblist_advance(&sdp->srcu_cblist,858 rcu_segcblist_advance(&sdp->srcu_cblist,
858 rcu_seq_current(&ssp->srcu_gp_seq));859 rcu_seq_current(&ssp->srcu_gp_seq));
859 s = rcu_seq_snap(&ssp->srcu_gp_seq);860 s = rcu_seq_snap(&ssp->srcu_gp_seq);
@@ -1052,7 +1053,7 @@ void srcu_barrier(struct srcu_struct *ssp) · 192 unmodified lines
1052 sdp->srcu_barrier_head.func = srcu_barrier_cb;1053 sdp->srcu_barrier_head.func = srcu_barrier_cb;
1053 debug_rcu_head_queue(&sdp->srcu_barrier_head);1054 debug_rcu_head_queue(&sdp->srcu_barrier_head);
1054 if (!rcu_segcblist_entrain(&sdp->srcu_cblist,1055 if (!rcu_segcblist_entrain(&sdp->srcu_cblist,
1055 &sdp->srcu_barrier_head, 0)) {1056 &sdp->srcu_barrier_head)) {
1056 debug_rcu_head_unqueue(&sdp->srcu_barrier_head);1057 debug_rcu_head_unqueue(&sdp->srcu_barrier_head);
1057 atomic_dec(&ssp->srcu_barrier_cpu_cnt);1058 atomic_dec(&ssp->srcu_barrier_cpu_cnt);
1058 }1059 }
kernel/rcu/tiny.c+27−1
@@ -22,6 +22,7 @@ · 21 unmodified lines
22#include <linux/time.h>22#include <linux/time.h>
23#include <linux/cpu.h>23#include <linux/cpu.h>
24#include <linux/prefetch.h>24#include <linux/prefetch.h>
25#include <linux/slab.h>
25 26
26#include "rcu.h"27#include "rcu.h"
27 28
@@ -73,6 +74,31 @@ void rcu_sched_clock_irq(int user) · 45 unmodified lines
73 }74 }
74}75}
75 76
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 */
81static 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
76/* Invoke the RCU callbacks whose grace period has elapsed. */102/* Invoke the RCU callbacks whose grace period has elapsed. */
77static __latent_entropy void rcu_process_callbacks(struct softirq_action *unused)103static __latent_entropy void rcu_process_callbacks(struct softirq_action *unused)
78{104{
@@ -100,7 +126,7 @@ static __latent_entropy void rcu_process_callbacks(struct softirq_action *unused · 21 unmodified lines
100 prefetch(next);126 prefetch(next);
101 debug_rcu_head_unqueue(list);127 debug_rcu_head_unqueue(list);
102 local_bh_disable();128 local_bh_disable();
103 __rcu_reclaim("", list);129 rcu_reclaim_tiny(list);
104 local_bh_enable();130 local_bh_enable();
105 list = next;131 list = next;
106 }132 }
kernel/rcu/tree.c+272−52
@@ -43,7 +43,6 @@ · 42 unmodified lines
43#include <uapi/linux/sched/types.h>43#include <uapi/linux/sched/types.h>
44#include <linux/prefetch.h>44#include <linux/prefetch.h>
45#include <linux/delay.h>45#include <linux/delay.h>
46#include <linux/stop_machine.h>
47#include <linux/random.h>46#include <linux/random.h>
48#include <linux/trace_events.h>47#include <linux/trace_events.h>
49#include <linux/suspend.h>48#include <linux/suspend.h>
@@ -55,6 +54,7 @@ · 5 unmodified lines
55#include <linux/oom.h>54#include <linux/oom.h>
56#include <linux/smpboot.h>55#include <linux/smpboot.h>
57#include <linux/jiffies.h>56#include <linux/jiffies.h>
57#include <linux/slab.h>
58#include <linux/sched/isolation.h>58#include <linux/sched/isolation.h>
59#include <linux/sched/clock.h>59#include <linux/sched/clock.h>
60#include "../time/tick-internal.h"60#include "../time/tick-internal.h"
@@ -84,7 +84,7 @@ static DEFINE_PER_CPU_SHARED_ALIGNED(struct rcu_data, rcu_data) = { · 23 unmodified lines
84 .dynticks_nmi_nesting = DYNTICK_IRQ_NONIDLE,84 .dynticks_nmi_nesting = DYNTICK_IRQ_NONIDLE,
85 .dynticks = ATOMIC_INIT(RCU_DYNTICK_CTRL_CTR),85 .dynticks = ATOMIC_INIT(RCU_DYNTICK_CTRL_CTR),
86};86};
87struct rcu_state rcu_state = {87static struct rcu_state rcu_state = {
88 .level = { &rcu_state.node[0] },88 .level = { &rcu_state.node[0] },
89 .gp_state = RCU_GP_IDLE,89 .gp_state = RCU_GP_IDLE,
90 .gp_seq = (0UL - 300UL) << RCU_SEQ_CTR_SHIFT,90 .gp_seq = (0UL - 300UL) << RCU_SEQ_CTR_SHIFT,
@@ -188,7 +188,7 @@ EXPORT_SYMBOL_GPL(rcu_get_gp_kthreads_prio); · 97 unmodified lines
188 * held, but the bit corresponding to the current CPU will be stable188 * held, but the bit corresponding to the current CPU will be stable
189 * in most contexts.189 * in most contexts.
190 */190 */
191unsigned long rcu_rnp_online_cpus(struct rcu_node *rnp)191static unsigned long rcu_rnp_online_cpus(struct rcu_node *rnp)
192{192{
193 return READ_ONCE(rnp->qsmaskinitnext);193 return READ_ONCE(rnp->qsmaskinitnext);
194}194}
@@ -294,7 +294,7 @@ static void rcu_dynticks_eqs_online(void) · 99 unmodified lines
294 *294 *
295 * No ordering, as we are sampling CPU-local information.295 * No ordering, as we are sampling CPU-local information.
296 */296 */
297bool rcu_dynticks_curr_cpu_in_eqs(void)297static bool rcu_dynticks_curr_cpu_in_eqs(void)
298{298{
299 struct rcu_data *rdp = this_cpu_ptr(&rcu_data);299 struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
300 300
@@ -305,7 +305,7 @@ bool rcu_dynticks_curr_cpu_in_eqs(void) · 4 unmodified lines
305 * Snapshot the ->dynticks counter with full ordering so as to allow305 * Snapshot the ->dynticks counter with full ordering so as to allow
306 * stable comparison of this counter with past and future snapshots.306 * stable comparison of this counter with past and future snapshots.
307 */307 */
308int rcu_dynticks_snap(struct rcu_data *rdp)308static int rcu_dynticks_snap(struct rcu_data *rdp)
309{309{
310 int snap = atomic_add_return(0, &rdp->dynticks);310 int snap = atomic_add_return(0, &rdp->dynticks);
311 311
@@ -528,16 +528,6 @@ static struct rcu_node *rcu_get_root(void) · 216 unmodified lines
528 return &rcu_state.node[0];528 return &rcu_state.node[0];
529}529}
530 530
531/*
532 * Convert a ->gp_state value to a character string.
533 */
534static 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
541/*531/*
542 * Send along grace-period-related data for rcutorture diagnostics.532 * Send along grace-period-related data for rcutorture diagnostics.
543 */533 */
@@ -577,7 +567,7 @@ static void rcu_eqs_enter(bool user) · 33 unmodified lines
577 }567 }
578 568
579 lockdep_assert_irqs_disabled();569 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));
581 WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && !user && !is_idle_task(current));571 WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && !user && !is_idle_task(current));
582 rdp = this_cpu_ptr(&rcu_data);572 rdp = this_cpu_ptr(&rcu_data);
583 do_nocb_deferred_wakeup(rdp);573 do_nocb_deferred_wakeup(rdp);
@@ -650,14 +640,15 @@ static __always_inline void rcu_nmi_exit_common(bool irq) · 66 unmodified lines
650 * leave it in non-RCU-idle state.640 * leave it in non-RCU-idle state.
651 */641 */
652 if (rdp->dynticks_nmi_nesting != 1) {642 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));
654 WRITE_ONCE(rdp->dynticks_nmi_nesting, /* No store tearing. */645 WRITE_ONCE(rdp->dynticks_nmi_nesting, /* No store tearing. */
655 rdp->dynticks_nmi_nesting - 2);646 rdp->dynticks_nmi_nesting - 2);
656 return;647 return;
657 }648 }
658 649
659 /* This NMI interrupted an RCU-idle CPU, restore RCU-idleness. */650 /* 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));
661 WRITE_ONCE(rdp->dynticks_nmi_nesting, 0); /* Avoid store tearing. */652 WRITE_ONCE(rdp->dynticks_nmi_nesting, 0); /* Avoid store tearing. */
662 653
663 if (irq)654 if (irq)
@@ -744,7 +735,7 @@ static void rcu_eqs_exit(bool user) · 80 unmodified lines
744 rcu_dynticks_task_exit();735 rcu_dynticks_task_exit();
745 rcu_dynticks_eqs_exit();736 rcu_dynticks_eqs_exit();
746 rcu_cleanup_after_idle();737 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));
748 WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && !user && !is_idle_task(current));739 WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) && !user && !is_idle_task(current));
749 WRITE_ONCE(rdp->dynticks_nesting, 1);740 WRITE_ONCE(rdp->dynticks_nesting, 1);
750 WARN_ON_ONCE(rdp->dynticks_nmi_nesting);741 WARN_ON_ONCE(rdp->dynticks_nmi_nesting);
@@ -800,8 +791,8 @@ void rcu_user_exit(void) · 49 unmodified lines
800 */791 */
801static __always_inline void rcu_nmi_enter_common(bool irq)792static __always_inline void rcu_nmi_enter_common(bool irq)
802{793{
803 struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
804 long incby = 2;794 long incby = 2;
795 struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
805 796
806 /* Complain about underflow. */797 /* Complain about underflow. */
807 WARN_ON_ONCE(rdp->dynticks_nmi_nesting < 0);798 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
828 } else if (tick_nohz_full_cpu(rdp->cpu) &&819 } else if (tick_nohz_full_cpu(rdp->cpu) &&
829 rdp->dynticks_nmi_nesting == DYNTICK_IRQ_NONIDLE &&820 rdp->dynticks_nmi_nesting == DYNTICK_IRQ_NONIDLE &&
830 READ_ONCE(rdp->rcu_urgent_qs) && !rdp->rcu_forced_tick) {821 READ_ONCE(rdp->rcu_urgent_qs) && !rdp->rcu_forced_tick) {
831 rdp->rcu_forced_tick = true;822 raw_spin_lock_rcu_node(rdp->mynode);
832 tick_dep_set_cpu(rdp->cpu, TICK_DEP_BIT_RCU);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);
833 }829 }
834 trace_rcu_dyntick(incby == 1 ? TPS("Endirq") : TPS("++="),830 trace_rcu_dyntick(incby == 1 ? TPS("Endirq") : TPS("++="),
835 rdp->dynticks_nmi_nesting,831 rdp->dynticks_nmi_nesting,
836 rdp->dynticks_nmi_nesting + incby, rdp->dynticks);832 rdp->dynticks_nmi_nesting + incby, atomic_read(&rdp->dynticks));
837 WRITE_ONCE(rdp->dynticks_nmi_nesting, /* Prevent store tearing. */833 WRITE_ONCE(rdp->dynticks_nmi_nesting, /* Prevent store tearing. */
838 rdp->dynticks_nmi_nesting + incby);834 rdp->dynticks_nmi_nesting + incby);
839 barrier();835 barrier();
@@ -898,6 +894,7 @@ void rcu_irq_enter_irqson(void) · 58 unmodified lines
898 */894 */
899static void rcu_disable_urgency_upon_qs(struct rcu_data *rdp)895static void rcu_disable_urgency_upon_qs(struct rcu_data *rdp)
900{896{
897 raw_lockdep_assert_held_rcu_node(rdp->mynode);
901 WRITE_ONCE(rdp->rcu_urgent_qs, false);898 WRITE_ONCE(rdp->rcu_urgent_qs, false);
902 WRITE_ONCE(rdp->rcu_need_heavy_qs, false);899 WRITE_ONCE(rdp->rcu_need_heavy_qs, false);
903 if (tick_nohz_full_cpu(rdp->cpu) && rdp->rcu_forced_tick) {900 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
1934 struct rcu_node *rnp_p;1931 struct rcu_node *rnp_p;
1935 1932
1936 raw_lockdep_assert_held_rcu_node(rnp);1933 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)) ||
1938 WARN_ON_ONCE(rcu_preempt_blocked_readers_cgp(rnp)) ||1935 WARN_ON_ONCE(rcu_preempt_blocked_readers_cgp(rnp)) ||
1939 rnp->qsmask != 0) {1936 rnp->qsmask != 0) {
1940 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);1937 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
@@ -2146,7 +2143,6 @@ static void rcu_do_batch(struct rcu_data *rdp) · 205 unmodified lines
2146 /* If no callbacks are ready, just return. */2143 /* If no callbacks are ready, just return. */
2147 if (!rcu_segcblist_ready_cbs(&rdp->cblist)) {2144 if (!rcu_segcblist_ready_cbs(&rdp->cblist)) {
2148 trace_rcu_batch_start(rcu_state.name,2145 trace_rcu_batch_start(rcu_state.name,
2149 rcu_segcblist_n_lazy_cbs(&rdp->cblist),
2150 rcu_segcblist_n_cbs(&rdp->cblist), 0);2146 rcu_segcblist_n_cbs(&rdp->cblist), 0);
2151 trace_rcu_batch_end(rcu_state.name, 0,2147 trace_rcu_batch_end(rcu_state.name, 0,
2152 !rcu_segcblist_empty(&rdp->cblist),2148 !rcu_segcblist_empty(&rdp->cblist),
@@ -2168,7 +2164,6 @@ static void rcu_do_batch(struct rcu_data *rdp) · 15 unmodified lines
2168 if (unlikely(bl > 100))2164 if (unlikely(bl > 100))
2169 tlimit = local_clock() + rcu_resched_ns;2165 tlimit = local_clock() + rcu_resched_ns;
2170 trace_rcu_batch_start(rcu_state.name,2166 trace_rcu_batch_start(rcu_state.name,
2171 rcu_segcblist_n_lazy_cbs(&rdp->cblist),
2172 rcu_segcblist_n_cbs(&rdp->cblist), bl);2167 rcu_segcblist_n_cbs(&rdp->cblist), bl);
2173 rcu_segcblist_extract_done_cbs(&rdp->cblist, &rcl);2168 rcu_segcblist_extract_done_cbs(&rdp->cblist, &rcl);
2174 if (offloaded)2169 if (offloaded)
@@ -2179,9 +2174,19 @@ static void rcu_do_batch(struct rcu_data *rdp) · 4 unmodified lines
2179 tick_dep_set_task(current, TICK_DEP_BIT_RCU);2174 tick_dep_set_task(current, TICK_DEP_BIT_RCU);
2180 rhp = rcu_cblist_dequeue(&rcl);2175 rhp = rcu_cblist_dequeue(&rcl);
2181 for (; rhp; rhp = rcu_cblist_dequeue(&rcl)) {2176 for (; rhp; rhp = rcu_cblist_dequeue(&rcl)) {
2177 rcu_callback_t f;
2178
2182 debug_rcu_head_unqueue(rhp);2179 debug_rcu_head_unqueue(rhp);
2183 if (__rcu_reclaim(rcu_state.name, rhp))2180
2184 rcu_cblist_dequeued_lazy(&rcl);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
2185 /*2190 /*
2186 * Stop only if limit reached and CPU has something to do.2191 * Stop only if limit reached and CPU has something to do.
2187 * Note: The rcl structure counts down from zero.2192 * 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
2294 mask = 0;2299 mask = 0;
2295 raw_spin_lock_irqsave_rcu_node(rnp, flags);2300 raw_spin_lock_irqsave_rcu_node(rnp, flags);
2296 if (rnp->qsmask == 0) {2301 if (rnp->qsmask == 0) {
2297 if (!IS_ENABLED(CONFIG_PREEMPTION) ||2302 if (!IS_ENABLED(CONFIG_PREEMPT_RCU) ||
2298 rcu_preempt_blocked_readers_cgp(rnp)) {2303 rcu_preempt_blocked_readers_cgp(rnp)) {
2299 /*2304 /*
2300 * No point in scanning bits because they2305 * 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
2308 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);2313 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
2309 continue;2314 continue;
2310 }2315 }
2311 for_each_leaf_node_possible_cpu(rnp, cpu) {2316 for_each_leaf_node_cpu_mask(rnp, cpu, rnp->qsmask) {
2312 unsigned long bit = leaf_node_cpu_bit(rnp, cpu);2317 rdp = per_cpu_ptr(&rcu_data, cpu);
2313 if ((rnp->qsmask & bit) != 0) {2318 if (f(rdp)) {
2314 rdp = per_cpu_ptr(&rcu_data, cpu);2319 mask |= rdp->grpmask;
2315 if (f(rdp)) {2320 rcu_disable_urgency_upon_qs(rdp);
2316 mask |= bit;
2317 rcu_disable_urgency_upon_qs(rdp);
2318 }
2319 }2321 }
2320 }2322 }
2321 if (mask != 0) {2323 if (mask != 0) {
@@ -2474,8 +2476,8 @@ static void rcu_cpu_kthread(unsigned int cpu) · 152 unmodified lines
2474 char work, *workp = this_cpu_ptr(&rcu_data.rcu_cpu_has_work);2476 char work, *workp = this_cpu_ptr(&rcu_data.rcu_cpu_has_work);
2475 int spincnt;2477 int spincnt;
2476 2478
2479 trace_rcu_utilization(TPS("Start CPU kthread@rcu_run"));
2477 for (spincnt = 0; spincnt < 10; spincnt++) {2480 for (spincnt = 0; spincnt < 10; spincnt++) {
2478 trace_rcu_utilization(TPS("Start CPU kthread@rcu_wait"));
2479 local_bh_disable();2481 local_bh_disable();
2480 *statusp = RCU_KTHREAD_RUNNING;2482 *statusp = RCU_KTHREAD_RUNNING;
2481 local_irq_disable();2483 local_irq_disable();
@@ -2583,7 +2585,7 @@ static void rcu_leak_callback(struct rcu_head *rhp) · 101 unmodified lines
2583 * is expected to specify a CPU.2585 * is expected to specify a CPU.
2584 */2586 */
2585static void2587static 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)
2587{2589{
2588 unsigned long flags;2590 unsigned long flags;
2589 struct rcu_data *rdp;2591 struct rcu_data *rdp;
@@ -2618,18 +2620,17 @@ __call_rcu(struct rcu_head *head, rcu_callback_t func, bool lazy) · 28 unmodified lines
2618 if (rcu_segcblist_empty(&rdp->cblist))2620 if (rcu_segcblist_empty(&rdp->cblist))
2619 rcu_segcblist_init(&rdp->cblist);2621 rcu_segcblist_init(&rdp->cblist);
2620 }2622 }
2623
2621 if (rcu_nocb_try_bypass(rdp, head, &was_alldone, flags))2624 if (rcu_nocb_try_bypass(rdp, head, &was_alldone, flags))
2622 return; // Enqueued onto ->nocb_bypass, so just leave.2625 return; // Enqueued onto ->nocb_bypass, so just leave.
2623 /* If we get here, rcu_nocb_try_bypass() acquired ->nocb_lock. */2626 /* 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);
2625 if (__is_kfree_rcu_offset((unsigned long)func))2628 if (__is_kfree_rcu_offset((unsigned long)func))
2626 trace_rcu_kfree_callback(rcu_state.name, head,2629 trace_rcu_kfree_callback(rcu_state.name, head,
2627 (unsigned long)func,2630 (unsigned long)func,
2628 rcu_segcblist_n_lazy_cbs(&rdp->cblist),
2629 rcu_segcblist_n_cbs(&rdp->cblist));2631 rcu_segcblist_n_cbs(&rdp->cblist));
2630 else2632 else
2631 trace_rcu_callback(rcu_state.name, head,2633 trace_rcu_callback(rcu_state.name, head,
2632 rcu_segcblist_n_lazy_cbs(&rdp->cblist),
2633 rcu_segcblist_n_cbs(&rdp->cblist));2634 rcu_segcblist_n_cbs(&rdp->cblist));
2634 2635
2635 /* Go handle any RCU core processing required. */2636 /* 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
2679 */2680 */
2680void call_rcu(struct rcu_head *head, rcu_callback_t func)2681void call_rcu(struct rcu_head *head, rcu_callback_t func)
2681{2682{
2682 __call_rcu(head, func, 0);2683 __call_rcu(head, func);
2683}2684}
2684EXPORT_SYMBOL_GPL(call_rcu);2685EXPORT_SYMBOL_GPL(call_rcu);
2685 2686
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
2699struct 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 */
2719struct 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
2728static 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 */
2734static 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
2686/*2769/*
2687 * Queue an RCU callback for lazy invocation after a grace period.2770 * Schedule the kfree batch RCU work to run in workqueue context after a GP.
2688 * This will likely be later named something like "call_rcu_lazy()",2771 *
2689 * but this change will require some way of tagging the lazy RCU2772 * This function is invoked by kfree_rcu_monitor() when the KFREE_DRAIN_JIFFIES
2690 * callbacks in the list of pending callbacks. Until then, this2773 * timeout has been reached.
2691 * function may only be called from __kfree_rcu().2774 */
2775static 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
2799static 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 */
2820static 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().
2692 */2846 */
2693void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func)2847void kfree_call_rcu(struct rcu_head *head, rcu_callback_t func)
2694{2848{
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
2875unlock_return:
2876 if (krcp->initialized)
2877 spin_unlock(&krcp->lock);
2878 local_irq_restore(flags);
2696}2879}
2697EXPORT_SYMBOL_GPL(kfree_call_rcu);2880EXPORT_SYMBOL_GPL(kfree_call_rcu);
2698 2881
2882void __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
2699/*2902/*
2700 * During early boot, any blocking grace-period wait automatically2903 * 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.
2702 *2905 *
2703 * Howevr, because a context switch is a grace period for !PREEMPT, any2906 * Howevr, because a context switch is a grace period for !PREEMPTION, any
2704 * blocking grace-period wait automatically implies a grace period if2907 * blocking grace-period wait automatically implies a grace period if
2705 * there is only one CPU online at any point time during execution of2908 * there is only one CPU online at any point time during execution of
2706 * either synchronize_rcu() or synchronize_rcu_expedited(). It is OK to2909 * 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
2896 debug_rcu_head_queue(&rdp->barrier_head);3099 debug_rcu_head_queue(&rdp->barrier_head);
2897 rcu_nocb_lock(rdp);3100 rcu_nocb_lock(rdp);
2898 WARN_ON_ONCE(!rcu_nocb_flush_bypass(rdp, NULL, jiffies));3101 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)) {
2900 atomic_inc(&rcu_state.barrier_cpu_count);3103 atomic_inc(&rcu_state.barrier_cpu_count);
2901 } else {3104 } else {
2902 debug_rcu_head_unqueue(&rdp->barrier_head);3105 debug_rcu_head_unqueue(&rdp->barrier_head);
@@ -3557,12 +3760,29 @@ static void __init rcu_dump_rcu_node_tree(void) · 654 unmodified lines
3557struct workqueue_struct *rcu_gp_wq;3760struct workqueue_struct *rcu_gp_wq;
3558struct workqueue_struct *rcu_par_gp_wq;3761struct workqueue_struct *rcu_par_gp_wq;
3559 3762
3763static 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
3560void __init rcu_init(void)3779void __init rcu_init(void)
3561{3780{
3562 int cpu;3781 int cpu;
3563 3782
3564 rcu_early_boot_tests();3783 rcu_early_boot_tests();
3565 3784
3785 kfree_rcu_batch_init();
3566 rcu_bootup_announce();3786 rcu_bootup_announce();
3567 rcu_init_geometry();3787 rcu_init_geometry();
3568 rcu_init_one();3788 rcu_init_one();
kernel/rcu/tree.h+1−17
@@ -16,7 +16,6 @@ · 15 unmodified lines
16#include <linux/cpumask.h>16#include <linux/cpumask.h>
17#include <linux/seqlock.h>17#include <linux/seqlock.h>
18#include <linux/swait.h>18#include <linux/swait.h>
19#include <linux/stop_machine.h>
20#include <linux/rcu_node_tree.h>19#include <linux/rcu_node_tree.h>
21 20
22#include "rcu_segcblist.h"21#include "rcu_segcblist.h"
@@ -182,8 +181,8 @@ struct rcu_data { · 159 unmodified lines
182 bool rcu_need_heavy_qs; /* GP old, so heavy quiescent state! */181 bool rcu_need_heavy_qs; /* GP old, so heavy quiescent state! */
183 bool rcu_urgent_qs; /* GP old need light quiescent state. */182 bool rcu_urgent_qs; /* GP old need light quiescent state. */
184 bool rcu_forced_tick; /* Forced tick to provide QS. */183 bool rcu_forced_tick; /* Forced tick to provide QS. */
184 bool rcu_forced_tick_exp; /* ... provide QS to expedited GP. */
185#ifdef CONFIG_RCU_FAST_NO_HZ185#ifdef CONFIG_RCU_FAST_NO_HZ
186 bool all_lazy; /* All CPU's CBs lazy at idle start? */
187 unsigned long last_accelerate; /* Last jiffy CBs were accelerated. */186 unsigned long last_accelerate; /* Last jiffy CBs were accelerated. */
188 unsigned long last_advance_all; /* Last jiffy CBs were all advanced. */187 unsigned long last_advance_all; /* Last jiffy CBs were all advanced. */
189 int tick_nohz_enabled_snap; /* Previously seen value from sysfs. */188 int tick_nohz_enabled_snap; /* Previously seen value from sysfs. */
@@ -368,18 +367,6 @@ struct rcu_state { · 178 unmodified lines
368#define RCU_GP_CLEANUP 7 /* Grace-period cleanup started. */367#define RCU_GP_CLEANUP 7 /* Grace-period cleanup started. */
369#define RCU_GP_CLEANED 8 /* Grace-period cleanup complete. */368#define RCU_GP_CLEANED 8 /* Grace-period cleanup complete. */
370 369
371static 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
383/*370/*
384 * In order to export the rcu_state name to the tracing tools, it371 * In order to export the rcu_state name to the tracing tools, it
385 * needs to be added in the __tracepoint_string section.372 * 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
403#define RCU_NAME rcu_name390#define RCU_NAME rcu_name
404#endif /* #else #ifdef CONFIG_TRACING */391#endif /* #else #ifdef CONFIG_TRACING */
405 392
406int rcu_dynticks_snap(struct rcu_data *rdp);
407
408/* Forward declarations for tree_plugin.h */393/* Forward declarations for tree_plugin.h */
409static void rcu_bootup_announce(void);394static void rcu_bootup_announce(void);
410static void rcu_qs(void);395static void rcu_qs(void);
@@ -415,7 +400,6 @@ static bool rcu_preempt_has_tasks(struct rcu_node *rnp); · 4 unmodified lines
415static int rcu_print_task_exp_stall(struct rcu_node *rnp);400static int rcu_print_task_exp_stall(struct rcu_node *rnp);
416static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp);401static void rcu_preempt_check_blocked_tasks(struct rcu_node *rnp);
417static void rcu_flavor_sched_clock_irq(int user);402static void rcu_flavor_sched_clock_irq(int user);
418void call_rcu(struct rcu_head *head, rcu_callback_t func);
419static void dump_blkd_tasks(struct rcu_node *rnp, int ncheck);403static void dump_blkd_tasks(struct rcu_node *rnp, int ncheck);
420static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags);404static void rcu_initiate_boost(struct rcu_node *rnp, unsigned long flags);
421static void rcu_preempt_boost_start_gp(struct rcu_node *rnp);405static 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
21}21}
22 22
23/*23/*
24 * Return then value that expedited-grace-period counter will have24 * Return the value that the expedited-grace-period counter will have
25 * at the end of the current grace period.25 * at the end of the current grace period.
26 */26 */
27static __maybe_unused unsigned long rcu_exp_gp_seq_endval(void)27static __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
39}39}
40 40
41/*41/*
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.
43 */45 */
44static unsigned long rcu_exp_gp_seq_snap(void)46static unsigned long rcu_exp_gp_seq_snap(void)
45{47{
@@ -134,7 +136,7 @@ static void __maybe_unused sync_exp_reset_tree(void) · 88 unmodified lines
134 rcu_for_each_node_breadth_first(rnp) {136 rcu_for_each_node_breadth_first(rnp) {
135 raw_spin_lock_irqsave_rcu_node(rnp, flags);137 raw_spin_lock_irqsave_rcu_node(rnp, flags);
136 WARN_ON_ONCE(rnp->expmask);138 WARN_ON_ONCE(rnp->expmask);
137 rnp->expmask = rnp->expmaskinit;139 WRITE_ONCE(rnp->expmask, rnp->expmaskinit);
138 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);140 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
139 }141 }
140}142}
@@ -143,31 +145,26 @@ static void __maybe_unused sync_exp_reset_tree(void) · 2 unmodified lines
143 * Return non-zero if there is no RCU expedited grace period in progress145 * Return non-zero if there is no RCU expedited grace period in progress
144 * for the specified rcu_node structure, in other words, if all CPUs and146 * for the specified rcu_node structure, in other words, if all CPUs and
145 * tasks covered by the specified rcu_node structure have done their bit147 * tasks covered by the specified rcu_node structure have done their bit
146 * for the current expedited grace period. Works only for preemptible148 * for the current expedited grace period.
147 * RCU -- other RCU implementation use other means.
148 *
149 * Caller must hold the specificed rcu_node structure's ->lock
150 */149 */
151static bool sync_rcu_preempt_exp_done(struct rcu_node *rnp)150static bool sync_rcu_exp_done(struct rcu_node *rnp)
152{151{
153 raw_lockdep_assert_held_rcu_node(rnp);152 raw_lockdep_assert_held_rcu_node(rnp);
154
155 return rnp->exp_tasks == NULL &&153 return rnp->exp_tasks == NULL &&
156 READ_ONCE(rnp->expmask) == 0;154 READ_ONCE(rnp->expmask) == 0;
157}155}
158 156
159/*157/*
160 * Like sync_rcu_preempt_exp_done(), but this function assumes the caller158 * Like sync_rcu_exp_done(), but where the caller does not hold the
161 * doesn't hold the rcu_node's ->lock, and will acquire and release the lock159 * rcu_node's ->lock.
162 * itself
163 */160 */
164static bool sync_rcu_preempt_exp_done_unlocked(struct rcu_node *rnp)161static bool sync_rcu_exp_done_unlocked(struct rcu_node *rnp)
165{162{
166 unsigned long flags;163 unsigned long flags;
167 bool ret;164 bool ret;
168 165
169 raw_spin_lock_irqsave_rcu_node(rnp, flags);166 raw_spin_lock_irqsave_rcu_node(rnp, flags);
170 ret = sync_rcu_preempt_exp_done(rnp);167 ret = sync_rcu_exp_done(rnp);
171 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);168 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
172 169
173 return ret;170 return ret;
@@ -181,8 +178,6 @@ static bool sync_rcu_preempt_exp_done_unlocked(struct rcu_node *rnp) · 7 unmodified lines
181 * which the task was queued or to one of that rcu_node structure's ancestors,178 * which the task was queued or to one of that rcu_node structure's ancestors,
182 * recursively up the tree. (Calm down, calm down, we do the recursion179 * recursively up the tree. (Calm down, calm down, we do the recursion
183 * iteratively!)180 * iteratively!)
184 *
185 * Caller must hold the specified rcu_node structure's ->lock.
186 */181 */
187static void __rcu_report_exp_rnp(struct rcu_node *rnp,182static void __rcu_report_exp_rnp(struct rcu_node *rnp,
188 bool wake, unsigned long flags)183 bool wake, unsigned long flags)
@@ -190,8 +185,9 @@ static void __rcu_report_exp_rnp(struct rcu_node *rnp, · 1 unmodified line
190{185{
191 unsigned long mask;186 unsigned long mask;
192 187
188 raw_lockdep_assert_held_rcu_node(rnp);
193 for (;;) {189 for (;;) {
194 if (!sync_rcu_preempt_exp_done(rnp)) {190 if (!sync_rcu_exp_done(rnp)) {
195 if (!rnp->expmask)191 if (!rnp->expmask)
196 rcu_initiate_boost(rnp, flags);192 rcu_initiate_boost(rnp, flags);
197 else193 else
@@ -211,7 +207,7 @@ static void __rcu_report_exp_rnp(struct rcu_node *rnp, · 13 unmodified lines
211 rnp = rnp->parent;207 rnp = rnp->parent;
212 raw_spin_lock_rcu_node(rnp); /* irqs already disabled */208 raw_spin_lock_rcu_node(rnp); /* irqs already disabled */
213 WARN_ON_ONCE(!(rnp->expmask & mask));209 WARN_ON_ONCE(!(rnp->expmask & mask));
214 rnp->expmask &= ~mask;210 WRITE_ONCE(rnp->expmask, rnp->expmask & ~mask);
215 }211 }
216}212}
217 213
@@ -234,14 +230,23 @@ static void __maybe_unused rcu_report_exp_rnp(struct rcu_node *rnp, bool wake) · 16 unmodified lines
234static void rcu_report_exp_cpu_mult(struct rcu_node *rnp,230static void rcu_report_exp_cpu_mult(struct rcu_node *rnp,
235 unsigned long mask, bool wake)231 unsigned long mask, bool wake)
236{232{
233 int cpu;
237 unsigned long flags;234 unsigned long flags;
235 struct rcu_data *rdp;
238 236
239 raw_spin_lock_irqsave_rcu_node(rnp, flags);237 raw_spin_lock_irqsave_rcu_node(rnp, flags);
240 if (!(rnp->expmask & mask)) {238 if (!(rnp->expmask & mask)) {
241 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);239 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
242 return;240 return;
243 }241 }
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 }
245 __rcu_report_exp_rnp(rnp, wake, flags); /* Releases rnp->lock. */250 __rcu_report_exp_rnp(rnp, wake, flags); /* Releases rnp->lock. */
246}251}
247 252
@@ -345,8 +350,8 @@ static void sync_rcu_exp_select_node_cpus(struct work_struct *wp) · 97 unmodified lines
345 /* Each pass checks a CPU for identity, offline, and idle. */350 /* Each pass checks a CPU for identity, offline, and idle. */
346 mask_ofl_test = 0;351 mask_ofl_test = 0;
347 for_each_leaf_node_cpu_mask(rnp, cpu, rnp->expmask) {352 for_each_leaf_node_cpu_mask(rnp, cpu, rnp->expmask) {
348 unsigned long mask = leaf_node_cpu_bit(rnp, cpu);
349 struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);353 struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
354 unsigned long mask = rdp->grpmask;
350 int snap;355 int snap;
351 356
352 if (raw_smp_processor_id() == cpu ||357 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
372 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);377 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
373 378
374 /* IPI the remaining CPUs for expedited quiescent state. */379 /* IPI the remaining CPUs for expedited quiescent state. */
375 for_each_leaf_node_cpu_mask(rnp, cpu, rnp->expmask) {380 for_each_leaf_node_cpu_mask(rnp, cpu, mask_ofl_ipi) {
376 unsigned long mask = leaf_node_cpu_bit(rnp, cpu);
377 struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);381 struct rcu_data *rdp = per_cpu_ptr(&rcu_data, cpu);
382 unsigned long mask = rdp->grpmask;
378 383
379 if (!(mask_ofl_ipi & mask))
380 continue;
381retry_ipi:384retry_ipi:
382 if (rcu_dynticks_in_eqs_since(rdp, rdp->exp_dynticks_snap)) {385 if (rcu_dynticks_in_eqs_since(rdp, rdp->exp_dynticks_snap)) {
383 mask_ofl_test |= mask;386 mask_ofl_test |= mask;
@@ -389,10 +392,10 @@ retry_ipi: · 5 unmodified lines
389 }392 }
390 ret = smp_call_function_single(cpu, rcu_exp_handler, NULL, 0);393 ret = smp_call_function_single(cpu, rcu_exp_handler, NULL, 0);
391 put_cpu();394 put_cpu();
392 if (!ret) {395 /* The CPU will report the QS in response to the IPI. */
393 mask_ofl_ipi &= ~mask;396 if (!ret)
394 continue;397 continue;
395 }398
396 /* Failed, raced with CPU hotplug operation. */399 /* Failed, raced with CPU hotplug operation. */
397 raw_spin_lock_irqsave_rcu_node(rnp, flags);400 raw_spin_lock_irqsave_rcu_node(rnp, flags);
398 if ((rnp->qsmaskinitnext & mask) &&401 if ((rnp->qsmaskinitnext & mask) &&
@@ -403,13 +406,12 @@ retry_ipi: · 4 unmodified lines
403 schedule_timeout_uninterruptible(1);406 schedule_timeout_uninterruptible(1);
404 goto retry_ipi;407 goto retry_ipi;
405 }408 }
406 /* CPU really is offline, so we can ignore it. */409 /* CPU really is offline, so we must report its QS. */
407 if (!(rnp->expmask & mask))410 if (rnp->expmask & mask)
408 mask_ofl_ipi &= ~mask;411 mask_ofl_test |= mask;
409 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);412 raw_spin_unlock_irqrestore_rcu_node(rnp, flags);
410 }413 }
411 /* Report quiescent states for those that went offline. */414 /* Report quiescent states for those that went offline. */
412 mask_ofl_test |= mask_ofl_ipi;
413 if (mask_ofl_test)415 if (mask_ofl_test)
414 rcu_report_exp_cpu_mult(rnp, mask_ofl_test, false);416 rcu_report_exp_cpu_mult(rnp, mask_ofl_test, false);
415}417}
@@ -456,29 +458,62 @@ static void sync_rcu_exp_select_cpus(void) · 40 unmodified lines
456 flush_work(&rnp->rew.rew_work);458 flush_work(&rnp->rew.rew_work);
457}459}
458 460
459static 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 */
466static 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 */
485static void synchronize_rcu_expedited_wait(void)
460{486{
461 int cpu;487 int cpu;
462 unsigned long jiffies_stall;488 unsigned long jiffies_stall;
463 unsigned long jiffies_start;489 unsigned long jiffies_start;
464 unsigned long mask;490 unsigned long mask;
465 int ndetected;491 int ndetected;
492 struct rcu_data *rdp;
466 struct rcu_node *rnp;493 struct rcu_node *rnp;
467 struct rcu_node *rnp_root = rcu_get_root();494 struct rcu_node *rnp_root = rcu_get_root();
468 int ret;
469 495
470 trace_rcu_exp_grace_period(rcu_state.name, rcu_exp_gp_seq_endval(), TPS("startwait"));496 trace_rcu_exp_grace_period(rcu_state.name, rcu_exp_gp_seq_endval(), TPS("startwait"));
471 jiffies_stall = rcu_jiffies_till_stall_check();497 jiffies_stall = rcu_jiffies_till_stall_check();
472 jiffies_start = jiffies;498 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 }
473 513
474 for (;;) {514 for (;;) {
475 ret = swait_event_timeout_exclusive(515 if (synchronize_rcu_expedited_wait_once(jiffies_stall))
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))
480 return;516 return;
481 WARN_ON(ret < 0); /* workqueues should not be signaled. */
482 if (rcu_cpu_stall_suppress)517 if (rcu_cpu_stall_suppress)
483 continue;518 continue;
484 panic_on_rcu_stall();519 panic_on_rcu_stall();
@@ -491,7 +526,7 @@ static void synchronize_sched_expedited_wait(void) · 6 unmodified lines
491 struct rcu_data *rdp;526 struct rcu_data *rdp;
492 527
493 mask = leaf_node_cpu_bit(rnp, cpu);528 mask = leaf_node_cpu_bit(rnp, cpu);
494 if (!(rnp->expmask & mask))529 if (!(READ_ONCE(rnp->expmask) & mask))
495 continue;530 continue;
496 ndetected++;531 ndetected++;
497 rdp = per_cpu_ptr(&rcu_data, cpu);532 rdp = per_cpu_ptr(&rcu_data, cpu);
@@ -503,17 +538,18 @@ static void synchronize_sched_expedited_wait(void) · 5 unmodified lines
503 }538 }
504 pr_cont(" } %lu jiffies s: %lu root: %#lx/%c\n",539 pr_cont(" } %lu jiffies s: %lu root: %#lx/%c\n",
505 jiffies - jiffies_start, rcu_state.expedited_sequence,540 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]);
507 if (ndetected) {543 if (ndetected) {
508 pr_err("blocking rcu_node structures:");544 pr_err("blocking rcu_node structures:");
509 rcu_for_each_node_breadth_first(rnp) {545 rcu_for_each_node_breadth_first(rnp) {
510 if (rnp == rnp_root)546 if (rnp == rnp_root)
511 continue; /* printed unconditionally */547 continue; /* printed unconditionally */
512 if (sync_rcu_preempt_exp_done_unlocked(rnp))548 if (sync_rcu_exp_done_unlocked(rnp))
513 continue;549 continue;
514 pr_cont(" l=%u:%d-%d:%#lx/%c",550 pr_cont(" l=%u:%d-%d:%#lx/%c",
515 rnp->level, rnp->grplo, rnp->grphi,551 rnp->level, rnp->grplo, rnp->grphi,
516 rnp->expmask,552 READ_ONCE(rnp->expmask),
517 ".T"[!!rnp->exp_tasks]);553 ".T"[!!rnp->exp_tasks]);
518 }554 }
519 pr_cont("\n");555 pr_cont("\n");
@@ -521,7 +557,7 @@ static void synchronize_sched_expedited_wait(void) · 1 unmodified line
521 rcu_for_each_leaf_node(rnp) {557 rcu_for_each_leaf_node(rnp) {
522 for_each_leaf_node_possible_cpu(rnp, cpu) {558 for_each_leaf_node_possible_cpu(rnp, cpu) {
523 mask = leaf_node_cpu_bit(rnp, cpu);559 mask = leaf_node_cpu_bit(rnp, cpu);
524 if (!(rnp->expmask & mask))560 if (!(READ_ONCE(rnp->expmask) & mask))
525 continue;561 continue;
526 dump_cpu_task(cpu);562 dump_cpu_task(cpu);
527 }563 }
@@ -540,15 +576,14 @@ static void rcu_exp_wait_wake(unsigned long s) · 12 unmodified lines
540{576{
541 struct rcu_node *rnp;577 struct rcu_node *rnp;
542 578
543 synchronize_sched_expedited_wait();579 synchronize_rcu_expedited_wait();
544 rcu_exp_gp_seq_end();
545 trace_rcu_exp_grace_period(rcu_state.name, s, TPS("end"));
546 580
547 /*581 // Switch over to wakeup mode, allowing the next GP to proceed.
548 * Switch over to wakeup mode, allowing the next GP, but -only- the582 // End the previous grace period only after acquiring the mutex
549 * next GP, to proceed.583 // to ensure that only one GP runs concurrently with wakeups.
550 */
551 mutex_lock(&rcu_state.exp_wake_mutex);584 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"));
552 587
553 rcu_for_each_node_breadth_first(rnp) {588 rcu_for_each_node_breadth_first(rnp) {
554 if (ULONG_CMP_LT(READ_ONCE(rnp->exp_seq_rq), s)) {589 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
559 spin_unlock(&rnp->exp_lock);594 spin_unlock(&rnp->exp_lock);
560 }595 }
561 smp_mb(); /* All above changes before wakeup. */596 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]);
563 }598 }
564 trace_rcu_exp_grace_period(rcu_state.name, s, TPS("endwake"));599 trace_rcu_exp_grace_period(rcu_state.name, s, TPS("endwake"));
565 mutex_unlock(&rcu_state.exp_wake_mutex);600 mutex_unlock(&rcu_state.exp_wake_mutex);
@@ -610,7 +645,7 @@ static void rcu_exp_handler(void *unused) · 44 unmodified lines
610 * critical section. If also enabled or idle, immediately645 * critical section. If also enabled or idle, immediately
611 * report the quiescent state, otherwise defer.646 * report the quiescent state, otherwise defer.
612 */647 */
613 if (!t->rcu_read_lock_nesting) {648 if (!rcu_preempt_depth()) {
614 if (!(preempt_count() & (PREEMPT_MASK | SOFTIRQ_MASK)) ||649 if (!(preempt_count() & (PREEMPT_MASK | SOFTIRQ_MASK)) ||
615 rcu_dynticks_curr_cpu_in_eqs()) {650 rcu_dynticks_curr_cpu_in_eqs()) {
616 rcu_report_exp_rdp(rdp);651 rcu_report_exp_rdp(rdp);
@@ -634,7 +669,7 @@ static void rcu_exp_handler(void *unused) · 17 unmodified lines
634 * can have caused this quiescent state to already have been669 * can have caused this quiescent state to already have been
635 * reported, so we really do need to check ->expmask.670 * reported, so we really do need to check ->expmask.
636 */671 */
637 if (t->rcu_read_lock_nesting > 0) {672 if (rcu_preempt_depth() > 0) {
638 raw_spin_lock_irqsave_rcu_node(rnp, flags);673 raw_spin_lock_irqsave_rcu_node(rnp, flags);
639 if (rnp->expmask & rdp->grpmask) {674 if (rnp->expmask & rdp->grpmask) {
640 rdp->exp_deferred_qs = true;675 rdp->exp_deferred_qs = true;
@@ -670,7 +705,7 @@ static void rcu_exp_handler(void *unused) · 29 unmodified lines
670 }705 }
671}706}
672 707
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. */
674static void sync_sched_exp_online_cleanup(int cpu)709static void sync_sched_exp_online_cleanup(int cpu)
675{710{
676}711}
@@ -785,7 +820,7 @@ static int rcu_print_task_exp_stall(struct rcu_node *rnp) · 108 unmodified lines
785 * implementations, it is still unfriendly to real-time workloads, so is820 * implementations, it is still unfriendly to real-time workloads, so is
786 * thus not recommended for any sort of common-case code. In fact, if821 * thus not recommended for any sort of common-case code. In fact, if
787 * you are using synchronize_rcu_expedited() in a loop, please restructure822 * 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()
789 * instead.824 * instead.
790 *825 *
791 * This has the same semantics as (but is more brutal than) synchronize_rcu().826 * 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
220 * blocked tasks.220 * blocked tasks.
221 */221 */
222 if (!rnp->gp_tasks && (blkd_state & RCU_GP_BLKD)) {222 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);
224 WARN_ON_ONCE(rnp->completedqs == rnp->gp_seq);224 WARN_ON_ONCE(rnp->completedqs == rnp->gp_seq);
225 }225 }
226 if (!rnp->exp_tasks && (blkd_state & RCU_EXP_BLKD))226 if (!rnp->exp_tasks && (blkd_state & RCU_EXP_BLKD))
@@ -290,8 +290,8 @@ void rcu_note_context_switch(bool preempt) · 63 unmodified lines
290 290
291 trace_rcu_utilization(TPS("Start context switch"));291 trace_rcu_utilization(TPS("Start context switch"));
292 lockdep_assert_irqs_disabled();292 lockdep_assert_irqs_disabled();
293 WARN_ON_ONCE(!preempt && t->rcu_read_lock_nesting > 0);293 WARN_ON_ONCE(!preempt && rcu_preempt_depth() > 0);
294 if (t->rcu_read_lock_nesting > 0 &&294 if (rcu_preempt_depth() > 0 &&
295 !t->rcu_read_unlock_special.b.blocked) {295 !t->rcu_read_unlock_special.b.blocked) {
296 296
297 /* Possibly blocking in an RCU read-side critical section. */297 /* Possibly blocking in an RCU read-side critical section. */
@@ -340,7 +340,7 @@ EXPORT_SYMBOL_GPL(rcu_note_context_switch); · 42 unmodified lines
340 */340 */
341static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp)341static int rcu_preempt_blocked_readers_cgp(struct rcu_node *rnp)
342{342{
343 return rnp->gp_tasks != NULL;343 return READ_ONCE(rnp->gp_tasks) != NULL;
344}344}
345 345
346/* Bias and limit values for ->rcu_read_lock_nesting. */346/* 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
348#define RCU_NEST_NMAX (-INT_MAX / 2)348#define RCU_NEST_NMAX (-INT_MAX / 2)
349#define RCU_NEST_PMAX (INT_MAX / 2)349#define RCU_NEST_PMAX (INT_MAX / 2)
350 350
351static void rcu_preempt_read_enter(void)
352{
353 current->rcu_read_lock_nesting++;
354}
355
356static void rcu_preempt_read_exit(void)
357{
358 current->rcu_read_lock_nesting--;
359}
360
361static void rcu_preempt_depth_set(int val)
362{
363 current->rcu_read_lock_nesting = val;
364}
365
351/*366/*
352 * Preemptible RCU implementation for rcu_read_lock().367 * Preemptible RCU implementation for rcu_read_lock().
353 * Just increment ->rcu_read_lock_nesting, shared state will be updated368 * 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
355 */370 */
356void __rcu_read_lock(void)371void __rcu_read_lock(void)
357{372{
358 current->rcu_read_lock_nesting++;373 rcu_preempt_read_enter();
359 if (IS_ENABLED(CONFIG_PROVE_LOCKING))374 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);
361 barrier(); /* critical section after entry code. */376 barrier(); /* critical section after entry code. */
362}377}
363EXPORT_SYMBOL_GPL(__rcu_read_lock);378EXPORT_SYMBOL_GPL(__rcu_read_lock);
@@ -373,19 +388,19 @@ void __rcu_read_unlock(void) · 9 unmodified lines
373{388{
374 struct task_struct *t = current;389 struct task_struct *t = current;
375 390
376 if (t->rcu_read_lock_nesting != 1) {391 if (rcu_preempt_depth() != 1) {
377 --t->rcu_read_lock_nesting;392 rcu_preempt_read_exit();
378 } else {393 } else {
379 barrier(); /* critical section before exit code. */394 barrier(); /* critical section before exit code. */
380 t->rcu_read_lock_nesting = -RCU_NEST_BIAS;395 rcu_preempt_depth_set(-RCU_NEST_BIAS);
381 barrier(); /* assign before ->rcu_read_unlock_special load */396 barrier(); /* assign before ->rcu_read_unlock_special load */
382 if (unlikely(READ_ONCE(t->rcu_read_unlock_special.s)))397 if (unlikely(READ_ONCE(t->rcu_read_unlock_special.s)))
383 rcu_read_unlock_special(t);398 rcu_read_unlock_special(t);
384 barrier(); /* ->rcu_read_unlock_special load before assign */399 barrier(); /* ->rcu_read_unlock_special load before assign */
385 t->rcu_read_lock_nesting = 0;400 rcu_preempt_depth_set(0);
386 }401 }
387 if (IS_ENABLED(CONFIG_PROVE_LOCKING)) {402 if (IS_ENABLED(CONFIG_PROVE_LOCKING)) {
388 int rrln = t->rcu_read_lock_nesting;403 int rrln = rcu_preempt_depth();
389 404
390 WARN_ON_ONCE(rrln < 0 && rrln > RCU_NEST_NMAX);405 WARN_ON_ONCE(rrln < 0 && rrln > RCU_NEST_NMAX);
391 }406 }
@@ -444,15 +459,9 @@ rcu_preempt_deferred_qs_irqrestore(struct task_struct *t, unsigned long flags) · 52 unmodified lines
444 local_irq_restore(flags);459 local_irq_restore(flags);
445 return;460 return;
446 }461 }
447 t->rcu_read_unlock_special.b.deferred_qs = false;462 t->rcu_read_unlock_special.s = 0;
448 if (special.b.need_qs) {463 if (special.b.need_qs)
449 rcu_qs();464 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 }
456 465
457 /*466 /*
458 * Respond to a request by an expedited grace period for a467 * 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
460 * tasks are handled when removing the task from the469 * tasks are handled when removing the task from the
461 * blocked-tasks list below.470 * blocked-tasks list below.
462 */471 */
463 if (rdp->exp_deferred_qs) {472 if (rdp->exp_deferred_qs)
464 rcu_report_exp_rdp(rdp);473 rcu_report_exp_rdp(rdp);
465 if (!t->rcu_read_unlock_special.s) {
466 local_irq_restore(flags);
467 return;
468 }
469 }
470 474
471 /* Clean up if blocked during RCU read-side critical section. */475 /* Clean up if blocked during RCU read-side critical section. */
472 if (special.b.blocked) {476 if (special.b.blocked) {
473 t->rcu_read_unlock_special.b.blocked = false;
474 477
475 /*478 /*
476 * Remove this task from the list it blocked on. The task479 * 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
485 empty_norm = !rcu_preempt_blocked_readers_cgp(rnp);488 empty_norm = !rcu_preempt_blocked_readers_cgp(rnp);
486 WARN_ON_ONCE(rnp->completedqs == rnp->gp_seq &&489 WARN_ON_ONCE(rnp->completedqs == rnp->gp_seq &&
487 (!empty_norm || rnp->qsmask));490 (!empty_norm || rnp->qsmask));
488 empty_exp = sync_rcu_preempt_exp_done(rnp);491 empty_exp = sync_rcu_exp_done(rnp);
489 smp_mb(); /* ensure expedited fastpath sees end of RCU c-s. */492 smp_mb(); /* ensure expedited fastpath sees end of RCU c-s. */
490 np = rcu_next_node_entry(t, rnp);493 np = rcu_next_node_entry(t, rnp);
491 list_del_init(&t->rcu_node_entry);494 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
493 trace_rcu_unlock_preempted_task(TPS("rcu_preempt"),496 trace_rcu_unlock_preempted_task(TPS("rcu_preempt"),
494 rnp->gp_seq, t->pid);497 rnp->gp_seq, t->pid);
495 if (&t->rcu_node_entry == rnp->gp_tasks)498 if (&t->rcu_node_entry == rnp->gp_tasks)
496 rnp->gp_tasks = np;499 WRITE_ONCE(rnp->gp_tasks, np);
497 if (&t->rcu_node_entry == rnp->exp_tasks)500 if (&t->rcu_node_entry == rnp->exp_tasks)
498 rnp->exp_tasks = np;501 rnp->exp_tasks = np;
499 if (IS_ENABLED(CONFIG_RCU_BOOST)) {502 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
509 * Note that rcu_report_unblock_qs_rnp() releases rnp->lock,512 * Note that rcu_report_unblock_qs_rnp() releases rnp->lock,
510 * so we must take a snapshot of the expedited state.513 * so we must take a snapshot of the expedited state.
511 */514 */
512 empty_exp_now = sync_rcu_preempt_exp_done(rnp);515 empty_exp_now = sync_rcu_exp_done(rnp);
513 if (!empty_norm && !rcu_preempt_blocked_readers_cgp(rnp)) {516 if (!empty_norm && !rcu_preempt_blocked_readers_cgp(rnp)) {
514 trace_rcu_quiescent_state_report(TPS("preempt_rcu"),517 trace_rcu_quiescent_state_report(TPS("preempt_rcu"),
515 rnp->gp_seq,518 rnp->gp_seq,
@@ -551,7 +554,7 @@ static bool rcu_preempt_need_deferred_qs(struct task_struct *t) · 35 unmodified lines
551{554{
552 return (__this_cpu_read(rcu_data.exp_deferred_qs) ||555 return (__this_cpu_read(rcu_data.exp_deferred_qs) ||
553 READ_ONCE(t->rcu_read_unlock_special.s)) &&556 READ_ONCE(t->rcu_read_unlock_special.s)) &&
554 t->rcu_read_lock_nesting <= 0;557 rcu_preempt_depth() <= 0;
555}558}
556 559
557/*560/*
@@ -564,16 +567,16 @@ static bool rcu_preempt_need_deferred_qs(struct task_struct *t) · 6 unmodified lines
564static void rcu_preempt_deferred_qs(struct task_struct *t)567static void rcu_preempt_deferred_qs(struct task_struct *t)
565{568{
566 unsigned long flags;569 unsigned long flags;
567 bool couldrecurse = t->rcu_read_lock_nesting >= 0;570 bool couldrecurse = rcu_preempt_depth() >= 0;
568 571
569 if (!rcu_preempt_need_deferred_qs(t))572 if (!rcu_preempt_need_deferred_qs(t))
570 return;573 return;
571 if (couldrecurse)574 if (couldrecurse)
572 t->rcu_read_lock_nesting -= RCU_NEST_BIAS;575 rcu_preempt_depth_set(rcu_preempt_depth() - RCU_NEST_BIAS);
573 local_irq_save(flags);576 local_irq_save(flags);
574 rcu_preempt_deferred_qs_irqrestore(t, flags);577 rcu_preempt_deferred_qs_irqrestore(t, flags);
575 if (couldrecurse)578 if (couldrecurse)
576 t->rcu_read_lock_nesting += RCU_NEST_BIAS;579 rcu_preempt_depth_set(rcu_preempt_depth() + RCU_NEST_BIAS);
577}580}
578 581
579/*582/*
@@ -610,9 +613,8 @@ static void rcu_read_unlock_special(struct task_struct *t) · 30 unmodified lines
610 struct rcu_data *rdp = this_cpu_ptr(&rcu_data);613 struct rcu_data *rdp = this_cpu_ptr(&rcu_data);
611 struct rcu_node *rnp = rdp->mynode;614 struct rcu_node *rnp = rdp->mynode;
612 615
613 t->rcu_read_unlock_special.b.exp_hint = false;
614 exp = (t->rcu_blocked_node && t->rcu_blocked_node->exp_tasks) ||616 exp = (t->rcu_blocked_node && t->rcu_blocked_node->exp_tasks) ||
615 (rdp->grpmask & rnp->expmask) ||617 (rdp->grpmask & READ_ONCE(rnp->expmask)) ||
616 tick_nohz_full_cpu(rdp->cpu);618 tick_nohz_full_cpu(rdp->cpu);
617 // Need to defer quiescent state until everything is enabled.619 // Need to defer quiescent state until everything is enabled.
618 if (irqs_were_disabled && use_softirq &&620 if (irqs_were_disabled && use_softirq &&
@@ -640,7 +642,6 @@ static void rcu_read_unlock_special(struct task_struct *t) · 21 unmodified lines
640 local_irq_restore(flags);642 local_irq_restore(flags);
641 return;643 return;
642 }644 }
643 WRITE_ONCE(t->rcu_read_unlock_special.b.exp_hint, false);
644 rcu_preempt_deferred_qs_irqrestore(t, flags);645 rcu_preempt_deferred_qs_irqrestore(t, flags);
645}646}
646 647
@@ -648,8 +649,7 @@ static void rcu_read_unlock_special(struct task_struct *t) · 1 unmodified line
648 * Check that the list of blocked tasks for the newly completed grace649 * Check that the list of blocked tasks for the newly completed grace
649 * period is in fact empty. It is a serious bug to complete a grace650 * period is in fact empty. It is a serious bug to complete a grace
650 * period that still has RCU readers blocked! This function must be651 * period that still has RCU readers blocked! This function must be
651 * invoked -before- updating this rnp's ->gp_seq, and the rnp's ->lock652 * invoked -before- updating this rnp's ->gp_seq.
652 * must be held by the caller.
653 *653 *
654 * Also, if there are blocked tasks on the list, they automatically654 * Also, if there are blocked tasks on the list, they automatically
655 * block the newly created grace period, so set up ->gp_tasks accordingly.655 * 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
659 struct task_struct *t;659 struct task_struct *t;
660 660
661 RCU_LOCKDEP_WARN(preemptible(), "rcu_preempt_check_blocked_tasks() invoked with preemption enabled!!!\n");661 RCU_LOCKDEP_WARN(preemptible(), "rcu_preempt_check_blocked_tasks() invoked with preemption enabled!!!\n");
662 raw_lockdep_assert_held_rcu_node(rnp);
662 if (WARN_ON_ONCE(rcu_preempt_blocked_readers_cgp(rnp)))663 if (WARN_ON_ONCE(rcu_preempt_blocked_readers_cgp(rnp)))
663 dump_blkd_tasks(rnp, 10);664 dump_blkd_tasks(rnp, 10);
664 if (rcu_preempt_has_tasks(rnp) &&665 if (rcu_preempt_has_tasks(rnp) &&
665 (rnp->qsmaskinit || rnp->wait_blkd_tasks)) {666 (rnp->qsmaskinit || rnp->wait_blkd_tasks)) {
666 rnp->gp_tasks = rnp->blkd_tasks.next;667 WRITE_ONCE(rnp->gp_tasks, rnp->blkd_tasks.next);
667 t = container_of(rnp->gp_tasks, struct task_struct,668 t = container_of(rnp->gp_tasks, struct task_struct,
668 rcu_node_entry);669 rcu_node_entry);
669 trace_rcu_unlock_preempted_task(TPS("rcu_preempt-GPS"),670 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
686 if (user || rcu_is_cpu_rrupt_from_idle()) {687 if (user || rcu_is_cpu_rrupt_from_idle()) {
687 rcu_note_voluntary_context_switch(current);688 rcu_note_voluntary_context_switch(current);
688 }689 }
689 if (t->rcu_read_lock_nesting > 0 ||690 if (rcu_preempt_depth() > 0 ||
690 (preempt_count() & (PREEMPT_MASK | SOFTIRQ_MASK))) {691 (preempt_count() & (PREEMPT_MASK | SOFTIRQ_MASK))) {
691 /* No QS, force context switch if deferred. */692 /* No QS, force context switch if deferred. */
692 if (rcu_preempt_need_deferred_qs(t)) {693 if (rcu_preempt_need_deferred_qs(t)) {
@@ -696,13 +697,13 @@ static void rcu_flavor_sched_clock_irq(int user) · 3 unmodified lines
696 } else if (rcu_preempt_need_deferred_qs(t)) {697 } else if (rcu_preempt_need_deferred_qs(t)) {
697 rcu_preempt_deferred_qs(t); /* Report deferred QS. */698 rcu_preempt_deferred_qs(t); /* Report deferred QS. */
698 return;699 return;
699 } else if (!t->rcu_read_lock_nesting) {700 } else if (!rcu_preempt_depth()) {
700 rcu_qs(); /* Report immediate QS. */701 rcu_qs(); /* Report immediate QS. */
701 return;702 return;
702 }703 }
703 704
704 /* If GP is oldish, ask for help from rcu_read_unlock_special(). */705 /* 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 &&
706 __this_cpu_read(rcu_data.core_needs_qs) &&707 __this_cpu_read(rcu_data.core_needs_qs) &&
707 __this_cpu_read(rcu_data.cpu_no_qs.b.norm) &&708 __this_cpu_read(rcu_data.cpu_no_qs.b.norm) &&
708 !t->rcu_read_unlock_special.b.need_qs &&709 !t->rcu_read_unlock_special.b.need_qs &&
@@ -723,11 +724,11 @@ void exit_rcu(void) · 14 unmodified lines
723 struct task_struct *t = current;724 struct task_struct *t = current;
724 725
725 if (unlikely(!list_empty(&current->rcu_node_entry))) {726 if (unlikely(!list_empty(&current->rcu_node_entry))) {
726 t->rcu_read_lock_nesting = 1;727 rcu_preempt_depth_set(1);
727 barrier();728 barrier();
728 WRITE_ONCE(t->rcu_read_unlock_special.b.blocked, true);729 WRITE_ONCE(t->rcu_read_unlock_special.b.blocked, true);
729 } else if (unlikely(t->rcu_read_lock_nesting)) {730 } else if (unlikely(rcu_preempt_depth())) {
730 t->rcu_read_lock_nesting = 1;731 rcu_preempt_depth_set(1);
731 } else {732 } else {
732 return;733 return;
733 }734 }
@@ -757,7 +758,8 @@ dump_blkd_tasks(struct rcu_node *rnp, int ncheck) · 23 unmodified lines
757 pr_info("%s: %d:%d ->qsmask %#lx ->qsmaskinit %#lx ->qsmaskinitnext %#lx\n",758 pr_info("%s: %d:%d ->qsmask %#lx ->qsmaskinit %#lx ->qsmaskinitnext %#lx\n",
758 __func__, rnp1->grplo, rnp1->grphi, rnp1->qsmask, rnp1->qsmaskinit, rnp1->qsmaskinitnext);759 __func__, rnp1->grplo, rnp1->grphi, rnp1->qsmask, rnp1->qsmaskinit, rnp1->qsmaskinitnext);
759 pr_info("%s: ->gp_tasks %p ->boost_tasks %p ->exp_tasks %p\n",760 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);
761 pr_info("%s: ->blkd_tasks", __func__);763 pr_info("%s: ->blkd_tasks", __func__);
762 i = 0;764 i = 0;
763 list_for_each(lhp, &rnp->blkd_tasks) {765 list_for_each(lhp, &rnp->blkd_tasks) {
@@ -788,7 +790,7 @@ static void __init rcu_bootup_announce(void) · 24 unmodified lines
788}790}
789 791
790/*792/*
791 * Note a quiescent state for PREEMPT=n. Because we do not need to know793 * Note a quiescent state for PREEMPTION=n. Because we do not need to know
792 * how many quiescent states passed, just if there was at least one since794 * how many quiescent states passed, just if there was at least one since
793 * the start of the grace period, this just sets a flag. The caller must795 * the start of the grace period, this just sets a flag. The caller must
794 * have disabled preemption.796 * have disabled preemption.
@@ -838,7 +840,7 @@ void rcu_all_qs(void) · 43 unmodified lines
838EXPORT_SYMBOL_GPL(rcu_all_qs);840EXPORT_SYMBOL_GPL(rcu_all_qs);
839 841
840/*842/*
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.
842 */844 */
843void rcu_note_context_switch(bool preempt)845void rcu_note_context_switch(bool preempt)
844{846{
@@ -1262,10 +1264,9 @@ static void rcu_prepare_for_idle(void) · 417 unmodified lines
1262/*1264/*
1263 * This code is invoked when a CPU goes idle, at which point we want1265 * This code is invoked when a CPU goes idle, at which point we want
1264 * to have the CPU do everything required for RCU so that it can enter1266 * 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 a1267 * the energy-efficient dyntick-idle mode.
1266 * state machine implemented by rcu_prepare_for_idle() below.
1267 *1268 *
1268 * The following three proprocessor symbols control this state machine:1269 * The following preprocessor symbol controls this:
1269 *1270 *
1270 * RCU_IDLE_GP_DELAY gives the number of jiffies that a CPU is permitted1271 * RCU_IDLE_GP_DELAY gives the number of jiffies that a CPU is permitted
1271 * to sleep in dyntick-idle mode with RCU callbacks pending. This1272 * 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
1274 * number, be warned: Setting RCU_IDLE_GP_DELAY too high can hang your1275 * number, be warned: Setting RCU_IDLE_GP_DELAY too high can hang your
1275 * system. And if you are -that- concerned about energy efficiency,1276 * system. And if you are -that- concerned about energy efficiency,
1276 * just power the system down and be done with it!1277 * 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.
1280 *1278 *
1281 * The values below work well in practice. If future workloads require1279 * The value below works well in practice. If future workloads require
1282 * adjustment, they can be converted into kernel config parameters, though1280 * adjustment, they can be converted into kernel config parameters, though
1283 * making the state machine smarter might be a better option.1281 * making the state machine smarter might be a better option.
1284 */1282 */
1285#define RCU_IDLE_GP_DELAY 4 /* Roughly one grace period. */1283#define RCU_IDLE_GP_DELAY 4 /* Roughly one grace period. */
1286#define RCU_IDLE_LAZY_GP_DELAY (6 * HZ) /* Roughly six seconds. */
1287 1284
1288static int rcu_idle_gp_delay = RCU_IDLE_GP_DELAY;1285static int rcu_idle_gp_delay = RCU_IDLE_GP_DELAY;
1289module_param(rcu_idle_gp_delay, int, 0644);1286module_param(rcu_idle_gp_delay, int, 0644);
1290static int rcu_idle_lazy_gp_delay = RCU_IDLE_LAZY_GP_DELAY;
1291module_param(rcu_idle_lazy_gp_delay, int, 0644);
1292 1287
1293/*1288/*
1294 * Try to advance callbacks on the current CPU, but only if it has been1289 * 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
1327/*1322/*
1328 * Allow the CPU to enter dyntick-idle mode unless it has callbacks ready1323 * Allow the CPU to enter dyntick-idle mode unless it has callbacks ready
1329 * to invoke. If the CPU has callbacks, try to advance them. Tell the1324 * 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-lazy1325 * caller about what to set the timeout.
1331 * callbacks.
1332 *1326 *
1333 * The caller must have disabled interrupts.1327 * The caller must have disabled interrupts.
1334 */1328 */
@@ -1354,25 +1348,18 @@ int rcu_needs_cpu(u64 basemono, u64 *nextevt) · 19 unmodified lines
1354 }1348 }
1355 rdp->last_accelerate = jiffies;1349 rdp->last_accelerate = jiffies;
1356 1350
1357 /* Request timer delay depending on laziness, and round. */1351 /* Request timer and round. */
1358 rdp->all_lazy = !rcu_segcblist_n_nonlazy_cbs(&rdp->cblist);1352 dj = round_up(rcu_idle_gp_delay + jiffies, rcu_idle_gp_delay) - jiffies;
1359 if (rdp->all_lazy) {1353
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 }
1365 *nextevt = basemono + dj * TICK_NSEC;1354 *nextevt = basemono + dj * TICK_NSEC;
1366 return 0;1355 return 0;
1367}1356}
1368 1357
1369/*1358/*
1370 * Prepare a CPU for idle from an RCU perspective. The first major task1359 * Prepare a CPU for idle from an RCU perspective. The first major task is to
1371 * is to sense whether nohz mode has been enabled or disabled via sysfs.1360 * sense whether nohz mode has been enabled or disabled via sysfs. The second
1372 * The second major task is to check to see if a non-lazy callback has1361 * major task is to accelerate (that is, assign grace-period numbers to) any
1373 * arrived at a CPU that previously had only lazy callbacks. The third1362 * recently arrived callbacks.
1374 * major task is to accelerate (that is, assign grace-period numbers to)
1375 * any recently arrived callbacks.
1376 *1363 *
1377 * The caller must have disabled interrupts.1364 * The caller must have disabled interrupts.
1378 */1365 */
@@ -1398,17 +1385,6 @@ static void rcu_prepare_for_idle(void) · 19 unmodified lines
1398 if (!tne)1385 if (!tne)
1399 return;1386 return;
1400 1387
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
1412 /*1388 /*
1413 * If we have not yet accelerated this jiffy, accelerate all1389 * If we have not yet accelerated this jiffy, accelerate all
1414 * callbacks on this CPU.1390 * callbacks on this CPU.
@@ -2321,6 +2297,8 @@ static void __init rcu_organize_nocb_kthreads(void) · 906 unmodified lines
2321{2297{
2322 int cpu;2298 int cpu;
2323 bool firsttime = true;2299 bool firsttime = true;
2300 bool gotnocbs = false;
2301 bool gotnocbscbs = true;
2324 int ls = rcu_nocb_gp_stride;2302 int ls = rcu_nocb_gp_stride;
2325 int nl = 0; /* Next GP kthread. */2303 int nl = 0; /* Next GP kthread. */
2326 struct rcu_data *rdp;2304 struct rcu_data *rdp;
@@ -2343,21 +2321,31 @@ static void __init rcu_organize_nocb_kthreads(void) · 16 unmodified lines
2343 rdp = per_cpu_ptr(&rcu_data, cpu);2321 rdp = per_cpu_ptr(&rcu_data, cpu);
2344 if (rdp->cpu >= nl) {2322 if (rdp->cpu >= nl) {
2345 /* New GP kthread, set up for CBs & next GP. */2323 /* New GP kthread, set up for CBs & next GP. */
2324 gotnocbs = true;
2346 nl = DIV_ROUND_UP(rdp->cpu + 1, ls) * ls;2325 nl = DIV_ROUND_UP(rdp->cpu + 1, ls) * ls;
2347 rdp->nocb_gp_rdp = rdp;2326 rdp->nocb_gp_rdp = rdp;
2348 rdp_gp = rdp;2327 rdp_gp = rdp;
2349 if (!firsttime && dump_tree)2328 if (dump_tree) {
2350 pr_cont("\n");2329 if (!firsttime)
2351 firsttime = false;2330 pr_cont("%s\n", gotnocbscbs
2352 pr_alert("%s: No-CB GP kthread CPU %d:", __func__, cpu);2331 ? "" : " (self only)");
2332 gotnocbscbs = false;
2333 firsttime = false;
2334 pr_alert("%s: No-CB GP kthread CPU %d:",
2335 __func__, cpu);
2336 }
2353 } else {2337 } else {
2354 /* Another CB kthread, link to previous GP kthread. */2338 /* Another CB kthread, link to previous GP kthread. */
2339 gotnocbscbs = true;
2355 rdp->nocb_gp_rdp = rdp_gp;2340 rdp->nocb_gp_rdp = rdp_gp;
2356 rdp_prev->nocb_next_cb_rdp = rdp;2341 rdp_prev->nocb_next_cb_rdp = rdp;
2357 pr_alert(" %d", cpu);2342 if (dump_tree)
2343 pr_cont(" %d", cpu);
2358 }2344 }
2359 rdp_prev = rdp;2345 rdp_prev = rdp;
2360 }2346 }
2347 if (gotnocbs && dump_tree)
2348 pr_cont("%s\n", gotnocbscbs ? "" : " (self only)");
2361}2349}
2362 2350
2363/*2351/*
kernel/rcu/tree_stall.h+27−7
@@ -163,7 +163,7 @@ static void rcu_iw_handler(struct irq_work *iwp) · 162 unmodified lines
163//163//
164// Printing RCU CPU stall warnings164// Printing RCU CPU stall warnings
165 165
166#ifdef CONFIG_PREEMPTION166#ifdef CONFIG_PREEMPT_RCU
167 167
168/*168/*
169 * Dump detailed information for all tasks blocking the current RCU169 * 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
215 return ndetected;215 return ndetected;
216}216}
217 217
218#else /* #ifdef CONFIG_PREEMPTION */218#else /* #ifdef CONFIG_PREEMPT_RCU */
219 219
220/*220/*
221 * Because preemptible RCU does not exist, we never have to check for221 * 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
233{233{
234 return 0;234 return 0;
235}235}
236#endif /* #else #ifdef CONFIG_PREEMPTION */236#endif /* #else #ifdef CONFIG_PREEMPT_RCU */
237 237
238/*238/*
239 * Dump stacks of all tasks running on stalled CPUs. First try using239 * 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
263{263{
264 struct rcu_data *rdp = &per_cpu(rcu_data, cpu);264 struct rcu_data *rdp = &per_cpu(rcu_data, cpu);
265 265
266 sprintf(cp, "last_accelerate: %04lx/%04lx, Nonlazy posted: %c%c%c",266 sprintf(cp, "last_accelerate: %04lx/%04lx dyntick_enabled: %d",
267 rdp->last_accelerate & 0xffff, jiffies & 0xffff,267 rdp->last_accelerate & 0xffff, jiffies & 0xffff,
268 ".l"[rdp->all_lazy],268 !!rdp->tick_nohz_enabled_snap);
269 ".L"[!rcu_segcblist_n_nonlazy_cbs(&rdp->cblist)],
270 ".D"[!!rdp->tick_nohz_enabled_snap]);
271}269}
272 270
273#else /* #ifdef CONFIG_RCU_FAST_NO_HZ */271#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
279 277
280#endif /* #else #ifdef CONFIG_RCU_FAST_NO_HZ */278#endif /* #else #ifdef CONFIG_RCU_FAST_NO_HZ */
281 279
280static 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 */
295static 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
282/*302/*
283 * Print out diagnostic information for the specified stalled CPU.303 * Print out diagnostic information for the specified stalled CPU.
284 *304 *
kernel/rcu/update.c+11−3
@@ -40,6 +40,7 @@ · 39 unmodified lines
40#include <linux/rcupdate_wait.h>40#include <linux/rcupdate_wait.h>
41#include <linux/sched/isolation.h>41#include <linux/sched/isolation.h>
42#include <linux/kprobes.h>42#include <linux/kprobes.h>
43#include <linux/slab.h>
43 44
44#define CREATE_TRACE_POINTS45#define CREATE_TRACE_POINTS
45 46
@@ -51,9 +52,7 @@ · 5 unmodified lines
51#define MODULE_PARAM_PREFIX "rcupdate."52#define MODULE_PARAM_PREFIX "rcupdate."
52 53
53#ifndef CONFIG_TINY_RCU54#ifndef CONFIG_TINY_RCU
54extern int rcu_expedited; /* from sysctl */
55module_param(rcu_expedited, int, 0);55module_param(rcu_expedited, int, 0);
56extern int rcu_normal; /* from sysctl */
57module_param(rcu_normal, int, 0);56module_param(rcu_normal, int, 0);
58static int rcu_normal_after_boot;57static int rcu_normal_after_boot;
59module_param(rcu_normal_after_boot, int, 0);58module_param(rcu_normal_after_boot, int, 0);
@@ -218,6 +217,7 @@ static int __init rcu_set_runtime_mode(void) · 158 unmodified lines
218{217{
219 rcu_test_sync_prims();218 rcu_test_sync_prims();
220 rcu_scheduler_active = RCU_SCHEDULER_RUNNING;219 rcu_scheduler_active = RCU_SCHEDULER_RUNNING;
220 kfree_rcu_scheduler_running();
221 rcu_test_sync_prims();221 rcu_test_sync_prims();
222 return 0;222 return 0;
223}223}
@@ -435,7 +435,7 @@ struct debug_obj_descr rcuhead_debug_descr = { · 211 unmodified lines
435EXPORT_SYMBOL_GPL(rcuhead_debug_descr);435EXPORT_SYMBOL_GPL(rcuhead_debug_descr);
436#endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */436#endif /* #ifdef CONFIG_DEBUG_OBJECTS_RCU_HEAD */
437 437
438#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU) || defined(CONFIG_RCU_TRACE)438#if defined(CONFIG_TREE_RCU) || defined(CONFIG_RCU_TRACE)
439void do_trace_rcu_torture_read(const char *rcutorturename, struct rcu_head *rhp,439void do_trace_rcu_torture_read(const char *rcutorturename, struct rcu_head *rhp,
440 unsigned long secs,440 unsigned long secs,
441 unsigned long c_old, unsigned long c)441 unsigned long c_old, unsigned long c)
@@ -853,14 +853,22 @@ static void test_callback(struct rcu_head *r) · 411 unmodified lines
853 853
854DEFINE_STATIC_SRCU(early_srcu);854DEFINE_STATIC_SRCU(early_srcu);
855 855
856struct early_boot_kfree_rcu {
857 struct rcu_head rh;
858};
859
856static void early_boot_test_call_rcu(void)860static void early_boot_test_call_rcu(void)
857{861{
858 static struct rcu_head head;862 static struct rcu_head head;
859 static struct rcu_head shead;863 static struct rcu_head shead;
864 struct early_boot_kfree_rcu *rhp;
860 865
861 call_rcu(&head, test_callback);866 call_rcu(&head, test_callback);
862 if (IS_ENABLED(CONFIG_SRCU))867 if (IS_ENABLED(CONFIG_SRCU))
863 call_srcu(&early_srcu, &shead, test_callback);868 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);
864}872}
865 873
866void rcu_early_boot_tests(void)874void rcu_early_boot_tests(void)
kernel/sysctl.c+1−1
@@ -1268,7 +1268,7 @@ static struct ctl_table kern_table[] = { · 1267 unmodified lines
1268 .proc_handler = proc_do_static_key,1268 .proc_handler = proc_do_static_key,
1269 },1269 },
1270#endif1270#endif
1271#if defined(CONFIG_TREE_RCU) || defined(CONFIG_PREEMPT_RCU)1271#if defined(CONFIG_TREE_RCU)
1272 {1272 {
1273 .procname = "panic_on_rcu_stall",1273 .procname = "panic_on_rcu_stall",
1274 .data = &sysctl_panic_on_rcu_stall,1274 .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
257#define tipc_aead_rcu_ptr(rcu_ptr, lock) \257#define tipc_aead_rcu_ptr(rcu_ptr, lock) \
258 rcu_dereference_protected((rcu_ptr), lockdep_is_held(lock))258 rcu_dereference_protected((rcu_ptr), lockdep_is_held(lock))
259 259
260#define tipc_aead_rcu_swap(rcu_ptr, ptr, lock) \
261 rcu_swap_protected((rcu_ptr), (ptr), lockdep_is_held(lock))
262
263#define tipc_aead_rcu_replace(rcu_ptr, ptr, lock) \260#define tipc_aead_rcu_replace(rcu_ptr, ptr, lock) \
264do { \261do { \
265 typeof(rcu_ptr) __tmp = rcu_dereference_protected((rcu_ptr), \262 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
1189 1186
1190 /* Move passive key if any */1187 /* Move passive key if any */
1191 if (key.passive) {1188 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));
1193 x = (key.passive - key.pending + new_pending) % KEY_MAX;1190 x = (key.passive - key.pending + new_pending) % KEY_MAX;
1194 new_passive = (x <= 0) ? x + KEY_MAX : x;1191 new_passive = (x <= 0) ? x + KEY_MAX : x;
1195 }1192 }
tools/testing/selftests/rcutorture/bin/cpus2use.sh+9−2
@@ -15,8 +15,15 @@ then · 14 unmodified lines
15 exit 015 exit 0
16fi16fi
17ncpus=`grep '^processor' /proc/cpuinfo | wc -l`17ncpus=`grep '^processor' /proc/cpuinfo | wc -l`
18idlecpus=`mpstat | tail -1 | \18if mpstat -V > /dev/null 2>&1
19 awk -v ncpus=$ncpus '{ print ncpus * ($7 + $NF) / 100 }'`19then
20 idlecpus=`mpstat | tail -1 | \
21 awk -v ncpus=$ncpus '{ print ncpus * ($7 + $NF) / 100 }'`
22else
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
26fi
20awk -v ncpus=$ncpus -v idlecpus=$idlecpus < /dev/null '27awk -v ncpus=$ncpus -v idlecpus=$idlecpus < /dev/null '
21BEGIN {28BEGIN {
22 cpus2use = idlecpus;29 cpus2use = idlecpus;
tools/testing/selftests/rcutorture/bin/jitter.sh+22−8
@@ -23,25 +23,39 @@ spinmax=${4-1000} · 22 unmodified lines
23 23
24n=124n=1
25 25
26starttime=`awk 'BEGIN { print systime(); }' < /dev/null`26starttime=`gawk 'BEGIN { print systime(); }' < /dev/null`
27
28nohotplugcpus=
29for i in /sys/devices/system/cpu/cpu[0-9]*
30do
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
38done
27 39
28while :40while :
29do41do
30 # Check for done.42 # 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`
32 if test "$t" -gt "$duration"44 if test "$t" -gt "$duration"
33 then45 then
34 exit 0;46 exit 0;
35 fi47 fi
36 48
37 # Set affinity to randomly selected online CPU49 # Set affinity to randomly selected online CPU
38 cpus=`grep 1 /sys/devices/system/cpu/*/online |50 if cpus=`grep 1 /sys/devices/system/cpu/*/online 2>&1 |
39 sed -e 's,/[^/]*$,,' -e 's/^[^0-9]*//'`51 sed -e 's,/[^/]*$,,' -e 's/^[^0-9]*//'`
40 52 then
41 # Do not leave out poor old cpu0 which may not be hot-pluggable53 :
42 if [ ! -f "/sys/devices/system/cpu/cpu0/online" ]; then54 else
43 cpus="0 $cpus"55 cpus=
44 fi56 fi
57 # Do not leave out non-hot-pluggable CPUs
58 cpus="$cpus $nohotplugcpus"
45 59
46 cpumask=`awk -v cpus="$cpus" -v me=$me -v n=$n 'BEGIN {60 cpumask=`awk -v cpus="$cpus" -v me=$me -v n=$n 'BEGIN {
47 srand(n + me + systime());61 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
25 tail -1 | sed -e 's/^\[[ 0-9.]*] //' |25 tail -1 | sed -e 's/^\[[ 0-9.]*] //' |
26 awk '{ print \"[\" $1 \" \" $5 \" \" $6 \" \" $7 \"]\"; }' |26 awk '{ print \"[\" $1 \" \" $5 \" \" $6 \" \" $7 \"]\"; }' |
27 tr -d '\012\015'`"27 tr -d '\012\015'`"
28fwdprog="`grep 'rcu_torture_fwd_prog_cr Duration' $i/console.log 2> /dev/null | sed -e 's/^\[[^]]*] //' | sort -k15nr | head -1 | awk '{ print $14 " " $15 }'`"
28if test -z "$ngps"29if test -z "$ngps"
29then30then
30 echo "$configfile ------- " $stopstate31 echo "$configfile ------- " $stopstate
@@ -39,7 +40,7 @@ else · 8 unmodified lines
39 BEGIN { print ngps / dur }' < /dev/null`40 BEGIN { print ngps / dur }' < /dev/null`
40 title="$title ($ngpsps/s)"41 title="$title ($ngpsps/s)"
41 fi42 fi
42 echo $title $stopstate43 echo $title $stopstate $fwdprog
43 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}'`44 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}'`
44 if test -z "$nclosecalls"45 if test -z "$nclosecalls"
45 then46 then
tools/testing/selftests/rcutorture/bin/kvm-test-1-run.sh+6−7
@@ -123,7 +123,7 @@ qemu_args=$5 · 122 unmodified lines
123boot_args=$6123boot_args=$6
124 124
125cd $KVM125cd $KVM
126kstarttime=`awk 'BEGIN { print systime() }' < /dev/null`126kstarttime=`gawk 'BEGIN { print systime() }' < /dev/null`
127if test -z "$TORTURE_BUILDONLY"127if test -z "$TORTURE_BUILDONLY"
128then128then
129 echo ' ---' `date`: Starting kernel129 echo ' ---' `date`: Starting kernel
@@ -133,11 +133,10 @@ fi · 3 unmodified lines
133qemu_args="-enable-kvm -nographic $qemu_args"133qemu_args="-enable-kvm -nographic $qemu_args"
134cpu_count=`configNR_CPUS.sh $resdir/ConfigFragment`134cpu_count=`configNR_CPUS.sh $resdir/ConfigFragment`
135cpu_count=`configfrag_boot_cpus "$boot_args" "$config_template" "$cpu_count"`135cpu_count=`configfrag_boot_cpus "$boot_args" "$config_template" "$cpu_count"`
136vcpus=`identify_qemu_vcpus`136if test "$cpu_count" -gt "$TORTURE_ALLOTED_CPUS"
137if test $cpu_count -gt $vcpus
138then137then
139 echo CPU count limited from $cpu_count to $vcpus | tee -a $resdir/Warnings138 echo CPU count limited from $cpu_count to $TORTURE_ALLOTED_CPUS | tee -a $resdir/Warnings
140 cpu_count=$vcpus139 cpu_count=$TORTURE_ALLOTED_CPUS
141fi140fi
142qemu_args="`specify_qemu_cpus "$QEMU" "$qemu_args" "$cpu_count"`"141qemu_args="`specify_qemu_cpus "$QEMU" "$qemu_args" "$cpu_count"`"
143 142
@@ -177,7 +176,7 @@ do · 33 unmodified lines
177 then176 then
178 qemu_pid=`cat "$resdir/qemu_pid"`177 qemu_pid=`cat "$resdir/qemu_pid"`
179 fi178 fi
180 kruntime=`awk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`179 kruntime=`gawk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
181 if test -z "$qemu_pid" || kill -0 "$qemu_pid" > /dev/null 2>&1180 if test -z "$qemu_pid" || kill -0 "$qemu_pid" > /dev/null 2>&1
182 then181 then
183 if test $kruntime -ge $seconds182 if test $kruntime -ge $seconds
@@ -213,7 +212,7 @@ then · 29 unmodified lines
213 oldline="`tail $resdir/console.log`"212 oldline="`tail $resdir/console.log`"
214 while :213 while :
215 do214 do
216 kruntime=`awk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`215 kruntime=`gawk 'BEGIN { print systime() - '"$kstarttime"' }' < /dev/null`
217 if kill -0 $qemu_pid > /dev/null 2>&1216 if kill -0 $qemu_pid > /dev/null 2>&1
218 then217 then
219 :218 :
tools/testing/selftests/rcutorture/bin/kvm.sh+21−9
@@ -24,7 +24,9 @@ dur=$((30*60)) · 23 unmodified lines
24dryrun=""24dryrun=""
25KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM25KVM="`pwd`/tools/testing/selftests/rcutorture"; export KVM
26PATH=${KVM}/bin:$PATH; export PATH26PATH=${KVM}/bin:$PATH; export PATH
27TORTURE_ALLOTED_CPUS=""27. functions.sh
28
29TORTURE_ALLOTED_CPUS="`identify_qemu_vcpus`"
28TORTURE_DEFCONFIG=defconfig30TORTURE_DEFCONFIG=defconfig
29TORTURE_BOOT_IMAGE=""31TORTURE_BOOT_IMAGE=""
30TORTURE_INITRD="$KVM/initrd"; export TORTURE_INITRD32TORTURE_INITRD="$KVM/initrd"; export TORTURE_INITRD
@@ -40,8 +42,6 @@ cpus=0 · 9 unmodified lines
40ds=`date +%Y.%m.%d-%H:%M:%S`42ds=`date +%Y.%m.%d-%H:%M:%S`
41jitter="-1"43jitter="-1"
42 44
43. functions.sh
44
45usage () {45usage () {
46 echo "Usage: $scriptname optional arguments:"46 echo "Usage: $scriptname optional arguments:"
47 echo " --bootargs kernel-boot-arguments"47 echo " --bootargs kernel-boot-arguments"
@@ -93,6 +93,11 @@ do · 45 unmodified lines
93 checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'93 checkarg --cpus "(number)" "$#" "$2" '^[0-9]*$' '^--'
94 cpus=$294 cpus=$2
95 TORTURE_ALLOTED_CPUS="$2"95 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
96 shift101 shift
97 ;;102 ;;
98 --datestamp)103 --datestamp)
@@ -198,9 +203,10 @@ fi · 99 unmodified lines
198 203
199CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG204CONFIGFRAG=${KVM}/configs/${TORTURE_SUITE}; export CONFIGFRAG
200 205
206defaultconfigs="`tr '\012' ' ' < $CONFIGFRAG/CFLIST`"
201if test -z "$configs"207if test -z "$configs"
202then208then
203 configs="`cat $CONFIGFRAG/CFLIST`"209 configs=$defaultconfigs
204fi210fi
205 211
206if test -z "$resdir"212if test -z "$resdir"
@@ -209,7 +215,7 @@ then · 2 unmodified lines
209fi215fi
210 216
211# Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.217# Create a file of test-name/#cpus pairs, sorted by decreasing #cpus.
212touch $T/cfgcpu218configs_derep=
213for CF in $configs219for CF in $configs
214do220do
215 case $CF in221 case $CF in
@@ -222,15 +228,21 @@ do · 6 unmodified lines
222 CF1=$CF228 CF1=$CF
223 ;;229 ;;
224 esac230 esac
231 for ((cur_rep=0;cur_rep<$config_reps;cur_rep++))
232 do
233 configs_derep="$configs_derep $CF1"
234 done
235done
236touch $T/cfgcpu
237configs_derep="`echo $configs_derep | sed -e "s/\<CFLIST\>/$defaultconfigs/g"`"
238for CF1 in $configs_derep
239do
225 if test -f "$CONFIGFRAG/$CF1"240 if test -f "$CONFIGFRAG/$CF1"
226 then241 then
227 cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF1`242 cpu_count=`configNR_CPUS.sh $CONFIGFRAG/$CF1`
228 cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`243 cpu_count=`configfrag_boot_cpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
229 cpu_count=`configfrag_boot_maxcpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`244 cpu_count=`configfrag_boot_maxcpus "$TORTURE_BOOTARGS" "$CONFIGFRAG/$CF1" "$cpu_count"`
230 for ((cur_rep=0;cur_rep<$config_reps;cur_rep++))245 echo $CF1 $cpu_count >> $T/cfgcpu
231 do
232 echo $CF1 $cpu_count >> $T/cfgcpu
233 done
234 else246 else
235 echo "The --configs file $CF1 does not exist, terminating."247 echo "The --configs file $CF1 does not exist, terminating."
236 exit 1248 exit 1
tools/testing/selftests/rcutorture/bin/mkinitrd.sh+3−52
@@ -20,58 +20,9 @@ if [ -s "$D/initrd/init" ]; then · 19 unmodified lines
20 exit 020 exit 0
21fi21fi
22 22
23T=${TMPDIR-/tmp}/mkinitrd.sh.$$23# Create a C-language initrd/init infinite-loop program and statically
24trap 'rm -rf $T' 0 224# link it. This results in a very small initrd.
25mkdir $T25echo "Creating a statically linked C-language initrd"
26
27cat > $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
40a4="a a a a"
41a16="$a4 $a4 $a4 $a4"
42a64="$a16 $a16 $a16 $a16"
43a192="$a64 $a64 $a64"
44while :
45do
46 q=
47 for i in $a192
48 do
49 q="$q $i"
50 done
51 sleep 1
52done
53__EOF___
54
55# Try using dracut to create initrd
56if command -v dracut >/dev/null 2>&1
57then
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
69fi
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.
74echo "Could not find dracut, attempting C initrd"
75cd $D26cd $D
76mkdir -p initrd27mkdir -p initrd
77cd initrd28cd initrd