[PATCH v2 6/8] genirq: soft_moderation: helpers for per-driver defaults

From: Luigi Rizzo
Date: Sun Nov 16 2025 - 13:30:25 EST


Introduce helpers to implement per-driver module parameters to enable
moderation at boot/probe time.

No functional change.

Change-Id: I305aa42fa348055004cc2221ef6b055a0ab4b9d5
Signed-off-by: Luigi Rizzo <lrizzo@xxxxxxxxxx>
---
include/linux/interrupt.h | 19 +++++++++++++++++++
kernel/irq/irq_moderation.c | 14 ++++++++++++++
2 files changed, 33 insertions(+)

diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index 51b6484c04934..17ce0aac181de 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -872,6 +872,25 @@ extern int early_irq_init(void);
extern int arch_probe_nr_irqs(void);
extern int arch_early_irq_init(void);

+#ifdef CONFIG_IRQ_SOFT_MODERATION
+
+/* helpers for per-driver moderation mode settings */
+#define DEFINE_IRQ_MODERATION_MODE_PARAMETER \
+ static bool soft_moderation; \
+ module_param(soft_moderation, bool, 0644); \
+ MODULE_PARM_DESC(soft_moderation, "0: off, 1: on")
+
+void irq_moderation_set_mode(int irq, bool enable);
+#define IRQ_MODERATION_SET_DEFAULT_MODE(_irq) \
+ irq_moderation_set_mode(_irq, READ_ONCE(soft_moderation))
+
+#else /* empty stubs to avoid conditional compilation */
+
+#define DEFINE_IRQ_MODERATION_MODE_PARAMETER
+#define IRQ_MODERATION_SET_DEFAULT_MODE(_irq)
+
+#endif
+
/*
* We want to know which function is an entrypoint of a hardirq or a softirq.
*/
diff --git a/kernel/irq/irq_moderation.c b/kernel/irq/irq_moderation.c
index 2d01e4cd4638b..c2542c92fbbd5 100644
--- a/kernel/irq/irq_moderation.c
+++ b/kernel/irq/irq_moderation.c
@@ -84,6 +84,10 @@ static inline bool posted_msi_supported(void) { return false; }
*
* echo "on" > /proc/irq/NN/soft_moderation # use "off" to disable
*
+ * For selected drivers, the default can also be supplied via module parameters
+ *
+ * ${DRIVER}.soft_moderation=1
+ *
* === MONITORING ===
*
* cat /proc/irq/soft_moderation shows per-CPU and global statistics.
@@ -307,6 +311,16 @@ static inline int set_moderation_mode(struct irq_desc *desc, bool enable)
return 0;
}

+/* irq_to_desc() is not exported. Wrap it for use in drivers. */
+void irq_moderation_set_mode(int irq, bool enable)
+{
+ struct irq_desc *desc = irq_to_desc(irq);
+
+ if (desc)
+ set_moderation_mode(desc, enable);
+}
+EXPORT_SYMBOL(irq_moderation_set_mode);
+
#pragma clang diagnostic error "-Wformat"
/* Print statistics */
static int moderation_show(struct seq_file *p, void *v)
--
2.52.0.rc1.455.g30608eb744-goog