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:
Stefan Hajnoczi 2024-01-02 10:35:25 -05:00
parent 897a06c6d7
commit 195801d700
95 changed files with 529 additions and 529 deletions

View file

@ -117,29 +117,29 @@ static QemuEvent cbevent;
typedef void (^CodeBlock)(void);
typedef bool (^BoolCodeBlock)(void);
static void with_iothread_lock(CodeBlock block)
static void with_bql(CodeBlock block)
{
bool locked = qemu_mutex_iothread_locked();
bool locked = bql_locked();
if (!locked) {
qemu_mutex_lock_iothread();
bql_lock();
}
block();
if (!locked) {
qemu_mutex_unlock_iothread();
bql_unlock();
}
}
static bool bool_with_iothread_lock(BoolCodeBlock block)
static bool bool_with_bql(BoolCodeBlock block)
{
bool locked = qemu_mutex_iothread_locked();
bool locked = bql_locked();
bool val;
if (!locked) {
qemu_mutex_lock_iothread();
bql_lock();
}
val = block();
if (!locked) {
qemu_mutex_unlock_iothread();
bql_unlock();
}
return val;
}
@ -605,7 +605,7 @@ static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type, CGEven
return;
}
with_iothread_lock(^{
with_bql(^{
[self updateUIInfoLocked];
});
}
@ -790,7 +790,7 @@ static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type, CGEven
- (bool) handleEvent:(NSEvent *)event
{
return bool_with_iothread_lock(^{
return bool_with_bql(^{
return [self handleEventLocked:event];
});
}
@ -1182,7 +1182,7 @@ static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type, CGEven
*/
- (void) raiseAllKeys
{
with_iothread_lock(^{
with_bql(^{
qkbd_state_lift_all_keys(kbd);
});
}
@ -1282,7 +1282,7 @@ static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type, CGEven
{
COCOA_DEBUG("QemuCocoaAppController: applicationWillTerminate\n");
with_iothread_lock(^{
with_bql(^{
shutdown_action = SHUTDOWN_ACTION_POWEROFF;
qemu_system_shutdown_request(SHUTDOWN_CAUSE_HOST_UI);
});
@ -1420,7 +1420,7 @@ static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type, CGEven
/* Pause the guest */
- (void)pauseQEMU:(id)sender
{
with_iothread_lock(^{
with_bql(^{
qmp_stop(NULL);
});
[sender setEnabled: NO];
@ -1431,7 +1431,7 @@ static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type, CGEven
/* Resume running the guest operating system */
- (void)resumeQEMU:(id) sender
{
with_iothread_lock(^{
with_bql(^{
qmp_cont(NULL);
});
[sender setEnabled: NO];
@ -1461,7 +1461,7 @@ static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type, CGEven
/* Restarts QEMU */
- (void)restartQEMU:(id)sender
{
with_iothread_lock(^{
with_bql(^{
qmp_system_reset(NULL);
});
}
@ -1469,7 +1469,7 @@ static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type, CGEven
/* Powers down QEMU */
- (void)powerDownQEMU:(id)sender
{
with_iothread_lock(^{
with_bql(^{
qmp_system_powerdown(NULL);
});
}
@ -1488,7 +1488,7 @@ static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type, CGEven
}
__block Error *err = NULL;
with_iothread_lock(^{
with_bql(^{
qmp_eject([drive cStringUsingEncoding: NSASCIIStringEncoding],
NULL, false, false, &err);
});
@ -1523,7 +1523,7 @@ static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type, CGEven
}
__block Error *err = NULL;
with_iothread_lock(^{
with_bql(^{
qmp_blockdev_change_medium([drive cStringUsingEncoding:
NSASCIIStringEncoding],
NULL,
@ -1605,7 +1605,7 @@ static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type, CGEven
// get the throttle percentage
throttle_pct = [sender tag];
with_iothread_lock(^{
with_bql(^{
cpu_throttle_set(throttle_pct);
});
COCOA_DEBUG("cpu throttling at %d%c\n", cpu_throttle_get_percentage(), '%');
@ -1819,7 +1819,7 @@ static void addRemovableDevicesMenuItems(void)
return;
}
with_iothread_lock(^{
with_bql(^{
QemuClipboardInfo *info = qemu_clipboard_info_ref(cbinfo);
qemu_event_reset(&cbevent);
qemu_clipboard_request(info, QEMU_CLIPBOARD_TYPE_TEXT);
@ -1827,9 +1827,9 @@ static void addRemovableDevicesMenuItems(void)
while (info == cbinfo &&
info->types[QEMU_CLIPBOARD_TYPE_TEXT].available &&
info->types[QEMU_CLIPBOARD_TYPE_TEXT].data == NULL) {
qemu_mutex_unlock_iothread();
bql_unlock();
qemu_event_wait(&cbevent);
qemu_mutex_lock_iothread();
bql_lock();
}
if (info == cbinfo) {
@ -1927,9 +1927,9 @@ static void *call_qemu_main(void *opaque)
int status;
COCOA_DEBUG("Second thread: calling qemu_default_main()\n");
qemu_mutex_lock_iothread();
bql_lock();
status = qemu_default_main();
qemu_mutex_unlock_iothread();
bql_unlock();
COCOA_DEBUG("Second thread: qemu_default_main() returned, exiting\n");
[cbowner release];
exit(status);
@ -1941,7 +1941,7 @@ static int cocoa_main(void)
COCOA_DEBUG("Entered %s()\n", __func__);
qemu_mutex_unlock_iothread();
bql_unlock();
qemu_thread_create(&thread, "qemu_main", call_qemu_main,
NULL, QEMU_THREAD_DETACHED);