stallwarn.txt 15 KB

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