]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
genirq: Cache the condition for /proc/interrupts exposure
authorThomas Gleixner <tglx@kernel.org>
Sun, 17 May 2026 20:02:19 +0000 (22:02 +0200)
committerThomas Gleixner <tglx@kernel.org>
Tue, 26 May 2026 14:21:13 +0000 (16:21 +0200)
show_interrupts() evaluates a boatload of conditions to establish whether
it should expose an interrupt in /proc/interrupts or not.

That can be simplified by caching the condition in an internal status flag,
which is updated when one of the relevant inputs changes.

The irq_desc::kstat_irq check is dropped because visible interrupt
descriptors always have a valid pointer.

As a result the number of instructions and branches for reading
/proc/interrupts is reduced significantly.

Signed-off-by: Thomas Gleixner <tglx@kernel.org>
Tested-by: Michael Kelley <mhklinux@outlook.com>
Reviewed-by: Dmitry Ilvokhin <d@ilvokhin.com>
Reviewed-by: Radu Rendec <radu@rendec.net>
Link: https://patch.msgid.link/20260517194931.680943749@kernel.org
include/linux/irq.h
kernel/irq/chip.c
kernel/irq/internals.h
kernel/irq/manage.c
kernel/irq/proc.c
kernel/irq/settings.h

index efa514ee562fcf9137f8b047db32e1807283b07b..f485369b1b4f707167e7540a492795f8c3be1702 100644 (file)
@@ -103,6 +103,7 @@ enum {
        IRQ_DISABLE_UNLAZY      = (1 << 19),
        IRQ_HIDDEN              = (1 << 20),
        IRQ_NO_DEBUG            = (1 << 21),
+       IRQ_RESERVED            = (1 << 22),
 };
 
 #define IRQF_MODIFY_MASK       \
index 6c9b1dc4e7d4676363b138756e8ef903ef60dd77..2d283d1390dc53f78f6ca485f84bcb2ffda8fe01 100644 (file)
@@ -1007,6 +1007,7 @@ __irq_do_set_handler(struct irq_desc *desc, irq_flow_handler_t handle,
                WARN_ON(irq_chip_pm_get(irq_desc_get_irq_data(desc)));
                irq_activate_and_startup(desc, IRQ_RESEND);
        }
+       irq_proc_update_valid(desc);
 }
 
 void __irq_set_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
@@ -1067,6 +1068,7 @@ void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set)
                        trigger = tmp;
 
                irqd_set(&desc->irq_data, trigger);
+               irq_proc_update_valid(desc);
        }
 }
 EXPORT_SYMBOL_GPL(irq_modify_status);
index db359acdf27fca2fac7af0512c14603e1ded412f..e5f3d310a825087e14b9ee73a76e8f9366a91065 100644 (file)
@@ -123,6 +123,7 @@ extern void register_irq_proc(unsigned int irq, struct irq_desc *desc);
 extern void unregister_irq_proc(unsigned int irq, struct irq_desc *desc);
 extern void register_handler_proc(unsigned int irq, struct irqaction *action);
 extern void unregister_handler_proc(unsigned int irq, struct irqaction *action);
+void irq_proc_update_valid(struct irq_desc *desc);
 #else
 static inline void register_irq_proc(unsigned int irq, struct irq_desc *desc) { }
 static inline void unregister_irq_proc(unsigned int irq, struct irq_desc *desc) { }
@@ -130,6 +131,7 @@ static inline void register_handler_proc(unsigned int irq,
                                         struct irqaction *action) { }
 static inline void unregister_handler_proc(unsigned int irq,
                                           struct irqaction *action) { }
+static inline void irq_proc_update_valid(struct irq_desc *desc) { }
 #endif
 
 extern bool irq_can_set_affinity_usr(unsigned int irq);
index 8863b2d4b8ca40fcdf55fa2075031c95e9cd484a..7eb07e3bdb4c2419e0a58a75c29d88b4b00b8287 100644 (file)
@@ -1802,6 +1802,7 @@ __setup_irq(unsigned int irq, struct irq_desc *desc, struct irqaction *new)
                __enable_irq(desc);
        }
 
