Skip to content

Commit f6f0c9a

Browse files
committed
LoongArch: Add SMT (Simultaneous Multi-Threading) support
Loongson-3A6000 has SMT (Simultaneous Multi-Threading) support, each physical core has two logical cores (threads). This patch add SMT probe and scheduler support via ACPI PPTT. If SCHED_SMT enabled, Loongson-3A6000 is treated as 4 cores, 8 threads; If SCHED_SMT disabled, Loongson-3A6000 is treated as 8 cores, 8 threads. Remove smp_num_siblings to support HMP (Heterogeneous Multi-Processing). Signed-off-by: Liupu Wang <[email protected]> Signed-off-by: Huacai Chen <[email protected]>
1 parent 6165002 commit f6f0c9a

File tree

7 files changed

+62
-15
lines changed

7 files changed

+62
-15
lines changed

arch/loongarch/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ config LOONGARCH
55
select ACPI
66
select ACPI_GENERIC_GSI if ACPI
77
select ACPI_MCFG if ACPI
8+
select ACPI_PPTT if ACPI
89
select ACPI_SYSTEM_POWER_STATES_SUPPORT if ACPI
910
select ARCH_BINFMT_ELF_STATE
1011
select ARCH_ENABLE_MEMORY_HOTPLUG
@@ -376,6 +377,13 @@ config EFI_STUB
376377
This kernel feature allows the kernel to be loaded directly by
377378
EFI firmware without the use of a bootloader.
378379

380+
config SCHED_SMT
381+
bool "SMT scheduler support"
382+
default y
383+
help
384+
Improves scheduler's performance when there are multiple
385+
threads in one physical core.
386+
379387
config SMP
380388
bool "Multi-Processing support"
381389
help

arch/loongarch/include/asm/acpi.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ extern int acpi_strict;
1313
extern int acpi_disabled;
1414
extern int acpi_pci_disabled;
1515
extern int acpi_noirq;
16+
extern int pptt_enabled;
1617

1718
#define acpi_os_ioremap acpi_os_ioremap
1819
void __iomem *acpi_os_ioremap(acpi_physical_address phys, acpi_size size);
@@ -30,6 +31,14 @@ static inline bool acpi_has_cpu_in_madt(void)
3031
}
3132

3233
extern struct list_head acpi_wakeup_device_list;
34+
extern struct acpi_madt_core_pic acpi_core_pic[NR_CPUS];
35+
36+
extern int __init parse_acpi_topology(void);
37+
38+
static inline u32 get_acpi_id_for_cpu(unsigned int cpu)
39+
{
40+
return acpi_core_pic[cpu_logical_map(cpu)].processor_id;
41+
}
3342

3443
#endif /* !CONFIG_ACPI */
3544

