Subject: [tip:smp/hotplug] cpu/hotplug: Split out cpu down functions

Commit-ID: 984581728eb4b2e10baed3d606f85a119795b207
Gitweb: http://git.kernel.org/tip/984581728eb4b2e10baed3d606f85a119795b207
Author: Thomas Gleixner <[email protected]>
AuthorDate: Fri, 26 Feb 2016 18:43:25 +0000
Committer: Thomas Gleixner <[email protected]>
CommitDate: Tue, 1 Mar 2016 20:36:53 +0100

cpu/hotplug: Split out cpu down functions

Split cpu_down in separate functions in preparation for state machine
conversion.

Signed-off-by: Thomas Gleixner <[email protected]>
Cc: [email protected]
Cc: Rik van Riel <[email protected]>
Cc: Rafael Wysocki <[email protected]>
Cc: "Srivatsa S. Bhat" <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Arjan van de Ven <[email protected]>
Cc: Sebastian Siewior <[email protected]>
Cc: Rusty Russell <[email protected]>
Cc: Steven Rostedt <[email protected]>
Cc: Oleg Nesterov <[email protected]>
Cc: Tejun Heo <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Paul McKenney <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Paul Turner <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Thomas Gleixner <[email protected]>
---
kernel/cpu.c | 83 ++++++++++++++++++++++++++++++++++++++----------------------
1 file changed, 53 insertions(+), 30 deletions(-)

diff --git a/kernel/cpu.c b/kernel/cpu.c
index 15a4136..0b5d259 100644
--- a/kernel/cpu.c
+++ b/kernel/cpu.c
@@ -266,11 +266,6 @@ static int bringup_cpu(unsigned int cpu)
}

#ifdef CONFIG_HOTPLUG_CPU
-
-static void cpu_notify_nofail(unsigned long val, unsigned int cpu)
-{
- BUG_ON(cpu_notify(val, cpu));
-}
EXPORT_SYMBOL(register_cpu_notifier);
EXPORT_SYMBOL(__register_cpu_notifier);

@@ -353,6 +348,25 @@ static inline void check_for_tasks(int dead_cpu)
read_unlock(&tasklist_lock);
}

+static void cpu_notify_nofail(unsigned long val, unsigned int cpu)
+{
+ BUG_ON(cpu_notify(val, cpu));
+}
+
+static int notify_down_prepare(unsigned int cpu)
+{
+ int err, nr_calls = 0;
+
+ err = __cpu_notify(CPU_DOWN_PREPARE, cpu, -1, &nr_calls);
+ if (err) {
+ nr_calls--;
+ __cpu_notify(CPU_DOWN_FAILED, cpu, nr_calls, NULL);
+ pr_warn("%s: attempt to take down CPU %u failed\n",
+ __func__, cpu);
+ }
+ return err;
+}
+
/* Take this CPU down. */
static int take_cpu_down(void *_param)
{
@@ -371,29 +385,9 @@ static int take_cpu_down(void *_param)
return 0;
}

-/* Requires cpu_add_remove_lock to be held */
-static int _cpu_down(unsigned int cpu, int tasks_frozen)
+static int takedown_cpu(unsigned int cpu)
{
- int err, nr_calls = 0;
-
- if (num_online_cpus() == 1)
- return -EBUSY;
-
- if (!cpu_online(cpu))
- return -EINVAL;
-
- cpu_hotplug_begin();
-
- cpuhp_tasks_frozen = tasks_frozen;
-
- err = __cpu_notify(CPU_DOWN_PREPARE, cpu, -1, &nr_calls);
- if (err) {
- nr_calls--;
- __cpu_notify(CPU_DOWN_FAILED, cpu, nr_calls, NULL);
- pr_warn("%s: attempt to take down CPU %u failed\n",
- __func__, cpu);
- goto out_release;
- }
+ int err;

/*
* By now we've cleared cpu_active_mask, wait for all preempt-disabled
@@ -426,7 +420,7 @@ static int _cpu_down(unsigned int cpu, int tasks_frozen)
/* CPU didn't die: tell everyone. Can't complain. */
cpu_notify_nofail(CPU_DOWN_FAILED, cpu);
irq_unlock_sparse();
- goto out_release;
+ return err;
}
BUG_ON(cpu_online(cpu));

