From nobody Mon Jun 8 20:42:21 2026 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE6D63FBEC2; Tue, 26 May 2026 14:22:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=193.142.43.55 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779805343; cv=none; b=JulzfrC3PRlXVEw++pV5CFCZdkRZN4fn0Rr9ZgZzd3n5adOgKZDdFSVchrf7YpgvqoKk/2MCoWasf46Xj3Ougn9AweL9JA+myBAUQ7YxtLk78okElgKxcXsV5SPvjZCWKjS+65F2RvkFkTtS1FL572arrDUGIjqljRouMe0BQaU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779805343; c=relaxed/simple; bh=+88b76PEpoE8DCX3il+WdX7OWh+SWymAhb/DK/QrPFM=; h=Date:From:To:Subject:Cc:In-Reply-To:References:MIME-Version: Message-ID:Content-Type; b=XKr7hhLzbDY26W7/X88Im0O+oq5tHUFauMTX3nh7Z3luS1Z0fmt0kLyDMEe0Et2elhnRnS6+akwggOh5CSodOORHgy0CWwJE5t5iF9WjL5WMZVYgRUNj8WjiErKTUheEEVl2XQv01fwn/5OX4oRQHKBgTbstHKY2eAx7WmtryNA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de; spf=pass smtp.mailfrom=linutronix.de; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=wt9/MFhb; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b=w/WD8E2V; arc=none smtp.client-ip=193.142.43.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linutronix.de Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linutronix.de Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="wt9/MFhb"; dkim=permerror (0-bit key) header.d=linutronix.de header.i=@linutronix.de header.b="w/WD8E2V" Date: Tue, 26 May 2026 14:22:17 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1779805339; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sytlf5YwbamLAB60ryfcQrogl88dGDCqxVLt7Y6CV6U=; b=wt9/MFhbeZLaRGMJnhLhnum154mPmdu7VKgCLa0uVHEvo13zIS8n1XLIxxVg6mCZmSmVPV 2/nQxwQLFy7O+TZv7a1AzBWkodStKUOSsqlGc3kFjT428jNZJMdgonOl9/Ip3DgnyrCmcR AnGer2ZDouJaXxxKHUK8TwSRbL5kXeyyWaG3vleniP2hMUgbpT0ROMo0gUMi+IGhXMZPxg 8yt6z29QdiFhexvoncHxnlA+/5bg1wNw6k7hP+1aHuTyIzXEPYmoiSPzzKUbCMU6n2fkRy 6dmPtpxz+Km8HYdSLGt7uMhUR7DPZjAvk61RTv17ym1POnPcX7W3KLf4iqLtCw== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1779805339; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sytlf5YwbamLAB60ryfcQrogl88dGDCqxVLt7Y6CV6U=; b=w/WD8E2V73faqImVHdgCX8spI3R53uiUh/selfVslTvligljf9pRHfCHFjy7VVnvfINyJS feDgVMfYKK7jNSAg== From: "tip-bot2 for Thomas Gleixner" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: irq/core] genirq/proc: Speed up /proc/interrupts iteration Cc: Thomas Gleixner , Michael Kelley , Dmitry Ilvokhin , x86@kernel.org, linux-kernel@vger.kernel.org, maz@kernel.org In-Reply-To: <20260517194932.165280601@kernel.org> References: <20260517194932.165280601@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-ID: <177980533797.1039918.3651700535537179451.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails Precedence: bulk Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The following commit has been merged into the irq/core branch of tip: Commit-ID: 171cc0d9eed1cad5de7ce6a212efbeda390edb0f Gitweb: https://git.kernel.org/tip/171cc0d9eed1cad5de7ce6a212efbeda3= 90edb0f Author: Thomas Gleixner AuthorDate: Sun, 17 May 2026 22:02:49 +02:00 Committer: Thomas Gleixner CommitterDate: Tue, 26 May 2026 16:21:15 +02:00 genirq/proc: Speed up /proc/interrupts iteration Reading /proc/interrupts iterates over the interrupt number space one by one and looks up the descriptors one by one. That's just a waste of time. When CONFIG_GENERIC_IRQ_SHOW is enabled this can utilize the maple tree and cache the descriptor pointer efficiently for the sequence file operations. Implement a CONFIG_GENERIC_IRQ_SHOW specific version in the core code and leave the fs/proc/ variant for the legacy architectures which ignore generic code. This reduces the time wasted for looking up the next record significantly. Signed-off-by: Thomas Gleixner Tested-by: Michael Kelley Reviewed-by: Dmitry Ilvokhin Link: https://patch.msgid.link/20260517194932.165280601@kernel.org --- fs/proc/Makefile | 4 +- kernel/irq/proc.c | 116 +++++++++++++++++++++++++++++++++++---------- 2 files changed, 94 insertions(+), 26 deletions(-) diff --git a/fs/proc/Makefile b/fs/proc/Makefile index 7b4db9c..8bc615f 100644 --- a/fs/proc/Makefile +++ b/fs/proc/Makefile @@ -16,7 +16,9 @@ proc-y +=3D cmdline.o proc-y +=3D consoles.o proc-y +=3D cpuinfo.o proc-y +=3D devices.o -proc-y +=3D interrupts.o +ifneq ($(CONFIG_GENERIC_IRQ_SHOW),y) +proc-y +=3D interrupts.o +endif proc-y +=3D loadavg.o proc-y +=3D meminfo.o proc-y +=3D stat.o diff --git a/kernel/irq/proc.c b/kernel/irq/proc.c index 9a96800..1b83572 100644 --- a/kernel/irq/proc.c +++ b/kernel/irq/proc.c @@ -452,6 +452,8 @@ void irq_proc_update_valid(struct irq_desc *desc) =20 #ifdef CONFIG_GENERIC_IRQ_SHOW =20 +#define ARCH_PROC_IRQDESC ((void *)0x00001111) + int __weak arch_show_interrupts(struct seq_file *p, int prec) { return 0; @@ -460,6 +462,7 @@ int __weak arch_show_interrupts(struct seq_file *p, int= prec) static DEFINE_RAW_SPINLOCK(irq_proc_constraints_lock); =20 static struct irq_proc_constraints { + bool print_header; unsigned int num_prec; unsigned int chip_width; } irq_proc_constraints __read_mostly =3D { @@ -533,34 +536,28 @@ void irq_proc_emit_counts(struct seq_file *p, unsigne= d int __percpu *cnts) irq_proc_emit_zero_counts(p, zeros); } =20 -int show_interrupts(struct seq_file *p, void *v) +static int irq_seq_show(struct seq_file *p, void *v) { - unsigned int chip_width =3D READ_ONCE(irq_proc_constraints.chip_width); - unsigned int prec =3D READ_ONCE(irq_proc_constraints.num_prec); - int i =3D *(loff_t *) v, j; + struct irq_proc_constraints *constr =3D p->private; + struct irq_desc *desc =3D v; struct irqaction *action; - struct irq_desc *desc; =20 - if (i > ACTUAL_NR_IRQS) - return 0; + /* Print header for the first interrupt? */ + if (constr->print_header) { + unsigned int cpu; =20 - if (i =3D=3D ACTUAL_NR_IRQS) - return arch_show_interrupts(p, prec); - - /* print header and calculate the width of the first column */ - if (i =3D=3D 0) { - seq_printf(p, "%*s", prec + 8, ""); - for_each_online_cpu(j) - seq_printf(p, "CPU%-8d", j); + seq_printf(p, "%*s", constr->num_prec + 8, ""); + for_each_online_cpu(cpu) + seq_printf(p, "CPU%-8d", cpu); seq_putc(p, '\n'); + constr->print_header =3D false; } =20 - guard(rcu)(); - desc =3D irq_to_desc(i); - if (!desc || !irq_settings_proc_valid(desc)) - return 0; + if (desc =3D=3D ARCH_PROC_IRQDESC) + return arch_show_interrupts(p, constr->num_prec); =20 - seq_printf(p, "%*d:", prec, i); + seq_put_decimal_ull_width(p, "", irq_desc_get_irq(desc), constr->num_prec= ); + seq_putc(p, ':'); =20 /* * Always output per CPU interrupts. Output device interrupts only when @@ -580,18 +577,18 @@ int show_interrupts(struct seq_file *p, void *v) if (desc->irq_data.chip->irq_print_chip) desc->irq_data.chip->irq_print_chip(&desc->irq_data, p); else if (desc->irq_data.chip->name) - seq_printf(p, "%-*s", chip_width, desc->irq_data.chip->name); + seq_printf(p, "%-*s", constr->chip_width, desc->irq_data.chip->name); else - seq_printf(p, "%-*s", chip_width, "-"); + seq_printf(p, "%-*s", constr->chip_width, "-"); } else { - seq_printf(p, "%-*s", chip_width, "None"); + seq_printf(p, "%-*s", constr->chip_width, "None"); } =20 seq_putc(p, ' '); if (desc->irq_data.domain) - seq_put_decimal_ull_width(p, "", desc->irq_data.hwirq, prec); + seq_put_decimal_ull_width(p, "", desc->irq_data.hwirq, constr->num_prec); else - seq_printf(p, " %*s", prec, ""); + seq_printf(p, " %*s", constr->num_prec, ""); =20 if (IS_ENABLED(CONFIG_GENERIC_IRQ_SHOW_LEVEL)) seq_printf(p, " %-8s", irqd_is_level_type(&desc->irq_data) ? "Level" : "= Edge"); @@ -609,4 +606,73 @@ int show_interrupts(struct seq_file *p, void *v) seq_putc(p, '\n'); return 0; } + +static void *irq_seq_next_desc(loff_t *pos) +{ + if (*pos > total_nr_irqs) + return NULL; + + guard(rcu)(); + for (;;) { + struct irq_desc *desc =3D irq_find_desc_at_or_after((unsigned int) *pos); + + if (desc) { + *pos =3D irq_desc_get_irq(desc); + /* + * If valid for output then try to acquire a reference + * count on the descriptor so that it can't be freed + * after dropping RCU read lock on return. + */ + if (irq_settings_proc_valid(desc) && irq_desc_get_ref(desc)) + return desc; + (*pos)++; + } else { + *pos =3D total_nr_irqs; + return ARCH_PROC_IRQDESC; + } + } +} + +static void *irq_seq_start(struct seq_file *f, loff_t *pos) +{ + if (!*pos) { + struct irq_proc_constraints *constr =3D f->private; + + constr->num_prec =3D READ_ONCE(irq_proc_constraints.num_prec); + constr->chip_width =3D READ_ONCE(irq_proc_constraints.chip_width); + constr->print_header =3D true; + } + return irq_seq_next_desc(pos); +} + +static void *irq_seq_next(struct seq_file *f, void *v, loff_t *pos) +{ + if (v && v !=3D ARCH_PROC_IRQDESC) + irq_desc_put_ref(v); + + (*pos)++; + return irq_seq_next_desc(pos); +} + +static void irq_seq_stop(struct seq_file *f, void *v) +{ + if (v && v !=3D ARCH_PROC_IRQDESC) + irq_desc_put_ref(v); +} + +static const struct seq_operations irq_seq_ops =3D { + .start =3D irq_seq_start, + .next =3D irq_seq_next, + .stop =3D irq_seq_stop, + .show =3D irq_seq_show, +}; + +static int __init irq_proc_init(void) +{ + proc_create_seq_private("interrupts", 0, NULL, &irq_seq_ops, + sizeof(irq_proc_constraints), NULL); + return 0; +} +fs_initcall(irq_proc_init); + #endif