Commit 33c3736e authored by Qais Yousef's avatar Qais Yousef Committed by Thomas Gleixner

cpu/hotplug: Hide cpu_up/down()

Use separate functions for the device core to bring a CPU up and down.

Users outside the device core must use add/remove_cpu() which will take
care of extra housekeeping work like keeping sysfs in sync.

Make cpu_up/down() static and replace the extra layer of indirection.

[ tglx: Removed the extra wrapper functions and adjusted function names ]
Signed-off-by: default avatarQais Yousef <qais.yousef@arm.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20200323135110.30522-18-qais.yousef@arm.com
parent b99a2659
...@@ -55,7 +55,7 @@ static int cpu_subsys_online(struct device *dev) ...@@ -55,7 +55,7 @@ static int cpu_subsys_online(struct device *dev)
if (from_nid == NUMA_NO_NODE) if (from_nid == NUMA_NO_NODE)
return -ENODEV; return -ENODEV;
ret = cpu_up(cpuid); ret = cpu_device_up(dev);
/* /*
* When hot adding memory to memoryless node and enabling a cpu * When hot adding memory to memoryless node and enabling a cpu
* on the node, node number of the cpu may internally change. * on the node, node number of the cpu may internally change.
...@@ -69,7 +69,7 @@ static int cpu_subsys_online(struct device *dev) ...@@ -69,7 +69,7 @@ static int cpu_subsys_online(struct device *dev)
static int cpu_subsys_offline(struct device *dev) static int cpu_subsys_offline(struct device *dev)
{ {
return cpu_down(dev->id); return cpu_device_down(dev);
} }
void unregister_cpu(struct cpu *cpu) void unregister_cpu(struct cpu *cpu)
......
...@@ -88,8 +88,8 @@ extern ssize_t arch_cpu_release(const char *, size_t); ...@@ -88,8 +88,8 @@ extern ssize_t arch_cpu_release(const char *, size_t);
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
extern bool cpuhp_tasks_frozen; extern bool cpuhp_tasks_frozen;
int cpu_up(unsigned int cpu);
int add_cpu(unsigned int cpu); int add_cpu(unsigned int cpu);
int cpu_device_up(struct device *dev);
void notify_cpu_starting(unsigned int cpu); void notify_cpu_starting(unsigned int cpu);
extern void cpu_maps_update_begin(void); extern void cpu_maps_update_begin(void);
extern void cpu_maps_update_done(void); extern void cpu_maps_update_done(void);
...@@ -120,8 +120,8 @@ extern void lockdep_assert_cpus_held(void); ...@@ -120,8 +120,8 @@ extern void lockdep_assert_cpus_held(void);
extern void cpu_hotplug_disable(void); extern void cpu_hotplug_disable(void);
extern void cpu_hotplug_enable(void); extern void cpu_hotplug_enable(void);
void clear_tasks_mm_cpumask(int cpu); void clear_tasks_mm_cpumask(int cpu);
int cpu_down(unsigned int cpu);
int remove_cpu(unsigned int cpu); int remove_cpu(unsigned int cpu);
int cpu_device_down(struct device *dev);
extern void smp_shutdown_nonboot_cpus(unsigned int primary_cpu); extern void smp_shutdown_nonboot_cpus(unsigned int primary_cpu);
#else /* CONFIG_HOTPLUG_CPU */ #else /* CONFIG_HOTPLUG_CPU */
......
...@@ -1041,7 +1041,7 @@ static int cpu_down_maps_locked(unsigned int cpu, enum cpuhp_state target) ...@@ -1041,7 +1041,7 @@ static int cpu_down_maps_locked(unsigned int cpu, enum cpuhp_state target)
return _cpu_down(cpu, 0, target); return _cpu_down(cpu, 0, target);
} }
static int do_cpu_down(unsigned int cpu, enum cpuhp_state target) static int cpu_down(unsigned int cpu, enum cpuhp_state target)
{ {
int err; int err;
...@@ -1051,11 +1051,18 @@ static int do_cpu_down(unsigned int cpu, enum cpuhp_state target) ...@@ -1051,11 +1051,18 @@ static int do_cpu_down(unsigned int cpu, enum cpuhp_state target)
return err; return err;
} }
int cpu_down(unsigned int cpu) /**
* cpu_device_down - Bring down a cpu device
* @dev: Pointer to the cpu device to offline
*
* This function is meant to be used by device core cpu subsystem only.
*
* Other subsystems should use remove_cpu() instead.
*/
int cpu_device_down(struct device *dev)
{ {
return do_cpu_down(cpu, CPUHP_OFFLINE); return cpu_down(dev->id, CPUHP_OFFLINE);
} }
EXPORT_SYMBOL(cpu_down);
int remove_cpu(unsigned int cpu) int remove_cpu(unsigned int cpu)
{ {
...@@ -1178,8 +1185,8 @@ static int _cpu_up(unsigned int cpu, int tasks_frozen, enum cpuhp_state target) ...@@ -1178,8 +1185,8 @@ static int _cpu_up(unsigned int cpu, int tasks_frozen, enum cpuhp_state target)
} }
/* /*
* The caller of do_cpu_up might have raced with another * The caller of cpu_up() might have raced with another
* caller. Ignore it for now. * caller. Nothing to do.
*/ */
if (st->state >= target) if (st->state >= target)
goto out; goto out;
...@@ -1223,7 +1230,7 @@ static int _cpu_up(unsigned int cpu, int tasks_frozen, enum cpuhp_state target) ...@@ -1223,7 +1230,7 @@ static int _cpu_up(unsigned int cpu, int tasks_frozen, enum cpuhp_state target)
return ret; return ret;
} }
static int do_cpu_up(unsigned int cpu, enum cpuhp_state target) static int cpu_up(unsigned int cpu, enum cpuhp_state target)
{ {
int err = 0; int err = 0;
...@@ -1257,11 +1264,18 @@ static int do_cpu_up(unsigned int cpu, enum cpuhp_state target) ...@@ -1257,11 +1264,18 @@ static int do_cpu_up(unsigned int cpu, enum cpuhp_state target)
return err; return err;
} }
int cpu_up(unsigned int cpu) /**
* cpu_device_up - Bring up a cpu device
* @dev: Pointer to the cpu device to online
*
* This function is meant to be used by device core cpu subsystem only.
*
* Other subsystems should use add_cpu() instead.
*/
int cpu_device_up(struct device *dev)
{ {
return do_cpu_up(cpu, CPUHP_ONLINE); return cpu_up(dev->id, CPUHP_ONLINE);
} }
EXPORT_SYMBOL_GPL(cpu_up);
int add_cpu(unsigned int cpu) int add_cpu(unsigned int cpu)
{ {
...@@ -1289,7 +1303,7 @@ int bringup_hibernate_cpu(unsigned int sleep_cpu) ...@@ -1289,7 +1303,7 @@ int bringup_hibernate_cpu(unsigned int sleep_cpu)
if (!cpu_online(sleep_cpu)) { if (!cpu_online(sleep_cpu)) {
pr_info("Hibernated on a CPU that is offline! Bringing CPU up.\n"); pr_info("Hibernated on a CPU that is offline! Bringing CPU up.\n");
ret = cpu_up(sleep_cpu); ret = cpu_up(sleep_cpu, CPUHP_ONLINE);
if (ret) { if (ret) {
pr_err("Failed to bring hibernate-CPU up!\n"); pr_err("Failed to bring hibernate-CPU up!\n");
return ret; return ret;
...@@ -1306,7 +1320,7 @@ void bringup_nonboot_cpus(unsigned int setup_max_cpus) ...@@ -1306,7 +1320,7 @@ void bringup_nonboot_cpus(unsigned int setup_max_cpus)
if (num_online_cpus() >= setup_max_cpus) if (num_online_cpus() >= setup_max_cpus)
break; break;
if (!cpu_online(cpu)) if (!cpu_online(cpu))
cpu_up(cpu); cpu_up(cpu, CPUHP_ONLINE);
} }
} }
...@@ -2129,9 +2143,9 @@ static ssize_t write_cpuhp_target(struct device *dev, ...@@ -2129,9 +2143,9 @@ static ssize_t write_cpuhp_target(struct device *dev,
goto out; goto out;
if (st->state < target) if (st->state < target)
ret = do_cpu_up(dev->id, target); ret = cpu_up(dev->id, target);
else else
ret = do_cpu_down(dev->id, target); ret = cpu_down(dev->id, target);
out: out:
unlock_device_hotplug(); unlock_device_hotplug();
return ret ? ret : count; return ret ? ret : count;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment