aboutsummaryrefslogtreecommitdiff
path: root/migration
diff options
context:
space:
mode:
authorStefan Hajnoczi <stefanha@redhat.com>2024-01-02 10:35:25 -0500
committerStefan Hajnoczi <stefanha@redhat.com>2024-01-08 10:45:43 -0500
commit195801d700c008b6a8d8acfa299aa5f177446647 (patch)
tree7ab423e4a773b818f6c6d65f2fa06dc4517cad24 /migration
parent897a06c6d7ce8fb962a33cea1910d17218c746e9 (diff)
downloadqemu-195801d700c008b6a8d8acfa299aa5f177446647.zip
qemu-195801d700c008b6a8d8acfa299aa5f177446647.tar.gz
qemu-195801d700c008b6a8d8acfa299aa5f177446647.tar.bz2
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>
Diffstat (limited to 'migration')
-rw-r--r--migration/block-dirty-bitmap.c4
-rw-r--r--migration/block.c16
-rw-r--r--migration/colo.c60
-rw-r--r--migration/dirtyrate.c12
-rw-r--r--migration/migration.c52
-rw-r--r--migration/ram.c12
6 files changed, 78 insertions, 78 deletions
diff --git a/migration/block-dirty-bitmap.c b/migration/block-dirty-bitmap.c
index 24347ab..92e031b 100644
--- a/migration/block-dirty-bitmap.c
+++ b/migration/block-dirty-bitmap.c
@@ -774,7 +774,7 @@ static void dirty_bitmap_state_pending(void *opaque,
SaveBitmapState *dbms;
uint64_t pending = 0;
- qemu_mutex_lock_iothread();
+ bql_lock();
QSIMPLEQ_FOREACH(dbms, &s->dbms_list, entry) {
uint64_t gran = bdrv_dirty_bitmap_granularity(dbms->bitmap);
@@ -784,7 +784,7 @@ static void dirty_bitmap_state_pending(void *opaque,
pending += DIV_ROUND_UP(sectors * BDRV_SECTOR_SIZE, gran);
}
- qemu_mutex_unlock_iothread();
+ bql_unlock();
trace_dirty_bitmap_state_pending(pending);
diff --git a/migration/block.c b/migration/block.c
index 6ec6a1d..b731d7d 100644
--- a/migration/block.c
+++ b/migration/block.c
@@ -269,7 +269,7 @@ static int mig_save_device_bulk(QEMUFile *f, BlkMigDevState *bmds)
int64_t count;
if (bmds->shared_base) {
- qemu_mutex_lock_iothread();
+ bql_lock();
/* Skip unallocated sectors; intentionally treats failure or
* partial sector as an allocated sector */
while (cur_sector < total_sectors &&
@@ -280,7 +280,7 @@ static int mig_save_device_bulk(QEMUFile *f, BlkMigDevState *bmds)
}
cur_sector += count >> BDRV_SECTOR_BITS;
}
- qemu_mutex_unlock_iothread();
+ bql_unlock();
}
if (cur_sector >= total_sectors) {
@@ -316,12 +316,12 @@ static int mig_save_device_bulk(QEMUFile *f, BlkMigDevState *bmds)
* I/O runs in the main loop AioContext (see
* qemu_get_current_aio_context()).
*/
- qemu_mutex_lock_iothread();
+ bql_lock();
bdrv_reset_dirty_bitmap(bmds->dirty_bitmap, cur_sector * BDRV_SECTOR_SIZE,
nr_sectors * BDRV_SECTOR_SIZE);
blk->aiocb = blk_aio_preadv(bb, cur_sector * BDRV_SECTOR_SIZE, &blk->qiov,
0, blk_mig_read_cb, blk);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
bmds->cur_sector = cur_sector + nr_sectors;
return (bmds->cur_sector >= total_sectors);
@@ -770,9 +770,9 @@ static int block_save_iterate(QEMUFile *f, void *opaque)
/* Always called with iothread lock taken for
* simplicity, block_save_complete also calls it.
*/
- qemu_mutex_lock_iothread();
+ bql_lock();
ret = blk_mig_save_dirty_block(f, 1);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
}
if (ret < 0) {
return ret;
@@ -844,9 +844,9 @@ static void block_state_pending(void *opaque, uint64_t *must_precopy,
/* Estimate pending number of bytes to send */
uint64_t pending;
- qemu_mutex_lock_iothread();
+ bql_lock();
pending = get_remaining_dirty();
- qemu_mutex_unlock_iothread();
+ bql_unlock();
blk_mig_lock();
pending += block_mig_state.submitted * BLK_MIG_BLOCK_SIZE +
diff --git a/migration/colo.c b/migration/colo.c
index 4447e34..2a74efd 100644
--- a/migration/colo.c
+++ b/migration/colo.c
@@ -420,13 +420,13 @@ static int colo_do_checkpoint_transaction(MigrationState *s,
qio_channel_io_seek(QIO_CHANNEL(bioc), 0, 0, NULL);
bioc->usage = 0;
- qemu_mutex_lock_iothread();
+ bql_lock();
if (failover_get_state() != FAILOVER_STATUS_NONE) {
- qemu_mutex_unlock_iothread();
+ bql_unlock();
goto out;
}
vm_stop_force_state(RUN_STATE_COLO);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
trace_colo_vm_state_change("run", "stop");
/*
* Failover request bh could be called after vm_stop_force_state(),
@@ -435,23 +435,23 @@ static int colo_do_checkpoint_transaction(MigrationState *s,
if (failover_get_state() != FAILOVER_STATUS_NONE) {
goto out;
}
- qemu_mutex_lock_iothread();
+ bql_lock();
replication_do_checkpoint_all(&local_err);
if (local_err) {
- qemu_mutex_unlock_iothread();
+ bql_unlock();
goto out;
}
colo_send_message(s->to_dst_file, COLO_MESSAGE_VMSTATE_SEND, &local_err);
if (local_err) {
- qemu_mutex_unlock_iothread();
+ bql_unlock();
goto out;
}
/* Note: device state is saved into buffer */
ret = qemu_save_device_state(fb);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
if (ret < 0) {
goto out;
}
@@ -504,9 +504,9 @@ static int colo_do_checkpoint_transaction(MigrationState *s,
ret = 0;
- qemu_mutex_lock_iothread();
+ bql_lock();
vm_start();
- qemu_mutex_unlock_iothread();
+ bql_unlock();
trace_colo_vm_state_change("stop", "run");
out:
@@ -557,15 +557,15 @@ static void colo_process_checkpoint(MigrationState *s)
fb = qemu_file_new_output(QIO_CHANNEL(bioc));
object_unref(OBJECT(bioc));
- qemu_mutex_lock_iothread();
+ bql_lock();
replication_start_all(REPLICATION_MODE_PRIMARY, &local_err);
if (local_err) {
- qemu_mutex_unlock_iothread();
+ bql_unlock();
goto out;
}
vm_start();
- qemu_mutex_unlock_iothread();
+ bql_unlock();
trace_colo_vm_state_change("stop", "run");
timer_mod(s->colo_delay_timer, qemu_clock_get_ms(QEMU_CLOCK_HOST) +
@@ -639,14 +639,14 @@ out:
void migrate_start_colo_process(MigrationState *s)
{
- qemu_mutex_unlock_iothread();
+ bql_unlock();
qemu_event_init(&s->colo_checkpoint_event, false);
s->colo_delay_timer = timer_new_ms(QEMU_CLOCK_HOST,
colo_checkpoint_notify, s);
qemu_sem_init(&s->colo_exit_sem, 0);
colo_process_checkpoint(s);
- qemu_mutex_lock_iothread();
+ bql_lock();
}
static void colo_incoming_process_checkpoint(MigrationIncomingState *mis,
@@ -657,9 +657,9 @@ static void colo_incoming_process_checkpoint(MigrationIncomingState *mis,
Error *local_err = NULL;
int ret;
- qemu_mutex_lock_iothread();
+ bql_lock();
vm_stop_force_state(RUN_STATE_COLO);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
trace_colo_vm_state_change("run", "stop");
/* FIXME: This is unnecessary for periodic checkpoint mode */
@@ -677,10 +677,10 @@ static void colo_incoming_process_checkpoint(MigrationIncomingState *mis,
return;
}
- qemu_mutex_lock_iothread();
+ bql_lock();
cpu_synchronize_all_states();
ret = qemu_loadvm_state_main(mis->from_src_file, mis);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
if (ret < 0) {
error_setg(errp, "Load VM's live state (ram) error");
@@ -719,14 +719,14 @@ static void colo_incoming_process_checkpoint(MigrationIncomingState *mis,
return;
}
- qemu_mutex_lock_iothread();
+ bql_lock();
vmstate_loading = true;
colo_flush_ram_cache();
ret = qemu_load_device_state(fb);
if (ret < 0) {
error_setg(errp, "COLO: load device state failed");
vmstate_loading = false;
- qemu_mutex_unlock_iothread();
+ bql_unlock();
return;
}
@@ -734,7 +734,7 @@ static void colo_incoming_process_checkpoint(MigrationIncomingState *mis,
if (local_err) {
error_propagate(errp, local_err);
vmstate_loading = false;
- qemu_mutex_unlock_iothread();
+ bql_unlock();
return;
}
@@ -743,7 +743,7 @@ static void colo_incoming_process_checkpoint(MigrationIncomingState *mis,
if (local_err) {
error_propagate(errp, local_err);
vmstate_loading = false;
- qemu_mutex_unlock_iothread();
+ bql_unlock();
return;
}
/* Notify all filters of all NIC to do checkpoint */
@@ -752,13 +752,13 @@ static void colo_incoming_process_checkpoint(MigrationIncomingState *mis,
if (local_err) {
error_propagate(errp, local_err);
vmstate_loading = false;
- qemu_mutex_unlock_iothread();
+ bql_unlock();
return;
}
vmstate_loading = false;
vm_start();
- qemu_mutex_unlock_iothread();
+ bql_unlock();
trace_colo_vm_state_change("stop", "run");
if (failover_get_state() == FAILOVER_STATUS_RELAUNCH) {
@@ -851,14 +851,14 @@ static void *colo_process_incoming_thread(void *opaque)
fb = qemu_file_new_input(QIO_CHANNEL(bioc));
object_unref(OBJECT(bioc));
- qemu_mutex_lock_iothread();
+ bql_lock();
replication_start_all(REPLICATION_MODE_SECONDARY, &local_err);
if (local_err) {
- qemu_mutex_unlock_iothread();
+ bql_unlock();
goto out;
}
vm_start();
- qemu_mutex_unlock_iothread();
+ bql_unlock();
trace_colo_vm_state_change("stop", "run");
colo_send_message(mis->to_src_file, COLO_MESSAGE_CHECKPOINT_READY,
@@ -920,7 +920,7 @@ int coroutine_fn colo_incoming_co(void)
Error *local_err = NULL;
QemuThread th;
- assert(qemu_mutex_iothread_locked());
+ assert(bql_locked());
if (!migration_incoming_colo_enabled()) {
return 0;
@@ -940,10 +940,10 @@ int coroutine_fn colo_incoming_co(void)
qemu_coroutine_yield();
mis->colo_incoming_co = NULL;
- qemu_mutex_unlock_iothread();
+ bql_unlock();
/* Wait checkpoint incoming thread exit before free resource */
qemu_thread_join(&th);
- qemu_mutex_lock_iothread();
+ bql_lock();
/* We hold the global iothread lock, so it is safe here */
colo_release_ram_cache();
diff --git a/migration/dirtyrate.c b/migration/dirtyrate.c
index 62d86b8..1d2e857 100644
--- a/migration/dirtyrate.c
+++ b/migration/dirtyrate.c
@@ -90,13 +90,13 @@ static int64_t do_calculate_dirtyrate(DirtyPageRecord dirty_pages,
void global_dirty_log_change(unsigned int flag, bool start)
{
- qemu_mutex_lock_iothread();
+ bql_lock();
if (start) {
memory_global_dirty_log_start(flag);
} else {
memory_global_dirty_log_stop(flag);
}
- qemu_mutex_unlock_iothread();
+ bql_unlock();
}
/*
@@ -106,12 +106,12 @@ void global_dirty_log_change(unsigned int flag, bool start)
*/
static void global_dirty_log_sync(unsigned int flag, bool one_shot)
{
- qemu_mutex_lock_iothread();
+ bql_lock();
memory_global_dirty_log_sync(false);
if (one_shot) {
memory_global_dirty_log_stop(flag);
}
- qemu_mutex_unlock_iothread();
+ bql_unlock();
}
static DirtyPageRecord *vcpu_dirty_stat_alloc(VcpuStat *stat)
@@ -609,7 +609,7 @@ static void calculate_dirtyrate_dirty_bitmap(struct DirtyRateConfig config)
int64_t start_time;
DirtyPageRecord dirty_pages;
- qemu_mutex_lock_iothread();
+ bql_lock();
memory_global_dirty_log_start(GLOBAL_DIRTY_DIRTY_RATE);
/*
@@ -626,7 +626,7 @@ static void calculate_dirtyrate_dirty_bitmap(struct DirtyRateConfig config)
* KVM_DIRTY_LOG_MANUAL_PROTECT_ENABLE cap is enabled.
*/
dirtyrate_manual_reset_protect();
- qemu_mutex_unlock_iothread();
+ bql_unlock();
record_dirtypages_bitmap(&dirty_pages, true);
diff --git a/migration/migration.c b/migration/migration.c
index 454cd4e..be173cd 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -1283,12 +1283,12 @@ static void migrate_fd_cleanup(MigrationState *s)
QEMUFile *tmp;
trace_migrate_fd_cleanup();
- qemu_mutex_unlock_iothread();
+ bql_unlock();
if (s->migration_thread_running) {
qemu_thread_join(&s->thread);
s->migration_thread_running = false;
}
- qemu_mutex_lock_iothread();
+ bql_lock();
multifd_save_cleanup();
qemu_mutex_lock(&s->qemu_file_lock);
@@ -2396,7 +2396,7 @@ static int postcopy_start(MigrationState *ms, Error **errp)
}
trace_postcopy_start();
- qemu_mutex_lock_iothread();
+ bql_lock();
trace_postcopy_start_set_run();
migration_downtime_start(ms);
@@ -2504,7 +2504,7 @@ static int postcopy_start(MigrationState *ms, Error **errp)
migration_downtime_end(ms);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
if (migrate_postcopy_ram()) {
/*
@@ -2545,7 +2545,7 @@ fail:
error_report_err(local_err);
}
}
- qemu_mutex_unlock_iothread();
+ bql_unlock();
return -1;
}
@@ -2579,14 +2579,14 @@ static int migration_maybe_pause(MigrationState *s,
* wait for the 'pause_sem' semaphore.
*/
if (s->state != MIGRATION_STATUS_CANCELLING) {
- qemu_mutex_unlock_iothread();
+ bql_unlock();
migrate_set_state(&s->state, *current_active_state,
MIGRATION_STATUS_PRE_SWITCHOVER);
qemu_sem_wait(&s->pause_sem);
migrate_set_state(&s->state, MIGRATION_STATUS_PRE_SWITCHOVER,
new_state);
*current_active_state = new_state;
- qemu_mutex_lock_iothread();
+ bql_lock();
}
return s->state == new_state ? 0 : -EINVAL;
@@ -2597,7 +2597,7 @@ static int migration_completion_precopy(MigrationState *s,
{
int ret;
- qemu_mutex_lock_iothread();
+ bql_lock();
migration_downtime_start(s);
s->vm_old_state = runstate_get();
@@ -2624,7 +2624,7 @@ static int migration_completion_precopy(MigrationState *s,
ret = qemu_savevm_state_complete_precopy(s->to_dst_file, false,
s->block_inactive);
out_unlock:
- qemu_mutex_unlock_iothread();
+ bql_unlock();
return ret;
}
@@ -2632,9 +2632,9 @@ static void migration_completion_postcopy(MigrationState *s)
{
trace_migration_completion_postcopy_end();
- qemu_mutex_lock_iothread();
+ bql_lock();
qemu_savevm_state_complete_postcopy(s->to_dst_file);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
/*
* Shutdown the postcopy fast path thread. This is only needed when dest
@@ -2658,14 +2658,14 @@ static void migration_completion_failed(MigrationState *s,
*/
Error *local_err = NULL;
- qemu_mutex_lock_iothread();
+ bql_lock();
bdrv_activate_all(&local_err);
if (local_err) {
error_report_err(local_err);
} else {
s->block_inactive = false;
}
- qemu_mutex_unlock_iothread();
+ bql_unlock();
}
migrate_set_state(&s->state, current_active_state,
@@ -3105,7 +3105,7 @@ static void migration_iteration_finish(MigrationState *s)
/* If we enabled cpu throttling for auto-converge, turn it off. */
cpu_throttle_stop();
- qemu_mutex_lock_iothread();
+ bql_lock();
switch (s->state) {
case MIGRATION_STATUS_COMPLETED:
migration_calculate_complete(s);
@@ -3136,7 +3136,7 @@ static void migration_iteration_finish(MigrationState *s)
break;
}
migrate_fd_cleanup_schedule(s);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
}
static void bg_migration_iteration_finish(MigrationState *s)
@@ -3148,7 +3148,7 @@ static void bg_migration_iteration_finish(MigrationState *s)
*/
ram_write_tracking_stop();
- qemu_mutex_lock_iothread();
+ bql_lock();
switch (s->state) {
case MIGRATION_STATUS_COMPLETED:
migration_calculate_complete(s);
@@ -3167,7 +3167,7 @@ static void bg_migration_iteration_finish(MigrationState *s)
}
migrate_fd_cleanup_schedule(s);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
}
/*
@@ -3289,9 +3289,9 @@ static void *migration_thread(void *opaque)
object_ref(OBJECT(s));
update_iteration_initial_status(s);
- qemu_mutex_lock_iothread();
+ bql_lock();
qemu_savevm_state_header(s->to_dst_file);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
/*
* If we opened the return path, we need to make sure dst has it
@@ -3319,9 +3319,9 @@ static void *migration_thread(void *opaque)
qemu_savevm_send_colo_enable(s->to_dst_file);
}
- qemu_mutex_lock_iothread();
+ bql_lock();
qemu_savevm_state_setup(s->to_dst_file);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
qemu_savevm_wait_unplug(s, MIGRATION_STATUS_SETUP,
MIGRATION_STATUS_ACTIVE);
@@ -3432,10 +3432,10 @@ static void *bg_migration_thread(void *opaque)
ram_write_tracking_prepare();
#endif
- qemu_mutex_lock_iothread();
+ bql_lock();
qemu_savevm_state_header(s->to_dst_file);
qemu_savevm_state_setup(s->to_dst_file);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
qemu_savevm_wait_unplug(s, MIGRATION_STATUS_SETUP,
MIGRATION_STATUS_ACTIVE);
@@ -3445,7 +3445,7 @@ static void *bg_migration_thread(void *opaque)
trace_migration_thread_setup_complete();
migration_downtime_start(s);
- qemu_mutex_lock_iothread();
+ bql_lock();
s->vm_old_state = runstate_get();
@@ -3483,7 +3483,7 @@ static void *bg_migration_thread(void *opaque)
s->vm_start_bh = qemu_bh_new(bg_migration_vm_start_bh, s);
qemu_bh_schedule(s->vm_start_bh);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
while (migration_is_active(s)) {
MigIterateState iter_state = bg_migration_iteration_run(s);
@@ -3512,7 +3512,7 @@ fail:
if (early_fail) {
migrate_set_state(&s->state, MIGRATION_STATUS_ACTIVE,
MIGRATION_STATUS_FAILED);
- qemu_mutex_unlock_iothread();
+ bql_unlock();
}
bg_migration_iteration_finish(s);
diff --git a/migration/ram.c b/migration/ram.c
index 8c7886a..08dc7e2 100644
--- a/migration/ram.c
+++ b/migration/ram.c
@@ -2984,9 +2984,9 @@ static int ram_save_setup(QEMUFile *f, void *opaque)
migration_ops = g_malloc0(sizeof(MigrationOps));
migration_ops->ram_save_target_page = ram_save_target_page_legacy;
- qemu_mutex_unlock_iothread();
+ bql_unlock();
ret = multifd_send_sync_main(f);
- qemu_mutex_lock_iothread();
+ bql_lock();
if (ret < 0) {
return ret;
}
@@ -3221,11 +3221,11 @@ static void ram_state_pending_exact(void *opaque, uint64_t *must_precopy,
uint64_t remaining_size = rs->migration_dirty_pages * TARGET_PAGE_SIZE;
if (!migration_in_postcopy() && remaining_size < s->threshold_size) {
- qemu_mutex_lock_iothread();
+ bql_lock();
WITH_RCU_READ_LOCK_GUARD() {
migration_bitmap_sync_precopy(rs, false);
}
- qemu_mutex_unlock_iothread();
+ bql_unlock();
remaining_size = rs->migration_dirty_pages * TARGET_PAGE_SIZE;
}
@@ -3453,7 +3453,7 @@ void colo_incoming_start_dirty_log(void)
{
RAMBlock *block = NULL;
/* For memory_global_dirty_log_start below. */
- qemu_mutex_lock_iothread();
+ bql_lock();
qemu_mutex_lock_ramlist();
memory_global_dirty_log_sync(false);
@@ -3467,7 +3467,7 @@ void colo_incoming_start_dirty_log(void)
}
ram_state->migration_dirty_pages = 0;
qemu_mutex_unlock_ramlist();
- qemu_mutex_unlock_iothread();
+ bql_unlock();
}
/* It is need to hold the global lock to call this helper */