Skip to content

Commit 5685d7f

Browse files
seehearfeelchenhuacai
authored andcommitted
LoongArch: Give a chance to build with !CONFIG_SMP
In the current code, SMP is selected in Kconfig for LoongArch, the users can not unset it, this is reasonable for a multi-processor machine. But as the help info of config SMP said, if you have a system with only one CPU, say N. On a uni-processor machine, the kernel will run faster if you say N here. Loongson-2K0500 is a single-core CPU for applications like industrial control, printing terminals, and BMC (Baseboard Management Controller), there are many development boards, products and solutions on the market, so it is better and necessary to give a chance to build with !CONFIG_SMP for a uni-processor machine. First of all, do not select SMP for config LOONGARCH in Kconfig to make it possible to unset CONFIG_SMP. Then, do some changes to fix warnings and errors if CONFIG_SMP is not set. (1) Define get_ipi_irq() only if CONFIG_SMP is set to fix the warning: arch/loongarch/kernel/irq.c:90:19: warning: 'get_ipi_irq' defined but not used [-Wunused-function] (2) Add "#ifdef CONFIG_SMP" in asm/smp.h to fix the warning: ./arch/loongarch/include/asm/smp.h:49:9: warning: "raw_smp_processor_id" redefined 49 | #define raw_smp_processor_id raw_smp_processor_id | ^~~~~~~~~~~~~~~~~~~~ ./include/linux/smp.h:198:9: note: this is the location of the previous definition 198 | #define raw_smp_processor_id() 0 (3) Define machine_shutdown() as empty under !CONFIG_SMP to fix the error: arch/loongarch/kernel/machine_kexec.c: In function 'machine_shutdown': arch/loongarch/kernel/machine_kexec.c:233:25: error: implicit declaration of function 'cpu_device_up'; did you mean 'put_device'? [-Wimplicit-function-declaration] (4) Make config SCHED_SMT depends on SMP to fix many errors such as: kernel/sched/core.c: In function 'sched_core_find': kernel/sched/core.c:310:43: error: 'struct rq' has no member named 'cpu' (5) Define cpu_logical_map(cpu) as 0 under !CONFIG_SMP in asm/smp.h, then include asm/smp.h in asm/acpi.h (because acpi.h is included in linux/irq.h indirectly) to fix many build errors under drivers/irqchip such as: drivers/irqchip/irq-loongson-eiointc.c: In function 'cpu_to_eio_node': drivers/irqchip/irq-loongson-eiointc.c:59:16: error: implicit declaration of function 'cpu_logical_map' [-Wimplicit-function-declaration] (6) Do not write per_cpu_offset(0) to PERCPU_BASE_KS when resume because the per_cpu_offset(x) macro is defined as (__per_cpu_offset[x]) only under CONFIG_SMP in include/asm-generic/percpu.h. Just save the value of PERCPU_BASE_KS when suspend and restore it when resume to fix the error: arch/loongarch/power/suspend.c: In function 'loongarch_common_resume': arch/loongarch/power/suspend.c:47:21: error: implicit declaration of function 'per_cpu_offset' [-Wimplicit-function-declaration] (7) Fix huge page handling under !CONFIG_SMP in tlbex.S. When running the UnixBench tests with "-c 1" single-streamed pass, the improvement of performance is about 9 percent with this patch. By the way, it is helpful to debug and analysis the kernel issues of multi-processor system under !CONFIG_SMP. Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent ff4a244 commit 5685d7f

File tree

7 files changed

+20
-6
lines changed

7 files changed

+20
-6
lines changed

arch/loongarch/Kconfig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,6 @@ config LOONGARCH
178178
select PCI_QUIRKS
179179
select PERF_USE_VMALLOC
180180
select RTC_LIB
181-
select SMP
182181
select SPARSE_IRQ
183182
select SYSCTL_ARCH_UNALIGN_ALLOW
184183
select SYSCTL_ARCH_UNALIGN_NO_WARN
@@ -424,6 +423,7 @@ config EFI_STUB
424423

425424
config SCHED_SMT
426425
bool "SMT scheduler support"
426+
depends on SMP
427427
default y
428428
help
429429
Improves scheduler's performance when there are multiple

arch/loongarch/include/asm/acpi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#ifndef _ASM_LOONGARCH_ACPI_H
99
#define _ASM_LOONGARCH_ACPI_H
1010

11+
#include <asm/smp.h>
1112
#include <asm/suspend.h>
1213

1314
#ifdef CONFIG_ACPI

arch/loongarch/include/asm/smp.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#ifndef __ASM_SMP_H
77
#define __ASM_SMP_H
88

9+
#ifdef CONFIG_SMP
10+
911
#include <linux/atomic.h>
1012
#include <linux/bitops.h>
1113
#include <linux/linkage.h>
@@ -101,4 +103,8 @@ static inline void __cpu_die(unsigned int cpu)
101103
}
102104
#endif
103105

106+
#else /* !CONFIG_SMP */
107+
#define cpu_logical_map(cpu) 0
108+
#endif /* CONFIG_SMP */
109+
104110
#endif /* __ASM_SMP_H */

arch/loongarch/kernel/irq.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ static void __init init_vec_parent_group(void)
8787
acpi_table_parse(ACPI_SIG_MCFG, early_pci_mcfg_parse);
8888
}
8989

90+
#ifdef CONFIG_SMP
9091
static int __init get_ipi_irq(void)
9192
{
9293
struct irq_domain *d = irq_find_matching_fwnode(cpuintc_handle, DOMAIN_BUS_ANY);
@@ -96,6 +97,7 @@ static int __init get_ipi_irq(void)
9697

9798
return -EINVAL;
9899
}
100+
#endif
99101

