Skip to contentSkip to conversation

*** Simplify RISC-V IPI code ***

PATCH Applied shannmu 4 participants 5 messages Dec 12, 2024 – Jan 1, 2025

Subsystems (2)
lore
Share & tools
lore

shannmu

author
#0 lore raw

cover *** Simplify RISC-V IPI code ***

RISC-V is different from aarch64. AArch64 has SGI0-15 and use SGI0-7 to send IPIs, so we introduced a feature that we handle inband ipis multiplexed over SGI0. But RISC-V only has one register to inform IPI and the ipi_types are recorded in the PER_CPU variables, which can store sizeof(atomic_t) bits. So we don't need to use the same way to send IPIs. We can simplify the code by unifying the IPI handling code and sending code for oob and inband ipis.

shannmu (1):
riscv: irq_pipeline: simplify the send and handle operation for ipis

 arch/riscv/include/asm/irq_pipeline.h |  18 +++--
 arch/riscv/kernel/sbi-ipi.c           |  10 ++-
 arch/riscv/kernel/smp.c               | 102 ++++++++------------------
 drivers/clocksource/timer-clint.c     |   8 ++
 4 files changed, 59 insertions(+), 79 deletions(-)
Signature · 1 line
2.34.1
author
#1 lore raw

PATCH 1/1 riscv: irq_pipeline: simplify the send and handle operation for ipis

riscv is different from aarch64 and we don't need to encode and decode inband ipis multiplexed over ipi_desc[0], because we can alloc for up to BITS_PER_TYPE(int) ipis. So we could introudce more OOB_XXX ipi_message_types and treat them as inband ipi.

---
 arch/riscv/include/asm/irq_pipeline.h |  18 +++--
 arch/riscv/kernel/sbi-ipi.c           |  10 ++-
 arch/riscv/kernel/smp.c               | 102 ++++++++------------------
 drivers/clocksource/timer-clint.c     |   8 ++
 4 files changed, 59 insertions(+), 79 deletions(-)
arch/riscv/include/asm/irq_pipeline.h +10 -8
index 2ef91c2af706..030823745787 100644
@@ -9,17 +9,19 @@
 #ifndef _ASM_RISCV_IRQ_PIPELINE_H
 #define _ASM_RISCV_IRQ_PIPELINE_H
 
-/*
- * Multiplex In-band IPI messages over software interrupt 0
- * as we do in the arm implementation.
- */
 #define OOB_NR_IPI		3
-#define OOB_IPI_OFFSET		1 /* Software interrupt 1 */
-#define TIMER_OOB_IPI		(ipi_virq_base + OOB_IPI_OFFSET)
-#define RESCHEDULE_OOB_IPI	(TIMER_OOB_IPI + 1)
-#define CALL_FUNCTION_OOB_IPI	(RESCHEDULE_OOB_IPI + 1)
+
 
 extern int ipi_virq_base;
+extern int NR_CALL_FUNCTION_OOB_IPI;
+extern int NR_RESCHEDULE_OOB_IPI;
+extern int NR_TIMER_OOB_IPI;
+extern int ipi_max;
+
+#define CALL_FUNCTION_OOB_IPI (ipi_virq_base + NR_CALL_FUNCTION_OOB_IPI)
+#define RESCHEDULE_OOB_IPI (ipi_virq_base + NR_RESCHEDULE_OOB_IPI)
+#define TIMER_OOB_IPI (ipi_virq_base + NR_TIMER_OOB_IPI)
+#define PIPELINED_IPI_MAX ipi_max
 
 #ifdef CONFIG_IRQ_PIPELINE
 
arch/riscv/kernel/sbi-ipi.c +9 -1
index 0cc5559c08d8..176f4ad3c427 100644
@@ -12,6 +12,7 @@
 #include <linux/irqchip/chained_irq.h>
 #include <linux/irqdomain.h>
 #include <asm/sbi.h>
+#include <asm/irq_pipeline.h>
 
 DEFINE_STATIC_KEY_FALSE(riscv_sbi_for_rfence);
 EXPORT_SYMBOL_GPL(riscv_sbi_for_rfence);
