Skip to content

Commit 009ee0c

Browse files
committed
LoongArch: Add HOTPLUG_SMT implementation
For benchmarking or debugging purpose, we usually want to control SMT via boot parameter and sysfs knobs. So add HOTPLUG_SMT implementation. 1. Boot parameters: nosmt: Disable SMT, can be enabled via sysfs knobs. nosmt=force: Disable SMT, cannot be enabled via sysfs knobs. 2. Runtime sysfs controls: Write "on", "off", "forceoff" or the number of SMT threads (1, 2, ...) to /sys/devices/system/cpu/smt/control. Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent 94b0c83 commit 009ee0c

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

Documentation/admin-guide/kernel-parameters.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4585,7 +4585,7 @@ Kernel parameters
45854585
nosmt [KNL,MIPS,PPC,EARLY] Disable symmetric multithreading (SMT).
45864586
Equivalent to smt=1.
45874587

4588-
[KNL,X86,PPC,S390] Disable symmetric multithreading (SMT).
4588+
[KNL,LOONGARCH,X86,PPC,S390] Disable symmetric multithreading (SMT).
45894589
nosmt=force: Force disable SMT, cannot be undone
45904590
via the sysfs control file.
45914591

arch/loongarch/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ config LOONGARCH
186186
select HAVE_SYSCALL_TRACEPOINTS
187187
select HAVE_TIF_NOHZ
188188
select HAVE_VIRT_CPU_ACCOUNTING_GEN
189+
select HOTPLUG_SMT if HOTPLUG_CPU
189190
select IRQ_FORCED_THREADING
190191
select IRQ_LOONGARCH_CPU
191192
select LOCK_MM_AND_FIND_VMA

arch/loongarch/kernel/smp.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,16 +365,29 @@ void __init loongson_smp_setup(void)
365365
void __init loongson_prepare_cpus(unsigned int max_cpus)
366366
{
367367
int i = 0;
368+
int threads_per_core = 0;
368369

369370
parse_acpi_topology();
370371
cpu_data[0].global_id = cpu_logical_map(0);
371372

373+
if (!pptt_enabled)
374+
threads_per_core = 1;
375+
else {
376+
for_each_possible_cpu(i) {
377+
if (cpu_to_node(i) != 0)
378+
continue;
379+
if (cpus_are_siblings(0, i))
380+
threads_per_core++;
381+
}
382+
}
383+
372384
for (i = 0; i < loongson_sysconf.nr_cpus; i++) {
373385
set_cpu_present(i, true);
374386
csr_mail_send(0, __cpu_logical_map[i], 0);
375387
}
376388

377389
per_cpu(cpu_state, smp_processor_id()) = CPU_ONLINE;
390+
cpu_smt_set_num_threads(threads_per_core, threads_per_core);
378391
}
379392

380393
/*

0 commit comments

Comments
 (0)