Skip to content

Commit 4e26ce4

Browse files
Frederic WeisbeckerNeeraj Upadhyay
authored andcommitted
rcu/nocb: (De-)offload callbacks on offline CPUs only
Currently callbacks can be (de-)offloaded only on online CPUs. This involves an overly elaborated state machine in order to make sure that callbacks are always handled during the process while ensuring synchronization between rcu_core and NOCB kthreads. The only potential user of NOCB (de-)offloading appears to be a nohz_full toggling interface through cpusets. And the general agreement is now to work toward toggling the nohz_full state on offline CPUs to simplify the whole picture. Therefore, convert the (de-)offloading to only support offline CPUs. This involves the following changes: * Call rcu_barrier() before deoffloading. An offline offloaded CPU may still carry callbacks in its queue ignored by rcutree_migrate_callbacks(). Those callbacks must all be flushed before switching to a regular queue because no more kthreads will handle those before the CPU ever gets re-onlined. This means that further calls to rcu_barrier() will find an empty queue until the CPU goes through rcutree_report_cpu_starting(). As a result it is guaranteed that further rcu_barrier() won't try to lock the nocb_lock for that target and thus won't risk an imbalance. Therefore barrier_mutex doesn't need to be locked anymore upon deoffloading. * Assume the queue is empty before offloading, as rcutree_migrate_callbacks() took care of everything. This means that further calls to rcu_barrier() will find an empty queue until the CPU goes through rcutree_report_cpu_starting(). As a result it is guaranteed that further rcu_barrier() won't risk a nocb_lock imbalance. Therefore barrier_mutex doesn't need to be locked anymore upon offloading. * No need to flush bypass anymore. Further simplifications will follow in upcoming patches. Signed-off-by: Frederic Weisbecker <[email protected]> Signed-off-by: Paul E. McKenney <[email protected]> Reviewed-by: Paul E. McKenney <[email protected]> Signed-off-by: Neeraj Upadhyay <[email protected]>
1 parent 7121dd9 commit 4e26ce4

File tree

1 file changed

+21
-61
lines changed

1 file changed

+21
-61
lines changed

kernel/rcu/tree_nocb.h

Lines changed: 21 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,43 +1049,26 @@ static int rdp_offload_toggle(struct rcu_data *rdp,
10491049
return wake_gp;
10501050
}
10511051

1052-
static long rcu_nocb_rdp_deoffload(void *arg)
1052+
static int rcu_nocb_rdp_deoffload(struct rcu_data *rdp)
10531053
{
1054-
struct rcu_data *rdp = arg;
10551054
struct rcu_segcblist *cblist = &rdp->cblist;
10561055
unsigned long flags;
10571056
int wake_gp;
10581057
struct rcu_data *rdp_gp = rdp->nocb_gp_rdp;
10591058

1060-
/*
1061-
* rcu_nocb_rdp_deoffload() may be called directly if
1062-
* rcuog/o[p] spawn failed, because at this time the rdp->cpu
1063-
* is not online yet.
1064-
*/
1065-
WARN_ON_ONCE((rdp->cpu != raw_smp_processor_id()) && cpu_online(rdp->cpu));
1059+
/* CPU must be offline, unless it's early boot */
1060+
WARN_ON_ONCE(cpu_online(rdp->cpu) && rdp->cpu != raw_smp_processor_id());
10661061

10671062
pr_info("De-offloading %d\n", rdp->cpu);
10681063

1064+
/* Flush all callbacks from segcblist and bypass */
1065+
rcu_barrier();
1066+
10691067
rcu_nocb_lock_irqsave(rdp, flags);
1070-
/*
1071-
* Flush once and for all now. This suffices because we are
1072-
* running on the target CPU holding ->nocb_lock (thus having
1073-
* interrupts disabled), and because rdp_offload_toggle()
1074-
* invokes rcu_segcblist_offload(), which clears SEGCBLIST_OFFLOADED.
1075-
* Thus future calls to rcu_segcblist_completely_offloaded() will
1076-
* return false, which means that future calls to rcu_nocb_try_bypass()
1077-
* will refuse to put anything into the bypass.
1078-
*/
1079-
WARN_ON_ONCE(!rcu_nocb_flush_bypass(rdp, NULL, jiffies, false));
1080-
/*
1081-
* Start with invoking rcu_core() early. This way if the current thread
1082-
* happens to preempt an ongoing call to rcu_core() in the middle,
1083-
* leaving some work dismissed because rcu_core() still thinks the rdp is
1084-
* completely offloaded, we are guaranteed a nearby future instance of
1085-
* rcu_core() to catch up.
1086-
*/
1068+
WARN_ON_ONCE(rcu_cblist_n_cbs(&rdp->nocb_bypass));
1069+
WARN_ON_ONCE(rcu_segcblist_n_cbs(&rdp->cblist));
1070+
10871071
rcu_segcblist_set_flags(cblist, SEGCBLIST_RCU_CORE);
1088-
invoke_rcu_core();
10891072
wake_gp = rdp_offload_toggle(rdp, false, flags);
10901073

10911074
mutex_lock(&rdp_gp->nocb_gp_kthread_mutex);
@@ -1128,10 +1111,6 @@ static long rcu_nocb_rdp_deoffload(void *arg)
11281111
*/
11291112
raw_spin_unlock_irqrestore(&rdp->nocb_lock, flags);
11301113

1131-
/* Sanity check */
1132-
WARN_ON_ONCE(rcu_cblist_n_cbs(&rdp->nocb_bypass));
1133-
1134-
11351114
return 0;
11361115
}
11371116

