mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Alexey Izbyshev <izbyshev@ispras.ru>
To: Rich Felker <dalias@aerifal.cx>
Cc: musl@lists.openwall.com
Subject: Re: Draft outline of thread-list design
Date: Fri, 15 Feb 2019 01:54:09 +0300	[thread overview]
Message-ID: <b9456609db80d5eff8d3890db942baea@ispras.ru> (raw)
In-Reply-To: <20190214223224.GV23599@brightrain.aerifal.cx>

On 2019-02-15 01:32, Rich Felker wrote:
> On Fri, Feb 15, 2019 at 12:16:39AM +0300, Alexey Izbyshev wrote:
>> On 2019-02-12 21:26, Rich Felker wrote:
>> >pthread_join:
>> >
>> >A joiner can no longer see the exit of the individual kernel thread
>> >via the exit futex (detach_state), so after seeing it in an exiting
>> >state, it must instead use the thread list to confirm completion of
>> >exit. The obvious way to do this is by taking a lock on the list and
>> >immediately releasing it, but the actual taking of the lock can be
>> >elided by simply doing a futex wait on the lock owner being equal to
>> >the tid (or an exit sequence number if we prefer that) of the exiting
>> >thread. In the case of tid reuse collisions, at worse this reverts to
>> >the cost of waiting for the lock to be released.
>> >
>> Since the kernel wakes only a single thread waiting on ctid address,
>> wouldn't the joiner still need to do a futex wake to unblock other
>> potential waiters even if it doesn't actually take the lock by
>> changing *ctid?
> 
> I'm not sure. If it's just a single wake rather than a broadcast then
> yes, but only if it waited. If it observed the lock word != to the
> exiting thread tid without performing a futex wait then it doesn't
> have to do a futex wake.
> 
Yes, it's a single wake: 
<http://man7.org/linux/man-pages/man2/set_tid_address.2.html>, 
<https://elixir.bootlin.com/linux/v4.20.8/source/kernel/fork.c#L1292>.
> 
>> In general, to my limited expertise, the design looks simple and
>> clean. I'm not sure whether it's worth optimizing to reduce
>> serialization pressure on pthread_create()/pthread_exit() because
>> creating a large amount of short-lived threads doesn't look like a
>> good idea anyway.
> 
> Yes. One thing I did notice is that the window where pthread_create
> has to hold a lock to prevent new dlopen from happening is a lot
> larger than the window where the thread list needs to be locked, and
> contains mmap/mprotect. I think we should add a new "DTLS lock" here
> that's held for the whole time, with a protocol that if you need both
> the DTLS lock and the thread list lock, you take them in that order
> (dlopen would also need them both). This reduces the thread list lock
> window to just the __clone call and list update.
> 
Looks good.

Alexey



  reply	other threads:[~2019-02-14 22:54 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-12 18:26 Rich Felker
2019-02-12 20:23 ` Rich Felker
2019-02-14 21:16 ` Alexey Izbyshev
2019-02-14 22:32   ` Rich Felker
2019-02-14 22:54     ` Alexey Izbyshev [this message]
2019-02-14 23:19     ` Rich Felker
2019-02-15  0:20 ` Rich Felker

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=b9456609db80d5eff8d3890db942baea@ispras.ru \
    --to=izbyshev@ispras.ru \
    --cc=dalias@aerifal.cx \
    --cc=musl@lists.openwall.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).