2024-04-11 01:05:28

by Tiezhu Yang

[permalink] [raw]
Subject: [PATCH v3 2/4] LoongArch: Refactor get_acpi_id_for_cpu() related code

Currently, cpu_logical_map(cpu) is defined as __cpu_logical_map[cpu]
in arch/loongarch/include/asm/smp.h and __cpu_logical_map[] is defined
in arch/loongarch/kernel/smp.c, that is to say, cpu_logical_map(cpu) is
vaild only under CONFIG_SMP, the implementation of get_acpi_id_for_cpu()
which calls cpu_logical_map(cpu) is not suitable for the case of non-SMP,
so refactor get_acpi_id_for_cpu() related code to make it work well for
both SMP and non-SMP.

Signed-off-by: Tiezhu Yang <[email protected]>
---
arch/loongarch/include/asm/acpi.h | 7 ++++++-
arch/loongarch/kernel/acpi.c | 9 ++++++++-
2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/arch/loongarch/include/asm/acpi.h b/arch/loongarch/include/asm/acpi.h
index 49e29b29996f..a4ad3f75bd60 100644
--- a/arch/loongarch/include/asm/acpi.h
+++ b/arch/loongarch/include/asm/acpi.h
@@ -39,9 +39,14 @@ extern struct acpi_madt_core_pic acpi_core_pic[MAX_CORE_PIC];

extern int __init parse_acpi_topology(void);

+static inline struct acpi_madt_core_pic *acpi_cpu_get_core_pic(int cpu)
+{
+ return &acpi_core_pic[cpu];
+}
+
static inline u32 get_acpi_id_for_cpu(unsigned int cpu)
{
- return acpi_core_pic[cpu_logical_map(cpu)].processor_id;
+ return acpi_cpu_get_core_pic(cpu)->processor_id;
}