@@ -57,7 +58,11 @@ void __init sbi_ipi_init(void)
 		return;
 	}
 
+#ifdef CONFIG_IRQ_PIPELINE
+	virq = ipi_mux_create(PIPELINED_IPI_MAX, sbi_send_ipi);
+#else
 	virq = ipi_mux_create(BITS_PER_BYTE, sbi_send_ipi);
+#endif
 	if (virq <= 0) {
 		pr_err("unable to create muxed IPIs\n");
 		irq_dispose_mapping(sbi_ipi_virq);
@@ -74,8 +79,11 @@ void __init sbi_ipi_init(void)
 	cpuhp_setup_state(CPUHP_AP_IRQ_RISCV_SBI_IPI_STARTING,
 			  "irqchip/sbi-ipi:starting",
 			  sbi_ipi_starting_cpu, NULL);
-
+#ifdef CONFIG_IRQ_PIPELINE
+	riscv_ipi_set_virq_range(virq, PIPELINED_IPI_MAX);
+#else
 	riscv_ipi_set_virq_range(virq, BITS_PER_BYTE);
+#endif
 	pr_info("providing IPIs using SBI IPI extension\n");
 
 	/*
arch/riscv/kernel/smp.c +32 -70

166 lines not on this page · raw message

drivers/clocksource/timer-clint.c +8 -0
index 0bdd9d7ec545..5345e4d373ac 100644
@@ -243,7 +243,11 @@ static int __init clint_timer_init_dt(struct device_node *np)
 	}
 
 #ifdef CONFIG_SMP
+#ifdef CONFIG_IRQ_PIPELINE
+	rc = ipi_mux_create(PIPELINED_IPI_MAX, clint_send_ipi);
+#else
 	rc = ipi_mux_create(BITS_PER_BYTE, clint_send_ipi);
+#endif
 	if (rc <= 0) {
 		pr_err("unable to create muxed IPIs\n");
 		rc = (rc < 0) ? rc : -ENODEV;
@@ -251,7 +255,11 @@ static int __init clint_timer_init_dt(struct device_node *np)
 	}
 
 	irq_set_chained_handler(clint_ipi_irq, clint_ipi_interrupt);
+#ifdef CONFIG_IRQ_PIPELINE
+	riscv_ipi_set_virq_range(rc, PIPELINED_IPI_MAX);
+#else
 	riscv_ipi_set_virq_range(rc, BITS_PER_BYTE);
+#endif
 	clint_clear_ipi();
 #endif
 
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH] riscv: irq_pipeline: simplify the send and handle operation for ipis

Quoted 59 lines · shannmu

riscv is different from aarch64 and we don't need to encode and decode inband ipis multiplexed over ipi_desc[0], because we can alloc for up to BITS_PER_TYPE(int) ipis. So we could introudce more OOB_XXX ipi_message_types and treat them as inband ipi.

---
 arch/riscv/include/asm/irq_pipeline.h |  18 +++--
 arch/riscv/kernel/sbi-ipi.c           |  10 ++-
 arch/riscv/kernel/smp.c               | 102 ++++++++------------------
 drivers/clocksource/timer-clint.c     |   8 ++
 4 files changed, 59 insertions(+), 79 deletions(-)
arch/riscv/include/asm/irq_pipeline.h +10 -8
index 2ef91c2af706..030823745787 100644
@@ -9,17 +9,19 @@
 #ifndef _ASM_RISCV_IRQ_PIPELINE_H
 #define _ASM_RISCV_IRQ_PIPELINE_H
 
-/*
- * Multiplex In-band IPI messages over software interrupt 0
- * as we do in the arm implementation.
- */
 #define OOB_NR_IPI		3
-#define OOB_IPI_OFFSET		1 /* Software interrupt 1 */
-#define TIMER_OOB_IPI		(ipi_virq_base + OOB_IPI_OFFSET)
-#define RESCHEDULE_OOB_IPI	(TIMER_OOB_IPI + 1)
-#define CALL_FUNCTION_OOB_IPI	(RESCHEDULE_OOB_IPI + 1)
+
 
 extern int ipi_virq_base;
+extern int NR_CALL_FUNCTION_OOB_IPI;
+extern int NR_RESCHEDULE_OOB_IPI;
+extern int NR_TIMER_OOB_IPI;
+extern int ipi_max;
+
+#define CALL_FUNCTION_OOB_IPI (ipi_virq_base + NR_CALL_FUNCTION_OOB_IPI)
+#define RESCHEDULE_OOB_IPI (ipi_virq_base + NR_RESCHEDULE_OOB_IPI)
+#define TIMER_OOB_IPI (ipi_virq_base + NR_TIMER_OOB_IPI)
+#define PIPELINED_IPI_MAX ipi_max
 
 #ifdef CONFIG_IRQ_PIPELINE
 
arch/riscv/kernel/sbi-ipi.c +1 -0
index 0cc5559c08d8..176f4ad3c427 100644
@@ -12,6 +12,7 @@
 #include <linux/irqchip/chained_irq.h>
 #include <linux/irqdomain.h>
 #include <asm/sbi.h>
+#include <asm/irq_pipeline.h>
 
 DEFINE_STATIC_KEY_FALSE(riscv_sbi_for_rfence);
 EXPORT_SYMBOL_GPL(riscv_sbi_for_rfence);

arch/riscv/kernel/sbi-ipi.c void __init sbi_ipi_init(void) · line 65

Quoted 8 lines
arch/riscv/kernel/sbi-ipi.c +4 -0
@@ -57,7 +58,11 @@ void __init sbi_ipi_init(void)
 		return;
 	}
 
