Skip to content

Commit f262af3

Browse files
committed
Merge branch 'core-rcu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip
* 'core-rcu-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/linux-2.6-tip: (24 commits) rcu: remove all rcu head initializations, except on_stack initializations rcu head introduce rcu head init on stack Debugobjects transition check rcu: fix build bug in RCU_FAST_NO_HZ builds rcu: RCU_FAST_NO_HZ must check RCU dyntick state rcu: make SRCU usable in modules rcu: improve the RCU CPU-stall warning documentation rcu: reduce the number of spurious RCU_SOFTIRQ invocations rcu: permit discontiguous cpu_possible_mask CPU numbering rcu: improve RCU CPU stall-warning messages rcu: print boot-time console messages if RCU configs out of ordinary rcu: disable CPU stall warnings upon panic rcu: enable CPU_STALL_VERBOSE by default rcu: slim down rcutiny by removing rcu_scheduler_active and friends rcu: refactor RCU's context-switch handling rcu: rename rcutiny rcu_ctrlblk to rcu_sched_ctrlblk rcu: shrink rcutiny by making synchronize_rcu_bh() be inline rcu: fix now-bogus rcu_scheduler_active comments. rcu: Fix bogus CONFIG_PROVE_LOCKING in comments to reflect reality. rcu: ignore offline CPUs in last non-dyntick-idle CPU check ...
2 parents 1014cfe + 72d5a9f commit f262af3

21 files changed

Lines changed: 470 additions & 143 deletions

‎Documentation/RCU/stallwarn.txt‎

Lines changed: 71 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,104 @@ Using RCU's CPU Stall Detector
33
The CONFIG_RCU_CPU_STALL_DETECTOR kernel config parameter enables
44
RCU's CPU stall detector, which detects conditions that unduly delay
55
RCU grace periods. The stall detector's idea of what constitutes
6-
"unduly delayed" is controlled by a pair of C preprocessor macros:
6+
"unduly delayed" is controlled by a set of C preprocessor macros:
77

88
RCU_SECONDS_TILL_STALL_CHECK
99

1010
This macro defines the period of time that RCU will wait from
1111
the beginning of a grace period until it issues an RCU CPU
12-
stall warning. It is normally ten seconds.
12+
stall warning. This time period is normally ten seconds.
1313

1414
RCU_SECONDS_TILL_STALL_RECHECK
1515

1616
This macro defines the period of time that RCU will wait after
17-
issuing a stall warning until it issues another stall warning.
18-
It is normally set to thirty seconds.
17+
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.
1920

2021
RCU_STALL_RAT_DELAY
2122

22-
The CPU stall detector tries to make the offending CPU rat on itself,
23-
as this often gives better-quality stack traces. However, if
24-
the offending CPU does not detect its own stall in the number
25-
of jiffies specified by RCU_STALL_RAT_DELAY, then other CPUs will
26-
complain. This is normally set to two jiffies.
23+
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.
2729

28-
The following problems can result in an RCU CPU stall warning:
30+
When a CPU detects that it is stalling, it will print a message similar
31+
to the following:
32+
33+
INFO: rcu_sched_state detected stall on CPU 5 (t=2500 jiffies)
34+
35+
This message indicates that CPU 5 detected that it was causing a stall,
36+
and that the stall was affecting RCU-sched. This message will normally be
37+
followed by a stack dump of the offending CPU. On TREE_RCU kernel builds,
38+
RCU and RCU-sched are implemented by the same underlying mechanism,
39+
while on TREE_PREEMPT_RCU kernel builds, RCU is instead implemented
40+
by rcu_preempt_state.
41+
42+
On the other hand, if the offending CPU fails to print out a stall-warning
43+
message quickly enough, some other CPU will print a message similar to
44+
the following:
45+
46+
INFO: rcu_bh_state detected stalls on CPUs/tasks: { 3 5 } (detected by 2, 2502 jiffies)
47+
48+
This message indicates that CPU 2 detected that CPUs 3 and 5 were both
49+
causing stalls, and that the stall was affecting RCU-bh. This message
50+
will normally be followed by stack dumps for each CPU. Please note that
51+
TREE_PREEMPT_RCU builds can be stalled by tasks as well as by CPUs,
52+
and that the tasks will be indicated by PID, for example, "P3421".
53+
It is even possible for a rcu_preempt_state stall to be caused by both
54+
CPUs -and- tasks, in which case the offending CPUs and tasks will all
55+
be called out in the list.
56+
57+
Finally, if the grace period ends just as the stall warning starts
58+
printing, there will be a spurious stall-warning message:
59+
60+
INFO: rcu_bh_state detected stalls on CPUs/tasks: { } (detected by 4, 2502 jiffies)
61+
62+
This is rare, but does happen from time to time in real life.
63+
64+
So 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
66+
warnings:
2967

