public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Mark Rutland <mark.rutland@arm.com>
Cc: linux-kernel@vger.kernel.org, tglx@linutronix.de, maz@kernel.org,
	paulmck@kernel.org
Subject: Re: [PATCH v3 1/2] irq: abstract irqaction handler invocation
Date: Thu, 15 Jul 2021 15:10:44 +0200	[thread overview]
Message-ID: <20210715131044.GB4717@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <20210715111531.GA56828@C02TD0UTHF1T.local>

On Thu, Jul 15, 2021 at 12:15:31PM +0100, Mark Rutland wrote:
> On Thu, Jul 15, 2021 at 12:49:54PM +0200, Peter Zijlstra wrote:
> > On Thu, Jul 15, 2021 at 10:50:30AM +0100, Mark Rutland wrote:
> > > diff --git a/kernel/irq/internals.h b/kernel/irq/internals.h
> > > index 54363527feea..70a4694cc891 100644
> > > --- a/kernel/irq/internals.h
> > > +++ b/kernel/irq/internals.h
> > > @@ -11,6 +11,8 @@
> > >  #include <linux/pm_runtime.h>
> > >  #include <linux/sched/clock.h>
> > >  
> > > +#include <trace/events/irq.h>
> > > +
> > >  #ifdef CONFIG_SPARSE_IRQ
> > >  # define IRQ_BITMAP_BITS	(NR_IRQS + 8196)
> > >  #else
> > > @@ -107,6 +109,32 @@ irqreturn_t __handle_irq_event_percpu(struct irq_desc *desc, unsigned int *flags
> > >  irqreturn_t handle_irq_event_percpu(struct irq_desc *desc);
> > >  irqreturn_t handle_irq_event(struct irq_desc *desc);
> > >  
> > > +static inline irqreturn_t __handle_irqaction(unsigned int irq,
> > > +					     struct irqaction *action,
> > > +					     void *dev_id)
> > > +{
> > > +	irqreturn_t res;
> > > +
> > > +	trace_irq_handler_entry(irq, action);
> > > +	res = action->handler(irq, dev_id);
> > > +	trace_irq_handler_exit(irq, action, res);
> > > +
> > > +	return res;
> > > +}
> > > +
> > > +static inline irqreturn_t handle_irqaction(unsigned int irq,
> > > +					   struct irqaction *action)
> > > +{
> > > +	return __handle_irqaction(irq, action, action->dev_id);
> > > +}
> > > +
> > > +static inline irqreturn_t handle_irqaction_percpu_devid(unsigned int irq,
> > > +							struct irqaction *action)
> > > +{
> > > +	return __handle_irqaction(irq, action,
> > > +				  raw_cpu_ptr(action->percpu_dev_id));
> > > +}
> > 
> > So I like this patch, it's a nice cleanup.
> > 
> > However, you could implement the next patch as a module that hooks into
> > those two tracepoints. Quite possibly the existing IRQ latency tracer
> > would already work for what you need and also provide you a function
> > trace of WTH the CPU was doing.
> 
> The issue with the existing tracers is that they're logging for
> later/concurrent analysis, whereas what I need is a notification (e.g. a
> WARN) when the maximum expected latency has been breached. That way it
> gets caught by Syzkaller or whatever without needing to specially manage
> the tracer.
> 
> If there's a way to do that (e.g. with boot-time options), I'm happy to
> use that instead; I just couldn't see hwo to do that today, and was
> under the impression that the existing tracepoints don't give quite what
> I need (e.g. since the entry/exit hooks are separate, so I'd have to
> store some state somewhere else).
> 
> I'm happy to take another look if you think I'm wrong on that. :)

For this particular thing I think you can use a simple per-cpu variable;
we don't do nested interrupts.

DEFINE_PER_CPU(u64, my_timestamp);

static notrace void my_entry(unsigned int irq, struct irq_action *action)
{
	this_cpu_write(my_timestamp, sched_clock());
}

static notrace void my_exit(unsigned int irq, struct irq_action *action)
{
	u64 delta = sched_clock() - this_cpu_read(my_timestamp);
	WARN_ON_ONCE(delta > biggie);
}

__init int mod_init(void)
{
	register_trace_irq_handler_exit(my_exit, NULL);
	register_trace_irq_handler_entry(my_entry, NULL);
}

Should work, no?

  reply	other threads:[~2021-07-15 13:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-07-15  9:50 [PATCH v3 0/2] irq: detect slow IRQ handlers Mark Rutland
2021-07-15  9:50 ` [PATCH v3 1/2] irq: abstract irqaction handler invocation Mark Rutland
2021-07-15 10:49   ` Peter Zijlstra
2021-07-15 11:15     ` Mark Rutland
2021-07-15 13:10       ` Peter Zijlstra [this message]
2021-07-15  9:50 ` [PATCH v3 2/2] irq: detect long-running IRQ handlers Mark Rutland

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=20210715131044.GB4717@worktop.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maz@kernel.org \
    --cc=paulmck@kernel.org \
    --cc=tglx@linutronix.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