]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - Documentation/RCU/stallwarn.txt
rcu: Add stall warnings to synchronize_sched_expedited()
[mirror_ubuntu-bionic-kernel.git] / Documentation / RCU / stallwarn.txt
CommitLineData
4c54005c
PM
1Using RCU's CPU Stall Detector
2
a00e0d71
PM
3The rcu_cpu_stall_suppress module parameter enables RCU's CPU stall
4detector, which detects conditions that unduly delay RCU grace periods.
5This module parameter enables CPU stall detection by default, but
6may be overridden via boot-time parameter or at runtime via sysfs.
7The stall detector's idea of what constitutes "unduly delayed" is
8controlled by a set of kernel configuration variables and cpp macros:
4c54005c 9
a00e0d71 10CONFIG_RCU_CPU_STALL_TIMEOUT
4c54005c 11
a00e0d71
PM
12 This kernel configuration parameter defines the period of time
13 that RCU will wait from the beginning of a grace period until it
14 issues an RCU CPU stall warning. This time period is normally
64d3b7a1 15 21 seconds.
4c54005c 16
24cd7fd0 17 This configuration parameter may be changed at runtime via the
84596ccb 18 /sys/module/rcupdate/parameters/rcu_cpu_stall_timeout, however
24cd7fd0 19 this parameter is checked only at the beginning of a cycle.
64d3b7a1 20 So if you are 10 seconds into a 40-second stall, setting this
24cd7fd0
PM
21 sysfs parameter to (say) five will shorten the timeout for the
22 -next- stall, or the following warning for the current stall
23 (assuming the stall lasts long enough). It will not affect the
24 timing of the next warning for the current stall.
4c54005c 25
24cd7fd0 26 Stall-warning messages may be enabled and disabled completely via
96224daa 27 /sys/module/rcupdate/parameters/rcu_cpu_stall_suppress.
24cd7fd0 28
24cd7fd0
PM
29RCU_STALL_DELAY_DELTA
30
31 Although the lockdep facility is extremely useful, it does add
32 some overhead. Therefore, under CONFIG_PROVE_RCU, the
33 RCU_STALL_DELAY_DELTA macro allows five extra seconds before
64d3b7a1
PM
34 giving an RCU CPU stall warning message. (This is a cpp
35 macro, not a kernel configuration parameter.)
4c54005c
PM
36
37RCU_STALL_RAT_DELAY
38
f1d507be
PM
39 The CPU stall detector tries to make the offending CPU print its
40 own warnings, as this often gives better-quality stack traces.
41 However, if the offending CPU does not detect its own stall in
42 the number of jiffies specified by RCU_STALL_RAT_DELAY, then
43 some other CPU will complain. This delay is normally set to
64d3b7a1
PM
44 two jiffies. (This is a cpp macro, not a kernel configuration
45 parameter.)
4c54005c 46
37fe5f0e
PM
47rcupdate.rcu_task_stall_timeout
48
49 This boot/sysfs parameter controls the RCU-tasks stall warning
50 interval. A value of zero or less suppresses RCU-tasks stall
51 warnings. A positive value sets the stall-warning interval
52 in jiffies. An RCU-tasks stall warning starts wtih the line:
53
54 INFO: rcu_tasks detected stalls on tasks:
55
56 And continues with the output of sched_show_task() for each
57 task stalling the current RCU-tasks grace period.
58
59For non-RCU-tasks flavors of RCU, when a CPU detects that it is stalling,
60it will print a message similar to the following:
f1d507be
PM
61
62INFO: rcu_sched_state detected stall on CPU 5 (t=2500 jiffies)
63
64This message indicates that CPU 5 detected that it was causing a stall,
65and that the stall was affecting RCU-sched. This message will normally be
66followed by a stack dump of the offending CPU. On TREE_RCU kernel builds,
67RCU and RCU-sched are implemented by the same underlying mechanism,
28f6569a 68while on PREEMPT_RCU kernel builds, RCU is instead implemented
f1d507be
PM
69by rcu_preempt_state.
70
71On the other hand, if the offending CPU fails to print out a stall-warning
72message quickly enough, some other CPU will print a message similar to
73the following:
74
75INFO: rcu_bh_state detected stalls on CPUs/tasks: { 3 5 } (detected by 2, 2502 jiffies)
76
77This message indicates that CPU 2 detected that CPUs 3 and 5 were both
78causing stalls, and that the stall was affecting RCU-bh. This message
79will normally be followed by stack dumps for each CPU. Please note that
28f6569a 80PREEMPT_RCU builds can be stalled by tasks as well as by CPUs,
f1d507be
PM
81and that the tasks will be indicated by PID, for example, "P3421".
82It is even possible for a rcu_preempt_state stall to be caused by both
83CPUs -and- tasks, in which case the offending CPUs and tasks will all
84be called out in the list.
85
86Finally, if the grace period ends just as the stall warning starts
87printing, there will be a spurious stall-warning message:
88
89INFO: rcu_bh_state detected stalls on CPUs/tasks: { } (detected by 4, 2502 jiffies)
90
64d3b7a1
PM
91This is rare, but does happen from time to time in real life. It is also
92possible for a zero-jiffy stall to be flagged in this case, depending
93on how the stall warning and the grace-period initialization happen to
94interact. Please note that it is not possible to entirely eliminate this
95sort of false positive without resorting to things like stop_machine(),
96which is overkill for this sort of problem.
f1d507be 97
75c27f11 98Recent kernels will print a long form of the stall-warning message:
24cd7fd0
PM
99
100 INFO: rcu_preempt detected stall on CPU
6231069b 101 0: (63959 ticks this GP) idle=241/3fffffffffffffff/0 softirq=82/543
24cd7fd0
PM
102 (t=65000 jiffies)
103
75c27f11 104In kernels with CONFIG_RCU_FAST_NO_HZ, more information is printed:
24cd7fd0
PM
105
106 INFO: rcu_preempt detected stall on CPU
6231069b 107 0: (64628 ticks this GP) idle=dd5/3fffffffffffffff/0 softirq=82/543 last_accelerate: a345/d342 nonlazy_posted: 25 .D
24cd7fd0
PM
108 (t=65000 jiffies)
109
110The "(64628 ticks this GP)" indicates that this CPU has taken more
111than 64,000 scheduling-clock interrupts during the current stalled
112grace period. If the CPU was not yet aware of the current grace
113period (for example, if it was offline), then this part of the message
114indicates how many grace periods behind the CPU is.
115
116The "idle=" portion of the message prints the dyntick-idle state.
117The hex number before the first "/" is the low-order 12 bits of the
118dynticks counter, which will have an even-numbered value if the CPU is
119in dyntick-idle mode and an odd-numbered value otherwise. The hex
120number between the two "/"s is the value of the nesting, which will
121be a small positive number if in the idle loop and a very large positive
122number (as shown above) otherwise.
123
6231069b
PM
124The "softirq=" portion of the message tracks the number of RCU softirq
125handlers that the stalled CPU has executed. The number before the "/"
126is the number that had executed since boot at the time that this CPU
127last noted the beginning of a grace period, which might be the current
128(stalled) grace period, or it might be some earlier grace period (for
129example, if the CPU might have been in dyntick-idle mode for an extended
130time period. The number after the "/" is the number that have executed
131since boot until the current time. If this latter number stays constant
132across repeated stall-warning messages, it is possible that RCU's softirq
133handlers are no longer able to execute on this CPU. This can happen if
134the stalled CPU is spinning with interrupts are disabled, or, in -rt
135kernels, if a high-priority process is starving RCU's softirq handler.
136
137For CONFIG_RCU_FAST_NO_HZ kernels, the "last_accelerate:" prints the
138low-order 16 bits (in hex) of the jiffies counter when this CPU last
139invoked rcu_try_advance_all_cbs() from rcu_needs_cpu() or last invoked
140rcu_accelerate_cbs() from rcu_prepare_for_idle(). The "nonlazy_posted:"
141prints the number of non-lazy callbacks posted since the last call to
142rcu_needs_cpu(). Finally, an "L" indicates that there are currently
143no non-lazy callbacks ("." is printed otherwise, as shown above) and
144"D" indicates that dyntick-idle processing is enabled ("." is printed
145otherwise, for example, if disabled via the "nohz=" kernel boot parameter).
24cd7fd0 146
fb81a44b
PM
147If the relevant grace-period kthread has been unable to run prior to
148the stall warning, the following additional line is printed:
149
150 rcu_preempt kthread starved for 2023 jiffies!
151
152Starving the grace-period kthreads of CPU time can of course result in
153RCU CPU stall warnings even when all CPUs and tasks have passed through
154the required quiescent states.
155
24cd7fd0
PM
156
157Multiple Warnings From One Stall
158
159If a stall lasts long enough, multiple stall-warning messages will be
160printed for it. The second and subsequent messages are printed at
161longer intervals, so that the time between (say) the first and second
162message will be about three times the interval between the beginning
163of the stall and the first message.
164
165
166What Causes RCU CPU Stall Warnings?
167
f1d507be
PM
168So your kernel printed an RCU CPU stall warning. The next question is
169"What caused it?" The following problems can result in RCU CPU stall
170warnings:
4c54005c
PM
171
172o A CPU looping in an RCU read-side critical section.
173
f1d507be
PM
174o A CPU looping with interrupts disabled. This condition can
175 result in RCU-sched and RCU-bh stalls.
4c54005c 176
f1d507be
PM
177o A CPU looping with preemption disabled. This condition can
178 result in RCU-sched stalls and, if ksoftirqd is in use, RCU-bh
179 stalls.
180
181o A CPU looping with bottom halves disabled. This condition can
182 result in RCU-sched and RCU-bh stalls.
4c54005c 183
37fe5f0e
PM
184o For !CONFIG_PREEMPT kernels, a CPU looping anywhere in the
185 kernel without invoking schedule(). Note that cond_resched()
186 does not necessarily prevent RCU CPU stall warnings. Therefore,
187 if the looping in the kernel is really expected and desirable
188 behavior, you might need to replace some of the cond_resched()
189 calls with calls to cond_resched_rcu_qs().
4c54005c 190
6ccd2ecd
PM
191o Anything that prevents RCU's grace-period kthreads from running.
192 This can result in the "All QSes seen" console-log message.
193 This message will include information on when the kthread last
194 ran and how often it should be expected to run.
195
2c96c775
PM
196o A CPU-bound real-time task in a CONFIG_PREEMPT kernel, which might
197 happen to preempt a low-priority task in the middle of an RCU
198 read-side critical section. This is especially damaging if
199 that low-priority task is not permitted to run on any other CPU,
200 in which case the next RCU grace period can never complete, which
201 will eventually cause the system to run out of memory and hang.
202 While the system is in the process of running itself out of
203 memory, you might see stall-warning messages.
204
205o A CPU-bound real-time task in a CONFIG_PREEMPT_RT kernel that
206 is running at a higher priority than the RCU softirq threads.
207 This will prevent RCU callbacks from ever being invoked,
28f6569a 208 and in a CONFIG_PREEMPT_RCU kernel will further prevent
2c96c775
PM
209 RCU grace periods from ever completing. Either way, the
210 system will eventually run out of memory and hang. In the
28f6569a 211 CONFIG_PREEMPT_RCU case, you might see stall-warning
2c96c775
PM
212 messages.
213
2c01531f
PM
214o A hardware or software issue shuts off the scheduler-clock
215 interrupt on a CPU that is not in dyntick-idle mode. This
216 problem really has happened, and seems to be most likely to
3451d024 217 result in RCU CPU stall warnings for CONFIG_NO_HZ_COMMON=n kernels.
2c01531f 218
4c54005c
PM
219o A bug in the RCU implementation.
220
221o A hardware failure. This is quite unlikely, but has occurred
f1d507be 222 at least once in real life. A CPU failed in a running system,
4c54005c
PM
223 becoming unresponsive, but not causing an immediate crash.
224 This resulted in a series of RCU CPU stall warnings, eventually
225 leading the realization that the CPU had failed.
226
37fe5f0e
PM
227The RCU, RCU-sched, RCU-bh, and RCU-tasks implementations have CPU stall
228warning. Note that SRCU does -not- have CPU stall warnings. Please note
229that RCU only detects CPU stalls when there is a grace period in progress.
230No grace period, no CPU stall warnings.
f1d507be
PM
231
232To diagnose the cause of the stall, inspect the stack traces.
233The offending function will usually be near the top of the stack.
234If you have a series of stall warnings from a single extended stall,
235comparing the stack traces can often help determine where the stall
236is occurring, which will usually be in the function nearest the top of
237that portion of the stack which remains the same from trace to trace.
238If you can reliably trigger the stall, ftrace can be quite helpful.
4c54005c 239
24cd7fd0 240RCU bugs can often be debugged with the help of CONFIG_RCU_TRACE
64d3b7a1
PM
241and with RCU's event tracing. For information on RCU's event tracing,
242see include/trace/events/rcu.h.