]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
x86/irq: Suppress unlikely interrupt stats by default
authorThomas Gleixner <tglx@kernel.org>
Sun, 17 May 2026 20:01:54 +0000 (22:01 +0200)
committerThomas Gleixner <tglx@kernel.org>
Tue, 26 May 2026 14:21:12 +0000 (16:21 +0200)
Unlikely interrupt counters like the spurious vector and the synthetic APIC
ICR read retry show up in /proc/interrupts with all counts 0 most of the
time.

As these are events which should never happen, suppress them by default and
enable them for output when they actually happen.

This requires a seperate bitmap as the description array is marked
__ro_after_init. With that bitmap in place it becomes RO data.

Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Tested-by: Michael Kelley <mhklinux@outlook.com>
Reviewed-by: Radu Rendec <radu@rendec.net>
Link: https://patch.msgid.link/20260517194931.276486277@kernel.org
arch/x86/include/asm/hardirq.h
arch/x86/kernel/apic/apic.c
arch/x86/kernel/apic/ipi.c
arch/x86/kernel/irq.c

index 423fa4d068a7daee1ce07015247994d78607c724..6723b512c6944739c12ca6649916572af300b770 100644 (file)
@@ -68,6 +68,7 @@ DECLARE_PER_CPU_ALIGNED(struct pi_desc, posted_msi_pi_desc);
 #define __ARCH_IRQ_STAT
 
 #define inc_irq_stat(index)    this_cpu_inc(irq_stat.counts[IRQ_COUNT_##index])
+void irq_stat_inc_and_enable(enum irq_stat_counts which);
 
 #ifdef CONFIG_X86_LOCAL_APIC
 #define inc_perf_irq_stat()    inc_irq_stat(APIC_PERF)
index 6599e8004d94a0aafd1fe1cb23df097c34ca0a6f..e27c263d6c13b5227a2700834bef214e558ecd79 100644 (file)
@@ -2114,7 +2114,7 @@ static noinline void handle_spurious_interrupt(u8 vector)
 
        trace_spurious_apic_entry(vector);
 
