Merge tag 'for-4.20/dm-changes' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux-2.6-block.git] / Documentation / RCU / stallwarn.txt
CommitLineData
4c54005c
PM
1Using RCU's CPU Stall Detector
2
8e2a4397
PM
3This document first discusses what sorts of issues RCU's CPU stall
4detector can locate, and then discusses kernel parameters and Kconfig
5options that can be used to fine-tune the detector's operation. Finally,
6this document explains the stall detector's "splat" format.
7
8
9What Causes RCU CPU Stall Warnings?
10
11So your kernel printed an RCU CPU stall warning. The next question is
12"What caused it?" The following problems can result in RCU CPU stall
13warnings:
14
15o A CPU looping in an RCU read-side critical section.
16
17o A CPU looping with interrupts disabled.
18
77095901 19o A CPU looping with preemption disabled.
8e2a4397 20
77095901 21o A CPU looping with bottom halves disabled.
8e2a4397 22
f2b1760a
PM
23o For !CONFIG_PREEMPT kernels, a CPU looping anywhere in the kernel
24 without invoking schedule(). If the looping in the kernel is
25 really expected and desirable behavior, you might need to add
26 some calls to cond_resched().
8e2a4397
PM
27
28o Booting Linux using a console connection that is too slow to
29 keep up with the boot-time console-message rate. For example,
30 a 115Kbaud serial console can be -way- too slow to keep up
31 with boot-time message rates, and will frequently result in
32 RCU CPU stall warning messages. Especially if you have added
33 debug printk()s.
34
35o Anything that prevents RCU's grace-period kthreads from running.
36 This can result in the "All QSes seen" console-log message.
37 This message will include information on when the kthread last
dfa0ee48
PM
38 ran and how often it should be expected to run. It can also
39 result in the "rcu_.*kthread starved for" console-log message,
40 which will include additional debugging information.
8e2a4397
PM
41
42o A CPU-bound real-time task in a CONFIG_PREEMPT kernel, which might
43 happen to preempt a low-priority task in the middle of an RCU
44 read-side critical section. This is especially damaging if
45 that low-priority task is not permitted to run on any other CPU,
46 in which case the next RCU grace period can never complete, which
47 will eventually cause the system to run out of memory and hang.
48 While the system is in the process of running itself out of
49 memory, you might see stall-warning messages.
50
51o A CPU-bound real-time task in a CONFIG_PREEMPT_RT kernel that
52 is running at a higher priority than the RCU softirq threads.
53 This will prevent RCU callbacks from ever being invoked,
54 and in a CONFIG_PREEMPT_RCU kernel will further prevent
55 RCU grace periods from ever completing. Either way, the
56 system will eventually run out of memory and hang. In the
57 CONFIG_PREEMPT_RCU case, you might see stall-warning
58 messages.
59
dfa0ee48
PM
60o A periodic interrupt whose handler takes longer than the time
61 interval between successive pairs of interrupts. This can
62 prevent RCU's kthreads and softirq handlers from running.
63 Note that certain high-overhead debugging options, for example
64 the function_graph tracer, can result in interrupt handler taking
65 considerably longer than normal, which can in turn result in
66 RCU CPU stall warnings.
67
3d916a44
PM
68o Testing a workload on a fast system, tuning the stall-warning
69 timeout down to just barely avoid RCU CPU stall warnings, and then
70 running the same workload with the same stall-warning timeout on a
71 slow system. Note that thermal throttling and on-demand governors
72 can cause a single system to be sometimes fast and sometimes slow!
73
8e2a4397
PM
74o A hardware or software issue shuts off the scheduler-clock
75 interrupt on a CPU that is not in dyntick-idle mode. This
76 problem really has happened, and seems to be most likely to
77 result in RCU CPU stall warnings for CONFIG_NO_HZ_COMMON=n kernels.
78
79o A bug in the RCU implementation.
80
81o A hardware failure. This is quite unlikely, but has occurred
82 at least once in real life. A CPU failed in a running system,
83 becoming unresponsive, but not causing an immediate crash.
84 This resulted in a series of RCU CPU stall warnings, eventually
85 leading the realization that the CPU had failed.
86
77095901
PM
87The RCU, RCU-sched, and RCU-tasks implementations have CPU stall warning.
88Note that SRCU does -not- have CPU stall warnings. Please note that
89RCU only detects CPU stalls when there is a grace period in progress.
8e2a4397
PM
90No grace period, no CPU stall warnings.
91
92To diagnose the cause of the stall, inspect the stack traces.
93The offending function will usually be near the top of the stack.
94If you have a series of stall warnings from a single extended stall,
95comparing the stack traces can often help determine where the stall
96is occurring, which will usually be in the function nearest the top of
97that portion of the stack which remains the same from trace to trace.
98If you can reliably trigger the stall, ftrace can be quite helpful.
99
100RCU bugs can often be debugged with the help of CONFIG_RCU_TRACE
101and with RCU's event tracing. For information on RCU's event tracing,
102see include/trace/events/rcu.h.
103
104
105Fine-Tuning the RCU CPU Stall Detector
106
107The rcuupdate.rcu_cpu_stall_suppress module parameter disables RCU's
108CPU stall detector, which detects conditions that unduly delay RCU grace
109periods. This module parameter enables CPU stall detection by default,
110but may be overridden via boot-time parameter or at runtime via sysfs.
a00e0d71
PM
111The stall detector's idea of what constitutes "unduly delayed" is
112controlled by a set of kernel configuration variables and cpp macros:
4c54005c 113
a00e0d71 114CONFIG_RCU_CPU_STALL_TIMEOUT
4c54005c 115
a00e0d71
PM
116 This kernel configuration parameter defines the period of time
117 that RCU will wait from the beginning of a grace period until it
118 issues an RCU CPU stall warning. This time period is normally
64d3b7a1 119 21 seconds.
4c54005c 120
24cd7fd0 121 This configuration parameter may be changed at runtime via the
84596ccb 122 /sys/module/rcupdate/parameters/rcu_cpu_stall_timeout, however
24cd7fd0 123 this parameter is checked only at the beginning of a cycle.
64d3b7a1 124 So if you are 10 seconds into a 40-second stall, setting this
24cd7fd0
PM
125 sysfs parameter to (say) five will shorten the timeout for the
126 -next- stall, or the following warning for the current stall
127 (assuming the stall lasts long enough). It will not affect the
128 timing of the next warning for the current stall.
4c54005c 129
24cd7fd0 130 Stall-warning messages may be enabled and disabled completely via
96224daa 131 /sys/module/rcupdate/parameters/rcu_cpu_stall_suppress.
24cd7fd0 132
24cd7fd0
PM
133RCU_STALL_DELAY_DELTA
134
135 Although the lockdep facility is extremely useful, it does add
136 some overhead. Therefore, under CONFIG_PROVE_RCU, the
137 RCU_STALL_DELAY_DELTA macro allows five extra seconds before
64d3b7a1
PM
138 giving an RCU CPU stall warning message. (This is a cpp
139 macro, not a kernel configuration parameter.)
4c54005c
PM
140
141RCU_STALL_RAT_DELAY
142
f1d507be
PM
143 The CPU stall detector tries to make the offending CPU print its
144 own warnings, as this often gives better-quality stack traces.
145 However, if the offending CPU does not detect its own stall in
146 the number of jiffies specified by RCU_STALL_RAT_DELAY, then
147 some other CPU will complain. This delay is normally set to
64d3b7a1
PM
148 two jiffies. (This is a cpp macro, not a kernel configuration
149 parameter.)
4c54005c 150
37fe5f0e
PM
151rcupdate.rcu_task_stall_timeout
152
153 This boot/sysfs parameter controls the RCU-tasks stall warning
154 interval. A value of zero or less suppresses RCU-tasks stall
155 warnings. A positive value sets the stall-warning interval
14ef0575 156 in jiffies. An RCU-tasks stall warning starts with the line:
37fe5f0e
PM
157
158 INFO: rcu_tasks detected stalls on tasks:
159
160 And continues with the output of sched_show_task() for each
161 task stalling the current RCU-tasks grace period.
162
8e2a4397
PM
163
164Interpreting RCU's CPU Stall-Detector "Splats"
165
37fe5f0e
PM
166For non-RCU-tasks flavors of RCU, when a CPU detects that it is stalling,
167it will print a message similar to the following:
f1d507be 168
d3cf5176
PM
169 INFO: rcu_sched detected stalls on CPUs/tasks:
170 2-...: (3 GPs behind) idle=06c/0/0 softirq=1453/1455 fqs=0
171 16-...: (0 ticks this GP) idle=81c/0/0 softirq=764/764 fqs=0
e1333462 172 (detected by 32, t=2603 jiffies, g=7075, q=625)
f1d507be 173
d3cf5176
PM
174This message indicates that CPU 32 detected that CPUs 2 and 16 were both
175causing stalls, and that the stall was affecting RCU-sched. This message
f1d507be 176will normally be followed by stack dumps for each CPU. Please note that
d3cf5176
PM
177PREEMPT_RCU builds can be stalled by tasks as well as by CPUs, and that
178the tasks will be indicated by PID, for example, "P3421". It is even
179possible for a rcu_preempt_state stall to be caused by both CPUs -and-
180tasks, in which case the offending CPUs and tasks will all be called
181out in the list.
24cd7fd0 182
d3cf5176
PM
183CPU 2's "(3 GPs behind)" indicates that this CPU has not interacted with
184the RCU core for the past three grace periods. In contrast, CPU 16's "(0
185ticks this GP)" indicates that this CPU has not taken any scheduling-clock
186interrupts during the current stalled grace period.
24cd7fd0
PM
187
188The "idle=" portion of the message prints the dyntick-idle state.
189The hex number before the first "/" is the low-order 12 bits of the
d3cf5176
PM
190dynticks counter, which will have an even-numbered value if the CPU
191is in dyntick-idle mode and an odd-numbered value otherwise. The hex
192number between the two "/"s is the value of the nesting, which will be
193a small non-negative number if in the idle loop (as shown above) and a
194very large positive number otherwise.
24cd7fd0 195
6231069b
PM
196The "softirq=" portion of the message tracks the number of RCU softirq
197handlers that the stalled CPU has executed. The number before the "/"
198is the number that had executed since boot at the time that this CPU
199last noted the beginning of a grace period, which might be the current
200(stalled) grace period, or it might be some earlier grace period (for
201example, if the CPU might have been in dyntick-idle mode for an extended
202time period. The number after the "/" is the number that have executed
203since boot until the current time. If this latter number stays constant
204across repeated stall-warning messages, it is possible that RCU's softirq
205handlers are no longer able to execute on this CPU. This can happen if
206the stalled CPU is spinning with interrupts are disabled, or, in -rt
207kernels, if a high-priority process is starving RCU's softirq handler.
208
d3cf5176
PM
209The "fps=" shows the number of force-quiescent-state idle/offline
210detection passes that the grace-period kthread has made across this
211CPU since the last time that this CPU noted the beginning of a grace
212period.
213
214The "detected by" line indicates which CPU detected the stall (in this
e1333462
PM
215case, CPU 32), how many jiffies have elapsed since the start of the grace
216period (in this case 2603), the grace-period sequence number (7075), and
217an estimate of the total number of RCU callbacks queued across all CPUs
218(625 in this case).
d3cf5176
PM
219
220In kernels with CONFIG_RCU_FAST_NO_HZ, more information is printed
221for each CPU:
222
223 0: (64628 ticks this GP) idle=dd5/3fffffffffffffff/0 softirq=82/543 last_accelerate: a345/d342 nonlazy_posted: 25 .D
224
225The "last_accelerate:" prints the low-order 16 bits (in hex) of the
226jiffies counter when this CPU last invoked rcu_try_advance_all_cbs()
227from rcu_needs_cpu() or last invoked rcu_accelerate_cbs() from
228rcu_prepare_for_idle(). The "nonlazy_posted:" prints the number
229of non-lazy callbacks posted since the last call to rcu_needs_cpu().
230Finally, an "L" indicates that there are currently no non-lazy callbacks
231("." is printed otherwise, as shown above) and "D" indicates that
232dyntick-idle processing is enabled ("." is printed otherwise, for example,
233if disabled via the "nohz=" kernel boot parameter).
234
235If the grace period ends just as the stall warning starts printing,
236there will be a spurious stall-warning message, which will include
237the following:
238
239 INFO: Stall ended before state dump start
240
241This is rare, but does happen from time to time in real life. It is also
242possible for a zero-jiffy stall to be flagged in this case, depending
243on how the stall warning and the grace-period initialization happen to
244interact. Please note that it is not possible to entirely eliminate this
245sort of false positive without resorting to things like stop_machine(),
246which is overkill for this sort of problem.
247
248If all CPUs and tasks have passed through quiescent states, but the
249grace period has nevertheless failed to end, the stall-warning splat
250will include something like the following:
251
252 All QSes seen, last rcu_preempt kthread activity 23807 (4297905177-4297881370), jiffies_till_next_fqs=3, root ->qsmask 0x0
253
254The "23807" indicates that it has been more than 23 thousand jiffies
255since the grace-period kthread ran. The "jiffies_till_next_fqs"
256indicates how frequently that kthread should run, giving the number
257of jiffies between force-quiescent-state scans, in this case three,
258which is way less than 23807. Finally, the root rcu_node structure's
259->qsmask field is printed, which will normally be zero.
24cd7fd0 260
fb81a44b 261If the relevant grace-period kthread has been unable to run prior to
d3cf5176
PM
262the stall warning, as was the case in the "All QSes seen" line above,
263the following additional line is printed:
fb81a44b 264
e1333462 265 kthread starved for 23807 jiffies! g7075 f0x0 RCU_GP_WAIT_FQS(3) ->state=0x1 ->cpu=5
fb81a44b 266
d3cf5176
PM
267Starving the grace-period kthreads of CPU time can of course result
268in RCU CPU stall warnings even when all CPUs and tasks have passed
e1333462
PM
269through the required quiescent states. The "g" number shows the current
270grace-period sequence number, the "f" precedes the ->gp_flags command
271to the grace-period kthread, the "RCU_GP_WAIT_FQS" indicates that the
272kthread is waiting for a short timeout, the "state" precedes value of the
273task_struct ->state field, and the "cpu" indicates that the grace-period
274kthread last ran on CPU 5.
fb81a44b 275
24cd7fd0
PM
276
277Multiple Warnings From One Stall
278
279If a stall lasts long enough, multiple stall-warning messages will be
280printed for it. The second and subsequent messages are printed at
281longer intervals, so that the time between (say) the first and second
282message will be about three times the interval between the beginning
283of the stall and the first message.
284
285
99a930b0
PM
286Stall Warnings for Expedited Grace Periods
287
288If an expedited grace period detects a stall, it will place a message
289like the following in dmesg:
290
d3cf5176
PM
291 INFO: rcu_sched detected expedited stalls on CPUs/tasks: { 7-... } 21119 jiffies s: 73 root: 0x2/.
292
293This indicates that CPU 7 has failed to respond to a reschedule IPI.
294The three periods (".") following the CPU number indicate that the CPU
295is online (otherwise the first period would instead have been "O"),
296that the CPU was online at the beginning of the expedited grace period
297(otherwise the second period would have instead been "o"), and that
298the CPU has been online at least once since boot (otherwise, the third
299period would instead have been "N"). The number before the "jiffies"
300indicates that the expedited grace period has been going on for 21,119
301jiffies. The number following the "s:" indicates that the expedited
302grace-period sequence counter is 73. The fact that this last value is
303odd indicates that an expedited grace period is in flight. The number
304following "root:" is a bitmask that indicates which children of the root
305rcu_node structure correspond to CPUs and/or tasks that are blocking the
306current expedited grace period. If the tree had more than one level,
307additional hex numbers would be printed for the states of the other
308rcu_node structures in the tree.
309
310As with normal grace periods, PREEMPT_RCU builds can be stalled by
311tasks as well as by CPUs, and that the tasks will be indicated by PID,
312for example, "P3421".
99a930b0
PM
313
314It is entirely possible to see stall warnings from normal and from
d3cf5176 315expedited grace periods at about the same time during the same run.