#endif /* !CONFIG_ACPI */
diff --git a/arch/loongarch/kernel/acpi.c b/arch/loongarch/kernel/acpi.c
index 5cf59c617126..ccfa90faf0ea 100644
--- a/arch/loongarch/kernel/acpi.c
+++ b/arch/loongarch/kernel/acpi.c
@@ -98,8 +98,15 @@ acpi_parse_processor(union acpi_subtable_headers *header, const unsigned long en
return -EINVAL;

acpi_table_print_madt_entry(&header->common);
+
+ /*
+ * When CONFIG_SMP is disabled, mapping won't be created for all cpus.
+ * CPUs more than num_possible_cpus will be ignored.
+ */
+ if (processor->core_id >= 0 && processor->core_id < num_possible_cpus())
+ acpi_core_pic[processor->core_id] = *processor;
+
#ifdef CONFIG_SMP
- acpi_core_pic[processor->core_id] = *processor;
set_processor_mask(processor->core_id, processor->flags);
#endif

--
2.42.0



2024-04-12 04:18:12

by Huacai Chen

[permalink] [raw]
Subject: Re: [PATCH v3 2/4] LoongArch: Refactor get_acpi_id_for_cpu() related code

Hi, Tiezhu,

On Thu, Apr 11, 2024 at 9:05 AM Tiezhu Yang <[email protected]> wrote:
>
> Currently, cpu_logical_map(cpu) is defined as __cpu_logical_map[cpu]
> in arch/loongarch/include/asm/smp.h and __cpu_logical_map[] is defined
> in arch/loongarch/kernel/smp.c, that is to say, cpu_logical_map(cpu) is
> vaild only under CONFIG_SMP, the implementation of get_acpi_id_for_cpu()
> which calls cpu_logical_map(cpu) is not suitable for the case of non-SMP,
> so refactor get_acpi_id_for_cpu() related code to make it work well for
> both SMP and non-SMP.
But you implement cpu_logical_map(cpu) for non-SMP in the 4th patch, right?

Huacai
>
> Signed-off-by: Tiezhu Yang <[email protected]>
> ---
> arch/loongarch/include/asm/acpi.h | 7 ++++++-
> arch/loongarch/kernel/acpi.c | 9 ++++++++-
> 2 files changed, 14 insertions(+), 2 deletions(-)
>
> diff --git a/arch/loongarch/include/asm/acpi.h b/arch/loongarch/include/asm/acpi.h
> index 49e29b29996f..a4ad3f75bd60 100644
> --- a/arch/loongarch/include/asm/acpi.h
> +++ b/arch/loongarch/include/asm/acpi.h
> @@ -39,9 +39,14 @@ extern struct acpi_madt_core_pic acpi_core_pic[MAX_CORE_PIC];
>
> extern int __init parse_acpi_topology(void);
>
> +static inline struct acpi_madt_core_pic *acpi_cpu_get_core_pic(int cpu)
> +{
> + return &acpi_core_pic[cpu];
> +}
> +
> static inline u32 get_acpi_id_for_cpu(unsigned int cpu)
> {
> - return acpi_core_pic[cpu_logical_map(cpu)].processor_id;
> + return acpi_cpu_get_core_pic(cpu)->processor_id;
> }
>
> #endif /* !CONFIG_ACPI */
> diff --git a/arch/loongarch/kernel/acpi.c b/arch/loongarch/kernel/acpi.c
> index 5cf59c617126..ccfa90faf0ea 100644
> --- a/arch/loongarch/kernel/acpi.c
> +++ b/arch/loongarch/kernel/acpi.c
> @@ -98,8 +98,15 @@ acpi_parse_processor(union acpi_subtable_headers *header, const unsigned long en
> return -EINVAL;
>
> acpi_table_print_madt_entry(&header->common);
> +
> + /*
> + * When CONFIG_SMP is disabled, mapping won't be created for all cpus.
> + * CPUs more than num_possible_cpus will be ignored.
> + */
> + if (processor->core_id >= 0 && processor->core_id < num_possible_cpus())
> + acpi_core_pic[processor->core_id] = *processor;
> +
> #ifdef CONFIG_SMP
> - acpi_core_pic[processor->core_id] = *processor;
> set_processor_mask(processor->core_id, processor->flags);
> #endif
>
> --
> 2.42.0
>

2024-04-12 09:29:04

by Tiezhu Yang

[permalink] [raw]
Subject: Re: [PATCH v3 2/4] LoongArch: Refactor get_acpi_id_for_cpu() related code



On 04/12/2024 12:17 PM, Huacai Chen wrote:
> Hi, Tiezhu,
>
> On Thu, Apr 11, 2024 at 9:05 AM Tiezhu Yang <[email protected]> wrote:
>>
>> Currently, cpu_logical_map(cpu) is defined as __cpu_logical_map[cpu]
>> in arch/loongarch/include/asm/smp.h and __cpu_logical_map[] is defined
>> in arch/loongarch/kernel/smp.c, that is to say, cpu_logical_map(cpu) is
>> vaild only under CONFIG_SMP, the implementation of get_acpi_id_for_cpu()
>> which calls cpu_logical_map(cpu) is not suitable for the case of non-SMP,
>> so refactor get_acpi_id_for_cpu() related code to make it work well for
>> both SMP and non-SMP.
> But you implement cpu_logical_map(cpu) for non-SMP in the 4th patch, right?

The initial aim is to make get_acpi_id_for_cpu() only related with
acpi stuff and referenced the following riscv code, this patch can
be dropped if you think it is better to only define cpu_logical_map(cpu)
under !CONFIG_SMP, I am not sure whether it needs to keep the changes
in acpi.c at least.

static int acpi_parse_madt_rintc(union acpi_subtable_headers *header,
const unsigned long end)
{
struct acpi_madt_rintc *rintc = (struct acpi_madt_rintc *)header;
int cpuid;

if (!(rintc->flags & ACPI_MADT_ENABLED))
return 0;

cpuid = riscv_hartid_to_cpuid(rintc->hart_id);
/*
* When CONFIG_SMP is disabled, mapping won't be created for
* all cpus.
* CPUs more than num_possible_cpus, will be ignored.
*/
if (cpuid >= 0 && cpuid < num_possible_cpus())
cpu_madt_rintc[cpuid] = *rintc;

return 0;
}

struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu)
{
return &cpu_madt_rintc[cpu];
}

u32 get_acpi_id_for_cpu(int cpu)
{
return acpi_cpu_get_madt_rintc(cpu)->uid;
}

https://elixir.bootlin.com/linux/v6.9-rc3/source/arch/riscv/kernel/acpi.c#L194

Thanks,
Tiezhu