From: Kurt Kanzenbach <kurt@linutronix.de>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>,
libc-alpha@sourceware.org
Cc: Florian Weimer <fweimer@redhat.com>,
Carlos O'Donell <carlos@redhat.com>,
Thomas Gleixner <tglx@linutronix.de>,
Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Subject: Re: [PATCH RFC 0/3] nptl: Introduce and use FUTEX_LOCK_PI2
Date: Tue, 22 Jun 2021 09:26:41 +0200 [thread overview]
Message-ID: <87h7hql5qm.fsf@kurt> (raw)
In-Reply-To: <bf4e7c28-11ce-fa4f-65b4-b00196440792@linaro.org>
[-- Attachment #1: Type: text/plain, Size: 4610 bytes --]
On Mon Jun 21 2021, Adhemerval Zanella wrote:
> Currently we check for PI mutex support on pthread_mutex_init which basically
> check for futex_cmpxchg_enabled within kernel (so it fails only on a handful
> configurations).
>
> For FUTEX_LOCK_PI2 I think we will need to rework it, since we are moving
> the futex PI failure from pthread_mutex_init to pthread_mutex_{timed}lock.
> It means that we will need to remove the prio_inherit_missing() test on
> pthread_mutex_init and make the pthread_mutex_{timed}lock fail instead
> (not sure if we should use ENOTSUP or keep with current EINVAL).
>
> The proposed futex_lockpi2_supported() incurs in an extra syscall on every
> mutex slow path, we should avoid it.
Yes, sure.
> I would like also to avoid the CRIU issue as well, so I think it would
> be better to avoid any caching (as done by prio_inherit_missing()),
> and optimize the FUTEX_LOCK_PI2 to be used only when the timeout for
> clock different than CLOCK_REALTIME is required.
OK.
>
> So instead it would be better to move the logic solely on futex_lock_pi()
> (I am assuming FUTEX_LOCK_PI2 would be only added for futex_time64):
The kernel also adds FUTEX_LOCK_PI2 for the old system call interface.
>
> static __always_inline int
> futex_lock_pi2_64 (int *futex_word, const struct __timespec64 *abtime,
> int private)
> {
> # if __ASSUME_FUTEX_LOCK_PI2
> return INTERNAL_SYSCALL_CALL (futex_time64, futex_word,
> __lll_private_flag (FUTEX_LOCK_PI2, private), 0,
> abstime);
> # else
> if (abstime != NULL && clockid != CLOCK_REALTIME)
> return INTERNAL_SYSCALL_CALL (futex_time64, futex_word,
> __lll_private_flag (FUTEX_LOCK_PI2, private), 0,
> abstime);
At this point __ASSUME_FUTEX_LOCK_PI2 is false meaning the kernel does
not have FUTEX_LOCK_PI2 support. But, it calls FUTEX_LOCK_PI2 for
clockid monotonic. This will result in ENOSYS unless it's an old kernel
which is patched. Is that intended?
> else
> {
> int err = INTERNAL_SYSCALL_CALL (futex_time64, futex_word,
> __lll_private_flag (FUTEX_LOCK_PI, private), 0,
> abstime);
> if (err == -ENOSYS)
> err = -EOVERFLOW;
> }
> # endif /* __ASSUME_FUTEX_LOCK_PI2 */
> }
>
> static __always_inline int
> futex_lock_pi64 (int *futex_word, const struct __timespec64 *abstime,
> int private)
> {
> int err;
> #ifdef __ASSUME_TIME64_SYSCALLS
> err = futex_lock_pi2_64 (futex_word, abstime, private);
Makes sense.
> #else /* __ASSUME_TIME64_SYSCALLS */
> bool need_time64 = abstime != NULL && !in_time_t_range (abstime->tv_sec)
> if (need_time64)
> {
> err = futex_lock_pi2_64 (futex_word, abstime, private);
> }
> else
> {
> struct timespec ts32;
> if (abstime != NULL)
> ts32 = valid_timespec64_to_timespec (*abstime);
>
> err = INTERNAL_SYSCALL_CALL (futex, futex_word, __lll_private_flag
> (FUTEX_LOCK_PI, private), 0,
> abstime != NULL ? &ts32 : NULL);
> }
> #endif /* __ASSUME_TIME64_SYSCALLS */
> [...]
> }
>
> It would make the changes on pthread_mutex code minimal, it would be only to
> remove the extra check for clockid and adjust the comment.
Well, that's an interesting point. I think the current check has to
stay, because there are two locking paths. Only the slow path calls
futex_lock_pi_64() which may result in ENOSYS for clock monotonic. But,
the fast path which doesn't call futex_lock_pi64() would succeed if the
check is removed.
Maybe something like this:
sysdeps/nptl/futex-internal.h:
|static __always_inline bool
|futex_lockpi2_supported (void)
|{
| return __ASSUME_FUTEX_LOCK_PI2;
|}
nptl/pthread_mutex_timedlock.c:
| if (__glibc_unlikely (! futex_lockpi2_supported () &&
| clockid != CLOCK_REALTIME))
| return EINVAL;
Or did I get something wrong?
>
> Also, as Joseph has noted the __ASSUME_FUTEX_LOCK_PI2 should be the first
> patch.
OK.
> It also does not make sense to add the __ASSUME_FUTEX_LOCK_PI2 on
> tests, they need to be kernel agnostic so you will need to handle a
> possible EINVAL/ENOSUP failure instead.
Agreed.
Thanks for your feedback. I'll rework it accordingly.
Thanks,
Kurt
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 861 bytes --]
next prev parent reply other threads:[~2021-06-22 7:26 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-21 11:16 Kurt Kanzenbach
2021-06-21 11:16 ` [PATCH RFC 1/3] nptl: Introduce futex_lock_pi2() Kurt Kanzenbach
2021-06-21 11:16 ` [PATCH RFC 2/3] nptl: Use futex_lock_pi2() Kurt Kanzenbach
2021-06-21 11:16 ` [PATCH RFC 3/3] nptl: Include CLOCK_MONOTONIC in mutex tests Kurt Kanzenbach
2021-06-21 20:07 ` Joseph Myers
2021-06-22 8:58 ` Kurt Kanzenbach
2021-06-21 21:32 ` [PATCH RFC 0/3] nptl: Introduce and use FUTEX_LOCK_PI2 Adhemerval Zanella
2021-06-22 7:26 ` Kurt Kanzenbach [this message]
2021-06-22 7:29 ` Florian Weimer
2021-06-22 8:55 ` Kurt Kanzenbach
2021-06-22 12:30 ` Adhemerval Zanella
2021-06-22 14:25 ` Kurt Kanzenbach
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=87h7hql5qm.fsf@kurt \
--to=kurt@linutronix.de \
--cc=adhemerval.zanella@linaro.org \
--cc=bigeasy@linutronix.de \
--cc=carlos@redhat.com \
--cc=fweimer@redhat.com \
--cc=libc-alpha@sourceware.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).