@@ -449,11 +443,40 @@ static int _cpu_down(unsigned int cpu, int tasks_frozen)
/* This actually kills the CPU. */
__cpu_die(cpu);

- /* CPU is completely dead: tell everyone. Too late to complain. */
tick_cleanup_dead_cpu(cpu);
- cpu_notify_nofail(CPU_DEAD, cpu);
+ return 0;
+}

+static int notify_dead(unsigned int cpu)
+{
+ cpu_notify_nofail(CPU_DEAD, cpu);
check_for_tasks(cpu);
+ return 0;
+}
+
+/* Requires cpu_add_remove_lock to be held */
+static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
+{
+ int err;
+
+ if (num_online_cpus() == 1)
+ return -EBUSY;
+
+ if (!cpu_online(cpu))
+ return -EINVAL;
+
+ cpu_hotplug_begin();
+
+ cpuhp_tasks_frozen = tasks_frozen;
+
+ err = notify_down_prepare(cpu);
+ if (err)
+ goto out_release;
+ err = takedown_cpu(cpu);
+ if (err)
+ goto out_release;
+
+ notify_dead(cpu);

out_release:
cpu_hotplug_done();


2016-03-02 23:05:14

by Srivatsa S. Bhat

[permalink] [raw]
Subject: Re: [tip:smp/hotplug] cpu/hotplug: Split out cpu down functions

On 3/1/16 2:52 PM, tip-bot for Thomas Gleixner wrote:
> Commit-ID: 984581728eb4b2e10baed3d606f85a119795b207
> Gitweb: http://git.kernel.org/tip/984581728eb4b2e10baed3d606f85a119795b207
> Author: Thomas Gleixner <[email protected]>
> AuthorDate: Fri, 26 Feb 2016 18:43:25 +0000
> Committer: Thomas Gleixner <[email protected]>
> CommitDate: Tue, 1 Mar 2016 20:36:53 +0100
>
> cpu/hotplug: Split out cpu down functions
>
> Split cpu_down in separate functions in preparation for state machine
> conversion.
>
> Signed-off-by: Thomas Gleixner <[email protected]>
> Cc: [email protected]
> Cc: Rik van Riel <[email protected]>
> Cc: Rafael Wysocki <[email protected]>
> Cc: "Srivatsa S. Bhat" <[email protected]>
> Cc: Peter Zijlstra <[email protected]>
> Cc: Arjan van de Ven <[email protected]>
> Cc: Sebastian Siewior <[email protected]>
> Cc: Rusty Russell <[email protected]>
> Cc: Steven Rostedt <[email protected]>
> Cc: Oleg Nesterov <[email protected]>
> Cc: Tejun Heo <[email protected]>
> Cc: Andrew Morton <[email protected]>
> Cc: Paul McKenney <[email protected]>
> Cc: Linus Torvalds <[email protected]>
> Cc: Paul Turner <[email protected]>
> Link: http://lkml.kernel.org/r/[email protected]
> Signed-off-by: Thomas Gleixner <[email protected]>
> ---

Reviewed-by: Srivatsa S. Bhat <[email protected]>

Regards,
Srivatsa S. Bhat

> kernel/cpu.c | 83 ++++++++++++++++++++++++++++++++++++++----------------------
> 1 file changed, 53 insertions(+), 30 deletions(-)
>
> diff --git a/kernel/cpu.c b/kernel/cpu.c
> index 15a4136..0b5d259 100644
> --- a/kernel/cpu.c
> +++ b/kernel/cpu.c
> @@ -266,11 +266,6 @@ static int bringup_cpu(unsigned int cpu)
> }
>
> #ifdef CONFIG_HOTPLUG_CPU
> -
> -static void cpu_notify_nofail(unsigned long val, unsigned int cpu)
> -{
> - BUG_ON(cpu_notify(val, cpu));
> -}
> EXPORT_SYMBOL(register_cpu_notifier);
> EXPORT_SYMBOL(__register_cpu_notifier);
>
> @@ -353,6 +348,25 @@ static inline void check_for_tasks(int dead_cpu)
> read_unlock(&tasklist_lock);
> }
>
> +static void cpu_notify_nofail(unsigned long val, unsigned int cpu)
> +{
> + BUG_ON(cpu_notify(val, cpu));
> +}
> +
> +static int notify_down_prepare(unsigned int cpu)
> +{
> + int err, nr_calls = 0;
> +
> + err = __cpu_notify(CPU_DOWN_PREPARE, cpu, -1, &nr_calls);
> + if (err) {
> + nr_calls--;
> + __cpu_notify(CPU_DOWN_FAILED, cpu, nr_calls, NULL);
> + pr_warn("%s: attempt to take down CPU %u failed\n",
> + __func__, cpu);
> + }
> + return err;
> +}
> +
> /* Take this CPU down. */
> static int take_cpu_down(void *_param)
> {
> @@ -371,29 +385,9 @@ static int take_cpu_down(void *_param)
> return 0;
> }
>
> -/* Requires cpu_add_remove_lock to be held */
> -static int _cpu_down(unsigned int cpu, int tasks_frozen)
> +static int takedown_cpu(unsigned int cpu)
> {
> - int err, nr_calls = 0;
> -
> - if (num_online_cpus() == 1)
> - return -EBUSY;
> -
> - if (!cpu_online(cpu))
> - return -EINVAL;
> -
> - cpu_hotplug_begin();
> -
> - cpuhp_tasks_frozen = tasks_frozen;
> -
> - err = __cpu_notify(CPU_DOWN_PREPARE, cpu, -1, &nr_calls);
> - if (err) {
> - nr_calls--;
> - __cpu_notify(CPU_DOWN_FAILED, cpu, nr_calls, NULL);
> - pr_warn("%s: attempt to take down CPU %u failed\n",
> - __func__, cpu);
> - goto out_release;
> - }
> + int err;
>
> /*
> * By now we've cleared cpu_active_mask, wait for all preempt-disabled
> @@ -426,7 +420,7 @@ static int _cpu_down(unsigned int cpu, int tasks_frozen)
> /* CPU didn't die: tell everyone. Can't complain. */
> cpu_notify_nofail(CPU_DOWN_FAILED, cpu);
> irq_unlock_sparse();
> - goto out_release;
> + return err;
> }
> BUG_ON(cpu_online(cpu));
>
> @@ -449,11 +443,40 @@ static int _cpu_down(unsigned int cpu, int tasks_frozen)
> /* This actually kills the CPU. */
> __cpu_die(cpu);
>
> - /* CPU is completely dead: tell everyone. Too late to complain. */
> tick_cleanup_dead_cpu(cpu);
> - cpu_notify_nofail(CPU_DEAD, cpu);
> + return 0;
> +}
>
> +static int notify_dead(unsigned int cpu)
> +{
> + cpu_notify_nofail(CPU_DEAD, cpu);
> check_for_tasks(cpu);
> + return 0;
> +}
> +
> +/* Requires cpu_add_remove_lock to be held */
> +static int __ref _cpu_down(unsigned int cpu, int tasks_frozen)
> +{
> + int err;
> +
> + if (num_online_cpus() == 1)
> + return -EBUSY;
> +
> + if (!cpu_online(cpu))
> + return -EINVAL;
> +
> + cpu_hotplug_begin();
> +
> + cpuhp_tasks_frozen = tasks_frozen;
> +
> + err = notify_down_prepare(cpu);
> + if (err)
> + goto out_release;
> + err = takedown_cpu(cpu);
> + if (err)
> + goto out_release;
> +
> + notify_dead(cpu);
>
> out_release:
> cpu_hotplug_done();
>