[RFC PATCH 1/4] stop_machine: Move cpu_stop_done into stop_machine.h

From: Yafang Shao
Date: Thu Nov 04 2021 - 10:57:37 EST


Move struct cpu_stop_done into the stop_machine.h, then it can be resued
by the functions outside of stop_maichine.c.

Signed-off-by: Yafang Shao <laoar.shao@xxxxxxxxx>
Cc: Valentin Schneider <valentin.schneider@xxxxxxx>
Cc: Vincent Guittot <vincent.guittot@xxxxxxxxxx>
Cc: Dietmar Eggemann <dietmar.eggemann@xxxxxxx>
---
include/linux/stop_machine.h | 12 ++++++++++++
kernel/stop_machine.c | 14 ++------------
2 files changed, 14 insertions(+), 12 deletions(-)

diff --git a/include/linux/stop_machine.h b/include/linux/stop_machine.h
index 46fb3ebdd16e..b1234cb6ab70 100644
--- a/include/linux/stop_machine.h
+++ b/include/linux/stop_machine.h
@@ -20,6 +20,15 @@
typedef int (*cpu_stop_fn_t)(void *arg);

#ifdef CONFIG_SMP
+/*
+ * Structure to determine completion condition and record errors. May
+ * be shared by works on different cpus.
+ */
+struct cpu_stop_done {
+ atomic_t nr_todo; /* nr left to execute */
+ int ret; /* collected return value */
+ struct completion completion; /* fired if nr_todo reaches 0 */
+};

struct cpu_stop_work {
struct list_head list; /* cpu_stopper->works */
@@ -29,6 +38,9 @@ struct cpu_stop_work {
struct cpu_stop_done *done;
};

+void cpu_stop_init_done(struct cpu_stop_done *done, unsigned int nr_todo);
+void cpu_stop_signal_done(struct cpu_stop_done *done);
+
int stop_one_cpu(unsigned int cpu, cpu_stop_fn_t fn, void *arg);
int stop_two_cpus(unsigned int cpu1, unsigned int cpu2, cpu_stop_fn_t fn, void *arg);
bool stop_one_cpu_nowait(unsigned int cpu, cpu_stop_fn_t fn, void *arg,
diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
index cbc30271ea4d..cc94eb7d2c5c 100644
--- a/kernel/stop_machine.c
+++ b/kernel/stop_machine.c
@@ -23,16 +23,6 @@
#include <linux/nmi.h>
#include <linux/sched/wake_q.h>

-/*
- * Structure to determine completion condition and record errors. May
- * be shared by works on different cpus.
- */
-struct cpu_stop_done {
- atomic_t nr_todo; /* nr left to execute */
- int ret; /* collected return value */
- struct completion completion; /* fired if nr_todo reaches 0 */
-};
-
/* the actual stopper, one per every possible cpu, enabled on online cpus */
struct cpu_stopper {
struct task_struct *thread;
@@ -67,7 +57,7 @@ void print_stop_info(const char *log_lvl, struct task_struct *task)
static DEFINE_MUTEX(stop_cpus_mutex);
static bool stop_cpus_in_progress;

-static void cpu_stop_init_done(struct cpu_stop_done *done, unsigned int nr_todo)
+void cpu_stop_init_done(struct cpu_stop_done *done, unsigned int nr_todo)
{
memset(done, 0, sizeof(*done));
atomic_set(&done->nr_todo, nr_todo);
@@ -75,7 +65,7 @@ static void cpu_stop_init_done(struct cpu_stop_done *done, unsigned int nr_todo)
}

/* signal completion unless @done is NULL */
-static void cpu_stop_signal_done(struct cpu_stop_done *done)
+void cpu_stop_signal_done(struct cpu_stop_done *done)
{
if (atomic_dec_and_test(&done->nr_todo))
complete(&done->completion);
--
2.17.1