pgsql: Optimize pg_atomic_exchange_u32 and pg_atomic_exchange_u64. - Mailing list pgsql-committers

From Nathan Bossart
Subject pgsql: Optimize pg_atomic_exchange_u32 and pg_atomic_exchange_u64.
Date
Msg-id E1rFGsH-00AnIH-01@gemulon.postgresql.org
Whole thread Raw
List pgsql-committers
Optimize pg_atomic_exchange_u32 and pg_atomic_exchange_u64.

Presently, all platforms implement atomic exchanges by performing
an atomic compare-and-swap in a loop until it succeeds.  This can
be especially expensive when there is contention on the atomic
variable.  This commit optimizes atomic exchanges on many platforms
by using compiler intrinsics, which should compile into something
much less expensive than a compare-and-swap loop.  Since these
intrinsics have been available for some time, the inline assembly
implementations are omitted.

Suggested-by: Andres Freund
Reviewed-by: Andres Freund
Discussion: https://postgr.es/m/20231129212905.GA1258737%40nathanxps13

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/64b1fb5f03266f0ef4eef3ad2b7d97170bb05b78

Modified Files
--------------
src/include/port/atomics/generic-gcc.h    | 34 +++++++++++++++++++++++++++++++
src/include/port/atomics/generic-msvc.h   | 18 ++++++++++++++++
src/include/port/atomics/generic-sunpro.h | 14 +++++++++++++
3 files changed, 66 insertions(+)


pgsql-committers by date:

Previous
From: Nathan Bossart
Date:
Subject: pgsql: Micro-optimize datum_to_json_internal() some more.
Next
From: Tom Lane
Date:
Subject: pgsql: compute_bitmap_pages' loop_count parameter should be double not