qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 1/5] system/cpus: rename qemu_mutex_lock_iothread() to bql


From: Akihiko Odaki
Subject: Re: [PATCH v2 1/5] system/cpus: rename qemu_mutex_lock_iothread() to bql_lock()
Date: Wed, 13 Dec 2023 15:37:00 +0900
User-agent: Mozilla Thunderbird

On 2023/12/13 0:39, Stefan Hajnoczi wrote:
The Big QEMU Lock (BQL) has many names and they are confusing. The
actual QemuMutex variable is called qemu_global_mutex but it's commonly
referred to as the BQL in discussions and some code comments. The
locking APIs, however, are called qemu_mutex_lock_iothread() and
qemu_mutex_unlock_iothread().

The "iothread" name is historic and comes from when the main thread was
split into into KVM vcpu threads and the "iothread" (now called the main
loop thread). I have contributed to the confusion myself by introducing
a separate --object iothread, a separate concept unrelated to the BQL.

The "iothread" name is no longer appropriate for the BQL. Rename the
locking APIs to:
- void bql_lock(void)
- void bql_unlock(void)
- bool bql_locked(void)

There are more APIs with "iothread" in their names. Subsequent patches
will rename them. There are also comments and documentation that will be
updated in later patches.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Paul Durrant <paul@xen.org>
Acked-by: Fabiano Rosas <farosas@suse.de>
Acked-by: David Woodhouse <dwmw@amazon.co.uk>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Acked-by: Peter Xu <peterx@redhat.com>
Acked-by: Eric Farman <farman@linux.ibm.com>
Reviewed-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
---
  include/block/aio-wait.h             |   2 +-
  include/qemu/main-loop.h             |  40 ++++-----
  include/qemu/thread.h                |   2 +-
  accel/accel-blocker.c                |  10 +--
  accel/dummy-cpus.c                   |   8 +-
  accel/hvf/hvf-accel-ops.c            |   4 +-
  accel/kvm/kvm-accel-ops.c            |   4 +-
  accel/kvm/kvm-all.c                  |  22 ++---
  accel/tcg/cpu-exec.c                 |  26 +++---
  accel/tcg/cputlb.c                   |  16 ++--
  accel/tcg/tcg-accel-ops-icount.c     |   4 +-
  accel/tcg/tcg-accel-ops-mttcg.c      |  12 +--
  accel/tcg/tcg-accel-ops-rr.c         |  14 ++--
  accel/tcg/tcg-accel-ops.c            |   2 +-
  accel/tcg/translate-all.c            |   2 +-
  cpu-common.c                         |   4 +-
  dump/dump.c                          |   4 +-
  hw/core/cpu-common.c                 |   6 +-
  hw/i386/intel_iommu.c                |   6 +-
  hw/i386/kvm/xen_evtchn.c             |  16 ++--
  hw/i386/kvm/xen_overlay.c            |   2 +-
  hw/i386/kvm/xen_xenstore.c           |   2 +-
  hw/intc/arm_gicv3_cpuif.c            |   2 +-
  hw/intc/s390_flic.c                  |  18 ++--
  hw/misc/edu.c                        |   4 +-
  hw/misc/imx6_src.c                   |   2 +-
  hw/misc/imx7_src.c                   |   2 +-
  hw/net/xen_nic.c                     |   8 +-
  hw/ppc/pegasos2.c                    |   2 +-
  hw/ppc/ppc.c                         |   4 +-
  hw/ppc/spapr.c                       |   2 +-
  hw/ppc/spapr_rng.c                   |   4 +-
  hw/ppc/spapr_softmmu.c               |   4 +-
  hw/remote/mpqemu-link.c              |  20 ++---
  hw/remote/vfio-user-obj.c            |   2 +-
  hw/s390x/s390-skeys.c                |   2 +-
  migration/block-dirty-bitmap.c       |   4 +-
  migration/block.c                    |  16 ++--
  migration/colo.c                     |  60 +++++++-------
  migration/dirtyrate.c                |  12 +--
  migration/migration.c                |  52 ++++++------
  migration/ram.c                      |  12 +--
  replay/replay-internal.c             |   2 +-
  semihosting/console.c                |   8 +-
  stubs/iothread-lock.c                |   6 +-
  system/cpu-throttle.c                |   4 +-
  system/cpus.c                        |  51 ++++++------
  system/dirtylimit.c                  |   4 +-
  system/memory.c                      |   2 +-
  system/physmem.c                     |   8 +-
  system/runstate.c                    |   2 +-
  system/watchpoint.c                  |   4 +-
  target/arm/arm-powerctl.c            |  14 ++--
  target/arm/helper.c                  |   4 +-
  target/arm/hvf/hvf.c                 |   8 +-
  target/arm/kvm.c                     |   4 +-
  target/arm/kvm64.c                   |   4 +-
  target/arm/ptw.c                     |   6 +-
  target/arm/tcg/helper-a64.c          |   8 +-
  target/arm/tcg/m_helper.c            |   6 +-
  target/arm/tcg/op_helper.c           |  24 +++---
  target/arm/tcg/psci.c                |   2 +-
  target/hppa/int_helper.c             |   8 +-
  target/i386/hvf/hvf.c                |   6 +-
  target/i386/kvm/hyperv.c             |   4 +-
  target/i386/kvm/kvm.c                |  28 +++----
  target/i386/kvm/xen-emu.c            |  14 ++--
  target/i386/nvmm/nvmm-accel-ops.c    |   4 +-
  target/i386/nvmm/nvmm-all.c          |  20 ++---
  target/i386/tcg/sysemu/fpu_helper.c  |   6 +-
  target/i386/tcg/sysemu/misc_helper.c |   4 +-
  target/i386/whpx/whpx-accel-ops.c    |   4 +-
  target/i386/whpx/whpx-all.c          |  24 +++---
  target/loongarch/csr_helper.c        |   4 +-
  target/mips/kvm.c                    |   4 +-
  target/mips/tcg/sysemu/cp0_helper.c  |   4 +-
  target/openrisc/sys_helper.c         |  16 ++--
  target/ppc/excp_helper.c             |  12 +--
  target/ppc/kvm.c                     |   4 +-
  target/ppc/misc_helper.c             |   8 +-
  target/ppc/timebase_helper.c         |   8 +-
  target/s390x/kvm/kvm.c               |   4 +-
  target/s390x/tcg/misc_helper.c       | 118 +++++++++++++--------------
  target/sparc/int32_helper.c          |   2 +-
  target/sparc/int64_helper.c          |   6 +-
  target/sparc/win_helper.c            |  20 ++---
  target/xtensa/exc_helper.c           |   8 +-
  ui/spice-core.c                      |   4 +-
  util/async.c                         |   2 +-
  util/main-loop.c                     |   8 +-
  util/qsp.c                           |   6 +-
  util/rcu.c                           |  14 ++--
  audio/coreaudio.m                    |   4 +-
  memory_ldst.c.inc                    |  18 ++--
  target/i386/hvf/README.md            |   2 +-
  ui/cocoa.m                           |  50 ++++++------
  96 files changed, 530 insertions(+), 529 deletions(-)

