mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@aerifal.cx>
To: musl@lists.openwall.com
Subject: Re: Transition path for removing lazy init of thread pointer
Date: Mon, 24 Mar 2014 19:04:05 -0400	[thread overview]
Message-ID: <20140324230405.GA23163@brightrain.aerifal.cx> (raw)
In-Reply-To: <20140324174915.GA1263@brightrain.aerifal.cx>

On Mon, Mar 24, 2014 at 01:49:15PM -0400, Rich Felker wrote:
> Phase 1: Initialize the thread pointer at startup, but do not make
> anything in musl assume that the thread pointer is valid unless the
> [...]

Phase 1 is now complete. The intent is that it not break any usage
(even on ancient kernels that are unsupported) that was not already
broken before, so regression reports would be very appreciated if I'm
wrong about that.

At this point we now have two mandatory syscalls at startup on most
archs (just one where setting the thread pointer is entirely a
userspace operation). The second syscall is set_tid_address, and it
seems like it should only be needed it pthread_create is being used
(to that pthread_join will work), but it serves a second purpose of
standing in for gettid() too. We could, however, eliminate it in some
cases:x

- In static-linked programs that never need to know their own tid and
  never create threads, it can be skipped. This could be achieved with
  some weak symbol magic.

- Even in dynamic-linked programs, we could defer the tid lookup until
  it's needed by adding a __gettid() function/macro that looks in the
  thread structure, and if it finds zero, calls set_tid_address. This
  might add a few cycles to some synchronization primitives, but we're
  shaving a good number of cycles now anyway since lazy thread-pointer
  initialization is gone and we can inline the thread-pointer access
  in a lot more places.

I'd welcome feedback on whether these sorts of optimizations (well,
more like tradeoffs than outright optimizations) are desirable.

Rich


  reply	other threads:[~2014-03-24 23:04 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-24 17:49 Rich Felker
2014-03-24 23:04 ` Rich Felker [this message]
2014-03-24 23:44   ` Justin Cormack
2014-03-25  0:01     ` Laurent Bercot
2014-03-25  1:55       ` Rich Felker
2014-03-25  6:35         ` Laurent Bercot
2014-03-25  7:11           ` Rich Felker
2014-03-25  0:58     ` 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=20140324230405.GA23163@brightrain.aerifal.cx \
    --to=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).