blob: 783e0720994d1716c69f80b90d60b4ad478dab12 [file] [log] [blame]
Paul E. McKenney4c540052010-01-14 16:10:57 -08001Using RCU's CPU Stall Detector
2
Paul E. McKenneya00e0d712011-02-08 17:14:39 -08003The rcu_cpu_stall_suppress module parameter enables RCU's CPU stall
4detector, which detects conditions that unduly delay RCU grace periods.
5This module parameter enables CPU stall detection by default, but
6may be overridden via boot-time parameter or at runtime via sysfs.
7The stall detector's idea of what constitutes "unduly delayed" is
8controlled by a set of kernel configuration variables and cpp macros:
Paul E. McKenney4c540052010-01-14 16:10:57 -08009
Paul E. McKenneya00e0d712011-02-08 17:14:39 -080010CONFIG_RCU_CPU_STALL_TIMEOUT
Paul E. McKenney4c540052010-01-14 16:10:57 -080011
Paul E. McKenneya00e0d712011-02-08 17:14:39 -080012 This kernel configuration parameter defines the period of time
13 that RCU will wait from the beginning of a grace period until it
14 issues an RCU CPU stall warning. This time period is normally
Paul E. McKenney64d3b7a2013-08-19 11:59:43 -070015 21 seconds.
Paul E. McKenney4c540052010-01-14 16:10:57 -080016
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -080017 This configuration parameter may be changed at runtime via the
18 /sys/module/rcutree/parameters/rcu_cpu_stall_timeout, however
19 this parameter is checked only at the beginning of a cycle.
Paul E. McKenney64d3b7a2013-08-19 11:59:43 -070020 So if you are 10 seconds into a 40-second stall, setting this
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -080021 sysfs parameter to (say) five will shorten the timeout for the
22 -next- stall, or the following warning for the current stall
23 (assuming the stall lasts long enough). It will not affect the
24 timing of the next warning for the current stall.
Paul E. McKenney4c540052010-01-14 16:10:57 -080025
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -080026 Stall-warning messages may be enabled and disabled completely via
Paul E. McKenney96224da2014-02-25 09:47:34 -080027 /sys/module/rcupdate/parameters/rcu_cpu_stall_suppress.
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -080028
29CONFIG_RCU_CPU_STALL_VERBOSE
30
31 This kernel configuration parameter causes the stall warning to
32 also dump the stacks of any tasks that are blocking the current
33 RCU-preempt grace period.
34
Paul E. McKenney64d3b7a2013-08-19 11:59:43 -070035CONFIG_RCU_CPU_STALL_INFO
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -080036
37 This kernel configuration parameter causes the stall warning to
38 print out additional per-CPU diagnostic information, including
39 information on scheduling-clock ticks and RCU's idle-CPU tracking.
40
41RCU_STALL_DELAY_DELTA
42
43 Although the lockdep facility is extremely useful, it does add
44 some overhead. Therefore, under CONFIG_PROVE_RCU, the
45 RCU_STALL_DELAY_DELTA macro allows five extra seconds before
Paul E. McKenney64d3b7a2013-08-19 11:59:43 -070046 giving an RCU CPU stall warning message. (This is a cpp
47 macro, not a kernel configuration parameter.)
Paul E. McKenney4c540052010-01-14 16:10:57 -080048
49RCU_STALL_RAT_DELAY
50
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -070051 The CPU stall detector tries to make the offending CPU print its
52 own warnings, as this often gives better-quality stack traces.
53 However, if the offending CPU does not detect its own stall in
54 the number of jiffies specified by RCU_STALL_RAT_DELAY, then
55 some other CPU will complain. This delay is normally set to
Paul E. McKenney64d3b7a2013-08-19 11:59:43 -070056 two jiffies. (This is a cpp macro, not a kernel configuration
57 parameter.)
Paul E. McKenney4c540052010-01-14 16:10:57 -080058
Paul E. McKenney37fe5f02014-07-29 09:49:23 -070059rcupdate.rcu_task_stall_timeout
60
61 This boot/sysfs parameter controls the RCU-tasks stall warning
62 interval. A value of zero or less suppresses RCU-tasks stall
63 warnings. A positive value sets the stall-warning interval
64 in jiffies. An RCU-tasks stall warning starts wtih the line:
65
66 INFO: rcu_tasks detected stalls on tasks:
67
68 And continues with the output of sched_show_task() for each
69 task stalling the current RCU-tasks grace period.
70
71For non-RCU-tasks flavors of RCU, when a CPU detects that it is stalling,
72it will print a message similar to the following:
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -070073
74INFO: rcu_sched_state detected stall on CPU 5 (t=2500 jiffies)
75
76This message indicates that CPU 5 detected that it was causing a stall,
77and that the stall was affecting RCU-sched. This message will normally be
78followed by a stack dump of the offending CPU. On TREE_RCU kernel builds,
79RCU and RCU-sched are implemented by the same underlying mechanism,
Pranith Kumar28f65692014-09-22 14:00:48 -040080while on PREEMPT_RCU kernel builds, RCU is instead implemented
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -070081by rcu_preempt_state.
82
83On the other hand, if the offending CPU fails to print out a stall-warning
84message quickly enough, some other CPU will print a message similar to
85the following:
86
87INFO: rcu_bh_state detected stalls on CPUs/tasks: { 3 5 } (detected by 2, 2502 jiffies)
88
89This message indicates that CPU 2 detected that CPUs 3 and 5 were both
90causing stalls, and that the stall was affecting RCU-bh. This message
91will normally be followed by stack dumps for each CPU. Please note that
Pranith Kumar28f65692014-09-22 14:00:48 -040092PREEMPT_RCU builds can be stalled by tasks as well as by CPUs,
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -070093and that the tasks will be indicated by PID, for example, "P3421".
94It is even possible for a rcu_preempt_state stall to be caused by both
95CPUs -and- tasks, in which case the offending CPUs and tasks will all
96be called out in the list.
97
98Finally, if the grace period ends just as the stall warning starts
99printing, there will be a spurious stall-warning message:
100
101INFO: rcu_bh_state detected stalls on CPUs/tasks: { } (detected by 4, 2502 jiffies)
102
Paul E. McKenney64d3b7a2013-08-19 11:59:43 -0700103This is rare, but does happen from time to time in real life. It is also
104possible for a zero-jiffy stall to be flagged in this case, depending
105on how the stall warning and the grace-period initialization happen to
106interact. Please note that it is not possible to entirely eliminate this
107sort of false positive without resorting to things like stop_machine(),
108which is overkill for this sort of problem.
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -0700109
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800110If the CONFIG_RCU_CPU_STALL_INFO kernel configuration parameter is set,
111more information is printed with the stall-warning message, for example:
112
113 INFO: rcu_preempt detected stall on CPU
Paul E. McKenney62310692013-03-06 13:37:09 -0800114 0: (63959 ticks this GP) idle=241/3fffffffffffffff/0 softirq=82/543
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800115 (t=65000 jiffies)
116
117In kernels with CONFIG_RCU_FAST_NO_HZ, even more information is
118printed:
119
120 INFO: rcu_preempt detected stall on CPU
Paul E. McKenney62310692013-03-06 13:37:09 -0800121 0: (64628 ticks this GP) idle=dd5/3fffffffffffffff/0 softirq=82/543 last_accelerate: a345/d342 nonlazy_posted: 25 .D
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800122 (t=65000 jiffies)
123
124The "(64628 ticks this GP)" indicates that this CPU has taken more
125than 64,000 scheduling-clock interrupts during the current stalled
126grace period. If the CPU was not yet aware of the current grace
127period (for example, if it was offline), then this part of the message
128indicates how many grace periods behind the CPU is.
129
130The "idle=" portion of the message prints the dyntick-idle state.
131The hex number before the first "/" is the low-order 12 bits of the
132dynticks counter, which will have an even-numbered value if the CPU is
133in dyntick-idle mode and an odd-numbered value otherwise. The hex
134number between the two "/"s is the value of the nesting, which will
135be a small positive number if in the idle loop and a very large positive
136number (as shown above) otherwise.
137
Paul E. McKenney62310692013-03-06 13:37:09 -0800138The "softirq=" portion of the message tracks the number of RCU softirq
139handlers that the stalled CPU has executed. The number before the "/"
140is the number that had executed since boot at the time that this CPU
141last noted the beginning of a grace period, which might be the current
142(stalled) grace period, or it might be some earlier grace period (for
143example, if the CPU might have been in dyntick-idle mode for an extended
144time period. The number after the "/" is the number that have executed
145since boot until the current time. If this latter number stays constant
146across repeated stall-warning messages, it is possible that RCU's softirq
147handlers are no longer able to execute on this CPU. This can happen if
148the stalled CPU is spinning with interrupts are disabled, or, in -rt
149kernels, if a high-priority process is starving RCU's softirq handler.
150
151For CONFIG_RCU_FAST_NO_HZ kernels, the "last_accelerate:" prints the
152low-order 16 bits (in hex) of the jiffies counter when this CPU last
153invoked rcu_try_advance_all_cbs() from rcu_needs_cpu() or last invoked
154rcu_accelerate_cbs() from rcu_prepare_for_idle(). The "nonlazy_posted:"
155prints the number of non-lazy callbacks posted since the last call to
156rcu_needs_cpu(). Finally, an "L" indicates that there are currently
157no non-lazy callbacks ("." is printed otherwise, as shown above) and
158"D" indicates that dyntick-idle processing is enabled ("." is printed
159otherwise, for example, if disabled via the "nohz=" kernel boot parameter).
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800160
161
162Multiple Warnings From One Stall
163
164If a stall lasts long enough, multiple stall-warning messages will be
165printed for it. The second and subsequent messages are printed at
166longer intervals, so that the time between (say) the first and second
167message will be about three times the interval between the beginning
168of the stall and the first message.
169
170
171What Causes RCU CPU Stall Warnings?
172
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -0700173So your kernel printed an RCU CPU stall warning. The next question is
174"What caused it?" The following problems can result in RCU CPU stall
175warnings:
Paul E. McKenney4c540052010-01-14 16:10:57 -0800176
177o A CPU looping in an RCU read-side critical section.
178
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -0700179o A CPU looping with interrupts disabled. This condition can
180 result in RCU-sched and RCU-bh stalls.
Paul E. McKenney4c540052010-01-14 16:10:57 -0800181
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -0700182o A CPU looping with preemption disabled. This condition can
183 result in RCU-sched stalls and, if ksoftirqd is in use, RCU-bh
184 stalls.
185
186o A CPU looping with bottom halves disabled. This condition can
187 result in RCU-sched and RCU-bh stalls.
Paul E. McKenney4c540052010-01-14 16:10:57 -0800188
Paul E. McKenney37fe5f02014-07-29 09:49:23 -0700189o For !CONFIG_PREEMPT kernels, a CPU looping anywhere in the
190 kernel without invoking schedule(). Note that cond_resched()
191 does not necessarily prevent RCU CPU stall warnings. Therefore,
192 if the looping in the kernel is really expected and desirable
193 behavior, you might need to replace some of the cond_resched()
194 calls with calls to cond_resched_rcu_qs().
Paul E. McKenney4c540052010-01-14 16:10:57 -0800195
Paul E. McKenney2c96c772010-08-23 16:34:02 -0700196o A CPU-bound real-time task in a CONFIG_PREEMPT kernel, which might
197 happen to preempt a low-priority task in the middle of an RCU
198 read-side critical section. This is especially damaging if
199 that low-priority task is not permitted to run on any other CPU,
200 in which case the next RCU grace period can never complete, which
201 will eventually cause the system to run out of memory and hang.
202 While the system is in the process of running itself out of
203 memory, you might see stall-warning messages.
204
205o A CPU-bound real-time task in a CONFIG_PREEMPT_RT kernel that
206 is running at a higher priority than the RCU softirq threads.
207 This will prevent RCU callbacks from ever being invoked,
Pranith Kumar28f65692014-09-22 14:00:48 -0400208 and in a CONFIG_PREEMPT_RCU kernel will further prevent
Paul E. McKenney2c96c772010-08-23 16:34:02 -0700209 RCU grace periods from ever completing. Either way, the
210 system will eventually run out of memory and hang. In the
Pranith Kumar28f65692014-09-22 14:00:48 -0400211 CONFIG_PREEMPT_RCU case, you might see stall-warning
Paul E. McKenney2c96c772010-08-23 16:34:02 -0700212 messages.
213
Paul E. McKenney2c015312011-10-02 17:21:18 -0700214o A hardware or software issue shuts off the scheduler-clock
215 interrupt on a CPU that is not in dyntick-idle mode. This
216 problem really has happened, and seems to be most likely to
Frederic Weisbecker3451d022011-08-10 23:21:01 +0200217 result in RCU CPU stall warnings for CONFIG_NO_HZ_COMMON=n kernels.
Paul E. McKenney2c015312011-10-02 17:21:18 -0700218
Paul E. McKenney4c540052010-01-14 16:10:57 -0800219o A bug in the RCU implementation.
220
221o A hardware failure. This is quite unlikely, but has occurred
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -0700222 at least once in real life. A CPU failed in a running system,
Paul E. McKenney4c540052010-01-14 16:10:57 -0800223 becoming unresponsive, but not causing an immediate crash.
224 This resulted in a series of RCU CPU stall warnings, eventually
225 leading the realization that the CPU had failed.
226
Paul E. McKenney37fe5f02014-07-29 09:49:23 -0700227The RCU, RCU-sched, RCU-bh, and RCU-tasks implementations have CPU stall
228warning. Note that SRCU does -not- have CPU stall warnings. Please note
229that RCU only detects CPU stalls when there is a grace period in progress.
230No grace period, no CPU stall warnings.
Paul E. McKenney4c540052010-01-14 16:10:57 -0800231
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -0700232To diagnose the cause of the stall, inspect the stack traces.
233The offending function will usually be near the top of the stack.
234If you have a series of stall warnings from a single extended stall,
235comparing the stack traces can often help determine where the stall
236is occurring, which will usually be in the function nearest the top of
237that portion of the stack which remains the same from trace to trace.
238If you can reliably trigger the stall, ftrace can be quite helpful.
Paul E. McKenney4c540052010-01-14 16:10:57 -0800239
Paul E. McKenney24cd7fd2012-01-20 17:35:55 -0800240RCU bugs can often be debugged with the help of CONFIG_RCU_TRACE
Paul E. McKenney64d3b7a2013-08-19 11:59:43 -0700241and with RCU's event tracing. For information on RCU's event tracing,
242see include/trace/events/rcu.h.