public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fw@deneb.enyo.de>
To: Torvald Riegel <triegel@redhat.com>
Cc: Stefan Liebler <stli@linux.vnet.ibm.com>,  libc-alpha@sourceware.org
Subject: Re: [PATCH 1/2] Optimize generic spinlock code and use C11 like atomic macros.
Date: Sun, 26 Feb 2017 07:55:00 -0000	[thread overview]
Message-ID: <87r32ltmh3.fsf@mid.deneb.enyo.de> (raw)
In-Reply-To: <1487596296.20203.119.camel@redhat.com> (Torvald Riegel's message of "Mon, 20 Feb 2017 14:11:36 +0100")

* Torvald Riegel:

> On Sun, 2017-02-19 at 10:20 +0100, Florian Weimer wrote:
>> * Torvald Riegel:
>> 
>> >> On 12/16/2016 09:12 PM, Florian Weimer wrote:
>> >> > That's undefined:
>> >> >
>> >> > “If an attempt is made to refer to an object defined with a
>> >> > volatile-qualified type through use of an lvalue with
>> >> > non-volatile-qualified type, the behavior is undefined.”
>> >> >
>> >> > But we cannot drop the volatile qualifier from the definition of
>> >> > pthread_spinlock_t because it would change the C++ mangling of
>> >> > pthread_spinlock_t * and similar types.
>> >
>> > Generally, I wouldn't agree with Florian's comment.  However, all we are
>> > interested in is the storage behind the volatile-qualified type.  Users
>> > aren't allowed the object through other means than the pthread_spin*
>> > functions, so if we cast everywhere, we'll never have any
>> > volatile-qualified accesses.
>> 
>> The spinlock is defined with the volatile qualifier.  This means that
>> accesses without the qualifier are undefined.
>
> The footnote for 6.7.3p6 (footnote 133, N1570) reads:
> This applies to those objects that behave as if they were defined with
> qualified types, even if they are
> never actually defined as objects in the program (such as an object at a
> memory-mapped input/output
> address).
>
> I don't remember whether footnotes are normative,

They are not.

> but this doesn't apply in our case.

I think it's a clarification intended to *extend* the scope of the
paragraph to objects not defined using C language elments.  It's not
intended to restrict this paragraph to such objects only.  The
footnote is not particularly meaningful anyway because it discusses
certain vendor extensions whose behavior is not described by the
standard.

(And on GNU, objects created by mmap or dlopen are not implicitly
volatile.)

>> > I believe none of the architectures we
>> > support makes weaker requirements on alignment for volatile-qualified
>> > than for non-volatile-qualified types, so I can't see any problem in
>> > practice with the cast.
>> 
>> We also need separate compilation or some other optimization barrier.
>
> Also consider 2.14.2 in
> https://www.cl.cam.ac.uk/~pes20/cerberus/notes30-full.pdf

Not sure how this applies here.  There's no volatile qualifier in
there.

> This states that one can cast between a union and the pointers to
> individual parts of a union.  If the spinlock's underlying type and the
> volatile-qualified type both have the same size+alignment, then the
> union will have the same size and alignment too.
> In our virtual union, we only ever use the non-volatile member (users
> are not allowed to acccess spinlocks other than through pthread_spin_*
> functions, which don't use volatile-qualified accesses).  But we pass
> the pointer to the volatile member around as handle to the spinlock.

We also need to cover the case when a spinlock is defined like this:

static pthread_spinlock_t lock;

And I don't see a way to get rid of the volatile there without a
compiler extension.

We cannot introduce an union here because …

> Maybe its best to just change pthread_spinlock_t from volatile int to
> int.

… like this, it would change the C++ name mangling of anything related
to pthread_spinlock_t.  It is defined as a typedef, so the mangling
uses the definition to refer to the type, not the name, according to
the language rules, where typedef does not create a new type, and
typedefs with the same definition can be used interchangeably.

  reply	other threads:[~2017-02-26  7:55 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-16 16:32 Stefan Liebler
2016-12-16 16:32 ` [PATCH 2/2] S390: Use generic spinlock code Stefan Liebler
2017-02-08 14:49   ` Stefan Liebler
2017-02-13 20:39     ` Torvald Riegel
2017-02-15 16:26       ` Stefan Liebler
2017-02-18 17:05         ` Torvald Riegel
2017-03-14 15:55           ` Stefan Liebler
2017-03-21 15:43             ` Stefan Liebler
2017-04-06 12:27             ` Torvald Riegel
2016-12-19 12:14 ` [PATCH 1/2] Optimize generic spinlock code and use C11 like atomic macros Szabolcs Nagy
2017-02-08 14:49   ` Stefan Liebler
2017-02-13 20:29     ` Torvald Riegel
2017-02-15  9:36       ` Stefan Liebler
2017-02-18 16:57         ` Torvald Riegel
2017-02-19  9:20           ` Florian Weimer
2017-02-20 13:11             ` Torvald Riegel
2017-02-26  7:55               ` Florian Weimer [this message]
2017-02-26 20:06                 ` Torvald Riegel
2017-02-26 20:29                   ` Florian Weimer
2017-02-26 20:35                     ` Torvald Riegel
2017-02-27 17:57                       ` Szabolcs Nagy
2017-02-28  7:15                         ` Torvald Riegel
2017-03-14 15:55                           ` Stefan Liebler
2017-02-20 12:15           ` Stefan Liebler
2017-02-20 13:51             ` Torvald Riegel
2017-03-14 15:55               ` Stefan Liebler
2017-03-21 15:43                 ` Stefan Liebler
2017-03-22 12:56                   ` Szabolcs Nagy
2017-03-23 16:16                     ` Stefan Liebler
2017-03-23 17:52                       ` Szabolcs Nagy
2017-04-06 12:04                     ` Torvald Riegel
2017-03-27 13:08                   ` Stefan Liebler
2017-04-04 10:29                     ` [PING] " Stefan Liebler
2017-03-29 14:16                 ` Stefan Liebler
2017-04-06 14:00                 ` Torvald Riegel
2017-04-07 16:23                   ` Stefan Liebler
2017-04-09 13:51                     ` Torvald Riegel
2017-04-10 12:00                       ` Stefan Liebler
2017-04-18 13:09                         ` Stefan Liebler
2017-04-25  6:47                           ` Stefan Liebler
2017-05-03 11:38                             ` [PATCH 1/2] [PING] " Stefan Liebler
2017-05-10 13:00                               ` Stefan Liebler
2017-05-17 13:09                                 ` Stefan Liebler
2017-05-24  6:37                                   ` Stefan Liebler
2017-05-30  7:18                                 ` Torvald Riegel
2017-05-31  8:29                                   ` Stefan Liebler
2017-05-31 16:48                                     ` Torvald Riegel
2017-06-01 13:40                                       ` Joseph Myers
2017-06-01 14:33                                         ` Torvald Riegel
2017-06-06  7:51                                       ` [PATCH 1/2] [COMMITTED] " Stefan Liebler
2017-04-10  8:17                     ` [PATCH 1/2] " Andreas Schwab
2017-04-10 12:00                       ` Stefan Liebler
2017-04-10 13:36                         ` Andreas Schwab
2017-04-11  7:06                           ` Stefan Liebler
2017-04-11  8:45                             ` Andreas Schwab
2017-04-11 10:15                               ` Stefan Liebler
2017-04-11 12:05                                 ` Andreas Schwab
2017-04-11 12:19                                   ` Stefan Liebler
2017-04-11 13:08                                   ` Zack Weinberg
2017-04-13 16:36                             ` Torvald Riegel
2017-05-30 21:00                     ` Tulio Magno Quites Machado Filho
2017-04-18 21:17                   ` Joseph Myers
2017-04-19  8:27                     ` Stefan Liebler

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=87r32ltmh3.fsf@mid.deneb.enyo.de \
    --to=fw@deneb.enyo.de \
    --cc=libc-alpha@sourceware.org \
    --cc=stli@linux.vnet.ibm.com \
    --cc=triegel@redhat.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).