mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Radu Rendec <radu@rendec.net>
To: Thomas Gleixner <tglx@kernel.org>, LKML <linux-kernel@vger.kernel.org>
Cc: x86@kernel.org, Dmitry Ilvokhin <d@ilvokhin.com>,
	Neil Horman <nhorman@tuxdriver.com>
Subject: Re: [patch v2 06/14] genirq: Cache the condition for /proc/interrupts exposure
Date: Mon, 23 Mar 2026 16:58:54 -0400	[thread overview]
Message-ID: <7d0dcf3dc90152a71de920dd22cc5eed57bab695.camel@rendec.net> (raw)
In-Reply-To: <20260320132102.431714412@kernel.org>

On Fri, 2026-03-20 at 14:21 +0100, Thomas Gleixner wrote:
> show_interrupts() evaluates a boatload of conditions to establish whether
> exposing 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.
> 
> As a result the number of instructions and branches for reading
> /proc/interrupts is reduced significantly.
> 
> Signed-off-by: Thomas Gleixner <tglx@kernel.org>
> Reviewed-by: Dmitry Ilvokhin <d@ilvokhin.com>
> ---
> V2: s/IRQF_/IRQ/ and fixup the enum treatment - Dmitry
> ---
>  include/linux/irq.h    |    1 +
>  kernel/irq/chip.c      |    2 ++
>  kernel/irq/internals.h |    2 ++
>  kernel/irq/manage.c    |    2 ++
>  kernel/irq/proc.c      |   16 ++++++++++++----
>  kernel/irq/settings.h  |   13 +++++++++++++
>  6 files changed, 32 insertions(+), 4 deletions(-)
> 
> --- a/include/linux/irq.h
> +++ b/include/linux/irq.h
> @@ -99,6 +99,7 @@ enum {
>  	IRQ_DISABLE_UNLAZY	= (1 << 19),
>  	IRQ_HIDDEN		= (1 << 20),
>  	IRQ_NO_DEBUG		= (1 << 21),
> +	IRQ_RESERVED		= (1 << 22),
>  };
>  
>  #define IRQF_MODIFY_MASK	\
> --- a/kernel/irq/chip.c
> +++ b/kernel/irq/chip.c
> @@ -1004,6 +1004,7 @@ static void
>  		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,
> @@ -1064,6 +1065,7 @@ void irq_modify_status(unsigned int irq,
>  			trigger = tmp;
>  
>  		irqd_set(&desc->irq_data, trigger);
> +		irq_proc_update_valid(desc);
>  	}
>  }
>  EXPORT_SYMBOL_GPL(irq_modify_status);
> --- a/kernel/irq/internals.h
> +++ b/kernel/irq/internals.h
> @@ -123,6 +123,7 @@ extern void register_irq_proc(unsigned i
>  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
>  					 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);
> --- a/kernel/irq/manage.c
> +++ b/kernel/irq/manage.c
> @@ -1802,6 +1802,7 @@ static int
>  		__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(stru
>  		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
> --- a/kernel/irq/proc.c
> +++ b/kernel/irq/proc.c
> @@ -439,6 +439,17 @@ 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) || !desc->action ||
> +	    irq_desc_is_chained(desc) || !desc->kstat_irqs)

Can desc->kstat_irqs ever be NULL? Looking at kernel/irq/irqdesc.c, it
seems to me that it's allocated always and very early (before every
other field in struct irq_desc), and with an explicit check for NULL on
allocation. It's also deallocated late, right before struct irq_desc
itself is deallocated (in irq_kobj_release()).

Other than that, LGTM.

