Skip to contentSkip to conversation

qemu/atomic.h: prefix qemu_ to solve <stdatomic.h> collisions

PATCH Superseded Stefan Hajnoczi 7 participants 12 messages Sep 21, 2020 – Sep 23, 2020

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 qemu/atomic.h: prefix qemu_ to solve <stdatomic.h> collisions

clang's C11 atomic_fetch_*() functions only take a C11 atomic type pointer argument. QEMU uses direct types (int, etc) and this causes a compiler error when a QEMU code calls these functions in a source file that also included <stdatomic.h> via a system header file:

  $ CC=clang CXX=clang++ ./configure ... && make
  ../util/async.c:79:17: error: address argument to atomic operation must be a pointer to _Atomic type ('unsigned int *' invalid)

Avoid using atomic_*() names in QEMU's atomic.h since that namespace is used by <stdatomic.h>. Prefix QEMU's APIs with qemu_ so that atomic.h and <stdatomic.h> can co-exist.

This patch was generated using:

  $ git diff | grep -o '\<atomic_[a-z0-9_]\+' | sort -u >/tmp/changed_identifiers
  $ for identifier in $(</tmp/changed_identifiers64); do \
       sed -i "s%\<$identifier\>%qemu_$identifier%" $(git grep -l "\<$identifier\>") \
    done

I manually fixed line-wrap issues and misaligned rST tables.

---
 docs/devel/lockcnt.txt                        |  14 +-
 docs/devel/rcu.txt                            |  40 +--
 accel/tcg/atomic_template.h                   |  20 +-
 include/block/aio-wait.h                      |   4 +-
 include/block/aio.h                           |   8 +-
 include/exec/cpu_ldst.h                       |   2 +-
 include/exec/exec-all.h                       |   6 +-
 include/exec/log.h                            |   6 +-
 include/exec/memory.h                         |   2 +-
 include/exec/ram_addr.h                       |  27 +-
 include/exec/ramlist.h                        |   2 +-
 include/exec/tb-lookup.h                      |   4 +-
 include/hw/core/cpu.h                         |   2 +-
 include/qemu/atomic.h                         | 258 +++++++-------
 include/qemu/atomic128.h                      |   6 +-
 include/qemu/bitops.h                         |   2 +-
 include/qemu/coroutine.h                      |   2 +-
 include/qemu/log.h                            |   6 +-
 include/qemu/queue.h                          |   8 +-
 include/qemu/rcu.h                            |  10 +-
 include/qemu/rcu_queue.h                      | 103 +++---
 include/qemu/seqlock.h                        |   8 +-
 include/qemu/stats64.h                        |  28 +-
 include/qemu/thread.h                         |  37 +-
 .../infiniband/hw/vmw_pvrdma/pvrdma_ring.h    |  14 +-
 linux-user/qemu.h                             |   4 +-
 tcg/i386/tcg-target.h                         |   2 +-
 tcg/s390/tcg-target.h                         |   2 +-
 tcg/tci/tcg-target.h                          |   2 +-
 accel/kvm/kvm-all.c                           |  12 +-
 accel/tcg/cpu-exec.c                          |  16 +-
 accel/tcg/cputlb.c                            |  24 +-
 accel/tcg/tcg-all.c                           |   2 +-
 accel/tcg/translate-all.c                     |  56 +--
 audio/jackaudio.c                             |  20 +-
 block.c                                       |   4 +-
 block/block-backend.c                         |  15 +-
 block/io.c                                    |  48 +--
 block/nfs.c                                   |   2 +-
 block/sheepdog.c                              |   2 +-
 block/throttle-groups.c                       |  13 +-
 block/throttle.c                              |   4 +-
 blockdev.c                                    |   2 +-
 blockjob.c                                    |   2 +-
 contrib/libvhost-user/libvhost-user.c         |   2 +-
 cpus-common.c                                 |  26 +-
 dump/dump.c                                   |   8 +-
 exec.c                                        |  49 +--
 hw/core/cpu.c                                 |   6 +-
 hw/display/qxl.c                              |   7 +-
 hw/hyperv/hyperv.c                            |  11 +-
 hw/hyperv/vmbus.c                             |   2 +-
 hw/i386/xen/xen-hvm.c                         |   2 +-
 hw/intc/rx_icu.c                              |  12 +-
 hw/intc/sifive_plic.c                         |   4 +-
 hw/misc/edu.c                                 |  16 +-
 hw/net/virtio-net.c                           |  10 +-
 hw/rdma/rdma_backend.c                        |  19 +-
 hw/rdma/rdma_rm.c                             |   2 +-
 hw/rdma/vmw/pvrdma_dev_ring.c                 |   4 +-
 hw/s390x/s390-pci-bus.c                       |   2 +-
 hw/s390x/virtio-ccw.c                         |   2 +-
 hw/virtio/vhost.c                             |   2 +-
 hw/virtio/virtio-mmio.c                       |   6 +-
 hw/virtio/virtio-pci.c                        |   6 +-
 hw/virtio/virtio.c                            |  16 +-
 hw/xtensa/pic_cpu.c                           |   4 +-
 iothread.c                                    |   6 +-
 linux-user/hppa/cpu_loop.c                    |  11 +-
 linux-user/signal.c                           |   8 +-
 migration/colo-failover.c                     |   4 +-
 migration/migration.c                         |   8 +-
 migration/multifd.c                           |  18 +-
 migration/postcopy-ram.c                      |  35 +-
 migration/rdma.c                              |  34 +-
 monitor/hmp.c                                 |   6 +-
 monitor/misc.c                                |   2 +-
 monitor/monitor.c                             |   6 +-
 qemu-nbd.c                                    |   2 +-
 qga/commands.c                                |  12 +-
 qom/object.c                                  |  20 +-
 scsi/qemu-pr-helper.c                         |   4 +-
 softmmu/cpu-throttle.c                        |  10 +-
 softmmu/cpus.c                                |  42 +--
 softmmu/memory.c                              |   6 +-
 softmmu/vl.c                                  |   2 +-
 target/arm/mte_helper.c                       |   6 +-
 target/hppa/op_helper.c                       |   2 +-
 target/i386/mem_helper.c                      |   2 +-
 target/i386/whpx-all.c                        |   6 +-
 target/riscv/cpu_helper.c                     |   2 +-
 target/s390x/mem_helper.c                     |   4 +-
 target/xtensa/exc_helper.c                    |   4 +-
 target/xtensa/op_helper.c                     |   2 +-
 tcg/tcg.c                                     |  59 ++--
 tcg/tci.c                                     |   2 +-
 tests/atomic64-bench.c                        |  14 +-
 tests/atomic_add-bench.c                      |  14 +-
 tests/iothread.c                              |   2 +-
 tests/qht-bench.c                             |  12 +-
 tests/rcutorture.c                            |  24 +-
 tests/test-aio-multithread.c                  |  52 +--
 tests/test-logging.c                          |   4 +-
 tests/test-rcu-list.c                         |  38 +-
 tests/test-thread-pool.c                      |  10 +-
 util/aio-posix.c                              |  15 +-
 util/aio-wait.c                               |   2 +-
 util/aio-win32.c                              |   6 +-
 util/async.c                                  |  37 +-
 util/atomic64.c                               |  10 +-
 util/bitmap.c                                 |  14 +-
 util/cacheinfo.c                              |   2 +-
 util/fdmon-epoll.c                            |   4 +-
 util/fdmon-io_uring.c                         |  13 +-
 util/lockcnt.c                                |  59 ++--
 util/log.c                                    |  10 +-
 util/qemu-coroutine-lock.c                    |  19 +-
 util/qemu-coroutine-sleep.c                   |   4 +-
 util/qemu-coroutine.c                         |   6 +-
 util/qemu-sockets.c                           |   4 +-
 util/qemu-thread-posix.c                      |  12 +-
 util/qemu-thread-win32.c                      |  12 +-
 util/qemu-timer.c                             |  12 +-
 util/qht.c                                    |  57 +--
 util/qsp.c                                    |  50 +--
 util/rcu.c                                    |  36 +-
 util/stats64.c                                |  34 +-
 docs/devel/atomics.rst                        | 326 +++++++++---------
 .../opensbi-riscv32-generic-fw_dynamic.elf    | Bin 558668 -> 558698 bytes
 .../opensbi-riscv64-generic-fw_dynamic.elf    | Bin 620424 -> 620454 bytes
 scripts/kernel-doc                            |   2 +-
 tcg/aarch64/tcg-target.c.inc                  |   2 +-
 tcg/mips/tcg-target.c.inc                     |   2 +-
 tcg/ppc/tcg-target.c.inc                      |   6 +-
 tcg/sparc/tcg-target.c.inc                    |   5 +-
 135 files changed, 1195 insertions(+), 1130 deletions(-)
docs/devel/lockcnt.txt +7 -7
index 7c099bc6c8..dc928f85f9 100644
@@ -95,10 +95,10 @@ not just frees, though there could be cases where this is not necessary.
 
 Reads, instead, can be done without taking the mutex, as long as the
 readers and writers use the same macros that are used for RCU, for
-example atomic_rcu_read, atomic_rcu_set, QLIST_FOREACH_RCU, etc.  This is
-because the reads are done outside a lock and a set or QLIST_INSERT_HEAD
-can happen concurrently with the read.  The RCU API ensures that the
-processor and the compiler see all required memory barriers.
+example qemu_atomic_rcu_read, qemu_atomic_rcu_set, QLIST_FOREACH_RCU, etc.
+This is because the reads are done outside a lock and a set or
+QLIST_INSERT_HEAD can happen concurrently with the read.  The RCU API ensures
+that the processor and the compiler see all required memory barriers.
 
 This could be implemented simply by protecting the counter with the
 mutex, for example:
@@ -189,7 +189,7 @@ qemu_lockcnt_lock and qemu_lockcnt_unlock:
     if (!xyz) {
         new_xyz = g_new(XYZ, 1);
         ...
-        atomic_rcu_set(&xyz, new_xyz);
+        qemu_atomic_rcu_set(&xyz, new_xyz);
     }
     qemu_lockcnt_unlock(&xyz_lockcnt);
 
@@ -198,7 +198,7 @@ qemu_lockcnt_dec:
 
     qemu_lockcnt_inc(&xyz_lockcnt);
     if (xyz) {
-        XYZ *p = atomic_rcu_read(&xyz);
+        XYZ *p = qemu_atomic_rcu_read(&xyz);
         ...
         /* Accesses can now be done through "p".  */
     }
@@ -222,7 +222,7 @@ the decrement, the locking and the check on count as follows:
 
     qemu_lockcnt_inc(&xyz_lockcnt);
     if (xyz) {
-        XYZ *p = atomic_rcu_read(&xyz);
+        XYZ *p = qemu_atomic_rcu_read(&xyz);
         ...
         /* Accesses can now be done through "p".  */
     }
docs/devel/rcu.txt +20 -20
index 0ce15ba198..d04791c915 100644
@@ -130,13 +130,13 @@ The core RCU API is small:
 
             g_free_rcu(&foo, rcu);
 
-     typeof(*p) atomic_rcu_read(p);
+     typeof(*p) qemu_atomic_rcu_read(p);
 
-        atomic_rcu_read() is similar to atomic_load_acquire(), but it makes
-        some assumptions on the code that calls it.  This allows a more
+	qemu_atomic_rcu_read() is similar to qemu_atomic_load_acquire(), but it
+	makes some assumptions on the code that calls it.  This allows a more
         optimized implementation.
 
-        atomic_rcu_read assumes that whenever a single RCU critical
+        qemu_atomic_rcu_read assumes that whenever a single RCU critical
         section reads multiple shared data, these reads are either
         data-dependent or need no ordering.  This is almost always the
         case when using RCU, because read-side critical sections typically
@@ -144,7 +144,7 @@ The core RCU API is small:
         every update) until reaching a data structure of interest,
         and then read from there.
 
-        RCU read-side critical sections must use atomic_rcu_read() to
+        RCU read-side critical sections must use qemu_atomic_rcu_read() to
         read data, unless concurrent writes are prevented by another
         synchronization mechanism.
 
@@ -152,18 +152,18 @@ The core RCU API is small:
         data structure in a single direction, opposite to the direction
         in which the updater initializes it.
 
-     void atomic_rcu_set(p, typeof(*p) v);
+     void qemu_atomic_rcu_set(p, typeof(*p) v);
 
-        atomic_rcu_set() is similar to atomic_store_release(), though it also
-        makes assumptions on the code that calls it in order to allow a more
-        optimized implementation.
+	qemu_atomic_rcu_set() is similar to qemu_atomic_store_release(), though
+	it also makes assumptions on the code that calls it in order to allow a
+        more optimized implementation.
 
-        In particular, atomic_rcu_set() suffices for synchronization
+        In particular, qemu_atomic_rcu_set() suffices for synchronization
         with readers, if the updater never mutates a field within a
         data item that is already accessible to readers.  This is the
         case when initializing a new copy of the RCU-protected data
         structure; just ensure that initialization of *p is carried out
-        before atomic_rcu_set() makes the data item visible to readers.
+        before qemu_atomic_rcu_set() makes the data item visible to readers.
         If this rule is observed, writes will happen in the opposite
         order as reads in the RCU read-side critical sections (or if
         there is just one update), and there will be no need for other
@@ -212,7 +212,7 @@ DIFFERENCES WITH LINUX
   programming; not allowing this would prevent upgrading an RCU read-side
   critical section to become an updater.
 
-- atomic_rcu_read and atomic_rcu_set replace rcu_dereference and
+- qemu_atomic_rcu_read and qemu_atomic_rcu_set replace rcu_dereference and
   rcu_assign_pointer.  They take a _pointer_ to the variable being accessed.
 
 - call_rcu is a macro that has an extra argument (the name of the first
@@ -257,7 +257,7 @@ may be used as a restricted reference-counting mechanism.  For example,
 consider the following code fragment:
 
     rcu_read_lock();
-    p = atomic_rcu_read(&foo);
+    p = qemu_atomic_rcu_read(&foo);
     /* do something with p. */
     rcu_read_unlock();
 
@@ -268,7 +268,7 @@ The write side looks simply like this (with appropriate locking):
 
     qemu_mutex_lock(&foo_mutex);
     old = foo;
-    atomic_rcu_set(&foo, new);
+    qemu_atomic_rcu_set(&foo, new);
     qemu_mutex_unlock(&foo_mutex);
     synchronize_rcu();
     free(old);
@@ -277,7 +277,7 @@ If the processing cannot be done purely within the critical section, it
 is possible to combine this idiom with a "real" reference count:
 
     rcu_read_lock();
-    p = atomic_rcu_read(&foo);
+    p = qemu_atomic_rcu_read(&foo);
     foo_ref(p);
     rcu_read_unlock();
     /* do something with p. */
@@ -287,7 +287,7 @@ The write side can be like this:
 
     qemu_mutex_lock(&foo_mutex);
     old = foo;
-    atomic_rcu_set(&foo, new);
+    qemu_atomic_rcu_set(&foo, new);
     qemu_mutex_unlock(&foo_mutex);
     synchronize_rcu();
     foo_unref(old);
@@ -296,7 +296,7 @@ or with call_rcu:
 
     qemu_mutex_lock(&foo_mutex);
     old = foo;
-    atomic_rcu_set(&foo, new);
+    qemu_atomic_rcu_set(&foo, new);
     qemu_mutex_unlock(&foo_mutex);
     call_rcu(foo_unref, old, rcu);
 
@@ -307,7 +307,7 @@ last reference may be dropped on the read side.  Hence you can
 use call_rcu() instead:
 
      foo_unref(struct foo *p) {
-        if (atomic_fetch_dec(&p->refcount) == 1) {
+        if (qemu_atomic_fetch_dec(&p->refcount) == 1) {
             call_rcu(foo_destroy, p, rcu);
         }
     }
@@ -375,7 +375,7 @@ Instead, we store the size of the array with the array itself:
 
     read side:
         rcu_read_lock();
-        struct arr *array = atomic_rcu_read(&global_array);
+        struct arr *array = qemu_atomic_rcu_read(&global_array);
         x = i < array->size ? array->data[i] : -1;
         rcu_read_unlock();
         return x;
@@ -392,7 +392,7 @@ Instead, we store the size of the array with the array itself:
 
             /* Removal phase.  */
             old_array = global_array;
-            atomic_rcu_set(&new_array->data, new_array);
+            qemu_atomic_rcu_set(&new_array->data, new_array);
             synchronize_rcu();
 
             /* Reclamation phase.  */
accel/tcg/atomic_template.h +10 -10
index 26969487d6..6e9e221f78 100644
@@ -83,7 +83,7 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, target_ulong addr,
 #if DATA_SIZE == 16
     ret = atomic16_cmpxchg(haddr, cmpv, newv);
 #else
-    ret = atomic_cmpxchg__nocheck(haddr, cmpv, newv);
+    ret = qemu_atomic_cmpxchg__nocheck(haddr, cmpv, newv);
 #endif
     ATOMIC_MMU_CLEANUP;
     atomic_trace_rmw_post(env, addr, info);
@@ -131,7 +131,7 @@ ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, target_ulong addr,
                                          ATOMIC_MMU_IDX);
 
     atomic_trace_rmw_pre(env, addr, info);
-    ret = atomic_xchg__nocheck(haddr, val);
+    ret = qemu_atomic_xchg__nocheck(haddr, val);
     ATOMIC_MMU_CLEANUP;
     atomic_trace_rmw_post(env, addr, info);
     return ret;
@@ -147,7 +147,7 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr,       \
     uint16_t info = trace_mem_build_info(SHIFT, false, 0, false,    \
                                          ATOMIC_MMU_IDX);           \
     atomic_trace_rmw_pre(env, addr, info);                          \
-    ret = atomic_##X(haddr, val);                                   \
+    ret = qemu_atomic_##X(haddr, val);                              \
     ATOMIC_MMU_CLEANUP;                                             \
     atomic_trace_rmw_post(env, addr, info);                         \
     return ret;                                                     \
@@ -182,10 +182,10 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr,       \
                                          ATOMIC_MMU_IDX);           \
     atomic_trace_rmw_pre(env, addr, info);                          \
     smp_mb();                                                       \
