public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: libc-alpha <libc-alpha@sourceware.org>
Subject: Re: [PATCH 1/5] nptl: Add <thread_pointer.h> for defining __thread_pointer
Date: Mon, 06 Dec 2021 18:01:44 +0100	[thread overview]
Message-ID: <87ee6poefb.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <1530989524.15107.1638809092304.JavaMail.zimbra@efficios.com> (Mathieu Desnoyers's message of "Mon, 6 Dec 2021 11:44:52 -0500 (EST)")

* Mathieu Desnoyers:

> Why do we find a mix of macros and static inline across architectures ?

It's following the existing snippets in <tls.h> for those architectures
which cannot use __builtin_thread_pointer.

> Defining macros end up clobbering the preprocessor namespace (output
> of "gcc -dM -E"), which is one reason why static inlines are sometimes
> preferred. Or do we intend users to use this for feature detection ?
> e.g. #ifdef __thread_pointer ?

It's currently not an installed header, so this isn't a concern.

>
> OTOH, static inline functions will not be inlined when compiling with "-fno-inline"
> (default at -O0). An attribute "always_inline" is needed for this.
>
>
>> +++ b/sysdeps/m68k/nptl/thread_pointer.h
> [...]
>> +extern void * __m68k_read_tp (void);
>> +#define __thread_pointer() __m68k_read_tp ()
> [...]
>
>> +++ b/sysdeps/microblaze/nptl/thread_pointer.h
> [...]
>> +#define __thread_pointer() ({ register void *__reg asm ("r21"); __reg; })
>
> Not that applications are supposed to use variable names with a leading
> "__" prefix (AFAIU this is reserved to libc), but one downside of these
> statement expressions is that they would shadow any "__reg" variables.

It doesn't matter in this context because there are no macro arguments.
The only thing that would break this would be a __reg macro.

>> +++ b/sysdeps/x86/nptl/thread_pointer.h
> [...]
>> +#if __GNUC_PREREQ (11, 1)
>
> I suspect this requires a #include "features.h" ?

It's an internal header.  We'd also need include guards if we made this
into an installed header.

>> +# define __thread_pointer() __builtin_thread_pointer ()
>> +#else
>> +static inline void *
>> +__thread_pointer (void)
>> +{
>> +  void *__result;
>> +# ifdef __x86_64__
>> +  __asm__ volatile ("mov %%fs:0, %0" : "=r" (__result));
>
> Just out of curiosity, is x32 supported by glibc, and is this the
> expected behavior ?

x32 is supported and uses %fs.

>> +# else
>> +  __asm__ volatile ("mov %%gs:0, %0" : "=r" (__result));
>
> Do we really want a "volatile" asm here ? E.g. see:

With sufficiently separate compilation, we do not need it.  It's
currently not needed.

THREAD_SELF should not use it because it is often used in ways that
isn't needed after all, e.g. if THREAD_SELF is passed to THREAD_GETMEM
on an architecture that does not need a materialized thread pointer to
change TCB fields.

> Is this expected to be a complete list of all architectures ? I
> notably identify that arm, aarch64, and s390 are missing. Or is it
> that all the other architectures map to
> "sysdeps/nptl/thread_pointers.h" ? Maybe it would be good to document
> this in the commit message.

Yes, those can use __builtin_thread_pointer.  The patch as is builds on
all targets with GCC 11.

Thanks,
Florian


  reply	other threads:[~2021-12-06 17:01 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-06 13:45 [PATCH 0/5] Extensible rseq support for glibc Florian Weimer
2021-12-06 13:46 ` [PATCH 1/5] nptl: Add <thread_pointer.h> for defining __thread_pointer Florian Weimer
2021-12-06 16:44   ` Mathieu Desnoyers
2021-12-06 17:01     ` Florian Weimer [this message]
2021-12-06 19:55       ` Florian Weimer
2021-12-06 13:46 ` [PATCH 2/5] nptl: Add rseq registration Florian Weimer
2021-12-06 16:53   ` Mathieu Desnoyers
2021-12-06 17:10     ` Florian Weimer
2021-12-06 16:59   ` Mathieu Desnoyers
2021-12-06 17:14     ` Florian Weimer
2021-12-06 18:52       ` Mathieu Desnoyers
2021-12-06 19:03         ` Florian Weimer
2021-12-06 20:11           ` Paul E. McKenney
2021-12-06 20:26             ` Florian Weimer
2021-12-06 21:08               ` Paul E. McKenney
2021-12-06 13:46 ` [PATCH 3/5] Linux: Use rseq to accelerate sched_getcpu Florian Weimer
2021-12-06 16:50   ` Szabolcs Nagy
2021-12-06 17:06     ` Florian Weimer
2021-12-06 17:45       ` Szabolcs Nagy
2021-12-07 15:48         ` Florian Weimer
2021-12-06 13:46 ` [PATCH 4/5] nptl: Add glibc.pthread.rseq tunable to control rseq registration Florian Weimer
2021-12-06 13:53 ` [PATCH 5/5] nptl: Add public rseq symbols and <sys/rseq.h> Florian Weimer
2021-12-07 11:01   ` Szabolcs Nagy
2021-12-07 11:28     ` Florian Weimer
2021-12-06 16:13 ` [PATCH 0/5] Extensible rseq support for glibc 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=87ee6poefb.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=mathieu.desnoyers@efficios.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.
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).