0001 .. SPDX-License-Identifier: GPL-2.0
0002
0003 ==============================
0004 Using RCU's CPU Stall Detector
0005 ==============================
0006
0007 This document first discusses what sorts of issues RCU's CPU stall
0008 detector can locate, and then discusses kernel parameters and Kconfig
0009 options that can be used to fine-tune the detector's operation. Finally,
0010 this document explains the stall detector's "splat" format.
0011
0012
0013 What Causes RCU CPU Stall Warnings?
0014 ===================================
0015
0016 So your kernel printed an RCU CPU stall warning. The next question is
0017 "What caused it?" The following problems can result in RCU CPU stall
0018 warnings:
0019
0020 - A CPU looping in an RCU read-side critical section.
0021
0022 - A CPU looping with interrupts disabled.
0023
0024 - A CPU looping with preemption disabled.
0025
0026 - A CPU looping with bottom halves disabled.
0027
0028 - For !CONFIG_PREEMPTION kernels, a CPU looping anywhere in the kernel
0029 without invoking schedule(). If the looping in the kernel is
0030 really expected and desirable behavior, you might need to add
0031 some calls to cond_resched().
0032
0033 - Booting Linux using a console connection that is too slow to
0034 keep up with the boot-time console-message rate. For example,
0035 a 115Kbaud serial console can be *way* too slow to keep up
0036 with boot-time message rates, and will frequently result in
0037 RCU CPU stall warning messages. Especially if you have added
0038 debug printk()s.
0039
0040 - Anything that prevents RCU's grace-period kthreads from running.
0041 This can result in the "All QSes seen" console-log message.
0042 This message will include information on when the kthread last
0043 ran and how often it should be expected to run. It can also
0044 result in the ``rcu_.*kthread starved for`` console-log message,
0045 which will include additional debugging information.
0046
0047 - A CPU-bound real-time task in a CONFIG_PREEMPTION kernel, which might
0048 happen to preempt a low-priority task in the middle of an RCU
0049 read-side critical section. This is especially damaging if
0050 that low-priority task is not permitted to run on any other CPU,
0051 in which case the next RCU grace period can never complete, which
0052 will eventually cause the system to run out of memory and hang.
0053 While the system is in the process of running itself out of
0054 memory, you might see stall-warning messages.
0055
0056 - A CPU-bound real-time task in a CONFIG_PREEMPT_RT kernel that
0057 is running at a higher priority than the RCU softirq threads.
0058 This will prevent RCU callbacks from ever being invoked,
0059 and in a CONFIG_PREEMPT_RCU kernel will further prevent
0060 RCU grace periods from ever completing. Either way, the
0061 system will eventually run out of memory and hang. In the
0062 CONFIG_PREEMPT_RCU case, you might see stall-warning
0063 messages.
0064
0065 You can use the rcutree.kthread_prio kernel boot parameter to
0066 increase the scheduling priority of RCU's kthreads, which can
0067 help avoid this problem. However, please note that doing this
0068 can increase your system's context-switch rate and thus degrade
0069 performance.
0070
0071 - A periodic interrupt whose handler takes longer than the time
0072 interval between successive pairs of interrupts. This can
0073 prevent RCU's kthreads and softirq handlers from running.
0074 Note that certain high-overhead debugging options, for example
0075 the function_graph tracer, can result in interrupt handler taking
0076 considerably longer than normal, which can in turn result in
0077 RCU CPU stall warnings.
0078
0079 - Testing a workload on a fast system, tuning the stall-warning
0080 timeout down to just barely avoid RCU CPU stall warnings, and then
0081 running the same workload with the same stall-warning timeout on a
0082 slow system. Note that thermal throttling and on-demand governors
0083 can cause a single system to be sometimes fast and sometimes slow!
0084
0085 - A hardware or software issue shuts off the scheduler-clock
0086 interrupt on a CPU that is not in dyntick-idle mode. This
0087 problem really has happened, and seems to be most likely to
0088 result in RCU CPU stall warnings for CONFIG_NO_HZ_COMMON=n kernels.
0089
0090 - A hardware or software issue that prevents time-based wakeups
0091 from occurring. These issues can range from misconfigured or
0092 buggy timer hardware through bugs in the interrupt or exception
0093 path (whether hardware, firmware, or software) through bugs
0094 in Linux's timer subsystem through bugs in the scheduler, and,
0095 yes, even including bugs in RCU itself. It can also result in
0096 the ``rcu_.*timer wakeup didn't happen for`` console-log message,
0097 which will include additional debugging information.
0098
0099 - A low-level kernel issue that either fails to invoke one of the
0100 variants of rcu_eqs_enter(true), rcu_eqs_exit(true), ct_idle_enter(),
0101 ct_idle_exit(), ct_irq_enter(), or ct_irq_exit() on the one
0102 hand, or that invokes one of them too many times on the other.
0103 Historically, the most frequent issue has been an omission
0104 of either irq_enter() or irq_exit(), which in turn invoke
0105 ct_irq_enter() or ct_irq_exit(), respectively. Building your
0106 kernel with CONFIG_RCU_EQS_DEBUG=y can help track down these types
0107 of issues, which sometimes arise in architecture-specific code.
0108
0109 - A bug in the RCU implementation.
0110
0111 - A hardware failure. This is quite unlikely, but has occurred
0112 at least once in real life. A CPU failed in a running system,
0113 becoming unresponsive, but not causing an immediate crash.
0114 This resulted in a series of RCU CPU stall warnings, eventually
0115 leading the realization that the CPU had failed.
0116
0117 The RCU, RCU-sched, and RCU-tasks implementations have CPU stall warning.
0118 Note that SRCU does *not* have CPU stall warnings. Please note that
0119 RCU only detects CPU stalls when there is a grace period in progress.
0120 No grace period, no CPU stall warnings.
0121
0122 To diagnose the cause of the stall, inspect the stack traces.
0123 The offending function will usually be near the top of the stack.
0124 If you have a series of stall warnings from a single extended stall,
0125 comparing the stack traces can often help determine where the stall
0126 is occurring, which will usually be in the function nearest the top of
0127 that portion of the stack which remains the same from trace to trace.
0128 If you can reliably trigger the stall, ftrace can be quite helpful.
0129
0130 RCU bugs can often be debugged with the help of CONFIG_RCU_TRACE
0131 and with RCU's event tracing. For information on RCU's event tracing,
0132 see include/trace/events/rcu.h.
0133
0134
0135 Fine-Tuning the RCU CPU Stall Detector
0136 ======================================
0137
0138 The rcuupdate.rcu_cpu_stall_suppress module parameter disables RCU's
0139 CPU stall detector, which detects conditions that unduly delay RCU grace
0140 periods. This module parameter enables CPU stall detection by default,
0141 but may be overridden via boot-time parameter or at runtime via sysfs.
0142 The stall detector's idea of what constitutes "unduly delayed" is
0143 controlled by a set of kernel configuration variables and cpp macros:
0144
0145 CONFIG_RCU_CPU_STALL_TIMEOUT
0146 ----------------------------
0147
0148 This kernel configuration parameter defines the period of time
0149 that RCU will wait from the beginning of a grace period until it
0150 issues an RCU CPU stall warning. This time period is normally
0151 21 seconds.
0152
0153 This configuration parameter may be changed at runtime via the
0154 /sys/module/rcupdate/parameters/rcu_cpu_stall_timeout, however
0155 this parameter is checked only at the beginning of a cycle.
0156 So if you are 10 seconds into a 40-second stall, setting this
0157 sysfs parameter to (say) five will shorten the timeout for the
0158 *next* stall, or the following warning for the current stall
0159 (assuming the stall lasts long enough). It will not affect the
0160 timing of the next warning for the current stall.
0161
0162 Stall-warning messages may be enabled and disabled completely via
0163 /sys/module/rcupdate/parameters/rcu_cpu_stall_suppress.
0164
0165 CONFIG_RCU_EXP_CPU_STALL_TIMEOUT
0166 --------------------------------
0167
0168 Same as the CONFIG_RCU_CPU_STALL_TIMEOUT parameter but only for
0169 the expedited grace period. This parameter defines the period
0170 of time that RCU will wait from the beginning of an expedited
0171 grace period until it issues an RCU CPU stall warning. This time
0172 period is normally 20 milliseconds on Android devices. A zero
0173 value causes the CONFIG_RCU_CPU_STALL_TIMEOUT value to be used,
0174 after conversion to milliseconds.
0175
0176 This configuration parameter may be changed at runtime via the
0177 /sys/module/rcupdate/parameters/rcu_exp_cpu_stall_timeout, however
0178 this parameter is checked only at the beginning of a cycle. If you
0179 are in a current stall cycle, setting it to a new value will change
0180 the timeout for the -next- stall.
0181
0182 Stall-warning messages may be enabled and disabled completely via
0183 /sys/module/rcupdate/parameters/rcu_cpu_stall_suppress.
0184
0185 RCU_STALL_DELAY_DELTA
0186 ---------------------
0187
0188 Although the lockdep facility is extremely useful, it does add
0189 some overhead. Therefore, under CONFIG_PROVE_RCU, the
0190 RCU_STALL_DELAY_DELTA macro allows five extra seconds before
0191 giving an RCU CPU stall warning message. (This is a cpp
0192 macro, not a kernel configuration parameter.)
0193
0194 RCU_STALL_RAT_DELAY
0195 -------------------
0196
0197 The CPU stall detector tries to make the offending CPU print its
0198 own warnings, as this often gives better-quality stack traces.
0199 However, if the offending CPU does not detect its own stall in
0200 the number of jiffies specified by RCU_STALL_RAT_DELAY, then
0201 some other CPU will complain. This delay is normally set to
0202 two jiffies. (This is a cpp macro, not a kernel configuration
0203 parameter.)
0204
0205 rcupdate.rcu_task_stall_timeout
0206 -------------------------------
0207
0208 This boot/sysfs parameter controls the RCU-tasks stall warning
0209 interval. A value of zero or less suppresses RCU-tasks stall
0210 warnings. A positive value sets the stall-warning interval
0211 in seconds. An RCU-tasks stall warning starts with the line:
0212
0213 INFO: rcu_tasks detected stalls on tasks:
0214
0215 And continues with the output of sched_show_task() for each
0216 task stalling the current RCU-tasks grace period.
0217
0218
0219 Interpreting RCU's CPU Stall-Detector "Splats"
0220 ==============================================
0221
0222 For non-RCU-tasks flavors of RCU, when a CPU detects that some other
0223 CPU is stalling, it will print a message similar to the following::
0224
0225 INFO: rcu_sched detected stalls on CPUs/tasks:
0226 2-...: (3 GPs behind) idle=06c/0/0 softirq=1453/1455 fqs=0
0227 16-...: (0 ticks this GP) idle=81c/0/0 softirq=764/764 fqs=0
0228 (detected by 32, t=2603 jiffies, g=7075, q=625)
0229
0230 This message indicates that CPU 32 detected that CPUs 2 and 16 were both
0231 causing stalls, and that the stall was affecting RCU-sched. This message
0232 will normally be followed by stack dumps for each CPU. Please note that
0233 PREEMPT_RCU builds can be stalled by tasks as well as by CPUs, and that
0234 the tasks will be indicated by PID, for example, "P3421". It is even
0235 possible for an rcu_state stall to be caused by both CPUs *and* tasks,
0236 in which case the offending CPUs and tasks will all be called out in the list.
0237 In some cases, CPUs will detect themselves stalling, which will result
0238 in a self-detected stall.
0239
0240 CPU 2's "(3 GPs behind)" indicates that this CPU has not interacted with
0241 the RCU core for the past three grace periods. In contrast, CPU 16's "(0
0242 ticks this GP)" indicates that this CPU has not taken any scheduling-clock
0243 interrupts during the current stalled grace period.
0244
0245 The "idle=" portion of the message prints the dyntick-idle state.
0246 The hex number before the first "/" is the low-order 12 bits of the
0247 dynticks counter, which will have an even-numbered value if the CPU
0248 is in dyntick-idle mode and an odd-numbered value otherwise. The hex
0249 number between the two "/"s is the value of the nesting, which will be
0250 a small non-negative number if in the idle loop (as shown above) and a
0251 very large positive number otherwise.
0252
0253 The "softirq=" portion of the message tracks the number of RCU softirq
0254 handlers that the stalled CPU has executed. The number before the "/"
0255 is the number that had executed since boot at the time that this CPU
0256 last noted the beginning of a grace period, which might be the current
0257 (stalled) grace period, or it might be some earlier grace period (for
0258 example, if the CPU might have been in dyntick-idle mode for an extended
0259 time period). The number after the "/" is the number that have executed
0260 since boot until the current time. If this latter number stays constant
0261 across repeated stall-warning messages, it is possible that RCU's softirq
0262 handlers are no longer able to execute on this CPU. This can happen if
0263 the stalled CPU is spinning with interrupts are disabled, or, in -rt
0264 kernels, if a high-priority process is starving RCU's softirq handler.
0265
0266 The "fqs=" shows the number of force-quiescent-state idle/offline
0267 detection passes that the grace-period kthread has made across this
0268 CPU since the last time that this CPU noted the beginning of a grace
0269 period.
0270
0271 The "detected by" line indicates which CPU detected the stall (in this
0272 case, CPU 32), how many jiffies have elapsed since the start of the grace
0273 period (in this case 2603), the grace-period sequence number (7075), and
0274 an estimate of the total number of RCU callbacks queued across all CPUs
0275 (625 in this case).
0276
0277 If the grace period ends just as the stall warning starts printing,
0278 there will be a spurious stall-warning message, which will include
0279 the following::
0280
0281 INFO: Stall ended before state dump start
0282
0283 This is rare, but does happen from time to time in real life. It is also
0284 possible for a zero-jiffy stall to be flagged in this case, depending
0285 on how the stall warning and the grace-period initialization happen to
0286 interact. Please note that it is not possible to entirely eliminate this
0287 sort of false positive without resorting to things like stop_machine(),
0288 which is overkill for this sort of problem.
0289
0290 If all CPUs and tasks have passed through quiescent states, but the
0291 grace period has nevertheless failed to end, the stall-warning splat
0292 will include something like the following::
0293
0294 All QSes seen, last rcu_preempt kthread activity 23807 (4297905177-4297881370), jiffies_till_next_fqs=3, root ->qsmask 0x0
0295
0296 The "23807" indicates that it has been more than 23 thousand jiffies
0297 since the grace-period kthread ran. The "jiffies_till_next_fqs"
0298 indicates how frequently that kthread should run, giving the number
0299 of jiffies between force-quiescent-state scans, in this case three,
0300 which is way less than 23807. Finally, the root rcu_node structure's
0301 ->qsmask field is printed, which will normally be zero.
0302
0303 If the relevant grace-period kthread has been unable to run prior to
0304 the stall warning, as was the case in the "All QSes seen" line above,
0305 the following additional line is printed::
0306
0307 rcu_sched kthread starved for 23807 jiffies! g7075 f0x0 RCU_GP_WAIT_FQS(3) ->state=0x1 ->cpu=5
0308 Unless rcu_sched kthread gets sufficient CPU time, OOM is now expected behavior.
0309
0310 Starving the grace-period kthreads of CPU time can of course result
0311 in RCU CPU stall warnings even when all CPUs and tasks have passed
0312 through the required quiescent states. The "g" number shows the current
0313 grace-period sequence number, the "f" precedes the ->gp_flags command
0314 to the grace-period kthread, the "RCU_GP_WAIT_FQS" indicates that the
0315 kthread is waiting for a short timeout, the "state" precedes value of the
0316 task_struct ->state field, and the "cpu" indicates that the grace-period
0317 kthread last ran on CPU 5.
0318
0319 If the relevant grace-period kthread does not wake from FQS wait in a
0320 reasonable time, then the following additional line is printed::
0321
0322 kthread timer wakeup didn't happen for 23804 jiffies! g7076 f0x0 RCU_GP_WAIT_FQS(5) ->state=0x402
0323
0324 The "23804" indicates that kthread's timer expired more than 23 thousand
0325 jiffies ago. The rest of the line has meaning similar to the kthread
0326 starvation case.
0327
0328 Additionally, the following line is printed::
0329
0330 Possible timer handling issue on cpu=4 timer-softirq=11142
0331
0332 Here "cpu" indicates that the grace-period kthread last ran on CPU 4,
0333 where it queued the fqs timer. The number following the "timer-softirq"
0334 is the current ``TIMER_SOFTIRQ`` count on cpu 4. If this value does not
0335 change on successive RCU CPU stall warnings, there is further reason to
0336 suspect a timer problem.
0337
0338 These messages are usually followed by stack dumps of the CPUs and tasks
0339 involved in the stall. These stack traces can help you locate the cause
0340 of the stall, keeping in mind that the CPU detecting the stall will have
0341 an interrupt frame that is mainly devoted to detecting the stall.
0342
0343
0344 Multiple Warnings From One Stall
0345 ================================
0346
0347 If a stall lasts long enough, multiple stall-warning messages will
0348 be printed for it. The second and subsequent messages are printed at
0349 longer intervals, so that the time between (say) the first and second
0350 message will be about three times the interval between the beginning
0351 of the stall and the first message. It can be helpful to compare the
0352 stack dumps for the different messages for the same stalled grace period.
0353
0354
0355 Stall Warnings for Expedited Grace Periods
0356 ==========================================
0357
0358 If an expedited grace period detects a stall, it will place a message
0359 like the following in dmesg::
0360
0361 INFO: rcu_sched detected expedited stalls on CPUs/tasks: { 7-... } 21119 jiffies s: 73 root: 0x2/.
0362
0363 This indicates that CPU 7 has failed to respond to a reschedule IPI.
0364 The three periods (".") following the CPU number indicate that the CPU
0365 is online (otherwise the first period would instead have been "O"),
0366 that the CPU was online at the beginning of the expedited grace period
0367 (otherwise the second period would have instead been "o"), and that
0368 the CPU has been online at least once since boot (otherwise, the third
0369 period would instead have been "N"). The number before the "jiffies"
0370 indicates that the expedited grace period has been going on for 21,119
0371 jiffies. The number following the "s:" indicates that the expedited
0372 grace-period sequence counter is 73. The fact that this last value is
0373 odd indicates that an expedited grace period is in flight. The number
0374 following "root:" is a bitmask that indicates which children of the root
0375 rcu_node structure correspond to CPUs and/or tasks that are blocking the
0376 current expedited grace period. If the tree had more than one level,
0377 additional hex numbers would be printed for the states of the other
0378 rcu_node structures in the tree.
0379
0380 As with normal grace periods, PREEMPT_RCU builds can be stalled by
0381 tasks as well as by CPUs, and that the tasks will be indicated by PID,
0382 for example, "P3421".
0383
0384 It is entirely possible to see stall warnings from normal and from
0385 expedited grace periods at about the same time during the same run.