-    cmp = atomic_read__nocheck(haddr);                              \
+    cmp = qemu_atomic_read__nocheck(haddr);                         \
     do {                                                            \
         old = cmp; new = FN(old, val);                              \
-        cmp = atomic_cmpxchg__nocheck(haddr, old, new);             \
+        cmp = qemu_atomic_cmpxchg__nocheck(haddr, old, new);        \
     } while (cmp != old);                                           \
     ATOMIC_MMU_CLEANUP;                                             \
     atomic_trace_rmw_post(env, addr, info);                         \
@@ -230,7 +230,7 @@ ABI_TYPE ATOMIC_NAME(cmpxchg)(CPUArchState *env, target_ulong addr,
 #if DATA_SIZE == 16
     ret = atomic16_cmpxchg(haddr, BSWAP(cmpv), BSWAP(newv));
 #else
-    ret = atomic_cmpxchg__nocheck(haddr, BSWAP(cmpv), BSWAP(newv));
+    ret = qemu_atomic_cmpxchg__nocheck(haddr, BSWAP(cmpv), BSWAP(newv));
 #endif
     ATOMIC_MMU_CLEANUP;
     atomic_trace_rmw_post(env, addr, info);
@@ -280,7 +280,7 @@ ABI_TYPE ATOMIC_NAME(xchg)(CPUArchState *env, target_ulong addr,
                                          ATOMIC_MMU_IDX);
 
     atomic_trace_rmw_pre(env, addr, info);
-    ret = atomic_xchg__nocheck(haddr, BSWAP(val));
+    ret = qemu_atomic_xchg__nocheck(haddr, BSWAP(val));
     ATOMIC_MMU_CLEANUP;
     atomic_trace_rmw_post(env, addr, info);
     return BSWAP(ret);
@@ -296,7 +296,7 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr,       \
     uint16_t info = trace_mem_build_info(SHIFT, false, MO_BSWAP,    \
                                          false, ATOMIC_MMU_IDX);    \
     atomic_trace_rmw_pre(env, addr, info);                          \
-    ret = atomic_##X(haddr, BSWAP(val));                            \
+    ret = qemu_atomic_##X(haddr, BSWAP(val));                       \
     ATOMIC_MMU_CLEANUP;                                             \
     atomic_trace_rmw_post(env, addr, info);                         \
     return BSWAP(ret);                                              \
@@ -329,10 +329,10 @@ ABI_TYPE ATOMIC_NAME(X)(CPUArchState *env, target_ulong addr,       \
                                          false, ATOMIC_MMU_IDX);    \
     atomic_trace_rmw_pre(env, addr, info);                          \
     smp_mb();                                                       \
-    ldn = atomic_read__nocheck(haddr);                              \
+    ldn = qemu_atomic_read__nocheck(haddr);                         \
     do {                                                            \
         ldo = ldn; old = BSWAP(ldo); new = FN(old, val);            \
-        ldn = atomic_cmpxchg__nocheck(haddr, ldo, BSWAP(new));      \
+        ldn = qemu_atomic_cmpxchg__nocheck(haddr, ldo, BSWAP(new)); \
     } while (ldo != ldn);                                           \
     ATOMIC_MMU_CLEANUP;                                             \
     atomic_trace_rmw_post(env, addr, info);                         \
include/block/aio-wait.h +2 -2
index 716d2639df..8f5a890666 100644
@@ -80,7 +80,7 @@ extern AioWait global_aio_wait;
     AioWait *wait_ = &global_aio_wait;                             \
     AioContext *ctx_ = (ctx);                                      \
     /* Increment wait_->num_waiters before evaluating cond. */     \
-    atomic_inc(&wait_->num_waiters);                               \
+    qemu_atomic_inc(&wait_->num_waiters);                          \
     if (ctx_ && in_aio_context_home_thread(ctx_)) {                \
         while ((cond)) {                                           \
             aio_poll(ctx_, true);                                  \
@@ -100,7 +100,7 @@ extern AioWait global_aio_wait;
             waited_ = true;                                        \
         }                                                          \
     }                                                              \
-    atomic_dec(&wait_->num_waiters);                               \
+    qemu_atomic_dec(&wait_->num_waiters);                          \
     waited_; })
 
 /**
include/block/aio.h +4 -4
index b2f703fa3f..057e73c48c 100644
@@ -595,7 +595,7 @@ int64_t aio_compute_timeout(AioContext *ctx);
  */
 static inline void aio_disable_external(AioContext *ctx)
 {
-    atomic_inc(&ctx->external_disable_cnt);
+    qemu_atomic_inc(&ctx->external_disable_cnt);
 }
 
 /**
@@ -608,7 +608,7 @@ static inline void aio_enable_external(AioContext *ctx)
 {
     int old;
 
-    old = atomic_fetch_dec(&ctx->external_disable_cnt);
+    old = qemu_atomic_fetch_dec(&ctx->external_disable_cnt);
     assert(old > 0);
     if (old == 1) {
         /* Kick event loop so it re-arms file descriptors */
@@ -624,7 +624,7 @@ static inline void aio_enable_external(AioContext *ctx)
  */
 static inline bool aio_external_disabled(AioContext *ctx)
 {
-    return atomic_read(&ctx->external_disable_cnt);
+    return qemu_atomic_read(&ctx->external_disable_cnt);
 }
 
 /**
@@ -637,7 +637,7 @@ static inline bool aio_external_disabled(AioContext *ctx)
  */
 static inline bool aio_node_check(AioContext *ctx, bool is_external)
 {
-    return !is_external || !atomic_read(&ctx->external_disable_cnt);
+    return !is_external || !qemu_atomic_read(&ctx->external_disable_cnt);
 }
 
 /**
include/exec/cpu_ldst.h +1 -1
index c14a48f65e..6dcf17f37b 100644
@@ -299,7 +299,7 @@ static inline target_ulong tlb_addr_write(const CPUTLBEntry *entry)
 #if TCG_OVERSIZED_GUEST
     return entry->addr_write;
 #else
-    return atomic_read(&entry->addr_write);
+    return qemu_atomic_read(&entry->addr_write);
 #endif
 }
 
include/exec/exec-all.h +3 -3
index 3cf88272df..05ad65a714 100644
@@ -89,7 +89,7 @@ void QEMU_NORETURN cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc);
  */
 static inline bool cpu_loop_exit_requested(CPUState *cpu)
 {
-    return (int32_t)atomic_read(&cpu_neg(cpu)->icount_decr.u32) < 0;
+    return (int32_t)qemu_atomic_read(&cpu_neg(cpu)->icount_decr.u32) < 0;
 }
 
 #if !defined(CONFIG_USER_ONLY)
