2024-03-26 12:11:43

by Tiezhu Yang

[permalink] [raw]
Subject: [PATCH v2 0/3] Give chance to build under !CONFIG_SMP for LoongArch

This patch series is based on 6.9-rc1, split the single patch of v1
to 3 patches after some thought, solve only one problem per patch.

Tiezhu Yang (3):
LoongArch: Give chance to build under !CONFIG_SMP
irqchip: Select GENERIC_IRQ_EFFECTIVE_AFF_MASK if SMP for
IRQ_LOONGARCH_CPU
irqchip: Set CPU affinity only on SMP machines for LoongArch

arch/loongarch/Kconfig | 2 +-
arch/loongarch/include/asm/acpi.h | 1 +
arch/loongarch/include/asm/smp.h | 5 +++++
arch/loongarch/kernel/irq.c | 2 ++
arch/loongarch/kernel/machine_kexec.c | 2 +-
arch/loongarch/power/suspend.c | 2 ++
drivers/irqchip/Kconfig | 2 +-
drivers/irqchip/irq-loongson-eiointc.c | 4 ++++
8 files changed, 17 insertions(+), 3 deletions(-)

--
2.42.0



2024-03-26 12:11:56

by Tiezhu Yang

[permalink] [raw]
Subject: [PATCH v2 2/3] irqchip: Select GENERIC_IRQ_EFFECTIVE_AFF_MASK if SMP for IRQ_LOONGARCH_CPU

An IRQ's effective affinity can only be different from its configured
affinity if there are multiple CPUs. Make it clear that this option is
only meaningful when SMP is enabled. Otherwise, there exists "WARNING:
unmet direct dependencies detected for GENERIC_IRQ_EFFECTIVE_AFF_MASK"
when make menuconfig if CONFIG_SMP is not set on LoongArch.

Signed-off-by: Tiezhu Yang <[email protected]>
---
drivers/irqchip/Kconfig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
index 72c07a12f5e1..bfa1d77749f3 100644
--- a/drivers/irqchip/Kconfig
+++ b/drivers/irqchip/Kconfig
@@ -568,7 +568,7 @@ config IRQ_LOONGARCH_CPU
bool
select GENERIC_IRQ_CHIP
select IRQ_DOMAIN
- select GENERIC_IRQ_EFFECTIVE_AFF_MASK
+ select GENERIC_IRQ_EFFECTIVE_AFF_MASK if SMP
select LOONGSON_HTVEC
select LOONGSON_LIOINTC
select LOONGSON_EIOINTC
--
2.42.0


2024-03-26 12:12:01

by Tiezhu Yang

[permalink] [raw]
Subject: [PATCH v2 1/3] LoongArch: Give chance to build under !CONFIG_SMP

In the current code, SMP is selected in Kconfig for LoongArch, the users
can not unset it, this is reasonable for a multiprocessor machine. But as
the help info of config SMP said, if you have a system with only one CPU,
say N. On a uniprocessor machine, the kernel will run faster if you say N
here.

The 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 under !CONFIG_SMP
for a uniprocessor 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 the warnings and
errors if CONFIG_SMP is not set.

(1) Define cpu_logical_map(cpu) as 0 under !CONFIG_SMP in asm/smp.h and
include asm/smp.h in asm/acpi.h to fix the error:
/arch/loongarch/include/asm/acpi.h: In function ‘get_acpi_id_for_cpu’:
/arch/loongarch/include/asm/acpi.h:44:30: error: implicit declaration of function ‘cpu_logical_map’ [-Wimplicit-function-declaration]

(2) 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]

(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 avoid 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) Call per_cpu_offset() only under CONFIG_HAVE_SETUP_PER_CPU_AREA 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]

When running the UnixBench tests with "-c 1" single-streamed pass,
the improvement in performance is about 9 percent with this patch.

By the way, it is helpful to debug and analysis the kernel issue
of multi-core system under !CONFIG_SMP.

Signed-off-by: Tiezhu Yang <[email protected]>
---
arch/loongarch/Kconfig | 2 +-
arch/loongarch/include/asm/acpi.h | 1 +
arch/loongarch/include/asm/smp.h | 5 +++++
arch/loongarch/kernel/irq.c | 2 ++
arch/loongarch/kernel/machine_kexec.c | 2 +-
arch/loongarch/power/suspend.c | 2 ++
6 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/arch/loongarch/Kconfig b/arch/loongarch/Kconfig
index a5f300ec6f28..8d892de0b7a8 100644
--- a/arch/loongarch/Kconfig
+++ b/arch/loongarch/Kconfig
@@ -174,7 +174,6 @@ config LOONGARCH
select PCI_QUIRKS
select PERF_USE_VMALLOC
select RTC_LIB
- select SMP
select SPARSE_IRQ
select SYSCTL_ARCH_UNALIGN_ALLOW
select SYSCTL_ARCH_UNALIGN_NO_WARN
@@ -420,6 +419,7 @@ config EFI_STUB