3068
o A CPU looping in an RCU read-side critical section.
3169

32-
o A CPU looping with interrupts disabled.
70+
o A CPU looping with interrupts disabled. This condition can
71+
result in RCU-sched and RCU-bh stalls.
3372

34-
o A CPU looping with preemption disabled.
73+
o 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+
77+
o A CPU looping with bottom halves disabled. This condition can
78+
result in RCU-sched and RCU-bh stalls.
3579

3680
o For !CONFIG_PREEMPT kernels, a CPU looping anywhere in the kernel
3781
without invoking schedule().
3882

3983
o A bug in the RCU implementation.
4084

4185
o A hardware failure. This is quite unlikely, but has occurred
42-
at least once in a former life. A CPU failed in a running system,
86+
at least once in real life. A CPU failed in a running system,
4387
becoming unresponsive, but not causing an immediate crash.
4488
This resulted in a series of RCU CPU stall warnings, eventually
4589
leading the realization that the CPU had failed.
4690

47-
The RCU, RCU-sched, and RCU-bh implementations have CPU stall warning.
48-
SRCU does not do so directly, but its calls to synchronize_sched() will
49-
result in RCU-sched detecting any CPU stalls that might be occurring.
50-
51-
To diagnose the cause of the stall, inspect the stack traces. The offending
52-
function will usually be near the top of the stack. If you have a series
53-
of stall warnings from a single extended stall, comparing the stack traces
54-
can often help determine where the stall is occurring, which will usually
55-
be in the function nearest the top of the stack that stays the same from
56-
trace to trace.
91+
The RCU, RCU-sched, and RCU-bh implementations have CPU stall
92+
warning. SRCU does not have its own CPU stall warnings, but its
93+
calls to synchronize_sched() will result in RCU-sched detecting
94+
RCU-sched-related CPU stalls. Please note that RCU only detects
95+
CPU stalls when there is a grace period in progress. No grace period,
96+
no CPU stall warnings.
97+
98+
To diagnose the cause of the stall, inspect the stack traces.
99+
The offending function will usually be near the top of the stack.
100+
If you have a series of stall warnings from a single extended stall,
101+
comparing the stack traces can often help determine where the stall
102+
is occurring, which will usually be in the function nearest the top of
103+
that portion of the stack which remains the same from trace to trace.
104+
If you can reliably trigger the stall, ftrace can be quite helpful.
57105

58106
RCU bugs can often be debugged with the help of CONFIG_RCU_TRACE.

‎Documentation/RCU/trace.txt‎

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -256,23 +256,23 @@ o Each element of the form "1/1 0:127 ^0" represents one struct
256256
The output of "cat rcu/rcu_pending" looks as follows:
257257

