Re: Fix performance of generic atomics
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Andres Freund <andres@anarazel.de>
Cc: Sokolov Yura <funny.falcon@postgrespro.ru>,
Robert Haas <robertmhaas@gmail.com>,
Simon Riggs <simon@2ndquadrant.com>,
Jeff Janes <jeff.janes@gmail.com>,
Jesper Pedersen <jesper.pedersen@redhat.com>,
pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2017-09-06T19:25:20Z
Lists: pgsql-hackers
Andres Freund <andres@anarazel.de> writes:
> On 2017-09-06 15:12:13 -0400, Tom Lane wrote:
>> It looks to me like two of the three implementations promise no such
>> thing.
> They're volatile vars, so why not?
Yeah, but so are the caller's variables. That is, in
pg_atomic_exchange_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 xchg_)
{
uint64 old;
old = ptr->value;
ISTM that the compiler is required to actually fetch ptr->value, not
rely on some previous read of it. I do not think that (the first
version of) pg_atomic_read_u64_impl is adding any guarantee that wasn't
there already.
>> Even if they somehow do, it hardly matters given that the cmpxchg loop
>> would be self-correcting.
> Well, in this one instance maybe, hardly in others.
All the functions involved use nigh-identical cmpxchg loops.
> What are you suggesting as an alternative?
I think we can just use "old = ptr->value" to set up for the cmpxchg
loop in every generic.h function that uses such a loop.
regards, tom lane
Commits
-
Further marginal hacking on generic atomic ops.
- bfea92563c51 11.0 landed
-
Use more of gcc's __sync_fetch_and_xxx builtin functions for atomic ops.
- e09db94c0a5f 11.0 landed
-
Remove duplicate reads from the inner loops in generic atomic ops.
- e530be96859e 11.0 landed