> +		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)
> @@ -514,10 +525,7 @@ int show_interrupts(struct seq_file *p,
>  
>  	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);
> --- a/kernel/irq/settings.h
> +++ b/kernel/irq/settings.h
> @@ -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
>  {
>  	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);
> +}

  reply	other threads:[~2026-03-23 20:59 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-20 13:21 [patch v2 00/14] Improve /proc/interrupts further and add a binary interface Thomas Gleixner
2026-03-20 13:21 ` [patch v2 01/14] x86/irq: Optimize interrupts decimals printing Thomas Gleixner
2026-03-21 16:10   ` Radu Rendec
2026-03-20 13:21 ` [patch v2 02/14] genirq/proc: Avoid formatting zero counts in /proc/interrupts Thomas Gleixner
2026-03-21 16:38   ` Radu Rendec
2026-03-20 13:21 ` [patch v2 03/14] genirq/proc: Utilize irq_desc::tot_count to avoid evaluation Thomas Gleixner
2026-03-22 19:59   ` Radu Rendec
2026-03-20 13:21 ` [patch v2 04/14] x86/irq: Make irqstats array based Thomas Gleixner
2026-03-20 16:39   ` Michael Kelley
2026-03-21 16:38     ` Thomas Gleixner
2026-03-21 20:32       ` Michael Kelley
2026-03-23 19:24   ` Radu Rendec
2026-03-24 19:54     ` Thomas Gleixner
2026-03-24 20:21       ` Thomas Gleixner
2026-03-24 20:32         ` Radu Rendec
2026-03-25 19:20           ` Radu Rendec
2026-03-25 22:52             ` Thomas Gleixner
2026-03-25 22:54               ` Florian Fainelli
2026-03-26 10:29                 ` Thomas Gleixner
2026-03-26 23:00                   ` Florian Fainelli
2026-03-27 11:03                     ` Thomas Gleixner
2026-03-26 12:34               ` Radu Rendec
2026-03-20 13:21 ` [patch v2 05/14] genirq: Expose nr_irqs in core code Thomas Gleixner
2026-03-23 19:48   ` Radu Rendec
2026-03-23 21:27     ` Thomas Gleixner
2026-03-20 13:21 ` [patch v2 06/14] genirq: Cache the condition for /proc/interrupts exposure Thomas Gleixner
2026-03-23 20:58   ` Radu Rendec [this message]
2026-03-24 20:31     ` Thomas Gleixner
2026-03-24 20:36       ` Radu Rendec
2026-03-20 13:21 ` [patch v2 07/14] genirq: Calculate precision only when required Thomas Gleixner
2026-03-25 19:47   ` Radu Rendec
2026-03-20 13:22 ` [patch v2 08/14] genirq: Add rcuref count to struct irq_desc Thomas Gleixner
2026-03-26 18:43   ` Dmitry Ilvokhin
2026-03-20 13:22 ` [patch v2 09/14] genirq: Expose irq_find_desc_at_or_after() in core code Thomas Gleixner
2026-03-26 19:13   ` Dmitry Ilvokhin
2026-03-26 21:11     ` Thomas Gleixner
2026-03-26 21:25       ` Thomas Gleixner
2026-03-20 13:22 ` [patch v2 10/14] genirq/proc: Speed up /proc/interrupts iteration Thomas Gleixner
2026-03-20 13:22 ` [patch v2 11/14] [RFC] genirq: Cache target CPU for single CPU affinities Thomas Gleixner
2026-03-20 13:22 ` [patch v2 12/14] [RFC] genirq/proc: Provide binary statistic interface Thomas Gleixner
2026-04-01 16:42   ` Dmitry Ilvokhin
2026-03-20 13:22 ` [patch v2 13/14] [RFC] genirq/proc: Provide architecture specific binary statistics Thomas Gleixner
2026-04-01 16:51   ` Dmitry Ilvokhin
2026-04-01 19:33     ` Thomas Gleixner
2026-03-20 13:22 ` [patch v2 14/14] [RFC] x86/irq: Hook up architecture specific stats Thomas Gleixner
2026-03-20 16:45 ` [patch v2 00/14] Improve /proc/interrupts further and add a binary interface Michael Kelley

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=7d0dcf3dc90152a71de920dd22cc5eed57bab695.camel@rendec.net \
    --to=radu@rendec.net \
    --cc=d@ilvokhin.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nhorman@tuxdriver.com \
    --cc=tglx@kernel.org \
    --cc=x86@kernel.org \
    /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

all inboxes | Powered by JetHome®