diff --git a/include/block/aio-wait.h b/include/block/aio-wait.h
index 5449b6d742..d22ca24329 100644
--- a/include/block/aio-wait.h
+++ b/include/block/aio-wait.h
@@ -151,7 +151,7 @@ static inline bool in_aio_context_home_thread(AioContext 
*ctx)
      }
if (ctx == qemu_get_aio_context()) {
-        return qemu_mutex_iothread_locked();
+        return bql_locked();
      } else {
          return false;
      }
diff --git a/include/qemu/main-loop.h b/include/qemu/main-loop.h
index 68e70e61aa..596a206acd 100644
--- a/include/qemu/main-loop.h
+++ b/include/qemu/main-loop.h
@@ -248,19 +248,19 @@ GSource *iohandler_get_g_source(void);
  AioContext *iohandler_get_aio_context(void);
/**
- * qemu_mutex_iothread_locked: Return lock status of the main loop mutex.
+ * bql_locked: Return lock status of the Big QEMU Lock (BQL)
   *
- * The main loop mutex is the coarsest lock in QEMU, and as such it
+ * The Big QEMU Lock (BQL) is the coarsest lock in QEMU, and as such it
   * must always be taken outside other locks.  This function helps
   * functions take different paths depending on whether the current
- * thread is running within the main loop mutex.
+ * thread is running within the BQL.
   *
   * This function should never be used in the block layer, because
   * unit tests, block layer tools and qemu-storage-daemon do not
   * have a BQL.
   * Please instead refer to qemu_in_main_thread().
   */
-bool qemu_mutex_iothread_locked(void);
+bool bql_locked(void);
/**
   * qemu_in_main_thread: return whether it's possible to safely access
@@ -312,58 +312,58 @@ bool qemu_in_main_thread(void);
      } while (0)
/**
- * qemu_mutex_lock_iothread: Lock the main loop mutex.
+ * bql_lock: Lock the Big QEMU Lock (BQL).
   *
- * This function locks the main loop mutex.  The mutex is taken by
+ * This function locks the Big QEMU Lock (BQL).  The lock is taken by
   * main() in vl.c and always taken except while waiting on
- * external events (such as with select).  The mutex should be taken
+ * external events (such as with select).  The lock should be taken
   * by threads other than the main loop thread when calling
   * qemu_bh_new(), qemu_set_fd_handler() and basically all other
   * functions documented in this file.
   *
- * NOTE: tools currently are single-threaded and qemu_mutex_lock_iothread
+ * NOTE: tools currently are single-threaded and bql_lock
   * is a no-op there.
   */
-#define qemu_mutex_lock_iothread()                      \
-    qemu_mutex_lock_iothread_impl(__FILE__, __LINE__)
-void qemu_mutex_lock_iothread_impl(const char *file, int line);
+#define bql_lock()                      \
+    bql_lock_impl(__FILE__, __LINE__)

This line break is no longer necessary.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]