]> git.proxmox.com Git - mirror_qemu.git/commitdiff
qemu/atomic: Add aligned_{int64,uint64}_t types
authorRichard Henderson <richard.henderson@linaro.org>
Fri, 16 Jul 2021 15:17:18 +0000 (08:17 -0700)
committerRichard Henderson <richard.henderson@linaro.org>
Wed, 21 Jul 2021 17:45:38 +0000 (07:45 -1000)
Use it to avoid some clang-12 -Watomic-alignment errors,
forcing some structures to be aligned and as a pointer when
we have ensured that the address is aligned.

Tested-by: Cole Robinson <crobinso@redhat.com>
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
accel/tcg/atomic_template.h
include/qemu/atomic.h
include/qemu/stats64.h
linux-user/hppa/cpu_loop.c
softmmu/timers-state.h
util/qsp.c

index afa8a9daf39938f5c60191f3691effb22b9ee16f..d347462af5b8929544fde90b734744dc9ad97e1f 100644 (file)
@@ -28,8 +28,8 @@
 # define SHIFT      4
 #elif DATA_SIZE == 8
 # define SUFFIX     q
-# define DATA_TYPE  uint64_t
-# define SDATA_TYPE int64_t
+# define DATA_TYPE  aligned_uint64_t
+# define SDATA_TYPE aligned_int64_t
 # define BSWAP      bswap64
 # define SHIFT      3
 #elif DATA_SIZE == 4
index fe5467d19369df72426475f30842f0c8635d3b4a..112a29910bea1d481ab8f23557141e0fa2406bfc 100644 (file)
     _oldn;                                                              \
 })
 
-/* Abstractions to access atomically (i.e. "once") i64/u64 variables */
+/*
+ * Abstractions to access atomically (i.e. "once") i64/u64 variables.
+ *
+ * The i386 abi is odd in that by default members are only aligned to
+ * 4 bytes, which means that 8-byte types can wind up mis-aligned.
+ * Clang will then warn about this, and emit a call into libatomic.
+ *
+ * Use of these types in structures when they will be used with atomic
+ * operations can avoid this.
+ */
+typedef int64_t aligned_int64_t __attribute__((aligned(8)));
+typedef uint64_t aligned_uint64_t __attribute__((aligned(8)));
+
 #ifdef CONFIG_ATOMIC64
 /* Use __nocheck because sizeof(void *) might be < sizeof(u64) */
 #define qatomic_read_i64(P) \
index fdd3d1b8f98fc0cdc1e189bcea7660eec32246f8..802402254b6f36346dca3e1a9af4c302edb0f1a7 100644 (file)
@@ -21,7 +21,7 @@
 
 typedef struct Stat64 {
 #ifdef CONFIG_ATOMIC64
-    uint64_t value;
+    aligned_uint64_t value;
 #else
     uint32_t low, high;
     uint32_t lock;
index 3aaaf3337cbffa2176c2fe846c423a32d7129486..82d8183821ad7218eccbeb2e13b04c581504b874 100644 (file)
@@ -82,7 +82,7 @@ static abi_ulong hppa_lws(CPUHPPAState *env)
                 o64 = *(uint64_t *)g2h(cs, old);
                 n64 = *(uint64_t *)g2h(cs, new);
 #ifdef CONFIG_ATOMIC64
-                r64 = qatomic_cmpxchg__nocheck((uint64_t *)g2h(cs, addr),
+                r64 = qatomic_cmpxchg__nocheck((aligned_uint64_t *)g2h(cs, addr),
                                                o64, n64);
                 ret = r64 != o64;
 #else
index 8c262ce139c754764f4a9b8116569d3957ef34c9..94bb7394c5d7e962f09a4242f3337bef5a03fd31 100644 (file)
@@ -47,7 +47,7 @@ typedef struct TimersState {
     int64_t last_delta;
 
     /* Compensate for varying guest execution speed.  */
-    int64_t qemu_icount_bias;
+    aligned_int64_t qemu_icount_bias;
 
     int64_t vm_clock_warp_start;
     int64_t cpu_clock_offset;
index bacc5fa2f6f21d752259b70696f161c1cd08e9a6..8562b14a8739bf3ef43904646792442937137716 100644 (file)
@@ -83,8 +83,8 @@ typedef struct QSPCallSite QSPCallSite;
 struct QSPEntry {
     void *thread_ptr;
     const QSPCallSite *callsite;
-    uint64_t n_acqs;
-    uint64_t ns;
+    aligned_uint64_t n_acqs;
+    aligned_uint64_t ns;
     unsigned int n_objs; /* count of coalesced objs; only used for reporting */
 };
 typedef struct QSPEntry QSPEntry;