From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: peterz@infradead.org, tglx@kernel.org, mingo@redhat.com,
linux-kernel@vger.kernel.org, will@kernel.org, boqun@kernel.org,
longman@redhat.com, rostedt@goodmis.org, clrkwllms@kernel.org,
dvhart@infradead.org, dave@stgolabs.net, andrealmeid@igalia.com,
shuah@kernel.org, juri.lelli@redhat.com,
linux-rt-devel@lists.linux.dev, linux-kselftest@vger.kernel.org
Subject: Re: [PATCH v2 4/5] selftests/futex: Test priority inheritance on PI futexes
Date: Mon, 16 Nov 2026 17:56:09 +0100 [thread overview]
Message-ID: <20261116165609.RMK-DX1Z@linutronix.de> (raw)
In-Reply-To: <20261108141347.1525532-5-mathieu.desnoyers@efficios.com>
On 2026-11-08 09:13:46 [-0500], Mathieu Desnoyers wrote:
> The PI futex selftests check what FUTEX_LOCK_PI returns. In these tests,
> the owner always sleeps. No test checks the priority an owner runs at.
> No test waits behind an owner that keeps running.
…
> Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
I did play with this and looks it catches the errors you reported/ fixed
earlier in this series.
Reviewed-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
> --- /dev/null
> +++ b/tools/testing/selftests/futex/functional/futex_lock_pi_inherit.c
> @@ -0,0 +1,773 @@
…
> +static pid_t sys_gettid(void)
> +{
> + return syscall(SYS_gettid);
> +}
glibc-2.42+ has pthread_gettid_np(pthread_self()) but this is fine.
Debian Trixie has just 2.41 which is a bit sad.
> +static uint64_t now_ns(void)
> +{
> + struct timespec ts;
> +
> + clock_gettime(CLOCK_MONOTONIC, &ts);
> + return ts.tv_sec * NSEC_PER_SEC + ts.tv_nsec;
> +}
> +
> +/* An absolute CLOCK_REALTIME timeout @ns from now, for FUTEX_LOCK_PI. */
> +static struct timespec abs_timeout(uint64_t ns)
> +{
> + struct timespec ts;
> +
> + clock_gettime(CLOCK_REALTIME, &ts);
> + ts.tv_sec += ns / NSEC_PER_SEC;
> + ts.tv_nsec += ns % NSEC_PER_SEC;
> + if (ts.tv_nsec >= (long)NSEC_PER_SEC) {
> + ts.tv_nsec -= NSEC_PER_SEC;
> + ts.tv_sec++;
> + }
This breaks if your timeout is something like 1.5s and ts.nsec is
already > 0.5s. We usually do
| while (ts->tv_nsec >= NSEC_PER_SEC) {
| ts->tv_nsec -= NSEC_PER_SEC;
| ts->tv_sec++;
| }
and in worst case gcc does a div. But other than that…
> + return ts;
> +}
…
> +/*
> + * Start @t and wait until it sleeps where it blocks. Return false if it
> + * could not be created, if it failed, or if it did not block within 2s.
> + * Unless it could not be created, the caller must still join it.
> + */
Could rename it to start_pi_thread() or pi_start_thread() rather than
just start?
> +static bool start(struct pi_thread *t)
> +{
> + uint64_t end = now_ns() + 2 * NSEC_PER_SEC;
> + pthread_attr_t attr;
> + char state = 0;
> + int err;
> +
> + pthread_attr_init(&attr);
> + pthread_attr_setstacksize(&attr, 64 * 1024);
it makes me wonder what you did use as a template for this or who wrote
this. I can't imagine why one would set a stack size 64KiB here. It
shouldn't matter.
> + err = pthread_create(&t->thread, &attr, pi_thread_fn, t);
> + pthread_attr_destroy(&attr);
> + if (err) {
> + t->thread = pthread_self();
> + t->err = err;
> + atomic_store(&t->done, 1);
> + ksft_print_msg("pthread_create: %s\n", strerror(err));
> + return false;
> + }
…
Sebastian
next prev parent reply other threads:[~2026-11-16 16:56 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-08 14:13 [PATCH v2 0/5] locking/rtmutex: priority inheritance fixes and tests Mathieu Desnoyers
2026-11-08 14:13 ` [PATCH v2 1/5] locking/rtmutex: Stop spinning on the owner when the waiter is woken Mathieu Desnoyers
2026-11-16 12:06 ` Sebastian Andrzej Siewior
2026-11-16 18:36 ` Mathieu Desnoyers
2026-11-08 14:13 ` [PATCH v2 2/5] locking/rtmutex: Initialize the ww_mutex context of a waiter Mathieu Desnoyers
2026-11-16 13:58 ` Sebastian Andrzej Siewior
2026-11-16 18:37 ` Mathieu Desnoyers
2026-11-08 14:13 ` [PATCH v2 3/5] locking/rtmutex: Clone the sort keys in rt_mutex_enqueue_pi() Mathieu Desnoyers
2026-11-16 15:11 ` Sebastian Andrzej Siewior
2026-11-16 18:35 ` Mathieu Desnoyers
2026-11-08 14:13 ` [PATCH v2 4/5] selftests/futex: Test priority inheritance on PI futexes Mathieu Desnoyers
2026-11-16 16:56 ` Sebastian Andrzej Siewior [this message]
2026-11-16 18:48 ` Mathieu Desnoyers
2026-11-08 14:13 ` [PATCH v2 5/5] locking/ww_mutex/test: Time an ABBA with both owners running Mathieu Desnoyers
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=20261116165609.RMK-DX1Z@linutronix.de \
--to=bigeasy@linutronix.de \
--cc=andrealmeid@igalia.com \
--cc=boqun@kernel.org \
--cc=clrkwllms@kernel.org \
--cc=dave@stgolabs.net \
--cc=dvhart@infradead.org \
--cc=juri.lelli@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-rt-devel@lists.linux.dev \
--cc=longman@redhat.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=shuah@kernel.org \
--cc=tglx@kernel.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®