From: Bitao Hu <yaoma@linux.alibaba.com>
To: dianders@chromium.org, tglx@linutronix.de,
liusong@linux.alibaba.com, akpm@linux-foundation.org,
pmladek@suse.com, kernelfans@gmail.com, deller@gmx.de,
npiggin@gmail.com, tsbogend@alpha.franken.de,
James.Bottomley@HansenPartnership.com, jan.kiszka@siemens.com
Cc: yaoma@linux.alibaba.com, linuxppc-dev@lists.ozlabs.org,
linux-kernel@vger.kernel.org, linux-parisc@vger.kernel.org,
linux-mips@vger.kernel.org
Subject: [PATCHv12 2/4] genirq: Avoid summation loops for /proc/interrupts
Date: Wed, 6 Mar 2024 20:52:06 +0800 [thread overview]
Message-ID: <20240306125208.71803-3-yaoma@linux.alibaba.com> (raw)
In-Reply-To: <20240306125208.71803-1-yaoma@linux.alibaba.com>
show_interrupts() unconditionally accumulates the per CPU interrupt
statistics to determine whether an interrupt was ever raised.
This can be avoided for all interrupts which are not strictly per CPU
and not of type NMI because those interrupts provide already an
accumulated counter. The required logic is already implemented in
kstat_irqs().
Split the inner access logic out of kstat_irqs() and use it for
kstat_irqs() and show_interrupts() to avoid the accumulation loop
when possible.
Originally-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Bitao Hu <yaoma@linux.alibaba.com>
Reviewed-by: Liu Song <liusong@linux.alibaba.com>
Reviewed-by: Douglas Anderson <dianders@chromium.org>
---
kernel/irq/internals.h | 2 ++
kernel/irq/irqdesc.c | 16 +++++++++++-----
kernel/irq/proc.c | 6 ++----
3 files changed, 15 insertions(+), 9 deletions(-)
diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h
index 1d92532c2aae..6c43ef3e7308 100644
--- a/kernel/irq/internals.h
+++ b/kernel/irq/internals.h
@@ -98,6 +98,8 @@ extern void mask_irq(struct irq_desc *desc);
extern void unmask_irq(struct irq_desc *desc);
extern void unmask_threaded_irq(struct irq_desc *desc);
+extern unsigned int kstat_irqs_desc(struct irq_desc *desc, const struct cpumask *cpumask);
+
#ifdef CONFIG_SPARSE_IRQ
static inline void irq_mark_irq(unsigned int irq) { }
#else
diff --git a/kernel/irq/irqdesc.c b/kernel/irq/irqdesc.c
index 44e187763384..05498788ead5 100644
--- a/kernel/irq/irqdesc.c
+++ b/kernel/irq/irqdesc.c
@@ -960,24 +960,30 @@ static bool irq_is_nmi(struct irq_desc *desc)
return desc->istate & IRQS_NMI;
}
-static unsigned int kstat_irqs(unsigned int irq)
+unsigned int kstat_irqs_desc(struct irq_desc *desc, const struct cpumask *cpumask)
{
- struct irq_desc *desc = irq_to_desc(irq);
unsigned int sum = 0;
int cpu;
- if (!desc || !desc->kstat_irqs)
- return 0;
if (!irq_settings_is_per_cpu_devid(desc) &&
!irq_settings_is_per_cpu(desc) &&
!irq_is_nmi(desc))
return data_race(desc->tot_count);
- for_each_possible_cpu(cpu)
+ for_each_cpu(cpu, cpumask)
sum += data_race(per_cpu(desc->kstat_irqs->cnt, cpu));
return sum;
}
+static unsigned int kstat_irqs(unsigned int irq)
+{
+ struct irq_desc *desc = irq_to_desc(irq);
+
+ if (!desc || !desc->kstat_irqs)
+ return 0;
+ return kstat_irqs_desc(desc, cpu_possible_mask);
+}
+
#ifdef CONFIG_GENERIC_IRQ_STAT_SNAPSHOT
void kstat_snapshot_irqs(void)
diff --git a/kernel/irq/proc.c b/kernel/irq/proc.c
index 6954e0a02047..5c320c3f10a7 100644
--- a/kernel/irq/proc.c
+++ b/kernel/irq/proc.c
@@ -488,10 +488,8 @@ int show_interrupts(struct seq_file *p, void *v)
if (!desc || irq_settings_is_hidden(desc))
goto outsparse;
- if (desc->kstat_irqs) {
- for_each_online_cpu(j)
- any_count |= data_race(per_cpu(desc->kstat_irqs->cnt, j));
- }
+ if (desc->kstat_irqs)
+ any_count = kstat_irqs_desc(desc, cpu_online_mask);
if ((!desc->action || irq_desc_is_chained(desc)) && !any_count)
goto outsparse;
--
2.37.1 (Apple Git-137.1)
next prev parent reply other threads:[~2024-03-06 12:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-06 12:52 [PATCHv12 0/4] *** Detect interrupt storm in softlockup *** Bitao Hu
2024-03-06 12:52 ` [PATCHv12 1/4] genirq: Provide a snapshot mechanism for interrupt statistics Bitao Hu
2024-04-09 9:58 ` Thomas Gleixner
2024-04-10 6:45 ` Bitao Hu
2024-04-10 14:17 ` Thomas Gleixner
2024-03-06 12:52 ` Bitao Hu [this message]
2024-03-06 12:52 ` [PATCHv12 3/4] watchdog/softlockup: low-overhead detection of interrupt storm Bitao Hu
2024-03-06 12:52 ` [PATCHv12 4/4] watchdog/softlockup: report the most frequent interrupts Bitao Hu
2024-03-23 20:43 ` Thomas Gleixner
2024-03-25 9:47 ` Bitao Hu
2024-04-01 16:41 ` Doug Anderson
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=20240306125208.71803-3-yaoma@linux.alibaba.com \
--to=yaoma@linux.alibaba.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=akpm@linux-foundation.org \
--cc=deller@gmx.de \
--cc=dianders@chromium.org \
--cc=jan.kiszka@siemens.com \
--cc=kernelfans@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mips@vger.kernel.org \
--cc=linux-parisc@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=liusong@linux.alibaba.com \
--cc=npiggin@gmail.com \
--cc=pmladek@suse.com \
--cc=tglx@linutronix.de \
--cc=tsbogend@alpha.franken.de \
/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;
as well as URLs for NNTP newsgroup(s).