Skip to content

Commit 78d1daa

Browse files
Atish Patrapalmer-dabbelt
authored andcommitted
RISC-V: Move cpuid to hartid mapping to SMP.
Currently, logical CPU id to physical hartid mapping is defined for both smp and non-smp configurations. This is not required as we need this only for smp configuration. The mapping function can define directly boot_cpu_hartid for non-smp use case. The reverse mapping function i.e. hartid to cpuid can be called for any valid but not booted harts. So it should return default cpu 0 only if it is a boot hartid. Signed-off-by: Atish Patra <atish.patra@wdc.com> Reviewed-by: Anup Patel <anup@brainfault.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Palmer Dabbelt <palmer@sifive.com>
1 parent e15c6e3 commit 78d1daa

3 files changed

Lines changed: 22 additions & 14 deletions

File tree

‎arch/riscv/include/asm/smp.h‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@
1919
#include <linux/thread_info.h>
2020

2121
#define INVALID_HARTID ULONG_MAX
22+
23+
struct seq_file;
24+
extern unsigned long boot_cpu_hartid;
25+
26+
#ifdef CONFIG_SMP
2227
/*
2328
* Mapping between linux logical cpu index and hartid.
2429
*/
2530
extern unsigned long __cpuid_to_hartid_map[NR_CPUS];
2631
#define cpuid_to_hartid_map(cpu) __cpuid_to_hartid_map[cpu]
2732

28-
struct seq_file;
29-
30-
#ifdef CONFIG_SMP
31-
3233
/* print IPI stats */
3334
void show_ipi_stats(struct seq_file *p, int prec);
3435

@@ -58,7 +59,14 @@ static inline void show_ipi_stats(struct seq_file *p, int prec)
5859

5960
static inline int riscv_hartid_to_cpuid(int hartid)
6061
{
61-
return 0;
62+
if (hartid == boot_cpu_hartid)
63+
return 0;
64+
65+
return -1;
66+
}
67+
static inline unsigned long cpuid_to_hartid_map(int cpu)
68+
{
69+
return boot_cpu_hartid;
6270
}
6371

6472
static inline void riscv_cpuid_to_hartid_mask(const struct cpumask *in,

‎arch/riscv/kernel/setup.c‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,6 @@ EXPORT_SYMBOL(empty_zero_page);
6161
atomic_t hart_lottery;
6262
unsigned long boot_cpu_hartid;
6363

64-
unsigned long __cpuid_to_hartid_map[NR_CPUS] = {
65-
[0 ... NR_CPUS-1] = INVALID_HARTID
66-
};
67-
68-
void __init smp_setup_processor_id(void)
69-
{
70-
cpuid_to_hartid_map(0) = boot_cpu_hartid;
71-
}
72-
7364
#ifdef CONFIG_BLK_DEV_INITRD
7465
static void __init setup_initrd(void)
7566
{

‎arch/riscv/kernel/smp.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ enum ipi_message_type {
3636
IPI_MAX
3737
};
3838

39+
unsigned long __cpuid_to_hartid_map[NR_CPUS] = {
40+
[0 ... NR_CPUS-1] = INVALID_HARTID
41+
};
42+
43+
void __init smp_setup_processor_id(void)
44+
{
45+
cpuid_to_hartid_map(0) = boot_cpu_hartid;
46+
}
47+
3948
/* A collection of single bit ipi messages. */
4049
static struct {
4150
unsigned long stats[IPI_MAX] ____cacheline_aligned;

0 commit comments

Comments
 (0)