blob: 862c08ef1fde4436ddac8010ba4a1aae40328719 [file] [log] [blame]
Paul E. McKenney4c540052010-01-14 16:10:57 -08001Using RCU's CPU Stall Detector
2
3The CONFIG_RCU_CPU_STALL_DETECTOR kernel config parameter enables
4RCU's CPU stall detector, which detects conditions that unduly delay
5RCU grace periods. The stall detector's idea of what constitutes
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -07006"unduly delayed" is controlled by a set of C preprocessor macros:
Paul E. McKenney4c540052010-01-14 16:10:57 -08007
8RCU_SECONDS_TILL_STALL_CHECK
9
10 This macro defines the period of time that RCU will wait from
11 the beginning of a grace period until it issues an RCU CPU
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -070012 stall warning. This time period is normally ten seconds.
Paul E. McKenney4c540052010-01-14 16:10:57 -080013
14RCU_SECONDS_TILL_STALL_RECHECK
15
16 This macro defines the period of time that RCU will wait after
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -070017 issuing a stall warning until it issues another stall warning
18 for the same stall. This time period is normally set to thirty
19 seconds.
Paul E. McKenney4c540052010-01-14 16:10:57 -080020
21RCU_STALL_RAT_DELAY
22
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -070023 The CPU stall detector tries to make the offending CPU print its
24 own warnings, as this often gives better-quality stack traces.
25 However, if the offending CPU does not detect its own stall in
26 the number of jiffies specified by RCU_STALL_RAT_DELAY, then
27 some other CPU will complain. This delay is normally set to
28 two jiffies.
Paul E. McKenney4c540052010-01-14 16:10:57 -080029
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -070030When a CPU detects that it is stalling, it will print a message similar
31to the following:
32
33INFO: rcu_sched_state detected stall on CPU 5 (t=2500 jiffies)
34
35This message indicates that CPU 5 detected that it was causing a stall,
36and that the stall was affecting RCU-sched. This message will normally be
37followed by a stack dump of the offending CPU. On TREE_RCU kernel builds,
38RCU and RCU-sched are implemented by the same underlying mechanism,
39while on TREE_PREEMPT_RCU kernel builds, RCU is instead implemented
40by rcu_preempt_state.
41
42On the other hand, if the offending CPU fails to print out a stall-warning
43message quickly enough, some other CPU will print a message similar to
44the following:
45
46INFO: rcu_bh_state detected stalls on CPUs/tasks: { 3 5 } (detected by 2, 2502 jiffies)
47
48This message indicates that CPU 2 detected that CPUs 3 and 5 were both
49causing stalls, and that the stall was affecting RCU-bh. This message
50will normally be followed by stack dumps for each CPU. Please note that
51TREE_PREEMPT_RCU builds can be stalled by tasks as well as by CPUs,
52and that the tasks will be indicated by PID, for example, "P3421".
53It is even possible for a rcu_preempt_state stall to be caused by both
54CPUs -and- tasks, in which case the offending CPUs and tasks will all
55be called out in the list.
56
57Finally, if the grace period ends just as the stall warning starts
58printing, there will be a spurious stall-warning message:
59
60INFO: rcu_bh_state detected stalls on CPUs/tasks: { } (detected by 4, 2502 jiffies)
61
62This is rare, but does happen from time to time in real life.
63
64So your kernel printed an RCU CPU stall warning. The next question is
65"What caused it?" The following problems can result in RCU CPU stall
66warnings:
Paul E. McKenney4c540052010-01-14 16:10:57 -080067
68o A CPU looping in an RCU read-side critical section.
69
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -070070o A CPU looping with interrupts disabled. This condition can
71 result in RCU-sched and RCU-bh stalls.
Paul E. McKenney4c540052010-01-14 16:10:57 -080072
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -070073o A CPU looping with preemption disabled. This condition can
74 result in RCU-sched stalls and, if ksoftirqd is in use, RCU-bh
75 stalls.
76
77o A CPU looping with bottom halves disabled. This condition can
78 result in RCU-sched and RCU-bh stalls.
Paul E. McKenney4c540052010-01-14 16:10:57 -080079
80o For !CONFIG_PREEMPT kernels, a CPU looping anywhere in the kernel
81 without invoking schedule().
82
Paul E. McKenney2c96c772010-08-23 16:34:02 -070083o A CPU-bound real-time task in a CONFIG_PREEMPT kernel, which might
84 happen to preempt a low-priority task in the middle of an RCU
85 read-side critical section. This is especially damaging if
86 that low-priority task is not permitted to run on any other CPU,
87 in which case the next RCU grace period can never complete, which
88 will eventually cause the system to run out of memory and hang.
89 While the system is in the process of running itself out of
90 memory, you might see stall-warning messages.
91
92o A CPU-bound real-time task in a CONFIG_PREEMPT_RT kernel that
93 is running at a higher priority than the RCU softirq threads.
94 This will prevent RCU callbacks from ever being invoked,
95 and in a CONFIG_TREE_PREEMPT_RCU kernel will further prevent
96 RCU grace periods from ever completing. Either way, the
97 system will eventually run out of memory and hang. In the
98 CONFIG_TREE_PREEMPT_RCU case, you might see stall-warning
99 messages.
100
Paul E. McKenney4c540052010-01-14 16:10:57 -0800101o A bug in the RCU implementation.
102
103o A hardware failure. This is quite unlikely, but has occurred
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -0700104 at least once in real life. A CPU failed in a running system,
Paul E. McKenney4c540052010-01-14 16:10:57 -0800105 becoming unresponsive, but not causing an immediate crash.
106 This resulted in a series of RCU CPU stall warnings, eventually
107 leading the realization that the CPU had failed.
108
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -0700109The RCU, RCU-sched, and RCU-bh implementations have CPU stall
110warning. SRCU does not have its own CPU stall warnings, but its
111calls to synchronize_sched() will result in RCU-sched detecting
112RCU-sched-related CPU stalls. Please note that RCU only detects
113CPU stalls when there is a grace period in progress. No grace period,
114no CPU stall warnings.
Paul E. McKenney4c540052010-01-14 16:10:57 -0800115
Paul E. McKenneyf1d507b2010-04-15 15:49:46 -0700116To diagnose the cause of the stall, inspect the stack traces.
117The offending function will usually be near the top of the stack.
118If you have a series of stall warnings from a single extended stall,
119comparing the stack traces can often help determine where the stall
120is occurring, which will usually be in the function nearest the top of
121that portion of the stack which remains the same from trace to trace.
122If you can reliably trigger the stall, ftrace can be quite helpful.
Paul E. McKenney4c540052010-01-14 16:10:57 -0800123
124RCU bugs can often be debugged with the help of CONFIG_RCU_TRACE.