Обсуждение: pgsql: Add a basic atomic ops API abstracting away platform/architectur
Add a basic atomic ops API abstracting away platform/architecture details. Several upcoming performance/scalability improvements require atomic operations. This new API avoids the need to splatter compiler and architecture dependent code over all the locations employing atomic ops. For several of the potential usages it'd be problematic to maintain both, a atomics using implementation and one using spinlocks or similar. In all likelihood one of the implementations would not get tested regularly under concurrency. To avoid that scenario the new API provides a automatic fallback of atomic operations to spinlocks. All properties of atomic operations are maintained. This fallback - obviously - isn't as fast as just using atomic ops, but it's not bad either. For one of the future users the atomics ontop spinlocks implementation was actually slightly faster than the old purely spinlock using implementation. That's important because it reduces the fear of regressing older platforms when improving the scalability for new ones. The API, loosely modeled after the C11 atomics support, currently provides 'atomic flags' and 32 bit unsigned integers. If the platform efficiently supports atomic 64 bit unsigned integers those are also provided. To implement atomics support for a platform/architecture/compiler for a type of atomics 32bit compare and exchange needs to be implemented. If available and more efficient native support for flags, 32 bit atomic addition, and corresponding 64 bit operations may also be provided. Additional useful atomic operations are implemented generically ontop of these. The implementation for various versions of gcc, msvc and sun studio have been tested. Additional existing stub implementations for * Intel icc * HUPX acc * IBM xlc are included but have never been tested. These will likely require fixes based on buildfarm and user feedback. As atomic operations also require barriers for some operations the existing barrier support has been moved into the atomics code. Author: Andres Freund with contributions from Oskari Saarenmaa Reviewed-By: Amit Kapila, Robert Haas, Heikki Linnakangas and Álvaro Herrera Discussion: CA+TgmoYBW+ux5-8Ja=Mcyuy8=VXAnVRHp3Kess6Pn3DMXAPAEA@mail.gmail.com, 20131015123303.GH5300@awork2.anarazel.de, 20131028205522.GI20248@awork2.anarazel.de Branch ------ master Details ------- http://git.postgresql.org/pg/commitdiff/b64d92f1a5602c55ee8b27a7ac474f03b7aee340 Modified Files -------------- config/c-compiler.m4 | 98 ++++ configure | 274 +++++++++-- configure.in | 34 +- src/backend/main/main.c | 1 + src/backend/port/Makefile | 2 +- src/backend/port/atomics.c | 127 ++++++ src/backend/storage/lmgr/spin.c | 7 +- src/include/c.h | 21 +- src/include/pg_config.h.in | 24 +- src/include/pg_config.h.win32 | 3 + src/include/pg_config_manual.h | 8 + src/include/port/atomics.h | 531 ++++++++++++++++++++++ src/include/port/atomics/arch-arm.h | 25 + src/include/port/atomics/arch-hppa.h | 17 + src/include/port/atomics/arch-ia64.h | 26 ++ src/include/port/atomics/arch-ppc.h | 26 ++ src/include/port/atomics/arch-x86.h | 241 ++++++++++ src/include/port/atomics/fallback.h | 132 ++++++ src/include/port/atomics/generic-acc.h | 99 ++++ src/include/port/atomics/generic-gcc.h | 236 ++++++++++ src/include/port/atomics/generic-msvc.h | 103 +++++ src/include/port/atomics/generic-sunpro.h | 74 +++ src/include/port/atomics/generic-xlc.h | 103 +++++ src/include/port/atomics/generic.h | 387 ++++++++++++++++ src/include/storage/barrier.h | 155 +------ src/include/storage/s_lock.h | 9 +- src/test/regress/expected/lock.out | 8 + src/test/regress/input/create_function_1.source | 5 + src/test/regress/output/create_function_1.source | 4 + src/test/regress/regress.c | 239 ++++++++++ src/test/regress/sql/lock.sql | 5 + 31 files changed, 2816 insertions(+), 208 deletions(-)
Re: pgsql: Add a basic atomic ops API abstracting away platform/architectur
От
Michael Paquier
Дата:
On Fri, Sep 26, 2014 at 8:59 AM, Andres Freund <andres@anarazel.de> wrote: > Add a basic atomic ops API abstracting away platform/architecture details. locust is not happy with this patch: http://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=locust&dt=2014-09-26%2000%3A00%3A48 Regards, -- Michael
On 2014-09-26 09:12:43 +0900, Michael Paquier wrote: > On Fri, Sep 26, 2014 at 8:59 AM, Andres Freund <andres@anarazel.de> wrote: > > Add a basic atomic ops API abstracting away platform/architecture details. > > locust is not happy with this patch: > http://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=locust&dt=2014-09-26%2000%3A00%3A48 On it. I'm pretty sure it won't feel lonely being red coloured... There'll be, as mentioned in the commit message, more breakage. This is highly compiler specific stuff and there's only so much that can be tested without access to the buildfarm... Greetings, Andres Freund -- Andres Freund http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Training & Services
Re: pgsql: Add a basic atomic ops API abstracting away platform/architectur
От
Michael Paquier
Дата:
On Fri, Sep 26, 2014 at 9:16 AM, Andres Freund <andres@anarazel.de> wrote: > On 2014-09-26 09:12:43 +0900, Michael Paquier wrote: >> On Fri, Sep 26, 2014 at 8:59 AM, Andres Freund <andres@anarazel.de> wrote: >> > Add a basic atomic ops API abstracting away platform/architecture details. >> >> locust is not happy with this patch: >> http://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=locust&dt=2014-09-26%2000%3A00%3A48 > > On it. I'm pretty sure it won't feel lonely being red > coloured... There'll be, as mentioned in the commit message, more > breakage. This is highly compiler specific stuff and there's only so > much that can be tested without access to the buildfarm... That's for sure. Note that lapwing as well showed up in red: http://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=lapwing&dt=2014-09-26%2000%3A15%3A02 -- Michael