258258
rcu_sched:
259-
0 np=255892 qsp=53936 cbr=0 cng=14417 gpc=10033 gps=24320 nf=6445 nn=146741
260-
1 np=261224 qsp=54638 cbr=0 cng=25723 gpc=16310 gps=2849 nf=5912 nn=155792
261-
2 np=237496 qsp=49664 cbr=0 cng=2762 gpc=45478 gps=1762 nf=1201 nn=136629
262-
3 np=236249 qsp=48766 cbr=0 cng=286 gpc=48049 gps=1218 nf=207 nn=137723
263-
4 np=221310 qsp=46850 cbr=0 cng=26 gpc=43161 gps=4634 nf=3529 nn=123110
264-
5 np=237332 qsp=48449 cbr=0 cng=54 gpc=47920 gps=3252 nf=201 nn=137456
265-
6 np=219995 qsp=46718 cbr=0 cng=50 gpc=42098 gps=6093 nf=4202 nn=120834
266-
7 np=249893 qsp=49390 cbr=0 cng=72 gpc=38400 gps=17102 nf=41 nn=144888
259+
0 np=255892 qsp=53936 rpq=85 cbr=0 cng=14417 gpc=10033 gps=24320 nf=6445 nn=146741
260+
1 np=261224 qsp=54638 rpq=33 cbr=0 cng=25723 gpc=16310 gps=2849 nf=5912 nn=155792
261+
2 np=237496 qsp=49664 rpq=23 cbr=0 cng=2762 gpc=45478 gps=1762 nf=1201 nn=136629
262+
3 np=236249 qsp=48766 rpq=98 cbr=0 cng=286 gpc=48049 gps=1218 nf=207 nn=137723
263+
4 np=221310 qsp=46850 rpq=7 cbr=0 cng=26 gpc=43161 gps=4634 nf=3529 nn=123110
264+
5 np=237332 qsp=48449 rpq=9 cbr=0 cng=54 gpc=47920 gps=3252 nf=201 nn=137456
265+
6 np=219995 qsp=46718 rpq=12 cbr=0 cng=50 gpc=42098 gps=6093 nf=4202 nn=120834
266+
7 np=249893 qsp=49390 rpq=42 cbr=0 cng=72 gpc=38400 gps=17102 nf=41 nn=144888
267267
rcu_bh:
268-
0 np=146741 qsp=1419 cbr=0 cng=6 gpc=0 gps=0 nf=2 nn=145314
269-
1 np=155792 qsp=12597 cbr=0 cng=0 gpc=4 gps=8 nf=3 nn=143180
270-
2 np=136629 qsp=18680 cbr=0 cng=0 gpc=7 gps=6 nf=0 nn=117936
271-
3 np=137723 qsp=2843 cbr=0 cng=0 gpc=10 gps=7 nf=0 nn=134863
272-
4 np=123110 qsp=12433 cbr=0 cng=0 gpc=4 gps=2 nf=0 nn=110671
273-
5 np=137456 qsp=4210 cbr=0 cng=0 gpc=6 gps=5 nf=0 nn=133235
274-
6 np=120834 qsp=9902 cbr=0 cng=0 gpc=6 gps=3 nf=2 nn=110921
275-
7 np=144888 qsp=26336 cbr=0 cng=0 gpc=8 gps=2 nf=0 nn=118542
268+
0 np=146741 qsp=1419 rpq=6 cbr=0 cng=6 gpc=0 gps=0 nf=2 nn=145314
269+
1 np=155792 qsp=12597 rpq=3 cbr=0 cng=0 gpc=4 gps=8 nf=3 nn=143180
270+
2 np=136629 qsp=18680 rpq=1 cbr=0 cng=0 gpc=7 gps=6 nf=0 nn=117936
271+
3 np=137723 qsp=2843 rpq=0 cbr=0 cng=0 gpc=10 gps=7 nf=0 nn=134863
272+
4 np=123110 qsp=12433 rpq=0 cbr=0 cng=0 gpc=4 gps=2 nf=0 nn=110671
273+
5 np=137456 qsp=4210 rpq=1 cbr=0 cng=0 gpc=6 gps=5 nf=0 nn=133235
274+
6 np=120834 qsp=9902 rpq=2 cbr=0 cng=0 gpc=6 gps=3 nf=2 nn=110921
275+
7 np=144888 qsp=26336 rpq=0 cbr=0 cng=0 gpc=8 gps=2 nf=0 nn=118542
276276

277277
As always, this is once again split into "rcu_sched" and "rcu_bh"
278278
portions, with CONFIG_TREE_PREEMPT_RCU kernels having an additional
@@ -284,6 +284,9 @@ o "np" is the number of times that __rcu_pending() has been invoked
284284
o "qsp" is the number of times that the RCU was waiting for a
285285
quiescent state from this CPU.
286286

287+
o "rpq" is the number of times that the CPU had passed through
288+
a quiescent state, but not yet reported it to RCU.
289+
287290
o "cbr" is the number of times that this CPU had RCU callbacks
288291
that had passed through a grace period, and were thus ready
289292
to be invoked.

