Skip to content

Commit 62ff262

Browse files
SiFiveHollandpalmer-dabbelt
authored andcommitted
riscv: Use the same CPU operations for all CPUs
RISC-V provides no binding (ACPI or DT) to describe per-cpu start/stop operations, so cpu_set_ops() will always detect the same operations for every CPU. Replace the cpu_ops array with a single pointer to save space and reduce boot time. Signed-off-by: Samuel Holland <[email protected]> Reviewed-by: Conor Dooley <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 79093f3 commit 62ff262

File tree

5 files changed

+18
-23
lines changed

5 files changed

+18
-23
lines changed

arch/riscv/include/asm/cpu_ops.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct cpu_operations {
2929
};
3030

3131
extern const struct cpu_operations cpu_ops_spinwait;
32-
extern const struct cpu_operations *cpu_ops[NR_CPUS];
33-
void __init cpu_set_ops(int cpu);
32+
extern const struct cpu_operations *cpu_ops;
33+
void __init cpu_set_ops(void);
3434

3535
#endif /* ifndef __ASM_CPU_OPS_H */

arch/riscv/kernel/cpu-hotplug.c

Lines changed: 5 additions & 5 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;
@@ -31,7 +31,7 @@ int __cpu_disable(void)
3131
{
3232
unsigned int cpu = smp_processor_id();
3333

34-
if (!cpu_ops[cpu] || !cpu_ops[cpu]->cpu_stop)
34+
if (!cpu_ops->cpu_stop)
3535
return -EOPNOTSUPP;
3636

3737
remove_cpu_topology(cpu);
@@ -55,8 +55,8 @@ void arch_cpuhp_cleanup_dead_cpu(unsigned int cpu)
5555
pr_notice("CPU%u: off\n", cpu);
5656

5757
/* Verify from the firmware if the cpu is really stopped*/
58-
if (cpu_ops[cpu]->cpu_is_stopped)
59-
ret = cpu_ops[cpu]->cpu_is_stopped(cpu);
58+
if (cpu_ops->cpu_is_stopped)
59+
ret = cpu_ops->cpu_is_stopped(cpu);
6060
if (ret)
6161
pr_warn("CPU%d may not have stopped: %d\n", cpu, ret);
6262
}
@@ -70,7 +70,7 @@ void __noreturn arch_cpu_idle_dead(void)
7070

7171
cpuhp_ap_report_dead();
7272

73-
cpu_ops[smp_processor_id()]->cpu_stop();
73+
cpu_ops->cpu_stop();
7474
/* It should never reach here */
7575
BUG();
7676
}

arch/riscv/kernel/cpu_ops.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
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
@@ -22,14 +22,12 @@ const struct cpu_operations cpu_ops_spinwait = {
2222
};
2323
#endif
2424

25-
void __init cpu_set_ops(int cpuid)
25+
void __init cpu_set_ops(void)
2626
{
2727
#if IS_ENABLED(CONFIG_RISCV_SBI)
2828
if (sbi_probe_extension(SBI_EXT_HSM)) {
29-
if (!cpuid)
30-
pr_info("SBI HSM extension detected\n");
31-
cpu_ops[cpuid] = &cpu_ops_sbi;
32-
} else
29+
pr_info("SBI HSM extension detected\n");
30+
cpu_ops = &cpu_ops_sbi;
31+
}
3332
#endif
34-
cpu_ops[cpuid] = &cpu_ops_spinwait;
3533
}

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: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -166,25 +166,22 @@ void __init setup_smp(void)
166166
{
167167
int cpuid;
168168

169-
cpu_set_ops(0);
169+
cpu_set_ops();
170170

171171
if (acpi_disabled)
172172
of_parse_and_init_cpus();
173173
else
174174
acpi_parse_and_init_cpus();
175175

176-
for (cpuid = 1; cpuid < nr_cpu_ids; cpuid++) {
177-
if (cpuid_to_hartid_map(cpuid) != INVALID_HARTID) {
178-
cpu_set_ops(cpuid);
176+
for (cpuid = 1; cpuid < nr_cpu_ids; cpuid++)
177+
if (cpuid_to_hartid_map(cpuid) != INVALID_HARTID)
179178
set_cpu_possible(cpuid, true);
180-
}
181-
}
182179
}
183180

184181
static int start_secondary_cpu(int cpu, struct task_struct *tidle)
185182
{
186-
if (cpu_ops[cpu]->cpu_start)
187-
return cpu_ops[cpu]->cpu_start(cpu, tidle);
183+
if (cpu_ops->cpu_start)
184+
return cpu_ops->cpu_start(cpu, tidle);
188185

189186
return -EOPNOTSUPP;
190187
}

0 commit comments

Comments
 (0)