Skip to content

Commit 5634d9c

Browse files
Merge patch series "riscv: CPU operations cleanup"
Samuel Holland <[email protected]> says: This series cleans up some duplicated and dead code around the RISC-V CPU operations, that was copied from arm64 but is not needed here. The result is a bit of memory savings and removal of a few SBI calls during boot, with no functional change. * b4-shazam-merge: riscv: Use the same CPU operations for all CPUs riscv: Remove unused members from struct cpu_operations riscv: Deduplicate code in setup_smp() Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
2 parents b7b4e4d + 62ff262 commit 5634d9c

File tree

9 files changed

+24
-95
lines changed

9 files changed

+24
-95
lines changed

arch/riscv/include/asm/cpu_ops.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,23 @@
1313
/**
1414
* struct cpu_operations - Callback operations for hotplugging CPUs.
1515
*
16-
* @name: Name of the boot protocol.
17-
* @cpu_prepare: Early one-time preparation step for a cpu. If there
18-
* is a mechanism for doing so, tests whether it is
19-
* possible to boot the given HART.
2016
* @cpu_start: Boots a cpu into the kernel.
21-
* @cpu_disable: Prepares a cpu to die. May fail for some
22-
* mechanism-specific reason, which will cause the hot
23-
* unplug to be aborted. Called from the cpu to be killed.
2417
* @cpu_stop: Makes a cpu leave the kernel. Must not fail. Called from
2518
* the cpu being stopped.
2619
* @cpu_is_stopped: Ensures a cpu has left the kernel. Called from another
2720
* cpu.
2821
*/
2922
struct cpu_operations {
30-
const char *name;
31-
int (*cpu_prepare)(unsigned int cpu);
3223
int (*cpu_start)(unsigned int cpu,
3324
struct task_struct *tidle);
3425
#ifdef CONFIG_HOTPLUG_CPU
35-
int (*cpu_disable)(unsigned int cpu);
3626
void (*cpu_stop)(void);
3727
int (*cpu_is_stopped)(unsigned int cpu);
3828
#endif
3929
};
4030

4131
extern const struct cpu_operations cpu_ops_spinwait;
42-
extern const struct cpu_operations *cpu_ops[NR_CPUS];
43-
void __init cpu_set_ops(int cpu);
32+
extern const struct cpu_operations *cpu_ops;
33+
void __init cpu_set_ops(void);
4434

4535
#endif /* ifndef __ASM_CPU_OPS_H */

arch/riscv/kernel/cpu-hotplug.c

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
bool cpu_has_hotplug(unsigned int cpu)
2020
{
21-
if (cpu_ops[cpu]->cpu_stop)
21+
if (cpu_ops->cpu_stop)
2222
return true;
2323

2424
return false;
@@ -29,25 +29,18 @@ bool cpu_has_hotplug(unsigned int cpu)
2929
*/
3030
int __cpu_disable(void)
3131
{
32-
int ret = 0;
3332
unsigned int cpu = smp_processor_id();
3433

35-
if (!cpu_ops[cpu] || !cpu_ops[cpu]->cpu_stop)
34+
if (!cpu_ops->cpu_stop)
3635
return -EOPNOTSUPP;
3736

38-
if (cpu_ops[cpu]->cpu_disable)
39-
ret = cpu_ops[cpu]->cpu_disable(cpu);
40-
41-
if (ret)
42-
return ret;
43-
4437
remove_cpu_topology(cpu);
4538
numa_remove_cpu(cpu);
4639
set_cpu_online(cpu, false);
4740
riscv_ipi_disable();
4841
irq_migrate_all_off_this_cpu();
4942

50-
return ret;
43+
return 0;
5144
}
5245

5346
#ifdef CONFIG_HOTPLUG_CPU
@@ -62,8 +55,8 @@ void arch_cpuhp_cleanup_dead_cpu(unsigned int cpu)
6255
pr_notice("CPU%u: off\n", cpu);
6356

6457
/* Verify from the firmware if the cpu is really stopped*/
65-
if (cpu_ops[cpu]->cpu_is_stopped)
66-
ret = cpu_ops[cpu]->cpu_is_stopped(cpu);
58+
if (cpu_ops->cpu_is_stopped)
59+
ret = cpu_ops->cpu_is_stopped(cpu);
6760
if (ret)
6861
pr_warn("CPU%d may not have stopped: %d\n", cpu, ret);
6962
}
@@ -77,7 +70,7 @@ void __noreturn arch_cpu_idle_dead(void)
7770