+#ifdef CONFIG_IRQ_PIPELINE
+	virq = ipi_mux_create(PIPELINED_IPI_MAX, sbi_send_ipi);
+#else
 	virq = ipi_mux_create(BITS_PER_BYTE, sbi_send_ipi);
+#endif

Maybe we rather want

#ifndef CONFIG_IRQ_PIPELINE
#define PIPELINED_IPI_MAX BITS_PER_BYTE
#endif

somewhere.

Jan

Signature · 2 lines
Siemens AG, Foundational Technologies
Linux Expert Center
Tested-by on the v1 series
#3 lore raw
In reply to shannmu
Quoted 8 lines · shannmu

RISC-V is different from aarch64. AArch64 has SGI0-15 and use SGI0-7 to send IPIs, so we introduced a feature that we handle inband ipis multiplexed over SGI0. But RISC-V only has one register to inform IPI and the ipi_types are recorded in the PER_CPU variables,
which can store sizeof(atomic_t) bits. So we don't need to use the same way to send IPIs. We can simplify the code by unifying the IPI handling code and sending code for oob and inband ipis.

Looks good to me. Thanks for this improvement.

Best,
Tobias

Quoted 12 lines

shannmu (1):
  riscv: irq_pipeline: simplify the send and handle operation for ipis

 arch/riscv/include/asm/irq_pipeline.h |  18 +++-- arch/riscv/kernel/sbi-ipi.c           |  10 ++- arch/riscv/kernel/smp.c               | 102 ++++++++---------------- --
 drivers/clocksource/timer-clint.c     |   8 ++

 4 files changed, 59 insertions(+), 79 deletions(-)
#4 lore raw
Quoted 10 lines · Tobias
Quoted 8 lines · shannmu

RISC-V is different from aarch64. AArch64 has SGI0-15 and use SGI0-7 to send IPIs, so we introduced a feature that we handle inband ipis multiplexed over SGI0. But RISC-V only has one register to inform IPI and the ipi_types are recorded in the PER_CPU variables,
which can store sizeof(atomic_t) bits. So we don't need to use the same way to send IPIs. We can simplify the code by unifying the IPI handling code and sending code for oob and inband ipis.

Quoted 4 lines

Looks good to me. Thanks for this improvement.

Merged into [1], thanks.

[1] https://source.denx.de/Xenomai/linux-dovetail/-/commits/wip/dovetail-riscv?ref_type=heads

Signature · 1 line
Philippe.