From: Nam Cao <namcao@linutronix.de>
To: Gabriele Monaco <gmonaco@redhat.com>
Cc: Steven Rostedt <rostedt@goodmis.org>,
linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org,
john.ogness@linutronix.de, Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>, Will Deacon <will@kernel.org>,
Boqun Feng <boqun.feng@gmail.com>,
Waiman Long <longman@redhat.com>
Subject: Re: [PATCH v5 21/23] rv: Add rtapp_sleep monitor
Date: Tue, 29 Apr 2025 19:20:55 +0200 [thread overview]
Message-ID: <20250429172055.QICnVQ2s@linutronix.de> (raw)
In-Reply-To: <bfe8322cf5817037af57f10ffbffcd9b30f43b42.camel@redhat.com>
On Tue, Apr 29, 2025 at 06:01:01PM +0200, Gabriele Monaco wrote:
> On Tue, 2025-04-29 at 14:01 +0200, Nam Cao wrote:
> > Add a monitor for checking that real-time tasks do not go to sleep in
> > a
> > manner that may cause undesirable latency.
> >
> > Also change
> > RV depends on TRACING
> > to
> > RV select TRACING
> > to avoid the following recursive dependency:
> >
> > error: recursive dependency detected!
> > symbol TRACING is selected by PREEMPTIRQ_TRACEPOINTS
> > symbol PREEMPTIRQ_TRACEPOINTS depends on TRACE_IRQFLAGS
> > symbol TRACE_IRQFLAGS is selected by RV_MON_SLEEP
> > symbol RV_MON_SLEEP depends on RV
> > symbol RV depends on TRACING
> >
> > Reviewed-by: Gabriele Monaco <gmonaco@redhat.com>
> > Signed-off-by: Nam Cao <namcao@linutronix.de>
> > ---
> > Cc: Peter Zijlstra <peterz@infradead.org>
> > Cc: Ingo Molnar <mingo@redhat.com>
> > Cc: Will Deacon <will@kernel.org>
> > Cc: Boqun Feng <boqun.feng@gmail.com>
> > Cc: Waiman Long <longman@redhat.com>
> > ---
> >
> > [...]
> >
> > +RULE = always ((RT and SLEEP) imply (RT_FRIENDLY_SLEEP or
> > ALLOWLIST))
> > +
> > +RT_FRIENDLY_SLEEP = (RT_VALID_SLEEP_REASON or KERNEL_THREAD)
> > + and ((not WAKE) until RT_FRIENDLY_WAKE)
> > +
> > +RT_VALID_SLEEP_REASON = PI_FUTEX
> > + or RT_FRIENDLY_NANOSLEEP
> > +
> > +RT_FRIENDLY_NANOSLEEP = CLOCK_NANOSLEEP
> > + and NANOSLEEP_TIMER_ABSTIME
> > + and NANOSLEEP_CLOCK_MONOTONIC
> > +
> > +RT_FRIENDLY_WAKE = WOKEN_BY_EQUAL_OR_HIGHER_PRIO
> > + or WOKEN_BY_HARDIRQ
> > + or WOKEN_BY_NMI
> > + or KTHREAD_SHOULD_STOP
> > +
> > +ALLOWLIST = BLOCK_ON_RT_MUTEX
> > + or TASK_IS_RCU
> > + or TASK_IS_MIGRATION
>
> So, just thinking out loud, PI_FUTEX is a valid sleep reason,
> technically also BLOCK_ON_RT_MUTEX is something you are allowing.
>
> In my understanding, the contention tracepoints already in the kernel
> can track all contention by kernel code and are leaving aside the PI
> futexes, which use the untracked rt_mutex_wait_proxy_lock.
>
> In your case, you are tracking PI_FUTEX via the system call, which
> should cover the above scenario.
>
> Do you really need extra tracepoints to track this too? Or is there any
> other use of start_proxy_lock/wait_proxy_lock I'm missing here?
>
> I see the only case in which rt_mutex_start_proxy_lock is called with a
> task different than current is via FUTEX_CMP_REQUEUE_PI, wouldn't
> considering this one too make the new tracepoints superfluous (assuming
> this one is even needed to be tracked before FUTEX_WAIT_REQUEUE_PI).
The monitor allows PI_FUTEX and allows BLOCK_ON_RT_MUTEX in different
manners.
PI_FUTEX is only a valid sleep reason. If a task sleeps with PI_FUTEX=true,
it still has to obey ((not WAKE) until RT_FRIENDLY_WAKE)
On the other hand, BLOCK_ON_RT_MUTEX alone is good enough. Waker is not
checked due to how rt_mutex is implemented: when a task unlocks an rt_mutex
and wakes waiter, the task is priority-deboosted first before doing the
wakeup, and we would see a false positive warning. See
rt_mutex_slowunlock().
In the case of futex_lock_pi(), both PI_FUTEX and BLOCK_ON_RT_MUTEX is
true. Therefore we don't check the waker.
However, in the case of futex_wait_requeue_pi(), PI_FUTEX is true but
BLOCK_ON_RT_MUTEX is false. In this case, we check the waker.
So, what happens if we don't have the tracepoint in *_proxy_lock()? The
futex_lock_pi() may generate a false positive warning, because we check the
waker and the waker may have lower priority.
But now that you mention it, perhaps instead of PI_FUTEX, we could define
FUTEX_LOCK_PI and FUTEX_WAIT_REQUEUE_PI separately. And we don't check the
waker if FUTEX_LOCK_PI=true. Something like the diff below.
Then we wouldn't need the block_on_rt_mutex tracepoints anymore. And the
specification is a bit more obvious.
Having a second pair of eyes is great, thanks!
Nam
diff --git a/tools/verification/models/rtapp/sleep.ltl b/tools/verification/models/rtapp/sleep.ltl
index 6e2f1ff31163..1f26e58e72f8 100644
--- a/tools/verification/models/rtapp/sleep.ltl
+++ b/tools/verification/models/rtapp/sleep.ltl
@@ -3,7 +3,7 @@ RULE = always ((RT and SLEEP) imply (RT_FRIENDLY_SLEEP or ALLOWLIST))
RT_FRIENDLY_SLEEP = (RT_VALID_SLEEP_REASON or KERNEL_THREAD)
and ((not WAKE) until RT_FRIENDLY_WAKE)
-RT_VALID_SLEEP_REASON = PI_FUTEX
+RT_VALID_SLEEP_REASON = FUTEX_WAIT_REQUEUE_PI
or RT_FRIENDLY_NANOSLEEP
RT_FRIENDLY_NANOSLEEP = CLOCK_NANOSLEEP
@@ -16,5 +16,6 @@ RT_FRIENDLY_WAKE = WOKEN_BY_EQUAL_OR_HIGHER_PRIO
or KTHREAD_SHOULD_STOP
ALLOWLIST = BLOCK_ON_RT_MUTEX
+ or FUTEX_LOCK_PI
or TASK_IS_RCU
or TASK_IS_MIGRATION
next prev parent reply other threads:[~2025-04-29 17:21 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-29 12:00 [PATCH v5 00/23] RV: Linear temporal logic monitors for RT application Nam Cao
2025-04-29 12:00 ` [PATCH v5 01/23] rv: Add #undef TRACE_INCLUDE_FILE Nam Cao
2025-04-29 12:00 ` [PATCH v5 02/23] printk: Make vprintk_deferred() public Nam Cao
2025-04-29 12:00 ` [PATCH v5 03/23] panic: Add vpanic() Nam Cao
2025-04-29 12:00 ` [PATCH v5 04/23] rv: Let the reactors take care of buffers Nam Cao
2025-04-29 12:00 ` [PATCH v5 05/23] verification/dot2k: Make a separate dot2k_templates/Kconfig_container Nam Cao
2025-04-29 12:00 ` [PATCH v5 06/23] verification/dot2k: Remove __buff_to_string() Nam Cao
2025-04-29 12:00 ` [PATCH v5 07/23] verification/dot2k: Replace is_container() hack with subparsers Nam Cao
2025-04-29 12:00 ` [PATCH v5 08/23] rv: rename CONFIG_DA_MON_EVENTS to CONFIG_RV_MON_EVENTS Nam Cao
2025-04-29 12:00 ` [PATCH v5 09/23] verification/dot2k: Prepare the frontend for LTL inclusion Nam Cao
2025-04-29 12:00 ` [PATCH v5 10/23] Documentation/rv: Prepare monitor synthesis document " Nam Cao
2025-04-29 12:00 ` [PATCH v5 11/23] verification/rvgen: Restructure the templates files Nam Cao
2025-04-29 12:00 ` [PATCH v5 12/23] verification/rvgen: Restructure the classes to prepare for LTL inclusion Nam Cao
2025-04-29 12:00 ` [PATCH v5 13/23] rv: Add support for LTL monitors Nam Cao
2025-04-29 12:00 ` [PATCH v5 14/23] rv: Add rtapp container monitor Nam Cao
2025-04-29 12:01 ` [PATCH v5 15/23] x86/tracing: Remove redundant trace_pagefault_key Nam Cao
2025-04-29 12:01 ` [PATCH v5 16/23] x86/tracing: Move page fault trace points to generic Nam Cao
2025-04-29 12:01 ` [PATCH v5 17/23] arm64: mm: Add page fault trace points Nam Cao
2025-04-29 12:01 ` [PATCH v5 18/23] riscv: " Nam Cao
2025-04-29 12:01 ` [PATCH v5 19/23] rv: Add rtapp_pagefault monitor Nam Cao
2025-04-29 12:01 ` [PATCH v5 20/23] locking/rtmutex: Add block_on_rt_mutex tracepoints Nam Cao
2025-04-29 12:01 ` [PATCH v5 21/23] rv: Add rtapp_sleep monitor Nam Cao
2025-04-29 16:01 ` Gabriele Monaco
2025-04-29 17:20 ` Nam Cao [this message]
2025-04-30 8:05 ` Gabriele Monaco
2025-04-30 8:38 ` Nam Cao
2025-04-29 12:01 ` [PATCH v5 22/23] rv: Add documentation for rtapp monitor Nam Cao
2025-04-29 12:01 ` [PATCH v5 23/23] rv: Allow to configure the number of per-task monitor Nam Cao
2025-08-10 21:12 ` [PATCH v5 00/23] RV: Linear temporal logic monitors for RT application patchwork-bot+linux-riscv
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=20250429172055.QICnVQ2s@linutronix.de \
--to=namcao@linutronix.de \
--cc=boqun.feng@gmail.com \
--cc=gmonaco@redhat.com \
--cc=john.ogness@linutronix.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=longman@redhat.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=will@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®