From: Luigi Rizzo <lrizzo@google.com>
To: Thomas Gleixner <tglx@linutronix.de>,
Marc Zyngier <maz@kernel.org>,
Luigi Rizzo <rizzo.unipi@gmail.com>,
Paolo Abeni <pabeni@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>,
Sean Christopherson <seanjc@google.com>,
Jacob Pan <jacob.jun.pan@linux.intel.com>
Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org,
Bjorn Helgaas <bhelgaas@google.com>,
Willem de Bruijn <willemb@google.com>,
Luigi Rizzo <lrizzo@google.com>
Subject: [PATCH 6/6] genirq: soft_moderation: implement per-driver defaults (nvme and vfio)
Date: Wed, 12 Nov 2025 19:24:08 +0000 [thread overview]
Message-ID: <20251112192408.3646835-7-lrizzo@google.com> (raw)
In-Reply-To: <20251112192408.3646835-1-lrizzo@google.com>
Introduce helpers to implement per-driver module parameters to enable
moderation at boot/probe time.
As an example, use the helpers in nvme and vfio drivers.
To test, boot a kernel with
${driver}.soft_moderation=1 # enables moderation.
and verify with "cat /proc/irq/soft_moderation" that
the counters increase.
Change-Id: Iaad4110977deb96df845501895e0043bd93fc350
---
drivers/nvme/host/pci.c | 3 +++
drivers/vfio/pci/vfio_pci_intrs.c | 3 +++
include/linux/interrupt.h | 13 +++++++++++++
kernel/irq/irq_moderation.c | 11 +++++++++++
4 files changed, 30 insertions(+)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 72fb675a696f4..b9d7bce30061f 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -72,6 +72,8 @@
static_assert(MAX_PRP_RANGE / NVME_CTRL_PAGE_SIZE <=
(1 /* prp1 */ + NVME_MAX_NR_DESCRIPTORS * PRPS_PER_PAGE));
+DEFINE_IRQ_MODERATION_MODE_PARAMETER;
+
static int use_threaded_interrupts;
module_param(use_threaded_interrupts, int, 0444);
@@ -1989,6 +1991,7 @@ static int nvme_create_queue(struct nvme_queue *nvmeq, int qid, bool polled)
result = queue_request_irq(nvmeq);
if (result < 0)
goto release_sq;
+ IRQ_MODERATION_SET_DEFAULT_MODE(pci_irq_vector(to_pci_dev(dev->dev), vector));
}
set_bit(NVMEQ_ENABLED, &nvmeq->flags);
diff --git a/drivers/vfio/pci/vfio_pci_intrs.c b/drivers/vfio/pci/vfio_pci_intrs.c
index 30d3e921cb0de..e54d88cfe601d 100644
--- a/drivers/vfio/pci/vfio_pci_intrs.c
+++ b/drivers/vfio/pci/vfio_pci_intrs.c
@@ -22,6 +22,8 @@
#include "vfio_pci_priv.h"
+DEFINE_IRQ_MODERATION_MODE_PARAMETER;
+
struct vfio_pci_irq_ctx {
struct vfio_pci_core_device *vdev;
struct eventfd_ctx *trigger;
@@ -317,6 +319,7 @@ static int vfio_intx_enable(struct vfio_pci_core_device *vdev,
vfio_irq_ctx_free(vdev, ctx, 0);
return ret;
}
+ IRQ_MODERATION_SET_DEFAULT_MODE(pdev->irq);
return 0;
}
diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
index 007201c8db6dd..c7d68d8ec49d7 100644
--- a/include/linux/interrupt.h
+++ b/include/linux/interrupt.h
@@ -879,12 +879,25 @@ void irq_moderation_init_fields(struct irq_desc *desc);
/* add/remove /proc/irq/NN/soft_moderation */
void irq_moderation_procfs_entry(struct irq_desc *desc, umode_t umode);
+/* 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: disable_irq")
+
+void irq_moderation_set_mode(int irq, bool mode);
+#define IRQ_MODERATION_SET_DEFAULT_MODE(_irq) \
+ irq_moderation_set_mode(_irq, READ_ONCE(soft_moderation))
+
#else /* empty stubs to avoid conditional compilation */
static inline void irq_moderation_percpu_init(void) {}
static inline void irq_moderation_init_fields(struct irq_desc *desc) {}
static inline void irq_moderation_procfs_entry(struct irq_desc *desc, umode_t umode) {};
+#define DEFINE_IRQ_MODERATION_MODE_PARAMETER
+#define IRQ_MODERATION_SET_DEFAULT_MODE(_irq)
+
#endif
/*
diff --git a/kernel/irq/irq_moderation.c b/kernel/irq/irq_moderation.c
index 672e161ecf29e..3b3962dae33d1 100644
--- a/kernel/irq/irq_moderation.c
+++ b/kernel/irq/irq_moderation.c
@@ -83,6 +83,10 @@ static bool enable_posted_msi;
*
* 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.
@@ -302,6 +306,13 @@ static void set_moderation_mode(struct irq_desc *desc, bool mode)
}
}
+/* irq_to_desc is not exported. Wrap it in this function for a specific use. */
+void irq_moderation_set_mode(int irq, bool mode)
+{
+ set_moderation_mode(irq_to_desc(irq), mode);
+}
+EXPORT_SYMBOL(irq_moderation_set_mode);
+
#pragma clang diagnostic error "-Wformat"
/* Print statistics */
static int moderation_show(struct seq_file *p, void *v)
--
2.51.2.1041.gc1ab5b90ca-goog
next prev parent reply other threads:[~2025-11-12 19:24 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-12 19:24 [PATCH 0/6] platform wide software interrupt moderation Luigi Rizzo
2025-11-12 19:24 ` [PATCH 1/6] genirq: platform wide interrupt moderation: Documentation, Kconfig, irq_desc Luigi Rizzo
2025-11-13 8:17 ` Thomas Gleixner
2025-11-13 9:44 ` Thomas Gleixner
2025-11-13 13:25 ` Marc Zyngier
2025-11-13 13:33 ` Luigi Rizzo
2025-11-13 14:42 ` Marc Zyngier
2025-11-13 14:55 ` Luigi Rizzo
2025-11-13 19:02 ` Marc Zyngier
2025-11-12 19:24 ` [PATCH 2/6] genirq: soft_moderation: add base files, procfs hooks Luigi Rizzo
2025-11-13 9:29 ` Thomas Gleixner
2025-11-13 10:24 ` Thomas Gleixner
2025-11-13 22:42 ` Luigi Rizzo
2025-11-13 22:32 ` Luigi Rizzo
2025-11-13 9:40 ` Thomas Gleixner
2025-11-12 19:24 ` [PATCH 3/6] genirq: soft_moderation: activate hooks in handle_irq_event() Luigi Rizzo
2025-11-13 9:45 ` Thomas Gleixner
2025-11-14 8:27 ` Luigi Rizzo
2025-11-12 19:24 ` [PATCH 4/6] genirq: soft_moderation: implement adaptive moderation Luigi Rizzo
2025-11-13 10:15 ` Thomas Gleixner
2025-11-12 19:24 ` [PATCH 5/6] x86/irq: soft_moderation: add support for posted_msi (intel) Luigi Rizzo
2025-11-12 19:24 ` Luigi Rizzo [this message]
2025-11-13 10:18 ` [PATCH 6/6] genirq: soft_moderation: implement per-driver defaults (nvme and vfio) Thomas Gleixner
2025-11-13 10:42 ` Luigi Rizzo
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20251112192408.3646835-7-lrizzo@google.com \
--to=lrizzo@google.com \
--cc=akpm@linux-foundation.org \
--cc=bhelgaas@google.com \
--cc=jacob.jun.pan@linux.intel.com \
--cc=linux-arch@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maz@kernel.org \
--cc=pabeni@redhat.com \
--cc=rizzo.unipi@gmail.com \
--cc=seanjc@google.com \
--cc=tglx@linutronix.de \
--cc=willemb@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®