7871
cpuhp_ap_report_dead();
7972

80-
cpu_ops[smp_processor_id()]->cpu_stop();
73+
cpu_ops->cpu_stop();
8174
/* It should never reach here */
8275
BUG();
8376
}

arch/riscv/kernel/cpu_ops.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,21 @@
1313
#include <asm/sbi.h>
1414
#include <asm/smp.h>
1515

16-
const struct cpu_operations *cpu_ops[NR_CPUS] __ro_after_init;
16+
const struct cpu_operations *cpu_ops __ro_after_init = &cpu_ops_spinwait;
1717

1818
extern const struct cpu_operations cpu_ops_sbi;
1919
#ifndef CONFIG_RISCV_BOOT_SPINWAIT
2020
const struct cpu_operations cpu_ops_spinwait = {
21-
.name = "",
22-
.cpu_prepare = NULL,
2321
.cpu_start = NULL,
2422
};
2523
#endif
2624

27-
void __init cpu_set_ops(int cpuid)
25+
void __init cpu_set_ops(void)
2826
{
2927
#if IS_ENABLED(CONFIG_RISCV_SBI)
3028
if (sbi_probe_extension(SBI_EXT_HSM)) {
31-
if (!cpuid)
32-
pr_info("SBI HSM extension detected\n");
33-
cpu_ops[cpuid] = &cpu_ops_sbi;
34-
} else
29+
pr_info("SBI HSM extension detected\n");
30+
cpu_ops = &cpu_ops_sbi;
31+
}
3532
#endif
36-
cpu_ops[cpuid] = &cpu_ops_spinwait;
3733
}

arch/riscv/kernel/cpu_ops_sbi.c

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -79,23 +79,7 @@ static int sbi_cpu_start(unsigned int cpuid, struct task_struct *tidle)
7979
return sbi_hsm_hart_start(hartid, boot_addr, hsm_data);
8080
}
8181