config SCHED_SMT
bool "SMT scheduler support"
+ depends on SMP
default y
help
Improves scheduler's performance when there are multiple
diff --git a/arch/loongarch/include/asm/acpi.h b/arch/loongarch/include/asm/acpi.h
index 49e29b29996f..313f66f7913a 100644
--- a/arch/loongarch/include/asm/acpi.h
+++ b/arch/loongarch/include/asm/acpi.h
@@ -8,6 +8,7 @@
#ifndef _ASM_LOONGARCH_ACPI_H
#define _ASM_LOONGARCH_ACPI_H

+#include <asm/smp.h>
#include <asm/suspend.h>

#ifdef CONFIG_ACPI
diff --git a/arch/loongarch/include/asm/smp.h b/arch/loongarch/include/asm/smp.h
index f81e5f01d619..c14ddfcd4829 100644
--- a/arch/loongarch/include/asm/smp.h
+++ b/arch/loongarch/include/asm/smp.h
@@ -6,6 +6,7 @@
#ifndef __ASM_SMP_H
#define __ASM_SMP_H

+#ifdef CONFIG_SMP
#include <linux/atomic.h>
#include <linux/bitops.h>
#include <linux/linkage.h>
@@ -101,4 +102,8 @@ static inline void __cpu_die(unsigned int cpu)
}
#endif

+#else /* !CONFIG_SMP */
+#define cpu_logical_map(cpu) 0
+#endif
+
#endif /* __ASM_SMP_H */
diff --git a/arch/loongarch/kernel/irq.c b/arch/loongarch/kernel/irq.c
index 883e5066ae44..e791fa275ec5 100644
--- a/arch/loongarch/kernel/irq.c
+++ b/arch/loongarch/kernel/irq.c
@@ -87,6 +87,7 @@ static void __init init_vec_parent_group(void)
acpi_table_parse(ACPI_SIG_MCFG, early_pci_mcfg_parse);
}

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

return -EINVAL;
}
+#endif

