mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v3] LoongArch: Correct the calculation logic of thread_count
@ 2025-11-27 10:19 Qiang Ma
  2025-11-27 12:08 ` Huacai Chen
  0 siblings, 1 reply; 2+ messages in thread
From: Qiang Ma @ 2025-11-27 10:19 UTC (permalink / raw)
  To: chenhuacai, kernel, hengqi.chen; +Cc: loongarch, linux-kernel, Qiang Ma

For thread_count, the current calculation method has a maximum of 255,
which may not be sufficient in the future. Therefore, we are correcting
it now.

Reference: SMBIOS Specification, 7.5 Processor Information (Type 4)[1]

[1]: https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.9.0.pdf

Signed-off-by: Qiang Ma <maqianga@uniontech.com>
---
 arch/loongarch/kernel/setup.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c
index 25a87378e48e..eb6e3ac27436 100644
--- a/arch/loongarch/kernel/setup.c
+++ b/arch/loongarch/kernel/setup.c
@@ -56,6 +56,7 @@
 #define SMBIOS_FREQLOW_MASK		0xFF
 #define SMBIOS_CORE_PACKAGE_OFFSET	0x23
 #define SMBIOS_THREAD_PACKAGE_OFFSET	0x25
+#define SMBIOS_THREAD_PACKAGE_2_OFFSET	0x2E
 #define LOONGSON_EFI_ENABLE		(1 << 3)
 
 unsigned long fw_arg0, fw_arg1, fw_arg2;
@@ -126,7 +127,12 @@ static void __init parse_cpu_table(const struct dmi_header *dm)
 	cpu_clock_freq = freq_temp * 1000000;
 
 	loongson_sysconf.cpuname = (void *)dmi_string_parse(dm, dmi_data[16]);
-	loongson_sysconf.cores_per_package = *(dmi_data + SMBIOS_THREAD_PACKAGE_OFFSET);
+	loongson_sysconf.cores_per_package = *(u8 *)(dmi_data + SMBIOS_THREAD_PACKAGE_OFFSET);
+	if (dm->length >= 0x30 && loongson_sysconf.cores_per_package == 0xff) {
+		/* SMBIOS 3.0+ has ThreadCount2 for more than 255 threads */
+		loongson_sysconf.cores_per_package =
+				*(u16 *)(dmi_data + SMBIOS_THREAD_PACKAGE_2_OFFSET);
+	}
 
 	pr_info("CpuClock = %llu\n", cpu_clock_freq);
 }
-- 
2.20.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH v3] LoongArch: Correct the calculation logic of thread_count
  2025-11-27 10:19 [PATCH v3] LoongArch: Correct the calculation logic of thread_count Qiang Ma
@ 2025-11-27 12:08 ` Huacai Chen
  0 siblings, 0 replies; 2+ messages in thread
From: Huacai Chen @ 2025-11-27 12:08 UTC (permalink / raw)
  To: Qiang Ma; +Cc: kernel, hengqi.chen, loongarch, linux-kernel

Applied, thanks.

Huacai

On Thu, Nov 27, 2025 at 6:21 PM Qiang Ma <maqianga@uniontech.com> wrote:
>
> For thread_count, the current calculation method has a maximum of 255,
> which may not be sufficient in the future. Therefore, we are correcting
> it now.
>
> Reference: SMBIOS Specification, 7.5 Processor Information (Type 4)[1]
>
> [1]: https://www.dmtf.org/sites/default/files/standards/documents/DSP0134_3.9.0.pdf
>
> Signed-off-by: Qiang Ma <maqianga@uniontech.com>
> ---
>  arch/loongarch/kernel/setup.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/arch/loongarch/kernel/setup.c b/arch/loongarch/kernel/setup.c
> index 25a87378e48e..eb6e3ac27436 100644
> --- a/arch/loongarch/kernel/setup.c
> +++ b/arch/loongarch/kernel/setup.c
> @@ -56,6 +56,7 @@
>  #define SMBIOS_FREQLOW_MASK            0xFF
>  #define SMBIOS_CORE_PACKAGE_OFFSET     0x23
>  #define SMBIOS_THREAD_PACKAGE_OFFSET   0x25
> +#define SMBIOS_THREAD_PACKAGE_2_OFFSET 0x2E
>  #define LOONGSON_EFI_ENABLE            (1 << 3)
>
>  unsigned long fw_arg0, fw_arg1, fw_arg2;
> @@ -126,7 +127,12 @@ static void __init parse_cpu_table(const struct dmi_header *dm)
>         cpu_clock_freq = freq_temp * 1000000;
>
>         loongson_sysconf.cpuname = (void *)dmi_string_parse(dm, dmi_data[16]);
> -       loongson_sysconf.cores_per_package = *(dmi_data + SMBIOS_THREAD_PACKAGE_OFFSET);
> +       loongson_sysconf.cores_per_package = *(u8 *)(dmi_data + SMBIOS_THREAD_PACKAGE_OFFSET);
> +       if (dm->length >= 0x30 && loongson_sysconf.cores_per_package == 0xff) {
> +               /* SMBIOS 3.0+ has ThreadCount2 for more than 255 threads */
> +               loongson_sysconf.cores_per_package =
> +                               *(u16 *)(dmi_data + SMBIOS_THREAD_PACKAGE_2_OFFSET);
> +       }
>
>         pr_info("CpuClock = %llu\n", cpu_clock_freq);
>  }
> --
> 2.20.1
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-11-27 12:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-27 10:19 [PATCH v3] LoongArch: Correct the calculation logic of thread_count Qiang Ma
2025-11-27 12:08 ` Huacai Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®