82-
static int sbi_cpu_prepare(unsigned int cpuid)
83-
{
84-
if (!cpu_ops_sbi.cpu_start) {
85-
pr_err("cpu start method not defined for CPU [%d]\n", cpuid);
86-
return -ENODEV;
87-
}
88-
return 0;
89-
}
90-
9182
#ifdef CONFIG_HOTPLUG_CPU
92-
static int sbi_cpu_disable(unsigned int cpuid)
93-
{
94-
if (!cpu_ops_sbi.cpu_stop)
95-
return -EOPNOTSUPP;
96-
return 0;
97-
}
98-
9983
static void sbi_cpu_stop(void)
10084
{
10185
int ret;
@@ -118,11 +102,8 @@ static int sbi_cpu_is_stopped(unsigned int cpuid)
118102
#endif
119103

120104
const struct cpu_operations cpu_ops_sbi = {
121-
.name = "sbi",
122-
.cpu_prepare = sbi_cpu_prepare,
123105
.cpu_start = sbi_cpu_start,
124106
#ifdef CONFIG_HOTPLUG_CPU
125-
.cpu_disable = sbi_cpu_disable,
126107
.cpu_stop = sbi_cpu_stop,
127108
.cpu_is_stopped = sbi_cpu_is_stopped,
128109
#endif

arch/riscv/kernel/cpu_ops_spinwait.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,6 @@ static void cpu_update_secondary_bootdata(unsigned int cpuid,
3939
WRITE_ONCE(__cpu_spinwait_task_pointer[hartid], tidle);
4040
}
4141

42-
static int spinwait_cpu_prepare(unsigned int cpuid)
43-
{
44-
if (!cpu_ops_spinwait.cpu_start) {
45-
pr_err("cpu start method not defined for CPU [%d]\n", cpuid);
46-
return -ENODEV;
47-
}
48-
return 0;
49-
}
50-
5142
static int spinwait_cpu_start(unsigned int cpuid, struct task_struct *tidle)
5243
{
5344
/*
@@ -64,7 +55,5 @@ static int spinwait_cpu_start(unsigned int cpuid, struct task_struct *tidle)
6455
}
6556

6657
const struct cpu_operations cpu_ops_spinwait = {
67-
.name = "spinwait",
68-
.cpu_prepare = spinwait_cpu_prepare,
6958
.cpu_start = spinwait_cpu_start,
7059
};

arch/riscv/kernel/head.S

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <asm/page.h>
1212
#include <asm/pgtable.h>
1313
#include <asm/csr.h>
14-
#include <asm/cpu_ops_sbi.h>
1514
#include <asm/hwcap.h>
1615
#include <asm/image.h>
1716
#include <asm/scs.h>

arch/riscv/kernel/setup.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include <asm/alternative.h>
2727
#include <asm/cacheflush.h>
2828
#include <asm/cpufeature.h>
29-
#include <asm/cpu_ops.h>
3029
#include <asm/early_ioremap.h>
3130
#include <asm/pgtable.h>
3231
#include <asm/setup.h>

arch/riscv/kernel/smp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ static inline void ipi_cpu_crash_stop(unsigned int cpu, struct pt_regs *regs)
8181

8282
#ifdef CONFIG_HOTPLUG_CPU
8383
if (cpu_has_hotplug(cpu))
84-
cpu_ops[cpu]->cpu_stop();
84+
cpu_ops->cpu_stop();
8585
#endif
8686

8787
for(;;)

arch/riscv/kernel/smpboot.c

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ void __init smp_prepare_boot_cpu(void)
4949
void __init smp_prepare_cpus(unsigned int max_cpus)
5050
{
5151
int cpuid;
52-
int ret;
5352
unsigned int curr_cpuid;
5453

5554
init_cpu_topology();
@@ -66,11 +65,6 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
6665
for_each_possible_cpu(cpuid) {
6766
if (cpuid == curr_cpuid)
6867
continue;
69-
if (cpu_ops[cpuid]->cpu_prepare) {
70-
ret = cpu_ops[cpuid]->cpu_prepare(cpuid);
71-
if (ret)
72-
continue;
73-
}
7468
set_cpu_present(cpuid, true);
7569
numa_store_cpu_info(cpuid);
7670
}
@@ -125,18 +119,7 @@ static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const un
125119

126120
static void __init acpi_parse_and_init_cpus(void)
127121
{
128-
int cpuid;
129-
130-
cpu_set_ops(0);
131-
132122
acpi_table_parse_madt(ACPI_MADT_TYPE_RINTC, acpi_parse_rintc, 0);
133-
134-
for (cpuid = 1; cpuid < nr_cpu_ids; cpuid++) {
135-
if (cpuid_to_hartid_map(cpuid) != INVALID_HARTID) {
136-
cpu_set_ops(cpuid);
137-
set_cpu_possible(cpuid, true);
138-
}
139-
}
140123
}
141124
#else
142125
#define acpi_parse_and_init_cpus(...) do { } while (0)
@@ -150,8 +133,6 @@ static void __init of_parse_and_init_cpus(void)
150133
int cpuid = 1;
151134
int rc;
152135

153-
cpu_set_ops(0);
154-
155136
for_each_of_cpu_node(dn) {
156137
rc = riscv_early_of_processor_hartid(dn, &hart);
157138
if (rc < 0)
@@ -179,27 +160,28 @@ static void __init of_parse_and_init_cpus(void)
179160
if (cpuid > nr_cpu_ids)
180161
pr_warn("Total number of cpus [%d] is greater than nr_cpus option value [%d]\n",
181162
cpuid, nr_cpu_ids);
182-
183-
for (cpuid = 1; cpuid < nr_cpu_ids; cpuid++) {
184-
if (cpuid_to_hartid_map(cpuid) != INVALID_HARTID) {
185-
cpu_set_ops(cpuid);
186-
set_cpu_possible(cpuid, true);
187-
}
188-
}
189163
}
190164

191165
void __init setup_smp(void)
192166
{
167+
int cpuid;
168+
169+
cpu_set_ops();
170+
193171
if (acpi_disabled)
194172
of_parse_and_init_cpus();
195173
else
196174
acpi_parse_and_init_cpus();
175+
176+
for (cpuid = 1; cpuid < nr_cpu_ids; cpuid++)
177+
if (cpuid_to_hartid_map(cpuid) != INVALID_HARTID)
178+
set_cpu_possible(cpuid, true);
197179
}
198180

199181
static int start_secondary_cpu(int cpu, struct task_struct *tidle)
200182
{
201-
if (cpu_ops[cpu]->cpu_start)
202-
return cpu_ops[cpu]->cpu_start(cpu, tidle);
183+
if (cpu_ops->cpu_start)
184+
return cpu_ops->cpu_start(cpu, tidle);
203185

204186
return -EOPNOTSUPP;
205187
}

0 commit comments

Comments
 (0)