void __init init_IRQ(void)
{
diff --git a/arch/loongarch/kernel/machine_kexec.c b/arch/loongarch/kernel/machine_kexec.c
index 2dcb9e003657..8ae641dc53bb 100644
--- a/arch/loongarch/kernel/machine_kexec.c
+++ b/arch/loongarch/kernel/machine_kexec.c
@@ -225,6 +225,7 @@ void crash_smp_send_stop(void)

void machine_shutdown(void)
{
+#ifdef CONFIG_SMP
int cpu;

/* All CPUs go to reboot_code_buffer */
@@ -232,7 +233,6 @@ void machine_shutdown(void)
if (!cpu_online(cpu))
cpu_device_up(get_cpu_device(cpu));

-#ifdef CONFIG_SMP
smp_call_function(kexec_shutdown_secondary, NULL, 0);
#endif
}
diff --git a/arch/loongarch/power/suspend.c b/arch/loongarch/power/suspend.c
index 166d9e06a64b..e8ca77eb3288 100644
--- a/arch/loongarch/power/suspend.c
+++ b/arch/loongarch/power/suspend.c
@@ -44,7 +44,9 @@ void loongarch_common_resume(void)
{
sync_counter();
local_flush_tlb_all();
+#ifdef CONFIG_HAVE_SETUP_PER_CPU_AREA
csr_write64(per_cpu_offset(0), PERCPU_BASE_KS);
+#endif
csr_write64(eentry, LOONGARCH_CSR_EENTRY);
csr_write64(eentry, LOONGARCH_CSR_MERRENTRY);
csr_write64(tlbrentry, LOONGARCH_CSR_TLBRENTRY);
--
2.42.0


2024-03-26 12:12:12

by Tiezhu Yang

[permalink] [raw]
Subject: [PATCH v2 3/3] irqchip: Set CPU affinity only on SMP machines for LoongArch

According to the code comment of "struct irq_chip" in include/linux/irq.h,
the member "irq_set_affinity" is to set the CPU affinity on SMP machines,
so define and call eiointc_set_irq_affinity() only under CONFIG_SMP.

Signed-off-by: Tiezhu Yang <[email protected]>
---
drivers/irqchip/irq-loongson-eiointc.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/irqchip/irq-loongson-eiointc.c b/drivers/irqchip/irq-loongson-eiointc.c
index b64cbe3052e8..4f5e6d21d77d 100644
--- a/drivers/irqchip/irq-loongson-eiointc.c
+++ b/drivers/irqchip/irq-loongson-eiointc.c
@@ -59,6 +59,7 @@ static int cpu_to_eio_node(int cpu)
return cpu_logical_map(cpu) / CORES_PER_EIO_NODE;
}

+#ifdef CONFIG_SMP
static void eiointc_set_irq_route(int pos, unsigned int cpu, unsigned int mnode, nodemask_t *node_map)
{
int i, node, cpu_node, route_node;
@@ -126,6 +127,7 @@ static int eiointc_set_irq_affinity(struct irq_data *d, const struct cpumask *af

return IRQ_SET_MASK_OK;
}
+#endif

static int eiointc_index(int node)
{
@@ -238,7 +240,9 @@ static struct irq_chip eiointc_irq_chip = {
.irq_ack = eiointc_ack_irq,
.irq_mask = eiointc_mask_irq,
.irq_unmask = eiointc_unmask_irq,
+#ifdef CONFIG_SMP
.irq_set_affinity = eiointc_set_irq_affinity,
+#endif
};

static int eiointc_domain_alloc(struct irq_domain *domain, unsigned int virq,
--
2.42.0


Subject: [tip: irq/core] irqchip/loongson-eiointc: Set CPU affinity only on SMP machines for LoongArch

The following commit has been merged into the irq/core branch of tip:

Commit-ID: a64003da0ef8e135cda678eb2c8a6f0baf4a9f35
Gitweb: https://git.kernel.org/tip/a64003da0ef8e135cda678eb2c8a6f0baf4a9f35
Author: Tiezhu Yang <[email protected]>
AuthorDate: Tue, 26 Mar 2024 20:11:30 +08:00
Committer: Thomas Gleixner <[email protected]>
CommitterDate: Tue, 09 Apr 2024 11:03:16 +02:00

irqchip/loongson-eiointc: Set CPU affinity only on SMP machines for LoongArch

According to the code comment of "struct irq_chip", the member
"irq_set_affinity" is to set the CPU affinity on SMP machines, so define
and call eiointc_set_irq_affinity() only under CONFIG_SMP.

Signed-off-by: Tiezhu Yang <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
---
drivers/irqchip/irq-loongson-eiointc.c | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/drivers/irqchip/irq-loongson-eiointc.c b/drivers/irqchip/irq-loongson-eiointc.c
index b64cbe3..4f5e6d2 100644
--- a/drivers/irqchip/irq-loongson-eiointc.c
+++ b/drivers/irqchip/irq-loongson-eiointc.c
@@ -59,6 +59,7 @@ static int cpu_to_eio_node(int cpu)
return cpu_logical_map(cpu) / CORES_PER_EIO_NODE;
}

+#ifdef CONFIG_SMP
static void eiointc_set_irq_route(int pos, unsigned int cpu, unsigned int mnode, nodemask_t *node_map)
{
int i, node, cpu_node, route_node;
@@ -126,6 +127,7 @@ static int eiointc_set_irq_affinity(struct irq_data *d, const struct cpumask *af

return IRQ_SET_MASK_OK;
}
+#endif

static int eiointc_index(int node)
{
@@ -238,7 +240,9 @@ static struct irq_chip eiointc_irq_chip = {
.irq_ack = eiointc_ack_irq,
.irq_mask = eiointc_mask_irq,
.irq_unmask = eiointc_unmask_irq,
+#ifdef CONFIG_SMP
.irq_set_affinity = eiointc_set_irq_affinity,
+#endif
};

static int eiointc_domain_alloc(struct irq_domain *domain, unsigned int virq,

Subject: [tip: irq/core] irqchip/loongson: Select GENERIC_IRQ_EFFECTIVE_AFF_MASK if SMP for IRQ_LOONGARCH_CPU

The following commit has been merged into the irq/core branch of tip:

Commit-ID: 42a7d887664b02a747ef5d479f6fd01081564af8
Gitweb: https://git.kernel.org/tip/42a7d887664b02a747ef5d479f6fd01081564af8
Author: Tiezhu Yang <[email protected]>
AuthorDate: Tue, 26 Mar 2024 20:11:29 +08:00
Committer: Thomas Gleixner <[email protected]>
CommitterDate: Tue, 09 Apr 2024 11:03:16 +02:00

irqchip/loongson: Select GENERIC_IRQ_EFFECTIVE_AFF_MASK if SMP for IRQ_LOONGARCH_CPU

An interrupt's effective affinity can only be different from its configured
affinity if there are multiple CPUs. Make it clear that this option is only
meaningful when SMP is enabled. Otherwise, there exists "WARNING: unmet
direct dependencies detected for GENERIC_IRQ_EFFECTIVE_AFF_MASK" when make
menuconfig if CONFIG_SMP is not set on LoongArch.

Signed-off-by: Tiezhu Yang <[email protected]>
Signed-off-by: Thomas Gleixner <[email protected]>
Link: https://lore.kernel.org/r/[email protected]

---
drivers/irqchip/Kconfig | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
index 687d17e..1446471 100644
--- a/drivers/irqchip/Kconfig
+++ b/drivers/irqchip/Kconfig
@@ -593,7 +593,7 @@ config IRQ_LOONGARCH_CPU
bool
select GENERIC_IRQ_CHIP
select IRQ_DOMAIN
- select GENERIC_IRQ_EFFECTIVE_AFF_MASK
+ select GENERIC_IRQ_EFFECTIVE_AFF_MASK if SMP
select LOONGSON_HTVEC
select LOONGSON_LIOINTC
select LOONGSON_EIOINTC