blob: a360a8796710a2c7e7d5c7571d7562a83c4d86ef [file] [log] [blame]
Paul E. McKenney4c540052010-01-14 16:10:57 -08001Using RCU's CPU Stall Detector
2
Paul E. McKenney8e2a4392017-02-08 14:30:15 -08003This 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
Paul E. McKenney77095902018-07-02 08:25:57 -070019o A CPU looping with preemption disabled.
Paul E. McKenney8e2a4392017-02-08 14:30:15 -080020
Paul E. McKenney77095902018-07-02 08:25:57 -070021o A CPU looping with bottom halves disabled.
Paul E. McKenney8e2a4392017-02-08 14:30:15 -080022
Paul E. McKenneyf2b17602017-10-24 08:42:41 -070023o 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().
Paul E. McKenney8e2a4392017-02-08 14:30:15 -080027
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
Paul E. McKenneydfa0ee42017-08-09 10:16:29 -070038 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.
Paul E. McKenney8e2a4392017-02-08 14:30:15 -080041
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
Paul E. McKenney05008732019-07-08 08:01:50 -070060 You can use the rcutree.kthread_prio kernel boot parameter to
61 increase the scheduling priority of RCU's kthreads, which can
62 help avoid this problem. However, please note that doing this
63 can increase your system's context-switch rate and thus degrade
64 performance.
65
Paul E. McKenneydfa0ee42017-08-09 10:16:29 -070066o A periodic interrupt whose handler takes longer than the time
67 interval between successive pairs of interrupts. This can
68 prevent RCU's kthreads and softirq handlers from running.
69 Note that certain high-overhead debugging options, for example
70 the function_graph tracer, can result in interrupt handler taking
71 considerably longer than normal, which can in turn result in
72 RCU CPU stall warnings.
73
Paul E. McKenney3d916a42017-08-10 14:33:17 -070074o Testing a workload on a fast system, tuning the stall-warning
75 timeout down to just barely avoid RCU CPU stall warnings, and then
76 running the same workload with the same stall-warning timeout on a
77 slow system. Note that thermal throttling and on-demand governors
78 can cause a single system to be sometimes fast and sometimes slow!
79
Paul E. McKenney8e2a4392017-02-08 14:30:15 -080080o A hardware or software issue shuts off the scheduler-clock
81 interrupt on a CPU that is not in dyntick-idle mode. This
82 problem really has happened, and seems to be most likely to
83 result in RCU CPU stall warnings for CONFIG_NO_HZ_COMMON=n kernels.
84
85o A bug in the RCU implementation.
86
87o A hardware failure. This is quite unlikely, but has occurred
88 at least once in real life. A CPU failed in a running system,
89 becoming unresponsive, but not causing an immediate crash.
90 This resulted in a series of RCU CPU stall warnings, eventually
91 leading the realization that the CPU had failed.
92
Paul E. McKenney77095902018-07-02 08:25:57 -070093The RCU, RCU-sched, and RCU-tasks implementations have CPU stall warning.
94Note that SRCU does -not- have CPU stall warnings. Please note that
95RCU only detects CPU stalls when there is a grace period in progress.
Paul E. McKenney8e2a4392017-02-08 14:30:15 -080096No grace period, no CPU stall warnings.
97
98To diagnose the cause of the stall, inspect the stack traces.
99The offending function will usually be near the top of the stack.
100If you have a series of stall warnings from a single extended stall,
101comparing the stack traces can often help determine where the stall
102is occurring, which will usually be in the function nearest the top of
103that portion of the stack which remains the same from trace to trace.
104If you can reliably trigger the stall, ftrace can be quite helpful.
105
106RCU bugs can often be debugged with the help of CONFIG_RCU_TRACE
107and with RCU's event tracing. For information on RCU's event tracing,
108see include/trace/events/rcu.h.
109
110
111Fine-Tuning the RCU CPU Stall Detector
112
113The rcuupdate.rcu_cpu_stall_suppress module parameter disables RCU's
114CPU stall detector, which detects conditions that unduly delay RCU grace
115periods. This module parameter enables CPU stall detection by default,
116but may be overridden via boot-time parameter or at runtime via sysfs.
Paul E. McKenneya00e0d712011-02-08 17:14:39 -0800117The stall detector's idea of what constitutes "unduly delayed" is
118controlled by a set of kernel configuration variables and cpp macros:
Paul E. McKenney4c540052010-01-14 16:10:57 -0800119
Paul E. McKenneya00e0d712011-02-08 17:14:39 -0800120CONFIG_RCU_CPU_STALL_TIMEOUT
Paul E. McKenney4c540052010-01-14 16:10:57 -0800121
Paul E. McKenneya00e0d712011-02-08 17:14:39 -0800122 This kernel configuration parameter defines the period of time
123 that RCU will wait from the beginning of a grace period until it
124 issues an RCU CPU stall warning. This time period is normally
Paul E. McKenney64d3b7a2013-08-19 11:59:43 -0700125 21 seconds.
Paul E. McKenney4c540052010-01-14 16:10:57 -0800126
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800127 This configuration parameter may be changed at runtime via the
Xie XiuQi84596ccb2014-11-11 12:03:26 +0800128 /sys/module/rcupdate/parameters/rcu_cpu_stall_timeout, however
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800129 this parameter is checked only at the beginning of a cycle.
Paul E. McKenney64d3b7a2013-08-19 11:59:43 -0700130 So if you are 10 seconds into a 40-second stall, setting this
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800131 sysfs parameter to (say) five will shorten the timeout for the
132 -next- stall, or the following warning for the current stall
133 (assuming the stall lasts long enough). It will not affect the
134 timing of the next warning for the current stall.
Paul E. McKenney4c540052010-01-14 16:10:57 -0800135
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800136 Stall-warning messages may be enabled and disabled completely via
Paul E. McKenney96224da2014-02-25 09:47:34 -0800137 /sys/module/rcupdate/parameters/rcu_cpu_stall_suppress.
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800138
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800139RCU_STALL_DELAY_DELTA
140
141 Although the lockdep facility is extremely useful, it does add
142 some overhead. Therefore, under CONFIG_PROVE_RCU, the
143 RCU_STALL_DELAY_DELTA macro allows five extra seconds before
Paul E. McKenney64d3b7a2013-08-19 11:59:43 -0700144 giving an RCU CPU stall warning message. (This is a cpp
145 macro, not a kernel configuration parameter.)
Paul E. McKenney4c540052010-01-14 16:10:57 -0800146
147RCU_STALL_RAT_DELAY
148
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -0700149 The CPU stall detector tries to make the offending CPU print its
150 own warnings, as this often gives better-quality stack traces.
151 However, if the offending CPU does not detect its own stall in
152 the number of jiffies specified by RCU_STALL_RAT_DELAY, then
153 some other CPU will complain. This delay is normally set to
Paul E. McKenney64d3b7a2013-08-19 11:59:43 -0700154 two jiffies. (This is a cpp macro, not a kernel configuration
155 parameter.)
Paul E. McKenney4c540052010-01-14 16:10:57 -0800156
Paul E. McKenney37fe5f02014-07-29 09:49:23 -0700157rcupdate.rcu_task_stall_timeout
158
159 This boot/sysfs parameter controls the RCU-tasks stall warning
160 interval. A value of zero or less suppresses RCU-tasks stall
161 warnings. A positive value sets the stall-warning interval
Zhenzhong Duan588759a2019-04-14 11:11:03 +0800162 in seconds. An RCU-tasks stall warning starts with the line:
Paul E. McKenney37fe5f02014-07-29 09:49:23 -0700163
164 INFO: rcu_tasks detected stalls on tasks:
165
166 And continues with the output of sched_show_task() for each
167 task stalling the current RCU-tasks grace period.
168
Paul E. McKenney8e2a4392017-02-08 14:30:15 -0800169
170Interpreting RCU's CPU Stall-Detector "Splats"
171
Paul E. McKenney37fe5f02014-07-29 09:49:23 -0700172For non-RCU-tasks flavors of RCU, when a CPU detects that it is stalling,
173it will print a message similar to the following:
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -0700174
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700175 INFO: rcu_sched detected stalls on CPUs/tasks:
176 2-...: (3 GPs behind) idle=06c/0/0 softirq=1453/1455 fqs=0
177 16-...: (0 ticks this GP) idle=81c/0/0 softirq=764/764 fqs=0
Paul E. McKenneye1333462018-05-02 12:39:42 -0700178 (detected by 32, t=2603 jiffies, g=7075, q=625)
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -0700179
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700180This message indicates that CPU 32 detected that CPUs 2 and 16 were both
181causing stalls, and that the stall was affecting RCU-sched. This message
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -0700182will normally be followed by stack dumps for each CPU. Please note that
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700183PREEMPT_RCU builds can be stalled by tasks as well as by CPUs, and that
184the tasks will be indicated by PID, for example, "P3421". It is even
Joel Fernandes (Google)dd944ca2018-09-22 19:41:27 -0400185possible for an rcu_state stall to be caused by both CPUs -and- tasks,
186in which case the offending CPUs and tasks will all be called out in the list.
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -0700187
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700188CPU 2's "(3 GPs behind)" indicates that this CPU has not interacted with
189the RCU core for the past three grace periods. In contrast, CPU 16's "(0
190ticks this GP)" indicates that this CPU has not taken any scheduling-clock
191interrupts during the current stalled grace period.
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800192
193The "idle=" portion of the message prints the dyntick-idle state.
194The hex number before the first "/" is the low-order 12 bits of the
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700195dynticks counter, which will have an even-numbered value if the CPU
196is in dyntick-idle mode and an odd-numbered value otherwise. The hex
197number between the two "/"s is the value of the nesting, which will be
198a small non-negative number if in the idle loop (as shown above) and a
199very large positive number otherwise.
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800200
Paul E. McKenney62310692013-03-06 13:37:09 -0800201The "softirq=" portion of the message tracks the number of RCU softirq
202handlers that the stalled CPU has executed. The number before the "/"
203is the number that had executed since boot at the time that this CPU
204last noted the beginning of a grace period, which might be the current
205(stalled) grace period, or it might be some earlier grace period (for
206example, if the CPU might have been in dyntick-idle mode for an extended
207time period. The number after the "/" is the number that have executed
208since boot until the current time. If this latter number stays constant
209across repeated stall-warning messages, it is possible that RCU's softirq
210handlers are no longer able to execute on this CPU. This can happen if
211the stalled CPU is spinning with interrupts are disabled, or, in -rt
212kernels, if a high-priority process is starving RCU's softirq handler.
213
Joel Fernandes (Google)a78ad162018-10-29 22:15:59 -0700214The "fqs=" shows the number of force-quiescent-state idle/offline
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700215detection passes that the grace-period kthread has made across this
216CPU since the last time that this CPU noted the beginning of a grace
217period.
218
219The "detected by" line indicates which CPU detected the stall (in this
Paul E. McKenneye1333462018-05-02 12:39:42 -0700220case, CPU 32), how many jiffies have elapsed since the start of the grace
221period (in this case 2603), the grace-period sequence number (7075), and
222an estimate of the total number of RCU callbacks queued across all CPUs
223(625 in this case).
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700224
225In kernels with CONFIG_RCU_FAST_NO_HZ, more information is printed
226for each CPU:
227
Joel Fernandes (Google)77a40f92019-08-30 12:36:32 -0400228 0: (64628 ticks this GP) idle=dd5/3fffffffffffffff/0 softirq=82/543 last_accelerate: a345/d342 dyntick_enabled: 1
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700229
230The "last_accelerate:" prints the low-order 16 bits (in hex) of the
231jiffies counter when this CPU last invoked rcu_try_advance_all_cbs()
232from rcu_needs_cpu() or last invoked rcu_accelerate_cbs() from
Joel Fernandes (Google)77a40f92019-08-30 12:36:32 -0400233rcu_prepare_for_idle(). "dyntick_enabled: 1" indicates that dyntick-idle
234processing is enabled.
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700235
236If the grace period ends just as the stall warning starts printing,
237there will be a spurious stall-warning message, which will include
238the following:
239
240 INFO: Stall ended before state dump start
241
242This is rare, but does happen from time to time in real life. It is also
243possible for a zero-jiffy stall to be flagged in this case, depending
244on how the stall warning and the grace-period initialization happen to
245interact. Please note that it is not possible to entirely eliminate this
246sort of false positive without resorting to things like stop_machine(),
247which is overkill for this sort of problem.
248
249If all CPUs and tasks have passed through quiescent states, but the
250grace period has nevertheless failed to end, the stall-warning splat
251will include something like the following:
252
253 All QSes seen, last rcu_preempt kthread activity 23807 (4297905177-4297881370), jiffies_till_next_fqs=3, root ->qsmask 0x0
254
255The "23807" indicates that it has been more than 23 thousand jiffies
256since the grace-period kthread ran. The "jiffies_till_next_fqs"
257indicates how frequently that kthread should run, giving the number
258of jiffies between force-quiescent-state scans, in this case three,
259which is way less than 23807. Finally, the root rcu_node structure's
260->qsmask field is printed, which will normally be zero.
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800261
Paul E. McKenneyfb81a442014-12-17 08:35:02 -0800262If the relevant grace-period kthread has been unable to run prior to
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700263the stall warning, as was the case in the "All QSes seen" line above,
264the following additional line is printed:
Paul E. McKenneyfb81a442014-12-17 08:35:02 -0800265
Paul E. McKenneye1333462018-05-02 12:39:42 -0700266 kthread starved for 23807 jiffies! g7075 f0x0 RCU_GP_WAIT_FQS(3) ->state=0x1 ->cpu=5
Paul E. McKenneyfb81a442014-12-17 08:35:02 -0800267
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700268Starving the grace-period kthreads of CPU time can of course result
269in RCU CPU stall warnings even when all CPUs and tasks have passed
Paul E. McKenneye1333462018-05-02 12:39:42 -0700270through the required quiescent states. The "g" number shows the current
271grace-period sequence number, the "f" precedes the ->gp_flags command
272to the grace-period kthread, the "RCU_GP_WAIT_FQS" indicates that the
273kthread is waiting for a short timeout, the "state" precedes value of the
274task_struct ->state field, and the "cpu" indicates that the grace-period
275kthread last ran on CPU 5.
Paul E. McKenneyfb81a442014-12-17 08:35:02 -0800276
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800277
278Multiple Warnings From One Stall
279
280If a stall lasts long enough, multiple stall-warning messages will be
281printed for it. The second and subsequent messages are printed at
282longer intervals, so that the time between (say) the first and second
283message will be about three times the interval between the beginning
284of the stall and the first message.
285
286
Paul E. McKenney99a930b2015-06-30 14:54:09 -0700287Stall Warnings for Expedited Grace Periods
288
289If an expedited grace period detects a stall, it will place a message
290like the following in dmesg:
291
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700292 INFO: rcu_sched detected expedited stalls on CPUs/tasks: { 7-... } 21119 jiffies s: 73 root: 0x2/.
Paul E. McKenney99a930b2015-06-30 14:54:09 -0700293
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700294This indicates that CPU 7 has failed to respond to a reschedule IPI.
295The three periods (".") following the CPU number indicate that the CPU
296is online (otherwise the first period would instead have been "O"),
297that the CPU was online at the beginning of the expedited grace period
298(otherwise the second period would have instead been "o"), and that
299the CPU has been online at least once since boot (otherwise, the third
300period would instead have been "N"). The number before the "jiffies"
301indicates that the expedited grace period has been going on for 21,119
302jiffies. The number following the "s:" indicates that the expedited
303grace-period sequence counter is 73. The fact that this last value is
304odd indicates that an expedited grace period is in flight. The number
305following "root:" is a bitmask that indicates which children of the root
306rcu_node structure correspond to CPUs and/or tasks that are blocking the
307current expedited grace period. If the tree had more than one level,
308additional hex numbers would be printed for the states of the other
309rcu_node structures in the tree.
310
311As with normal grace periods, PREEMPT_RCU builds can be stalled by
312tasks as well as by CPUs, and that the tasks will be indicated by PID,
313for example, "P3421".
Paul E. McKenney99a930b2015-06-30 14:54:09 -0700314
315It is entirely possible to see stall warnings from normal and from
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700316expedited grace periods at about the same time during the same run.