History

rcu: Move RCU_FAST_NO_HZ per-CPU variables to rcu_dynticks structure

The RCU_FAST_NO_HZ code relies on a number of per-CPU variables. This works, but is hidden from someone scanning the data structures in rcutree.h. This commit therefore converts these per-CPU variables to fields in the per-CPU rcu_dynticks structures.

Paul E. McKenney committed 14 years ago

Commit 5955f7e1 parent fd4b3522 files · +58 −55Browse files

Unified · Split

2 files
  1. kernel/rcutree.h +14 −0
  2. kernel/rcutree_plugin.h +44 −55
kernel/rcutree.h+14−0
@@ -84,6 +84,20 @@ struct rcu_dynticks { · 83 unmodified lines
8484 /* Process level is worth LLONG_MAX/2. */
8585 int dynticks_nmi_nesting; /* Track NMI nesting level. */
8686 atomic_t dynticks; /* Even value for idle, else odd. */
87+#ifdef CONFIG_RCU_FAST_NO_HZ
88+ int dyntick_drain; /* Prepare-for-idle state variable. */
89+ unsigned long dyntick_holdoff;
90+ /* No retries for the jiffy of failure. */
91+ struct timer_list idle_gp_timer;
92+ /* Wake up CPU sleeping with callbacks. */
93+ unsigned long idle_gp_timer_expires;
94+ /* When to wake up CPU (for repost). */
95+ bool idle_first_pass; /* First pass of attempt to go idle? */
96+ unsigned long nonlazy_posted;
97+ /* # times non-lazy CBs posted to CPU. */
98+ unsigned long nonlazy_posted_snap;
99+ /* idle-period nonlazy_posted snapshot. */
100+#endif /* #ifdef CONFIG_RCU_FAST_NO_HZ */
87101 };
88102
89103 /* RCU's kthread states for tracing. */
kernel/rcutree_plugin.h+44−55
@@ -1962,21 +1962,6 @@ static void rcu_idle_count_callbacks_posted(void) · 1961 unmodified lines
19621962 #define RCU_IDLE_GP_DELAY 6 /* Roughly one grace period. */
19631963 #define RCU_IDLE_LAZY_GP_DELAY (6 * HZ) /* Roughly six seconds. */
19641964
1965−/* Loop counter for rcu_prepare_for_idle(). */
1966−static DEFINE_PER_CPU(int, rcu_dyntick_drain);
1967−/* If rcu_dyntick_holdoff==jiffies, don't try to enter dyntick-idle mode. */
1968−static DEFINE_PER_CPU(unsigned long, rcu_dyntick_holdoff);
1969−/* Timer to awaken the CPU if it enters dyntick-idle mode with callbacks. */
1970−static DEFINE_PER_CPU(struct timer_list, rcu_idle_gp_timer);
1971−/* Scheduled expiry time for rcu_idle_gp_timer to allow reposting. */
1972−static DEFINE_PER_CPU(unsigned long, rcu_idle_gp_timer_expires);
1973−/* Enable special processing on first attempt to enter dyntick-idle mode. */
1974−static DEFINE_PER_CPU(bool, rcu_idle_first_pass);
1975−/* Running count of non-lazy callbacks posted, never decremented. */
1976−static DEFINE_PER_CPU(unsigned long, rcu_nonlazy_posted);
1977−/* Snapshot of rcu_nonlazy_posted to detect meaningful exits from idle. */
1978−static DEFINE_PER_CPU(unsigned long, rcu_nonlazy_posted_snap);
1979−
19801965 /*
19811966 * Allow the CPU to enter dyntick-idle mode if either: (1) There are no
19821967 * callbacks on this CPU, (2) this CPU has not yet attempted to enter
@@ -1988,13 +1973,15 @@ static DEFINE_PER_CPU(unsigned long, rcu_nonlazy_posted_snap); · 5 unmodified lines
19881973 */
19891974 int rcu_needs_cpu(int cpu)
19901975 {
1976+ struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu);
1977+
19911978 /* Flag a new idle sojourn to the idle-entry state machine. */
1992− per_cpu(rcu_idle_first_pass, cpu) = 1;
1979+ rdtp->idle_first_pass = 1;
19931980 /* If no callbacks, RCU doesn't need the CPU. */
19941981 if (!rcu_cpu_has_callbacks(cpu))
19951982 return 0;
19961983 /* Otherwise, RCU needs the CPU only if it recently tried and failed. */
1997− return per_cpu(rcu_dyntick_holdoff, cpu) == jiffies;
1984+ return rdtp->dyntick_holdoff == jiffies;
19981985 }
19991986
20001987 /*
@@ -2075,21 +2062,24 @@ static void rcu_idle_gp_timer_func(unsigned long cpu_in) · 74 unmodified lines
20752062 */
20762063 static void rcu_prepare_for_idle_init(int cpu)
20772064 {
2078− per_cpu(rcu_dyntick_holdoff, cpu) = jiffies - 1;
2079− setup_timer(&per_cpu(rcu_idle_gp_timer, cpu),
2080− rcu_idle_gp_timer_func, cpu);
2081− per_cpu(rcu_idle_gp_timer_expires, cpu) = jiffies - 1;
2082− per_cpu(rcu_idle_first_pass, cpu) = 1;
2065+ struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu);
2066+
2067+ rdtp->dyntick_holdoff = jiffies - 1;
2068+ setup_timer(&rdtp->idle_gp_timer, rcu_idle_gp_timer_func, cpu);
2069+ rdtp->idle_gp_timer_expires = jiffies - 1;
2070+ rdtp->idle_first_pass = 1;
20832071 }
20842072
20852073 /*
20862074 * Clean up for exit from idle. Because we are exiting from idle, there
2087− * is no longer any point to rcu_idle_gp_timer, so cancel it. This will
2075+ * is no longer any point to ->idle_gp_timer, so cancel it. This will
20882076 * do nothing if this timer is not active, so just cancel it unconditionally.
20892077 */
20902078 static void rcu_cleanup_after_idle(int cpu)
20912079 {
2092− del_timer(&per_cpu(rcu_idle_gp_timer, cpu));
2080+ struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu);
2081+
2082+ del_timer(&rdtp->idle_gp_timer);
20932083 trace_rcu_prep_idle("Cleanup after idle");
20942084 }
20952085
@@ -2108,42 +2098,41 @@ static void rcu_cleanup_after_idle(int cpu) · 12 unmodified lines
21082098 * Because it is not legal to invoke rcu_process_callbacks() with irqs
21092099 * disabled, we do one pass of force_quiescent_state(), then do a
21102100 * invoke_rcu_core() to cause rcu_process_callbacks() to be invoked
2111− * later. The per-cpu rcu_dyntick_drain variable controls the sequencing.
2101+ * later. The ->dyntick_drain field controls the sequencing.
21122102 *
21132103 * The caller must have disabled interrupts.
21142104 */
21152105 static void rcu_prepare_for_idle(int cpu)
21162106 {
21172107 struct timer_list *tp;
2108+ struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu);
21182109
21192110 /*
21202111 * If this is an idle re-entry, for example, due to use of
21212112 * RCU_NONIDLE() or the new idle-loop tracing API within the idle
21222113 * loop, then don't take any state-machine actions, unless the
21232114 * momentary exit from idle queued additional non-lazy callbacks.
2124− * Instead, repost the rcu_idle_gp_timer if this CPU has callbacks
2115+ * Instead, repost the ->idle_gp_timer if this CPU has callbacks
21252116 * pending.
21262117 */
2127− if (!per_cpu(rcu_idle_first_pass, cpu) &&
2128− (per_cpu(rcu_nonlazy_posted, cpu) ==
2129− per_cpu(rcu_nonlazy_posted_snap, cpu))) {
2118+ if (!rdtp->idle_first_pass &&
2119+ (rdtp->nonlazy_posted == rdtp->nonlazy_posted_snap)) {
21302120 if (rcu_cpu_has_callbacks(cpu)) {
2131− tp = &per_cpu(rcu_idle_gp_timer, cpu);
2132− mod_timer_pinned(tp, per_cpu(rcu_idle_gp_timer_expires, cpu));
2121+ tp = &rdtp->idle_gp_timer;
2122+ mod_timer_pinned(tp, rdtp->idle_gp_timer_expires);
21332123 }
21342124 return;
21352125 }
2136− per_cpu(rcu_idle_first_pass, cpu) = 0;
2137− per_cpu(rcu_nonlazy_posted_snap, cpu) =
2138− per_cpu(rcu_nonlazy_posted, cpu) - 1;
2126+ rdtp->idle_first_pass = 0;
2127+ rdtp->nonlazy_posted_snap = rdtp->nonlazy_posted - 1;
21392128
21402129 /*
21412130 * If there are no callbacks on this CPU, enter dyntick-idle mode.
21422131 * Also reset state to avoid prejudicing later attempts.
21432132 */
21442133 if (!rcu_cpu_has_callbacks(cpu)) {
2145− per_cpu(rcu_dyntick_holdoff, cpu) = jiffies - 1;
2146− per_cpu(rcu_dyntick_drain, cpu) = 0;
2134+ rdtp->dyntick_holdoff = jiffies - 1;
2135+ rdtp->dyntick_drain = 0;
21472136 trace_rcu_prep_idle("No callbacks");
21482137 return;
21492138 }
@@ -2152,38 +2141,37 @@ static void rcu_prepare_for_idle(int cpu) · 2 unmodified lines
21522141 * If in holdoff mode, just return. We will presumably have
21532142 * refrained from disabling the scheduling-clock tick.
21542143 */
2155− if (per_cpu(rcu_dyntick_holdoff, cpu) == jiffies) {
2144+ if (rdtp->dyntick_holdoff == jiffies) {
21562145 trace_rcu_prep_idle("In holdoff");
21572146 return;
21582147 }
21592148
2160− /* Check and update the rcu_dyntick_drain sequencing. */
2161− if (per_cpu(rcu_dyntick_drain, cpu) <= 0) {
2149+ /* Check and update the ->dyntick_drain sequencing. */
2150+ if (rdtp->dyntick_drain <= 0) {
21622151 /* First time through, initialize the counter. */
2163− per_cpu(rcu_dyntick_drain, cpu) = RCU_IDLE_FLUSHES;
2164− } else if (per_cpu(rcu_dyntick_drain, cpu) <= RCU_IDLE_OPT_FLUSHES &&
2152+ rdtp->dyntick_drain = RCU_IDLE_FLUSHES;
2153+ } else if (rdtp->dyntick_drain <= RCU_IDLE_OPT_FLUSHES &&
21652154 !rcu_pending(cpu) &&
21662155 !local_softirq_pending()) {
21672156 /* Can we go dyntick-idle despite still having callbacks? */
2168− per_cpu(rcu_dyntick_drain, cpu) = 0;
2169− per_cpu(rcu_dyntick_holdoff, cpu) = jiffies;
2157+ rdtp->dyntick_drain = 0;
2158+ rdtp->dyntick_holdoff = jiffies;
21702159 if (rcu_cpu_has_nonlazy_callbacks(cpu)) {
21712160 trace_rcu_prep_idle("Dyntick with callbacks");
2172− per_cpu(rcu_idle_gp_timer_expires, cpu) =
2161+ rdtp->idle_gp_timer_expires =
21732162 jiffies + RCU_IDLE_GP_DELAY;
21742163 } else {
2175− per_cpu(rcu_idle_gp_timer_expires, cpu) =
2164+ rdtp->idle_gp_timer_expires =
21762165 jiffies + RCU_IDLE_LAZY_GP_DELAY;
21772166 trace_rcu_prep_idle("Dyntick with lazy callbacks");
21782167 }
2179− tp = &per_cpu(rcu_idle_gp_timer, cpu);
2180− mod_timer_pinned(tp, per_cpu(rcu_idle_gp_timer_expires, cpu));
2181− per_cpu(rcu_nonlazy_posted_snap, cpu) =
2182− per_cpu(rcu_nonlazy_posted, cpu);
2168+ tp = &rdtp->idle_gp_timer;
2169+ mod_timer_pinned(tp, rdtp->idle_gp_timer_expires);
2170+ rdtp->nonlazy_posted_snap = rdtp->nonlazy_posted;
21832171 return; /* Nothing more to do immediately. */
2184− } else if (--per_cpu(rcu_dyntick_drain, cpu) <= 0) {
2172+ } else if (--(rdtp->dyntick_drain) <= 0) {
21852173 /* We have hit the limit, so time to give up. */
2186− per_cpu(rcu_dyntick_holdoff, cpu) = jiffies;
2174+ rdtp->dyntick_holdoff = jiffies;
21872175 trace_rcu_prep_idle("Begin holdoff");
21882176 invoke_rcu_core(); /* Force the CPU out of dyntick-idle. */
21892177 return;
@@ -2229,7 +2217,7 @@ static void rcu_prepare_for_idle(int cpu) · 39 unmodified lines
22292217 */
22302218 static void rcu_idle_count_callbacks_posted(void)
22312219 {
2232− __this_cpu_add(rcu_nonlazy_posted, 1);
2220+ __this_cpu_add(rcu_dynticks.nonlazy_posted, 1);
22332221 }
22342222
22352223 #endif /* #else #if !defined(CONFIG_RCU_FAST_NO_HZ) */
@@ -2240,11 +2228,12 @@ static void rcu_idle_count_callbacks_posted(void) · 4 unmodified lines
22402228
22412229 static void print_cpu_stall_fast_no_hz(char *cp, int cpu)
22422230 {
2243− struct timer_list *tltp = &per_cpu(rcu_idle_gp_timer, cpu);
2231+ struct rcu_dynticks *rdtp = &per_cpu(rcu_dynticks, cpu);
2232+ struct timer_list *tltp = &rdtp->idle_gp_timer;
22442233
22452234 sprintf(cp, "drain=%d %c timer=%lu",
2246− per_cpu(rcu_dyntick_drain, cpu),
2247− per_cpu(rcu_dyntick_holdoff, cpu) == jiffies ? 'H' : '.',
2235+ rdtp->dyntick_drain,
2236+ rdtp->dyntick_holdoff == jiffies ? 'H' : '.',
22482237 timer_pending(tltp) ? tltp->expires - jiffies : -1);
22492238 }
22502239

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t