mirror of
https://github.com/torvalds/linux.git
synced 2024-11-28 23:21:31 +00:00
5685d7fcb5
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>
76 lines
1.8 KiB
C
76 lines
1.8 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* loongson-specific suspend support
|
|
*
|
|
* Author: Huacai Chen <chenhuacai@loongson.cn>
|
|
* Copyright (C) 2020-2022 Loongson Technology Corporation Limited
|
|
*/
|
|
#include <linux/acpi.h>
|
|
#include <linux/pm.h>
|
|
#include <linux/suspend.h>
|
|
|
|
#include <asm/loongarch.h>
|
|
#include <asm/loongson.h>
|
|
#include <asm/setup.h>
|
|
#include <asm/time.h>
|
|
#include <asm/tlbflush.h>
|
|
|
|
u64 loongarch_suspend_addr;
|
|
|
|
struct saved_registers {
|
|
u32 ecfg;
|
|
u32 euen;
|
|
u64 pgd;
|
|
u64 kpgd;
|
|
u32 pwctl0;
|
|
u32 pwctl1;
|
|
u64 pcpu_base;
|
|
};
|
|
static struct saved_registers saved_regs;
|
|
|
|
void loongarch_common_suspend(void)
|
|
{
|
|
save_counter();
|
|
saved_regs.pgd = csr_read64(LOONGARCH_CSR_PGDL);
|
|
saved_regs.kpgd = csr_read64(LOONGARCH_CSR_PGDH);
|
|
saved_regs.pwctl0 = csr_read32(LOONGARCH_CSR_PWCTL0);
|
|
saved_regs.pwctl1 = csr_read32(LOONGARCH_CSR_PWCTL1);
|
|
saved_regs.ecfg = csr_read32(LOONGARCH_CSR_ECFG);
|
|
saved_regs.euen = csr_read32(LOONGARCH_CSR_EUEN);
|
|
saved_regs.pcpu_base = csr_read64(PERCPU_BASE_KS);
|
|
|
|
loongarch_suspend_addr = loongson_sysconf.suspend_addr;
|
|
}
|
|
|
|
void loongarch_common_resume(void)
|
|
{
|
|
sync_counter();
|
|
local_flush_tlb_all();
|
|
csr_write64(eentry, LOONGARCH_CSR_EENTRY);
|
|
csr_write64(eentry, LOONGARCH_CSR_MERRENTRY);
|
|
csr_write64(tlbrentry, LOONGARCH_CSR_TLBRENTRY);
|
|
|
|
csr_write64(saved_regs.pgd, LOONGARCH_CSR_PGDL);
|
|
csr_write64(saved_regs.kpgd, LOONGARCH_CSR_PGDH);
|
|
csr_write32(saved_regs.pwctl0, LOONGARCH_CSR_PWCTL0);
|
|
csr_write32(saved_regs.pwctl1, LOONGARCH_CSR_PWCTL1);
|
|
csr_write32(saved_regs.ecfg, LOONGARCH_CSR_ECFG);
|
|
csr_write32(saved_regs.euen, LOONGARCH_CSR_EUEN);
|
|
csr_write64(saved_regs.pcpu_base, PERCPU_BASE_KS);
|
|
}
|
|
|
|
int loongarch_acpi_suspend(void)
|
|
{
|
|
enable_gpe_wakeup();
|
|
enable_pci_wakeup();
|
|
|
|
loongarch_common_suspend();
|
|
|
|
/* processor specific suspend */
|
|
loongarch_suspend_enter();
|
|
|
|
loongarch_common_resume();
|
|
|
|
return 0;
|
|
}
|