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 |
| 15 | ten seconds. |
Paul E. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 16 | |
| 17 | RCU_SECONDS_TILL_STALL_RECHECK |
| 18 | |
| 19 | This macro defines the period of time that RCU will wait after |
Paul E. McKenney | f1d507b | 2010-04-15 15:49:46 -0700 | [diff] [blame] | 20 | issuing a stall warning until it issues another stall warning |
Paul E. McKenney | a00e0d71 | 2011-02-08 17:14:39 -0800 | [diff] [blame] | 21 | for the same stall. This time period is normally set to three |
| 22 | times the check interval plus thirty seconds. |
Paul E. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 23 | |
| 24 | RCU_STALL_RAT_DELAY |
| 25 | |
Paul E. McKenney | f1d507b | 2010-04-15 15:49:46 -0700 | [diff] [blame] | 26 | The CPU stall detector tries to make the offending CPU print its |
| 27 | own warnings, as this often gives better-quality stack traces. |
| 28 | However, if the offending CPU does not detect its own stall in |
| 29 | the number of jiffies specified by RCU_STALL_RAT_DELAY, then |
| 30 | some other CPU will complain. This delay is normally set to |
| 31 | two jiffies. |
Paul E. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 32 | |
Paul E. McKenney | f1d507b | 2010-04-15 15:49:46 -0700 | [diff] [blame] | 33 | When a CPU detects that it is stalling, it will print a message similar |
| 34 | to the following: |
| 35 | |
| 36 | INFO: rcu_sched_state detected stall on CPU 5 (t=2500 jiffies) |
| 37 | |
| 38 | This message indicates that CPU 5 detected that it was causing a stall, |
| 39 | and that the stall was affecting RCU-sched. This message will normally be |
| 40 | followed by a stack dump of the offending CPU. On TREE_RCU kernel builds, |
| 41 | RCU and RCU-sched are implemented by the same underlying mechanism, |
| 42 | while on TREE_PREEMPT_RCU kernel builds, RCU is instead implemented |
| 43 | by rcu_preempt_state. |
| 44 | |
| 45 | On the other hand, if the offending CPU fails to print out a stall-warning |
| 46 | message quickly enough, some other CPU will print a message similar to |
| 47 | the following: |
| 48 | |
| 49 | INFO: rcu_bh_state detected stalls on CPUs/tasks: { 3 5 } (detected by 2, 2502 jiffies) |
| 50 | |
| 51 | This message indicates that CPU 2 detected that CPUs 3 and 5 were both |
| 52 | causing stalls, and that the stall was affecting RCU-bh. This message |
| 53 | will normally be followed by stack dumps for each CPU. Please note that |
| 54 | TREE_PREEMPT_RCU builds can be stalled by tasks as well as by CPUs, |
| 55 | and that the tasks will be indicated by PID, for example, "P3421". |
| 56 | It is even possible for a rcu_preempt_state stall to be caused by both |
| 57 | CPUs -and- tasks, in which case the offending CPUs and tasks will all |
| 58 | be called out in the list. |
| 59 | |
| 60 | Finally, if the grace period ends just as the stall warning starts |
| 61 | printing, there will be a spurious stall-warning message: |
| 62 | |
| 63 | INFO: rcu_bh_state detected stalls on CPUs/tasks: { } (detected by 4, 2502 jiffies) |
| 64 | |
| 65 | This is rare, but does happen from time to time in real life. |
| 66 | |
| 67 | So your kernel printed an RCU CPU stall warning. The next question is |
| 68 | "What caused it?" The following problems can result in RCU CPU stall |
| 69 | warnings: |
Paul E. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 70 | |
| 71 | o A CPU looping in an RCU read-side critical section. |
| 72 | |
Paul E. McKenney | f1d507b | 2010-04-15 15:49:46 -0700 | [diff] [blame] | 73 | o A CPU looping with interrupts disabled. This condition can |
| 74 | result in RCU-sched and RCU-bh stalls. |
Paul E. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 75 | |
Paul E. McKenney | f1d507b | 2010-04-15 15:49:46 -0700 | [diff] [blame] | 76 | o A CPU looping with preemption disabled. This condition can |
| 77 | result in RCU-sched stalls and, if ksoftirqd is in use, RCU-bh |
| 78 | stalls. |
| 79 | |
| 80 | o A CPU looping with bottom halves disabled. This condition can |
| 81 | result in RCU-sched and RCU-bh stalls. |
Paul E. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 82 | |
| 83 | o For !CONFIG_PREEMPT kernels, a CPU looping anywhere in the kernel |
| 84 | without invoking schedule(). |
| 85 | |
Paul E. McKenney | 2c96c77 | 2010-08-23 16:34:02 -0700 | [diff] [blame] | 86 | o A CPU-bound real-time task in a CONFIG_PREEMPT kernel, which might |
| 87 | happen to preempt a low-priority task in the middle of an RCU |
| 88 | read-side critical section. This is especially damaging if |
| 89 | that low-priority task is not permitted to run on any other CPU, |
| 90 | in which case the next RCU grace period can never complete, which |
| 91 | will eventually cause the system to run out of memory and hang. |
| 92 | While the system is in the process of running itself out of |
| 93 | memory, you might see stall-warning messages. |
| 94 | |
| 95 | o A CPU-bound real-time task in a CONFIG_PREEMPT_RT kernel that |
| 96 | is running at a higher priority than the RCU softirq threads. |
| 97 | This will prevent RCU callbacks from ever being invoked, |
| 98 | and in a CONFIG_TREE_PREEMPT_RCU kernel will further prevent |
| 99 | RCU grace periods from ever completing. Either way, the |
| 100 | system will eventually run out of memory and hang. In the |
| 101 | CONFIG_TREE_PREEMPT_RCU case, you might see stall-warning |
| 102 | messages. |
| 103 | |
Paul E. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 104 | o A bug in the RCU implementation. |
| 105 | |
| 106 | o A hardware failure. This is quite unlikely, but has occurred |
Paul E. McKenney | f1d507b | 2010-04-15 15:49:46 -0700 | [diff] [blame] | 107 | 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] | 108 | becoming unresponsive, but not causing an immediate crash. |
| 109 | This resulted in a series of RCU CPU stall warnings, eventually |
| 110 | leading the realization that the CPU had failed. |
| 111 | |
Paul E. McKenney | f1d507b | 2010-04-15 15:49:46 -0700 | [diff] [blame] | 112 | The RCU, RCU-sched, and RCU-bh implementations have CPU stall |
| 113 | warning. SRCU does not have its own CPU stall warnings, but its |
| 114 | calls to synchronize_sched() will result in RCU-sched detecting |
| 115 | RCU-sched-related CPU stalls. Please note that RCU only detects |
| 116 | CPU stalls when there is a grace period in progress. No grace period, |
| 117 | no CPU stall warnings. |
Paul E. McKenney | 4c54005 | 2010-01-14 16:10:57 -0800 | [diff] [blame] | 118 | |
Paul E. McKenney | f1d507b | 2010-04-15 15:49:46 -0700 | [diff] [blame] | 119 | To diagnose the cause of the stall, inspect the stack traces. |
| 120 | The offending function will usually be near the top of the stack. |
| 121 | If you have a series of stall warnings from a single extended stall, |
| 122 | comparing the stack traces can often help determine where the stall |
| 123 | is occurring, which will usually be in the function nearest the top of |
| 124 | that portion of the stack which remains the same from trace to trace. |
| 125 | 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] | 126 | |
| 127 | RCU bugs can often be debugged with the help of CONFIG_RCU_TRACE. |