4444#include <linux/debugobjects.h>
4545#include <linux/bug.h>
4646#include <linux/compiler.h>
47+ #include <linux/percpu.h>
4748#include <asm/barrier.h>
4849
4950extern int rcu_expedited ; /* for sysctl */
5051#ifdef CONFIG_RCU_TORTURE_TEST
5152extern int rcutorture_runnable ; /* for sysctl */
5253#endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
5354
55+ enum rcutorture_type {
56+ RCU_FLAVOR ,
57+ RCU_BH_FLAVOR ,
58+ RCU_SCHED_FLAVOR ,
59+ SRCU_FLAVOR ,
60+ INVALID_RCU_FLAVOR
61+ };
62+
5463#if defined(CONFIG_TREE_RCU ) || defined(CONFIG_TREE_PREEMPT_RCU )
64+ void rcutorture_get_gp_data (enum rcutorture_type test_type , int * flags ,
65+ unsigned long * gpnum , unsigned long * completed );
5566void rcutorture_record_test_transition (void );
5667void rcutorture_record_progress (unsigned long vernum );
5768void do_trace_rcu_torture_read (const char * rcutorturename ,
@@ -60,6 +71,15 @@ void do_trace_rcu_torture_read(const char *rcutorturename,
6071 unsigned long c_old ,
6172 unsigned long c );
6273#else
74+ static inline void rcutorture_get_gp_data (enum rcutorture_type test_type ,
75+ int * flags ,
76+ unsigned long * gpnum ,
77+ unsigned long * completed )
78+ {
79+ * flags = 0 ;
80+ * gpnum = 0 ;
81+ * completed = 0 ;
82+ }
6383static inline void rcutorture_record_test_transition (void )
6484{
6585}
@@ -267,6 +287,41 @@ static inline void rcu_user_hooks_switch(struct task_struct *prev,
267287bool __rcu_is_watching (void );
268288#endif /* #if defined(CONFIG_DEBUG_LOCK_ALLOC) || defined(CONFIG_RCU_TRACE) || defined(CONFIG_SMP) */
269289
290+ /*
291+ * Hooks for cond_resched() and friends to avoid RCU CPU stall warnings.
292+ */
293+
294+ #define RCU_COND_RESCHED_LIM 256 /* ms vs. 100s of ms. */
295+ DECLARE_PER_CPU (int , rcu_cond_resched_count );
296+ void rcu_resched (void );
297+
298+ /*
299+ * Is it time to report RCU quiescent states?
300+ *
301+ * Note unsynchronized access to rcu_cond_resched_count. Yes, we might
302+ * increment some random CPU's count, and possibly also load the result from
303+ * yet another CPU's count. We might even clobber some other CPU's attempt
304+ * to zero its counter. This is all OK because the goal is not precision,
305+ * but rather reasonable amortization of rcu_note_context_switch() overhead
306+ * and extremely high probability of avoiding RCU CPU stall warnings.
307+ * Note that this function has to be preempted in just the wrong place,
308+ * many thousands of times in a row, for anything bad to happen.
309+ */
310+ static inline bool rcu_should_resched (void )
311+ {
312+ return raw_cpu_inc_return (rcu_cond_resched_count ) >=
313+ RCU_COND_RESCHED_LIM ;
314+ }
315+
316+ /*
317+ * Report quiscent states to RCU if it is time to do so.
318+ */
319+ static inline void rcu_cond_resched (void )
320+ {
321+ if (unlikely (rcu_should_resched ()))
322+ rcu_resched ();
323+ }
324+
270325/*
271326 * Infrastructure to implement the synchronize_() primitives in
272327 * TREE_RCU and rcu_barrier_() primitives in TINY_RCU.
@@ -328,7 +383,7 @@ extern struct lockdep_map rcu_lock_map;
328383extern struct lockdep_map rcu_bh_lock_map ;
329384extern struct lockdep_map rcu_sched_lock_map ;
330385extern struct lockdep_map rcu_callback_map ;
331- extern int debug_lockdep_rcu_enabled (void );
386+ int debug_lockdep_rcu_enabled (void );
332387
333388/**
334389 * rcu_read_lock_held() - might we be in RCU read-side critical section?
@@ -949,6 +1004,9 @@ static inline notrace void rcu_read_unlock_sched_notrace(void)
9491004 * pointers, but you must use rcu_assign_pointer() to initialize the
9501005 * external-to-structure pointer -after- you have completely initialized
9511006 * the reader-accessible portions of the linked structure.
1007+ *
1008+ * Note that unlike rcu_assign_pointer(), RCU_INIT_POINTER() provides no
1009+ * ordering guarantees for either the CPU or the compiler.
9521010 */
9531011#define RCU_INIT_POINTER (p , v ) \
9541012 do { \
0 commit comments