pgsql: Add a basic atomic ops API abstracting away platform/architectur

Поиск
Список
Период
Сортировка
От Andres Freund
Тема pgsql: Add a basic atomic ops API abstracting away platform/architectur
Дата
Msg-id E1XXIwS-0000Yb-KR@gemulon.postgresql.org
обсуждение исходный текст
Ответы Re: pgsql: Add a basic atomic ops API abstracting away platform/architectur  (Michael Paquier <michael.paquier@gmail.com>)
Список pgsql-committers
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(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Andrew Dunstan
Дата:
Сообщение: pgsql: Remove ill-conceived ban on zero length json object keys.
Следующее
От: Michael Paquier
Дата:
Сообщение: Re: pgsql: Add a basic atomic ops API abstracting away platform/architectur