blob: 08bc9aec4606afd9fef8f22e215de87d487ca8f6 [file] [log] [blame]
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +02001.. SPDX-License-Identifier: GPL-2.0
2
3==============================
Paul E. McKenney4c540052010-01-14 16:10:57 -08004Using RCU's CPU Stall Detector
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +02005==============================
Paul E. McKenney4c540052010-01-14 16:10:57 -08006
Paul E. McKenney8e2a4392017-02-08 14:30:15 -08007This document first discusses what sorts of issues RCU's CPU stall
8detector can locate, and then discusses kernel parameters and Kconfig
9options that can be used to fine-tune the detector's operation. Finally,
10this document explains the stall detector's "splat" format.
11
12
13What Causes RCU CPU Stall Warnings?
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +020014===================================
Paul E. McKenney8e2a4392017-02-08 14:30:15 -080015
16So your kernel printed an RCU CPU stall warning. The next question is
17"What caused it?" The following problems can result in RCU CPU stall
18warnings:
19
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +020020- A CPU looping in an RCU read-side critical section.
Paul E. McKenney8e2a4392017-02-08 14:30:15 -080021
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +020022- A CPU looping with interrupts disabled.
Paul E. McKenney8e2a4392017-02-08 14:30:15 -080023
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +020024- A CPU looping with preemption disabled.
Paul E. McKenney8e2a4392017-02-08 14:30:15 -080025
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +020026- A CPU looping with bottom halves disabled.
Paul E. McKenney8e2a4392017-02-08 14:30:15 -080027
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +020028- For !CONFIG_PREEMPT kernels, a CPU looping anywhere in the kernel
Paul E. McKenneyf2b17602017-10-24 08:42:41 -070029 without invoking schedule(). If the looping in the kernel is
30 really expected and desirable behavior, you might need to add
31 some calls to cond_resched().
Paul E. McKenney8e2a4392017-02-08 14:30:15 -080032
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +020033- Booting Linux using a console connection that is too slow to
Paul E. McKenney8e2a4392017-02-08 14:30:15 -080034 keep up with the boot-time console-message rate. For example,
35 a 115Kbaud serial console can be -way- too slow to keep up
36 with boot-time message rates, and will frequently result in
37 RCU CPU stall warning messages. Especially if you have added
38 debug printk()s.
39
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +020040- Anything that prevents RCU's grace-period kthreads from running.
Paul E. McKenney8e2a4392017-02-08 14:30:15 -080041 This can result in the "All QSes seen" console-log message.
42 This message will include information on when the kthread last
Paul E. McKenneydfa0ee42017-08-09 10:16:29 -070043 ran and how often it should be expected to run. It can also
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +020044 result in the ``rcu_.*kthread starved for`` console-log message,
Paul E. McKenneydfa0ee42017-08-09 10:16:29 -070045 which will include additional debugging information.
Paul E. McKenney8e2a4392017-02-08 14:30:15 -080046
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +020047- A CPU-bound real-time task in a CONFIG_PREEMPT kernel, which might
Paul E. McKenney8e2a4392017-02-08 14:30:15 -080048 happen to preempt a low-priority task in the middle of an RCU
49 read-side critical section. This is especially damaging if
50 that low-priority task is not permitted to run on any other CPU,
51 in which case the next RCU grace period can never complete, which
52 will eventually cause the system to run out of memory and hang.
53 While the system is in the process of running itself out of
54 memory, you might see stall-warning messages.
55
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +020056- A CPU-bound real-time task in a CONFIG_PREEMPT_RT kernel that
Paul E. McKenney8e2a4392017-02-08 14:30:15 -080057 is running at a higher priority than the RCU softirq threads.
58 This will prevent RCU callbacks from ever being invoked,
59 and in a CONFIG_PREEMPT_RCU kernel will further prevent
60 RCU grace periods from ever completing. Either way, the
61 system will eventually run out of memory and hang. In the
62 CONFIG_PREEMPT_RCU case, you might see stall-warning
63 messages.
64
Paul E. McKenney05008732019-07-08 08:01:50 -070065 You can use the rcutree.kthread_prio kernel boot parameter to
66 increase the scheduling priority of RCU's kthreads, which can
67 help avoid this problem. However, please note that doing this
68 can increase your system's context-switch rate and thus degrade
69 performance.
70
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +020071- A periodic interrupt whose handler takes longer than the time
Paul E. McKenneydfa0ee42017-08-09 10:16:29 -070072 interval between successive pairs of interrupts. This can
73 prevent RCU's kthreads and softirq handlers from running.
74 Note that certain high-overhead debugging options, for example
75 the function_graph tracer, can result in interrupt handler taking
76 considerably longer than normal, which can in turn result in
77 RCU CPU stall warnings.
78
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +020079- Testing a workload on a fast system, tuning the stall-warning
Paul E. McKenney3d916a42017-08-10 14:33:17 -070080 timeout down to just barely avoid RCU CPU stall warnings, and then
81 running the same workload with the same stall-warning timeout on a
82 slow system. Note that thermal throttling and on-demand governors
83 can cause a single system to be sometimes fast and sometimes slow!
84
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +020085- A hardware or software issue shuts off the scheduler-clock
Paul E. McKenney8e2a4392017-02-08 14:30:15 -080086 interrupt on a CPU that is not in dyntick-idle mode. This
87 problem really has happened, and seems to be most likely to
88 result in RCU CPU stall warnings for CONFIG_NO_HZ_COMMON=n kernels.
89
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +020090- A bug in the RCU implementation.
Paul E. McKenney8e2a4392017-02-08 14:30:15 -080091
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +020092- A hardware failure. This is quite unlikely, but has occurred
Paul E. McKenney8e2a4392017-02-08 14:30:15 -080093 at least once in real life. A CPU failed in a running system,
94 becoming unresponsive, but not causing an immediate crash.
95 This resulted in a series of RCU CPU stall warnings, eventually
96 leading the realization that the CPU had failed.
97
Paul E. McKenney77095902018-07-02 08:25:57 -070098The RCU, RCU-sched, and RCU-tasks implementations have CPU stall warning.
99Note that SRCU does -not- have CPU stall warnings. Please note that
100RCU only detects CPU stalls when there is a grace period in progress.
Paul E. McKenney8e2a4392017-02-08 14:30:15 -0800101No grace period, no CPU stall warnings.
102
103To diagnose the cause of the stall, inspect the stack traces.
104The offending function will usually be near the top of the stack.
105If you have a series of stall warnings from a single extended stall,
106comparing the stack traces can often help determine where the stall
107is occurring, which will usually be in the function nearest the top of
108that portion of the stack which remains the same from trace to trace.
109If you can reliably trigger the stall, ftrace can be quite helpful.
110
111RCU bugs can often be debugged with the help of CONFIG_RCU_TRACE
112and with RCU's event tracing. For information on RCU's event tracing,
113see include/trace/events/rcu.h.
114
115
116Fine-Tuning the RCU CPU Stall Detector
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +0200117======================================
Paul E. McKenney8e2a4392017-02-08 14:30:15 -0800118
119The rcuupdate.rcu_cpu_stall_suppress module parameter disables RCU's
120CPU stall detector, which detects conditions that unduly delay RCU grace
121periods. This module parameter enables CPU stall detection by default,
122but may be overridden via boot-time parameter or at runtime via sysfs.
Paul E. McKenneya00e0d712011-02-08 17:14:39 -0800123The stall detector's idea of what constitutes "unduly delayed" is
124controlled by a set of kernel configuration variables and cpp macros:
Paul E. McKenney4c540052010-01-14 16:10:57 -0800125
Paul E. McKenneya00e0d712011-02-08 17:14:39 -0800126CONFIG_RCU_CPU_STALL_TIMEOUT
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +0200127----------------------------
Paul E. McKenney4c540052010-01-14 16:10:57 -0800128
Paul E. McKenneya00e0d712011-02-08 17:14:39 -0800129 This kernel configuration parameter defines the period of time
130 that RCU will wait from the beginning of a grace period until it
131 issues an RCU CPU stall warning. This time period is normally
Paul E. McKenney64d3b7a2013-08-19 11:59:43 -0700132 21 seconds.
Paul E. McKenney4c540052010-01-14 16:10:57 -0800133
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800134 This configuration parameter may be changed at runtime via the
Xie XiuQi84596ccb2014-11-11 12:03:26 +0800135 /sys/module/rcupdate/parameters/rcu_cpu_stall_timeout, however
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800136 this parameter is checked only at the beginning of a cycle.
Paul E. McKenney64d3b7a2013-08-19 11:59:43 -0700137 So if you are 10 seconds into a 40-second stall, setting this
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800138 sysfs parameter to (say) five will shorten the timeout for the
139 -next- stall, or the following warning for the current stall
140 (assuming the stall lasts long enough). It will not affect the
141 timing of the next warning for the current stall.
Paul E. McKenney4c540052010-01-14 16:10:57 -0800142
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800143 Stall-warning messages may be enabled and disabled completely via
Paul E. McKenney96224da2014-02-25 09:47:34 -0800144 /sys/module/rcupdate/parameters/rcu_cpu_stall_suppress.
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800145
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800146RCU_STALL_DELAY_DELTA
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +0200147---------------------
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800148
149 Although the lockdep facility is extremely useful, it does add
150 some overhead. Therefore, under CONFIG_PROVE_RCU, the
151 RCU_STALL_DELAY_DELTA macro allows five extra seconds before
Paul E. McKenney64d3b7a2013-08-19 11:59:43 -0700152 giving an RCU CPU stall warning message. (This is a cpp
153 macro, not a kernel configuration parameter.)
Paul E. McKenney4c540052010-01-14 16:10:57 -0800154
155RCU_STALL_RAT_DELAY
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +0200156-------------------
Paul E. McKenney4c540052010-01-14 16:10:57 -0800157
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -0700158 The CPU stall detector tries to make the offending CPU print its
159 own warnings, as this often gives better-quality stack traces.
160 However, if the offending CPU does not detect its own stall in
161 the number of jiffies specified by RCU_STALL_RAT_DELAY, then
162 some other CPU will complain. This delay is normally set to
Paul E. McKenney64d3b7a2013-08-19 11:59:43 -0700163 two jiffies. (This is a cpp macro, not a kernel configuration
164 parameter.)
Paul E. McKenney4c540052010-01-14 16:10:57 -0800165
Paul E. McKenney37fe5f02014-07-29 09:49:23 -0700166rcupdate.rcu_task_stall_timeout
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +0200167-------------------------------
Paul E. McKenney37fe5f02014-07-29 09:49:23 -0700168
169 This boot/sysfs parameter controls the RCU-tasks stall warning
170 interval. A value of zero or less suppresses RCU-tasks stall
171 warnings. A positive value sets the stall-warning interval
Zhenzhong Duan588759a2019-04-14 11:11:03 +0800172 in seconds. An RCU-tasks stall warning starts with the line:
Paul E. McKenney37fe5f02014-07-29 09:49:23 -0700173
174 INFO: rcu_tasks detected stalls on tasks:
175
176 And continues with the output of sched_show_task() for each
177 task stalling the current RCU-tasks grace period.
178
Paul E. McKenney8e2a4392017-02-08 14:30:15 -0800179
180Interpreting RCU's CPU Stall-Detector "Splats"
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +0200181==============================================
Paul E. McKenney8e2a4392017-02-08 14:30:15 -0800182
Paul E. McKenney37fe5f02014-07-29 09:49:23 -0700183For non-RCU-tasks flavors of RCU, when a CPU detects that it is stalling,
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +0200184it will print a message similar to the following::
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -0700185
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700186 INFO: rcu_sched detected stalls on CPUs/tasks:
187 2-...: (3 GPs behind) idle=06c/0/0 softirq=1453/1455 fqs=0
188 16-...: (0 ticks this GP) idle=81c/0/0 softirq=764/764 fqs=0
Paul E. McKenneye1333462018-05-02 12:39:42 -0700189 (detected by 32, t=2603 jiffies, g=7075, q=625)
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -0700190
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700191This message indicates that CPU 32 detected that CPUs 2 and 16 were both
192causing stalls, and that the stall was affecting RCU-sched. This message
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -0700193will normally be followed by stack dumps for each CPU. Please note that
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700194PREEMPT_RCU builds can be stalled by tasks as well as by CPUs, and that
195the tasks will be indicated by PID, for example, "P3421". It is even
Joel Fernandes (Google)dd944ca2018-09-22 19:41:27 -0400196possible for an rcu_state stall to be caused by both CPUs -and- tasks,
197in which case the offending CPUs and tasks will all be called out in the list.
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -0700198
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700199CPU 2's "(3 GPs behind)" indicates that this CPU has not interacted with
200the RCU core for the past three grace periods. In contrast, CPU 16's "(0
201ticks this GP)" indicates that this CPU has not taken any scheduling-clock
202interrupts during the current stalled grace period.
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800203
204The "idle=" portion of the message prints the dyntick-idle state.
205The hex number before the first "/" is the low-order 12 bits of the
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700206dynticks counter, which will have an even-numbered value if the CPU
207is in dyntick-idle mode and an odd-numbered value otherwise. The hex
208number between the two "/"s is the value of the nesting, which will be
209a small non-negative number if in the idle loop (as shown above) and a
210very large positive number otherwise.
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800211
Paul E. McKenney62310692013-03-06 13:37:09 -0800212The "softirq=" portion of the message tracks the number of RCU softirq
213handlers that the stalled CPU has executed. The number before the "/"
214is the number that had executed since boot at the time that this CPU
215last noted the beginning of a grace period, which might be the current
216(stalled) grace period, or it might be some earlier grace period (for
217example, if the CPU might have been in dyntick-idle mode for an extended
218time period. The number after the "/" is the number that have executed
219since boot until the current time. If this latter number stays constant
220across repeated stall-warning messages, it is possible that RCU's softirq
221handlers are no longer able to execute on this CPU. This can happen if
222the stalled CPU is spinning with interrupts are disabled, or, in -rt
223kernels, if a high-priority process is starving RCU's softirq handler.
224
Joel Fernandes (Google)a78ad162018-10-29 22:15:59 -0700225The "fqs=" shows the number of force-quiescent-state idle/offline
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700226detection passes that the grace-period kthread has made across this
227CPU since the last time that this CPU noted the beginning of a grace
228period.
229
230The "detected by" line indicates which CPU detected the stall (in this
Paul E. McKenneye1333462018-05-02 12:39:42 -0700231case, CPU 32), how many jiffies have elapsed since the start of the grace
232period (in this case 2603), the grace-period sequence number (7075), and
233an estimate of the total number of RCU callbacks queued across all CPUs
234(625 in this case).
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700235
236In kernels with CONFIG_RCU_FAST_NO_HZ, more information is printed
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +0200237for each CPU::
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700238
Joel Fernandes (Google)77a40f92019-08-30 12:36:32 -0400239 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 -0700240
241The "last_accelerate:" prints the low-order 16 bits (in hex) of the
242jiffies counter when this CPU last invoked rcu_try_advance_all_cbs()
243from rcu_needs_cpu() or last invoked rcu_accelerate_cbs() from
Joel Fernandes (Google)77a40f92019-08-30 12:36:32 -0400244rcu_prepare_for_idle(). "dyntick_enabled: 1" indicates that dyntick-idle
245processing is enabled.
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700246
247If the grace period ends just as the stall warning starts printing,
248there will be a spurious stall-warning message, which will include
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +0200249the following::
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700250
251 INFO: Stall ended before state dump start
252
253This is rare, but does happen from time to time in real life. It is also
254possible for a zero-jiffy stall to be flagged in this case, depending
255on how the stall warning and the grace-period initialization happen to
256interact. Please note that it is not possible to entirely eliminate this
257sort of false positive without resorting to things like stop_machine(),
258which is overkill for this sort of problem.
259
260If all CPUs and tasks have passed through quiescent states, but the
261grace period has nevertheless failed to end, the stall-warning splat
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +0200262will include something like the following::
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700263
264 All QSes seen, last rcu_preempt kthread activity 23807 (4297905177-4297881370), jiffies_till_next_fqs=3, root ->qsmask 0x0
265
266The "23807" indicates that it has been more than 23 thousand jiffies
267since the grace-period kthread ran. The "jiffies_till_next_fqs"
268indicates how frequently that kthread should run, giving the number
269of jiffies between force-quiescent-state scans, in this case three,
270which is way less than 23807. Finally, the root rcu_node structure's
271->qsmask field is printed, which will normally be zero.
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800272
Paul E. McKenneyfb81a442014-12-17 08:35:02 -0800273If the relevant grace-period kthread has been unable to run prior to
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700274the stall warning, as was the case in the "All QSes seen" line above,
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +0200275the following additional line is printed::
Paul E. McKenneyfb81a442014-12-17 08:35:02 -0800276
Paul E. McKenneye1333462018-05-02 12:39:42 -0700277 kthread starved for 23807 jiffies! g7075 f0x0 RCU_GP_WAIT_FQS(3) ->state=0x1 ->cpu=5
Paul E. McKenneyfb81a442014-12-17 08:35:02 -0800278
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700279Starving the grace-period kthreads of CPU time can of course result
280in RCU CPU stall warnings even when all CPUs and tasks have passed
Paul E. McKenneye1333462018-05-02 12:39:42 -0700281through the required quiescent states. The "g" number shows the current
282grace-period sequence number, the "f" precedes the ->gp_flags command
283to the grace-period kthread, the "RCU_GP_WAIT_FQS" indicates that the
284kthread is waiting for a short timeout, the "state" precedes value of the
285task_struct ->state field, and the "cpu" indicates that the grace-period
286kthread last ran on CPU 5.
Paul E. McKenneyfb81a442014-12-17 08:35:02 -0800287
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800288
289Multiple Warnings From One Stall
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +0200290================================
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800291
292If a stall lasts long enough, multiple stall-warning messages will be
293printed for it. The second and subsequent messages are printed at
294longer intervals, so that the time between (say) the first and second
295message will be about three times the interval between the beginning
296of the stall and the first message.
297
298
Paul E. McKenney99a930b2015-06-30 14:54:09 -0700299Stall Warnings for Expedited Grace Periods
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +0200300==========================================
Paul E. McKenney99a930b2015-06-30 14:54:09 -0700301
302If an expedited grace period detects a stall, it will place a message
Mauro Carvalho Chehabf2286ab2020-04-21 19:04:10 +0200303like the following in dmesg::
Paul E. McKenney99a930b2015-06-30 14:54:09 -0700304
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700305 INFO: rcu_sched detected expedited stalls on CPUs/tasks: { 7-... } 21119 jiffies s: 73 root: 0x2/.
Paul E. McKenney99a930b2015-06-30 14:54:09 -0700306
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700307This indicates that CPU 7 has failed to respond to a reschedule IPI.
308The three periods (".") following the CPU number indicate that the CPU
309is online (otherwise the first period would instead have been "O"),
310that the CPU was online at the beginning of the expedited grace period
311(otherwise the second period would have instead been "o"), and that
312the CPU has been online at least once since boot (otherwise, the third
313period would instead have been "N"). The number before the "jiffies"
314indicates that the expedited grace period has been going on for 21,119
315jiffies. The number following the "s:" indicates that the expedited
316grace-period sequence counter is 73. The fact that this last value is
317odd indicates that an expedited grace period is in flight. The number
318following "root:" is a bitmask that indicates which children of the root
319rcu_node structure correspond to CPUs and/or tasks that are blocking the
320current expedited grace period. If the tree had more than one level,
321additional hex numbers would be printed for the states of the other
322rcu_node structures in the tree.
323
324As with normal grace periods, PREEMPT_RCU builds can be stalled by
325tasks as well as by CPUs, and that the tasks will be indicated by PID,
326for example, "P3421".
Paul E. McKenney99a930b2015-06-30 14:54:09 -0700327
328It is entirely possible to see stall warnings from normal and from
Paul E. McKenneyd3cf5172017-08-17 12:29:22 -0700329expedited grace periods at about the same time during the same run.