+       irq_proc_update_valid(desc);
        raw_spin_unlock_irqrestore(&desc->lock, flags);
        chip_bus_sync_unlock(desc);
        mutex_unlock(&desc->request_mutex);
@@ -1906,6 +1907,7 @@ static struct irqaction *__free_irq(struct irq_desc *desc, void *dev_id)
                desc->affinity_hint = NULL;
 #endif
 
+       irq_proc_update_valid(desc);
        raw_spin_unlock_irqrestore(&desc->lock, flags);
        /*
         * Drop bus_lock here so the changes which were done in the chip
@@ -2047,6 +2049,8 @@ static const void *__cleanup_nmi(unsigned int irq, struct irq_desc *desc)
                irq_shutdown_and_deactivate(desc);
        }
 
+       irq_proc_update_valid(desc);
+
        if (action)
                unregister_handler_proc(irq, action);
        kfree(action);
@@ -2433,8 +2437,10 @@ static struct irqaction *__free_percpu_irq(unsigned int irq, void __percpu *dev_
                *action_ptr = action->next;
 
                /* Demote from NMI if we killed the last action */
-               if (!desc->action)
+               if (!desc->action) {
                        desc->istate &= ~IRQS_NMI;
+                       irq_proc_update_valid(desc);
+               }
        }
 
        unregister_handler_proc(irq, action);
index d5b812680f5ca48e83b389995a70e01bb0027bb6..cc9c7c907dd2af7ebfe7ac37cba749db1438f158 100644 (file)
@@ -440,6 +440,16 @@ void init_irq_proc(void)
                register_irq_proc(irq, desc);
 }
 
+void irq_proc_update_valid(struct irq_desc *desc)
+{
+       u32 set = _IRQ_PROC_VALID;
+
+       if (irq_settings_is_hidden(desc) || irq_desc_is_chained(desc) || !desc->action)
+               set = 0;
+
+       irq_settings_update_proc_valid(desc, set);
+}
+
 #ifdef CONFIG_GENERIC_IRQ_SHOW
 
 int __weak arch_show_interrupts(struct seq_file *p, int prec)
@@ -516,10 +526,7 @@ int show_interrupts(struct seq_file *p, void *v)
 
        guard(rcu)();
        desc = irq_to_desc(i);
-       if (!desc || irq_settings_is_hidden(desc))
-               return 0;
-
-       if (!desc->action || irq_desc_is_chained(desc) || !desc->kstat_irqs)
+       if (!desc || !irq_settings_proc_valid(desc))
                return 0;
 
        seq_printf(p, "%*d:", prec, i);
index 00b3bd127692cb8ea8bd0750b35e589fb15367af..0a0c027a5d3426cf1df951969cbc056287cf359b 100644 (file)
@@ -18,6 +18,7 @@ enum {
        _IRQ_DISABLE_UNLAZY     = IRQ_DISABLE_UNLAZY,
        _IRQ_HIDDEN             = IRQ_HIDDEN,
        _IRQ_NO_DEBUG           = IRQ_NO_DEBUG,
+       _IRQ_PROC_VALID         = IRQ_RESERVED,
        _IRQF_MODIFY_MASK       = IRQF_MODIFY_MASK,
 };
 
@@ -34,6 +35,7 @@ enum {
 #define IRQ_DISABLE_UNLAZY     GOT_YOU_MORON
 #define IRQ_HIDDEN             GOT_YOU_MORON
 #define IRQ_NO_DEBUG           GOT_YOU_MORON
+#define IRQ_RESERVED           GOT_YOU_MORON
 #undef IRQF_MODIFY_MASK
 #define IRQF_MODIFY_MASK       GOT_YOU_MORON
 
@@ -180,3 +182,14 @@ static inline bool irq_settings_no_debug(struct irq_desc *desc)
 {
        return desc->status_use_accessors & _IRQ_NO_DEBUG;
 }
+
+static inline bool irq_settings_proc_valid(struct irq_desc *desc)
+{
+       return desc->status_use_accessors & _IRQ_PROC_VALID;
+}
+
+static inline void irq_settings_update_proc_valid(struct irq_desc *desc, u32 set)
+{
+       desc->status_use_accessors &= ~_IRQ_PROC_VALID;
+       desc->status_use_accessors |= (set & _IRQ_PROC_VALID);
+}