@@ -487,10 +487,10 @@ struct TranslationBlock {
 
 extern bool parallel_cpus;
 
-/* Hide the atomic_read to make code a little easier on the eyes */
+/* Hide the qemu_atomic_read to make code a little easier on the eyes */
 static inline uint32_t tb_cflags(const TranslationBlock *tb)
 {
-    return atomic_read(&tb->cflags);
+    return qemu_atomic_read(&tb->cflags);
 }
 
 /* current cflags for hashing/comparison */
include/exec/log.h +3 -3
index 3ed797c1c8..2ff0ac0f7f 100644
@@ -19,7 +19,7 @@ static inline void log_cpu_state(CPUState *cpu, int flags)
 
     if (qemu_log_enabled()) {
         rcu_read_lock();
-        logfile = atomic_rcu_read(&qemu_logfile);
+        logfile = qemu_atomic_rcu_read(&qemu_logfile);
         if (logfile) {
             cpu_dump_state(cpu, logfile->fd, flags);
         }
@@ -49,7 +49,7 @@ static inline void log_target_disas(CPUState *cpu, target_ulong start,
 {
     QemuLogFile *logfile;
     rcu_read_lock();
-    logfile = atomic_rcu_read(&qemu_logfile);
+    logfile = qemu_atomic_rcu_read(&qemu_logfile);
     if (logfile) {
         target_disas(logfile->fd, cpu, start, len);
     }
@@ -60,7 +60,7 @@ static inline void log_disas(void *code, unsigned long size, const char *note)
 {
     QemuLogFile *logfile;
     rcu_read_lock();
-    logfile = atomic_rcu_read(&qemu_logfile);
+    logfile = qemu_atomic_rcu_read(&qemu_logfile);
     if (logfile) {
         disas(logfile->fd, code, size, note);
     }
include/exec/memory.h +1 -1
index f1bb2a7df5..d879d82d0f 100644
@@ -685,7 +685,7 @@ struct FlatView {
 
 static inline FlatView *address_space_to_flatview(AddressSpace *as)
 {
-    return atomic_rcu_read(&as->current_map);
+    return qemu_atomic_rcu_read(&as->current_map);
 }
 
 
include/exec/ram_addr.h +15 -12
index 3ef729a23c..6e7313d736 100644
@@ -164,7 +164,7 @@ static inline bool cpu_physical_memory_get_dirty(ram_addr_t start,
     page = start >> TARGET_PAGE_BITS;
 
     WITH_RCU_READ_LOCK_GUARD() {
-        blocks = atomic_rcu_read(&ram_list.dirty_memory[client]);
+        blocks = qemu_atomic_rcu_read(&ram_list.dirty_memory[client]);
 
         idx = page / DIRTY_MEMORY_BLOCK_SIZE;
         offset = page % DIRTY_MEMORY_BLOCK_SIZE;
@@ -205,7 +205,7 @@ static inline bool cpu_physical_memory_all_dirty(ram_addr_t start,
 
     RCU_READ_LOCK_GUARD();
 
-    blocks = atomic_rcu_read(&ram_list.dirty_memory[client]);
+    blocks = qemu_atomic_rcu_read(&ram_list.dirty_memory[client]);
 
     idx = page / DIRTY_MEMORY_BLOCK_SIZE;
     offset = page % DIRTY_MEMORY_BLOCK_SIZE;
@@ -278,7 +278,7 @@ static inline void cpu_physical_memory_set_dirty_flag(ram_addr_t addr,
 
     RCU_READ_LOCK_GUARD();
 
-    blocks = atomic_rcu_read(&ram_list.dirty_memory[client]);
+    blocks = qemu_atomic_rcu_read(&ram_list.dirty_memory[client]);
 
     set_bit_atomic(offset, blocks->blocks[idx]);
 }
@@ -301,7 +301,7 @@ static inline void cpu_physical_memory_set_dirty_range(ram_addr_t start,
 
     WITH_RCU_READ_LOCK_GUARD() {
         for (i = 0; i < DIRTY_MEMORY_NUM; i++) {
-            blocks[i] = atomic_rcu_read(&ram_list.dirty_memory[i]);
+            blocks[i] = qemu_atomic_rcu_read(&ram_list.dirty_memory[i]);
         }
 
         idx = page / DIRTY_MEMORY_BLOCK_SIZE;
@@ -361,23 +361,26 @@ static inline void cpu_physical_memory_set_dirty_lebitmap(unsigned long *bitmap,
 
         WITH_RCU_READ_LOCK_GUARD() {
             for (i = 0; i < DIRTY_MEMORY_NUM; i++) {
-                blocks[i] = atomic_rcu_read(&ram_list.dirty_memory[i])->blocks;
+                blocks[i] =
+                    qemu_atomic_rcu_read(&ram_list.dirty_memory[i])->blocks;
             }
 
             for (k = 0; k < nr; k++) {
                 if (bitmap[k]) {
                     unsigned long temp = leul_to_cpu(bitmap[k]);
 
-                    atomic_or(&blocks[DIRTY_MEMORY_VGA][idx][offset], temp);
+                    qemu_atomic_or(&blocks[DIRTY_MEMORY_VGA][idx][offset],
+                                   temp);
 
                     if (global_dirty_log) {
-                        atomic_or(&blocks[DIRTY_MEMORY_MIGRATION][idx][offset],
-                                  temp);
+                        qemu_atomic_or(
+                            &blocks[DIRTY_MEMORY_MIGRATION][idx][offset],
+                            temp);
                     }
 
                     if (tcg_enabled()) {
-                        atomic_or(&blocks[DIRTY_MEMORY_CODE][idx][offset],
-                                  temp);
+                        qemu_atomic_or(&blocks[DIRTY_MEMORY_CODE][idx][offset],
+                                       temp);
                     }
                 }
 
@@ -461,12 +464,12 @@ uint64_t cpu_physical_memory_sync_dirty_bitmap(RAMBlock *rb,
                                         DIRTY_MEMORY_BLOCK_SIZE);
         unsigned long page = BIT_WORD(start >> TARGET_PAGE_BITS);
 
-        src = atomic_rcu_read(
+        src = qemu_atomic_rcu_read(
                 &ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION])->blocks;
 
         for (k = page; k < page + nr; k++) {
             if (src[idx][offset]) {
-                unsigned long bits = atomic_xchg(&src[idx][offset], 0);
+                unsigned long bits = qemu_atomic_xchg(&src[idx][offset], 0);
                 unsigned long new_dirty;
                 new_dirty = ~dest[k];
                 dest[k] |= bits;
include/exec/ramlist.h +1 -1
index bc4faa1b00..af5806f143 100644
@@ -19,7 +19,7 @@ typedef struct RAMBlockNotifier RAMBlockNotifier;
  *   rcu_read_lock();
  *
  *   DirtyMemoryBlocks *blocks =
- *       atomic_rcu_read(&ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION]);
+ *       qemu_atomic_rcu_read(&ram_list.dirty_memory[DIRTY_MEMORY_MIGRATION]);
  *
  *   ram_addr_t idx = (addr >> TARGET_PAGE_BITS) / DIRTY_MEMORY_BLOCK_SIZE;
  *   unsigned long *block = blocks.blocks[idx];
include/exec/tb-lookup.h +2 -2
index 26921b6daf..85eaded201 100644
@@ -27,7 +27,7 @@ tb_lookup__cpu_state(CPUState *cpu, target_ulong *pc, target_ulong *cs_base,
 
     cpu_get_tb_cpu_state(env, pc, cs_base, flags);
     hash = tb_jmp_cache_hash_func(*pc);
-    tb = atomic_rcu_read(&cpu->tb_jmp_cache[hash]);
+    tb = qemu_atomic_rcu_read(&cpu->tb_jmp_cache[hash]);
 
     cf_mask &= ~CF_CLUSTER_MASK;
     cf_mask |= cpu->cluster_index << CF_CLUSTER_SHIFT;
@@ -44,7 +44,7 @@ tb_lookup__cpu_state(CPUState *cpu, target_ulong *pc, target_ulong *cs_base,
     if (tb == NULL) {
         return NULL;
     }
-    atomic_set(&cpu->tb_jmp_cache[hash], tb);
+    qemu_atomic_set(&cpu->tb_jmp_cache[hash], tb);
     return tb;
 }
 
include/hw/core/cpu.h +1 -1
index 99dc33ffeb..3231caa860 100644
@@ -482,7 +482,7 @@ static inline void cpu_tb_jmp_cache_clear(CPUState *cpu)
     unsigned int i;
 
     for (i = 0; i < TB_JMP_CACHE_SIZE; i++) {
-        atomic_set(&cpu->tb_jmp_cache[i], NULL);
+        qemu_atomic_set(&cpu->tb_jmp_cache[i], NULL);
     }
 }
 
include/qemu/atomic.h +137 -121

425 lines not on this page · raw message

include/qemu/atomic128.h +3 -3
index 6b34484e15..1fbb514c59 100644
@@ -44,7 +44,7 @@
 #if defined(CONFIG_ATOMIC128)
 static inline Int128 atomic16_cmpxchg(Int128 *ptr, Int128 cmp, Int128 new)
 {
-    return atomic_cmpxchg__nocheck(ptr, cmp, new);
+    return qemu_atomic_cmpxchg__nocheck(ptr, cmp, new);
 }
 # define HAVE_CMPXCHG128 1
 #elif defined(CONFIG_CMPXCHG128)
@@ -89,12 +89,12 @@ Int128 QEMU_ERROR("unsupported atomic")
 #if defined(CONFIG_ATOMIC128)
 static inline Int128 atomic16_read(Int128 *ptr)
 {
-    return atomic_read__nocheck(ptr);
+    return qemu_atomic_read__nocheck(ptr);
 }
 
 static inline void atomic16_set(Int128 *ptr, Int128 val)
 {
-    atomic_set__nocheck(ptr, val);
+    qemu_atomic_set__nocheck(ptr, val);
 }
 
 # define HAVE_ATOMIC128 1
include/qemu/bitops.h +1 -1
index f55ce8b320..f74600de90 100644
@@ -51,7 +51,7 @@ static inline void set_bit_atomic(long nr, unsigned long *addr)
     unsigned long mask = BIT_MASK(nr);
     unsigned long *p = addr + BIT_WORD(nr);
 
-    atomic_or(p, mask);
+    qemu_atomic_or(p, mask);
 }
 
 /**
include/qemu/coroutine.h +1 -1
index dfd261c5b1..4d7020d188 100644
@@ -179,7 +179,7 @@ static inline coroutine_fn void qemu_co_mutex_assert_locked(CoMutex *mutex)
      * because the condition will be false no matter whether we read NULL or
      * the pointer for any other coroutine.
      */
-    assert(atomic_read(&mutex->locked) &&
+    assert(qemu_atomic_read(&mutex->locked) &&
            mutex->holder == qemu_coroutine_self());
 }
 
include/qemu/log.h +3 -3
index f4724f7330..e4d454ccfa 100644
@@ -36,7 +36,7 @@ static inline bool qemu_log_separate(void)
     bool res = false;
 
     rcu_read_lock();
-    logfile = atomic_rcu_read(&qemu_logfile);
+    logfile = qemu_atomic_rcu_read(&qemu_logfile);
     if (logfile && logfile->fd != stderr) {
         res = true;
     }
@@ -75,7 +75,7 @@ static inline FILE *qemu_log_lock(void)
 {
     QemuLogFile *logfile;
     rcu_read_lock();
-    logfile = atomic_rcu_read(&qemu_logfile);
+    logfile = qemu_atomic_rcu_read(&qemu_logfile);
     if (logfile) {
         qemu_flockfile(logfile->fd);
         return logfile->fd;
@@ -102,7 +102,7 @@ qemu_log_vprintf(const char *fmt, va_list va)
     QemuLogFile *logfile;
 
     rcu_read_lock();
-    logfile = atomic_rcu_read(&qemu_logfile);
+    logfile = qemu_atomic_rcu_read(&qemu_logfile);
     if (logfile) {
         vfprintf(logfile->fd, fmt, va);
     }
include/qemu/queue.h +5 -3
index 456a5b01ee..707ae10062 100644
@@ -218,12 +218,13 @@ struct {                                                                \
         typeof(elm) save_sle_next;                                           \
         do {                                                                 \
             save_sle_next = (elm)->field.sle_next = (head)->slh_first;       \
-        } while (atomic_cmpxchg(&(head)->slh_first, save_sle_next, (elm)) != \
+        } while (qemu_atomic_cmpxchg(&(head)->slh_first,                     \
+                                     save_sle_next, (elm)) !=                \
                  save_sle_next);                                             \
 } while (/*CONSTCOND*/0)
 
 #define QSLIST_MOVE_ATOMIC(dest, src) do {                               \
-        (dest)->slh_first = atomic_xchg(&(src)->slh_first, NULL);        \
+        (dest)->slh_first = qemu_atomic_xchg(&(src)->slh_first, NULL);   \
 } while (/*CONSTCOND*/0)
 
 #define QSLIST_REMOVE_HEAD(head, field) do {                             \
@@ -376,7 +377,8 @@ struct {                                                                \
 /*
  * Simple queue access methods.
  */
-#define QSIMPLEQ_EMPTY_ATOMIC(head) (atomic_read(&((head)->sqh_first)) == NULL)
+#define QSIMPLEQ_EMPTY_ATOMIC(head) \
+    (qemu_atomic_read(&((head)->sqh_first)) == NULL)
 #define QSIMPLEQ_EMPTY(head)        ((head)->sqh_first == NULL)
 #define QSIMPLEQ_FIRST(head)        ((head)->sqh_first)
 #define QSIMPLEQ_NEXT(elm, field)   ((elm)->field.sqe_next)
include/qemu/rcu.h +5 -5
index 0e375ebe13..96a1bb9039 100644
@@ -79,8 +79,8 @@ static inline void rcu_read_lock(void)
         return;
     }
 
-    ctr = atomic_read(&rcu_gp_ctr);
-    atomic_set(&p_rcu_reader->ctr, ctr);
+    ctr = qemu_atomic_read(&rcu_gp_ctr);
+    qemu_atomic_set(&p_rcu_reader->ctr, ctr);
 
     /* Write p_rcu_reader->ctr before reading RCU-protected pointers.  */
     smp_mb_placeholder();
@@ -100,12 +100,12 @@ static inline void rcu_read_unlock(void)
      * smp_mb_placeholder(), this ensures writes to p_rcu_reader->ctr
      * are sequentially consistent.
      */
-    atomic_store_release(&p_rcu_reader->ctr, 0);
+    qemu_atomic_store_release(&p_rcu_reader->ctr, 0);
 
     /* Write p_rcu_reader->ctr before reading p_rcu_reader->waiting.  */
     smp_mb_placeholder();
-    if (unlikely(atomic_read(&p_rcu_reader->waiting))) {
-        atomic_set(&p_rcu_reader->waiting, false);
+    if (unlikely(qemu_atomic_read(&p_rcu_reader->waiting))) {
+        qemu_atomic_set(&p_rcu_reader->waiting, false);
         qemu_event_set(&rcu_gp_event);
     }
 }
include/qemu/rcu_queue.h +56 -47

262 lines not on this page · raw message

include/qemu/seqlock.h +4 -4
index 8b6b4ee4bb..b282aef078 100644
@@ -32,7 +32,7 @@ static inline void seqlock_init(QemuSeqLock *sl)
 /* Lock out other writers and update the count.  */
 static inline void seqlock_write_begin(QemuSeqLock *sl)
 {
-    atomic_set(&sl->sequence, sl->sequence + 1);
+    qemu_atomic_set(&sl->sequence, sl->sequence + 1);
 
     /* Write sequence before updating other fields.  */
     smp_wmb();
@@ -43,7 +43,7 @@ static inline void seqlock_write_end(QemuSeqLock *sl)
     /* Write other fields before finalizing sequence.  */
     smp_wmb();
 
-    atomic_set(&sl->sequence, sl->sequence + 1);
+    qemu_atomic_set(&sl->sequence, sl->sequence + 1);
 }
 
 /* Lock out other writers and update the count.  */
@@ -68,7 +68,7 @@ static inline void seqlock_write_unlock_impl(QemuSeqLock *sl, QemuLockable *lock
 static inline unsigned seqlock_read_begin(const QemuSeqLock *sl)
 {
     /* Always fail if a write is in progress.  */
-    unsigned ret = atomic_read(&sl->sequence);
+    unsigned ret = qemu_atomic_read(&sl->sequence);
 
     /* Read sequence before reading other fields.  */
     smp_rmb();
@@ -79,7 +79,7 @@ static inline int seqlock_read_retry(const QemuSeqLock *sl, unsigned start)
 {
     /* Read other fields before reading final sequence.  */
     smp_rmb();
-    return unlikely(atomic_read(&sl->sequence) != start);
+    return unlikely(qemu_atomic_read(&sl->sequence) != start);
 }
 
 #endif
include/qemu/stats64.h +14 -14
index 19a5ac4c56..d43eca1dd2 100644
@@ -37,27 +37,27 @@ static inline void stat64_init(Stat64 *s, uint64_t value)
 
 static inline uint64_t stat64_get(const Stat64 *s)
 {
-    return atomic_read__nocheck(&s->value);
+    return qemu_atomic_read__nocheck(&s->value);
 }
 
 static inline void stat64_add(Stat64 *s, uint64_t value)
 {
-    atomic_add(&s->value, value);
+    qemu_atomic_add(&s->value, value);
 }
 
 static inline void stat64_min(Stat64 *s, uint64_t value)
 {
-    uint64_t orig = atomic_read__nocheck(&s->value);
+    uint64_t orig = qemu_atomic_read__nocheck(&s->value);
     while (orig > value) {
-        orig = atomic_cmpxchg__nocheck(&s->value, orig, value);
+        orig = qemu_atomic_cmpxchg__nocheck(&s->value, orig, value);
     }
 }
 
 static inline void stat64_max(Stat64 *s, uint64_t value)
 {
-    uint64_t orig = atomic_read__nocheck(&s->value);
+    uint64_t orig = qemu_atomic_read__nocheck(&s->value);
     while (orig < value) {
-        orig = atomic_cmpxchg__nocheck(&s->value, orig, value);
+        orig = qemu_atomic_cmpxchg__nocheck(&s->value, orig, value);
     }
 }
 #else
@@ -79,7 +79,7 @@ static inline void stat64_add(Stat64 *s, uint64_t value)
     low = (uint32_t) value;
     if (!low) {
         if (high) {
-            atomic_add(&s->high, high);
+            qemu_atomic_add(&s->high, high);
         }
         return;
     }
@@ -101,7 +101,7 @@ static inline void stat64_add(Stat64 *s, uint64_t value)
          * the high 32 bits, so it can race just fine with stat64_add32_carry
          * and even stat64_get!
          */
-        old = atomic_cmpxchg(&s->low, orig, result);
+        old = qemu_atomic_cmpxchg(&s->low, orig, result);
         if (orig == old) {
             return;
         }
@@ -116,7 +116,7 @@ static inline void stat64_min(Stat64 *s, uint64_t value)
     high = value >> 32;
     low = (uint32_t) value;
     do {
-        orig_high = atomic_read(&s->high);
+        orig_high = qemu_atomic_read(&s->high);
         if (orig_high < high) {
             return;
         }
@@ -128,7 +128,7 @@ static inline void stat64_min(Stat64 *s, uint64_t value)
              * the write barrier in stat64_min_slow.
              */
             smp_rmb();
-            orig_low = atomic_read(&s->low);
+            orig_low = qemu_atomic_read(&s->low);
             if (orig_low <= low) {
                 return;
             }
@@ -138,7 +138,7 @@ static inline void stat64_min(Stat64 *s, uint64_t value)
              * we may miss being lucky.
              */
             smp_rmb();
-            orig_high = atomic_read(&s->high);
+            orig_high = qemu_atomic_read(&s->high);
             if (orig_high < high) {
                 return;
             }
@@ -156,7 +156,7 @@ static inline void stat64_max(Stat64 *s, uint64_t value)
     high = value >> 32;
     low = (uint32_t) value;
     do {
-        orig_high = atomic_read(&s->high);
+        orig_high = qemu_atomic_read(&s->high);
         if (orig_high > high) {
             return;
         }
@@ -168,7 +168,7 @@ static inline void stat64_max(Stat64 *s, uint64_t value)
              * the write barrier in stat64_max_slow.
              */
             smp_rmb();
-            orig_low = atomic_read(&s->low);
+            orig_low = qemu_atomic_read(&s->low);
             if (orig_low >= low) {
                 return;
             }
@@ -178,7 +178,7 @@ static inline void stat64_max(Stat64 *s, uint64_t value)
              * we may miss being lucky.
              */
             smp_rmb();
-            orig_high = atomic_read(&s->high);
+            orig_high = qemu_atomic_read(&s->high);
             if (orig_high > high) {
                 return;
             }
include/qemu/thread.h +20 -17
index 4baf4d1715..104e811236 100644
@@ -69,35 +69,38 @@ extern QemuCondTimedWaitFunc qemu_cond_timedwait_func;
 #define qemu_cond_timedwait(c, m, ms)                                   \
             qemu_cond_timedwait_impl(c, m, ms, __FILE__, __LINE__)
 #else
-#define qemu_mutex_lock(m) ({                                           \
-            QemuMutexLockFunc _f = atomic_read(&qemu_mutex_lock_func);  \
-            _f(m, __FILE__, __LINE__);                                  \
+#define qemu_mutex_lock(m) ({                                                \
+            QemuMutexLockFunc _f = qemu_atomic_read(&qemu_mutex_lock_func);  \
+            _f(m, __FILE__, __LINE__);                                       \
         })
 
 #define qemu_mutex_trylock(m) ({                                        \
-            QemuMutexTrylockFunc _f = atomic_read(&qemu_mutex_trylock_func); \
+            QemuMutexTrylockFunc _f =                                   \
+                qemu_atomic_read(&qemu_mutex_trylock_func);             \
             _f(m, __FILE__, __LINE__);                                  \
         })
 
 #define qemu_rec_mutex_lock(m) ({                                       \
-            QemuRecMutexLockFunc _f = atomic_read(&qemu_rec_mutex_lock_func); \
+            QemuRecMutexLockFunc _f =                                   \
+                qemu_atomic_read(&qemu_rec_mutex_lock_func);            \
             _f(m, __FILE__, __LINE__);                                  \
         })
 
-#define qemu_rec_mutex_trylock(m) ({                            \
-            QemuRecMutexTrylockFunc _f;                         \
-            _f = atomic_read(&qemu_rec_mutex_trylock_func);     \
-            _f(m, __FILE__, __LINE__);                          \
+#define qemu_rec_mutex_trylock(m) ({                                 \
+            QemuRecMutexTrylockFunc _f;                              \
+            _f = qemu_atomic_read(&qemu_rec_mutex_trylock_func);     \
+            _f(m, __FILE__, __LINE__);                               \
         })
 
-#define qemu_cond_wait(c, m) ({                                         \
-            QemuCondWaitFunc _f = atomic_read(&qemu_cond_wait_func);    \
-            _f(c, m, __FILE__, __LINE__);                               \
+#define qemu_cond_wait(c, m) ({                                              \
+            QemuCondWaitFunc _f = qemu_atomic_read(&qemu_cond_wait_func);    \
+            _f(c, m, __FILE__, __LINE__);                                    \
         })
 
-#define qemu_cond_timedwait(c, m, ms) ({                                       \
-            QemuCondTimedWaitFunc _f = atomic_read(&qemu_cond_timedwait_func); \
-            _f(c, m, ms, __FILE__, __LINE__);                                  \
+#define qemu_cond_timedwait(c, m, ms) ({                                     \
+            QemuCondTimedWaitFunc _f =                                       \
+                qemu_atomic_read(&qemu_cond_timedwait_func);                 \
+            _f(c, m, ms, __FILE__, __LINE__);                                \
         })
 #endif
 
@@ -236,7 +239,7 @@ static inline void qemu_spin_lock(QemuSpin *spin)
     __tsan_mutex_pre_lock(spin, 0);
 #endif
     while (unlikely(__sync_lock_test_and_set(&spin->value, true))) {
-        while (atomic_read(&spin->value)) {
+        while (qemu_atomic_read(&spin->value)) {
             cpu_relax();
         }
     }
@@ -261,7 +264,7 @@ static inline bool qemu_spin_trylock(QemuSpin *spin)
 
 static inline bool qemu_spin_locked(QemuSpin *spin)
 {
-    return atomic_read(&spin->value);
+    return qemu_atomic_read(&spin->value);
 }
 
 static inline void qemu_spin_unlock(QemuSpin *spin)
include/standard-headers/drivers/infiniband/hw/vmw_pvrdma/pvrdma_ring.h +7 -7
index acd4c8346d..8e712904e9 100644
@@ -68,7 +68,7 @@ static inline int pvrdma_idx_valid(uint32_t idx, uint32_t max_elems)
 
 static inline int32_t pvrdma_idx(int *var, uint32_t max_elems)
 {
-	const unsigned int idx = atomic_read(var);
+	const unsigned int idx = qemu_atomic_read(var);
 
 	if (pvrdma_idx_valid(idx, max_elems))
 		return idx & (max_elems - 1);
@@ -77,17 +77,17 @@ static inline int32_t pvrdma_idx(int *var, uint32_t max_elems)
 
 static inline void pvrdma_idx_ring_inc(int *var, uint32_t max_elems)
 {
-	uint32_t idx = atomic_read(var) + 1;	/* Increment. */
+	uint32_t idx = qemu_atomic_read(var) + 1;	/* Increment. */
 
 	idx &= (max_elems << 1) - 1;		/* Modulo size, flip gen. */
-	atomic_set(var, idx);
+	qemu_atomic_set(var, idx);
 }
 
 static inline int32_t pvrdma_idx_ring_has_space(const struct pvrdma_ring *r,
 					      uint32_t max_elems, uint32_t *out_tail)
 {
-	const uint32_t tail = atomic_read(&r->prod_tail);
-	const uint32_t head = atomic_read(&r->cons_head);
+	const uint32_t tail = qemu_atomic_read(&r->prod_tail);
+	const uint32_t head = qemu_atomic_read(&r->cons_head);
 
 	if (pvrdma_idx_valid(tail, max_elems) &&
 	    pvrdma_idx_valid(head, max_elems)) {
@@ -100,8 +100,8 @@ static inline int32_t pvrdma_idx_ring_has_space(const struct pvrdma_ring *r,
 static inline int32_t pvrdma_idx_ring_has_data(const struct pvrdma_ring *r,
 					     uint32_t max_elems, uint32_t *out_head)
 {
-	const uint32_t tail = atomic_read(&r->prod_tail);
-	const uint32_t head = atomic_read(&r->cons_head);
+	const uint32_t tail = qemu_atomic_read(&r->prod_tail);
+	const uint32_t head = qemu_atomic_read(&r->cons_head);
 
 	if (pvrdma_idx_valid(tail, max_elems) &&
 	    pvrdma_idx_valid(head, max_elems)) {
linux-user/qemu.h +2 -2
index a69a0bd347..f9e835de80 100644
@@ -146,8 +146,8 @@ typedef struct TaskState {
     /* Nonzero if process_pending_signals() needs to do something (either
      * handle a pending signal or unblock signals).
      * This flag is written from a signal handler so should be accessed via
-     * the atomic_read() and atomic_set() functions. (It is not accessed
-     * from multiple threads.)
+     * the qemu_atomic_read() and qemu_atomic_set() functions. (It is not
+     * accessed from multiple threads.)
      */
     int signal_pending;
 
tcg/i386/tcg-target.h +1 -1
index 99ac1e3958..8eede29e32 100644
@@ -215,7 +215,7 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr,
                                             uintptr_t jmp_addr, uintptr_t addr)
 {
     /* patch the branch destination */
-    atomic_set((int32_t *)jmp_addr, addr - (jmp_addr + 4));
+    qemu_atomic_set((int32_t *)jmp_addr, addr - (jmp_addr + 4));
     /* no need to flush icache explicitly */
 }
 
tcg/s390/tcg-target.h +1 -1
index 07accabbd1..b8a6b51556 100644
@@ -154,7 +154,7 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr,
 {
     /* patch the branch destination */
     intptr_t disp = addr - (jmp_addr - 2);
-    atomic_set((int32_t *)jmp_addr, disp / 2);
+    qemu_atomic_set((int32_t *)jmp_addr, disp / 2);
     /* no need to flush icache explicitly */
 }
 
tcg/tci/tcg-target.h +1 -1
index 8b90ab71cb..2fac115db6 100644
@@ -206,7 +206,7 @@ static inline void tb_target_set_jmp_target(uintptr_t tc_ptr,
                                             uintptr_t jmp_addr, uintptr_t addr)
 {
     /* patch the branch destination */
-    atomic_set((int32_t *)jmp_addr, addr - (jmp_addr + 4));
+    qemu_atomic_set((int32_t *)jmp_addr, addr - (jmp_addr + 4));
     /* no need to flush icache explicitly */
 }
 
accel/kvm/kvm-all.c +6 -6
index ad8b315b35..06e50b8ac6 100644
@@ -2379,7 +2379,7 @@ static __thread bool have_sigbus_pending;
 
 static void kvm_cpu_kick(CPUState *cpu)
 {
-    atomic_set(&cpu->kvm_run->immediate_exit, 1);
+    qemu_atomic_set(&cpu->kvm_run->immediate_exit, 1);
 }
 
 static void kvm_cpu_kick_self(void)
@@ -2400,7 +2400,7 @@ static void kvm_eat_signals(CPUState *cpu)
     int r;
 
     if (kvm_immediate_exit) {
-        atomic_set(&cpu->kvm_run->immediate_exit, 0);
+        qemu_atomic_set(&cpu->kvm_run->immediate_exit, 0);
         /* Write kvm_run->immediate_exit before the cpu->exit_request
          * write in kvm_cpu_exec.
          */
@@ -2434,7 +2434,7 @@ int kvm_cpu_exec(CPUState *cpu)
     DPRINTF("kvm_cpu_exec()\n");
 
     if (kvm_arch_process_async_events(cpu)) {
-        atomic_set(&cpu->exit_request, 0);
+        qemu_atomic_set(&cpu->exit_request, 0);
         return EXCP_HLT;
     }
 
@@ -2450,7 +2450,7 @@ int kvm_cpu_exec(CPUState *cpu)
         }
 
         kvm_arch_pre_run(cpu, run);
-        if (atomic_read(&cpu->exit_request)) {
+        if (qemu_atomic_read(&cpu->exit_request)) {
             DPRINTF("interrupt exit requested\n");
             /*
              * KVM requires us to reenter the kernel after IO exits to complete
@@ -2577,7 +2577,7 @@ int kvm_cpu_exec(CPUState *cpu)
         vm_stop(RUN_STATE_INTERNAL_ERROR);
     }
 
-    atomic_set(&cpu->exit_request, 0);
+    qemu_atomic_set(&cpu->exit_request, 0);
     return ret;
 }
 
@@ -2994,7 +2994,7 @@ int kvm_on_sigbus_vcpu(CPUState *cpu, int code, void *addr)
     have_sigbus_pending = true;
     pending_sigbus_addr = addr;
     pending_sigbus_code = code;
-    atomic_set(&cpu->exit_request, 1);
+    qemu_atomic_set(&cpu->exit_request, 1);
     return 0;
 #else
     return 1;
accel/tcg/cpu-exec.c +9 -7
index 66d38f9d85..abbd5e9588 100644
@@ -367,7 +367,9 @@ static inline void tb_add_jump(TranslationBlock *tb, int n,
         goto out_unlock_next;
     }
     /* Atomically claim the jump destination slot only if it was NULL */
-    old = atomic_cmpxchg(&tb->jmp_dest[n], (uintptr_t)NULL, (uintptr_t)tb_next);
+    old = qemu_atomic_cmpxchg(&tb->jmp_dest[n],
+                              (uintptr_t)NULL,
+                              (uintptr_t)tb_next);
     if (old) {
         goto out_unlock_next;
     }
@@ -407,7 +409,7 @@ static inline TranslationBlock *tb_find(CPUState *cpu,
         tb = tb_gen_code(cpu, pc, cs_base, flags, cf_mask);
         mmap_unlock();
         /* We add the TB in the virtual pc hash table for the fast lookup */
-        atomic_set(&cpu->tb_jmp_cache[tb_jmp_cache_hash_func(pc)], tb);
+        qemu_atomic_set(&cpu->tb_jmp_cache[tb_jmp_cache_hash_func(pc)], tb);
     }
 #ifndef CONFIG_USER_ONLY
     /* We don't take care of direct jumps when address mapping changes in
@@ -536,9 +538,9 @@ static inline bool cpu_handle_interrupt(CPUState *cpu,
      * Ensure zeroing happens before reading cpu->exit_request or
      * cpu->interrupt_request (see also smp_wmb in cpu_exit())
      */
-    atomic_mb_set(&cpu_neg(cpu)->icount_decr.u16.high, 0);
+    qemu_atomic_mb_set(&cpu_neg(cpu)->icount_decr.u16.high, 0);
 
-    if (unlikely(atomic_read(&cpu->interrupt_request))) {
+    if (unlikely(qemu_atomic_read(&cpu->interrupt_request))) {
         int interrupt_request;
         qemu_mutex_lock_iothread();
         interrupt_request = cpu->interrupt_request;
@@ -613,10 +615,10 @@ static inline bool cpu_handle_interrupt(CPUState *cpu,
     }
 
     /* Finally, check if we need to exit to the main loop.  */
-    if (unlikely(atomic_read(&cpu->exit_request))
+    if (unlikely(qemu_atomic_read(&cpu->exit_request))
         || (use_icount
             && cpu_neg(cpu)->icount_decr.u16.low + cpu->icount_extra == 0)) {
-        atomic_set(&cpu->exit_request, 0);
+        qemu_atomic_set(&cpu->exit_request, 0);
         if (cpu->exception_index == -1) {
             cpu->exception_index = EXCP_INTERRUPT;
         }
@@ -642,7 +644,7 @@ static inline void cpu_loop_exec_tb(CPUState *cpu, TranslationBlock *tb,
     }
 
     *last_tb = NULL;
-    insns_left = atomic_read(&cpu_neg(cpu)->icount_decr.u32);
+    insns_left = qemu_atomic_read(&cpu_neg(cpu)->icount_decr.u32);
     if (insns_left < 0) {
         /* Something asked us to stop executing chained TBs; just
          * continue round the main loop. Whatever requested the exit
accel/tcg/cputlb.c +12 -12
index 6489abbf8c..eaaf0af574 100644
@@ -312,9 +312,9 @@ void tlb_flush_counts(size_t *pfull, size_t *ppart, size_t *pelide)
     CPU_FOREACH(cpu) {
         CPUArchState *env = cpu->env_ptr;
 
-        full += atomic_read(&env_tlb(env)->c.full_flush_count);
-        part += atomic_read(&env_tlb(env)->c.part_flush_count);
-        elide += atomic_read(&env_tlb(env)->c.elide_flush_count);
+        full += qemu_atomic_read(&env_tlb(env)->c.full_flush_count);
+        part += qemu_atomic_read(&env_tlb(env)->c.part_flush_count);
+        elide += qemu_atomic_read(&env_tlb(env)->c.elide_flush_count);
     }
     *pfull = full;
     *ppart = part;
@@ -349,13 +349,13 @@ static void tlb_flush_by_mmuidx_async_work(CPUState *cpu, run_on_cpu_data data)
     cpu_tb_jmp_cache_clear(cpu);
 
     if (to_clean == ALL_MMUIDX_BITS) {
-        atomic_set(&env_tlb(env)->c.full_flush_count,
+        qemu_atomic_set(&env_tlb(env)->c.full_flush_count,
                    env_tlb(env)->c.full_flush_count + 1);
     } else {
-        atomic_set(&env_tlb(env)->c.part_flush_count,
+        qemu_atomic_set(&env_tlb(env)->c.part_flush_count,
                    env_tlb(env)->c.part_flush_count + ctpop16(to_clean));
         if (to_clean != asked) {
-            atomic_set(&env_tlb(env)->c.elide_flush_count,
+            qemu_atomic_set(&env_tlb(env)->c.elide_flush_count,
                        env_tlb(env)->c.elide_flush_count +
                        ctpop16(asked & ~to_clean));
         }
@@ -693,7 +693,7 @@ void tlb_unprotect_code(ram_addr_t ram_addr)
  * generated code.
  *
  * Other vCPUs might be reading their TLBs during guest execution, so we update
- * te->addr_write with atomic_set. We don't need to worry about this for
+ * te->addr_write with qemu_atomic_set. We don't need to worry about this for
  * oversized guests as MTTCG is disabled for them.
  *
  * Called with tlb_c.lock held.
@@ -711,7 +711,7 @@ static void tlb_reset_dirty_range_locked(CPUTLBEntry *tlb_entry,
 #if TCG_OVERSIZED_GUEST
             tlb_entry->addr_write |= TLB_NOTDIRTY;
 #else
-            atomic_set(&tlb_entry->addr_write,
+            qemu_atomic_set(&tlb_entry->addr_write,
                        tlb_entry->addr_write | TLB_NOTDIRTY);
 #endif
         }
@@ -1138,8 +1138,8 @@ static inline target_ulong tlb_read_ofs(CPUTLBEntry *entry, size_t ofs)
 #if TCG_OVERSIZED_GUEST
     return *(target_ulong *)((uintptr_t)entry + ofs);
 #else
-    /* ofs might correspond to .addr_write, so use atomic_read */
-    return atomic_read((target_ulong *)((uintptr_t)entry + ofs));
+    /* ofs might correspond to .addr_write, so use qemu_atomic_read */
+    return qemu_atomic_read((target_ulong *)((uintptr_t)entry + ofs));
 #endif
 }
 
@@ -1155,11 +1155,11 @@ static bool victim_tlb_hit(CPUArchState *env, size_t mmu_idx, size_t index,
         CPUTLBEntry *vtlb = &env_tlb(env)->d[mmu_idx].vtable[vidx];
         target_ulong cmp;
 
-        /* elt_ofs might correspond to .addr_write, so use atomic_read */
+        /* elt_ofs might correspond to .addr_write, so use qemu_atomic_read */
 #if TCG_OVERSIZED_GUEST
         cmp = *(target_ulong *)((uintptr_t)vtlb + elt_ofs);
 #else
-        cmp = atomic_read((target_ulong *)((uintptr_t)vtlb + elt_ofs));
+        cmp = qemu_atomic_read((target_ulong *)((uintptr_t)vtlb + elt_ofs));
 #endif
 
         if (cmp == page) {
accel/tcg/tcg-all.c +1 -1
index 7098ad96c3..2d2ea21b78 100644
@@ -65,7 +65,7 @@ static void tcg_handle_interrupt(CPUState *cpu, int mask)
     if (!qemu_cpu_is_self(cpu)) {
         qemu_cpu_kick(cpu);
     } else {
-        atomic_set(&cpu_neg(cpu)->icount_decr.u16.high, -1);
+        qemu_atomic_set(&cpu_neg(cpu)->icount_decr.u16.high, -1);
         if (use_icount &&
             !cpu->can_do_io
             && (mask & ~old_mask) != 0) {
accel/tcg/translate-all.c +29 -27

183 lines not on this page · raw message

audio/jackaudio.c +11 -9
index 72ed7c4929..e0e9e005b7 100644
@@ -104,7 +104,7 @@ static void qjack_buffer_create(QJackBuffer *buffer, int channels, int frames)
 static void qjack_buffer_clear(QJackBuffer *buffer)
 {
     assert(buffer->data);
-    atomic_store_release(&buffer->used, 0);
+    qemu_atomic_store_release(&buffer->used, 0);
     buffer->rptr = 0;
     buffer->wptr = 0;
 }
@@ -129,7 +129,8 @@ static int qjack_buffer_write(QJackBuffer *buffer, float *data, int size)
     assert(buffer->data);
     const int samples = size / sizeof(float);
     int frames        = samples / buffer->channels;
-    const int avail   = buffer->frames - atomic_load_acquire(&buffer->used);
+    const int avail   = buffer->frames -
+                        qemu_atomic_load_acquire(&buffer->used);
 
     if (frames > avail) {
         frames = avail;
@@ -153,7 +154,7 @@ static int qjack_buffer_write(QJackBuffer *buffer, float *data, int size)
 
     buffer->wptr = wptr;
 
-    atomic_add(&buffer->used, frames);
+    qemu_atomic_add(&buffer->used, frames);
     return frames * buffer->channels * sizeof(float);
 };
 
@@ -161,7 +162,8 @@ static int qjack_buffer_write(QJackBuffer *buffer, float *data, int size)
 static int qjack_buffer_write_l(QJackBuffer *buffer, float **dest, int frames)
 {
     assert(buffer->data);
-    const int avail   = buffer->frames - atomic_load_acquire(&buffer->used);
+    const int avail   = buffer->frames -
+                        qemu_atomic_load_acquire(&buffer->used);
     int wptr = buffer->wptr;
 
     if (frames > avail) {
@@ -185,7 +187,7 @@ static int qjack_buffer_write_l(QJackBuffer *buffer, float **dest, int frames)
     }
     buffer->wptr = wptr;
 
-    atomic_add(&buffer->used, frames);
+    qemu_atomic_add(&buffer->used, frames);
     return frames;
 }
 
@@ -195,7 +197,7 @@ static int qjack_buffer_read(QJackBuffer *buffer, float *dest, int size)
     assert(buffer->data);
     const int samples = size / sizeof(float);
     int frames        = samples / buffer->channels;
-    const int avail   = atomic_load_acquire(&buffer->used);
+    const int avail   = qemu_atomic_load_acquire(&buffer->used);
 
     if (frames > avail) {
         frames = avail;
@@ -219,7 +221,7 @@ static int qjack_buffer_read(QJackBuffer *buffer, float *dest, int size)
 
     buffer->rptr = rptr;
 
-    atomic_sub(&buffer->used, frames);
+    qemu_atomic_sub(&buffer->used, frames);
     return frames * buffer->channels * sizeof(float);
 }
 
@@ -228,7 +230,7 @@ static int qjack_buffer_read_l(QJackBuffer *buffer, float **dest, int frames)
 {
     assert(buffer->data);
     int copy       = frames;
-    const int used = atomic_load_acquire(&buffer->used);
+    const int used = qemu_atomic_load_acquire(&buffer->used);
     int rptr       = buffer->rptr;
 
     if (copy > used) {
@@ -252,7 +254,7 @@ static int qjack_buffer_read_l(QJackBuffer *buffer, float **dest, int frames)
     }
     buffer->rptr = rptr;
 
-    atomic_sub(&buffer->used, copy);
+    qemu_atomic_sub(&buffer->used, copy);
     return copy;
 }
 
block.c +2 -2
index 9538af4884..54987b3ad5 100644
@@ -1694,7 +1694,7 @@ static int bdrv_open_common(BlockDriverState *bs, BlockBackend *file,
     }
 
     /* bdrv_new() and bdrv_close() make it so */
-    assert(atomic_read(&bs->copy_on_read) == 0);
+    assert(qemu_atomic_read(&bs->copy_on_read) == 0);
 
     if (bs->open_flags & BDRV_O_COPY_ON_READ) {
         if (!bs->read_only) {
@@ -4436,7 +4436,7 @@ static void bdrv_close(BlockDriverState *bs)
     bs->file = NULL;
     g_free(bs->opaque);
     bs->opaque = NULL;
-    atomic_set(&bs->copy_on_read, 0);
+    qemu_atomic_set(&bs->copy_on_read, 0);
     bs->backing_file[0] = '\0';
     bs->backing_format[0] = '\0';
     bs->total_sectors = 0;
block/block-backend.c +8 -7
index 24dd0670d1..05390209a6 100644
@@ -1353,12 +1353,12 @@ int blk_make_zero(BlockBackend *blk, BdrvRequestFlags flags)
 
 void blk_inc_in_flight(BlockBackend *blk)
 {
-    atomic_inc(&blk->in_flight);
+    qemu_atomic_inc(&blk->in_flight);
 }
 
 void blk_dec_in_flight(BlockBackend *blk)
 {
-    atomic_dec(&blk->in_flight);
+    qemu_atomic_dec(&blk->in_flight);
     aio_wait_kick();
 }
 
@@ -1720,7 +1720,7 @@ void blk_drain(BlockBackend *blk)
 
     /* We may have -ENOMEDIUM completions in flight */
     AIO_WAIT_WHILE(blk_get_aio_context(blk),
-                   atomic_mb_read(&blk->in_flight) > 0);
+                   qemu_atomic_mb_read(&blk->in_flight) > 0);
 
     if (bs) {
         bdrv_drained_end(bs);
@@ -1739,7 +1739,7 @@ void blk_drain_all(void)
         aio_context_acquire(ctx);
 
         /* We may have -ENOMEDIUM completions in flight */
-        AIO_WAIT_WHILE(ctx, atomic_mb_read(&blk->in_flight) > 0);
+        AIO_WAIT_WHILE(ctx, qemu_atomic_mb_read(&blk->in_flight) > 0);
 
         aio_context_release(ctx);
     }
@@ -2346,6 +2346,7 @@ void blk_io_limits_update_group(BlockBackend *blk, const char *group)
 static void blk_root_drained_begin(BdrvChild *child)
 {
     BlockBackend *blk = child->opaque;
+    ThrottleGroupMember *tgm = &blk->public.throttle_group_member;
 
     if (++blk->quiesce_counter == 1) {
         if (blk->dev_ops && blk->dev_ops->drained_begin) {
@@ -2356,8 +2357,8 @@ static void blk_root_drained_begin(BdrvChild *child)
     /* Note that blk->root may not be accessible here yet if we are just
      * attaching to a BlockDriverState that is drained. Use child instead. */
 
-    if (atomic_fetch_inc(&blk->public.throttle_group_member.io_limits_disabled) == 0) {
-        throttle_group_restart_tgm(&blk->public.throttle_group_member);
+    if (qemu_atomic_fetch_inc(&tgm->io_limits_disabled) == 0) {
+        throttle_group_restart_tgm(tgm);
     }
 }
 
@@ -2374,7 +2375,7 @@ static void blk_root_drained_end(BdrvChild *child, int *drained_end_counter)
     assert(blk->quiesce_counter);
 
     assert(blk->public.throttle_group_member.io_limits_disabled);
-    atomic_dec(&blk->public.throttle_group_member.io_limits_disabled);
+    qemu_atomic_dec(&blk->public.throttle_group_member.io_limits_disabled);
 
     if (--blk->quiesce_counter == 0) {
         if (blk->dev_ops && blk->dev_ops->drained_end) {
block/io.c +24 -24

185 lines not on this page · raw message

block/nfs.c +1 -1
index 61a249a9fc..d266f93d8c 100644
@@ -721,7 +721,7 @@ nfs_get_allocated_file_size_cb(int ret, struct nfs_context *nfs, void *data,
     }
 
     /* Set task->complete before reading bs->wakeup.  */
-    atomic_mb_set(&task->complete, 1);
+    qemu_atomic_mb_set(&task->complete, 1);
     bdrv_wakeup(task->bs);
 }
 
block/sheepdog.c +1 -1
index cbbebc1aaf..b535830799 100644
@@ -665,7 +665,7 @@ out:
     srco->co = NULL;
     srco->ret = ret;
     /* Set srco->finished before reading bs->wakeup.  */
-    atomic_mb_set(&srco->finished, true);
+    qemu_atomic_mb_set(&srco->finished, true);
     if (srco->bs) {
         bdrv_wakeup(srco->bs);
     }
block/throttle-groups.c +7 -6
index 4e28365d8d..8d84d7cf61 100644
@@ -228,7 +228,7 @@ static ThrottleGroupMember *next_throttle_token(ThrottleGroupMember *tgm,
      * immediately if it has pending requests. Otherwise we could be
      * forcing it to wait for other member's throttled requests. */
     if (tgm_has_pending_reqs(tgm, is_write) &&
-        atomic_read(&tgm->io_limits_disabled)) {
+        qemu_atomic_read(&tgm->io_limits_disabled)) {
         return tgm;
     }
 
@@ -272,7 +272,7 @@ static bool throttle_group_schedule_timer(ThrottleGroupMember *tgm,
     ThrottleTimers *tt = &tgm->throttle_timers;
     bool must_wait;
 
-    if (atomic_read(&tgm->io_limits_disabled)) {
+    if (qemu_atomic_read(&tgm->io_limits_disabled)) {
         return false;
     }
 
@@ -417,7 +417,7 @@ static void coroutine_fn throttle_group_restart_queue_entry(void *opaque)
 
     g_free(data);
 
-    atomic_dec(&tgm->restart_pending);
+    qemu_atomic_dec(&tgm->restart_pending);
     aio_wait_kick();
 }
 
@@ -434,7 +434,7 @@ static void throttle_group_restart_queue(ThrottleGroupMember *tgm, bool is_write
      * be no timer pending on this tgm at this point */
     assert(!timer_pending(tgm->throttle_timers.timers[is_write]));
 
-    atomic_inc(&tgm->restart_pending);
+    qemu_atomic_inc(&tgm->restart_pending);
 
     co = qemu_coroutine_create(throttle_group_restart_queue_entry, rd);
     aio_co_enter(tgm->aio_context, co);
@@ -544,7 +544,7 @@ void throttle_group_register_tgm(ThrottleGroupMember *tgm,
 
     tgm->throttle_state = ts;
     tgm->aio_context = ctx;
-    atomic_set(&tgm->restart_pending, 0);
+    qemu_atomic_set(&tgm->restart_pending, 0);
 
     qemu_mutex_lock(&tg->lock);
     /* If the ThrottleGroup is new set this ThrottleGroupMember as the token */
@@ -592,7 +592,8 @@ void throttle_group_unregister_tgm(ThrottleGroupMember *tgm)
     }
 
     /* Wait for throttle_group_restart_queue_entry() coroutines to finish */
-    AIO_WAIT_WHILE(tgm->aio_context, atomic_read(&tgm->restart_pending) > 0);
+    AIO_WAIT_WHILE(tgm->aio_context,
+                   qemu_atomic_read(&tgm->restart_pending) > 0);
 
     qemu_mutex_lock(&tg->lock);
     for (i = 0; i < 2; i++) {
block/throttle.c +2 -2
index 9a0f38149a..879cde65d7 100644
@@ -217,7 +217,7 @@ static void throttle_reopen_abort(BDRVReopenState *reopen_state)
 static void coroutine_fn throttle_co_drain_begin(BlockDriverState *bs)
 {
     ThrottleGroupMember *tgm = bs->opaque;
-    if (atomic_fetch_inc(&tgm->io_limits_disabled) == 0) {
+    if (qemu_atomic_fetch_inc(&tgm->io_limits_disabled) == 0) {
         throttle_group_restart_tgm(tgm);
     }
 }
@@ -226,7 +226,7 @@ static void coroutine_fn throttle_co_drain_end(BlockDriverState *bs)
 {
     ThrottleGroupMember *tgm = bs->opaque;
     assert(tgm->io_limits_disabled);
-    atomic_dec(&tgm->io_limits_disabled);
+    qemu_atomic_dec(&tgm->io_limits_disabled);
 }
 
 static const char *const throttle_strong_runtime_opts[] = {
blockdev.c +1 -1
index 7f2561081e..6c72ac46f4 100644
@@ -1604,7 +1604,7 @@ static void external_snapshot_commit(BlkActionState *common)
     /* We don't need (or want) to use the transactional
      * bdrv_reopen_multiple() across all the entries at once, because we
      * don't want to abort all of them if one of them fails the reopen */
-    if (!atomic_read(&state->old_bs->copy_on_read)) {
+    if (!qemu_atomic_read(&state->old_bs->copy_on_read)) {
         bdrv_reopen_set_read_only(state->old_bs, true, NULL);
     }
 
blockjob.c +1 -1
index 470facfd47..e21e2ce77c 100644
@@ -298,7 +298,7 @@ BlockJobInfo *block_job_query(BlockJob *job, Error **errp)
     info = g_new0(BlockJobInfo, 1);
     info->type      = g_strdup(job_type_str(&job->job));
     info->device    = g_strdup(job->job.id);
-    info->busy      = atomic_read(&job->job.busy);
+    info->busy      = qemu_atomic_read(&job->job.busy);
     info->paused    = job->job.pause_count > 0;
     info->offset    = job->job.progress.current;
     info->len       = job->job.progress.total;
contrib/libvhost-user/libvhost-user.c +1 -1
index 53f16bdf08..8d9623bcbc 100644
@@ -448,7 +448,7 @@ static void
 vu_log_page(uint8_t *log_table, uint64_t page)
 {
     DPRINT("Logged dirty guest page: %"PRId64"\n", page);
-    atomic_or(&log_table[page / 8], 1 << (page % 8));
+    qemu_atomic_or(&log_table[page / 8], 1 << (page % 8));
 }
 
 static void
cpus-common.c +13 -13
index 34044f4e4c..6a6b82de52 100644
@@ -148,7 +148,7 @@ void do_run_on_cpu(CPUState *cpu, run_on_cpu_func func, run_on_cpu_data data,
     wi.exclusive = false;
 
     queue_work_on_cpu(cpu, &wi);
-    while (!atomic_mb_read(&wi.done)) {
+    while (!qemu_atomic_mb_read(&wi.done)) {
         CPUState *self_cpu = current_cpu;
 
         qemu_cond_wait(&qemu_work_cond, mutex);
@@ -188,20 +188,20 @@ void start_exclusive(void)
     exclusive_idle();
 
     /* Make all other cpus stop executing.  */
-    atomic_set(&pending_cpus, 1);
+    qemu_atomic_set(&pending_cpus, 1);
 
     /* Write pending_cpus before reading other_cpu->running.  */
     smp_mb();
     running_cpus = 0;
     CPU_FOREACH(other_cpu) {
-        if (atomic_read(&other_cpu->running)) {
+        if (qemu_atomic_read(&other_cpu->running)) {
             other_cpu->has_waiter = true;
             running_cpus++;
             qemu_cpu_kick(other_cpu);
         }
     }
 
-    atomic_set(&pending_cpus, running_cpus + 1);
+    qemu_atomic_set(&pending_cpus, running_cpus + 1);
     while (pending_cpus > 1) {
         qemu_cond_wait(&exclusive_cond, &qemu_cpu_list_lock);
     }
@@ -220,7 +220,7 @@ void end_exclusive(void)
     current_cpu->in_exclusive_context = false;
 
     qemu_mutex_lock(&qemu_cpu_list_lock);
-    atomic_set(&pending_cpus, 0);
+    qemu_atomic_set(&pending_cpus, 0);
     qemu_cond_broadcast(&exclusive_resume);
     qemu_mutex_unlock(&qemu_cpu_list_lock);
 }
@@ -228,7 +228,7 @@ void end_exclusive(void)
 /* Wait for exclusive ops to finish, and begin cpu execution.  */
 void cpu_exec_start(CPUState *cpu)
 {
-    atomic_set(&cpu->running, true);
+    qemu_atomic_set(&cpu->running, true);
 
     /* Write cpu->running before reading pending_cpus.  */
     smp_mb();
@@ -246,17 +246,17 @@ void cpu_exec_start(CPUState *cpu)
      * 3. pending_cpus == 0.  Then start_exclusive is definitely going to
      * see cpu->running == true, and it will kick the CPU.
      */
-    if (unlikely(atomic_read(&pending_cpus))) {
+    if (unlikely(qemu_atomic_read(&pending_cpus))) {
         QEMU_LOCK_GUARD(&qemu_cpu_list_lock);
         if (!cpu->has_waiter) {
             /* Not counted in pending_cpus, let the exclusive item
              * run.  Since we have the lock, just set cpu->running to true
              * while holding it; no need to check pending_cpus again.
              */
-            atomic_set(&cpu->running, false);
+            qemu_atomic_set(&cpu->running, false);
             exclusive_idle();
             /* Now pending_cpus is zero.  */
-            atomic_set(&cpu->running, true);
+            qemu_atomic_set(&cpu->running, true);
         } else {
             /* Counted in pending_cpus, go ahead and release the
              * waiter at cpu_exec_end.
@@ -268,7 +268,7 @@ void cpu_exec_start(CPUState *cpu)
 /* Mark cpu as not executing, and release pending exclusive ops.  */
 void cpu_exec_end(CPUState *cpu)
 {
-    atomic_set(&cpu->running, false);
+    qemu_atomic_set(&cpu->running, false);
 
     /* Write cpu->running before reading pending_cpus.  */
     smp_mb();
@@ -288,11 +288,11 @@ void cpu_exec_end(CPUState *cpu)
      * see cpu->running == false, and it can ignore this CPU until the
      * next cpu_exec_start.
      */
-    if (unlikely(atomic_read(&pending_cpus))) {
+    if (unlikely(qemu_atomic_read(&pending_cpus))) {
         QEMU_LOCK_GUARD(&qemu_cpu_list_lock);
         if (cpu->has_waiter) {
             cpu->has_waiter = false;
-            atomic_set(&pending_cpus, pending_cpus - 1);
+            qemu_atomic_set(&pending_cpus, pending_cpus - 1);
             if (pending_cpus == 1) {
                 qemu_cond_signal(&exclusive_cond);
             }
@@ -346,7 +346,7 @@ void process_queued_cpu_work(CPUState *cpu)
         if (wi->free) {
             g_free(wi);
         } else {
-            atomic_mb_set(&wi->done, true);
+            qemu_atomic_mb_set(&wi->done, true);
         }
     }
     qemu_mutex_unlock(&cpu->work_mutex);
dump/dump.c +4 -4
index 13fda440a4..1b2fbb6442 100644
@@ -1572,7 +1572,7 @@ static void dump_state_prepare(DumpState *s)
 bool dump_in_progress(void)
 {
     DumpState *state = &dump_state_global;
-    return (atomic_read(&state->status) == DUMP_STATUS_ACTIVE);
+    return (qemu_atomic_read(&state->status) == DUMP_STATUS_ACTIVE);
 }
 
 /* calculate total size of memory to be dumped (taking filter into
@@ -1882,7 +1882,7 @@ static void dump_process(DumpState *s, Error **errp)
 
     /* make sure status is written after written_size updates */
     smp_wmb();
-    atomic_set(&s->status,
+    qemu_atomic_set(&s->status,
                (local_err ? DUMP_STATUS_FAILED : DUMP_STATUS_COMPLETED));
 
     /* send DUMP_COMPLETED message (unconditionally) */
@@ -1908,7 +1908,7 @@ DumpQueryResult *qmp_query_dump(Error **errp)
 {
     DumpQueryResult *result = g_new(DumpQueryResult, 1);
     DumpState *state = &dump_state_global;
-    result->status = atomic_read(&state->status);
+    result->status = qemu_atomic_read(&state->status);
     /* make sure we are reading status and written_size in order */
     smp_rmb();
     result->completed = state->written_size;
@@ -2013,7 +2013,7 @@ void qmp_dump_guest_memory(bool paging, const char *file,
               begin, length, &local_err);
     if (local_err) {
         error_propagate(errp, local_err);
-        atomic_set(&s->status, DUMP_STATUS_FAILED);
+        qemu_atomic_set(&s->status, DUMP_STATUS_FAILED);
         return;
     }
 
exec.c +26 -23

173 lines not on this page · raw message

hw/core/cpu.c +3 -3
index 8f65383ffb..dda45764f5 100644
@@ -111,10 +111,10 @@ void cpu_reset_interrupt(CPUState *cpu, int mask)
 
 void cpu_exit(CPUState *cpu)
 {
-    atomic_set(&cpu->exit_request, 1);
+    qemu_atomic_set(&cpu->exit_request, 1);
     /* Ensure cpu_exec will see the exit request after TCG has exited.  */
     smp_wmb();
-    atomic_set(&cpu->icount_decr_ptr->u16.high, -1);
+    qemu_atomic_set(&cpu->icount_decr_ptr->u16.high, -1);
 }
 
 int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
@@ -261,7 +261,7 @@ static void cpu_common_reset(DeviceState *dev)
     cpu->halted = cpu->start_powered_off;
     cpu->mem_io_pc = 0;
     cpu->icount_extra = 0;
-    atomic_set(&cpu->icount_decr_ptr->u32, 0);
+    qemu_atomic_set(&cpu->icount_decr_ptr->u32, 0);
     cpu->can_do_io = 1;
     cpu->exception_index = -1;
     cpu->crash_occurred = false;
hw/display/qxl.c +4 -3
index 11871340e7..0a33027685 100644
@@ -1908,7 +1908,7 @@ static void qxl_send_events(PCIQXLDevice *d, uint32_t events)
     /*
      * Older versions of Spice forgot to define the QXLRam struct
      * with the '__aligned__(4)' attribute. clang 7 and newer will
-     * thus warn that atomic_fetch_or(&d->ram->int_pending, ...)
+     * thus warn that qemu_atomic_fetch_or(&d->ram->int_pending, ...)
      * might be a misaligned atomic access, and will generate an
      * out-of-line call for it, which results in a link error since
      * we don't currently link against libatomic.
@@ -1928,8 +1928,9 @@ static void qxl_send_events(PCIQXLDevice *d, uint32_t events)
 #define ALIGNED_UINT32_PTR(P) ((uint32_t *)P)
 #endif
 
-    old_pending = atomic_fetch_or(ALIGNED_UINT32_PTR(&d->ram->int_pending),
-                                  le_events);
+    old_pending =
+        qemu_atomic_fetch_or(ALIGNED_UINT32_PTR(&d->ram->int_pending),
+                             le_events);
     if ((old_pending & le_events) == le_events) {
         return;
     }
hw/hyperv/hyperv.c +6 -5
index aa5a2a9bd8..a832b85ad0 100644
@@ -233,7 +233,7 @@ static void sint_msg_bh(void *opaque)
     HvSintRoute *sint_route = opaque;
     HvSintStagedMessage *staged_msg = sint_route->staged_msg;
 
-    if (atomic_read(&staged_msg->state) != HV_STAGED_MSG_POSTED) {
+    if (qemu_atomic_read(&staged_msg->state) != HV_STAGED_MSG_POSTED) {
         /* status nor ready yet (spurious ack from guest?), ignore */
         return;
     }
@@ -242,7 +242,7 @@ static void sint_msg_bh(void *opaque)
     staged_msg->status = 0;
 
     /* staged message processing finished, ready to start over */
-    atomic_set(&staged_msg->state, HV_STAGED_MSG_FREE);
+    qemu_atomic_set(&staged_msg->state, HV_STAGED_MSG_FREE);
     /* drop the reference taken in hyperv_post_msg */
     hyperv_sint_route_unref(sint_route);
 }
@@ -280,7 +280,7 @@ static void cpu_post_msg(CPUState *cs, run_on_cpu_data data)
     memory_region_set_dirty(&synic->msg_page_mr, 0, sizeof(*synic->msg_page));
 
 posted:
-    atomic_set(&staged_msg->state, HV_STAGED_MSG_POSTED);
+    qemu_atomic_set(&staged_msg->state, HV_STAGED_MSG_POSTED);
     /*
      * Notify the msg originator of the progress made; if the slot was busy we
      * set msg_pending flag in it so it will be the guest who will do EOM and
@@ -303,7 +303,7 @@ int hyperv_post_msg(HvSintRoute *sint_route, struct hyperv_message *src_msg)
     assert(staged_msg);
 
     /* grab the staging area */
-    if (atomic_cmpxchg(&staged_msg->state, HV_STAGED_MSG_FREE,
+    if (qemu_atomic_cmpxchg(&staged_msg->state, HV_STAGED_MSG_FREE,
                        HV_STAGED_MSG_BUSY) != HV_STAGED_MSG_FREE) {
         return -EAGAIN;
     }
@@ -353,7 +353,8 @@ int hyperv_set_event_flag(HvSintRoute *sint_route, unsigned eventno)
     set_mask = BIT_MASK(eventno);
     flags = synic->event_page->slot[sint_route->sint].flags;
 
-    if ((atomic_fetch_or(&flags[set_idx], set_mask) & set_mask) != set_mask) {
+    if ((qemu_atomic_fetch_or(&flags[set_idx], set_mask) & set_mask) !=
+            set_mask) {
         memory_region_set_dirty(&synic->event_page_mr, 0,
                                 sizeof(*synic->event_page));
         ret = hyperv_sint_route_set_sint(sint_route);
hw/hyperv/vmbus.c +1 -1
index 6ef895bc35..c5ad261600 100644
@@ -747,7 +747,7 @@ static int vmbus_channel_notify_guest(VMBusChannel *chan)
 
     idx = BIT_WORD(chan->id);
     mask = BIT_MASK(chan->id);
-    if ((atomic_fetch_or(&int_map[idx], mask) & mask) != mask) {
+    if ((qemu_atomic_fetch_or(&int_map[idx], mask) & mask) != mask) {
         res = hyperv_sint_route_set_sint(chan->notify_route);
         dirty = len;
     }
hw/i386/xen/xen-hvm.c +1 -1
index cde981bad6..ca6b3e2408 100644
@@ -1140,7 +1140,7 @@ static int handle_buffered_iopage(XenIOState *state)
         assert(req.dir == IOREQ_WRITE);
         assert(!req.data_is_ptr);
 
-        atomic_add(&buf_page->read_pointer, qw + 1);
+        qemu_atomic_add(&buf_page->read_pointer, qw + 1);
     }
 
     return req.count;
hw/intc/rx_icu.c +6 -6
index df4b6a8d22..4220120739 100644
@@ -81,8 +81,8 @@ static void rxicu_request(RXICUState *icu, int n_IRQ)
     int enable;
 
     enable = icu->ier[n_IRQ / 8] & (1 << (n_IRQ & 7));
-    if (n_IRQ > 0 && enable != 0 && atomic_read(&icu->req_irq) < 0) {
-        atomic_set(&icu->req_irq, n_IRQ);
+    if (n_IRQ > 0 && enable != 0 && qemu_atomic_read(&icu->req_irq) < 0) {
+        qemu_atomic_set(&icu->req_irq, n_IRQ);
         set_irq(icu, n_IRQ, rxicu_level(icu, n_IRQ));
     }
 }
@@ -124,10 +124,10 @@ static void rxicu_set_irq(void *opaque, int n_IRQ, int level)
     }
     if (issue == 0 && src->sense == TRG_LEVEL) {
         icu->ir[n_IRQ] = 0;
-        if (atomic_read(&icu->req_irq) == n_IRQ) {
+        if (qemu_atomic_read(&icu->req_irq) == n_IRQ) {
             /* clear request */
             set_irq(icu, n_IRQ, 0);
-            atomic_set(&icu->req_irq, -1);
+            qemu_atomic_set(&icu->req_irq, -1);
         }
         return;
     }
@@ -144,11 +144,11 @@ static void rxicu_ack_irq(void *opaque, int no, int level)
     int n_IRQ;
     int max_pri;
 
-    n_IRQ = atomic_read(&icu->req_irq);
+    n_IRQ = qemu_atomic_read(&icu->req_irq);
     if (n_IRQ < 0) {
         return;
     }
-    atomic_set(&icu->req_irq, -1);
+    qemu_atomic_set(&icu->req_irq, -1);
     if (icu->src[n_IRQ].sense != TRG_LEVEL) {
         icu->ir[n_IRQ] = 0;
     }
hw/intc/sifive_plic.c +2 -2
index af611f8db8..4b9e401b79 100644
@@ -89,12 +89,12 @@ static void sifive_plic_print_state(SiFivePLICState *plic)
 
 static uint32_t atomic_set_masked(uint32_t *a, uint32_t mask, uint32_t value)
 {
-    uint32_t old, new, cmp = atomic_read(a);
+    uint32_t old, new, cmp = qemu_atomic_read(a);
 
     do {
         old = cmp;
         new = (old & ~mask) | (value & mask);
-        cmp = atomic_cmpxchg(a, old, new);
+        cmp = qemu_atomic_cmpxchg(a, old, new);
     } while (old != cmp);
 
     return old;
hw/misc/edu.c +8 -8
index 0ff9d1ac78..c2196dafb5 100644
@@ -212,7 +212,7 @@ static uint64_t edu_mmio_read(void *opaque, hwaddr addr, unsigned size)
         qemu_mutex_unlock(&edu->thr_mutex);
         break;
     case 0x20:
-        val = atomic_read(&edu->status);
+        val = qemu_atomic_read(&edu->status);
         break;
     case 0x24:
         val = edu->irq_status;
@@ -252,7 +252,7 @@ static void edu_mmio_write(void *opaque, hwaddr addr, uint64_t val,
         edu->addr4 = ~val;
         break;
     case 0x08:
-        if (atomic_read(&edu->status) & EDU_STATUS_COMPUTING) {
+        if (qemu_atomic_read(&edu->status) & EDU_STATUS_COMPUTING) {
             break;
         }
         /* EDU_STATUS_COMPUTING cannot go 0->1 concurrently, because it is only
@@ -260,15 +260,15 @@ static void edu_mmio_write(void *opaque, hwaddr addr, uint64_t val,
          */
         qemu_mutex_lock(&edu->thr_mutex);
         edu->fact = val;
-        atomic_or(&edu->status, EDU_STATUS_COMPUTING);
+        qemu_atomic_or(&edu->status, EDU_STATUS_COMPUTING);
         qemu_cond_signal(&edu->thr_cond);
         qemu_mutex_unlock(&edu->thr_mutex);
         break;
     case 0x20:
         if (val & EDU_STATUS_IRQFACT) {
-            atomic_or(&edu->status, EDU_STATUS_IRQFACT);
+            qemu_atomic_or(&edu->status, EDU_STATUS_IRQFACT);
         } else {
-            atomic_and(&edu->status, ~EDU_STATUS_IRQFACT);
+            qemu_atomic_and(&edu->status, ~EDU_STATUS_IRQFACT);
         }
         break;
     case 0x60:
@@ -322,7 +322,7 @@ static void *edu_fact_thread(void *opaque)
         uint32_t val, ret = 1;
 
         qemu_mutex_lock(&edu->thr_mutex);
-        while ((atomic_read(&edu->status) & EDU_STATUS_COMPUTING) == 0 &&
+        while ((qemu_atomic_read(&edu->status) & EDU_STATUS_COMPUTING) == 0 &&
                         !edu->stopping) {
             qemu_cond_wait(&edu->thr_cond, &edu->thr_mutex);
         }
@@ -347,9 +347,9 @@ static void *edu_fact_thread(void *opaque)
         qemu_mutex_lock(&edu->thr_mutex);
         edu->fact = ret;
         qemu_mutex_unlock(&edu->thr_mutex);
-        atomic_and(&edu->status, ~EDU_STATUS_COMPUTING);
+        qemu_atomic_and(&edu->status, ~EDU_STATUS_COMPUTING);
 
-        if (atomic_read(&edu->status) & EDU_STATUS_IRQFACT) {
+        if (qemu_atomic_read(&edu->status) & EDU_STATUS_IRQFACT) {
             qemu_mutex_lock_iothread();
             edu_raise_irq(edu, FACT_IRQ);
             qemu_mutex_unlock_iothread();
hw/net/virtio-net.c +5 -5
index cb0d27084c..0c9c253367 100644
@@ -933,7 +933,7 @@ static void virtio_net_set_features(VirtIODevice *vdev, uint64_t features)
 
     if (virtio_has_feature(features, VIRTIO_NET_F_STANDBY)) {
         qapi_event_send_failover_negotiated(n->netclient_name);
-        atomic_set(&n->primary_should_be_hidden, false);
+        qemu_atomic_set(&n->primary_should_be_hidden, false);
         failover_add_primary(n, &err);
         if (err) {
             n->primary_dev = virtio_connect_failover_devices(n, n->qdev, &err);
@@ -3168,7 +3168,7 @@ static void virtio_net_handle_migration_primary(VirtIONet *n,
     bool should_be_hidden;
     Error *err = NULL;
 
-    should_be_hidden = atomic_read(&n->primary_should_be_hidden);
+    should_be_hidden = qemu_atomic_read(&n->primary_should_be_hidden);
 
     if (!n->primary_dev) {
         n->primary_dev = virtio_connect_failover_devices(n, n->qdev, &err);
@@ -3183,7 +3183,7 @@ static void virtio_net_handle_migration_primary(VirtIONet *n,
                     qdev_get_vmsd(n->primary_dev),
                     n->primary_dev);
             qapi_event_send_unplug_primary(n->primary_device_id);
-            atomic_set(&n->primary_should_be_hidden, true);
+            qemu_atomic_set(&n->primary_should_be_hidden, true);
         } else {
             warn_report("couldn't unplug primary device");
         }
@@ -3234,7 +3234,7 @@ static int virtio_net_primary_should_be_hidden(DeviceListener *listener,
     n->primary_device_opts = device_opts;
 
     /* primary_should_be_hidden is set during feature negotiation */
-    hide = atomic_read(&n->primary_should_be_hidden);
+    hide = qemu_atomic_read(&n->primary_should_be_hidden);
 
     if (n->primary_device_dict) {
         g_free(n->primary_device_id);
@@ -3291,7 +3291,7 @@ static void virtio_net_device_realize(DeviceState *dev, Error **errp)
     if (n->failover) {
         n->primary_listener.should_be_hidden =
             virtio_net_primary_should_be_hidden;
-        atomic_set(&n->primary_should_be_hidden, true);
+        qemu_atomic_set(&n->primary_should_be_hidden, true);
         device_listener_register(&n->primary_listener);
         n->migration_state.notify = virtio_net_migration_state_notifier;
         add_migration_state_change_notifier(&n->migration_state);
hw/rdma/rdma_backend.c +10 -9
index db7e5c8be5..886ce8758e 100644
@@ -68,7 +68,7 @@ static void free_cqe_ctx(gpointer data, gpointer user_data)
     bctx = rdma_rm_get_cqe_ctx(rdma_dev_res, cqe_ctx_id);
     if (bctx) {
         rdma_rm_dealloc_cqe_ctx(rdma_dev_res, cqe_ctx_id);
-        atomic_dec(&rdma_dev_res->stats.missing_cqe);
+        qemu_atomic_dec(&rdma_dev_res->stats.missing_cqe);
     }
     g_free(bctx);
 }
@@ -81,7 +81,7 @@ static void clean_recv_mads(RdmaBackendDev *backend_dev)
         cqe_ctx_id = rdma_protected_qlist_pop_int64(&backend_dev->
                                                     recv_mads_list);
         if (cqe_ctx_id != -ENOENT) {
-            atomic_inc(&backend_dev->rdma_dev_res->stats.missing_cqe);
+            qemu_atomic_inc(&backend_dev->rdma_dev_res->stats.missing_cqe);
             free_cqe_ctx(GINT_TO_POINTER(cqe_ctx_id),
                          backend_dev->rdma_dev_res);
         }
@@ -123,7 +123,7 @@ static int rdma_poll_cq(RdmaDeviceResources *rdma_dev_res, struct ibv_cq *ibcq)
             }
             total_ne += ne;
         } while (ne > 0);
-        atomic_sub(&rdma_dev_res->stats.missing_cqe, total_ne);
+        qemu_atomic_sub(&rdma_dev_res->stats.missing_cqe, total_ne);
     }
 
     if (ne < 0) {
@@ -195,17 +195,18 @@ static void *comp_handler_thread(void *arg)
 
 static inline void disable_rdmacm_mux_async(RdmaBackendDev *backend_dev)
 {
-    atomic_set(&backend_dev->rdmacm_mux.can_receive, 0);
+    qemu_atomic_set(&backend_dev->rdmacm_mux.can_receive, 0);
 }
 
 static inline void enable_rdmacm_mux_async(RdmaBackendDev *backend_dev)
 {
-    atomic_set(&backend_dev->rdmacm_mux.can_receive, sizeof(RdmaCmMuxMsg));
+    qemu_atomic_set(&backend_dev->rdmacm_mux.can_receive,
+                    sizeof(RdmaCmMuxMsg));
 }
 
 static inline int rdmacm_mux_can_process_async(RdmaBackendDev *backend_dev)
 {
-    return atomic_read(&backend_dev->rdmacm_mux.can_receive);
+    return qemu_atomic_read(&backend_dev->rdmacm_mux.can_receive);
 }
 
 static int rdmacm_mux_check_op_status(CharBackend *mad_chr_be)
@@ -555,7 +556,7 @@ void rdma_backend_post_send(RdmaBackendDev *backend_dev,
         goto err_dealloc_cqe_ctx;
     }
 
-    atomic_inc(&backend_dev->rdma_dev_res->stats.missing_cqe);
+    qemu_atomic_inc(&backend_dev->rdma_dev_res->stats.missing_cqe);
     backend_dev->rdma_dev_res->stats.tx++;
 
     return;
@@ -658,7 +659,7 @@ void rdma_backend_post_recv(RdmaBackendDev *backend_dev,
         goto err_dealloc_cqe_ctx;
     }
 
-    atomic_inc(&backend_dev->rdma_dev_res->stats.missing_cqe);
+    qemu_atomic_inc(&backend_dev->rdma_dev_res->stats.missing_cqe);
     backend_dev->rdma_dev_res->stats.rx_bufs++;
 
     return;
@@ -710,7 +711,7 @@ void rdma_backend_post_srq_recv(RdmaBackendDev *backend_dev,
         goto err_dealloc_cqe_ctx;
     }
 
-    atomic_inc(&backend_dev->rdma_dev_res->stats.missing_cqe);
+    qemu_atomic_inc(&backend_dev->rdma_dev_res->stats.missing_cqe);
     backend_dev->rdma_dev_res->stats.rx_bufs++;
     backend_dev->rdma_dev_res->stats.rx_srq++;
 
hw/rdma/rdma_rm.c +1 -1
index 60957f88db..d6955d1d1b 100644
@@ -790,7 +790,7 @@ int rdma_rm_init(RdmaDeviceResources *dev_res, struct ibv_device_attr *dev_attr)
     qemu_mutex_init(&dev_res->lock);
 
     memset(&dev_res->stats, 0, sizeof(dev_res->stats));
-    atomic_set(&dev_res->stats.missing_cqe, 0);
+    qemu_atomic_set(&dev_res->stats.missing_cqe, 0);
 
     return 0;
 }
hw/rdma/vmw/pvrdma_dev_ring.c +2 -2
index c122fe7035..43c7dfbd52 100644
@@ -38,8 +38,8 @@ int pvrdma_ring_init(PvrdmaRing *ring, const char *name, PCIDevice *dev,
     ring->max_elems = max_elems;
     ring->elem_sz = elem_sz;
     /* TODO: Give a moment to think if we want to redo driver settings
-    atomic_set(&ring->ring_state->prod_tail, 0);
-    atomic_set(&ring->ring_state->cons_head, 0);
+    qemu_atomic_set(&ring->ring_state->prod_tail, 0);
+    qemu_atomic_set(&ring->ring_state->cons_head, 0);
     */
     ring->npages = npages;
     ring->pages = g_malloc(npages * sizeof(void *));
hw/s390x/s390-pci-bus.c +1 -1
index 92146a2119..84e40b4395 100644
@@ -650,7 +650,7 @@ static uint8_t set_ind_atomic(uint64_t ind_loc, uint8_t to_be_set)
     actual = *ind_addr;
     do {
         expected = actual;
-        actual = atomic_cmpxchg(ind_addr, expected, expected | to_be_set);
+        actual = qemu_atomic_cmpxchg(ind_addr, expected, expected | to_be_set);
     } while (actual != expected);
     cpu_physical_memory_unmap((void *)ind_addr, len, 1, len);
 
hw/s390x/virtio-ccw.c +1 -1
index 8feb3451a0..8aef2cc8a1 100644
@@ -800,7 +800,7 @@ static uint8_t virtio_set_ind_atomic(SubchDev *sch, uint64_t ind_loc,
     actual = *ind_addr;
     do {
         expected = actual;
-        actual = atomic_cmpxchg(ind_addr, expected, expected | to_be_set);
+        actual = qemu_atomic_cmpxchg(ind_addr, expected, expected | to_be_set);
     } while (actual != expected);
     trace_virtio_ccw_set_ind(ind_loc, actual, actual | to_be_set);
     cpu_physical_memory_unmap((void *)ind_addr, len, 1, len);
hw/virtio/vhost.c +1 -1
index 1a1384e7a6..ea13a90891 100644
@@ -90,7 +90,7 @@ static void vhost_dev_sync_region(struct vhost_dev *dev,
         }
         /* Data must be read atomically. We don't really need barrier semantics
          * but it's easier to use atomic_* than roll our own. */
-        log = atomic_xchg(from, 0);
+        log = qemu_atomic_xchg(from, 0);
         while (log) {
             int bit = ctzl(log);
             hwaddr page_addr;
hw/virtio/virtio-mmio.c +3 -3
index f12d1595aa..d0117a0b6f 100644
@@ -179,7 +179,7 @@ static uint64_t virtio_mmio_read(void *opaque, hwaddr offset, unsigned size)
         }
         return proxy->vqs[vdev->queue_sel].enabled;
     case VIRTIO_MMIO_INTERRUPT_STATUS:
-        return atomic_read(&vdev->isr);
+        return qemu_atomic_read(&vdev->isr);
     case VIRTIO_MMIO_STATUS:
         return vdev->status;
     case VIRTIO_MMIO_CONFIG_GENERATION:
@@ -370,7 +370,7 @@ static void virtio_mmio_write(void *opaque, hwaddr offset, uint64_t value,
         }
         break;
     case VIRTIO_MMIO_INTERRUPT_ACK:
-        atomic_and(&vdev->isr, ~value);
+        qemu_atomic_and(&vdev->isr, ~value);
         virtio_update_irq(vdev);
         break;
     case VIRTIO_MMIO_STATUS:
@@ -496,7 +496,7 @@ static void virtio_mmio_update_irq(DeviceState *opaque, uint16_t vector)
     if (!vdev) {
         return;
     }
-    level = (atomic_read(&vdev->isr) != 0);
+    level = (qemu_atomic_read(&vdev->isr) != 0);
     trace_virtio_mmio_setting_irq(level);
     qemu_set_irq(proxy->irq, level);
 }
hw/virtio/virtio-pci.c +3 -3
index 5bc769f685..8dd6a00ee5 100644
@@ -72,7 +72,7 @@ static void virtio_pci_notify(DeviceState *d, uint16_t vector)
         msix_notify(&proxy->pci_dev, vector);
     else {
         VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus);
-        pci_set_irq(&proxy->pci_dev, atomic_read(&vdev->isr) & 1);
+        pci_set_irq(&proxy->pci_dev, qemu_atomic_read(&vdev->isr) & 1);
     }
 }
 
@@ -398,7 +398,7 @@ static uint32_t virtio_ioport_read(VirtIOPCIProxy *proxy, uint32_t addr)
         break;
     case VIRTIO_PCI_ISR:
         /* reading from the ISR also clears it. */
-        ret = atomic_xchg(&vdev->isr, 0);
+        ret = qemu_atomic_xchg(&vdev->isr, 0);
         pci_irq_deassert(&proxy->pci_dev);
         break;
     case VIRTIO_MSI_CONFIG_VECTOR:
@@ -1362,7 +1362,7 @@ static uint64_t virtio_pci_isr_read(void *opaque, hwaddr addr,
 {
     VirtIOPCIProxy *proxy = opaque;
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

hw/virtio/virtio.c +8 -8
index e983025217..08f3c1cdd7 100644

Lines of this file are not shown. View the raw message.

hw/xtensa/pic_cpu.c +2 -2
index 1d5982a9e4..2d28392b7a 100644

Lines of this file are not shown. View the raw message.

iothread.c +3 -3
index 3a3860a09c..54e2d30c3d 100644

Lines of this file are not shown. View the raw message.

linux-user/hppa/cpu_loop.c +6 -5
index 9915456a1d..7ef313c325 100644

Lines of this file are not shown. View the raw message.

linux-user/signal.c +4 -4
index 8cf51ffecd..ac4eee73f0 100644

Lines of this file are not shown. View the raw message.

migration/colo-failover.c +2 -2
index e9ca0b4774..b961d251fa 100644

Lines of this file are not shown. View the raw message.

migration/migration.c +4 -4
index 58a5452471..044e7c1fe7 100644

Lines of this file are not shown. View the raw message.

migration/multifd.c +9 -9
index d0441202aa..94c9679262 100644

Lines of this file are not shown. View the raw message.

migration/postcopy-ram.c +18 -17
index 1bb22f2b6c..08ca265d5a 100644

Lines of this file are not shown. View the raw message.

migration/rdma.c +17 -17
index 1dc563ec3f..c4a380348d 100644

Lines of this file are not shown. View the raw message.

monitor/hmp.c +3 -3
index d598dd02bb..a42653e573 100644

Lines of this file are not shown. View the raw message.

monitor/misc.c +1 -1
index 0b1b9b196c..c052b06f12 100644

Lines of this file are not shown. View the raw message.

monitor/monitor.c +3 -3
index b385a3d569..71fa9bea6e 100644

Lines of this file are not shown. View the raw message.

qemu-nbd.c +1 -1
index 33476a1000..b63a75c3f8 100644

Lines of this file are not shown. View the raw message.

qga/commands.c +6 -6
index d3fec807c1..83f3a54d15 100644

Lines of this file are not shown. View the raw message.

qom/object.c +10 -10
index 387efb25eb..36c1ff14c8 100644

Lines of this file are not shown. View the raw message.

scsi/qemu-pr-helper.c +2 -2
index 57ad830d54..95ebe892ff 100644

Lines of this file are not shown. View the raw message.

softmmu/cpu-throttle.c +5 -5
index 4e6b2818ca..7b7dbcc9dc 100644

Lines of this file are not shown. View the raw message.

softmmu/cpus.c +21 -21

42 lines not on this page · raw message

softmmu/memory.c +3 -3
index d030eb6f7c..cabbd4ea3a 100644

Lines of this file are not shown. View the raw message.

softmmu/vl.c +1 -1
index f7b103467c..36ac55cb91 100644

Lines of this file are not shown. View the raw message.

target/arm/mte_helper.c +3 -3
index 891306f5b0..e1adf5ae33 100644

Lines of this file are not shown. View the raw message.

target/hppa/op_helper.c +1 -1
index 5685e303ab..ba33cba27c 100644

Lines of this file are not shown. View the raw message.

target/i386/mem_helper.c +1 -1
index acf41f8885..da7b4d6d67 100644

Lines of this file are not shown. View the raw message.

target/i386/whpx-all.c +3 -3
index c78baac6df..57d56d3831 100644

Lines of this file are not shown. View the raw message.

target/riscv/cpu_helper.c +1 -1
index f4c4111536..41779e3068 100644

Lines of this file are not shown. View the raw message.

target/s390x/mem_helper.c +2 -2
index a237dec757..26d97dd0c5 100644

Lines of this file are not shown. View the raw message.

target/xtensa/exc_helper.c +2 -2
index 58a64e6d62..dd3f8226b9 100644

Lines of this file are not shown. View the raw message.

target/xtensa/op_helper.c +1 -1
index 09f4962d00..8b2b26c622 100644

Lines of this file are not shown. View the raw message.

tcg/tcg.c +30 -29

59 lines not on this page · raw message

tcg/tci.c +1 -1
index 46fe9ce63f..e0fed902b2 100644

Lines of this file are not shown. View the raw message.

tests/atomic64-bench.c +7 -7
index 121a8c14f4..6f56ae2ec5 100644

Lines of this file are not shown. View the raw message.

tests/atomic_add-bench.c +7 -7
index 5666f6bbff..8d095b8988 100644

Lines of this file are not shown. View the raw message.

tests/iothread.c +1 -1
index d3a2ee9a01..6d86d7ca24 100644

Lines of this file are not shown. View the raw message.

tests/qht-bench.c +6 -6
index 362f03cb03..cf2990b353 100644

Lines of this file are not shown. View the raw message.

tests/rcutorture.c +12 -12
index 732f03abda..78148140d7 100644

Lines of this file are not shown. View the raw message.

tests/test-aio-multithread.c +26 -26

52 lines not on this page · raw message

tests/test-logging.c +2 -2
index 8b1522cfed..32d4a270ac 100644

Lines of this file are not shown. View the raw message.

tests/test-rcu-list.c +20 -18
index 92be51ec50..d014e3f21b 100644

Lines of this file are not shown. View the raw message.

tests/test-thread-pool.c +5 -5
index 0b675923f6..0e53e867d9 100644

Lines of this file are not shown. View the raw message.

util/aio-posix.c +8 -7
index f7f13ebfc2..777eae4d1d 100644

Lines of this file are not shown. View the raw message.

util/aio-wait.c +1 -1
index b4877493f8..1aea6e7fa0 100644

Lines of this file are not shown. View the raw message.

util/aio-win32.c +4 -2
index 49bd90e62e..cfa81c6217 100644

Lines of this file are not shown. View the raw message.

util/async.c +19 -18
index 4266745dee..9341aacdcd 100644

Lines of this file are not shown. View the raw message.

util/atomic64.c +5 -5
index b198a6c9c8..87e59bbac0 100644

Lines of this file are not shown. View the raw message.

util/bitmap.c +7 -7
index 1753ff7f5b..d7995776ab 100644

Lines of this file are not shown. View the raw message.

util/cacheinfo.c +1 -1
index d94dc6adc8..4881ff3568 100644

Lines of this file are not shown. View the raw message.

util/fdmon-epoll.c +2 -2
index fcd989d47d..02447ea89a 100644

Lines of this file are not shown. View the raw message.

util/fdmon-io_uring.c +7 -6
index 1d14177df0..b1222e5370 100644

Lines of this file are not shown. View the raw message.

util/lockcnt.c +32 -27

59 lines not on this page · raw message

util/log.c +5 -5
index bdb3d712e8..e2a8eb4fed 100644

Lines of this file are not shown. View the raw message.

util/qemu-coroutine-lock.c +10 -9
index 5da5234155..942f5c43f2 100644

Lines of this file are not shown. View the raw message.

util/qemu-coroutine-sleep.c +2 -2
index 769a76e57d..9a81a7d6ee 100644

Lines of this file are not shown. View the raw message.

util/qemu-coroutine.c +3 -3
index c3caa6c770..ad28603a71 100644

Lines of this file are not shown. View the raw message.

util/qemu-sockets.c +2 -2
index b37d288866..294ea21446 100644

Lines of this file are not shown. View the raw message.

util/qemu-thread-posix.c +6 -6
index b4c2359272..6457fda165 100644

Lines of this file are not shown. View the raw message.

util/qemu-thread-win32.c +6 -6
index 56a83333da..409b28d21b 100644

Lines of this file are not shown. View the raw message.

util/qemu-timer.c +6 -6
index 878d80fd5e..a70c03fc59 100644

Lines of this file are not shown. View the raw message.

util/qht.c +29 -28

57 lines not on this page · raw message

util/qsp.c +25 -25

50 lines not on this page · raw message

util/rcu.c +18 -18
index c4fefa9333..92a14e0a0f 100644

Lines of this file are not shown. View the raw message.

util/stats64.c +17 -17
index 389c365a9e..a93c04dce0 100644

Lines of this file are not shown. View the raw message.

docs/devel/atomics.rst +163 -163

326 lines not on this page · raw message

pc-bios/opensbi-riscv32-generic-fw_dynamic.elf binary +0 -0
index eb9ebf5674d3953ab25de6bf4db134abe904eb20..35b80512446dcf5c49424ae90caacf3c579be1b5 100644
GIT binary patch
pc-bios/opensbi-riscv64-generic-fw_dynamic.elf binary +0 -0
index 642a64e240d09b2ddb9fc12c74718ae8d386b9d3..9cf2cf23b747cb5be1d3389a0611d8697609c6f8 100644
GIT binary patch
scripts/kernel-doc +1 -1
index 030b5c8691..9ec38a1bf1 100755

Lines of this file are not shown. View the raw message.

tcg/aarch64/tcg-target.c.inc +1 -1
index 948c35d825..33d90c6da3 100644

Lines of this file are not shown. View the raw message.

tcg/mips/tcg-target.c.inc +1 -1
index bd5b8e09a0..364aa2f64a 100644

Lines of this file are not shown. View the raw message.

tcg/ppc/tcg-target.c.inc +3 -3
index 393c4b30e0..21accf60fe 100644

Lines of this file are not shown. View the raw message.

tcg/sparc/tcg-target.c.inc +3 -2
index 0f1d91fc21..c24fb403da 100644

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.26.2

Part of the diff is not shown here. View the raw message.

#1 lore raw
Patchew URL: https://patchew.org/QEMU/[email protected]/

Patchew URL: https://patchew.org/QEMU/[email protected]/

Hi,

This series seems to have some coding style problems. See output below for more information:

Type: series
Message-id: [email protected]
Subject: [PATCH] qemu/atomic.h: prefix qemu_ to solve <stdatomic.h> collisions

=== TEST SCRIPT BEGIN ===
#!/bin/bash
git rev-parse base > /dev/null || exit 0
git config --local diff.renamelimit 0
git config --local diff.renames True
git config --local diff.algorithm histogram
./scripts/checkpatch.pl --mailback base..
=== TEST SCRIPT END ===

Updating 3c8cf5a9c21ff8782164d1def7f44bd888713384
From https://github.com/patchew-project/qemu
- [tag update] patchew/[email protected] -> patchew/[email protected]
Switched to a new branch 'test'
25ca702 qemu/atomic.h: prefix qemu_ to solve <stdatomic.h> collisions

=== OUTPUT BEGIN ===
ERROR: Macros with multiple statements should be enclosed in a do - while loop #2968: FILE: include/qemu/atomic.h:152:

+#define qemu_atomic_rcu_read__nocheck(ptr, valptr)      \
     __atomic_load(ptr, valptr, __ATOMIC_RELAXED);       \
     smp_read_barrier_depends();

ERROR: space required before that '*' (ctx:VxB)
#3123: FILE: include/qemu/atomic.h:347:
+#define qemu_atomic_read__nocheck(p) (*(__typeof__(*(p)) volatile*) (p))

                                                                  ^

ERROR: Use of volatile is usually wrong, please add a comment #3123: FILE: include/qemu/atomic.h:347:
+#define qemu_atomic_read__nocheck(p) (*(__typeof__(*(p)) volatile*) (p))

ERROR: space required before that '*' (ctx:VxB)
#3125: FILE: include/qemu/atomic.h:349:
+ ((*(__typeof__(*(p)) volatile*) (p)) = (i))

                                  ^

ERROR: Use of volatile is usually wrong, please add a comment #3125: FILE: include/qemu/atomic.h:349:
+ ((*(__typeof__(*(p)) volatile*) (p)) = (i))

ERROR: space required after that ',' (ctx:VxV)
#3130: FILE: include/qemu/atomic.h:352:
+#define qemu_atomic_set(ptr, i) qemu_atomic_set__nocheck(ptr,i)

                                                                 ^

ERROR: memory barrier without comment
#3205: FILE: include/qemu/atomic.h:410:
+#define qemu_atomic_xchg(ptr, i) (smp_mb(), __sync_lock_test_and_set(ptr, i))

WARNING: Block comments use a leading /* on a separate line #3280: FILE: include/qemu/atomic.h:462:
+/* qemu_atomic_mb_read/set semantics map Java volatile variables. They are

WARNING: Block comments use a leading /* on a separate line #6394: FILE: util/bitmap.c:214:
+ /* If we avoided the full barrier in qemu_atomic_or(), issue a

WARNING: Block comments use a leading /* on a separate line #7430: FILE: util/rcu.c:85:
+ /* Instead of using qemu_atomic_mb_set for index->waiting, and

WARNING: Block comments use a leading /* on a separate line #7456: FILE: util/rcu.c:154:
+ /* In either case, the qemu_atomic_mb_set below blocks stores that free

total: 7 errors, 4 warnings, 6507 lines checked

Commit 25ca7029b2f2 (qemu/atomic.h: prefix qemu_ to solve <stdatomic.h> collisions) has style problems, please review. If any of these errors are false positives report them to the maintainer, see
CHECKPATCH in MAINTAINERS.
=== OUTPUT END ===

Test command exited with code: 1

The full log is available at
http://patchew.org/logs/[email protected]/testing.checkpatch/?type=message.
---
Email generated automatically by Patchew [https://patchew.org/].
Please send your feedback to [email protected]

#2 lore raw
Quoted 45 lines · On Mon, Sep 21, 2020 at 01:56:08PM -0700, [email protected] wrote:

ERROR: Macros with multiple statements should be enclosed in a do - while loop #2968: FILE: include/qemu/atomic.h:152:

+#define qemu_atomic_rcu_read__nocheck(ptr, valptr)      \
     __atomic_load(ptr, valptr, __ATOMIC_RELAXED);       \
     smp_read_barrier_depends();

ERROR: space required before that '*' (ctx:VxB)
#3123: FILE: include/qemu/atomic.h:347:
+#define qemu_atomic_read__nocheck(p) (*(__typeof__(*(p)) volatile*) (p))

                                                                  ^

ERROR: Use of volatile is usually wrong, please add a comment #3123: FILE: include/qemu/atomic.h:347:
+#define qemu_atomic_read__nocheck(p) (*(__typeof__(*(p)) volatile*) (p))

ERROR: space required before that '*' (ctx:VxB)
#3125: FILE: include/qemu/atomic.h:349:
+ ((*(__typeof__(*(p)) volatile*) (p)) = (i))

                                  ^

ERROR: Use of volatile is usually wrong, please add a comment #3125: FILE: include/qemu/atomic.h:349:
+ ((*(__typeof__(*(p)) volatile*) (p)) = (i))

ERROR: space required after that ',' (ctx:VxV)
#3130: FILE: include/qemu/atomic.h:352:
+#define qemu_atomic_set(ptr, i) qemu_atomic_set__nocheck(ptr,i)

                                                                 ^

ERROR: memory barrier without comment
#3205: FILE: include/qemu/atomic.h:410:
+#define qemu_atomic_xchg(ptr, i) (smp_mb(), __sync_lock_test_and_set(ptr, i))

WARNING: Block comments use a leading /* on a separate line #3280: FILE: include/qemu/atomic.h:462:
+/* qemu_atomic_mb_read/set semantics map Java volatile variables. They are

WARNING: Block comments use a leading /* on a separate line #6394: FILE: util/bitmap.c:214:
+ /* If we avoided the full barrier in qemu_atomic_or(), issue a

WARNING: Block comments use a leading /* on a separate line #7430: FILE: util/rcu.c:85:
+ /* Instead of using qemu_atomic_mb_set for index->waiting, and

Quoted 5 lines

WARNING: Block comments use a leading /* on a separate line #7456: FILE: util/rcu.c:154:
+ /* In either case, the qemu_atomic_mb_set below blocks stores that free

total: 7 errors, 4 warnings, 6507 lines checked

These are pre-existing coding style issues. This is a big patch that tries to make as few actual changes as possible so I would rather not try to fix them.

Stefan

#3 lore raw
Quoted 7 lines · Stefan Hajnoczi
Quoted 6 lines · On Mon, Sep 21, 2020 at 01:56:08PM -0700, [email protected] wrote:

ERROR: Macros with multiple statements should be enclosed in a do - while loop #2968: FILE: include/qemu/atomic.h:152:

+#define qemu_atomic_rcu_read__nocheck(ptr, valptr)      \
     __atomic_load(ptr, valptr, __ATOMIC_RELAXED);       \
     smp_read_barrier_depends();

...

Quoted 9 lines
Quoted 5 lines

WARNING: Block comments use a leading /* on a separate line #7456: FILE: util/rcu.c:154:
+ /* In either case, the qemu_atomic_mb_set below blocks stores that free

total: 7 errors, 4 warnings, 6507 lines checked

These are pre-existing coding style issues. This is a big patch that tries to make as few actual changes as possible so I would rather not try to fix them.

What I do with automated patches triggering checkpatch errors:

- run automated conversion
- fix errors until checkpatch is happy
- run automated conversion inversed
- result is the checkpatch changes, commit them
- run automated conversion again, commit

#4 lore raw
In reply to Stefan Hajnoczi
Quoted 8 lines · Stefan Hajnoczi

clang's C11 atomic_fetch_*() functions only take a C11 atomic type pointer argument. QEMU uses direct types (int, etc) and this causes a compiler error when a QEMU code calls these functions in a source file that also included <stdatomic.h> via a system header file:

   $ CC=clang CXX=clang++ ./configure ... && make
   ../util/async.c:79:17: error: address argument to atomic operation must be a pointer to _Atomic type ('unsigned int *' invalid)
Quoted 7 lines

Avoid using atomic_*() names in QEMU's atomic.h since that namespace is used by <stdatomic.h>. Prefix QEMU's APIs with qemu_ so that atomic.h and <stdatomic.h> can co-exist.

This patch was generated using:

   $ git diff | grep -o '\<atomic_[a-z0-9_]\+' | sort -u >/tmp/changed_identifiers

Missing a step in the recipe: namely, you probably modified include/qemu/atomic*.h prior to running 'git diff' (so that you actually had input to feed to grep -o). But spelling it 'git diff HEAD^ include/qemu/atomic*.h | ...' does indeed give me a sane list of identifiers that looks like what you touched in the rest of the patch.

Quoted 1 line
   $ for identifier in $(</tmp/changed_identifiers64); do \

Also not quite the right recipe, based on the file name used in the line above.

Quoted 3 lines
        sed -i "s%\<$identifier\>%qemu_$identifier%" $(git grep -l "\<$identifier\>") \
     done

Fortunately, running "git grep -c '\<atomic_[a-z0-9_]\+'" on the pre-patch state of the tree gives me a list that is somewhat close to yours, where the obvious difference in line counts is explained by:

Quoted 4 lines

I manually fixed line-wrap issues and misaligned rST tables.

---

First, focusing on the change summary:

Quoted 7 lines
  docs/devel/lockcnt.txt                        |  14 +-
  docs/devel/rcu.txt                            |  40 +--
  accel/tcg/atomic_template.h                   |  20 +-
  include/block/aio-wait.h                      |   4 +-
  include/block/aio.h                           |   8 +-
  include/exec/cpu_ldst.h                       |   2 +-
  include/exec/exec-all.h                       |   6 +-
Quoted 8 lines
  include/exec/log.h                            |   6 +-
  include/exec/memory.h                         |   2 +-
  include/exec/ram_addr.h                       |  27 +-
  include/exec/ramlist.h                        |   2 +-
  include/exec/tb-lookup.h                      |   4 +-
  include/hw/core/cpu.h                         |   2 +-
  include/qemu/atomic.h                         | 258 +++++++-------
  include/qemu/atomic128.h                      |   6 +-

These two are the most important for the sake of this patch; perhaps it's worth a temporary override of your git orderfile if you have to respin, to list them first?

Quoted 6 lines
  include/qemu/bitops.h                         |   2 +-
  include/qemu/coroutine.h                      |   2 +-
  include/qemu/log.h                            |   6 +-
  include/qemu/queue.h                          |   8 +-
  include/qemu/rcu.h                            |  10 +-
  include/qemu/rcu_queue.h                      | 103 +++---

Presumably, this and any other file with an odd number of changes was due to a difference in lines after reformatting long lines.

Quoted 1 line
  include/qemu/seqlock.h                        |   8 +-

...

Quoted 4 lines
  util/stats64.c                                |  34 +-
  docs/devel/atomics.rst                        | 326 +++++++++---------
  .../opensbi-riscv32-generic-fw_dynamic.elf    | Bin 558668 -> 558698 bytes
  .../opensbi-riscv64-generic-fw_dynamic.elf    | Bin 620424 -> 620454 bytes

Why are we regenerating .elf files in this patch? Is your change even correct for those two files?

Quoted 6 lines
  scripts/kernel-doc                            |   2 +-
  tcg/aarch64/tcg-target.c.inc                  |   2 +-
  tcg/mips/tcg-target.c.inc                     |   2 +-
  tcg/ppc/tcg-target.c.inc                      |   6 +-
  tcg/sparc/tcg-target.c.inc                    |   5 +-
  135 files changed, 1195 insertions(+), 1130 deletions(-)

I don't spot accel/tcg/atomic_common.c.inc in the list (which declares functions such as atomic_trace_rmw_pre) - I guess that's intentional based on how you tried to edit only the identifiers you touched in include/qemu/atomic*.h.

For the rest of this patch, I only spot-checked in places, trusting the mechanical nature of this patch, and not spotting anything wrong in the places I checked. But the two .elf files worry me enough to withhold R-b. At the same time, because it's big, it will probably be a source of conflicts if we don't get it in soon, but can also be regenerated (if your recipe is corrected) without too much difficulty. So I am in favor of the idea.

Quoted 27 lines
pc-bios/opensbi-riscv32-generic-fw_dynamic.elf binary +0 -0
index eb9ebf5674d3953ab25de6bf4db134abe904eb20..35b80512446dcf5c49424ae90caacf3c579be1b5 100644
GIT binary patch
pc-bios/opensbi-riscv64-generic-fw_dynamic.elf binary +0 -0
index 642a64e240d09b2ddb9fc12c74718ae8d386b9d3..9cf2cf23b747cb5be1d3389a0611d8697609c6f8 100644
GIT binary patch
scripts/kernel-doc +0 -0
index 030b5c8691..9ec38a1bf1 100755

scripts/kernel-doc sub dump_function($$) { · line 1629

Quoted 6 lines
scripts/kernel-doc +1 -1
@@ -1625,7 +1625,7 @@ sub dump_function($$) {
      # If you mess with these regexps, it's a good idea to check that
      # the following functions' documentation still comes out right:
      # - parport_register_device (function pointer parameters)
-    # - atomic_set (macro)
+    # - qemu_atomic_set (macro)
      # - pci_match_device, __copy_to_user (long return type)

Does the result of sphinx still look good, as mentioned in this comment?

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org
#5 lore raw
Quoted 1 line · Eric Blake

On 9/21/20 11:23 AM, Stefan Hajnoczi wrote:

Thanks for the review! Your feedback prompted me to do this more systematically. I fixed the command-lines and published a diff of just the manual changes I made on top of the mechanical changes (see v2).

Quoted 14 lines
Quoted 14 lines

clang's C11 atomic_fetch_*() functions only take a C11 atomic type pointer argument. QEMU uses direct types (int, etc) and this causes a compiler error when a QEMU code calls these functions in a source file that also included <stdatomic.h> via a system header file:

   $ CC=clang CXX=clang++ ./configure ... && make
   ../util/async.c:79:17: error: address argument to atomic operation must be a pointer to _Atomic type ('unsigned int *' invalid)

Avoid using atomic_*() names in QEMU's atomic.h since that namespace is used by <stdatomic.h>. Prefix QEMU's APIs with qemu_ so that atomic.h and <stdatomic.h> can co-exist.

This patch was generated using:

Quoted 7 lines
Quoted 1 line
   $ git diff | grep -o '\<atomic_[a-z0-9_]\+' | sort -u >/tmp/changed_identifiers

Missing a step in the recipe: namely, you probably modified include/qemu/atomic*.h prior to running 'git diff' (so that you actually had input to feed to grep -o). But spelling it 'git diff HEAD^ include/qemu/atomic*.h | ...' does indeed give me a sane list of identifiers that looks like what you touched in the rest of the patch.

Yes, I edited the file first and then used this command-line. The one you posted it better :).

Quoted 5 lines
Quoted 2 lines
   $ for identifier in $(</tmp/changed_identifiers64); do \

Also not quite the right recipe, based on the file name used in the line above.

Yes, "64" is when I realized the original grep expression hadn't matched the atomic64 APIs.

These commands only show the gist of it. It involved a few manual steps.

Quoted 32 lines
Quoted 4 lines
        sed -i "s%\<$identifier\>%qemu_$identifier%" $(git grep -l "\<$identifier\>") \
     done

Fortunately, running "git grep -c '\<atomic_[a-z0-9_]\+'" on the pre-patch state of the tree gives me a list that is somewhat close to yours, where the obvious difference in line counts is explained by:

Quoted 4 lines

I manually fixed line-wrap issues and misaligned rST tables.

---

First, focusing on the change summary:

Quoted 7 lines
  docs/devel/lockcnt.txt                        |  14 +-
  docs/devel/rcu.txt                            |  40 +--
  accel/tcg/atomic_template.h                   |  20 +-
  include/block/aio-wait.h                      |   4 +-
  include/block/aio.h                           |   8 +-
  include/exec/cpu_ldst.h                       |   2 +-
  include/exec/exec-all.h                       |   6 +-
Quoted 8 lines
  include/exec/log.h                            |   6 +-
  include/exec/memory.h                         |   2 +-
  include/exec/ram_addr.h                       |  27 +-
  include/exec/ramlist.h                        |   2 +-
  include/exec/tb-lookup.h                      |   4 +-
  include/hw/core/cpu.h                         |   2 +-
  include/qemu/atomic.h                         | 258 +++++++-------
  include/qemu/atomic128.h                      |   6 +-
Quoted 3 lines

These two are the most important for the sake of this patch; perhaps it's worth a temporary override of your git orderfile if you have to respin, to list them first?

Will do in v2.

Quoted 10 lines
Quoted 7 lines
  include/qemu/bitops.h                         |   2 +-
  include/qemu/coroutine.h                      |   2 +-
  include/qemu/log.h                            |   6 +-
  include/qemu/queue.h                          |   8 +-
  include/qemu/rcu.h                            |  10 +-
  include/qemu/rcu_queue.h                      | 103 +++---

Presumably, this and any other file with an odd number of changes was due to a difference in lines after reformatting long lines.

Yes, line-wrapping required many changes in this file.

Quoted 11 lines
Quoted 2 lines
  include/qemu/seqlock.h                        |   8 +-

...

Quoted 4 lines
  util/stats64.c                                |  34 +-
  docs/devel/atomics.rst                        | 326 +++++++++---------
  .../opensbi-riscv32-generic-fw_dynamic.elf    | Bin 558668 -> 558698 bytes
  .../opensbi-riscv64-generic-fw_dynamic.elf    | Bin 620424 -> 620454 bytes

Why are we regenerating .elf files in this patch? Is your change even correct for those two files?

Thanks for noticing this! The git-grep(1) man page documents the -I option for skipping binary files. I thought this was the default.

Will fix in v2.

Quoted 8 lines
Quoted 7 lines
  scripts/kernel-doc                            |   2 +-
  tcg/aarch64/tcg-target.c.inc                  |   2 +-
  tcg/mips/tcg-target.c.inc                     |   2 +-
  tcg/ppc/tcg-target.c.inc                      |   6 +-
  tcg/sparc/tcg-target.c.inc                    |   5 +-
  135 files changed, 1195 insertions(+), 1130 deletions(-)
Quoted 4 lines

I don't spot accel/tcg/atomic_common.c.inc in the list (which declares functions such as atomic_trace_rmw_pre) - I guess that's intentional based on how you tried to edit only the identifiers you touched in include/qemu/atomic*.h.

Yes. The namespace cleaning only applies to atomic.h. Any other part of QEMU uses atomic_ is unaffected.

Quoted 5 lines
Quoted 5 lines
scripts/kernel-doc +0 -0
index 030b5c8691..9ec38a1bf1 100755
@@ -1625,7 +1625,7 @@ sub dump_function($$) {
Quoted 8 lines

scripts/kernel-doc sub dump_function($$) { · line 1629

Quoted 6 lines
scripts/kernel-doc +1 -1
      # If you mess with these regexps, it's a good idea to check that
      # the following functions' documentation still comes out right:
      # - parport_register_device (function pointer parameters)
-    # - atomic_set (macro)
+    # - qemu_atomic_set (macro)
      # - pci_match_device, __copy_to_user (long return type)

Does the result of sphinx still look good, as mentioned in this comment?

Yes.

Stefan

maintainer
#6 lore raw
In reply to Stefan Hajnoczi
Quoted 12 lines · Stefan Hajnoczi

clang's C11 atomic_fetch_*() functions only take a C11 atomic type pointer argument. QEMU uses direct types (int, etc) and this causes a compiler error when a QEMU code calls these functions in a source file that also included <stdatomic.h> via a system header file:

  $ CC=clang CXX=clang++ ./configure ... && make
  ../util/async.c:79:17: error: address argument to atomic operation must be a pointer to _Atomic type ('unsigned int *' invalid)

Avoid using atomic_*() names in QEMU's atomic.h since that namespace is used by <stdatomic.h>. Prefix QEMU's APIs with qemu_ so that atomic.h and <stdatomic.h> can co-exist.

Quoted 6 lines

This patch was generated using:

  $ git diff | grep -o '\<atomic_[a-z0-9_]\+' | sort -u >/tmp/changed_identifiers
  $ for identifier in $(</tmp/changed_identifiers64); do \
       sed -i "s%\<$identifier\>%qemu_$identifier%" $(git grep -l "\<$identifier\>") \
    done

It's certainly a good idea but it's quite verbose.

What about using atomic__* as the prefix? It is not very common in QEMU but there are some cases (and I cannot think of anything better).

Paolo

#7 lore raw
Quoted 20 lines · Paolo Bonzini
Quoted 12 lines · Stefan Hajnoczi

clang's C11 atomic_fetch_*() functions only take a C11 atomic type pointer argument. QEMU uses direct types (int, etc) and this causes a compiler error when a QEMU code calls these functions in a source file that also included <stdatomic.h> via a system header file:

  $ CC=clang CXX=clang++ ./configure ... && make
  ../util/async.c:79:17: error: address argument to atomic operation must be a pointer to _Atomic type ('unsigned int *' invalid)

Avoid using atomic_*() names in QEMU's atomic.h since that namespace is used by <stdatomic.h>. Prefix QEMU's APIs with qemu_ so that atomic.h and <stdatomic.h> can co-exist.

Quoted 6 lines

This patch was generated using:

  $ git diff | grep -o '\<atomic_[a-z0-9_]\+' | sort -u >/tmp/changed_identifiers
  $ for identifier in $(</tmp/changed_identifiers64); do \
       sed -i "s%\<$identifier\>%qemu_$identifier%" $(git grep -l "\<$identifier\>") \
    done
Quoted 5 lines

It's certainly a good idea but it's quite verbose.

What about using atomic__* as the prefix? It is not very common in QEMU but there are some cases (and I cannot think of anything better).

aqomic_*, lol :)

Quoted 2 lines

Paolo

Signature · 3 lines
Thanks,

David / dhildenb
maintainer
#8 lore raw
Quoted 6 lines · David Hildenbrand
Quoted 4 lines

It's certainly a good idea but it's quite verbose.

What about using atomic__* as the prefix? It is not very common in QEMU but there are some cases (and I cannot think of anything better).

aqomic_*, lol :)

Actually qatomic_ would be a good one, wouldn't it?

Paolo

#9 lore raw
Quoted 9 lines · Paolo Bonzini
Quoted 6 lines · David Hildenbrand
Quoted 4 lines

It's certainly a good idea but it's quite verbose.

What about using atomic__* as the prefix? It is not very common in QEMU but there are some cases (and I cannot think of anything better).

aqomic_*, lol :)

Actually qatomic_ would be a good one, wouldn't it?

agreed!

Signature · 3 lines
Thanks,

David / dhildenb
#10 lore raw
In reply to Paolo Bonzini
Quoted 9 lines · Paolo Bonzini
Quoted 6 lines · David Hildenbrand
Quoted 4 lines

It's certainly a good idea but it's quite verbose.

What about using atomic__* as the prefix? It is not very common in QEMU but there are some cases (and I cannot think of anything better).

aqomic_*, lol :)

Actually qatomic_ would be a good one, wouldn't it?

Yes, I think just adding a 'q' on the front of methods is more than sufficient (see also all the qcrypto_*, qio_* APIs I wrote). The only think a plain 'q' prefix is likely to clash with is the Qt library and that isn't something we're likely to link with (famous last words...).

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#11 lore raw
Quoted 9 lines · Daniel P. Berrangé
Quoted 8 lines · Paolo Bonzini
Quoted 6 lines · David Hildenbrand
Quoted 4 lines

It's certainly a good idea but it's quite verbose.

What about using atomic__* as the prefix? It is not very common in QEMU but there are some cases (and I cannot think of anything better).

aqomic_*, lol :)

Quoted 7 lines
Quoted 1 line

Actually qatomic_ would be a good one, wouldn't it?

Yes, I think just adding a 'q' on the front of methods is more than sufficient (see also all the qcrypto_*, qio_* APIs I wrote). The only think a plain 'q' prefix is likely to clash with is the Qt library and that isn't something we're likely to link with (famous last words...).

This is why I didn't use "qatomic". "atomic" feels too common to prefix with just a single letter.

But I grepped /usr/include and code searched GitHub. I can't find any uses of "qatomic_" so it looks safe. FWIW Qt does have qatomic.h but doesn't use the name for identifiers in the code.

Let's do it!

Stefan