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>
117 lines
2.7 KiB
C
117 lines
2.7 KiB
C
// SPDX-License-Identifier: GPL-2.0
|
|
/*
|
|
* Copyright (C) 2020-2022 Loongson Technology Corporation Limited
|
|
*/
|
|
#include <linux/kernel.h>
|
|
#include <linux/acpi.h>
|
|
#include <linux/atomic.h>
|
|
#include <linux/delay.h>
|
|
#include <linux/init.h>
|
|
#include <linux/interrupt.h>
|
|
#include <linux/irqchip.h>
|
|
#include <linux/kernel_stat.h>
|
|
#include <linux/proc_fs.h>
|
|
#include <linux/mm.h>
|
|
#include <linux/sched.h>
|
|
#include <linux/seq_file.h>
|
|
#include <linux/kallsyms.h>
|
|
#include <linux/uaccess.h>
|
|
|
|
#include <asm/irq.h>
|
|
#include <asm/loongson.h>
|
|
#include <asm/setup.h>
|
|
|
|
DEFINE_PER_CPU(unsigned long, irq_stack);
|
|
DEFINE_PER_CPU_SHARED_ALIGNED(irq_cpustat_t, irq_stat);
|
|
EXPORT_PER_CPU_SYMBOL(irq_stat);
|
|
|
|
struct acpi_vector_group pch_group[MAX_IO_PICS];
|
|
struct acpi_vector_group msi_group[MAX_IO_PICS];
|
|
/*
|
|
* 'what should we do if we get a hw irq event on an illegal vector'.
|
|
* each architecture has to answer this themselves.
|
|
*/
|
|
void ack_bad_irq(unsigned int irq)
|
|
{
|
|
pr_warn("Unexpected IRQ # %d\n", irq);
|
|
}
|
|
|
|
atomic_t irq_err_count;
|
|
|
|
asmlinkage void spurious_interrupt(void)
|
|
{
|
|
atomic_inc(&irq_err_count);
|
|
}
|
|
|
|
int arch_show_interrupts(struct seq_file *p, int prec)
|
|
{
|
|
#ifdef CONFIG_SMP
|
|
show_ipi_list(p, prec);
|
|
#endif
|
|
seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
|
|
return 0;
|
|
}
|
|
|
|
static int __init early_pci_mcfg_parse(struct acpi_table_header *header)
|
|
{
|
|
struct acpi_table_mcfg *mcfg;
|
|
struct acpi_mcfg_allocation *mptr;
|
|
int i, n;
|
|
|
|
if (header->length < sizeof(struct acpi_table_mcfg))
|
|
return -EINVAL;
|
|
|
|
n = (header->length - sizeof(struct acpi_table_mcfg)) /
|
|
sizeof(struct acpi_mcfg_allocation);
|
|
mcfg = (struct acpi_table_mcfg *)header;
|
|
mptr = (struct acpi_mcfg_allocation *) &mcfg[1];
|
|
|
|
for (i = 0; i < n; i++, mptr++) {
|
|
msi_group[i].pci_segment = mptr->pci_segment;
|
|
pch_group[i].node = msi_group[i].node = (mptr->address >> 44) & 0xf;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static void __init init_vec_parent_group(void)
|
|
{
|
|
int i;
|
|
|
|
for (i = 0; i < MAX_IO_PICS; i++) {
|
|
msi_group[i].pci_segment = -1;
|
|
msi_group[i].node = -1;
|
|
pch_group[i].node = -1;
|
|
}
|
|
|
|
acpi_table_parse(ACPI_SIG_MCFG, early_pci_mcfg_parse);
|
|
}
|
|
|
|
void __init init_IRQ(void)
|
|
{
|
|
int i;
|
|
unsigned int order = get_order(IRQ_STACK_SIZE);
|
|
struct page *page;
|
|
|
|
clear_csr_ecfg(ECFG0_IM);
|
|
clear_csr_estat(ESTATF_IP);
|
|
|
|
init_vec_parent_group();
|
|
irqchip_init();
|
|
#ifdef CONFIG_SMP
|
|
mp_ops.init_ipi();
|
|
#endif
|
|
|
|
for (i = 0; i < NR_IRQS; i++)
|
|
irq_set_noprobe(i);
|
|
|
|
for_each_possible_cpu(i) {
|
|
page = alloc_pages_node(cpu_to_node(i), GFP_KERNEL, order);
|
|
|
|
per_cpu(irq_stack, i) = (unsigned long)page_address(page);
|
|
pr_debug("CPU%d IRQ stack at 0x%lx - 0x%lx\n", i,
|
|
per_cpu(irq_stack, i), per_cpu(irq_stack, i) + IRQ_STACK_SIZE);
|
|
}
|
|
|
|
set_csr_ecfg(ECFGF_SIP0 | ECFGF_IP0 | ECFGF_IP1 | ECFGF_IP2 | ECFGF_IPI | ECFGF_PMC);
|
|
}
|