100102
void __init init_IRQ(void)
101103
{

arch/loongarch/kernel/machine_kexec.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,14 @@ void crash_smp_send_stop(void)
225225

226226
void machine_shutdown(void)
227227
{
228+
#ifdef CONFIG_SMP
228229
int cpu;
229230

230231
/* All CPUs go to reboot_code_buffer */
231232
for_each_possible_cpu(cpu)
232233
if (!cpu_online(cpu))
233234
cpu_device_up(get_cpu_device(cpu));
234235

235-
#ifdef CONFIG_SMP
236236
smp_call_function(kexec_shutdown_secondary, NULL, 0);
237237
#endif
238238
}

arch/loongarch/mm/tlbex.S

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,8 @@ vmalloc_load:
125125
tlb_huge_update_load:
126126
#ifdef CONFIG_SMP
127127
ll.d ra, t1, 0
128+
#else
129+
rotri.d ra, ra, 64 - (_PAGE_HUGE_SHIFT + 1)
128130
#endif
129131
andi t0, ra, _PAGE_PRESENT
130132
beqz t0, nopage_tlb_load
@@ -135,7 +137,6 @@ tlb_huge_update_load:
135137
beqz t0, tlb_huge_update_load
136138
ori t0, ra, _PAGE_VALID
137139
#else
138-
rotri.d ra, ra, 64 - (_PAGE_HUGE_SHIFT + 1)
139140
ori t0, ra, _PAGE_VALID
140141
st.d t0, t1, 0
141142
#endif
@@ -281,6 +282,8 @@ vmalloc_store:
281282
tlb_huge_update_store:
282283
#ifdef CONFIG_SMP
283284
ll.d ra, t1, 0
285+
#else
286+
rotri.d ra, ra, 64 - (_PAGE_HUGE_SHIFT + 1)
284287
#endif
285288
andi t0, ra, _PAGE_PRESENT | _PAGE_WRITE
286289
xori t0, t0, _PAGE_PRESENT | _PAGE_WRITE
@@ -292,7 +295,6 @@ tlb_huge_update_store:
292295
beqz t0, tlb_huge_update_store
293296
ori t0, ra, (_PAGE_VALID | _PAGE_DIRTY | _PAGE_MODIFIED)
294297
#else
295-
rotri.d ra, ra, 64 - (_PAGE_HUGE_SHIFT + 1)
296298
ori t0, ra, (_PAGE_VALID | _PAGE_DIRTY | _PAGE_MODIFIED)
297299
st.d t0, t1, 0
298300
#endif
@@ -438,6 +440,8 @@ vmalloc_modify:
438440
tlb_huge_update_modify:
439441
#ifdef CONFIG_SMP
440442
ll.d ra, t1, 0
443+
#else
444+
rotri.d ra, ra, 64 - (_PAGE_HUGE_SHIFT + 1)
441445
#endif
442446
andi t0, ra, _PAGE_WRITE
443447
beqz t0, nopage_tlb_modify
@@ -448,7 +452,6 @@ tlb_huge_update_modify:
448452
beqz t0, tlb_huge_update_modify
449453
ori t0, ra, (_PAGE_VALID | _PAGE_DIRTY | _PAGE_MODIFIED)
450454
#else
451-
rotri.d ra, ra, 64 - (_PAGE_HUGE_SHIFT + 1)
452455
ori t0, ra, (_PAGE_VALID | _PAGE_DIRTY | _PAGE_MODIFIED)
453456
st.d t0, t1, 0
454457
#endif

arch/loongarch/power/suspend.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct saved_registers {
2424
u64 kpgd;
2525
u32 pwctl0;
2626
u32 pwctl1;
27+
u64 pcpu_base;
2728
};
2829
static struct saved_registers saved_regs;
2930

@@ -36,6 +37,7 @@ void loongarch_common_suspend(void)
3637
saved_regs.pwctl1 = csr_read32(LOONGARCH_CSR_PWCTL1);
3738
saved_regs.ecfg = csr_read32(LOONGARCH_CSR_ECFG);
3839
saved_regs.euen = csr_read32(LOONGARCH_CSR_EUEN);
40+
saved_regs.pcpu_base = csr_read64(PERCPU_BASE_KS);
3941

4042
loongarch_suspend_addr = loongson_sysconf.suspend_addr;
4143
}
@@ -44,7 +46,6 @@ void loongarch_common_resume(void)
4446
{
4547
sync_counter();
4648
local_flush_tlb_all();
47-
csr_write64(per_cpu_offset(0), PERCPU_BASE_KS);
4849
csr_write64(eentry, LOONGARCH_CSR_EENTRY);
4950
csr_write64(eentry, LOONGARCH_CSR_MERRENTRY);
5051
csr_write64(tlbrentry, LOONGARCH_CSR_TLBRENTRY);
@@ -55,6 +56,7 @@ void loongarch_common_resume(void)
5556
csr_write32(saved_regs.pwctl1, LOONGARCH_CSR_PWCTL1);
5657
csr_write32(saved_regs.ecfg, LOONGARCH_CSR_ECFG);
5758
csr_write32(saved_regs.euen, LOONGARCH_CSR_EUEN);
59+
csr_write64(saved_regs.pcpu_base, PERCPU_BASE_KS);
5860
}
5961

6062
int loongarch_acpi_suspend(void)

0 commit comments

Comments
 (0)