mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-11 03:24:58 -06:00
system/cpus: rename qemu_mutex_lock_iothread() to bql_lock()
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> Acked-by: Hyman Huang <yong.huang@smartx.com> Reviewed-by: Akihiko Odaki <akihiko.odaki@daynix.com> Message-id: 20240102153529.486531-2-stefanha@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
897a06c6d7
commit
195801d700
95 changed files with 529 additions and 529 deletions
|
@ -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,57 @@ 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__)
|
||||
void bql_lock_impl(const char *file, int line);
|
||||
|
||||
/**
|
||||
* qemu_mutex_unlock_iothread: Unlock the main loop mutex.
|
||||
* bql_unlock: Unlock the Big QEMU Lock (BQL).
|
||||
*
|
||||
* This function unlocks the main loop mutex. The mutex is taken by
|
||||
* This function unlocks the Big QEMU Lock. 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 unlocked
|
||||
* external events (such as with select). The lock should be unlocked
|
||||
* as soon as possible by threads other than the main loop thread,
|
||||
* because it prevents the main loop from processing callbacks,
|
||||
* including timers and bottom halves.
|
||||
*
|
||||
* NOTE: tools currently are single-threaded and qemu_mutex_unlock_iothread
|
||||
* NOTE: tools currently are single-threaded and bql_unlock
|
||||
* is a no-op there.
|
||||
*/
|
||||
void qemu_mutex_unlock_iothread(void);
|
||||
void bql_unlock(void);
|
||||
|
||||
/**
|
||||
* QEMU_IOTHREAD_LOCK_GUARD
|
||||
*
|
||||
* Wrap a block of code in a conditional qemu_mutex_{lock,unlock}_iothread.
|
||||
* Wrap a block of code in a conditional bql_{lock,unlock}.
|
||||
*/
|
||||
typedef struct IOThreadLockAuto IOThreadLockAuto;
|
||||
|
||||
static inline IOThreadLockAuto *qemu_iothread_auto_lock(const char *file,
|
||||
int line)
|
||||
{
|
||||
if (qemu_mutex_iothread_locked()) {
|
||||
if (bql_locked()) {
|
||||
return NULL;
|
||||
}
|
||||
qemu_mutex_lock_iothread_impl(file, line);
|
||||
bql_lock_impl(file, line);
|
||||
/* Anything non-NULL causes the cleanup function to be called */
|
||||
return (IOThreadLockAuto *)(uintptr_t)1;
|
||||
}
|
||||
|
||||
static inline void qemu_iothread_auto_unlock(IOThreadLockAuto *l)
|
||||
{
|
||||
qemu_mutex_unlock_iothread();
|
||||
bql_unlock();
|
||||
}
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(IOThreadLockAuto, qemu_iothread_auto_unlock)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue