Paul E. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 1 | Using RCU's CPU Stall Detector |
| 2 | |
Paul E. McKenney | a00e0d71 | 2011-02-08 17:14:39 -0800 | [diff] [blame] | 3 | The rcu_cpu_stall_suppress module parameter enables RCU's CPU stall |
| 4 | detector, which detects conditions that unduly delay RCU grace periods. |
| 5 | This module parameter enables CPU stall detection by default, but |
| 6 | may be overridden via boot-time parameter or at runtime via sysfs. |
| 7 | The stall detector's idea of what constitutes "unduly delayed" is |
| 8 | controlled by a set of kernel configuration variables and cpp macros: |
Paul E. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 9 | |
Paul E. McKenney | a00e0d71 | 2011-02-08 17:14:39 -0800 | [diff] [blame] | 10 | CONFIG_RCU_CPU_STALL_TIMEOUT |
Paul E. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 11 | |
Paul E. McKenney | a00e0d71 | 2011-02-08 17:14:39 -0800 | [diff] [blame] | 12 | 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. McKenney | 64d3b7a | 2013-08-19 11:59:43 -0700 | [diff] [blame] | 15 | 21 seconds. |
Paul E. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 16 | |
Paul E. McKenney | 24cd7fd | 2012-01-20 17:35:55 -0800 | [diff] [blame] | 17 | This configuration parameter may be changed at runtime via the |
Xie XiuQi | 84596cc | 2014-11-11 12:03:26 +0800 | [diff] [blame] | 18 | /sys/module/rcupdate/parameters/rcu_cpu_stall_timeout, however |
Paul E. McKenney | 24cd7fd | 2012-01-20 17:35:55 -0800 | [diff] [blame] | 19 | this parameter is checked only at the beginning of a cycle. |
Paul E. McKenney | 64d3b7a | 2013-08-19 11:59:43 -0700 | [diff] [blame] | 20 | So if you are 10 seconds into a 40-second stall, setting this |
Paul E. McKenney | 24cd7fd | 2012-01-20 17:35:55 -0800 | [diff] [blame] | 21 | 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. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 25 | |
Paul E. McKenney | 24cd7fd | 2012-01-20 17:35:55 -0800 | [diff] [blame] | 26 | Stall-warning messages may be enabled and disabled completely via |
Paul E. McKenney | 96224da | 2014-02-25 09:47:34 -0800 | [diff] [blame] | 27 | /sys/module/rcupdate/parameters/rcu_cpu_stall_suppress. |
Paul E. McKenney | 24cd7fd | 2012-01-20 17:35:55 -0800 | [diff] [blame] | 28 | |
Paul E. McKenney | 24cd7fd | 2012-01-20 17:35:55 -0800 | [diff] [blame] | 29 | RCU_STALL_DELAY_DELTA |
| 30 | |
| 31 | Although the lockdep facility is extremely useful, it does add |
| 32 | some overhead. Therefore, under CONFIG_PROVE_RCU, the |
| 33 | RCU_STALL_DELAY_DELTA macro allows five extra seconds before |
Paul E. McKenney | 64d3b7a | 2013-08-19 11:59:43 -0700 | [diff] [blame] | 34 | giving an RCU CPU stall warning message. (This is a cpp |
| 35 | macro, not a kernel configuration parameter.) |
Paul E. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 36 | |
| 37 | RCU_STALL_RAT_DELAY |
| 38 | |
Paul E. McKenney | f1d507b | 2010-04-15 15:49:46 -0700 | [diff] [blame] | 39 | The CPU stall detector tries to make the offending CPU print its |
| 40 | own warnings, as this often gives better-quality stack traces. |
| 41 | However, if the offending CPU does not detect its own stall in |
| 42 | the number of jiffies specified by RCU_STALL_RAT_DELAY, then |
| 43 | some other CPU will complain. This delay is normally set to |
Paul E. McKenney | 64d3b7a | 2013-08-19 11:59:43 -0700 | [diff] [blame] | 44 | two jiffies. (This is a cpp macro, not a kernel configuration |
| 45 | parameter.) |
Paul E. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 46 | |
Paul E. McKenney | 37fe5f0 | 2014-07-29 09:49:23 -0700 | [diff] [blame] | 47 | rcupdate.rcu_task_stall_timeout |
| 48 | |
| 49 | This boot/sysfs parameter controls the RCU-tasks stall warning |
| 50 | interval. A value of zero or less suppresses RCU-tasks stall |
| 51 | warnings. A positive value sets the stall-warning interval |
Eric Engestrom | 14ef057 | 2016-04-25 07:36:59 +0100 | [diff] [blame] | 52 | in jiffies. An RCU-tasks stall warning starts with the line: |
Paul E. McKenney | 37fe5f0 | 2014-07-29 09:49:23 -0700 | [diff] [blame] | 53 | |
| 54 | INFO: rcu_tasks detected stalls on tasks: |
| 55 | |
| 56 | And continues with the output of sched_show_task() for each |
| 57 | task stalling the current RCU-tasks grace period. |
| 58 | |
| 59 | For non-RCU-tasks flavors of RCU, when a CPU detects that it is stalling, |
| 60 | it will print a message similar to the following: |
Paul E. McKenney | f1d507b | 2010-04-15 15:49:46 -0700 | [diff] [blame] | 61 | |
| 62 | INFO: rcu_sched_state detected stall on CPU 5 (t=2500 jiffies) |
| 63 | |
| 64 | This message indicates that CPU 5 detected that it was causing a stall, |
| 65 | and that the stall was affecting RCU-sched. This message will normally be |
| 66 | followed by a stack dump of the offending CPU. On TREE_RCU kernel builds, |
| 67 | RCU and RCU-sched are implemented by the same underlying mechanism, |
Pranith Kumar | 28f6569 | 2014-09-22 14:00:48 -0400 | [diff] [blame] | 68 | while on PREEMPT_RCU kernel builds, RCU is instead implemented |
Paul E. McKenney | f1d507b | 2010-04-15 15:49:46 -0700 | [diff] [blame] | 69 | by rcu_preempt_state. |
| 70 | |
| 71 | On the other hand, if the offending CPU fails to print out a stall-warning |
| 72 | message quickly enough, some other CPU will print a message similar to |
| 73 | the following: |
| 74 | |
| 75 | INFO: rcu_bh_state detected stalls on CPUs/tasks: { 3 5 } (detected by 2, 2502 jiffies) |
| 76 | |
| 77 | This message indicates that CPU 2 detected that CPUs 3 and 5 were both |
| 78 | causing stalls, and that the stall was affecting RCU-bh. This message |
| 79 | will normally be followed by stack dumps for each CPU. Please note that |
Pranith Kumar | 28f6569 | 2014-09-22 14:00:48 -0400 | [diff] [blame] | 80 | PREEMPT_RCU builds can be stalled by tasks as well as by CPUs, |
Paul E. McKenney | f1d507b | 2010-04-15 15:49:46 -0700 | [diff] [blame] | 81 | and that the tasks will be indicated by PID, for example, "P3421". |
| 82 | It is even possible for a rcu_preempt_state stall to be caused by both |
| 83 | CPUs -and- tasks, in which case the offending CPUs and tasks will all |
| 84 | be called out in the list. |
| 85 | |
| 86 | Finally, if the grace period ends just as the stall warning starts |
| 87 | printing, there will be a spurious stall-warning message: |
| 88 | |
| 89 | INFO: rcu_bh_state detected stalls on CPUs/tasks: { } (detected by 4, 2502 jiffies) |
| 90 | |
Paul E. McKenney | 64d3b7a | 2013-08-19 11:59:43 -0700 | [diff] [blame] | 91 | This is rare, but does happen from time to time in real life. It is also |
| 92 | possible for a zero-jiffy stall to be flagged in this case, depending |
| 93 | on how the stall warning and the grace-period initialization happen to |
| 94 | interact. Please note that it is not possible to entirely eliminate this |
| 95 | sort of false positive without resorting to things like stop_machine(), |
| 96 | which is overkill for this sort of problem. |
Paul E. McKenney | f1d507b | 2010-04-15 15:49:46 -0700 | [diff] [blame] | 97 | |
Paul E. McKenney | 75c27f1 | 2015-06-11 15:22:43 -0700 | [diff] [blame] | 98 | Recent kernels will print a long form of the stall-warning message: |
Paul E. McKenney | 24cd7fd | 2012-01-20 17:35:55 -0800 | [diff] [blame] | 99 | |
| 100 | INFO: rcu_preempt detected stall on CPU |
Paul E. McKenney | 6231069 | 2013-03-06 13:37:09 -0800 | [diff] [blame] | 101 | 0: (63959 ticks this GP) idle=241/3fffffffffffffff/0 softirq=82/543 |
Paul E. McKenney | 24cd7fd | 2012-01-20 17:35:55 -0800 | [diff] [blame] | 102 | (t=65000 jiffies) |
| 103 | |
Paul E. McKenney | 75c27f1 | 2015-06-11 15:22:43 -0700 | [diff] [blame] | 104 | In kernels with CONFIG_RCU_FAST_NO_HZ, more information is printed: |
Paul E. McKenney | 24cd7fd | 2012-01-20 17:35:55 -0800 | [diff] [blame] | 105 | |
| 106 | INFO: rcu_preempt detected stall on CPU |
Paul E. McKenney | 6231069 | 2013-03-06 13:37:09 -0800 | [diff] [blame] | 107 | 0: (64628 ticks this GP) idle=dd5/3fffffffffffffff/0 softirq=82/543 last_accelerate: a345/d342 nonlazy_posted: 25 .D |
Paul E. McKenney | 24cd7fd | 2012-01-20 17:35:55 -0800 | [diff] [blame] | 108 | (t=65000 jiffies) |
| 109 | |
| 110 | The "(64628 ticks this GP)" indicates that this CPU has taken more |
| 111 | than 64,000 scheduling-clock interrupts during the current stalled |
| 112 | grace period. If the CPU was not yet aware of the current grace |
| 113 | period (for example, if it was offline), then this part of the message |
| 114 | indicates how many grace periods behind the CPU is. |
| 115 | |
| 116 | The "idle=" portion of the message prints the dyntick-idle state. |
| 117 | The hex number before the first "/" is the low-order 12 bits of the |
| 118 | dynticks counter, which will have an even-numbered value if the CPU is |
| 119 | in dyntick-idle mode and an odd-numbered value otherwise. The hex |
| 120 | number between the two "/"s is the value of the nesting, which will |
| 121 | be a small positive number if in the idle loop and a very large positive |
| 122 | number (as shown above) otherwise. |
| 123 | |
Paul E. McKenney | 6231069 | 2013-03-06 13:37:09 -0800 | [diff] [blame] | 124 | The "softirq=" portion of the message tracks the number of RCU softirq |
| 125 | handlers that the stalled CPU has executed. The number before the "/" |
| 126 | is the number that had executed since boot at the time that this CPU |
| 127 | last noted the beginning of a grace period, which might be the current |
| 128 | (stalled) grace period, or it might be some earlier grace period (for |
| 129 | example, if the CPU might have been in dyntick-idle mode for an extended |
| 130 | time period. The number after the "/" is the number that have executed |
| 131 | since boot until the current time. If this latter number stays constant |
| 132 | across repeated stall-warning messages, it is possible that RCU's softirq |
| 133 | handlers are no longer able to execute on this CPU. This can happen if |
| 134 | the stalled CPU is spinning with interrupts are disabled, or, in -rt |
| 135 | kernels, if a high-priority process is starving RCU's softirq handler. |
| 136 | |
| 137 | For CONFIG_RCU_FAST_NO_HZ kernels, the "last_accelerate:" prints the |
| 138 | low-order 16 bits (in hex) of the jiffies counter when this CPU last |
| 139 | invoked rcu_try_advance_all_cbs() from rcu_needs_cpu() or last invoked |
| 140 | rcu_accelerate_cbs() from rcu_prepare_for_idle(). The "nonlazy_posted:" |
| 141 | prints the number of non-lazy callbacks posted since the last call to |
| 142 | rcu_needs_cpu(). Finally, an "L" indicates that there are currently |
| 143 | no non-lazy callbacks ("." is printed otherwise, as shown above) and |
| 144 | "D" indicates that dyntick-idle processing is enabled ("." is printed |
| 145 | otherwise, for example, if disabled via the "nohz=" kernel boot parameter). |
Paul E. McKenney | 24cd7fd | 2012-01-20 17:35:55 -0800 | [diff] [blame] | 146 | |
Paul E. McKenney | fb81a44 | 2014-12-17 08:35:02 -0800 | [diff] [blame] | 147 | If the relevant grace-period kthread has been unable to run prior to |
| 148 | the stall warning, the following additional line is printed: |
| 149 | |
| 150 | rcu_preempt kthread starved for 2023 jiffies! |
| 151 | |
| 152 | Starving the grace-period kthreads of CPU time can of course result in |
| 153 | RCU CPU stall warnings even when all CPUs and tasks have passed through |
| 154 | the required quiescent states. |
| 155 | |
Paul E. McKenney | 24cd7fd | 2012-01-20 17:35:55 -0800 | [diff] [blame] | 156 | |
| 157 | Multiple Warnings From One Stall |
| 158 | |
| 159 | If a stall lasts long enough, multiple stall-warning messages will be |
| 160 | printed for it. The second and subsequent messages are printed at |
| 161 | longer intervals, so that the time between (say) the first and second |
| 162 | message will be about three times the interval between the beginning |
| 163 | of the stall and the first message. |
| 164 | |
| 165 | |
Paul E. McKenney | 99a930b | 2015-06-30 14:54:09 -0700 | [diff] [blame] | 166 | Stall Warnings for Expedited Grace Periods |
| 167 | |
| 168 | If an expedited grace period detects a stall, it will place a message |
| 169 | like the following in dmesg: |
| 170 | |
| 171 | INFO: rcu_sched detected expedited stalls on CPUs: { 1 2 6 } 26009 jiffies s: 1043 |
| 172 | |
| 173 | This indicates that CPUs 1, 2, and 6 have failed to respond to a |
| 174 | reschedule IPI, that the expedited grace period has been going on for |
| 175 | 26,009 jiffies, and that the expedited grace-period sequence counter is |
| 176 | 1043. The fact that this last value is odd indicates that an expedited |
| 177 | grace period is in flight. |
| 178 | |
| 179 | It is entirely possible to see stall warnings from normal and from |
| 180 | expedited grace periods at about the same time from the same run. |
| 181 | |
| 182 | |
Paul E. McKenney | 24cd7fd | 2012-01-20 17:35:55 -0800 | [diff] [blame] | 183 | What Causes RCU CPU Stall Warnings? |
| 184 | |
Paul E. McKenney | f1d507b | 2010-04-15 15:49:46 -0700 | [diff] [blame] | 185 | So your kernel printed an RCU CPU stall warning. The next question is |
| 186 | "What caused it?" The following problems can result in RCU CPU stall |
| 187 | warnings: |
Paul E. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 188 | |
| 189 | o A CPU looping in an RCU read-side critical section. |
| 190 | |
Paul E. McKenney | f1d507b | 2010-04-15 15:49:46 -0700 | [diff] [blame] | 191 | o A CPU looping with interrupts disabled. This condition can |
| 192 | result in RCU-sched and RCU-bh stalls. |
Paul E. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 193 | |
Paul E. McKenney | f1d507b | 2010-04-15 15:49:46 -0700 | [diff] [blame] | 194 | o A CPU looping with preemption disabled. This condition can |
| 195 | result in RCU-sched stalls and, if ksoftirqd is in use, RCU-bh |
| 196 | stalls. |
| 197 | |
| 198 | o A CPU looping with bottom halves disabled. This condition can |
| 199 | result in RCU-sched and RCU-bh stalls. |
Paul E. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 200 | |
Paul E. McKenney | 37fe5f0 | 2014-07-29 09:49:23 -0700 | [diff] [blame] | 201 | o For !CONFIG_PREEMPT kernels, a CPU looping anywhere in the |
| 202 | kernel without invoking schedule(). Note that cond_resched() |
| 203 | does not necessarily prevent RCU CPU stall warnings. Therefore, |
| 204 | if the looping in the kernel is really expected and desirable |
| 205 | behavior, you might need to replace some of the cond_resched() |
| 206 | calls with calls to cond_resched_rcu_qs(). |
Paul E. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 207 | |
Paul E. McKenney | da873de | 2015-08-04 11:54:04 -0700 | [diff] [blame] | 208 | o Booting Linux using a console connection that is too slow to |
| 209 | keep up with the boot-time console-message rate. For example, |
| 210 | a 115Kbaud serial console can be -way- too slow to keep up |
| 211 | with boot-time message rates, and will frequently result in |
| 212 | RCU CPU stall warning messages. Especially if you have added |
| 213 | debug printk()s. |
| 214 | |
Paul E. McKenney | 6ccd2ec | 2014-12-11 10:20:59 -0800 | [diff] [blame] | 215 | o Anything that prevents RCU's grace-period kthreads from running. |
| 216 | This can result in the "All QSes seen" console-log message. |
| 217 | This message will include information on when the kthread last |
| 218 | ran and how often it should be expected to run. |
| 219 | |
Paul E. McKenney | 2c96c77 | 2010-08-23 16:34:02 -0700 | [diff] [blame] | 220 | o A CPU-bound real-time task in a CONFIG_PREEMPT kernel, which might |
| 221 | happen to preempt a low-priority task in the middle of an RCU |
| 222 | read-side critical section. This is especially damaging if |
| 223 | that low-priority task is not permitted to run on any other CPU, |
| 224 | in which case the next RCU grace period can never complete, which |
| 225 | will eventually cause the system to run out of memory and hang. |
| 226 | While the system is in the process of running itself out of |
| 227 | memory, you might see stall-warning messages. |
| 228 | |
| 229 | o A CPU-bound real-time task in a CONFIG_PREEMPT_RT kernel that |
| 230 | is running at a higher priority than the RCU softirq threads. |
| 231 | This will prevent RCU callbacks from ever being invoked, |
Pranith Kumar | 28f6569 | 2014-09-22 14:00:48 -0400 | [diff] [blame] | 232 | and in a CONFIG_PREEMPT_RCU kernel will further prevent |
Paul E. McKenney | 2c96c77 | 2010-08-23 16:34:02 -0700 | [diff] [blame] | 233 | RCU grace periods from ever completing. Either way, the |
| 234 | system will eventually run out of memory and hang. In the |
Pranith Kumar | 28f6569 | 2014-09-22 14:00:48 -0400 | [diff] [blame] | 235 | CONFIG_PREEMPT_RCU case, you might see stall-warning |
Paul E. McKenney | 2c96c77 | 2010-08-23 16:34:02 -0700 | [diff] [blame] | 236 | messages. |
| 237 | |
Paul E. McKenney | 2c01531 | 2011-10-02 17:21:18 -0700 | [diff] [blame] | 238 | o A hardware or software issue shuts off the scheduler-clock |
| 239 | interrupt on a CPU that is not in dyntick-idle mode. This |
| 240 | problem really has happened, and seems to be most likely to |
Frederic Weisbecker | 3451d02 | 2011-08-10 23:21:01 +0200 | [diff] [blame] | 241 | result in RCU CPU stall warnings for CONFIG_NO_HZ_COMMON=n kernels. |
Paul E. McKenney | 2c01531 | 2011-10-02 17:21:18 -0700 | [diff] [blame] | 242 | |
Paul E. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 243 | o A bug in the RCU implementation. |
| 244 | |
| 245 | o A hardware failure. This is quite unlikely, but has occurred |
Paul E. McKenney | f1d507b | 2010-04-15 15:49:46 -0700 | [diff] [blame] | 246 | at least once in real life. A CPU failed in a running system, |
Paul E. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 247 | becoming unresponsive, but not causing an immediate crash. |
| 248 | This resulted in a series of RCU CPU stall warnings, eventually |
| 249 | leading the realization that the CPU had failed. |
| 250 | |
Paul E. McKenney | 37fe5f0 | 2014-07-29 09:49:23 -0700 | [diff] [blame] | 251 | The RCU, RCU-sched, RCU-bh, and RCU-tasks implementations have CPU stall |
| 252 | warning. Note that SRCU does -not- have CPU stall warnings. Please note |
| 253 | that RCU only detects CPU stalls when there is a grace period in progress. |
| 254 | No grace period, no CPU stall warnings. |
Paul E. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 255 | |
Paul E. McKenney | f1d507b | 2010-04-15 15:49:46 -0700 | [diff] [blame] | 256 | To diagnose the cause of the stall, inspect the stack traces. |
| 257 | The offending function will usually be near the top of the stack. |
| 258 | If you have a series of stall warnings from a single extended stall, |
| 259 | comparing the stack traces can often help determine where the stall |
| 260 | is occurring, which will usually be in the function nearest the top of |
| 261 | that portion of the stack which remains the same from trace to trace. |
| 262 | If you can reliably trigger the stall, ftrace can be quite helpful. |
Paul E. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 263 | |
Paul E. McKenney | 24cd7fd | 2012-01-20 17:35:55 -0800 | [diff] [blame] | 264 | RCU bugs can often be debugged with the help of CONFIG_RCU_TRACE |
Paul E. McKenney | 64d3b7a | 2013-08-19 11:59:43 -0700 | [diff] [blame] | 265 | and with RCU's event tracing. For information on RCU's event tracing, |
| 266 | see include/trace/events/rcu.h. |