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:34:09Z
Lists: pgsql-hackers
Andres Freund <andres@anarazel.de> writes: > On 2017-09-06 15:25:20 -0400, Tom Lane wrote: >> 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. > I think we might have been talking past each other - I thought you were > talking about changing the pg_atomic_read_u64_impl implementation for > external users. Ah. I was not thinking of touching pg_atomic_read_u32/u64_impl, although now that you mention it, it's not clear to me why we couldn't simplify - return *(&ptr->value); + return ptr->value; AFAIK, the compiler is entitled to, and does, simplify away that take-a-pointer-and-immediately-dereference-it dance. If it did not, a whole lot of standard array locutions would be much less efficient than they should be. What matters here is the volatile qualifier, which we've already got. 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