@@ -1142,34 +1121,31 @@ int rcu_nocb_cpu_deoffload(int cpu)
11421121

11431122
cpus_read_lock();
11441123
mutex_lock(&rcu_state.nocb_mutex);
1145-
mutex_lock(&rcu_state.barrier_mutex);
11461124
if (rcu_rdp_is_offloaded(rdp)) {
1147-
if (cpu_online(cpu)) {
1148-
ret = work_on_cpu(cpu, rcu_nocb_rdp_deoffload, rdp);
1125+
if (!cpu_online(cpu)) {
1126+
ret = rcu_nocb_rdp_deoffload(rdp);
11491127
if (!ret)
11501128
cpumask_clear_cpu(cpu, rcu_nocb_mask);
11511129
} else {
1152-
pr_info("NOCB: Cannot CB-deoffload offline CPU %d\n", rdp->cpu);
1130+
pr_info("NOCB: Cannot CB-deoffload online CPU %d\n", rdp->cpu);
11531131
ret = -EINVAL;
11541132
}
11551133
}
1156-
mutex_unlock(&rcu_state.barrier_mutex);
11571134
mutex_unlock(&rcu_state.nocb_mutex);
11581135
cpus_read_unlock();
11591136

11601137
return ret;
11611138
}
11621139
EXPORT_SYMBOL_GPL(rcu_nocb_cpu_deoffload);
11631140

1164-
static long rcu_nocb_rdp_offload(void *arg)
1141+
static int rcu_nocb_rdp_offload(struct rcu_data *rdp)
11651142
{
1166-
struct rcu_data *rdp = arg;
11671143
struct rcu_segcblist *cblist = &rdp->cblist;
11681144
unsigned long flags;
11691145
int wake_gp;
11701146
struct rcu_data *rdp_gp = rdp->nocb_gp_rdp;
11711147

1172-
WARN_ON_ONCE(rdp->cpu != raw_smp_processor_id());
1148+
WARN_ON_ONCE(cpu_online(rdp->cpu));
11731149
/*
11741150
* For now we only support re-offload, ie: the rdp must have been
11751151
* offloaded on boot first.
@@ -1182,28 +1158,15 @@ static long rcu_nocb_rdp_offload(void *arg)
11821158

11831159
pr_info("Offloading %d\n", rdp->cpu);
11841160

1161+
WARN_ON_ONCE(rcu_cblist_n_cbs(&rdp->nocb_bypass));
1162+
WARN_ON_ONCE(rcu_segcblist_n_cbs(&rdp->cblist));
1163+
11851164
/*
11861165
* Can't use rcu_nocb_lock_irqsave() before SEGCBLIST_LOCKING
11871166
* is set.
11881167
*/
11891168
raw_spin_lock_irqsave(&rdp->nocb_lock, flags);
11901169

1191-
/*
1192-
* We didn't take the nocb lock while working on the
1193-
* rdp->cblist with SEGCBLIST_LOCKING cleared (pure softirq/rcuc mode).
1194-
* Every modifications that have been done previously on
1195-
* rdp->cblist must be visible remotely by the nocb kthreads
1196-
* upon wake up after reading the cblist flags.
1197-
*
1198-
* The layout against nocb_lock enforces that ordering:
1199-
*
1200-
* __rcu_nocb_rdp_offload() nocb_cb_wait()/nocb_gp_wait()
1201-
* ------------------------- ----------------------------
1202-
* WRITE callbacks rcu_nocb_lock()
1203-
* rcu_nocb_lock() READ flags
1204-
* WRITE flags READ callbacks
1205-
* rcu_nocb_unlock() rcu_nocb_unlock()
1206-
*/
12071170
wake_gp = rdp_offload_toggle(rdp, true, flags);
12081171
if (wake_gp)
12091172
wake_up_process(rdp_gp->nocb_gp_kthread);
@@ -1214,8 +1177,7 @@ static long rcu_nocb_rdp_offload(void *arg)
12141177
rcu_segcblist_test_flags(cblist, SEGCBLIST_KTHREAD_GP));
12151178

12161179
/*
1217-
* All kthreads are ready to work, we can finally relieve rcu_core() and
1218-
* enable nocb bypass.
1180+
* All kthreads are ready to work, we can finally enable nocb bypass.
12191181
*/
12201182
rcu_nocb_lock_irqsave(rdp, flags);
12211183
rcu_segcblist_clear_flags(cblist, SEGCBLIST_RCU_CORE);
@@ -1231,18 +1193,16 @@ int rcu_nocb_cpu_offload(int cpu)
12311193

12321194
cpus_read_lock();
12331195
mutex_lock(&rcu_state.nocb_mutex);
1234-
mutex_lock(&rcu_state.barrier_mutex);
12351196
if (!rcu_rdp_is_offloaded(rdp)) {
1236-
if (cpu_online(cpu)) {
1237-
ret = work_on_cpu(cpu, rcu_nocb_rdp_offload, rdp);
1197+
if (!cpu_online(cpu)) {
1198+
ret = rcu_nocb_rdp_offload(rdp);
12381199
if (!ret)
12391200
cpumask_set_cpu(cpu, rcu_nocb_mask);
12401201
} else {
1241-
pr_info("NOCB: Cannot CB-offload offline CPU %d\n", rdp->cpu);
1202+
pr_info("NOCB: Cannot CB-offload online CPU %d\n", rdp->cpu);
12421203
ret = -EINVAL;
12431204
}
12441205
}
1245-
mutex_unlock(&rcu_state.barrier_mutex);
12461206
mutex_unlock(&rcu_state.nocb_mutex);
12471207
cpus_read_unlock();
12481208

0 commit comments

Comments
 (0)