From nobody Mon Feb 9 08:54:00 2026 Received: from mail-ed1-f73.google.com (mail-ed1-f73.google.com [209.85.208.73]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C1395352925 for ; Wed, 12 Nov 2025 19:24:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762975476; cv=none; b=UpM/6cRsjKuMffeuNlDXnu2b2+pKJXSByHKDMXixWy7JPrydNhrveMICGjBsn6oDLtsoIdi2vqVRCEVIlEIpSQitkOYwLM/sYENknSBr/A3L3vIMIezKkDXDzovXp+AsOiO3dMdT/WyysMRYwEXQPr5T4wFecM+OYNtroKGlj3g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762975476; c=relaxed/simple; bh=toNGEDGM2fDo8bSkeyRBZN131/gcqcXF1zPXs1SMotM=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=S1NhYGwGOrh/eNYtHtXv1vtwc4wGe0gp9kkFDAp3bbGOTT8X1L4kjAphpNWBfoh3X3J739wdfBHCFiuA20JzL7A9qN+bx8hmLI4Swpy3t/xk8b6xAjxci3qf5YzUe6dimIMvsJfrqgjCSetu/FmKOEGfOdMYjQCe6IyRhgx/JsY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--lrizzo.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=0t8G89EN; arc=none smtp.client-ip=209.85.208.73 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--lrizzo.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="0t8G89EN" Received: by mail-ed1-f73.google.com with SMTP id 4fb4d7f45d1cf-64165abd7ffso17741a12.0 for ; Wed, 12 Nov 2025 11:24:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1762975473; x=1763580273; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=Bc56Im0L/wPheTuphZBEmtz1ndMMkc1rQdJZlfQeq+U=; b=0t8G89ENKBnhFiDLYda3FT79chNWlGLJUShyVKb1Nhmsq2Mu0eIFNwUM/fvuuFwkOU aCvpv8+1CJciltNNyewOfxg3b4D7BhSZFuJNxyC8MFGDWH9hU8cN+g9JvnjIzlCBc5AB 8C6pA0T6DCH/ScTfaFAUsV1KkLDLZUUJ5QbrB8G2dzXYVlkH00Om184Kl850423xpIBH Smu4x/N82AM+mKjar2hs7BW3Zae8VKtPAmZ7gRyg1mb13PDDRwjDc+/HV5/Pf4acvsXE fOHntq32xpOLPC6ef2rl9CA0r4YTcF6dBQtd3X1BCuuGNmcYzEXOLHwP4SnLR+hzIg0j ku8g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762975473; x=1763580273; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Bc56Im0L/wPheTuphZBEmtz1ndMMkc1rQdJZlfQeq+U=; b=LJt4lG7g0E1X+zVjypCyvlj+KVBMyyh33kVTzvY9GB6ueesweCRWuwBLwN0XHBZ12o 5B5V4Zz57MVpWxtVE1EppRdCrjnVL74fQ11i6LitkPyfHYBZW+caee325EmWatANyKJT UzRTJUXH37pQq8JPj8ioQKzw/WkGggWQEUuuuVnCFnZkxAfK6M1gxahqjBJKBE9ENzzB 2HccNCvS5bHcDFBfj0x6n8Gd/wQx6SZkaNOFForter1B0t5ut1NT3kSbisQYfA+Aosv9 ys2k12Op3iCIImqqFRGIno0Y8BDFW7+JCRwKNaJ6KfR5DdSeki2flf35H/hIjtXbH8JK dj5Q== X-Gm-Message-State: AOJu0YyiGK20fxtQQU/ZWQ0DuBN6LUYT5US2ooCF108mAZLJ5WI6m4mn HCViSRmoDb2YdZXnDYrRnXxm4r3OuiLG8au7zYx4jjafnrZ89k52QFxFh3JqX0xH97ttPanGY43 sn2v+dg== X-Google-Smtp-Source: AGHT+IHy1JZdLmmhLtppnkVtk92yU/GzqkzRArhgbpy6IgXzyGv+2/u+PlsYwaDikLZmzfb52j6h4XAZ/GY= X-Received: from edhr5.prod.google.com ([2002:a50:8d85:0:b0:641:92ae:b599]) (user=lrizzo job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6402:1449:b0:640:b8a0:1aad with SMTP id 4fb4d7f45d1cf-6431a39287emr4098002a12.6.1762975473032; Wed, 12 Nov 2025 11:24:33 -0800 (PST) Date: Wed, 12 Nov 2025 19:24:08 +0000 In-Reply-To: <20251112192408.3646835-1-lrizzo@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20251112192408.3646835-1-lrizzo@google.com> X-Mailer: git-send-email 2.51.2.1041.gc1ab5b90ca-goog Message-ID: <20251112192408.3646835-7-lrizzo@google.com> Subject: [PATCH 6/6] genirq: soft_moderation: implement per-driver defaults (nvme and vfio) From: Luigi Rizzo To: Thomas Gleixner , Marc Zyngier , Luigi Rizzo , Paolo Abeni , Andrew Morton , Sean Christopherson , Jacob Pan Cc: linux-kernel@vger.kernel.org, linux-arch@vger.kernel.org, Bjorn Helgaas , Willem de Bruijn , Luigi Rizzo Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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=3D1 # 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 <=3D (1 /* prp1 */ + NVME_MAX_NR_DESCRIPTORS * PRPS_PER_PAGE)); =20 +DEFINE_IRQ_MODERATION_MODE_PARAMETER; + static int use_threaded_interrupts; module_param(use_threaded_interrupts, int, 0444); =20 @@ -1989,6 +1991,7 @@ static int nvme_create_queue(struct nvme_queue *nvmeq= , int qid, bool polled) result =3D queue_request_irq(nvmeq); if (result < 0) goto release_sq; + IRQ_MODERATION_SET_DEFAULT_MODE(pci_irq_vector(to_pci_dev(dev->dev), vec= tor)); } =20 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 @@ =20 #include "vfio_pci_priv.h" =20 +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); =20 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); =20 +/* 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 */ =20 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, umod= e_t umode) {}; =20 +#define DEFINE_IRQ_MODERATION_MODE_PARAMETER +#define IRQ_MODERATION_SET_DEFAULT_MODE(_irq) + #endif =20 /* 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 param= eters + * + * ${DRIVER}.soft_moderation=3D1 + * * =3D=3D=3D MONITORING =3D=3D=3D * * 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) } } =20 +/* irq_to_desc is not exported. Wrap it in this function for a specific us= e. */ +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) --=20 2.51.2.1041.gc1ab5b90ca-goog