summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2020-06-08 19:52:19 -0700
committerAndres Freund <andres@anarazel.de>2020-06-08 20:03:16 -0700
commite3c878ffdddce4a70ba9771e0493f3bb3f7b1b7d (patch)
tree5398b4aab907ba5a43e6f33c23f60cfbb52247df
parent644cac32a0bcfb1749e82c17f2d01d1b6aad8207 (diff)
Avoid need for valgrind suppressions for pg_atomic_init_u64 on some platforms.
Previously we used pg_atomic_write_64_impl inside pg_atomic_init_u64. That works correctly, but on platforms without 64bit single copy atomicity it could trigger spurious valgrind errors about uninitialized memory, because we use compare_and_swap for atomic writes on such platforms. I previously suppressed one instance of this problem (6c878edc1df), but as Tom reports that wasn't enough. As the atomic variable cannot yet be concurrently accessible during initialization, it seems better to have pg_atomic_init_64_impl set the value directly. Change pg_atomic_init_u32_impl for symmetry. Reported-By: Tom Lane Author: Andres Freund Discussion: https://postgr.es/m/1714601.1591503815@sss.pgh.pa.us Backpatch: 9.5-
-rw-r--r--src/include/port/atomics/generic.h4
-rw-r--r--src/tools/valgrind.supp14
2 files changed, 2 insertions, 16 deletions
diff --git a/src/include/port/atomics/generic.h b/src/include/port/atomics/generic.h
index 1acd19242b2..6a1a79315b9 100644
--- a/src/include/port/atomics/generic.h
+++ b/src/include/port/atomics/generic.h
@@ -160,7 +160,7 @@ pg_atomic_clear_flag_impl(volatile pg_atomic_flag *ptr)
static inline void
pg_atomic_init_u32_impl(volatile pg_atomic_uint32 *ptr, uint32 val_)
{
- pg_atomic_write_u32_impl(ptr, val_);
+ ptr->value = val_;
}
#endif
@@ -310,7 +310,7 @@ pg_atomic_read_u64_impl(volatile pg_atomic_uint64 *ptr)
static inline void
pg_atomic_init_u64_impl(volatile pg_atomic_uint64 *ptr, uint64 val_)
{
- pg_atomic_write_u64_impl(ptr, val_);
+ ptr->value = val_;
}
#endif
diff --git a/src/tools/valgrind.supp b/src/tools/valgrind.supp
index ead30858314..e82ec2ab394 100644
--- a/src/tools/valgrind.supp
+++ b/src/tools/valgrind.supp
@@ -134,20 +134,6 @@
fun:IsBinaryCoercible
}
-# Atomic writes to 64bit atomic vars uses compare/exchange to
-# guarantee atomic writes of 64bit variables. pg_atomic_write is used
-# during initialization of the atomic variable; that leads to an
-# initial read of the old, undefined, memory value. But that's just to
-# make sure the swap works correctly.
-{
- uninitialized_atomic_init_u64
- Memcheck:Cond
- fun:pg_atomic_exchange_u64_impl
- fun:pg_atomic_write_u64_impl
- fun:pg_atomic_init_u64_impl
-}
-
-
# Python's allocator does some low-level tricks for efficiency. Those
# can be disabled for better instrumentation; but few people testing
# postgres will have such a build of python. So add broad