aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/rcu
diff options
context:
space:
mode:
authorPaul E. McKenney <paulmck@linux.vnet.ibm.com>2014-03-11 16:02:16 -0400
committerPaul E. McKenney <paulmck@linux.vnet.ibm.com>2014-04-29 11:44:07 -0400
commit48a7639ce80cf279834d0d44865e49ecd714f37d (patch)
tree78ef128affd547e83363a6e2258b915fb0c73ab4 /kernel/rcu
parent4fc5b75537d4f56577ad00355b4cd09627deb3c3 (diff)
rcu: Make callers awaken grace-period kthread
The rcu_start_gp_advanced() function currently uses irq_work_queue() to defer wakeups of the RCU grace-period kthread. This deferring is necessary to avoid RCU-scheduler deadlocks involving the rcu_node structure's lock, meaning that RCU cannot call any of the scheduler's wake-up functions while holding one of these locks. Unfortunately, the second and subsequent calls to irq_work_queue() are ignored, and the first call will be ignored (aside from queuing the work item) if the scheduler-clock tick is turned off. This is OK for many uses, especially those where irq_work_queue() is called from an interrupt or softirq handler, because in those cases the scheduler-clock-tick state will be re-evaluated, which will turn the scheduler-clock tick back on. On the next tick, any deferred work will then be processed. However, this strategy does not always work for RCU, which can be invoked at process level from idle CPUs. In this case, the tick might never be turned back on, indefinitely defering a grace-period start request. Note that the RCU CPU stall detector cannot see this condition, because there is no RCU grace period in progress. Therefore, we can (and do!) see long tens-of-seconds stalls in grace-period handling. In theory, we could see a full grace-period hang, but rcutorture testing to date has seen only the tens-of-seconds stalls. Event tracing demonstrates that irq_work_queue() is being called repeatedly to no effect during these stalls: The "newreq" event appears repeatedly from a task that is not one of the grace-period kthreads. In theory, irq_work_queue() might be fixed to avoid this sort of issue, but RCU's requirements are unusual and it is quite straightforward to pass wake-up responsibility up through RCU's call chain, so that the wakeup happens when the offending locks are released. This commit therefore makes this change. The rcu_start_gp_advanced(), rcu_start_future_gp(), rcu_accelerate_cbs(), rcu_advance_cbs(), __note_gp_changes(), and rcu_start_gp() functions now return a boolean which indicates when a wake-up is needed. A new rcu_gp_kthread_wake() does the wakeup when it is necessary and safe to do so: No self-wakes, no wake-ups if the ->gp_flags field indicates there is no need (as in someone else did the wake-up before we got around to it), and no wake-ups before the grace-period kthread has been created. Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Steven Rostedt <rostedt@goodmis.org> Cc: Frederic Weisbecker <fweisbec@gmail.com> Reviewed-by: Josh Triplett <josh@joshtriplett.org>
Diffstat (limited to 'kernel/rcu')
-rw-r--r--kernel/rcu/tree.c137
-rw-r--r--kernel/rcu/tree.h1
-rw-r--r--kernel/rcu/tree_plugin.h10
3 files changed, 94 insertions, 54 deletions
diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index c624415f8386..fca911b6b29c 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -243,7 +243,7 @@ static ulong jiffies_till_next_fqs = ULONG_MAX;
243module_param(jiffies_till_first_fqs, ulong, 0644); 243module_param(jiffies_till_first_fqs, ulong, 0644);
244module_param(jiffies_till_next_fqs, ulong, 0644); 244module_param(jiffies_till_next_fqs, ulong, 0644);
245 245
246static void rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp, 246static bool rcu_start_gp_advanced(struct rcu_state *rsp, struct rcu_node *rnp,
247 struct rcu_data *rdp); 247 struct rcu_data *rdp);
248static void force_qs_rnp(struct rcu_state *rsp, 248static void force_qs_rnp(struct rcu_state *rsp,
249 int (*f)(struct rcu_data *rsp, bool *isidle, 249 int (*f)(struct rcu_data *rsp, bool *isidle,
@@ -1138,15 +1138,18 @@ static void trace_rcu_future_gp(struct rcu_node *rnp, struct rcu_data *rdp,
1138/* 1138/*
1139 * Start some future grace period, as needed to handle newly arrived 1139 * Start some future grace period, as needed to handle newly arrived
1140 * callbacks. The required future grace periods are recorded in each 1140 * callbacks. The required future grace periods are recorded in each
1141 * rcu_node structure's ->need_future_gp field. 1141 * rcu_node structure's ->need_future_gp field. Returns true if there
1142 * is reason to awaken the grace-period kthread.
1142 * 1143 *
1143 * The caller must hold the specified rcu_node structure's ->lock. 1144 * The caller must hold the specified rcu_node structure's ->lock.
1144 */ 1145 */
1145static unsigned long __maybe_unused 1146static bool __maybe_unused
1146rcu_start_future_gp(struct rcu_node *rnp, struct rcu_data *rdp) 1147rcu_start_future_gp(struct rcu_node *rnp, struct rcu_data *rdp,
1148 unsigned long *c_out)
1147{ 1149{
1148 unsigned long c; 1150 unsigned long c;
1149 int i; 1151 int i;
1152 bool ret = false;
1150 struct rcu_node *rnp_root = rcu_get_root(rdp->rsp); 1153 struct rcu_node *rnp_root = rcu_get_root(rdp->rsp);
1151 1154
1152 /* 1155 /*
@@ -1157,7 +1160,7 @@ rcu_start_future_gp(struct rcu_node *rnp, struct rcu_data *rdp)
1157 trace_rcu_future_gp(rnp, rdp, c, TPS("Startleaf")); 1160 trace_rcu_future_gp(rnp, rdp, c, TPS("Startleaf"));
1158 if (rnp->need_future_gp[c & 0x1]) { 1161 if (rnp->need_future_gp[c & 0x1]) {
1159 trace_rcu_future_gp(rnp, rdp, c, TPS("Prestartleaf")); 1162 trace_rcu_future_gp(rnp, rdp, c, TPS("Prestartleaf"));
1160 return c; 1163 goto out;
1161 } 1164 }
1162 1165
1163 /* 1166 /*
@@ -1171,7 +1174,7 @@ rcu_start_future_gp(struct rcu_node *rnp, struct rcu_data *rdp)
1171 ACCESS_ONCE(rnp->gpnum) != ACCESS_ONCE(rnp->completed)) { 1174 ACCESS_ONCE(rnp->gpnum) != ACCESS_ONCE(rnp->completed)) {
1172 rnp->need_future_gp[c & 0x1]++; 1175 rnp->need_future_gp[c & 0x1]++;
1173 trace_rcu_future_gp(rnp, rdp, c, TPS("Startedleaf")); 1176 trace_rcu_future_gp(rnp, rdp, c, TPS("Startedleaf"));
1174 return c; 1177 goto out;
1175 } 1178 }
1176 1179
1177 /* 1180 /*
@@ -1212,12 +1215,15 @@ rcu_start_future_gp(struct rcu_node *rnp, struct rcu_data *rdp)
1212 trace_rcu_future_gp(rnp, rdp, c, TPS("Startedleafroot")); 1215 trace_rcu_future_gp(rnp, rdp, c, TPS("Startedleafroot"));
1213 } else { 1216 } else {
1214 trace_rcu_future_gp(rnp, rdp, c, TPS("Startedroot")); 1217 trace_rcu_future_gp(rnp, rdp, c, TPS("Startedroot"));
1215 rcu_start_gp_advanced(rdp->rsp, rnp_root, rdp); 1218 ret = rcu_start_gp_advanced(rdp->rsp, rnp_root, rdp);
1216 } 1219 }
1217unlock_out: 1220unlock_out:
1218 if (rnp != rnp_root) 1221 if (rnp != rnp_root)
1219 raw_spin_unlock(&rnp_root->lock); 1222 raw_spin_unlock(&rnp_root->lock);
1220 return c; 1223out:
1224 if (c_out != NULL)
1225 *c_out = c;
1226 return ret;
1221} 1227}
1222 1228
1223/* 1229/*
@@ -1241,25 +1247,43 @@ static int rcu_future_gp_cleanup(struct rcu_state *rsp, struct rcu_node *rnp)
1241} 1247}
1242 1248
1243/* 1249/*
1250 * Awaken the grace-period kthread for the specified flavor of RCU.
1251 * Don't do a self-awaken, and don't bother awakening when there is
1252 * nothing for the grace-period kthread to do (as in several CPUs
1253 * raced to awaken, and we lost), and finally don't try to awaken
1254 * a kthread that has not yet been created.
1255 */
1256static void rcu_gp_kthread_wake(struct rcu_state *rsp)
1257{
1258 if (current == rsp->gp_kthread ||
1259 !ACCESS_ONCE(rsp->gp_flags) ||
1260 !rsp->gp_kthread)
1261 return;
1262 wake_up(&rsp->gp_wq);
1263}
1264
1265/*
1244 * If there is room, assign a ->completed number to any callbacks on 1266 * If there is room, assign a ->completed number to any callbacks on
1245 * this CPU that have not already been assigned. Also accelerate any 1267 * this CPU that have not already been assigned. Also accelerate any
1246 * callbacks that were previously assigned a ->completed number that has 1268 * callbacks that were previously assigned a ->completed number that has
1247 * since proven to be too conservative, which can happen if callbacks get 1269 * since proven to be too conservative, which can happen if callbacks get
1248 * assigned a ->completed number while RCU is idle, but with reference to 1270 * assigned a ->completed number while RCU is idle, but with reference to
1249 * a non-root rcu_node structure. This function is idempotent, so it does 1271 * a non-root rcu_node structure. This function is idempotent, so it does
1250 * not hurt to call it repeatedly. 1272 * not hurt to call it repeatedly. Returns an flag saying that we should
1273 * awaken the RCU grace-period kthread.
1251 * 1274 *
1252 * The caller must hold rnp->lock with interrupts disabled. 1275 * The caller must hold rnp->lock with interrupts disabled.
1253 */ 1276 */
1254static void rcu_accelerate_cbs(struct rcu_state *rsp, struct rcu_node *rnp, 1277static bool rcu_accelerate_cbs(struct rcu_state *rsp, struct rcu_node *rnp,
1255 struct rcu_data *rdp) 1278 struct rcu_data *rdp)
1256{ 1279{
1257 unsigned long c; 1280 unsigned long c;
1258 int i; 1281 int i;
1282 bool ret;
1259 1283
1260 /* If the CPU has no callbacks, nothing to do. */ 1284 /* If the CPU has no callbacks, nothing to do. */
1261 if (!rdp->nxttail[RCU_NEXT_TAIL] || !*rdp->nxttail[RCU_DONE_TAIL]) 1285 if (!rdp->nxttail[RCU_NEXT_TAIL] || !*rdp->nxttail[RCU_DONE_TAIL])
1262 return; 1286 return false;
1263 1287
1264 /* 1288 /*
1265 * Starting from the sublist containing the callbacks most 1289 * Starting from the sublist containing the callbacks most
@@ -1288,7 +1312,7 @@ static void rcu_accelerate_cbs(struct rcu_state *rsp, struct rcu_node *rnp,
1288 * be grouped into. 1312 * be grouped into.
1289 */ 1313 */
1290 if (++i >= RCU_NEXT_TAIL) 1314 if (++i >= RCU_NEXT_TAIL)
1291 return; 1315 return false;
1292 1316
1293 /* 1317 /*
1294 * Assign all subsequent callbacks' ->completed number to the next 1318 * Assign all subsequent callbacks' ->completed number to the next
@@ -1300,13 +1324,14 @@ static void rcu_accelerate_cbs(struct rcu_state *rsp, struct rcu_node *rnp,
1300 rdp->nxtcompleted[i] = c; 1324 rdp->nxtcompleted[i] = c;
1301 } 1325 }
1302 /* Record any needed additional grace periods. */ 1326 /* Record any needed additional grace periods. */
1303 rcu_start_future_gp(rnp, rdp); 1327 ret = rcu_start_future_gp(rnp, rdp, NULL);
1304 1328
1305 /* Trace depending on how much we were able to accelerate. */ 1329 /* Trace depending on how much we were able to accelerate. */
1306 if (!*rdp->nxttail[RCU_WAIT_TAIL]) 1330 if (!*rdp->nxttail[RCU_WAIT_TAIL])
1307 trace_rcu_grace_period(rsp->name, rdp->gpnum, TPS("AccWaitCB")); 1331 trace_rcu_grace_period(rsp->name, rdp->gpnum, TPS("AccWaitCB"));
1308 else 1332 else
1309 trace_rcu_grace_period(rsp->name, rdp->gpnum, TPS("AccReadyCB")); 1333 trace_rcu_grace_period(rsp->name, rdp->gpnum, TPS("AccReadyCB"));
1334 return ret;
1310} 1335}
1311 1336
1312/* 1337/*
@@ -1315,17 +1340,18 @@ static void rcu_accelerate_cbs(struct rcu_state *rsp, struct rcu_node *rnp,
1315 * assign ->completed numbers to any callbacks in the RCU_NEXT_TAIL 1340 * assign ->completed numbers to any callbacks in the RCU_NEXT_TAIL
1316 * sublist. This function is idempotent, so it does not hurt to 1341 * sublist. This function is idempotent, so it does not hurt to
1317 * invoke it repeatedly. As long as it is not invoked -too- often... 1342 * invoke it repeatedly. As long as it is not invoked -too- often...
1343 * Returns true if the RCU grace-period kthread needs to be awakened.
1318 * 1344 *