Linux Trace Kernel
 help / color / mirror / Atom feed
From: Gabriele Monaco <gmonaco@redhat.com>
To: Karl Mehltretter <kmehltretter@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>
Cc: Masami Hiramatsu <mhiramat@kernel.org>,
	Mathieu Desnoyers	 <mathieu.desnoyers@efficios.com>,
	Thomas Gleixner <tglx@kernel.org>,
	 Sebastian Andrzej Siewior	 <bigeasy@linutronix.de>,
	Clark Williams <clrkwllms@kernel.org>,
	Ingo Molnar	 <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Andy Lutomirski	 <luto@kernel.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot	 <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	 Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	 K Prateek Nayak <kprateek.nayak@amd.com>,
	Jonathan Corbet <corbet@lwn.net>,
	Shuah Khan <skhan@linuxfoundation.org>,
	 Randy Dunlap <rdunlap@infradead.org>,
	Wen Yang <wen.yang@linux.dev>,
	linux-trace-kernel@vger.kernel.org,
		linux-rt-devel@lists.linux.dev, linux-doc@vger.kernel.org,
		linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH v2 1/9] tracing/irq: Add generic IRQ context boundary tracepoints
Date: Sat, 21 Nov 2026 11:26:44 +0100	[thread overview]
Message-ID: <661a3aad86b215989dfc916fa9f568c66e18a466.camel@redhat.com> (raw)
In-Reply-To: <20261107171252.25090-2-kmehltretter@gmail.com>

On Sat, 2026-11-07 at 18:12 +0100, Karl Mehltretter wrote:
...
>  void __local_bh_disable_ip(unsigned long ip, unsigned int cnt)
>  {
> +	unsigned long trace_flags = 0;
>  	unsigned long flags;
> +	bool trace_serving;
>  	int newcnt;
>  
>  	WARN_ON_ONCE(in_hardirq());
> @@ -200,6 +202,16 @@ void __local_bh_disable_ip(unsigned long ip, unsigned int
> cnt)
>  		}
>  	}
>  
> +	/*
> +	 * A serving interval starts here, before handle_softirqs(). When its
> +	 * entry is traced, keep IRQs and task switches from observing the
> bit
> +	 * before the event. Any blocking BH lock was acquired above.
> +	 */
> +	trace_serving = (cnt & SOFTIRQ_OFFSET) &&
> +			trace_softirq_context_entry_tp_enabled();
> +	if (trace_serving)
> +		local_irq_save(trace_flags);
> +
>  	/*
>  	 * Track the per CPU softirq disabled state. On RT this is per CPU
>  	 * state to allow preemption of bottom half disabled sections.
> @@ -233,15 +245,27 @@ void __local_bh_disable_ip(unsigned long ip, unsigned
> int cnt)
>  			raw_local_irq_restore(flags);
>  		}
>  	}
> +
> +	if (trace_serving) {
> +		trace_softirq_context_entry_tp(!!in_serving_softirq(),
> false);

Probably someone more experienced with this code can comment whether the
tracepoints and other things you do make sense, you're going to need an
ack from these folks anyway.

From the tracing point of view. You're doing good avoiding any extra
action if trace_##_enabled() is false. Since you are already checking
for it, you may simplify the call to the tracepoint, essentially

 trace_##_tp() <=> if (trace_##_enabled()) trace_call__##_tp()

As you see, you're basically checking for the static key twice. Not a
big deal but you can use the new API and skip it:

  s/trace_softirq_context_entry_tp/trace_call__sched_set_state_tp/

Obviously you do the trace_call__##_tp() function ONLY if you're already
checking the static key.

> +		local_irq_restore(trace_flags);
> +	}
>  }
>  EXPORT_SYMBOL(__local_bh_disable_ip);
>  
>  static void __local_bh_enable(unsigned int cnt, bool unlock)
>  {
> +	bool entering = (cnt & SOFTIRQ_OFFSET) && !in_serving_softirq();
> +	bool trace_exiting = (cnt & SOFTIRQ_OFFSET) && !entering &&
> +			     trace_softirq_context_exit_tp_enabled();
>  	unsigned long flags;
>  	bool sirq_en = false;
>  	int newcnt;
>  
> +	/* Callers already disabled IRQs around the counter and its events.
> */
> +	if (trace_exiting)
> +		trace_softirq_context_exit_tp(!!in_serving_softirq(), false);

Here as well, you're checking so you can simply trace_call()