-       inc_irq_stat(SPURIOUS);
+       irq_stat_inc_and_enable(IRQ_COUNT_SPURIOUS);
 
        /*
         * If this is a spurious interrupt then do not acknowledge
index 3635c4d7b7f5cc805539b9baa07a22044bed9747..c627bee3b14f7365f6a24a4dd1430a7688fd3669 100644 (file)
@@ -120,7 +120,7 @@ u32 apic_mem_wait_icr_idle_timeout(void)
        for (cnt = 0; cnt < 1000; cnt++) {
                if (!(apic_read(APIC_ICR) & APIC_ICR_BUSY))
                        return 0;
-               inc_irq_stat(ICR_READ_RETRY);
+               irq_stat_inc_and_enable(IRQ_COUNT_ICR_READ_RETRY);
                udelay(100);
        }
        return APIC_ICR_BUSY;
index decd08d3d3151872f17a1d0b918961dcf4c9add9..2d8ca411661086a36cea2127ff0ae06b157d440c 100644 (file)
@@ -68,19 +68,24 @@ struct irq_stat_info {
        const char      *text;
 };
 
+#define DEFAULT_SUPPRESSED_VECTOR      UINT_MAX
+
 #define ISS(idx, sym, txt) [IRQ_COUNT_##idx] = { .symbol = sym, .text = txt }
 
 #define ITS(idx, sym, txt) [IRQ_COUNT_##idx] =                         \
        { .skip_vector = idx## _VECTOR, .symbol = sym, .text = txt }
 
-static struct irq_stat_info irq_stat_info[IRQ_COUNT_MAX] __ro_after_init = {
+#define IDS(idx, sym, txt) [IRQ_COUNT_##idx] =                         \
+       { .skip_vector = DEFAULT_SUPPRESSED_VECTOR, .symbol = sym, .text = txt }
+
+static const struct irq_stat_info irq_stat_info[IRQ_COUNT_MAX] = {
        ISS(NMI,                        "NMI",  "  Non-maskable interrupts\n"),
 #ifdef CONFIG_X86_LOCAL_APIC
        ISS(APIC_TIMER,                 "LOC",  "  Local timer interrupts\n"),
-       ISS(SPURIOUS,                   "SPU",  "  Spurious interrupts\n"),
+       IDS(SPURIOUS,                   "SPU",  "  Spurious interrupts\n"),
        ISS(APIC_PERF,                  "PMI",  "  Performance monitoring interrupts\n"),
        ISS(IRQ_WORK,                   "IWI",  "  IRQ work interrupts\n"),
-       ISS(ICR_READ_RETRY,             "RTR",  "  APIC ICR read retries\n"),
+       IDS(ICR_READ_RETRY,             "RTR",  "  APIC ICR read retries\n"),
        ISS(X86_PLATFORM_IPI,           "PLT",  "  Platform interrupts\n"),
 #endif
 #ifdef CONFIG_SMP
@@ -121,34 +126,47 @@ static struct irq_stat_info irq_stat_info[IRQ_COUNT_MAX] __ro_after_init = {
 #endif
 };
 
+static DECLARE_BITMAP(irq_stat_count_show, IRQ_COUNT_MAX) __read_mostly;
+
 static int __init irq_init_stats(void)
 {
-       struct irq_stat_info *info = irq_stat_info;
+       const struct irq_stat_info *info = irq_stat_info;
 
        for (unsigned int i = 0; i < ARRAY_SIZE(irq_stat_info); i++, info++) {
-               if (info->skip_vector && test_bit(info->skip_vector, system_vectors))
-                       info->skip_vector = 0;
+               if (!info->skip_vector || (info->skip_vector != DEFAULT_SUPPRESSED_VECTOR &&
+                                          test_bit(info->skip_vector, system_vectors)))
+                       set_bit(i, irq_stat_count_show);
        }
 
 #ifdef CONFIG_X86_LOCAL_APIC
        if (!x86_platform_ipi_callback)
-               irq_stat_info[IRQ_COUNT_X86_PLATFORM_IPI].skip_vector = 1;
+               clear_bit(IRQ_COUNT_X86_PLATFORM_IPI, irq_stat_count_show);
 #endif
 
 #ifdef CONFIG_X86_POSTED_MSI
        if (!posted_msi_enabled())
-               irq_stat_info[IRQ_COUNT_POSTED_MSI_NOTIFICATION].skip_vector = 1;
+               clear_bit(IRQ_COUNT_POSTED_MSI_NOTIFICATION, irq_stat_count_show);
 #endif
 
 #ifdef CONFIG_X86_MCE_AMD
        if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD &&
            boot_cpu_data.x86_vendor != X86_VENDOR_HYGON)
-               irq_stat_info[IRQ_COUNT_DEFERRED_ERROR].skip_vector = 1;
+               clear_bit(IRQ_COUNT_DEFERRED_ERROR, irq_stat_count_show);
 #endif
        return 0;
 }
 late_initcall(irq_init_stats);
 
+/*
+ * Used for default disabled counters to increment the stats and to enable the
+ * entry for /proc/interrupts output.
+ */
+void irq_stat_inc_and_enable(enum irq_stat_counts which)
+{
+       this_cpu_inc(irq_stat.counts[which]);
+       set_bit(which, irq_stat_count_show);
+}
+
 #ifdef CONFIG_PROC_FS
 /*
  * /proc/interrupts printing for arch specific interrupts
@@ -158,7 +176,7 @@ int arch_show_interrupts(struct seq_file *p, int prec)
        const struct irq_stat_info *info = irq_stat_info;
 
        for (unsigned int i = 0; i < ARRAY_SIZE(irq_stat_info); i++, info++) {
-               if (info->skip_vector)
+               if (!test_bit(i, irq_stat_count_show))
                        continue;
 
                seq_printf(p, "%*s:", prec, info->symbol);