stop_machine_cpuslocked() currently configures struct multi_stop_data and
invokes the multi-stop operation. An upcoming stop_machine() variant will
have different configurations but the latter part will be shareable.
Extract the common part into stop_multi_cpus() to highlight each unique
front-end.
No functional change.
Signed-off-by: Chang S. Bae <chang.seok.bae@intel.com>
---
V1 -> V2: New patch
---
kernel/stop_machine.c | 35 ++++++++++++++++++++---------------
1 file changed, 20 insertions(+), 15 deletions(-)
diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
index 15268f1207e9..092c65c002ff 100644
--- a/kernel/stop_machine.c
+++ b/kernel/stop_machine.c
@@ -584,18 +584,8 @@ static int __init cpu_stop_init(void)
}
early_initcall(cpu_stop_init);
-int stop_machine_cpuslocked(cpu_stop_fn_t fn, void *data,
- const struct cpumask *cpus)
+static int stop_multi_cpus(struct multi_stop_data *msdata)
{
- struct multi_stop_data msdata = {
- .fn = fn,
- .data = data,
- .num_threads = num_online_cpus(),
- .active_cpus = cpus,
- };
-
- lockdep_assert_cpus_held();
-
if (!stop_machine_initialized) {
/*
* Handle the case where stop_machine() is called
@@ -605,19 +595,34 @@ int stop_machine_cpuslocked(cpu_stop_fn_t fn, void *data,
unsigned long flags;
int ret;
- WARN_ON_ONCE(msdata.num_threads != 1);
+ WARN_ON_ONCE(msdata->num_threads != 1);
local_irq_save(flags);
hard_irq_disable();
- ret = (*fn)(data);
+ ret = msdata->fn(msdata->data);
local_irq_restore(flags);
return ret;
}
/* Set the initial state and stop all online cpus. */
- set_state(&msdata, MULTI_STOP_PREPARE);
- return stop_cpus(cpu_online_mask, multi_cpu_stop, &msdata);
+ set_state(msdata, MULTI_STOP_PREPARE);
+ return stop_cpus(cpu_online_mask, multi_cpu_stop, msdata);
+}
+
+int stop_machine_cpuslocked(cpu_stop_fn_t fn, void *data,
+ const struct cpumask *cpus)
+{
+ struct multi_stop_data msdata = {
+ .fn = fn,
+ .data = data,
+ .num_threads = num_online_cpus(),
+ .active_cpus = cpus,
+ };
+
+ lockdep_assert_cpus_held();
+
+ return stop_multi_cpus(&msdata);
}
int stop_machine(cpu_stop_fn_t fn, void *data, const struct cpumask *cpus)
--
2.51.0