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