‎include/linux/debugobjects.h‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ struct debug_obj_descr;
2020
* struct debug_obj - representaion of an tracked object
2121
* @node: hlist node to link the object into the tracker list
2222
* @state: tracked object state
23+
* @astate: current active state
2324
* @object: pointer to the real object
2425
* @descr: pointer to an object type specific debug description structure
2526
*/
2627
struct debug_obj {
2728
struct hlist_node node;
2829
enum debug_obj_state state;
30+
unsigned int astate;
2931
void *object;
3032
struct debug_obj_descr *descr;
3133
};
@@ -60,6 +62,15 @@ extern void debug_object_deactivate(void *addr, struct debug_obj_descr *descr);
6062
extern void debug_object_destroy (void *addr, struct debug_obj_descr *descr);
6163
extern void debug_object_free (void *addr, struct debug_obj_descr *descr);
6264

65+
/*
66+
* Active state:
67+
* - Set at 0 upon initialization.
68+
* - Must return to 0 before deactivation.
69+
*/
70+
extern void
71+
debug_object_active_state(void *addr, struct debug_obj_descr *descr,
72+
unsigned int expect, unsigned int next);
73+
6374
extern void debug_objects_early_init(void);
6475
extern void debug_objects_mem_init(void);
6576
#else

‎include/linux/init_task.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ extern struct group_info init_groups;
4949
{ .first = &init_task.pids[PIDTYPE_PGID].node }, \
5050
{ .first = &init_task.pids[PIDTYPE_SID].node }, \
5151
}, \
52-
.rcu = RCU_HEAD_INIT, \
5352
.level = 0, \
5453
.numbers = { { \
5554
.nr = 0, \

‎include/linux/rcupdate.h‎

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ struct rcu_head {
5656
};
5757

5858
/* Exported common interfaces */
59-
extern void synchronize_rcu_bh(void);
60-
extern void synchronize_sched(void);
6159
extern void rcu_barrier(void);
6260
extern void rcu_barrier_bh(void);
6361
extern void rcu_barrier_sched(void);
@@ -66,8 +64,6 @@ extern int sched_expedited_torture_stats(char *page);
6664

6765
/* Internal to kernel */
6866
extern void rcu_init(void);
69-
extern int rcu_scheduler_active;
70-
extern void rcu_scheduler_starting(void);
7167

7268
#if defined(CONFIG_TREE_RCU) || defined(CONFIG_TREE_PREEMPT_RCU)
7369
#include <linux/rcutree.h>
@@ -83,6 +79,14 @@ extern void rcu_scheduler_starting(void);
8379
(ptr)->next = NULL; (ptr)->func = NULL; \
8480
} while (0)
8581

82+
static inline void init_rcu_head_on_stack(struct rcu_head *head)
83+
{
84+
}
85+
86+
static inline void destroy_rcu_head_on_stack(struct rcu_head *head)
87+
{
88+
}
89+
8690
#ifdef CONFIG_DEBUG_LOCK_ALLOC
8791

8892
extern struct lockdep_map rcu_lock_map;
@@ -106,12 +110,13 @@ extern int debug_lockdep_rcu_enabled(void);
106110
/**
107111
* rcu_read_lock_held - might we be in RCU read-side critical section?
108112
*
109-
* If CONFIG_PROVE_LOCKING is selected and enabled, returns nonzero iff in
110-
* an RCU read-side critical section. In absence of CONFIG_PROVE_LOCKING,
113+
* If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an RCU
114+
* read-side critical section. In absence of CONFIG_DEBUG_LOCK_ALLOC,
111115
* this assumes we are in an RCU read-side critical section unless it can
112116
* prove otherwise.
113117
*
114-
* Check rcu_scheduler_active to prevent false positives during boot.
118+
* Check debug_lockdep_rcu_enabled() to prevent false positives during boot
119+
* and while lockdep is disabled.
115120
*/
116121
static inline int rcu_read_lock_held(void)
117122
{
@@ -129,13 +134,15 @@ extern int rcu_read_lock_bh_held(void);
129134
/**
130135
* rcu_read_lock_sched_held - might we be in RCU-sched read-side critical section?
131136
*
132-
* If CONFIG_PROVE_LOCKING is selected and enabled, returns nonzero iff in an
133-
* RCU-sched read-side critical section. In absence of CONFIG_PROVE_LOCKING,
134-
* this assumes we are in an RCU-sched read-side critical section unless it
135-
* can prove otherwise. Note that disabling of preemption (including
136-
* disabling irqs) counts as an RCU-sched read-side critical section.
137+
* If CONFIG_DEBUG_LOCK_ALLOC is selected, returns nonzero iff in an
138+
* RCU-sched read-side critical section. In absence of
139+
* CONFIG_DEBUG_LOCK_ALLOC, this assumes we are in an RCU-sched read-side
140+
* critical section unless it can prove otherwise. Note that disabling
141+
* of preemption (including disabling irqs) counts as an RCU-sched
142+
* read-side critical section.
137143
*
138-
* Check rcu_scheduler_active to prevent false positives during boot.
144+
* Check debug_lockdep_rcu_enabled() to prevent false positives during boot
145+
* and while lockdep is disabled.
139146
*/
140147
#ifdef CONFIG_PREEMPT
141148
static inline int rcu_read_lock_sched_held(void)
@@ -177,7 +184,7 @@ static inline int rcu_read_lock_bh_held(void)
177184
#ifdef CONFIG_PREEMPT
178185
static inline int rcu_read_lock_sched_held(void)
179186
{
180-
return !rcu_scheduler_active || preempt_count() != 0 || irqs_disabled();
187+
return preempt_count() != 0 || irqs_disabled();
181188
}
182189
#else /* #ifdef CONFIG_PREEMPT */
183190
static inline int rcu_read_lock_sched_held(void)
@@ -192,6 +199,15 @@ static inline int rcu_read_lock_sched_held(void)
192199

193200
extern int rcu_my_thread_group_empty(void);
194201

202+
#define __do_rcu_dereference_check(c) \
203+
do { \
204+
static bool __warned; \
205+
if (debug_lockdep_rcu_enabled() && !__warned && !(c)) { \
206+
__warned = true; \
207+
lockdep_rcu_dereference(__FILE__, __LINE__); \
208+
} \
209+
} while (0)
210+
195211
/**
196212
* rcu_dereference_check - rcu_dereference with debug checking
197213
* @p: The pointer to read, prior to dereferencing
@@ -221,8 +237,7 @@ extern int rcu_my_thread_group_empty(void);
221237
*/
222238
#define rcu_dereference_check(p, c) \
223239
({ \
224-
if (debug_lockdep_rcu_enabled() && !(c)) \
225-
lockdep_rcu_dereference(__FILE__, __LINE__); \
240+
__do_rcu_dereference_check(c); \
226241
rcu_dereference_raw(p); \
227242
})
228243

@@ -239,8 +254,7 @@ extern int rcu_my_thread_group_empty(void);
239254
*/
240255
#define rcu_dereference_protected(p, c) \
241256
({ \
242-
if (debug_lockdep_rcu_enabled() && !(c)) \
243-
lockdep_rcu_dereference(__FILE__, __LINE__); \
257+
__do_rcu_dereference_check(c); \
244258
(p); \
245259
})
246260

‎include/linux/rcutiny.h‎

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929

3030
void rcu_sched_qs(int cpu);
3131
void rcu_bh_qs(int cpu);
32+
static inline void rcu_note_context_switch(int cpu)
33+
{
34+
rcu_sched_qs(cpu);
35+
}
3236

3337
#define __rcu_read_lock() preempt_disable()
3438
#define __rcu_read_unlock() preempt_enable()
@@ -74,7 +78,17 @@ static inline void rcu_sched_force_quiescent_state(void)
7478
{
7579
}
7680

77-
#define synchronize_rcu synchronize_sched
81+
extern void synchronize_sched(void);
82+
83+
static inline void synchronize_rcu(void)
84+
{
85+
synchronize_sched();
86+
}
87+
88+
static inline void synchronize_rcu_bh(void)
89+
{
90+
synchronize_sched();
91+
}
7892

7993
static inline void synchronize_rcu_expedited(void)
8094
{
@@ -114,4 +128,17 @@ static inline int rcu_preempt_depth(void)
114128
return 0;
115129
}
116130

131+
#ifdef CONFIG_DEBUG_LOCK_ALLOC
132+
133+
extern int rcu_scheduler_active __read_mostly;
134+
extern void rcu_scheduler_starting(void);
135+
136+
#else /* #ifdef CONFIG_DEBUG_LOCK_ALLOC */
137+
138+
static inline void rcu_scheduler_starting(void)
139+
{
140+
}
141+
142+
#endif /* #else #ifdef CONFIG_DEBUG_LOCK_ALLOC */
143+
117144
#endif /* __LINUX_RCUTINY_H */

0 commit comments

Comments
 (0)