arch/loongarch/include/asm/cpu-info.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ struct cpuinfo_loongarch {
5454
struct cache_desc cache_leaves[CACHE_LEAVES_MAX];
5555
int core; /* physical core number in package */
5656
int package;/* physical package number */
57+
int global_id; /* physical global thread number */
5758
int vabits; /* Virtual Address size in bits */
5859
int pabits; /* Physical Address size in bits */
5960
unsigned int ksave_mask; /* Usable KSave mask. */

arch/loongarch/kernel/acpi.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ u64 acpi_saved_sp;
3333

3434
#define PREFIX "ACPI: "
3535

36+
struct acpi_madt_core_pic acpi_core_pic[NR_CPUS];
37+
3638
void __init __iomem * __acpi_map_table(unsigned long phys, unsigned long size)
3739
{
3840

@@ -99,6 +101,7 @@ acpi_parse_processor(union acpi_subtable_headers *header, const unsigned long en
99101

100102
acpi_table_print_madt_entry(&header->common);
101103
#ifdef CONFIG_SMP
104+
acpi_core_pic[processor->core_id] = *processor;
102105
set_processor_mask(processor->core_id, processor->flags);
103106
#endif
104107

@@ -140,6 +143,35 @@ static void __init acpi_process_madt(void)
140143
loongson_sysconf.nr_cpus = num_processors;
141144
}
142145

146+
int pptt_enabled;
147+
148+
int __init parse_acpi_topology(void)
149+
{
150+
int cpu, topology_id;
151+
152+
for_each_possible_cpu(cpu) {
153+
topology_id = find_acpi_cpu_topology(cpu, 0);
154+
if (topology_id < 0) {
155+
pr_warn("Invalid BIOS PPTT\n");
156+
return -ENOENT;
157+
}
158+
159+
if (acpi_pptt_cpu_is_thread(cpu) <= 0)
160+
cpu_data[cpu].core = topology_id;
161+
else {
162+
topology_id = find_acpi_cpu_topology(cpu, 1);
163+
if (topology_id < 0)
164+
return -ENOENT;
165+
166+
cpu_data[cpu].core = topology_id;
167+
}
168+
}
169+
170+
pptt_enabled = 1;
171+
172+
return 0;
173+
}
174+
143175
#ifndef CONFIG_SUSPEND
144176
int (*acpi_suspend_lowlevel)(void);
145177
#else

arch/loongarch/kernel/proc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ static int show_cpuinfo(struct seq_file *m, void *v)
4949
seq_printf(m, "processor\t\t: %ld\n", n);
5050
seq_printf(m, "package\t\t\t: %d\n", cpu_data[n].package);
5151
seq_printf(m, "core\t\t\t: %d\n", cpu_data[n].core);
52+
seq_printf(m, "global_id\t\t: %d\n", cpu_data[n].global_id);
5253
seq_printf(m, "CPU Family\t\t: %s\n", __cpu_family[n]);
5354
seq_printf(m, "Model Name\t\t: %s\n", __cpu_full_name[n]);
5455
seq_printf(m, "CPU Revision\t\t: 0x%02x\n", version);

arch/loongarch/kernel/smp.c

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Copyright (C) 2000, 2001 Silicon Graphics, Inc.
99
* Copyright (C) 2000, 2001, 2003 Broadcom Corporation
1010
*/
11+
#include <linux/acpi.h>
1112
#include <linux/cpu.h>
1213
#include <linux/cpumask.h>
1314
#include <linux/init.h>
@@ -37,10 +38,6 @@ EXPORT_SYMBOL(__cpu_number_map);
3738
int __cpu_logical_map[NR_CPUS]; /* Map logical to physical */
3839
EXPORT_SYMBOL(__cpu_logical_map);
3940

40-
/* Number of threads (siblings) per CPU core */
41-
int smp_num_siblings = 1;
42-
EXPORT_SYMBOL(smp_num_siblings);
43-
4441
/* Representing the threads (siblings) of each logical CPU */
4542
cpumask_t cpu_sibling_map[NR_CPUS] __read_mostly;
4643
EXPORT_SYMBOL(cpu_sibling_map);
@@ -229,9 +226,12 @@ void __init loongson_prepare_cpus(unsigned int max_cpus)
229226
{
230227
int i = 0;
231228

229+
parse_acpi_topology();
230+
232231
for (i = 0; i < loongson_sysconf.nr_cpus; i++) {
233232
set_cpu_present(i, true);
234233
csr_mail_send(0, __cpu_logical_map[i], 0);
234+
cpu_data[i].global_id = __cpu_logical_map[i];
235235
}
236236

237237
per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE;
@@ -272,10 +272,10 @@ void loongson_init_secondary(void)
272272
numa_add_cpu(cpu);
273273
#endif
274274
per_cpu(cpu_state, cpu) = CPU_ONLINE;
275-
cpu_data[cpu].core =
276-
cpu_logical_map(cpu) % loongson_sysconf.cores_per_package;
277275
cpu_data[cpu].package =
278276
cpu_logical_map(cpu) / loongson_sysconf.cores_per_package;
277+
cpu_data[cpu].core = pptt_enabled ? cpu_data[cpu].core :
278+
cpu_logical_map(cpu) % loongson_sysconf.cores_per_package;
279279
}
280280

281281
void loongson_smp_finish(void)
@@ -381,14 +381,10 @@ static inline void set_cpu_sibling_map(int cpu)
381381

382382
cpumask_set_cpu(cpu, &cpu_sibling_setup_map);
383383

384-
if (smp_num_siblings <= 1)
385-
cpumask_set_cpu(cpu, &cpu_sibling_map[cpu]);
386-
else {
387-
for_each_cpu(i, &cpu_sibling_setup_map) {
388-
if (cpus_are_siblings(cpu, i)) {
389-
cpumask_set_cpu(i, &cpu_sibling_map[cpu]);
390-
cpumask_set_cpu(cpu, &cpu_sibling_map[i]);
391-
}
384+
for_each_cpu(i, &cpu_sibling_setup_map) {
385+
if (cpus_are_siblings(cpu, i)) {
386+
cpumask_set_cpu(i, &cpu_sibling_map[cpu]);
387+
cpumask_set_cpu(cpu, &cpu_sibling_map[i]);
392388
}
393389
}
394390
}

drivers/acpi/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,10 +542,10 @@ config ACPI_PFRUT
542542

543543
if ARM64
544544
source "drivers/acpi/arm64/Kconfig"
545+
endif
545546

546547
config ACPI_PPTT
547548
bool
548-
endif
549549

550550
config ACPI_PCC
551551
bool "ACPI PCC Address Space"

0 commit comments

Comments
 (0)