Skip to content

Commit 33c3736

Browse files
Qais YousefKAGA-KOKO
authored andcommitted
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: Qais Yousef <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent b99a265 commit 33c3736

File tree

3 files changed

+32
-18
lines changed

3 files changed

+32
-18
lines changed

drivers/base/cpu.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ static int cpu_subsys_online(struct device *dev)
5555
if (from_nid == NUMA_NO_NODE)
5656
return -ENODEV;
5757

58-
ret = cpu_up(cpuid);
58+
ret = cpu_device_up(dev);
5959
/*
6060
* When hot adding memory to memoryless node and enabling a cpu
6161
* on the node, node number of the cpu may internally change.
@@ -69,7 +69,7 @@ static int cpu_subsys_online(struct device *dev)
6969

7070
static int cpu_subsys_offline(struct device *dev)
7171
{
72-
return cpu_down(dev->id);
72+
return cpu_device_down(dev);
7373
}
7474

7575
void unregister_cpu(struct cpu *cpu)

include/linux/cpu.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ extern ssize_t arch_cpu_release(const char *, size_t);
8888

8989
#ifdef CONFIG_SMP
9090
extern bool cpuhp_tasks_frozen;
91-
int cpu_up(unsigned int cpu);
9291
int add_cpu(unsigned int cpu);
92+
int cpu_device_up(struct device *dev);
9393
void notify_cpu_starting(unsigned int cpu);
9494
extern void cpu_maps_update_begin(void);
9595
extern void cpu_maps_update_done(void);
@@ -120,8 +120,8 @@ extern void lockdep_assert_cpus_held(void);
120120
extern void cpu_hotplug_disable(void);
121121
extern void cpu_hotplug_enable(void);
122122
void clear_tasks_mm_cpumask(int cpu);
123-
int cpu_down(unsigned int cpu);
124123
int remove_cpu(unsigned int cpu);
124+
int cpu_device_down(struct device *dev);
125125
extern void smp_shutdown_nonboot_cpus(unsigned int primary_cpu);
126126

127127
#else /* CONFIG_HOTPLUG_CPU */

kernel/cpu.c

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ static int cpu_down_maps_locked(unsigned int cpu, enum cpuhp_state target)
10411041
return _cpu_down(cpu, 0, target);
10421042
}
10431043

1044-
static int do_cpu_down(unsigned int cpu, enum cpuhp_state target)
1044+
static int cpu_down(unsigned int cpu, enum cpuhp_state target)
10451045
{
10461046
int err;
10471047

@@ -1051,11 +1051,18 @@ static int do_cpu_down(unsigned int cpu, enum cpuhp_state target)
10511051
return err;
10521052
}
10531053

1054-
int cpu_down(unsigned int cpu)
1054+
/**
1055+
* cpu_device_down - Bring down a cpu device
1056+
* @dev: Pointer to the cpu device to offline
1057+
*
1058+
* This function is meant to be used by device core cpu subsystem only.
1059+
*
1060+
* Other subsystems should use remove_cpu() instead.
1061+
*/
1062+
int cpu_device_down(struct device *dev)
10551063
{
1056-
return do_cpu_down(cpu, CPUHP_OFFLINE);
1064+
return cpu_down(dev->id, CPUHP_OFFLINE);
10571065
}
1058-
EXPORT_SYMBOL(cpu_down);
10591066

10601067
int remove_cpu(unsigned int cpu)
10611068
{
@@ -1178,8 +1185,8 @@ static int _cpu_up(unsigned int cpu, int tasks_frozen, enum cpuhp_state target)
11781185
}
11791186

11801187
/*
1181-
* The caller of do_cpu_up might have raced with another
1182-
* caller. Ignore it for now.
1188+
* The caller of cpu_up() might have raced with another
1189+
* caller. Nothing to do.
11831190
*/
11841191
if (st->state >= target)
11851192
goto out;
@@ -1223,7 +1230,7 @@ static int _cpu_up(unsigned int cpu, int tasks_frozen, enum cpuhp_state target)
12231230
return ret;
12241231
}
12251232

1226-
static int do_cpu_up(unsigned int cpu, enum cpuhp_state target)
1233+
static int cpu_up(unsigned int cpu, enum cpuhp_state target)
12271234
{
12281235
int err = 0;
12291236

@@ -1257,11 +1264,18 @@ static int do_cpu_up(unsigned int cpu, enum cpuhp_state target)
12571264
return err;
12581265
}
12591266

1260-
int cpu_up(unsigned int cpu)
1267+
/**
1268+
* cpu_device_up - Bring up a cpu device
1269+
* @dev: Pointer to the cpu device to online
1270+
*
1271+
* This function is meant to be used by device core cpu subsystem only.
1272+
*
1273+
* Other subsystems should use add_cpu() instead.
1274+
*/
1275+
int cpu_device_up(struct device *dev)
12611276
{
1262-
return do_cpu_up(cpu, CPUHP_ONLINE);
1277+
return cpu_up(dev->id, CPUHP_ONLINE);
12631278
}
1264-
EXPORT_SYMBOL_GPL(cpu_up);
12651279

12661280
int add_cpu(unsigned int cpu)
12671281
{
@@ -1289,7 +1303,7 @@ int bringup_hibernate_cpu(unsigned int sleep_cpu)
12891303

12901304
if (!cpu_online(sleep_cpu)) {
12911305
pr_info("Hibernated on a CPU that is offline! Bringing CPU up.\n");
1292-
ret = cpu_up(sleep_cpu);
1306+
ret = cpu_up(sleep_cpu, CPUHP_ONLINE);
12931307
if (ret) {
12941308
pr_err("Failed to bring hibernate-CPU up!\n");
12951309
return ret;
@@ -1306,7 +1320,7 @@ void bringup_nonboot_cpus(unsigned int setup_max_cpus)
13061320
if (num_online_cpus() >= setup_max_cpus)
13071321
break;
13081322
if (!cpu_online(cpu))
1309-
cpu_up(cpu);
1323+
cpu_up(cpu, CPUHP_ONLINE);
13101324
}
13111325
}
13121326

@@ -2129,9 +2143,9 @@ static ssize_t write_cpuhp_target(struct device *dev,
21292143
goto out;
21302144

21312145
if (st->state < target)
2132-
ret = do_cpu_up(dev->id, target);
2146+
ret = cpu_up(dev->id, target);
21332147
else
2134-
ret = do_cpu_down(dev->id, target);
2148+
ret = cpu_down(dev->id, target);
21352149
out:
21362150
unlock_device_hotplug();
21372151
return ret ? ret : count;

0 commit comments

Comments
 (0)