> +
>  	if (IS_ENABLED(CONFIG_PREEMPT_RT_NEEDS_BH_LOCK)) {
>  		DEBUG_LOCKS_WARN_ON(current->softirq_disable_cnt !=
>  				    this_cpu_read(softirq_ctrl.cnt));
> @@ -276,6 +300,18 @@ static void __local_bh_enable(unsigned int cnt, bool
> unlock)
>  			WARN_ON_ONCE(current->softirq_disable_cnt < 0);
>  		}
>  	}
> +
> +	/*
> +	 * An exit probe can raise a softirq while serving state still
> suppresses
> +	 * the normal ksoftirqd wakeup. Hand it off once no outer BH-disable
> +	 * reference remains.
> +	 */
> +	if (trace_exiting && sirq_en && unlikely(local_softirq_pending()))
> +		wakeup_softirqd();
> +
> +	/* local_bh_enable() can turn BH-disabled state into serving state.
> */
> +	if (entering)
> +		trace_softirq_context_entry_tp(!!in_serving_softirq(),
> false);

Here for example, entering doesn't check the static key so you must keep
the tracing as is.

>  }
>  
>  void __local_bh_enable_ip(unsigned long ip, unsigned int cnt)
> @@ -640,11 +676,15 @@ static void handle_softirqs(bool ksirqd)
>  	 */
>  	current->flags &= ~PF_MEMALLOC;
>  
> -	pending = local_softirq_pending();
> -
>  	from_irq_exit = softirq_handle_begin();
>  	in_hardirq = lockdep_softirq_start();
>  	account_softirq_enter(current);
> +	if (!IS_ENABLED(CONFIG_PREEMPT_RT))
> +		trace_softirq_context_entry_tp(!!in_serving_softirq(),
> +					       from_irq_exit);
> +
> +	/* Include work raised by the context-entry event. */
> +	pending = local_softirq_pending();
>  
>  restart:
>  	/* Reset the pending bitmask before enabling irqs */
> @@ -692,6 +732,14 @@ static void handle_softirqs(bool ksirqd)
>  		wakeup_softirqd();
>  	}
>  
> +	if (!IS_ENABLED(CONFIG_PREEMPT_RT) &&
> +	    trace_softirq_context_exit_tp_enabled()) {
> +		trace_softirq_context_exit_tp(!!in_serving_softirq(),
> +					      from_irq_exit);
> +		/* The final pending-work decision above has already
> completed. */
> +		if (unlikely(local_softirq_pending()))
> +			wakeup_softirqd();
> +	}
>  	account_softirq_exit(current);
>  	lockdep_softirq_end(in_hardirq);
>  	softirq_handle_end(from_irq_exit);
> @@ -722,6 +770,7 @@ void irq_enter_rcu(void)
>  		tick_irq_enter();
>  
>  	account_hardirq_enter(current);
> +	trace_hardirq_context_entry_tp(hardirq_count() >> HARDIRQ_SHIFT);

Here again, no check, so keep it as is.

Thanks,
Gabriele


  reply	other threads:[~2026-11-21 10:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-07 17:12 [RFC PATCH v2 0/9] rv: Verify generic IRQ context transitions Karl Mehltretter
2026-11-07 17:12 ` [RFC PATCH v2 1/9] tracing/irq: Add generic IRQ context boundary tracepoints Karl Mehltretter
2026-11-21 10:26   ` Gabriele Monaco [this message]
2026-11-07 17:12 ` [RFC PATCH v2 2/9] tracing/sched: Add IRQ preemption lifecycle tracepoints Karl Mehltretter
2026-11-21 10:35   ` Gabriele Monaco
2026-11-07 17:12 ` [RFC PATCH v2 3/9] rv: Add a monitor for generic IRQ context transitions Karl Mehltretter
2026-11-07 17:12 ` [RFC PATCH v2 4/9] rv: Add a monitor for IRQ-exit scheduling ownership Karl Mehltretter
2026-11-07 17:12 ` [RFC PATCH v2 5/9] docs/rv: Document the IRQ monitors Karl Mehltretter
2026-11-07 17:12 ` [RFC PATCH v2 6/9] rv: Add KUnit coverage for IRQ context transitions Karl Mehltretter
2026-11-07 17:12 ` [RFC PATCH v2 7/9] rv: Add KUnit coverage for IRQ-exit scheduling Karl Mehltretter
2026-11-07 17:12 ` [RFC PATCH v2 8/9] rv: Test empty PREEMPT_RT softirq worker intervals Karl Mehltretter
2026-11-07 17:12 ` [RFC PATCH v2 9/9] rv: Test IRQ-exit softirq provenance and handoff Karl Mehltretter

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=661a3aad86b215989dfc916fa9f568c66e18a466.camel@redhat.com \
    --to=gmonaco@redhat.com \
    --cc=bigeasy@linutronix.de \
    --cc=bsegall@google.com \
    --cc=clrkwllms@kernel.org \
    --cc=corbet@lwn.net \
    --cc=dietmar.eggemann@arm.com \
    --cc=juri.lelli@redhat.com \
    --cc=kmehltretter@gmail.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mgorman@suse.de \
    --cc=mhiramat@kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rdunlap@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=skhan@linuxfoundation.org \
    --cc=tglx@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    --cc=wen.yang@linux.dev \
    /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