linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Slaby <jirislaby@kernel.org>
To: Wladislav Wiebe <wladislav.wiebe@nokia.com>,
	tglx@linutronix.de, corbet@lwn.net
Cc: akpm@linux-foundation.org, paulmck@kernel.org,
	rostedt@goodmis.org, Neeraj.Upadhyay@amd.com, david@redhat.com,
	bp@alien8.de, arnd@arndb.de, fvdl@google.com,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org,
	peterz@infradead.org
Subject: Re: [PATCH v2] genirq: add support for warning on long-running IRQ handlers
Date: Tue, 22 Jul 2025 10:21:47 +0200	[thread overview]
Message-ID: <adbc919f-772b-46f1-99fb-d05cf0989763@kernel.org> (raw)
In-Reply-To: <20250714084209.918-1-wladislav.wiebe@nokia.com>

On 14. 07. 25, 10:41, Wladislav Wiebe wrote:
> This patch adds a mechanism to detect and warn about long-running IRQ
> handlers exceeding a user-defined duration threshold in microseconds.
> 
> The feature is enabled via the kernel boot parameter:
> "irqhandler.duration_warn_us=<threshold_in_us>"
> 
> For example, passing irqhandler.duration_warn_us=1000 will warn if an
> IRQ handler takes more than 1000 microseconds.
> 
> Implementation uses local_clock() to measure the execution duration of
> IRQ handlers. When the threshold is exceeded, a ratelimited warning is
> printed:
> 
> "[CPU14] long duration on IRQ[159:bad_irq_handler [long_irq]], took: 1330 us"
> 
> Signed-off-by: Wladislav Wiebe <wladislav.wiebe@nokia.com>
> ---
> V1 -> V2: refactor to use local_clock() instead of jiffies and replace
> 	  Kconfig knobs by a new command-line parameter.
> V1 link:  https://lore.kernel.org/lkml/20250630124721.18232-1-wladislav.wiebe@nokia.com/
> ---
>   .../admin-guide/kernel-parameters.txt         |  5 ++
>   kernel/irq/handle.c                           | 48 ++++++++++++++++++-
>   2 files changed, 52 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index f1f2c0874da9..fa89f21ea1e6 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -2543,6 +2543,11 @@
>   			for it. Intended to get systems with badly broken
>   			firmware running.
>   
> +	irqhandler.duration_warn_us= [KNL,EARLY]
> +			Warn if an IRQ handler exceeds the specified duration
> +			threshold in microseconds. Useful for identifying
> +			long-running IRQs in the system.
> +
>   	irqpoll		[HW]
>   			When an interrupt is not handled search all handlers
>   			for it. Also check all handlers each timer
> diff --git a/kernel/irq/handle.c b/kernel/irq/handle.c
> index 9489f93b3db3..eab8fdfab8d8 100644
> --- a/kernel/irq/handle.c
> +++ b/kernel/irq/handle.c
> @@ -136,6 +136,44 @@ void __irq_wake_thread(struct irq_desc *desc, struct irqaction *action)
>   	wake_up_process(action->thread);
>   }
>   
> +static DEFINE_STATIC_KEY_FALSE(irqhandler_duration_check_enabled);
> +static u64 irqhandler_duration_threshold_us __ro_after_init;
> +
> +static int __init irqhandler_duration_check_setup(char *arg)
> +{
> +	unsigned long val;
> +	int ret;
> +
> +	if (!arg)
> +		return 0;
> +
> +	ret = kstrtoul(arg, 0, &val);
> +	if (ret)
> +		return ret;
> +
> +	if (val > 0) {
> +		irqhandler_duration_threshold_us = val;
> +		static_branch_enable(&irqhandler_duration_check_enabled);
> +	} else {
> +		pr_err("Invalid irqhandler.duration_warn_us setting (%lu)\n", val);
> +		return -EINVAL;

Perhaps invert the condition and drop the "else {}"?

> +	}
> +
> +	return 0;
> +}
> +early_param("irqhandler.duration_warn_us", irqhandler_duration_check_setup);
> +
> +static inline void irqhandler_duration_check(u64 ts_start, unsigned int irq,
> +					      struct irqaction *action)

Can be const.

> +{
> +	u64 delta_us = (local_clock() - ts_start) >> 10;
> +
> +	if (unlikely(delta_us > irqhandler_duration_threshold_us)) {
> +		pr_warn_ratelimited("[CPU%d] long duration on IRQ[%u:%ps], took: %llu us\n",

s/%d/%u/.
Do you mean "of IRQ[...]"?

> +			smp_processor_id(), irq, action->handler, delta_us);
> +	}
> +}
> +
>   irqreturn_t __handle_irq_event_percpu(struct irq_desc *desc)
>   {
>   	irqreturn_t retval = IRQ_NONE;

thanks,
-- 
js
suse labs


  parent reply	other threads:[~2025-07-22  8:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-14  8:41 [PATCH v2] genirq: add support for warning on long-running IRQ handlers Wladislav Wiebe
2025-07-18 20:53 ` Thomas Gleixner
2025-07-23 18:39   ` Wladislav Wiebe
2025-07-22  8:21 ` Jiri Slaby [this message]
2025-07-23 18:34   ` Wladislav Wiebe

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=adbc919f-772b-46f1-99fb-d05cf0989763@kernel.org \
    --to=jirislaby@kernel.org \
    --cc=Neeraj.Upadhyay@amd.com \
    --cc=akpm@linux-foundation.org \
    --cc=arnd@arndb.de \
    --cc=bp@alien8.de \
    --cc=corbet@lwn.net \
    --cc=david@redhat.com \
    --cc=fvdl@google.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@linutronix.de \
    --cc=wladislav.wiebe@nokia.com \
    /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).