From: Florian Weimer <fweimer@redhat.com>
To: Peng Zheng <pengzheng@apache.org>
Cc: libc-alpha@sourceware.org
Subject: Re: Priority Inversion and Unlimited Spin of pthread_rwlock_t
Date: Tue, 12 Mar 2024 15:39:11 +0100 [thread overview]
Message-ID: <87jzm7tsz4.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <0e210b7b-5349-41fe-a476-87958990e03e@apache.org> (Peng Zheng's message of "Tue, 12 Mar 2024 11:19:53 +0800")
* Peng Zheng:
> And the SCHED_OTHER writer was just about to enable the `__wrphase_futex` in
> `__pthread_rwlock_wrlock_full` (just one ARM instruction away)
> but never able to do that (the two readers ate nearly all available CPUs):
>
> while ((r & PTHREAD_RWLOCK_WRPHASE) == 0
> && (r >> PTHREAD_RWLOCK_READER_SHIFT) == 0)
> {
> if (atomic_compare_exchange_weak_acquire (&rwlock->__data.__readers,
> &r, r | PTHREAD_RWLOCK_WRPHASE))
> {
> atomic_store_relaxed (&rwlock->__data.__wrphase_futex, 1); /* writer was stuck HERE! */
>
> goto done;
> }
> /* TODO Back-off. */
> }
Is this about filling in the TODO?
> Unlimited user space spin is too dangerous to be used, how about
> limiting the total number of spins before suspending using futex? Or
> using rseq as mentioned in the LWN artible?
> [0] https://lwn.net/Articles/944895/
The LWN article does not talk about priority inversion. With rseq,
userspace can detect preemption, but that may never happen with certain
realtime scheduling priorities.
Thanks,
Florian
next prev parent reply other threads:[~2024-03-12 14:39 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-12 3:19 Peng Zheng
2024-03-12 3:48 ` Peng Zheng
2024-03-14 7:32 ` Peng Zheng
2024-03-12 14:39 ` Florian Weimer [this message]
2024-03-13 1:48 ` Peng Zheng
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=87jzm7tsz4.fsf@oldenburg.str.redhat.com \
--to=fweimer@redhat.com \
--cc=libc-alpha@sourceware.org \
--cc=pengzheng@apache.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).