Skip to content

Commit cbad455

Browse files
committed
Merge tag 'migration-20241030-pull-request' of https://gitlab.com/peterx/qemu into staging
Migration pull request for softfreeze v2: - Patch "migration: Move cpu-throttle.c from system to migration", fix build on MacOS, and subject spelling NOTE: checkpatch.pl could report a false positive on this branch: WARNING: added, moved or deleted file(s), does MAINTAINERS need updating? #21: {include/sysemu => migration}/cpu-throttle.h | 0 That's covered by "F: migration/" entry. Changelog: - Peter's cleanup patch on migrate_fd_cleanup() - Peter's cleanup patch to introduce thread name macros - Hanna's error path fix for vmstate subsection save()s - Hyman's auto converge enhancement on background dirty sync - Peter's additional tracepoints for save state entries - Thomas's build fix for OpenBSD in dirtyrate.c - Peter's deprecation of query-migrationthreads command - Peter's cleanup/fixes from the "export misc.h" series - Maciej's two small patches from multifd+vfio series # -----BEGIN PGP SIGNATURE----- # # iIgEABYKADAWIQS5GE3CDMRX2s990ak7X8zN86vXBgUCZyTbVRIccGV0ZXJ4QHJl # ZGhhdC5jb20ACgkQO1/MzfOr1wan3wD+L4TVNDc34Hy4mvWu7u1lCOePX0GBdUEc # oEeBGblwbrcBAIR8d+5z9O5YcWH1coozG1aUC4qCtSHHk5TGbJk4/UUD # =XB5Q # -----END PGP SIGNATURE----- # gpg: Signature made Fri 01 Nov 2024 13:44:53 GMT # gpg: using EDDSA key B9184DC20CC457DACF7DD1A93B5FCCCDF3ABD706 # gpg: issuer "[email protected]" # gpg: Good signature from "Peter Xu <[email protected]>" [marginal] # gpg: aka "Peter Xu <[email protected]>" [marginal] # gpg: WARNING: This key is not certified with sufficiently trusted signatures! # gpg: It is not certain that the signature belongs to the owner. # Primary key fingerprint: B918 4DC2 0CC4 57DA CF7D D1A9 3B5F CCCD F3AB D706 * tag 'migration-20241030-pull-request' of https://gitlab.com/peterx/qemu: migration/multifd: Zero p->flags before starting filling a packet migration/ram: Add load start trace event migration: Drop migration_is_idle() migration: Drop migration_is_setup_or_active() migration: Unexport ram_mig_init() migration: Unexport dirty_bitmap_mig_init() migration: Take migration object refcount earlier for threads migration: Deprecate query-migrationthreads command migration/dirtyrate: Silence warning about strcpy() on OpenBSD tests/migration: Add case for periodic ramblock dirty sync migration: Support periodic RAMBlock dirty bitmap sync migration: Remove "rs" parameter in migration_bitmap_sync_precopy migration: Move cpu-throttle.c from system to migration migration: Stop CPU throttling conditionally accel/tcg/icount-common: Remove the reference to the unused header file migration: Ensure vmstate_save() sets errp migration: Put thread names together with macros migration: Cleanup migrate_fd_cleanup() on accessing to_dst_file Signed-off-by: Peter Maydell <[email protected]>
2 parents c94bee4 + 00b4b21 commit cbad455

26 files changed

+254
-122
lines changed

accel/tcg/icount-common.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
#include "sysemu/runstate.h"
3737
#include "hw/core/cpu.h"
3838
#include "sysemu/cpu-timers.h"
39-
#include "sysemu/cpu-throttle.h"
4039
#include "sysemu/cpu-timers-internal.h"
4140

4241
/*

docs/about/deprecated.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,14 @@ options are removed in favor of using explicit ``blockdev-create`` and
147147
``blockdev-add`` calls. See :doc:`/interop/live-block-operations` for
148148
details.
149149

150+
``query-migrationthreads`` (since 9.2)
151+
''''''''''''''''''''''''''''''''''''''
152+
153+
To be removed with no replacement, as it reports only a limited set of
154+
threads (for example, it only reports source side of multifd threads,
155+
without reporting any destination threads, or non-multifd source threads).
156+
For debugging purpose, please use ``-name $VM,debug-threads=on`` instead.
157+
150158
Incorrectly typed ``device_add`` arguments (since 6.2)
151159
''''''''''''''''''''''''''''''''''''''''''''''''''''''
152160

hw/vfio/common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ bool vfio_viommu_preset(VFIODevice *vbasedev)
149149

150150
static void vfio_set_migration_error(int ret)
151151
{
152-
if (migration_is_setup_or_active()) {
152+
if (migration_is_running()) {
153153
migration_file_set_error(ret, NULL);
154154
}
155155
}

hw/virtio/virtio-mem.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ static bool virtio_mem_is_busy(void)
188188
* after plugging them) until we're running on the destination (as we didn't
189189
* migrate these blocks when they were unplugged).
190190
*/
191-
return migration_in_incoming_postcopy() || !migration_is_idle();
191+
return migration_in_incoming_postcopy() || migration_is_running();
192192
}
193193

194194
typedef int (*virtio_mem_range_cb)(VirtIOMEM *vmem, void *arg,

include/migration/misc.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ void precopy_add_notifier(NotifierWithReturn *n);
3939
void precopy_remove_notifier(NotifierWithReturn *n);
4040
int precopy_notify(PrecopyNotifyReason reason, Error **errp);
4141

42-
void ram_mig_init(void);
4342
void qemu_guest_free_page_hint(void *addr, size_t len);
4443
bool migrate_ram_is_ignored(RAMBlock *block);
4544

@@ -53,11 +52,11 @@ void dump_vmstate_json_to_file(FILE *out_fp);
5352
/* migration/migration.c */
5453
void migration_object_init(void);
5554
void migration_shutdown(void);
56-
bool migration_is_idle(void);
55+
5756
bool migration_is_active(void);
5857
bool migration_is_device(void);
58+
bool migration_is_running(void);
5959
bool migration_thread_is_self(void);
60-
bool migration_is_setup_or_active(void);
6160

6261
typedef enum MigrationEventType {
6362
MIG_EVENT_PRECOPY_SETUP,
@@ -96,7 +95,6 @@ void migration_add_notifier_mode(NotifierWithReturn *notify,
9695
MigrationNotifyFunc func, MigMode mode);
9796

9897
void migration_remove_notifier(NotifierWithReturn *notify);
99-
bool migration_is_running(void);
10098
void migration_file_set_error(int ret, Error *err);
10199

102100
/* True if incoming migration entered POSTCOPY_INCOMING_DISCARD */
@@ -108,7 +106,4 @@ bool migration_incoming_postcopy_advised(void);
108106
/* True if background snapshot is active */
109107
bool migration_in_bg_snapshot(void);
110108

111-
/* migration/block-dirty-bitmap.c */
112-
void dirty_bitmap_mig_init(void);
113-
114109
#endif

include/sysemu/cpu-throttle.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,18 @@ bool cpu_throttle_active(void);
6565
*/
6666
int cpu_throttle_get_percentage(void);
6767

68+
/**
69+
* cpu_throttle_dirty_sync_timer_tick:
70+
*
71+
* Dirty sync timer hook.
72+
*/
73+
void cpu_throttle_dirty_sync_timer_tick(void *opaque);
74+
75+
/**
76+
* cpu_throttle_dirty_sync_timer:
77+
*
78+
* Start or stop the dirty sync timer.
79+
*/
80+
void cpu_throttle_dirty_sync_timer(bool enable);
81+
6882
#endif /* SYSEMU_CPU_THROTTLE_H */

migration/colo.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,8 @@ void coroutine_fn colo_incoming_co(void)
935935
assert(bql_locked());
936936
assert(migration_incoming_colo_enabled());
937937

938-
qemu_thread_create(&th, "mig/dst/colo", colo_process_incoming_thread,
938+
qemu_thread_create(&th, MIGRATION_THREAD_DST_COLO,
939+
colo_process_incoming_thread,
939940
mis, QEMU_THREAD_JOINABLE);
940941

941942
mis->colo_incoming_co = qemu_coroutine_self();

system/cpu-throttle.c renamed to migration/cpu-throttle.c

Lines changed: 69 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,23 @@
2828
#include "qemu/main-loop.h"
2929
#include "sysemu/cpus.h"
3030
#include "sysemu/cpu-throttle.h"
31+
#include "migration.h"
32+
#include "migration-stats.h"
3133
#include "trace.h"
3234

3335
/* vcpu throttling controls */
34-
static QEMUTimer *throttle_timer;
36+
static QEMUTimer *throttle_timer, *throttle_dirty_sync_timer;
3537
static unsigned int throttle_percentage;
38+
static bool throttle_dirty_sync_timer_active;
39+
static uint64_t throttle_dirty_sync_count_prev;
3640

3741
#define CPU_THROTTLE_PCT_MIN 1
3842
#define CPU_THROTTLE_PCT_MAX 99
3943
#define CPU_THROTTLE_TIMESLICE_NS 10000000
4044

45+
/* Making sure RAMBlock dirty bitmap is synchronized every five seconds */
46+
#define CPU_THROTTLE_DIRTY_SYNC_TIMESLICE_MS 5000
47+
4148
static void cpu_throttle_thread(CPUState *cpu, run_on_cpu_data opaque)
4249
{
4350
double pct;
@@ -112,6 +119,7 @@ void cpu_throttle_set(int new_throttle_pct)
112119
void cpu_throttle_stop(void)
113120
{
114121
qatomic_set(&throttle_percentage, 0);
122+
cpu_throttle_dirty_sync_timer(false);
115123
}
116124

117125
bool cpu_throttle_active(void)
@@ -124,8 +132,68 @@ int cpu_throttle_get_percentage(void)
124132
return qatomic_read(&throttle_percentage);
125133
}
126134

135+
void cpu_throttle_dirty_sync_timer_tick(void *opaque)
136+
{
137+
uint64_t sync_cnt = stat64_get(&mig_stats.dirty_sync_count);
138+
139+
/*
140+
* The first iteration copies all memory anyhow and has no
141+
* effect on guest performance, therefore omit it to avoid
142+
* paying extra for the sync penalty.
143+
*/
144+
if (sync_cnt <= 1) {
145+
goto end;
146+
}
147+
148+
if (sync_cnt == throttle_dirty_sync_count_prev) {
149+
trace_cpu_throttle_dirty_sync();
150+
WITH_RCU_READ_LOCK_GUARD() {
151+
migration_bitmap_sync_precopy(false);
152+
}
153+
}
154+
155+
end:
156+
throttle_dirty_sync_count_prev = stat64_get(&mig_stats.dirty_sync_count);
157+
158+
timer_mod(throttle_dirty_sync_timer,
159+
qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL_RT) +
160+
CPU_THROTTLE_DIRTY_SYNC_TIMESLICE_MS);
161+
}
162+
163+
static bool cpu_throttle_dirty_sync_active(void)
164+
{
165+
return qatomic_read(&throttle_dirty_sync_timer_active);
166+
}
167+
168+
void cpu_throttle_dirty_sync_timer(bool enable)
169+
{
170+
assert(throttle_dirty_sync_timer);
171+
172+
if (enable) {
173+
if (!cpu_throttle_dirty_sync_active()) {
174+
/*
175+
* Always reset the dirty sync count cache, in case migration
176+
* was cancelled once.
177+
*/
178+
throttle_dirty_sync_count_prev = 0;
179+
timer_mod(throttle_dirty_sync_timer,
180+
qemu_clock_get_ms(QEMU_CLOCK_VIRTUAL_RT) +
181+
CPU_THROTTLE_DIRTY_SYNC_TIMESLICE_MS);
182+
qatomic_set(&throttle_dirty_sync_timer_active, 1);
183+
}
184+
} else {
185+
if (cpu_throttle_dirty_sync_active()) {
186+
timer_del(throttle_dirty_sync_timer);
187+
qatomic_set(&throttle_dirty_sync_timer_active, 0);
188+
}
189+
}
190+
}
191+
127192
void cpu_throttle_init(void)
128193
{
129194
throttle_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL_RT,
130195
cpu_throttle_timer_tick, NULL);
196+
throttle_dirty_sync_timer =
197+
timer_new_ms(QEMU_CLOCK_VIRTUAL_RT,
198+
cpu_throttle_dirty_sync_timer_tick, NULL);
131199
}

migration/dirtyrate.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "sysemu/runstate.h"
3030
#include "exec/memory.h"
3131
#include "qemu/xxhash.h"
32+
#include "migration.h"
3233

3334
/*
3435
* total_dirty_pages is procted by BQL and is used
@@ -436,6 +437,7 @@ static void get_ramblock_dirty_info(RAMBlock *block,
436437
struct DirtyRateConfig *config)
437438
{
438439
uint64_t sample_pages_per_gigabytes = config->sample_pages_per_gigabytes;
440+
gsize len;
439441

440442
/* Right shift 30 bits to calc ramblock size in GB */
441443
info->sample_pages_count = (qemu_ram_get_used_length(block) *
@@ -444,7 +446,9 @@ static void get_ramblock_dirty_info(RAMBlock *block,
444446
info->ramblock_pages = qemu_ram_get_used_length(block) >>
445447
qemu_target_page_bits();
446448
info->ramblock_addr = qemu_ram_get_host_addr(block);
447-
strcpy(info->idstr, qemu_ram_get_idstr(block));
449+
len = g_strlcpy(info->idstr, qemu_ram_get_idstr(block),
450+
sizeof(info->idstr));
451+
g_assert(len < sizeof(info->idstr));
448452
}
449453

450454
static void free_ramblock_dirty_info(struct RamblockDirtyInfo *infos, int count)
@@ -839,8 +843,9 @@ void qmp_calc_dirty_rate(int64_t calc_time,
839843

840844
init_dirtyrate_stat(config);
841845

842-
qemu_thread_create(&thread, "get_dirtyrate", get_dirtyrate_thread,
843-
(void *)&config, QEMU_THREAD_DETACHED);
846+
qemu_thread_create(&thread, MIGRATION_THREAD_DIRTY_RATE,
847+
get_dirtyrate_thread, (void *)&config,
848+
QEMU_THREAD_DETACHED);
844849
}
845850

846851

migration/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ system_ss.add(files(
1313
'block-dirty-bitmap.c',
1414
'channel.c',
1515
'channel-block.c',
16+
'cpu-throttle.c',
1617
'dirtyrate.c',
1718
'exec.c',
1819
'fd.c',

0 commit comments

Comments
 (0)