migration patches for VFIO
cover migration patches for VFIO
Hi
VFIO migration has several requirements:
- the size of the state is only known when the guest is stopped
- they need to send possible lots of data.
this series only address the 1st set of problems.
What they do:
- res_compatible parameter was not used anywhere, just add that information to res_postcopy.
- Remove QEMUFILE parameter from save_live_pending
- Split save_live_pending into
* save_pending_estimate(): the pending state size without trying too hard
* save_pending_exact(): the real pending state size, it is called with the guest stopped.
- Now save_pending_* don't need the threshold parameter
- HACK a way to stop the guest before moving there.
ToDo:
- autoconverge test is broken, no real clue why, but it is possible that the test is wrong.
- Make an artifact to be able to send massive amount of data in the save state stage (probably more multifd channels).
- Be able to not having to start the guest between cheking the state pending size and migration_completion().
Please review.
Thanks, Juan.
Juan Quintela (7):
migration: Remove res_compatible parameter
migration: No save_live_pending() method uses the QEMUFile parameter
migration: Block migration comment or code is wrong
migration: Split save_live_pending() into state_pending_*
migration: Remove unused threshold_size parameter
migration: simplify migration_iteration_run()
migration: call qemu_savevm_state_pending_exact() with the guest
stopped
docs/devel/migration.rst | 18 ++++++------ docs/devel/vfio-migration.rst | 4 +-- include/migration/register.h | 29 ++++++++++--------- migration/savevm.h | 8 +++--- hw/s390x/s390-stattrib.c | 11 ++++--- hw/vfio/migration.c | 17 +++++------ migration/block-dirty-bitmap.c | 14 ++++----- migration/block.c | 17 ++++++----- migration/migration.c | 52 ++++++++++++++++++++++------------ migration/ram.c | 35 ++++++++++++++++------- migration/savevm.c | 37 +++++++++++++++++------- tests/qtest/migration-test.c | 3 +- hw/vfio/trace-events | 2 +- migration/trace-events | 7 +++-- 14 files changed, 148 insertions(+), 106 deletions(-)
Signature · 1 line
2.37.2
RFC 1/7 migration: Remove res_compatible parameter
It was only used for RAM, and in that case, it means that this amount of data was sent for memory. Just delete the field in all callers.
--- include/migration/register.h | 20 ++++++++++---------- migration/savevm.h | 4 +--- hw/s390x/s390-stattrib.c | 6 ++---- hw/vfio/migration.c | 10 ++++------ migration/block-dirty-bitmap.c | 7 +++---- migration/block.c | 7 +++---- migration/migration.c | 9 ++++----- migration/ram.c | 8 +++----- migration/savevm.c | 14 +++++--------- hw/vfio/trace-events | 2 +- migration/trace-events | 2 +- 11 files changed, 37 insertions(+), 52 deletions(-)
include/migration/register.h +10 -10
@@ -48,18 +48,18 @@ typedef struct SaveVMHandlers {int (*save_setup)(QEMUFile *f,void *opaque);void (*save_live_pending)(QEMUFile *f,void *opaque,uint64_t threshold_size, -uint64_t *res_precopy_only, -uint64_t *res_compatible, -uint64_t *res_postcopy_only); +uint64_t *rest_precopy, +uint64_t *rest_postcopy);/* Note for save_live_pending: -* - res_precopy_only is for data which must be migrated in precopy phase -* or in stopped state, in other words - before target vm start -* - res_compatible is for data which may be migrated in any phase -* - res_postcopy_only is for data which must be migrated in postcopy phase -* or in stopped state, in other words - after source vm stop +* - res_precopy is for data which must be migrated in precopy +* phase or in stopped state, in other words - before target +* vm start +* - res_postcopy is for data which must be migrated in postcopy +* phase or in stopped state, in other words - after source vm +* stop * -* Sum of res_postcopy_only, res_compatible and res_postcopy_only is the -* whole amount of pending data. +* Sum of res_precopy and res_postcopy is the whole amount of +* pending data. */
migration/savevm.h +1 -3
@@ -41,9 +41,7 @@ void qemu_savevm_state_complete_postcopy(QEMUFile *f);int qemu_savevm_state_complete_precopy (QEMUFile *f,bool iterable_only,bool inactivate_disks);void qemu_savevm_state_pending (QEMUFile *f,uint64_t max_size, -uint64_t *res_precopy_only, -uint64_t *res_compatible, -uint64_t *res_postcopy_only); +uint64_t *res_precopy,uint64_t *res_postcopy);void qemu_savevm_send_ping (QEMUFile *f,uint32_t value);void qemu_savevm_send_open_return_path (QEMUFile *f);int qemu_savevm_send_packaged (QEMUFile *f,const uint8_t *buf,size_t len);
hw/s390x/s390-stattrib.c +2 -4
@@ -183,16 +183,14 @@ static int cmma_save_setup(QEMUFile *f, void *opaque) }static void cmma_save_pending (QEMUFile *f,void *opaque,uint64_t max_size, -uint64_t *res_precopy_only, -uint64_t *res_compatible, -uint64_t *res_postcopy_only) +uint64_t *res_precopy,uint64_t *res_postcopy) {S390StAttribState *sas =S390_STATTRIB (opaque);S390StAttribClass *sac =S390_STATTRIB_GET_CLASS (sas);long long res = sac->get_dirtycount (sas);if (res >=0 ) { - *res_precopy_only += res; + *res_precopy += res; } }
hw/vfio/migration.c +4 -6
@@ -458,9 +458,8 @@ static void vfio_save_cleanup(void *opaque)static void vfio_save_pending (QEMUFile *f,void *opaque,uint64_t threshold_size, -uint64_t *res_precopy_only, -uint64_t *res_compatible, -uint64_t *res_postcopy_only) +uint64_t *res_precopy, +uint64_t *res_postcopy) {VFIODevice *vbasedev = opaque;VFIOMigration *migration = vbasedev->migration;
@@ -471,10 +470,9 @@ static void vfio_save_pending(QEMUFile *f, void *opaque,return ; } - *res_precopy_only += migration->pending_bytes; + *res_precopy += migration->pending_bytes; -trace_vfio_save_pending (vbasedev->name, *res_precopy_only, - *res_postcopy_only, *res_compatible); +trace_vfio_save_pending (vbasedev->name, *res_precopy, *res_postcopy); }static int vfio_save_iterate (QEMUFile *f,void *opaque)
migration/block-dirty-bitmap.c +3 -4
@@ -763,9 +763,8 @@ static int dirty_bitmap_save_complete(QEMUFile *f, void *opaque)static void dirty_bitmap_save_pending (QEMUFile *f,void *opaque,uint64_t max_size, -uint64_t *res_precopy_only, -uint64_t *res_compatible, -uint64_t *res_postcopy_only) +uint64_t *res_precopy, +uint64_t *res_postcopy) {DBMSaveState *s = &((DBMState *)opaque)->save;SaveBitmapState *dbms;
@@ -785,7 +784,7 @@ static void dirty_bitmap_save_pending(QEMUFile *f, void *opaque,trace_dirty_bitmap_save_pending (pending, max_size); - *res_postcopy_only += pending; + *res_postcopy += pending; }/* First occurrence of this bitmap. It should be created if doesn't exist */
migration/block.c +3 -4
@@ -863,9 +863,8 @@ static int block_save_complete(QEMUFile *f, void *opaque) }static void block_save_pending (QEMUFile *f,void *opaque,uint64_t max_size, -uint64_t *res_precopy_only, -uint64_t *res_compatible, -uint64_t *res_postcopy_only) +uint64_t *res_precopy, +uint64_t *res_postcopy) {/* Estimate pending number of bytes to send */ uint64_t pending;
@@ -886,7 +885,7 @@ static void block_save_pending(QEMUFile *f, void *opaque, uint64_t max_size,trace_migration_block_save_pending (pending);/* We don't do postcopy */ - *res_precopy_only += pending; + *res_precopy += pending; }static int block_load (QEMUFile *f,void *opaque,int version_id)
migration/migration.c +4 -5
@@ -3734,15 +3734,14 @@ typedef enum {*/ static MigIterateState migration_iteration_run (MigrationState *s) { -uint64_t pending_size, pend_pre, pend_compat, pend_post; +uint64_t pending_size, pend_pre, pend_post;bool in_postcopy = s->state ==MIGRATION_STATUS_POSTCOPY_ACTIVE ;qemu_savevm_state_pending (s->to_dst_file, s->threshold_size, &pend_pre, - &pend_compat, &pend_post); - pending_size = pend_pre + pend_compat + pend_post; + &pend_post); + pending_size = pend_pre + pend_post; -trace_migrate_pending (pending_size, s->threshold_size, - pend_pre, pend_compat, pend_post); +trace_migrate_pending (pending_size, s->threshold_size, pend_pre, pend_post);if (pending_size && pending_size >= s->threshold_size) {/* Still a significant amount to transfer */
migration/ram.c +3 -5
@@ -3435,9 +3435,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque) }static void ram_save_pending (QEMUFile *f,void *opaque,uint64_t max_size, -uint64_t *res_precopy_only, -uint64_t *res_compatible, -uint64_t *res_postcopy_only) +uint64_t *res_precopy,uint64_t *res_postcopy) {RAMState **temp = opaque;RAMState *rs = *temp;
@@ -3457,9 +3455,9 @@ static void ram_save_pending(QEMUFile *f, void *opaque, uint64_t max_size,if (migrate_postcopy_ram ()) {/* We can do postcopy, and all the data is postcopiable */ - *res_compatible += remaining_size; + *res_postcopy += remaining_size; }else { - *res_precopy_only += remaining_size; + *res_precopy += remaining_size; } }
migration/savevm.c +5 -9
@@ -1472,16 +1472,13 @@ flush:* for units that can't do postcopy. */ void qemu_savevm_state_pending (QEMUFile *f,uint64_t threshold_size, -uint64_t *res_precopy_only, -uint64_t *res_compatible, -uint64_t *res_postcopy_only) +uint64_t *res_precopy, +uint64_t *res_postcopy) {SaveStateEntry *se; - *res_precopy_only =0 ; - *res_compatible =0 ; - *res_postcopy_only =0 ; - + *res_precopy =0 ; + *res_postcopy =0 ; QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {if (!se->ops || !se->ops->save_live_pending) {
@@ -1493,8 +1490,7 @@ void qemu_savevm_state_pending(QEMUFile *f, uint64_t threshold_size, } } se->ops->save_live_pending (f, se->opaque, threshold_size, - res_precopy_only, res_compatible, - res_postcopy_only); + res_precopy, res_postcopy); } }
hw/vfio/trace-events +1 -1
@@ -157,7 +157,7 @@ vfio_save_cleanup(const char *name) " (%s)" vfio_save_buffer(const char *name, uint64_t data_offset, uint64_t data_size, uint64_t pending) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64" pending 0x%"PRIx64 vfio_update_pending(const char *name, uint64_t pending) " (%s) pending 0x%"PRIx64 vfio_save_device_config_state(const char *name) " (%s)" -vfio_save_pending(const char *name, uint64_t precopy, uint64_t postcopy, uint64_t compatible) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" compatible 0x%"PRIx64 +vfio_save_pending(const char *name, uint64_t precopy, uint64_t postcopy) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64 vfio_save_iterate(const char *name, int data_size) " (%s) data_size %d" vfio_save_complete_precopy(const char *name) " (%s)" vfio_load_device_config_state(const char *name) " (%s)"
migration/trace-events +1 -1
@@ -150,7 +150,7 @@ migrate_fd_cleanup(void) "" migrate_fd_error(const char *error_desc) "error=%s" migrate_fd_cancel(void) "" migrate_handle_rp_req_pages(const char *rbname, size_t start, size_t len) "in %s at 0x%zx len 0x%zx" -migrate_pending(uint64_t size, uint64_t max, uint64_t pre, uint64_t compat, uint64_t post) "pending size %" PRIu64 " max %" PRIu64 " (pre = %" PRIu64 " compat=%" PRIu64 " post=%" PRIu64 ")" +migrate_pending(uint64_t size, uint64_t max, uint64_t pre, uint64_t post) "pending size %" PRIu64 " max %" PRIu64 " (pre = %" PRIu64 " post=%" PRIu64 ")" migrate_send_rp_message(int msg_type, uint16_t len) "%d: len %d" migrate_send_rp_recv_bitmap(char *name, int64_t size) "block '%s' size 0x%"PRIi64 migration_completion_file_err(void) ""
Signature · 1 line
2.37.2
Re: [RFC 1/7] migration: Remove res_compatible parameter
Quoted 38 lines · * Juan Quintela ([email protected]) wrote:
It was only used for RAM, and in that case, it means that this amount of data was sent for memory. Just delete the field in all callers.
Signed-off-by Juan Quintela <[email protected]>--- include/migration/register.h | 20 ++++++++++---------- migration/savevm.h | 4 +--- hw/s390x/s390-stattrib.c | 6 ++---- hw/vfio/migration.c | 10 ++++------ migration/block-dirty-bitmap.c | 7 +++---- migration/block.c | 7 +++---- migration/migration.c | 9 ++++----- migration/ram.c | 8 +++----- migration/savevm.c | 14 +++++--------- hw/vfio/trace-events | 2 +- migration/trace-events | 2 +- 11 files changed, 37 insertions(+), 52 deletions(-)include/migration/register.h +3
-8@@ -48,18 +48,18 @@ typedef struct SaveVMHandlers {int (*save_setup)(QEMUFile *f,void *opaque);void (*save_live_pending)(QEMUFile *f,void *opaque,uint64_t threshold_size, -uint64_t *res_precopy_only, -uint64_t *res_compatible, -uint64_t *res_postcopy_only); +uint64_t *rest_precopy, +uint64_t *rest_postcopy);/* Note for save_live_pending: -* - res_precopy_only is for data which must be migrated in precopy phase -* or in stopped state, in other words - before target vm start -* - res_compatible is for data which may be migrated in any phase -* - res_postcopy_only is for data which must be migrated in postcopy phase -* or in stopped state, in other words - after source vm stop +* - res_precopy is for data which must be migrated in precopy
include/migration/register.h typedef struct SaveVMHandlers { · line 62
Quoted 10 lines
include/migration/register.h +7
-2+* phase or in stopped state, in other words - before target +* vm start +* - res_postcopy is for data which must be migrated in postcopy +* phase or in stopped state, in other words - after source vm +* stop * -* Sum of res_postcopy_only, res_compatible and res_postcopy_only is the -* whole amount of pending data. +* Sum of res_precopy and res_postcopy is the whole amount of +* pending data.
I'm not sure if this is correct; I think we really do have three different kinds of device:
a) Those that don't know how to postcopy
b) Those that can only send data in postcopy (which I think is what
the dirty-bitmap block stuff does)
c) Devices that know how to postcopy, like RAM
<snip>
Quoted 16 lines
migration/ram.c +1
-3@@ -3435,9 +3435,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque) }static void ram_save_pending (QEMUFile *f,void *opaque,uint64_t max_size, -uint64_t *res_precopy_only, -uint64_t *res_compatible, -uint64_t *res_postcopy_only) +uint64_t *res_precopy,uint64_t *res_postcopy) {RAMState **temp = opaque;RAMState *rs = *temp;
migration/ram.c static void ram_save_pending(QEMUFile *f, void *opaque, uint64_t max_size, · line 3458
Quoted 5 lines
migration/ram.c +1
-1@@ -3457,9 +3455,9 @@ static void ram_save_pending(QEMUFile *f, void *opaque, uint64_t max_size,if (migrate_postcopy_ram ()) {/* We can do postcopy, and all the data is postcopiable */ - *res_compatible += remaining_size; + *res_postcopy += remaining_size;
migrate_postcopy_ram() says that postcopy is enabled, not active, so here you are saying that ram is 'postcopy only' according to your definition above.
I don't think it actually changes behaviour though at the moment; but it doesn't feel right to assign that to something that says 'postcopy only' migration_iteration_run doesn't enforce the postcopy-only part very
hard; it's just part of the threshold as far as I can tell.
Dave
Quoted 95 lines
migration/ram.c +1
-1}else { - *res_precopy_only += remaining_size; + *res_precopy += remaining_size; } }migration/migration.c +4
-5@@ -3734,15 +3734,14 @@ typedef enum {*/ static MigIterateState migration_iteration_run (MigrationState *s) { -uint64_t pending_size, pend_pre, pend_compat, pend_post; +uint64_t pending_size, pend_pre, pend_post;bool in_postcopy = s->state ==MIGRATION_STATUS_POSTCOPY_ACTIVE ;qemu_savevm_state_pending (s->to_dst_file, s->threshold_size, &pend_pre, - &pend_compat, &pend_post); - pending_size = pend_pre + pend_compat + pend_post; + &pend_post); + pending_size = pend_pre + pend_post; -trace_migrate_pending (pending_size, s->threshold_size, - pend_pre, pend_compat, pend_post); +trace_migrate_pending (pending_size, s->threshold_size, pend_pre, pend_post);if (pending_size && pending_size >= s->threshold_size) {/* Still a significant amount to transfer */ migration/savevm.c +5
-9@@ -1472,16 +1472,13 @@ flush:* for units that can't do postcopy. */ void qemu_savevm_state_pending (QEMUFile *f,uint64_t threshold_size, -uint64_t *res_precopy_only, -uint64_t *res_compatible, -uint64_t *res_postcopy_only) +uint64_t *res_precopy, +uint64_t *res_postcopy) {SaveStateEntry *se; - *res_precopy_only =0 ; - *res_compatible =0 ; - *res_postcopy_only =0 ; - + *res_precopy =0 ; + *res_postcopy =0 ; QTAILQ_FOREACH(se, &savevm_state.handlers, entry) {if (!se->ops || !se->ops->save_live_pending) {@@ -1493,8 +1490,7 @@ void qemu_savevm_state_pending(QEMUFile *f, uint64_t threshold_size, } } se->ops->save_live_pending (f, se->opaque, threshold_size, - res_precopy_only, res_compatible, - res_postcopy_only); + res_precopy, res_postcopy); } }hw/vfio/trace-events +1
-1@@ -157,7 +157,7 @@ vfio_save_cleanup(const char *name) " (%s)" vfio_save_buffer(const char *name, uint64_t data_offset, uint64_t data_size, uint64_t pending) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64" pending 0x%"PRIx64 vfio_update_pending(const char *name, uint64_t pending) " (%s) pending 0x%"PRIx64 vfio_save_device_config_state(const char *name) " (%s)" -vfio_save_pending(const char *name, uint64_t precopy, uint64_t postcopy, uint64_t compatible) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64" compatible 0x%"PRIx64 +vfio_save_pending(const char *name, uint64_t precopy, uint64_t postcopy) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64 vfio_save_iterate(const char *name, int data_size) " (%s) data_size %d" vfio_save_complete_precopy(const char *name) " (%s)" vfio_load_device_config_state(const char *name) " (%s)"migration/trace-events +1
-1@@ -150,7 +150,7 @@ migrate_fd_cleanup(void) "" migrate_fd_error(const char *error_desc) "error=%s" migrate_fd_cancel(void) "" migrate_handle_rp_req_pages(const char *rbname, size_t start, size_t len) "in %s at 0x%zx len 0x%zx" -migrate_pending(uint64_t size, uint64_t max, uint64_t pre, uint64_t compat, uint64_t post) "pending size %" PRIu64 " max %" PRIu64 " (pre = %" PRIu64 " compat=%" PRIu64 " post=%" PRIu64 ")" +migrate_pending(uint64_t size, uint64_t max, uint64_t pre, uint64_t post) "pending size %" PRIu64 " max %" PRIu64 " (pre = %" PRIu64 " post=%" PRIu64 ")" migrate_send_rp_message(int msg_type, uint16_t len) "%d: len %d" migrate_send_rp_recv_bitmap(char *name, int64_t size) "block '%s' size 0x%"PRIi64 migration_completion_file_err(void) ""Signature · 1 line
2.37.2
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
RFC 2/7 migration: No save_live_pending() method uses the QEMUFile parameter
In reply to Juan QuintelaSo remove it everywhere.
--- include/migration/register.h | 6 ++---- migration/savevm.h | 2 +- hw/s390x/s390-stattrib.c | 2 +- hw/vfio/migration.c | 6 ++---- migration/block-dirty-bitmap.c | 5 ++--- migration/block.c | 2 +- migration/migration.c | 3 +-- migration/ram.c | 2 +- migration/savevm.c | 5 ++--- 9 files changed, 13 insertions(+), 20 deletions(-)
include/migration/register.h +2 -4
@@ -46,10 +46,8 @@ typedef struct SaveVMHandlers {/* This runs outside the iothread lock! */ int (*save_setup)(QEMUFile *f,void *opaque); -void (*save_live_pending)(QEMUFile *f,void *opaque, -uint64_t threshold_size, -uint64_t *rest_precopy, -uint64_t *rest_postcopy); +void (*save_live_pending)(void *opaque,uint64_t threshold_size, +uint64_t *rest_precopy,uint64_t *rest_postcopy);/* Note for save_live_pending: * - res_precopy is for data which must be migrated in precopy * phase or in stopped state, in other words - before target
migration/savevm.h +1 -1
@@ -40,7 +40,7 @@ void qemu_savevm_state_cleanup(void);void qemu_savevm_state_complete_postcopy (QEMUFile *f);int qemu_savevm_state_complete_precopy (QEMUFile *f,bool iterable_only,bool inactivate_disks); -void qemu_savevm_state_pending (QEMUFile *f,uint64_t max_size, +void qemu_savevm_state_pending (uint64_t max_size,uint64_t *res_precopy,uint64_t *res_postcopy);void qemu_savevm_send_ping (QEMUFile *f,uint32_t value);void qemu_savevm_send_open_return_path (QEMUFile *f);
hw/s390x/s390-stattrib.c +1 -1
@@ -182,7 +182,7 @@ static int cmma_save_setup(QEMUFile *f, void *opaque)return 0 ; } -static void cmma_save_pending (QEMUFile *f,void *opaque,uint64_t max_size, +static void cmma_save_pending (void *opaque,uint64_t max_size,uint64_t *res_precopy,uint64_t *res_postcopy) {S390StAttribState *sas =S390_STATTRIB (opaque);
hw/vfio/migration.c +2 -4
@@ -456,10 +456,8 @@ static void vfio_save_cleanup(void *opaque)trace_vfio_save_cleanup (vbasedev->name); } -static void vfio_save_pending (QEMUFile *f,void *opaque, -uint64_t threshold_size, -uint64_t *res_precopy, -uint64_t *res_postcopy) +static void vfio_save_pending (void *opaque,uint64_t threshold_size, +uint64_t *res_precopy,uint64_t *res_postcopy) {VFIODevice *vbasedev = opaque;VFIOMigration *migration = vbasedev->migration;
migration/block-dirty-bitmap.c +2 -3
@@ -761,9 +761,8 @@ static int dirty_bitmap_save_complete(QEMUFile *f, void *opaque)return 0 ; } -static void dirty_bitmap_save_pending (QEMUFile *f,void *opaque, -uint64_t max_size, -uint64_t *res_precopy, +static void dirty_bitmap_save_pending (void *opaque,uint64_t max_size, +uint64_t *res_precopy,uint64_t *res_postcopy) {DBMSaveState *s = &((DBMState *)opaque)->save;
migration/block.c +1 -1
@@ -862,7 +862,7 @@ static int block_save_complete(QEMUFile *f, void *opaque)return 0 ; } -static void block_save_pending (QEMUFile *f,void *opaque,uint64_t max_size, +static void block_save_pending (void *opaque,uint64_t max_size,uint64_t *res_precopy,uint64_t *res_postcopy) {
migration/migration.c +1 -2
@@ -3737,8 +3737,7 @@ static MigIterateState migration_iteration_run(MigrationState *s)uint64_t pending_size, pend_pre, pend_post;bool in_postcopy = s->state ==MIGRATION_STATUS_POSTCOPY_ACTIVE ; -qemu_savevm_state_pending (s->to_dst_file, s->threshold_size, &pend_pre, - &pend_post); +qemu_savevm_state_pending (s->threshold_size, &pend_pre, &pend_post); pending_size = pend_pre + pend_post;trace_migrate_pending (pending_size, s->threshold_size, pend_pre, pend_post);
migration/ram.c +1 -1
@@ -3434,7 +3434,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque)return 0 ; } -static void ram_save_pending (QEMUFile *f,void *opaque,uint64_t max_size, +static void ram_save_pending (void *opaque,uint64_t max_size,uint64_t *res_precopy,uint64_t *res_postcopy) {RAMState **temp = opaque;
migration/savevm.c +2 -3
@@ -1471,8 +1471,7 @@ flush:* the result is split into the amount for units that can and * for units that can't do postcopy. */ -void qemu_savevm_state_pending (QEMUFile *f,uint64_t threshold_size, -uint64_t *res_precopy, +void qemu_savevm_state_pending (uint64_t threshold_size,uint64_t *res_precopy,uint64_t *res_postcopy) {SaveStateEntry *se;
@@ -1489,7 +1488,7 @@ void qemu_savevm_state_pending(QEMUFile *f, uint64_t threshold_size,continue ; } } - se->ops->save_live_pending (f, se->opaque, threshold_size, + se->ops->save_live_pending (se->opaque, threshold_size, res_precopy, res_postcopy); } }
Signature · 1 line
2.37.2
Re: [RFC 2/7] migration: No save_live_pending() method uses the QEMUFile parameter
Quoted 3 lines · * Juan Quintela ([email protected]) wrote:
So remove it everywhere.
Signed-off-by Juan Quintela <[email protected]>
Quoted 155 lines
--- include/migration/register.h | 6 ++---- migration/savevm.h | 2 +- hw/s390x/s390-stattrib.c | 2 +- hw/vfio/migration.c | 6 ++---- migration/block-dirty-bitmap.c | 5 ++--- migration/block.c | 2 +- migration/migration.c | 3 +-- migration/ram.c | 2 +- migration/savevm.c | 5 ++--- 9 files changed, 13 insertions(+), 20 deletions(-)include/migration/register.h +2
-4@@ -46,10 +46,8 @@ typedef struct SaveVMHandlers {/* This runs outside the iothread lock! */ int (*save_setup)(QEMUFile *f,void *opaque); -void (*save_live_pending)(QEMUFile *f,void *opaque, -uint64_t threshold_size, -uint64_t *rest_precopy, -uint64_t *rest_postcopy); +void (*save_live_pending)(void *opaque,uint64_t threshold_size, +uint64_t *rest_precopy,uint64_t *rest_postcopy);/* Note for save_live_pending: * - res_precopy is for data which must be migrated in precopy * phase or in stopped state, in other words - before target migration/savevm.h +1
-1@@ -40,7 +40,7 @@ void qemu_savevm_state_cleanup(void);void qemu_savevm_state_complete_postcopy (QEMUFile *f);int qemu_savevm_state_complete_precopy (QEMUFile *f,bool iterable_only,bool inactivate_disks); -void qemu_savevm_state_pending (QEMUFile *f,uint64_t max_size, +void qemu_savevm_state_pending (uint64_t max_size,uint64_t *res_precopy,uint64_t *res_postcopy);void qemu_savevm_send_ping (QEMUFile *f,uint32_t value);void qemu_savevm_send_open_return_path (QEMUFile *f);hw/s390x/s390-stattrib.c +1
-1@@ -182,7 +182,7 @@ static int cmma_save_setup(QEMUFile *f, void *opaque)return 0 ; } -static void cmma_save_pending (QEMUFile *f,void *opaque,uint64_t max_size, +static void cmma_save_pending (void *opaque,uint64_t max_size,uint64_t *res_precopy,uint64_t *res_postcopy) {S390StAttribState *sas =S390_STATTRIB (opaque);hw/vfio/migration.c +2
-4@@ -456,10 +456,8 @@ static void vfio_save_cleanup(void *opaque)trace_vfio_save_cleanup (vbasedev->name); } -static void vfio_save_pending (QEMUFile *f,void *opaque, -uint64_t threshold_size, -uint64_t *res_precopy, -uint64_t *res_postcopy) +static void vfio_save_pending (void *opaque,uint64_t threshold_size, +uint64_t *res_precopy,uint64_t *res_postcopy) {VFIODevice *vbasedev = opaque;VFIOMigration *migration = vbasedev->migration;migration/block-dirty-bitmap.c +2
-3@@ -761,9 +761,8 @@ static int dirty_bitmap_save_complete(QEMUFile *f, void *opaque)return 0 ; } -static void dirty_bitmap_save_pending (QEMUFile *f,void *opaque, -uint64_t max_size, -uint64_t *res_precopy, +static void dirty_bitmap_save_pending (void *opaque,uint64_t max_size, +uint64_t *res_precopy,uint64_t *res_postcopy) {DBMSaveState *s = &((DBMState *)opaque)->save;migration/block.c +1
-1@@ -862,7 +862,7 @@ static int block_save_complete(QEMUFile *f, void *opaque)return 0 ; } -static void block_save_pending (QEMUFile *f,void *opaque,uint64_t max_size, +static void block_save_pending (void *opaque,uint64_t max_size,uint64_t *res_precopy,uint64_t *res_postcopy) {migration/migration.c +1
-2@@ -3737,8 +3737,7 @@ static MigIterateState migration_iteration_run(MigrationState *s)uint64_t pending_size, pend_pre, pend_post;bool in_postcopy = s->state ==MIGRATION_STATUS_POSTCOPY_ACTIVE ; -qemu_savevm_state_pending (s->to_dst_file, s->threshold_size, &pend_pre, - &pend_post); +qemu_savevm_state_pending (s->threshold_size, &pend_pre, &pend_post); pending_size = pend_pre + pend_post;trace_migrate_pending (pending_size, s->threshold_size, pend_pre, pend_post);migration/ram.c +1
-1@@ -3434,7 +3434,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque)return 0 ; } -static void ram_save_pending (QEMUFile *f,void *opaque,uint64_t max_size, +static void ram_save_pending (void *opaque,uint64_t max_size,uint64_t *res_precopy,uint64_t *res_postcopy) {RAMState **temp = opaque;migration/savevm.c +2
-3@@ -1471,8 +1471,7 @@ flush:* the result is split into the amount for units that can and * for units that can't do postcopy. */ -void qemu_savevm_state_pending (QEMUFile *f,uint64_t threshold_size, -uint64_t *res_precopy, +void qemu_savevm_state_pending (uint64_t threshold_size,uint64_t *res_precopy,uint64_t *res_postcopy) {SaveStateEntry *se;@@ -1489,7 +1488,7 @@ void qemu_savevm_state_pending(QEMUFile *f, uint64_t threshold_size,continue ; } } - se->ops->save_live_pending (f, se->opaque, threshold_size, + se->ops->save_live_pending (se->opaque, threshold_size, res_precopy, res_postcopy); } }Signature · 1 line
2.37.2
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
RFC 3/7 migration: Block migration comment or code is wrong
In reply to Juan QuintelaAnd it appears that what is wrong is the code. During bulk stage we need to make sure that some block is dirty, but no games with max_size at all.
--- migration/block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
migration/block.c +2 -2
@@ -879,8 +879,8 @@ static void block_save_pending(void *opaque, uint64_t max_size,blk_mig_unlock ();/* Report at least one block pending during bulk phase */ -if (pending <= max_size && !block_mig_state.bulk_completed) { - pending = max_size +BLK_MIG_BLOCK_SIZE ; +if (!pending && !block_mig_state.bulk_completed) { + pending =BLK_MIG_BLOCK_SIZE ; }trace_migration_block_save_pending (pending);
Signature · 1 line
2.37.2
Re: [RFC 3/7] migration: Block migration comment or code is wrong
Quoted 8 lines · Juan Quintela
And it appears that what is wrong is the code. During bulk stage we need to make sure that some block is dirty, but no games with
max_sizeat all.Signed-off-by Juan Quintela <[email protected]>--- migration/block.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
RFC 4/7 migration: Split save_live_pending() into state_pending_*
In reply to Juan QuintelaWe split the function into to:
- state_pending_estimate: We estimate the remaining state size without stopping the machine.
- state pending_exact: We calculate the exact amount of remaining state.
The only "device" that implements different functions for _estimate() and _exact() is ram.
--- docs/devel/migration.rst | 18 ++++++++++-------- docs/devel/vfio-migration.rst | 4 ++-- include/migration/register.h | 12 ++++++++---- migration/savevm.h | 8 ++++++-- hw/s390x/s390-stattrib.c | 7 ++++--- hw/vfio/migration.c | 9 +++++---- migration/block-dirty-bitmap.c | 11 ++++++----- migration/block.c | 11 ++++++----- migration/migration.c | 13 +++++++++---- migration/ram.c | 31 ++++++++++++++++++++++++------- migration/savevm.c | 34 +++++++++++++++++++++++++++++----- hw/vfio/trace-events | 2 +- migration/trace-events | 7 ++++--- 13 files changed, 114 insertions(+), 53 deletions(-)
docs/devel/migration.rst +10 -8
@@ -482,15 +482,17 @@ An iterative device must provide: - A ``load_setup`` function that initialises the data structures on the destination. - - A ``save_live_pending`` function that is called repeatedly and must - indicate how much more data the iterative data must save. The core - migration code will use this to determine when to pause the CPUs - and complete the migration. + - A ``state_pending_exact`` function that indicates how much more + data we must save. The core migration code will use this to + determine when to pause the CPUs and complete the migration. - - A ``save_live_iterate`` function (called after ``save_live_pending`` - when there is significant data still to be sent). It should send - a chunk of data until the point that stream bandwidth limits tell it - to stop. Each call generates one section. + - A ``state_pending_estimate`` function that indicates how much more + data we must save. When the estimated amount is smaller than the + threshold, we call ``state_pending_exact``. + + - A ``save_live_iterate`` function should send a chunk of data until + the point that stream bandwidth limits tell it to stop. Each call + generates one section. - A ``save_live_complete_precopy`` function that must transmit the last section for the device containing any remaining data.
docs/devel/vfio-migration.rst +2 -2
@@ -28,7 +28,7 @@ VFIO implements the device hooks for the iterative approach as follows: * A ``load_setup`` function that sets up the migration region on the destination and sets _RESUMING flag in the VFIO device state. -* A ``save_live_pending`` function that reads pending_bytes from the vendor +* A ``state_pending_exact`` function that reads pending_bytes from the vendor driver, which indicates the amount of data that the vendor driver has yet to save for the VFIO device.
@@ -114,7 +114,7 @@ Live migration save path (RUNNING, _SETUP, _RUNNING|_SAVING) | (RUNNING, _ACTIVE, _RUNNING|_SAVING) - If device is active, get pending_bytes by .save_live_pending() + If device is active, get pending_bytes by .state_pending_exact() If total pending_bytes >= threshold_size, call .save_live_iterate() Data of VFIO device for pre-copy phase is copied Iterate till total pending bytes converge and are less than threshold
include/migration/register.h +8 -4
@@ -46,9 +46,7 @@ typedef struct SaveVMHandlers {/* This runs outside the iothread lock! */ int (*save_setup)(QEMUFile *f,void *opaque); -void (*save_live_pending)(void *opaque,uint64_t threshold_size, -uint64_t *rest_precopy,uint64_t *rest_postcopy); -/* Note for save_live_pending: +/* Note for state_pending_*: * - res_precopy is for data which must be migrated in precopy * phase or in stopped state, in other words - before target * vm start
@@ -59,7 +57,13 @@ typedef struct SaveVMHandlers {* Sum of res_precopy and res_postcopy is the whole amount of * pending data. */ - +/* This calculate the exact remaining data to transfer */ +void (*state_pending_exact)(void *opaque,uint64_t threshold_size, +uint64_t *rest_precopy,uint64_t *rest_postcopy); +/* This estimates the remaining data to transfer */ +void (*state_pending_estimate)(void *opaque,uint64_t threshold_size, +uint64_t *rest_precopy, +uint64_t *rest_postcopy);LoadStateHandler *load_state;int (*load_setup)(QEMUFile *f,void *opaque);
migration/savevm.h +6 -2
@@ -40,8 +40,12 @@ void qemu_savevm_state_cleanup(void);void qemu_savevm_state_complete_postcopy (QEMUFile *f);int qemu_savevm_state_complete_precopy (QEMUFile *f,bool iterable_only,bool inactivate_disks); -void qemu_savevm_state_pending (uint64_t max_size, -uint64_t *res_precopy,uint64_t *res_postcopy); +void qemu_savevm_state_pending_exact (uint64_t max_size, +uint64_t *res_precopy, +uint64_t *res_postcopy); +void qemu_savevm_state_pending_estimate (uint64_t max_size, +uint64_t *res_precopy, +uint64_t *res_postcopy);void qemu_savevm_send_ping (QEMUFile *f,uint32_t value);void qemu_savevm_send_open_return_path (QEMUFile *f);int qemu_savevm_send_packaged (QEMUFile *f,const uint8_t *buf,size_t len);
hw/s390x/s390-stattrib.c +4 -3
@@ -182,8 +182,8 @@ static int cmma_save_setup(QEMUFile *f, void *opaque)return 0 ; } -static void cmma_save_pending (void *opaque,uint64_t max_size, -uint64_t *res_precopy,uint64_t *res_postcopy) +static void cmma_state_pending (void *opaque,uint64_t *res_precopy, +uint64_t *res_postcopy) {S390StAttribState *sas =S390_STATTRIB (opaque);S390StAttribClass *sac =S390_STATTRIB_GET_CLASS (sas);
@@ -369,7 +369,8 @@ static SaveVMHandlers savevm_s390_stattrib_handlers = { .save_setup = cmma_save_setup, .save_live_iterate = cmma_save_iterate, .save_live_complete_precopy = cmma_save_complete, - .save_live_pending = cmma_save_pending, + .state_pending_exact = cmma_state_pending, + .state_pending_estimate = cmma_state_pending, .save_cleanup = cmma_save_cleanup, .load_state = cmma_load, .is_active = cmma_active,
hw/vfio/migration.c +5 -4
@@ -456,8 +456,8 @@ static void vfio_save_cleanup(void *opaque)trace_vfio_save_cleanup (vbasedev->name); } -static void vfio_save_pending (void *opaque,uint64_t threshold_size, -uint64_t *res_precopy,uint64_t *res_postcopy) +static void vfio_state_pending (void *opaque,uint64_t threshold_size, +uint64_t *res_precopy,uint64_t *res_postcopy) {VFIODevice *vbasedev = opaque;VFIOMigration *migration = vbasedev->migration;
@@ -470,7 +470,7 @@ static void vfio_save_pending(void *opaque, uint64_t threshold_size, *res_precopy += migration->pending_bytes; -trace_vfio_save_pending (vbasedev->name, *res_precopy, *res_postcopy); +trace_vfio_state_pending (vbasedev->name, *res_precopy, *res_postcopy); }static int vfio_save_iterate (QEMUFile *f,void *opaque)
@@ -681,7 +681,8 @@ static int vfio_load_state(QEMUFile *f, void *opaque, int version_id)static SaveVMHandlers savevm_vfio_handlers = { .save_setup = vfio_save_setup, .save_cleanup = vfio_save_cleanup, - .save_live_pending = vfio_save_pending, + .state_pending_exact = vfio_state_pending, + .state_pending_estimate = vfio_state_pending, .save_live_iterate = vfio_save_iterate, .save_live_complete_precopy = vfio_save_complete_precopy, .save_state = vfio_save_state,
migration/block-dirty-bitmap.c +6 -5
@@ -761,9 +761,9 @@ static int dirty_bitmap_save_complete(QEMUFile *f, void *opaque)return 0 ; } -static void dirty_bitmap_save_pending (void *opaque,uint64_t max_size, -uint64_t *res_precopy, -uint64_t *res_postcopy) +static void dirty_bitmap_state_pending (void *opaque,uint64_t max_size, +uint64_t *res_precopy, +uint64_t *res_postcopy) {DBMSaveState *s = &((DBMState *)opaque)->save;SaveBitmapState *dbms;
@@ -781,7 +781,7 @@ static void dirty_bitmap_save_pending(void *opaque, uint64_t max_size,qemu_mutex_unlock_iothread (); -trace_dirty_bitmap_save_pending (pending, max_size); +trace_dirty_bitmap_state_pending (pending); *res_postcopy += pending; }
@@ -1250,7 +1250,8 @@ static SaveVMHandlers savevm_dirty_bitmap_handlers = { .save_live_complete_postcopy = dirty_bitmap_save_complete, .save_live_complete_precopy = dirty_bitmap_save_complete, .has_postcopy = dirty_bitmap_has_postcopy, - .save_live_pending = dirty_bitmap_save_pending, + .state_pending_exact = dirty_bitmap_state_pending, + .state_pending_estimate = dirty_bitmap_state_pending, .save_live_iterate = dirty_bitmap_save_iterate, .is_active_iterate = dirty_bitmap_is_active_iterate, .load_state = dirty_bitmap_load,
migration/block.c +6 -5
@@ -862,9 +862,9 @@ static int block_save_complete(QEMUFile *f, void *opaque)return 0 ; } -static void block_save_pending (void *opaque,uint64_t max_size, -uint64_t *res_precopy, -uint64_t *res_postcopy) +static void block_state_pending (void *opaque,uint64_t max_size, +uint64_t *res_precopy, +uint64_t *res_postcopy) {/* Estimate pending number of bytes to send */ uint64_t pending;
@@ -883,7 +883,7 @@ static void block_save_pending(void *opaque, uint64_t max_size, pending =BLK_MIG_BLOCK_SIZE ; } -trace_migration_block_save_pending (pending); +trace_migration_block_state_pending (pending);/* We don't do postcopy */ *res_precopy += pending; }
@@ -1018,7 +1018,8 @@ static SaveVMHandlers savevm_block_handlers = { .save_setup = block_save_setup, .save_live_iterate = block_save_iterate, .save_live_complete_precopy = block_save_complete, - .save_live_pending = block_save_pending, + .state_pending_exact = block_state_pending, + .state_pending_estimate = block_state_pending, .load_state = block_load, .save_cleanup = block_migration_cleanup, .is_active = block_is_active,
migration/migration.c +9 -4
@@ -3734,13 +3734,18 @@ typedef enum {*/ static MigIterateState migration_iteration_run (MigrationState *s) { -uint64_t pending_size, pend_pre, pend_post; +uint64_t pend_pre, pend_post;bool in_postcopy = s->state ==MIGRATION_STATUS_POSTCOPY_ACTIVE ; -qemu_savevm_state_pending (s->threshold_size, &pend_pre, &pend_post); - pending_size = pend_pre + pend_post; +qemu_savevm_state_pending_estimate (s->threshold_size, &pend_pre, &pend_post); +uint64_t pending_size = pend_pre + pend_post; +trace_migrate_pending_estimate (pending_size, s->threshold_size, pend_pre, pend_post); -trace_migrate_pending (pending_size, s->threshold_size, pend_pre, pend_post); +if (pend_pre <= s->threshold_size) { +qemu_savevm_state_pending_exact (s->threshold_size, &pend_pre, &pend_post); + pending_size = pend_pre + pend_post; +trace_migrate_pending_exact (pending_size, s->threshold_size, pend_pre, pend_post); + }if (pending_size && pending_size >= s->threshold_size) {/* Still a significant amount to transfer */
migration/ram.c +24 -7
@@ -3434,17 +3434,33 @@ static int ram_save_complete(QEMUFile *f, void *opaque)return 0 ; } -static void ram_save_pending (void *opaque,uint64_t max_size, -uint64_t *res_precopy,uint64_t *res_postcopy) +static void ram_state_pending_estimate (void *opaque,uint64_t max_size, +uint64_t *res_precopy, +uint64_t *res_postcopy) {RAMState **temp = opaque;RAMState *rs = *temp; -uint64_t remaining_size; - remaining_size = rs->migration_dirty_pages *TARGET_PAGE_SIZE ; +uint64_t remaining_size = rs->migration_dirty_pages *TARGET_PAGE_SIZE ; -if (!migration_in_postcopy () && - remaining_size < max_size) { +if (migrate_postcopy_ram ()) { +/* We can do postcopy, and all the data is postcopiable */ + *res_postcopy += remaining_size; + }else { + *res_precopy += remaining_size; + } +} + +static void ram_state_pending_exact (void *opaque,uint64_t max_size, +uint64_t *res_precopy, +uint64_t *res_postcopy) +{ +RAMState **temp = opaque; +RAMState *rs = *temp; + +uint64_t remaining_size = rs->migration_dirty_pages *TARGET_PAGE_SIZE ; + +if (!migration_in_postcopy ()) {qemu_mutex_lock_iothread (); WITH_RCU_READ_LOCK_GUARD() {migration_bitmap_sync_precopy (rs);
@@ -4600,7 +4616,8 @@ static SaveVMHandlers savevm_ram_handlers = { .save_live_complete_postcopy = ram_save_complete, .save_live_complete_precopy = ram_save_complete, .has_postcopy = ram_has_postcopy, - .save_live_pending = ram_save_pending, + .state_pending_exact = ram_state_pending_exact, + .state_pending_estimate = ram_state_pending_estimate, .load_state = ram_load, .save_cleanup = ram_save_cleanup, .load_setup = ram_load_setup,
migration/savevm.c +29 -5
@@ -1471,8 +1471,9 @@ flush:* the result is split into the amount for units that can and * for units that can't do postcopy. */ -void qemu_savevm_state_pending (uint64_t threshold_size,uint64_t *res_precopy, -uint64_t *res_postcopy) +void qemu_savevm_state_pending_exact (uint64_t threshold_size, +uint64_t *res_precopy, +uint64_t *res_postcopy) {SaveStateEntry *se;
@@ -1480,7 +1481,7 @@ void qemu_savevm_state_pending(uint64_t threshold_size, uint64_t *res_precopy, *res_postcopy =0 ; QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { -if (!se->ops || !se->ops->save_live_pending) { +if (!se->ops || !se->ops->state_pending_exact) {continue ; }if (se->ops->is_active) {
@@ -1488,8 +1489,31 @@ void qemu_savevm_state_pending(uint64_t threshold_size, uint64_t *res_precopy,continue ; } } - se->ops->save_live_pending (se->opaque, threshold_size, - res_precopy, res_postcopy); + se->ops->state_pending_exact (se->opaque, threshold_size, + res_precopy, res_postcopy); + } +} + +void qemu_savevm_state_pending_estimate (uint64_t threshold_size, +uint64_t *res_precopy, +uint64_t *res_postcopy) +{ +SaveStateEntry *se; + + *res_precopy =0 ; + *res_postcopy =0 ; + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { +if (!se->ops || !se->ops->state_pending_estimate) { +continue ; + } +if (se->ops->is_active) { +if (!se->ops->is_active (se->opaque)) { +continue ; + } + } + se->ops->state_pending_estimate (se->opaque, threshold_size, + res_precopy, res_postcopy); } }
hw/vfio/trace-events +1 -1
@@ -157,7 +157,7 @@ vfio_save_cleanup(const char *name) " (%s)" vfio_save_buffer(const char *name, uint64_t data_offset, uint64_t data_size, uint64_t pending) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64" pending 0x%"PRIx64 vfio_update_pending(const char *name, uint64_t pending) " (%s) pending 0x%"PRIx64 vfio_save_device_config_state(const char *name) " (%s)" -vfio_save_pending(const char *name, uint64_t precopy, uint64_t postcopy) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64 +vfio_state_pending(const char *name, uint64_t precopy, uint64_t postcopy) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64 vfio_save_iterate(const char *name, int data_size) " (%s) data_size %d" vfio_save_complete_precopy(const char *name) " (%s)" vfio_load_device_config_state(const char *name) " (%s)"
migration/trace-events +4 -3
@@ -150,7 +150,8 @@ migrate_fd_cleanup(void) "" migrate_fd_error(const char *error_desc) "error=%s" migrate_fd_cancel(void) "" migrate_handle_rp_req_pages(const char *rbname, size_t start, size_t len) "in %s at 0x%zx len 0x%zx" -migrate_pending(uint64_t size, uint64_t max, uint64_t pre, uint64_t post) "pending size %" PRIu64 " max %" PRIu64 " (pre = %" PRIu64 " post=%" PRIu64 ")" +migrate_pending_estimate(uint64_t size, uint64_t max, uint64_t pre, uint64_t post) "pending size %" PRIu64 " max %" PRIu64 " (pre = %" PRIu64 " post=%" PRIu64 ")" +migrate_pending_exact(uint64_t size, uint64_t max, uint64_t pre, uint64_t post) "pending size %" PRIu64 " max %" PRIu64 " (pre = %" PRIu64 " post=%" PRIu64 ")" migrate_send_rp_message(int msg_type, uint16_t len) "%d: len %d" migrate_send_rp_recv_bitmap(char *name, int64_t size) "block '%s' size 0x%"PRIi64 migration_completion_file_err(void) ""
@@ -330,7 +331,7 @@ send_bitmap_bits(uint32_t flags, uint64_t start_sector, uint32_t nr_sectors, uin dirty_bitmap_save_iterate(int in_postcopy) "in postcopy: %d" dirty_bitmap_save_complete_enter(void) "" dirty_bitmap_save_complete_finish(void) "" -dirty_bitmap_save_pending(uint64_t pending, uint64_t max_size) "pending %" PRIu64 " max: %" PRIu64 +dirty_bitmap_state_pending(uint64_t pending) "pending %" PRIu64 dirty_bitmap_load_complete(void) "" dirty_bitmap_load_bits_enter(uint64_t first_sector, uint32_t nr_sectors) "chunk: %" PRIu64 " %" PRIu32 dirty_bitmap_load_bits_zeroes(void) ""
@@ -355,7 +356,7 @@ migration_block_save_device_dirty(int64_t sector) "Error reading sector %" PRId6 migration_block_flush_blks(const char *action, int submitted, int read_done, int transferred) "%s submitted %d read_done %d transferred %d" migration_block_save(const char *mig_stage, int submitted, int transferred) "Enter save live %s submitted %d transferred %d" migration_block_save_complete(void) "Block migration completed" -migration_block_save_pending(uint64_t pending) "Enter save live pending %" PRIu64 +migration_block_state_pending(uint64_t pending) "Enter save live pending %" PRIu64 # page_cache.c migration_pagecache_init(int64_t max_num_items) "Setting cache buckets to %" PRId64
Signature · 1 line
2.37.2
Re: [RFC 4/7] migration: Split save_live_pending() into state_pending_*
Quoted 5 lines · * Juan Quintela ([email protected]) wrote:
We split the function into to:
-
state_pending_estimate: We estimate the remaining state size without stopping the machine.
Quoted 7 lines
- state
pending_exact: We calculate the exact amount of remaining state.The only "device" that implements different functions for
_estimate()and_exact()is ram.Signed-off-by Juan Quintela <[email protected]>
Yeh I think that's OK; I'm a little worried whether you end up calling the two functions in migration_iteration_run a lot, but still
Quoted 437 lines
--- docs/devel/migration.rst | 18 ++++++++++-------- docs/devel/vfio-migration.rst | 4 ++-- include/migration/register.h | 12 ++++++++---- migration/savevm.h | 8 ++++++-- hw/s390x/s390-stattrib.c | 7 ++++--- hw/vfio/migration.c | 9 +++++---- migration/block-dirty-bitmap.c | 11 ++++++----- migration/block.c | 11 ++++++----- migration/migration.c | 13 +++++++++---- migration/ram.c | 31 ++++++++++++++++++++++++------- migration/savevm.c | 34 +++++++++++++++++++++++++++++----- hw/vfio/trace-events | 2 +- migration/trace-events | 7 ++++--- 13 files changed, 114 insertions(+), 53 deletions(-)docs/devel/migration.rst +10
-8@@ -482,15 +482,17 @@ An iterative device must provide: - A ``load_setup`` function that initialises the data structures on the destination. - - A ``save_live_pending`` function that is called repeatedly and must - indicate how much more data the iterative data must save. The core - migration code will use this to determine when to pause the CPUs - and complete the migration. + - A ``state_pending_exact`` function that indicates how much more + data we must save. The core migration code will use this to + determine when to pause the CPUs and complete the migration. - - A ``save_live_iterate`` function (called after ``save_live_pending`` - when there is significant data still to be sent). It should send - a chunk of data until the point that stream bandwidth limits tell it - to stop. Each call generates one section. + - A ``state_pending_estimate`` function that indicates how much more + data we must save. When the estimated amount is smaller than the + threshold, we call ``state_pending_exact``. + + - A ``save_live_iterate`` function should send a chunk of data until + the point that stream bandwidth limits tell it to stop. Each call + generates one section. - A ``save_live_complete_precopy`` function that must transmit the last section for the device containing any remaining data.docs/devel/vfio-migration.rst +2
-2@@ -28,7 +28,7 @@ VFIO implements the device hooks for the iterative approach as follows: * A ``load_setup`` function that sets up the migration region on the destination and sets _RESUMING flag in the VFIO device state. -* A ``save_live_pending`` function that reads pending_bytes from the vendor +* A ``state_pending_exact`` function that reads pending_bytes from the vendor driver, which indicates the amount of data that the vendor driver has yet to save for the VFIO device.@@ -114,7 +114,7 @@ Live migration save path (RUNNING, _SETUP, _RUNNING|_SAVING) | (RUNNING, _ACTIVE, _RUNNING|_SAVING) - If device is active, get pending_bytes by .save_live_pending() + If device is active, get pending_bytes by .state_pending_exact() If total pending_bytes >= threshold_size, call .save_live_iterate() Data of VFIO device for pre-copy phase is copied Iterate till total pending bytes converge and are less than thresholdinclude/migration/register.h +8
-4@@ -46,9 +46,7 @@ typedef struct SaveVMHandlers {/* This runs outside the iothread lock! */ int (*save_setup)(QEMUFile *f,void *opaque); -void (*save_live_pending)(void *opaque,uint64_t threshold_size, -uint64_t *rest_precopy,uint64_t *rest_postcopy); -/* Note for save_live_pending: +/* Note for state_pending_*: * - res_precopy is for data which must be migrated in precopy * phase or in stopped state, in other words - before target * vm start @@ -59,7 +57,13 @@ typedef struct SaveVMHandlers {* Sum of res_precopy and res_postcopy is the whole amount of * pending data. */ - +/* This calculate the exact remaining data to transfer */ +void (*state_pending_exact)(void *opaque,uint64_t threshold_size, +uint64_t *rest_precopy,uint64_t *rest_postcopy); +/* This estimates the remaining data to transfer */ +void (*state_pending_estimate)(void *opaque,uint64_t threshold_size, +uint64_t *rest_precopy, +uint64_t *rest_postcopy);LoadStateHandler *load_state;int (*load_setup)(QEMUFile *f,void *opaque);migration/savevm.h +6
-2@@ -40,8 +40,12 @@ void qemu_savevm_state_cleanup(void);void qemu_savevm_state_complete_postcopy (QEMUFile *f);int qemu_savevm_state_complete_precopy (QEMUFile *f,bool iterable_only,bool inactivate_disks); -void qemu_savevm_state_pending (uint64_t max_size, -uint64_t *res_precopy,uint64_t *res_postcopy); +void qemu_savevm_state_pending_exact (uint64_t max_size, +uint64_t *res_precopy, +uint64_t *res_postcopy); +void qemu_savevm_state_pending_estimate (uint64_t max_size, +uint64_t *res_precopy, +uint64_t *res_postcopy);void qemu_savevm_send_ping (QEMUFile *f,uint32_t value);void qemu_savevm_send_open_return_path (QEMUFile *f);int qemu_savevm_send_packaged (QEMUFile *f,const uint8_t *buf,size_t len);hw/s390x/s390-stattrib.c +4
-3@@ -182,8 +182,8 @@ static int cmma_save_setup(QEMUFile *f, void *opaque)return 0 ; } -static void cmma_save_pending (void *opaque,uint64_t max_size, -uint64_t *res_precopy,uint64_t *res_postcopy) +static void cmma_state_pending (void *opaque,uint64_t *res_precopy, +uint64_t *res_postcopy) {S390StAttribState *sas =S390_STATTRIB (opaque);S390StAttribClass *sac =S390_STATTRIB_GET_CLASS (sas);@@ -369,7 +369,8 @@ static SaveVMHandlers savevm_s390_stattrib_handlers = { .save_setup = cmma_save_setup, .save_live_iterate = cmma_save_iterate, .save_live_complete_precopy = cmma_save_complete, - .save_live_pending = cmma_save_pending, + .state_pending_exact = cmma_state_pending, + .state_pending_estimate = cmma_state_pending, .save_cleanup = cmma_save_cleanup, .load_state = cmma_load, .is_active = cmma_active,hw/vfio/migration.c +5
-4@@ -456,8 +456,8 @@ static void vfio_save_cleanup(void *opaque)trace_vfio_save_cleanup (vbasedev->name); } -static void vfio_save_pending (void *opaque,uint64_t threshold_size, -uint64_t *res_precopy,uint64_t *res_postcopy) +static void vfio_state_pending (void *opaque,uint64_t threshold_size, +uint64_t *res_precopy,uint64_t *res_postcopy) {VFIODevice *vbasedev = opaque;VFIOMigration *migration = vbasedev->migration;@@ -470,7 +470,7 @@ static void vfio_save_pending(void *opaque, uint64_t threshold_size, *res_precopy += migration->pending_bytes; -trace_vfio_save_pending (vbasedev->name, *res_precopy, *res_postcopy); +trace_vfio_state_pending (vbasedev->name, *res_precopy, *res_postcopy); }static int vfio_save_iterate (QEMUFile *f,void *opaque)@@ -681,7 +681,8 @@ static int vfio_load_state(QEMUFile *f, void *opaque, int version_id)static SaveVMHandlers savevm_vfio_handlers = { .save_setup = vfio_save_setup, .save_cleanup = vfio_save_cleanup, - .save_live_pending = vfio_save_pending, + .state_pending_exact = vfio_state_pending, + .state_pending_estimate = vfio_state_pending, .save_live_iterate = vfio_save_iterate, .save_live_complete_precopy = vfio_save_complete_precopy, .save_state = vfio_save_state,migration/block-dirty-bitmap.c +6
-5@@ -761,9 +761,9 @@ static int dirty_bitmap_save_complete(QEMUFile *f, void *opaque)return 0 ; } -static void dirty_bitmap_save_pending (void *opaque,uint64_t max_size, -uint64_t *res_precopy, -uint64_t *res_postcopy) +static void dirty_bitmap_state_pending (void *opaque,uint64_t max_size, +uint64_t *res_precopy, +uint64_t *res_postcopy) {DBMSaveState *s = &((DBMState *)opaque)->save;SaveBitmapState *dbms;@@ -781,7 +781,7 @@ static void dirty_bitmap_save_pending(void *opaque, uint64_t max_size,qemu_mutex_unlock_iothread (); -trace_dirty_bitmap_save_pending (pending, max_size); +trace_dirty_bitmap_state_pending (pending); *res_postcopy += pending; }@@ -1250,7 +1250,8 @@ static SaveVMHandlers savevm_dirty_bitmap_handlers = { .save_live_complete_postcopy = dirty_bitmap_save_complete, .save_live_complete_precopy = dirty_bitmap_save_complete, .has_postcopy = dirty_bitmap_has_postcopy, - .save_live_pending = dirty_bitmap_save_pending, + .state_pending_exact = dirty_bitmap_state_pending, + .state_pending_estimate = dirty_bitmap_state_pending, .save_live_iterate = dirty_bitmap_save_iterate, .is_active_iterate = dirty_bitmap_is_active_iterate, .load_state = dirty_bitmap_load,migration/block.c +6
-5@@ -862,9 +862,9 @@ static int block_save_complete(QEMUFile *f, void *opaque)return 0 ; } -static void block_save_pending (void *opaque,uint64_t max_size, -uint64_t *res_precopy, -uint64_t *res_postcopy) +static void block_state_pending (void *opaque,uint64_t max_size, +uint64_t *res_precopy, +uint64_t *res_postcopy) {/* Estimate pending number of bytes to send */ uint64_t pending;@@ -883,7 +883,7 @@ static void block_save_pending(void *opaque, uint64_t max_size, pending =BLK_MIG_BLOCK_SIZE ; } -trace_migration_block_save_pending (pending); +trace_migration_block_state_pending (pending);/* We don't do postcopy */ *res_precopy += pending; }@@ -1018,7 +1018,8 @@ static SaveVMHandlers savevm_block_handlers = { .save_setup = block_save_setup, .save_live_iterate = block_save_iterate, .save_live_complete_precopy = block_save_complete, - .save_live_pending = block_save_pending, + .state_pending_exact = block_state_pending, + .state_pending_estimate = block_state_pending, .load_state = block_load, .save_cleanup = block_migration_cleanup, .is_active = block_is_active,migration/migration.c +9
-4@@ -3734,13 +3734,18 @@ typedef enum {*/ static MigIterateState migration_iteration_run (MigrationState *s) { -uint64_t pending_size, pend_pre, pend_post; +uint64_t pend_pre, pend_post;bool in_postcopy = s->state ==MIGRATION_STATUS_POSTCOPY_ACTIVE ; -qemu_savevm_state_pending (s->threshold_size, &pend_pre, &pend_post); - pending_size = pend_pre + pend_post; +qemu_savevm_state_pending_estimate (s->threshold_size, &pend_pre, &pend_post); +uint64_t pending_size = pend_pre + pend_post; +trace_migrate_pending_estimate (pending_size, s->threshold_size, pend_pre, pend_post); -trace_migrate_pending (pending_size, s->threshold_size, pend_pre, pend_post); +if (pend_pre <= s->threshold_size) { +qemu_savevm_state_pending_exact (s->threshold_size, &pend_pre, &pend_post); + pending_size = pend_pre + pend_post; +trace_migrate_pending_exact (pending_size, s->threshold_size, pend_pre, pend_post); + }if (pending_size && pending_size >= s->threshold_size) {/* Still a significant amount to transfer */ migration/ram.c +24
-7@@ -3434,17 +3434,33 @@ static int ram_save_complete(QEMUFile *f, void *opaque)return 0 ; } -static void ram_save_pending (void *opaque,uint64_t max_size, -uint64_t *res_precopy,uint64_t *res_postcopy) +static void ram_state_pending_estimate (void *opaque,uint64_t max_size, +uint64_t *res_precopy, +uint64_t *res_postcopy) {RAMState **temp = opaque;RAMState *rs = *temp; -uint64_t remaining_size; - remaining_size = rs->migration_dirty_pages *TARGET_PAGE_SIZE ; +uint64_t remaining_size = rs->migration_dirty_pages *TARGET_PAGE_SIZE ; -if (!migration_in_postcopy () && - remaining_size < max_size) { +if (migrate_postcopy_ram ()) { +/* We can do postcopy, and all the data is postcopiable */ + *res_postcopy += remaining_size; + }else { + *res_precopy += remaining_size; + } +} + +static void ram_state_pending_exact (void *opaque,uint64_t max_size, +uint64_t *res_precopy, +uint64_t *res_postcopy) +{ +RAMState **temp = opaque; +RAMState *rs = *temp; + +uint64_t remaining_size = rs->migration_dirty_pages *TARGET_PAGE_SIZE ; + +if (!migration_in_postcopy ()) {qemu_mutex_lock_iothread (); WITH_RCU_READ_LOCK_GUARD() {migration_bitmap_sync_precopy (rs);@@ -4600,7 +4616,8 @@ static SaveVMHandlers savevm_ram_handlers = { .save_live_complete_postcopy = ram_save_complete, .save_live_complete_precopy = ram_save_complete, .has_postcopy = ram_has_postcopy, - .save_live_pending = ram_save_pending, + .state_pending_exact = ram_state_pending_exact, + .state_pending_estimate = ram_state_pending_estimate, .load_state = ram_load, .save_cleanup = ram_save_cleanup, .load_setup = ram_load_setup,migration/savevm.c +29
-5@@ -1471,8 +1471,9 @@ flush:* the result is split into the amount for units that can and * for units that can't do postcopy. */ -void qemu_savevm_state_pending (uint64_t threshold_size,uint64_t *res_precopy, -uint64_t *res_postcopy) +void qemu_savevm_state_pending_exact (uint64_t threshold_size, +uint64_t *res_precopy, +uint64_t *res_postcopy) {SaveStateEntry *se;@@ -1480,7 +1481,7 @@ void qemu_savevm_state_pending(uint64_t threshold_size, uint64_t *res_precopy, *res_postcopy =0 ; QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { -if (!se->ops || !se->ops->save_live_pending) { +if (!se->ops || !se->ops->state_pending_exact) {continue ; }if (se->ops->is_active) {@@ -1488,8 +1489,31 @@ void qemu_savevm_state_pending(uint64_t threshold_size, uint64_t *res_precopy,continue ; } } - se->ops->save_live_pending (se->opaque, threshold_size, - res_precopy, res_postcopy); + se->ops->state_pending_exact (se->opaque, threshold_size, + res_precopy, res_postcopy); + } +} + +void qemu_savevm_state_pending_estimate (uint64_t threshold_size, +uint64_t *res_precopy, +uint64_t *res_postcopy) +{ +SaveStateEntry *se; + + *res_precopy =0 ; + *res_postcopy =0 ; + + QTAILQ_FOREACH(se, &savevm_state.handlers, entry) { +if (!se->ops || !se->ops->state_pending_estimate) { +continue ; + } +if (se->ops->is_active) { +if (!se->ops->is_active (se->opaque)) { +continue ; + } + } + se->ops->state_pending_estimate (se->opaque, threshold_size, + res_precopy, res_postcopy); } }hw/vfio/trace-events +1
-1@@ -157,7 +157,7 @@ vfio_save_cleanup(const char *name) " (%s)" vfio_save_buffer(const char *name, uint64_t data_offset, uint64_t data_size, uint64_t pending) " (%s) Offset 0x%"PRIx64" size 0x%"PRIx64" pending 0x%"PRIx64 vfio_update_pending(const char *name, uint64_t pending) " (%s) pending 0x%"PRIx64 vfio_save_device_config_state(const char *name) " (%s)" -vfio_save_pending(const char *name, uint64_t precopy, uint64_t postcopy) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64 +vfio_state_pending(const char *name, uint64_t precopy, uint64_t postcopy) " (%s) precopy 0x%"PRIx64" postcopy 0x%"PRIx64 vfio_save_iterate(const char *name, int data_size) " (%s) data_size %d" vfio_save_complete_precopy(const char *name) " (%s)" vfio_load_device_config_state(const char *name) " (%s)"migration/trace-events +4
-3@@ -150,7 +150,8 @@ migrate_fd_cleanup(void) "" migrate_fd_error(const char *error_desc) "error=%s" migrate_fd_cancel(void) "" migrate_handle_rp_req_pages(const char *rbname, size_t start, size_t len) "in %s at 0x%zx len 0x%zx" -migrate_pending(uint64_t size, uint64_t max, uint64_t pre, uint64_t post) "pending size %" PRIu64 " max %" PRIu64 " (pre = %" PRIu64 " post=%" PRIu64 ")" +migrate_pending_estimate(uint64_t size, uint64_t max, uint64_t pre, uint64_t post) "pending size %" PRIu64 " max %" PRIu64 " (pre = %" PRIu64 " post=%" PRIu64 ")" +migrate_pending_exact(uint64_t size, uint64_t max, uint64_t pre, uint64_t post) "pending size %" PRIu64 " max %" PRIu64 " (pre = %" PRIu64 " post=%" PRIu64 ")" migrate_send_rp_message(int msg_type, uint16_t len) "%d: len %d" migrate_send_rp_recv_bitmap(char *name, int64_t size) "block '%s' size 0x%"PRIi64 migration_completion_file_err(void) ""@@ -330,7 +331,7 @@ send_bitmap_bits(uint32_t flags, uint64_t start_sector, uint32_t nr_sectors, uin dirty_bitmap_save_iterate(int in_postcopy) "in postcopy: %d" dirty_bitmap_save_complete_enter(void) "" dirty_bitmap_save_complete_finish(void) "" -dirty_bitmap_save_pending(uint64_t pending, uint64_t max_size) "pending %" PRIu64 " max: %" PRIu64 +dirty_bitmap_state_pending(uint64_t pending) "pending %" PRIu64 dirty_bitmap_load_complete(void) "" dirty_bitmap_load_bits_enter(uint64_t first_sector, uint32_t nr_sectors) "chunk: %" PRIu64 " %" PRIu32 dirty_bitmap_load_bits_zeroes(void) ""@@ -355,7 +356,7 @@ migration_block_save_device_dirty(int64_t sector) "Error reading sector %" PRId6 migration_block_flush_blks(const char *action, int submitted, int read_done, int transferred) "%s submitted %d read_done %d transferred %d" migration_block_save(const char *mig_stage, int submitted, int transferred) "Enter save live %s submitted %d transferred %d" migration_block_save_complete(void) "Block migration completed" -migration_block_save_pending(uint64_t pending) "Enter save live pending %" PRIu64 +migration_block_state_pending(uint64_t pending) "Enter save live pending %" PRIu64 # page_cache.c migration_pagecache_init(int64_t max_num_items) "Setting cache buckets to %" PRId64Signature · 1 line
2.37.2
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
RFC 5/7 migration: Remove unused threshold_size parameter
In reply to Juan QuintelaUntil previous commit, save_live_pending() was used for ram. Now with the split into state_pending_estimate() and state_pending_exact() it is not needed anymore, so remove them.
--- include/migration/register.h | 7 +++---- migration/savevm.h | 6 ++---- hw/vfio/migration.c | 6 +++--- migration/block-dirty-bitmap.c | 3 +-- migration/block.c | 3 +-- migration/migration.c | 4 ++-- migration/ram.c | 6 ++---- migration/savevm.c | 12 ++++-------- 8 files changed, 18 insertions(+), 29 deletions(-)
include/migration/register.h +3 -4
@@ -58,11 +58,10 @@ typedef struct SaveVMHandlers {* pending data. */ /* This calculate the exact remaining data to transfer */ -void (*state_pending_exact)(void *opaque,uint64_t threshold_size, -uint64_t *rest_precopy,uint64_t *rest_postcopy); +void (*state_pending_exact)(void *opaque,uint64_t *rest_precopy, +uint64_t *rest_postcopy);/* This estimates the remaining data to transfer */ -void (*state_pending_estimate)(void *opaque,uint64_t threshold_size, -uint64_t *rest_precopy, +void (*state_pending_estimate)(void *opaque,uint64_t *rest_precopy,uint64_t *rest_postcopy);LoadStateHandler *load_state;
migration/savevm.h +2 -4
@@ -40,11 +40,9 @@ void qemu_savevm_state_cleanup(void);void qemu_savevm_state_complete_postcopy (QEMUFile *f);int qemu_savevm_state_complete_precopy (QEMUFile *f,bool iterable_only,bool inactivate_disks); -void qemu_savevm_state_pending_exact (uint64_t max_size, -uint64_t *res_precopy, +void qemu_savevm_state_pending_exact (uint64_t *res_precopy,uint64_t *res_postcopy); -void qemu_savevm_state_pending_estimate (uint64_t max_size, -uint64_t *res_precopy, +void qemu_savevm_state_pending_estimate (uint64_t *res_precopy,uint64_t *res_postcopy);void qemu_savevm_send_ping (QEMUFile *f,uint32_t value);void qemu_savevm_send_open_return_path (QEMUFile *f);
hw/vfio/migration.c +3 -3
@@ -456,8 +456,8 @@ static void vfio_save_cleanup(void *opaque)trace_vfio_save_cleanup (vbasedev->name); } -static void vfio_state_pending (void *opaque,uint64_t threshold_size, -uint64_t *res_precopy,uint64_t *res_postcopy) +static void vfio_state_pending (void *opaque,uint64_t *res_precopy, +uint64_t *res_postcopy) {VFIODevice *vbasedev = opaque;VFIOMigration *migration = vbasedev->migration;
@@ -511,7 +511,7 @@ static int vfio_save_iterate(QEMUFile *f, void *opaque) }/* -* Reset pending_bytes as .save_live_pending is not called during savevm or +* Reset pending_bytes as .state_pending_* is not called during savevm or * snapshot case, in such case vfio_update_pending() at the start of this * function updates pending_bytes. */
migration/block-dirty-bitmap.c +1 -2
@@ -761,8 +761,7 @@ static int dirty_bitmap_save_complete(QEMUFile *f, void *opaque)return 0 ; } -static void dirty_bitmap_state_pending (void *opaque,uint64_t max_size, -uint64_t *res_precopy, +static void dirty_bitmap_state_pending (void *opaque,uint64_t *res_precopy,uint64_t *res_postcopy) {DBMSaveState *s = &((DBMState *)opaque)->save;
migration/block.c +1 -2
@@ -862,8 +862,7 @@ static int block_save_complete(QEMUFile *f, void *opaque)return 0 ; } -static void block_state_pending (void *opaque,uint64_t max_size, -uint64_t *res_precopy, +static void block_state_pending (void *opaque,uint64_t *res_precopy,uint64_t *res_postcopy) {/* Estimate pending number of bytes to send */
migration/migration.c +2 -2
@@ -3737,12 +3737,12 @@ static MigIterateState migration_iteration_run(MigrationState *s)uint64_t pend_pre, pend_post;bool in_postcopy = s->state ==MIGRATION_STATUS_POSTCOPY_ACTIVE ; -qemu_savevm_state_pending_estimate (s->threshold_size, &pend_pre, &pend_post); +qemu_savevm_state_pending_estimate (&pend_pre, &pend_post);uint64_t pending_size = pend_pre + pend_post;trace_migrate_pending_estimate (pending_size, s->threshold_size, pend_pre, pend_post);if (pend_pre <= s->threshold_size) { -qemu_savevm_state_pending_exact (s->threshold_size, &pend_pre, &pend_post); +qemu_savevm_state_pending_exact (&pend_pre, &pend_post); pending_size = pend_pre + pend_post;trace_migrate_pending_exact (pending_size, s->threshold_size, pend_pre, pend_post); }
migration/ram.c +2 -4
@@ -3434,8 +3434,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque)return 0 ; } -static void ram_state_pending_estimate (void *opaque,uint64_t max_size, -uint64_t *res_precopy, +static void ram_state_pending_estimate (void *opaque,uint64_t *res_precopy,uint64_t *res_postcopy) {RAMState **temp = opaque;
@@ -3451,8 +3450,7 @@ static void ram_state_pending_estimate(void *opaque, uint64_t max_size, } } -static void ram_state_pending_exact (void *opaque,uint64_t max_size, -uint64_t *res_precopy, +static void ram_state_pending_exact (void *opaque,uint64_t *res_precopy,uint64_t *res_postcopy) {RAMState **temp = opaque;
migration/savevm.c +4 -8
@@ -1471,8 +1471,7 @@ flush:* the result is split into the amount for units that can and * for units that can't do postcopy. */ -void qemu_savevm_state_pending_exact (uint64_t threshold_size, -uint64_t *res_precopy, +void qemu_savevm_state_pending_exact (uint64_t *res_precopy,uint64_t *res_postcopy) {SaveStateEntry *se;
@@ -1489,13 +1488,11 @@ void qemu_savevm_state_pending_exact(uint64_t threshold_size,continue ; } } - se->ops->state_pending_exact (se->opaque, threshold_size, - res_precopy, res_postcopy); + se->ops->state_pending_exact (se->opaque, res_precopy, res_postcopy); } } -void qemu_savevm_state_pending_estimate (uint64_t threshold_size, -uint64_t *res_precopy, +void qemu_savevm_state_pending_estimate (uint64_t *res_precopy,uint64_t *res_postcopy) {SaveStateEntry *se;
@@ -1512,8 +1509,7 @@ void qemu_savevm_state_pending_estimate(uint64_t threshold_size,continue ; } } - se->ops->state_pending_estimate (se->opaque, threshold_size, - res_precopy, res_postcopy); + se->ops->state_pending_estimate (se->opaque, res_precopy, res_postcopy); } }
Signature · 1 line
2.37.2
Re: [RFC 5/7] migration: Remove unused threshold_size parameter
Quoted 69 lines · * Juan Quintela ([email protected]) wrote:
Until previous commit,
save_live_pending()was used for ram. Now with the split intostate_pending_estimate()andstate_pending_exact()it is not needed anymore, so remove them.Signed-off-by Juan Quintela <[email protected]>--- include/migration/register.h | 7 +++---- migration/savevm.h | 6 ++---- hw/vfio/migration.c | 6 +++--- migration/block-dirty-bitmap.c | 3 +-- migration/block.c | 3 +-- migration/migration.c | 4 ++-- migration/ram.c | 6 ++---- migration/savevm.c | 12 ++++-------- 8 files changed, 18 insertions(+), 29 deletions(-)include/migration/register.h +3
-4@@ -58,11 +58,10 @@ typedef struct SaveVMHandlers {* pending data. */ /* This calculate the exact remaining data to transfer */ -void (*state_pending_exact)(void *opaque,uint64_t threshold_size, -uint64_t *rest_precopy,uint64_t *rest_postcopy); +void (*state_pending_exact)(void *opaque,uint64_t *rest_precopy, +uint64_t *rest_postcopy);/* This estimates the remaining data to transfer */ -void (*state_pending_estimate)(void *opaque,uint64_t threshold_size, -uint64_t *rest_precopy, +void (*state_pending_estimate)(void *opaque,uint64_t *rest_precopy,uint64_t *rest_postcopy);LoadStateHandler *load_state;migration/savevm.h +2
-4@@ -40,11 +40,9 @@ void qemu_savevm_state_cleanup(void);void qemu_savevm_state_complete_postcopy (QEMUFile *f);int qemu_savevm_state_complete_precopy (QEMUFile *f,bool iterable_only,bool inactivate_disks); -void qemu_savevm_state_pending_exact (uint64_t max_size, -uint64_t *res_precopy, +void qemu_savevm_state_pending_exact (uint64_t *res_precopy,uint64_t *res_postcopy); -void qemu_savevm_state_pending_estimate (uint64_t max_size, -uint64_t *res_precopy, +void qemu_savevm_state_pending_estimate (uint64_t *res_precopy,uint64_t *res_postcopy);void qemu_savevm_send_ping (QEMUFile *f,uint32_t value);void qemu_savevm_send_open_return_path (QEMUFile *f);hw/vfio/migration.c +2
-2@@ -456,8 +456,8 @@ static void vfio_save_cleanup(void *opaque)trace_vfio_save_cleanup (vbasedev->name); } -static void vfio_state_pending (void *opaque,uint64_t threshold_size, -uint64_t *res_precopy,uint64_t *res_postcopy) +static void vfio_state_pending (void *opaque,uint64_t *res_precopy, +uint64_t *res_postcopy) {VFIODevice *vbasedev = opaque;VFIOMigration *migration = vbasedev->migration;
hw/vfio/migration.c static int vfio_save_iterate(QEMUFile *f, void *opaque) · line 514
Quoted 5 lines
hw/vfio/migration.c +1
-1@@ -511,7 +511,7 @@ static int vfio_save_iterate(QEMUFile *f, void *opaque) }/* -* Reset pending_bytes as .save_live_pending is not called during savevm or +* Reset pending_bytes as .state_pending_* is not called during savevm or
That comment change feels like it lives in a different patch, other than that:
Quoted 118 lines
hw/vfio/migration.c +0
-0* snapshot case, in such case vfio_update_pending() at the start of this * function updates pending_bytes. */ migration/block-dirty-bitmap.c +1
-2@@ -761,8 +761,7 @@ static int dirty_bitmap_save_complete(QEMUFile *f, void *opaque)return 0 ; } -static void dirty_bitmap_state_pending (void *opaque,uint64_t max_size, -uint64_t *res_precopy, +static void dirty_bitmap_state_pending (void *opaque,uint64_t *res_precopy,uint64_t *res_postcopy) {DBMSaveState *s = &((DBMState *)opaque)->save;migration/block.c +1
-2@@ -862,8 +862,7 @@ static int block_save_complete(QEMUFile *f, void *opaque)return 0 ; } -static void block_state_pending (void *opaque,uint64_t max_size, -uint64_t *res_precopy, +static void block_state_pending (void *opaque,uint64_t *res_precopy,uint64_t *res_postcopy) {/* Estimate pending number of bytes to send */ migration/migration.c +2
-2@@ -3737,12 +3737,12 @@ static MigIterateState migration_iteration_run(MigrationState *s)uint64_t pend_pre, pend_post;bool in_postcopy = s->state ==MIGRATION_STATUS_POSTCOPY_ACTIVE ; -qemu_savevm_state_pending_estimate (s->threshold_size, &pend_pre, &pend_post); +qemu_savevm_state_pending_estimate (&pend_pre, &pend_post);uint64_t pending_size = pend_pre + pend_post;trace_migrate_pending_estimate (pending_size, s->threshold_size, pend_pre, pend_post);if (pend_pre <= s->threshold_size) { -qemu_savevm_state_pending_exact (s->threshold_size, &pend_pre, &pend_post); +qemu_savevm_state_pending_exact (&pend_pre, &pend_post); pending_size = pend_pre + pend_post;trace_migrate_pending_exact (pending_size, s->threshold_size, pend_pre, pend_post); }migration/ram.c +2
-4@@ -3434,8 +3434,7 @@ static int ram_save_complete(QEMUFile *f, void *opaque)return 0 ; } -static void ram_state_pending_estimate (void *opaque,uint64_t max_size, -uint64_t *res_precopy, +static void ram_state_pending_estimate (void *opaque,uint64_t *res_precopy,uint64_t *res_postcopy) {RAMState **temp = opaque;@@ -3451,8 +3450,7 @@ static void ram_state_pending_estimate(void *opaque, uint64_t max_size, } } -static void ram_state_pending_exact (void *opaque,uint64_t max_size, -uint64_t *res_precopy, +static void ram_state_pending_exact (void *opaque,uint64_t *res_precopy,uint64_t *res_postcopy) {RAMState **temp = opaque;migration/savevm.c +4
-8@@ -1471,8 +1471,7 @@ flush:* the result is split into the amount for units that can and * for units that can't do postcopy. */ -void qemu_savevm_state_pending_exact (uint64_t threshold_size, -uint64_t *res_precopy, +void qemu_savevm_state_pending_exact (uint64_t *res_precopy,uint64_t *res_postcopy) {SaveStateEntry *se;@@ -1489,13 +1488,11 @@ void qemu_savevm_state_pending_exact(uint64_t threshold_size,continue ; } } - se->ops->state_pending_exact (se->opaque, threshold_size, - res_precopy, res_postcopy); + se->ops->state_pending_exact (se->opaque, res_precopy, res_postcopy); } } -void qemu_savevm_state_pending_estimate (uint64_t threshold_size, -uint64_t *res_precopy, +void qemu_savevm_state_pending_estimate (uint64_t *res_precopy,uint64_t *res_postcopy) {SaveStateEntry *se;@@ -1512,8 +1509,7 @@ void qemu_savevm_state_pending_estimate(uint64_t threshold_size,continue ; } } - se->ops->state_pending_estimate (se->opaque, threshold_size, - res_precopy, res_postcopy); + se->ops->state_pending_estimate (se->opaque, res_precopy, res_postcopy); } }Signature · 1 line
2.37.2
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
RFC 6/7 migration: simplify migration_iteration_run()
In reply to Juan Quintela--- migration/migration.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)
migration/migration.c +12 -12
@@ -3747,23 +3747,23 @@ static MigIterateState migration_iteration_run(MigrationState *s)trace_migrate_pending_exact (pending_size, s->threshold_size, pend_pre, pend_post); } -if (pending_size && pending_size >= s->threshold_size) { -/* Still a significant amount to transfer */ -if (!in_postcopy && pend_pre <= s->threshold_size && -qatomic_read (&s->start_postcopy)) { -if (postcopy_start (s)) { -error_report ("%s: postcopy failed to start" , __func__); - } -return MIG_ITERATE_SKIP ; - } -/* Just another iteration step */ -qemu_savevm_state_iterate (s->to_dst_file, in_postcopy); - }else { +if (pending_size < s->threshold_size) {trace_migration_thread_low_pending (pending_size);migration_completion (s);return MIG_ITERATE_BREAK ; } +/* Still a significant amount to transfer */ +if (!in_postcopy && pend_pre <= s->threshold_size && +qatomic_read (&s->start_postcopy)) { +if (postcopy_start (s)) { +error_report ("%s: postcopy failed to start" , __func__); + } +return MIG_ITERATE_SKIP ; + } + +/* Just another iteration step */ +qemu_savevm_state_iterate (s->to_dst_file, in_postcopy);return MIG_ITERATE_RESUME ; }
Signature · 1 line
2.37.2
Re: [RFC 6/7] migration: simplify migration_iteration_run()
Quoted 1 line · * Juan Quintela ([email protected]) wrote:
Signed-off-by Juan Quintela <[email protected]>
Quoted 48 lines
--- migration/migration.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-)migration/migration.c +12
-12@@ -3747,23 +3747,23 @@ static MigIterateState migration_iteration_run(MigrationState *s)trace_migrate_pending_exact (pending_size, s->threshold_size, pend_pre, pend_post); } -if (pending_size && pending_size >= s->threshold_size) { -/* Still a significant amount to transfer */ -if (!in_postcopy && pend_pre <= s->threshold_size && -qatomic_read (&s->start_postcopy)) { -if (postcopy_start (s)) { -error_report ("%s: postcopy failed to start" , __func__); - } -return MIG_ITERATE_SKIP ; - } -/* Just another iteration step */ -qemu_savevm_state_iterate (s->to_dst_file, in_postcopy); - }else { +if (pending_size < s->threshold_size) {trace_migration_thread_low_pending (pending_size);migration_completion (s);return MIG_ITERATE_BREAK ; } +/* Still a significant amount to transfer */ +if (!in_postcopy && pend_pre <= s->threshold_size && +qatomic_read (&s->start_postcopy)) { +if (postcopy_start (s)) { +error_report ("%s: postcopy failed to start" , __func__); + } +return MIG_ITERATE_SKIP ; + } + +/* Just another iteration step */ +qemu_savevm_state_iterate (s->to_dst_file, in_postcopy);return MIG_ITERATE_RESUME ; }Signature · 1 line
2.37.2
Signature · 1 line
Dr. David Alan Gilbert / [email protected] / Manchester, UK
RFC 7/7 migration: call qemu_savevm_state_pending_exact() with the guest stopped
In reply to Juan QuintelaHACK ahead.
There are devices that require the guest to be stopped to tell us what is the size of its state. So we need to stop the vm "before" we cal the functions.
It is a hack because:
- we are "starting" the guest again to stop it in migration_complete() I know, I know, but it is not trivial to get all the information easily to migration_complete(), so this hack.
- auto_converge test fails with this hack. I think that it is related to previous problem. We start the guest when it is supposed to be stopped for convergence reasons.
- All experiments that I did to do the proper thing failed with having the iothread_locked() or try to unlock() it when not locked.
- several of the pending functions are using the iothread lock themselves, so I need to split it to have two versions (one for the _estimate() case with the iothread lock), and another for the _exact() case without the iothread_lock(). I want comments about this approach before I try to continue on this direction.
--- migration/migration.c | 13 +++++++++++++ tests/qtest/migration-test.c | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-)
migration/migration.c +13 -0
@@ -3742,7 +3742,20 @@ static MigIterateState migration_iteration_run(MigrationState *s)trace_migrate_pending_estimate (pending_size, s->threshold_size, pend_pre, pend_post);if (pend_pre <= s->threshold_size) { +int old_state = s->state; +qemu_mutex_lock_iothread (); +// is this really necessary? it works for me both ways. +qemu_system_wakeup_request (QEMU_WAKEUP_REASON_OTHER ,NULL ); + s->vm_was_running =runstate_is_running (); +vm_stop_force_state (RUN_STATE_FINISH_MIGRATE ); +qemu_mutex_unlock_iothread ();qemu_savevm_state_pending_exact (&pend_pre, &pend_post); +qemu_mutex_lock_iothread (); +runstate_set (old_state); +if (s->vm_was_running) { +vm_start (); + } +qemu_mutex_unlock_iothread (); pending_size = pend_pre + pend_post;trace_migrate_pending_exact (pending_size, s->threshold_size, pend_pre, pend_post); }
tests/qtest/migration-test.c +2 -1
@@ -2564,7 +2564,8 @@ int main(int argc, char **argv)qtest_add_func ("/migration/validate_uuid_dst_not_set" , test_validate_uuid_dst_not_set); -qtest_add_func ("/migration/auto_converge" , test_migrate_auto_converge); +if (0 ) +qtest_add_func ("/migration/auto_converge" , test_migrate_auto_converge);qtest_add_func ("/migration/multifd/tcp/plain/none" , test_multifd_tcp_none); qtest_add_func("/migration/multifd/tcp/plain/cancel",
Signature · 1 line
2.37.2
Re: [RFC 7/7] migration: call qemu_savevm_state_pending_exact() with the guest stopped
+Avihai, +Jason
Quoted 4 lines · Juan Quintela
HACK ahead.
There are devices that require the guest to be stopped to tell us what is the size of its state.
"... and have transferred said device state" if we are talking current vfio.
We can't query size of the data_fd right now
It would need a @data_size in addition to @data_fd in vfio_device_feature_mig_state, or getting fseek supported over the fd
Quoted 8 lines
So we need to stop the vm "before" we
cal the functions.It is a hack because:
- we are "starting" the guest again to stop it inmigration_complete()I know, I know, but it is not trivial to get all the information easily tomigration_complete(), so this hack.
Could you expand on that? Naively, I was assuming that by 'all information' the locally stored counters in migration_iteration_run() that aren't present in MigrateState?
Quoted 31 lines
-
auto_convergetest fails with this hack. I think that it is related to previous problem. We start the guest when it is supposed to be stopped for convergence reasons.- All experiments that I did to do the proper thing failed with having the
iothread_locked()or try tounlock()it when not locked.- several of the pending functions are using the iothread lock themselves, so I need to split it to have two versions (one for the
_estimate()case with the iothread lock), and another for the_exact()case without theiothread_lock(). I want comments about this approach before I try to continue on this direction.Signed-off-by Juan Quintela <[email protected]>--- migration/migration.c | 13 +++++++++++++ tests/qtest/migration-test.c | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-)migration/migration.c +4
-0@@ -3742,7 +3742,20 @@ static MigIterateState migration_iteration_run(MigrationState *s)trace_migrate_pending_estimate (pending_size, s->threshold_size, pend_pre, pend_post);if (pend_pre <= s->threshold_size) { +int old_state = s->state; +qemu_mutex_lock_iothread (); +// is this really necessary? it works for me both ways. +qemu_system_wakeup_request (QEMU_WAKEUP_REASON_OTHER ,NULL );
migration/migration.c static MigIterateState migration_iteration_run(MigrationState *s) · line 3758
Quoted 10 lines
migration/migration.c +9
-0+ s->vm_was_running =runstate_is_running (); +vm_stop_force_state (RUN_STATE_FINISH_MIGRATE ); +qemu_mutex_unlock_iothread ();qemu_savevm_state_pending_exact (&pend_pre, &pend_post); +qemu_mutex_lock_iothread (); +runstate_set (old_state); +if (s->vm_was_running) { +vm_start (); + } +qemu_mutex_unlock_iothread ();
Couldn't we just have an extra patch that just stores pend_pre and pending_size in MigrateState, which would allow all this check to be moved into migration_completion(). Or maybe that wasn't an option for some other reason?
Additionally what about having a migration helper function that vfio_save_complete_precopy() callback needs to use into to check if the expected-device state size meets the threshold/downtime as it is saving the device state and otherwise fail earlier accordingly when saving beyond the threshold?
It would allow supporting both the (current UAPI) case where you need to transfer the state to get device state size (so checking against threshold_size pending_pre constantly would allow to not violate the SLA) as well as any other UAPI improvement to fseek()/data_size that lets you fail even earlier.
Seems like at least it keeps some of the rules (both under iothread lock) as this patch
Re: [RFC 7/7] migration: call qemu_savevm_state_pending_exact() with the guest stopped
Quoted 9 lines · Joao Martins
+Avihai, +Jason
Quoted 4 lines · Juan Quintela
HACK ahead.
There are devices that require the guest to be stopped to tell us what is the size of its state.
"... and have transferred said device state" if we are talking current vfio.
Yeap.
Quoted 1 line
We can't query size of the
data_fdright now
Oops. My understanding was that once the guest is stopped you can say how big is it. That is a deal breaker. We can't continue if we don't know the size. Copying the whole state to know the size looks too much.
Quoted 2 lines
It would need a @data_size in addition to @data_fd in
vfio_device_feature_mig_state, or getting fseek supported over the fd
Ok, we can decided how to do it, but I think that putting fseek into it will only make things more complicated.
Quoted 9 lines
Quoted 8 lines
So we need to stop the vm "before" we
cal the functions.It is a hack because:
- we are "starting" the guest again to stop it inmigration_complete()I know, I know, but it is not trivial to get all the information easily tomigration_complete(), so this hack.
Quoted 3 lines
Could you expand on that? Naively, I was assuming that by 'all information' the locally stored counters in
migration_iteration_run()that aren't present in MigrateState?
This is not related to vfio at all.
The problem is that current code assumes that the guest is still running, and then do qemu_mutex_lock_iothread() and unlock() inside the pending handlers. To stop the guest, we need to lock the iothread first. So this was going to hang. I fixed it doing the lock/unlock twice. That is the hack. I will change the callers once that we decide what is the right path ahead. This is not a problem related to vfio. it is a problem related about how we can stop/resume guests programatically in the middle of qemu code.
Quoted 37 lines
Quoted 37 lines
-
auto_convergetest fails with this hack. I think that it is related to previous problem. We start the guest when it is supposed to be stopped for convergence reasons.- All experiments that I did to do the proper thing failed with having the
iothread_locked()or try tounlock()it when not locked.- several of the pending functions are using the iothread lock themselves, so I need to split it to have two versions (one for the
_estimate()case with the iothread lock), and another for the_exact()case without theiothread_lock(). I want comments about this approach before I try to continue on this direction.Signed-off-by Juan Quintela <[email protected]>--- migration/migration.c | 13 +++++++++++++ tests/qtest/migration-test.c | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-)migration/migration.c +9
-0@@ -3742,7 +3742,20 @@ static MigIterateState migration_iteration_run(MigrationState *s)trace_migrate_pending_estimate (pending_size, s->threshold_size, pend_pre, pend_post);if (pend_pre <= s->threshold_size) { +int old_state = s->state; +qemu_mutex_lock_iothread (); +// is this really necessary? it works for me both ways. +qemu_system_wakeup_request (QEMU_WAKEUP_REASON_OTHER ,NULL ); + s->vm_was_running =runstate_is_running (); +vm_stop_force_state (RUN_STATE_FINISH_MIGRATE ); +qemu_mutex_unlock_iothread ();qemu_savevm_state_pending_exact (&pend_pre, &pend_post); +qemu_mutex_lock_iothread (); +runstate_set (old_state);
Quoted 8 lines
migration/migration.c static MigIterateState migration_iteration_run(MigrationState *s) · line 3758
Quoted 4 lines
migration/migration.c +4
-0+if (s->vm_was_running) { +vm_start (); + } +qemu_mutex_unlock_iothread ();Couldn't we just have an extra patch that just stores
pend_preandpending_sizein MigrateState, which would allow all this check to be moved intomigration_completion(). Or maybe that wasn't an option for some other reason?
This is not an option, because we don't have a way to get back from migration_completion() to migrate_iteration_run() if there is not enough space to send all the state.
Quoted 5 lines
Additionally what about having a migration helper function that
vfio_save_complete_precopy()callback needs to use into to check if the expected-device state size meets the threshold/downtime as it is saving the device state and otherwise fail earlier accordingly when saving beyond the threshold?
That is what I tried to do with the code.
See patch 4. ram.c
How I have two functions:
- ram_state_pending_estimate()
- ram_state_pending_exact()
1st should work without any locking, i.e. just best estimation without too much work, second should give the real value.
What we had discussed before for vfio is that the device will "cache" the value returned from previous ram_state_pending_exact().
Quoted 7 lines
It would allow supporting both the (current UAPI) case where you need to transfer the state to get device state size (so checking against
threshold_sizepending_preconstantly would allow to not violate the SLA) as well as any other UAPI improvement to fseek()/data_size that lets you fail even earlier.Seems like at least it keeps some of the rules (both under iothread lock) as this patch
Coming to worse thing, you need to read the state into a local buffer and then calculate the size in exact? Looks overkill, but in your case, I can't see other way to do it.
My understanding was that for new hardware you have an easy way to calculate this value "if the guest was stopped".
My next series are a way to do in parallel the read/send of the state with respect to the migration_thread(), but that is a different problem. I need a way to calculate sizes to start with, otherwise I have no way to decide if I can enter the completion stage (or for old devices one can lie and assume than size is zero, but then you are going to have bigger downtimes).
Later, Juan.
Re: [RFC 7/7] migration: call qemu_savevm_state_pending_exact() with the guest stopped
Quoted 2 lines · Juan Quintela
Oops. My understanding was that once the guest is stopped you can say how big is it.
It's worth keeping in mind that conceptually a VF won't stop (e.g. DMA) until really told through VFIO. So, stopping CPUs (guest) just means that guest code does not arm the VF for more I/O but still is a weak guarantee as VF still has outstanding I/O to deal with until VFIO tells it to quiesce DMA (for devices that support it).
Quoted 3 lines
That is a deal breaker. We can't continue if we don't
know the size. Copying the whole state to know the size looks too much.
It's fair to say that the kernel could know the size of the state once the VF is stopped but right now it is only on the STOP -> STOP_COPY arc (which is when it is saved to kernel pages, regardless of userspace reading it). And it will block read() until device has finished transferring it (unless you do a nonblocking read ofc). Knowing the device state would need to be reflected in the vfio UAPI and needs that adjustment. Providing total length ahead of device transfer might depend on the hardware, but current vfio vendor drivers look capable of that (from looking at the code).
Quoted 6 lines
Quoted 2 lines
It would need a @data_size in addition to @data_fd in
vfio_device_feature_mig_state, or getting fseek supported over the fdOk, we can decided how to do it, but I think that putting fseek into it will only make things more complicated.
fseek() was just a suggestion as a way to calculate file length (device state length) with current file APIs:
fseek(data_fd, 0L, SEEK_END); size = ftell(data_fd);
@data_size way is likely better (or simpler), but it would need to get an extra u64 added into VFIO_DEVICE_FEATURE_MIG_DEVICE_STATE ioctl
I am sure there are other alternatives
Quoted 14 lines
Quoted 9 lines
Quoted 8 lines
So we need to stop the vm "before" we
cal the functions.It is a hack because:
- we are "starting" the guest again to stop it inmigration_complete()I know, I know, but it is not trivial to get all the information easily tomigration_complete(), so this hack.Quoted 3 lines
Could you expand on that? Naively, I was assuming that by 'all information' the locally stored counters in
migration_iteration_run()that aren't present in MigrateState?This is not related to vfio at all.
Quoted 9 lines
Quoted 1 line
The problem is that current code assumes that the guest is still
running, and then do
qemu_mutex_lock_iothread()andunlock()inside the pending handlers. To stop the guest, we need to lock the iothread first. So this was going to hang. I fixed it doing the lock/unlock twice. That is the hack. I will change the callers once that we decide what is the right path ahead. This is not a problem related to vfio. it is a problem related about how we can stop/resume guests programatically in the middle of qemu code.
/me nods
Quoted 50 lines
Quoted 37 lines
Quoted 37 lines
-
auto_convergetest fails with this hack. I think that it is related to previous problem. We start the guest when it is supposed to be stopped for convergence reasons.- All experiments that I did to do the proper thing failed with having the
iothread_locked()or try tounlock()it when not locked.- several of the pending functions are using the iothread lock themselves, so I need to split it to have two versions (one for the
_estimate()case with the iothread lock), and another for the_exact()case without theiothread_lock(). I want comments about this approach before I try to continue on this direction.Signed-off-by Juan Quintela <[email protected]>--- migration/migration.c | 13 +++++++++++++ tests/qtest/migration-test.c | 3 ++- 2 files changed, 15 insertions(+), 1 deletion(-)migration/migration.c +9
-0@@ -3742,7 +3742,20 @@ static MigIterateState migration_iteration_run(MigrationState *s)trace_migrate_pending_estimate (pending_size, s->threshold_size, pend_pre, pend_post);if (pend_pre <= s->threshold_size) { +int old_state = s->state; +qemu_mutex_lock_iothread (); +// is this really necessary? it works for me both ways. +qemu_system_wakeup_request (QEMU_WAKEUP_REASON_OTHER ,NULL ); + s->vm_was_running =runstate_is_running (); +vm_stop_force_state (RUN_STATE_FINISH_MIGRATE ); +qemu_mutex_unlock_iothread ();qemu_savevm_state_pending_exact (&pend_pre, &pend_post); +qemu_mutex_lock_iothread (); +runstate_set (old_state);Quoted 8 lines
migration/migration.c static MigIterateState migration_iteration_run(MigrationState *s) · line 3758
Quoted 4 lines
migration/migration.c +4
-0+if (s->vm_was_running) { +vm_start (); + } +qemu_mutex_unlock_iothread ();Couldn't we just have an extra patch that just stores
pend_preandpending_sizein MigrateState, which would allow all this check to be moved intomigration_completion(). Or maybe that wasn't an option for some other reason?This is not an option, because we don't have a way to get back from
migration_completion()tomigrate_iteration_run()if there is not enough space to send all the state.
Quoted 9 lines
Quoted 5 lines
Additionally what about having a migration helper function that
vfio_save_complete_precopy()callback needs to use into to check if the expected-device state size meets the threshold/downtime as it is saving the device state and otherwise fail earlier accordingly when saving beyond the threshold?That is what I tried to do with the code.
See patch 4.ram.c
So what I was saying earlier was to have something like a:
migration_check_pending(ms, device_state_size)
Which would call into migration core to check the SLA is still met. But callable from the client (hw/vfio/migration) as opposed to the core calling into the client. This allows that the client controls when to stop the VF
The copy to userspace one could probably be amortized via pread() at at an arbritary offset to read 1 byte, and get an estimate size. Say you could check that the size is readable with a @threshold_size + 1 offset without necessarily copying the whole thing to userspace. If it reads succesfully it would bailing off earlier (failing the migration) -- and it would avoid doing the full copy to userspace.
But the one gotcha is the STOP -> STOP_COPY needs to
happen and that is what triggers the transfer the device state into kernel-managed pages before userspace decides to do anything to access/copy said state.
Quoted 7 lines
How I have two functions:
-ram_state_pending_estimate()
-ram_state_pending_exact()1st should work without any locking, i.e. just best estimation without too much work, second should give the real value.
Right -- I did notice that
Quoted 3 lines
What we had discussed before for vfio is that the device will "cache" the value returned from previous
ram_state_pending_exact().
A concern I see is that if we stop and resume the VF on a regular basis to accommodate a calculation just to be made available throughout all migration flow -- it is going to be a little invasive from guest performance/behaviour PoV?
Perhaps this check ought to be amortized at different major stage transitions of migration (as opposed to any iteration) as this can end up happening very often as soon as non-VFIO state + dirty pages get to a small enough threshold?
Quoted 9 lines
Quoted 8 lines
It would allow supporting both the (current UAPI) case where you need to transfer the state to get device state size (so checking against
threshold_sizepending_preconstantly would allow to not violate the SLA) as well as any other UAPI improvement to fseek()/data_size that lets you fail even earlier.Seems like at least it keeps some of the rules (both under iothread lock) as this patch
Quoted 7 lines
Coming to worse thing, you need to read the state into a local buffer and then calculate the size in exact? Looks overkill, but in your case, I can't see other way to do it.
My understanding was that for new hardware you have an easy way to calculate this value "if the guest was stopped".
s/guest/VF
Quoted 3 lines
My next series are a way to do in parallel the read/send of the state with respect to the
migration_thread(), but that is a different problem.
There's also non-blocking reads not sure it helps towards the asynchronous transfer?
Quoted 4 lines
I need a way to calculate sizes to start with,
otherwise I
have no way to decide if I can enter the completion stage (or for old devices one can lie and assume than size is zero,
to be fair that's what happens right now with migration v1 protocol -- it's not unprecedented IIUC
Quoted 5 lines
but then you are going
to have bigger downtimes).Later, Juan.
Thanks
Re: [RFC 7/7] migration: call qemu_savevm_state_pending_exact() with the guest stopped
Quoted 3 lines · Joao Martins
Quoted 2 lines · Juan Quintela
Oops. My understanding was that once the guest is stopped you can say how big is it.
Hi
Quoted 5 lines
It's worth keeping in mind that conceptually a VF won't stop (e.g. DMA) until really told through VFIO. So, stopping CPUs (guest) just means that guest code does not arm the VF for more I/O but still is a weak guarantee as VF still has outstanding I/O to deal with until VFIO tells it to quiesce DMA (for devices that support it).
How can we make sure about that?
i.e. I know I have a vfio device. I need two things:
- in the iterative stage, I eed to check the size, but a estimate is ok. for example with RAM, we use whatever is the size of the dirty bitmap at that moment.
If the estimated size is smaller than the theshold, we
* stop the guest
* sync dirty bitmap
* now we test the (real) dirty bitmap size
How can we do something like that with a vfio device.
Quoted 4 lines
Quoted 3 lines
That is a deal breaker. We can't continue if we don't
know the size. Copying the whole state to know the size looks too much.
Quoted 8 lines
It's fair to say that the kernel could know the size of the state once the VF is stopped but right now it is only on the STOP ->
STOP_COPYarc (which is when it is saved to kernel pages, regardless of userspace reading it). And it will blockread()until device has finished transferring it (unless you do a nonblocking read ofc). Knowing the device state would need to be reflected in the vfio UAPI and needs that adjustment. Providing total length ahead of device transfer might depend on the hardware, but current vfio vendor drivers look capable of that (from looking at the code).
I have no clue about vfio, so I need help here. I can only provide hooks. But I expect that we should be able to convince firmware to give us that information.
Quoted 10 lines
Quoted 6 lines
Quoted 2 lines
It would need a @data_size in addition to @data_fd in
vfio_device_feature_mig_state, or getting fseek supported over the fdOk, we can decided how to do it, but I think that putting fseek into it will only make things more complicated.
fseek()was just a suggestion as a way to calculate file length (device state length) with current file APIs:
Quoted 7 lines
fseek(data_fd, 0L, SEEK_END); size = ftell(data_fd);@data_size way is likely better (or simpler), but it would need to get an extra u64 added into
VFIO_DEVICE_FEATURE_MIG_DEVICE_STATEioctlI am sure there are other alternatives
My understanding from NVidia folks was that newer firmware have an ioctl to return than information.
Quoted 70 lines
Quoted 14 lines
Quoted 9 lines
Quoted 8 lines
So we need to stop the vm "before" we
cal the functions.It is a hack because:
- we are "starting" the guest again to stop it inmigration_complete()I know, I know, but it is not trivial to get all the information easily tomigration_complete(), so this hack.Quoted 3 lines
Could you expand on that? Naively, I was assuming that by 'all information' the locally stored counters in
migration_iteration_run()that aren't present in MigrateState?This is not related to vfio at all.
Quoted 9 lines
Quoted 1 line
The problem is that current code assumes that the guest is still
running, and then do
qemu_mutex_lock_iothread()andunlock()inside the pending handlers. To stop the guest, we need to lock the iothread first. So this was going to hang. I fixed it doing the lock/unlock twice. That is the hack. I will change the callers once that we decide what is the right path ahead. This is not a problem related to vfio. it is a problem related about how we can stop/resume guests programatically in the middle of qemu code./me nods
Quoted 8 lines
Quoted 3 lines
Couldn't we just have an extra patch that just stores
pend_preandpending_sizein MigrateState, which would allow all this check to be moved intomigration_completion(). Or maybe that wasn't an option for some other reason?This is not an option, because we don't have a way to get back from
migration_completion()tomigrate_iteration_run()if there is not enough space to send all the state.Quoted 9 lines
Quoted 5 lines
Additionally what about having a migration helper function that
vfio_save_complete_precopy()callback needs to use into to check if the expected-device state size meets the threshold/downtime as it is saving the device state and otherwise fail earlier accordingly when saving beyond the threshold?That is what I tried to do with the code.
See patch 4.ram.cSo what I was saying earlier was to have something like a:
migration_check_pending(ms, device_state_size)Which would call into migration core to check the SLA is still met. But callable from the client (hw/vfio/migration) as opposed to the core calling into the client. This allows that the client controls when to stop the VF
The copy to userspace one could probably be amortized via
pread()at at an arbritary offset to read 1 byte, and get an estimate size. Say you could check that the size is readable with a @threshold_size + 1 offset without necessarily copying the whole thing to userspace. If it reads succesfully it would bailing off earlier (failing the migration) -- and it would avoid doing the full copy to userspace.But the one gotcha is the STOP ->
STOP_COPYneeds to
happen and that is what triggers the transfer the device state into kernel-managed pages before userspace decides to do anything to access/copy said state.Quoted 7 lines
How I have two functions:
-ram_state_pending_estimate()
-ram_state_pending_exact()1st should work without any locking, i.e. just best estimation without too much work, second should give the real value.
Right -- I did notice that
Quoted 7 lines
Quoted 3 lines
What we had discussed before for vfio is that the device will "cache" the value returned from previous
ram_state_pending_exact().A concern I see is that if we stop and resume the VF on a regular basis to accommodate a calculation just to be made available throughout all migration flow -- it is going to be a little invasive from guest performance/behaviour PoV?
It is *kind* of invasive (make things slower), but we already have the problem that current code, we are not counting the size of the devices state on calculation, and we should. This adds a hook for all devices to include this information.
I see two options:
- we stop the guest for the calculations (it makes the last iteration downtime faster), but it makes the rest of the end of iterations slower. Notice that we should not have so many iterations to start with.
Quoted 3 lines
Perhaps this check ought to be amortized at different major stage transitions of migration (as opposed to any iteration) as this can end up happening very often as soon as non-VFIO state + dirty pages get to a small enough threshold?
This is the reason why we add the estimate size for the vfio. if the estimate is good enough, we shouldn't stop so many times.
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
It would allow supporting both the (current UAPI) case where you need to transfer the state to get device state size (so checking against
threshold_sizepending_preconstantly would allow to not violate the SLA) as well as any other UAPI improvement to fseek()/data_size that lets you fail even earlier.Seems like at least it keeps some of the rules (both under iothread lock) as this patch
Quoted 8 lines
Quoted 7 lines
Coming to worse thing, you need to read the state into a local buffer and then calculate the size in exact? Looks overkill, but in your case, I can't see other way to do it.
My understanding was that for new hardware you have an easy way to calculate this value "if the guest was stopped".
s/guest/VF
The use case that I was discussing the whole card was assigned to the guest, not a VF. I have no clue if that makes the problem easier of more difficult.
Quoted 5 lines
Quoted 3 lines
My next series are a way to do in parallel the read/send of the state with respect to the
migration_thread(), but that is a different problem.There's also non-blocking reads not sure it helps towards the asynchronous transfer?
My current "cunning" plan is to create a new channel for each vfio device, hat allow the device to do whatever they want, and using a blocking interface.
Quoted 7 lines
Quoted 4 lines
I need a way to calculate sizes to start with,
otherwise I
have no way to decide if I can enter the completion stage (or for old devices one can lie and assume than size is zero,to be fair that's what happens right now with migration v1 protocol -- it's not unprecedented IIUC
Ok, thanks for the comments.
Later, Juan.
Re: [RFC 7/7] migration: call qemu_savevm_state_pending_exact() with the guest stopped
Quoted 24 lines · Juan Quintela
Quoted 3 lines · Joao Martins
Quoted 2 lines · Juan Quintela
Oops. My understanding was that once the guest is stopped you can say how big is it.
Hi
Quoted 5 lines
It's worth keeping in mind that conceptually a VF won't stop (e.g. DMA) until really told through VFIO. So, stopping CPUs (guest) just means that guest code does not arm the VF for more I/O but still is a weak guarantee as VF still has outstanding I/O to deal with until VFIO tells it to quiesce DMA (for devices that support it).
How can we make sure about that?
i.e. I know I have a vfio device. I need two things:
- in the iterative stage, I eed to check the size, but a estimate is ok. for example with RAM, we use whatever is the size of the dirty bitmap at that moment.
If the estimated size is smaller than the theshold, we
* stop the guest
* sync dirty bitmap
* now we test the (real) dirty bitmap size
Quoted 2 lines
How can we do something like that with a vfio device.
You would have an extra intermediate step that stops the VF prior to asking the device state length. What I am not sure is whether stopping vCPUs can be skipped as an optimization. In theory you could, but perhaps is best to be conservative and handling with same assumptions as any other guest related state.
Quoted 14 lines
Quoted 5 lines
Quoted 4 lines
That is a deal breaker. We can't continue if we don't
know the size. Copying the whole state to know the size looks too much.Quoted 8 lines
It's fair to say that the kernel could know the size of the state once the VF is stopped but right now it is only on the STOP ->
STOP_COPYarc (which is when it is saved to kernel pages, regardless of userspace reading it). And it will blockread()until device has finished transferring it (unless you do a nonblocking read ofc). Knowing the device state would need to be reflected in the vfio UAPI and needs that adjustment. Providing total length ahead of device transfer might depend on the hardware, but current vfio vendor drivers look capable of that (from looking at the code).
Quoted 4 lines
I have no clue about vfio, so I need help here. I can only provide hooks. But I expect that we should be able to convince firmware to give us that information.
The above was me talking about kernel interface.
Quoted 13 lines
Quoted 13 lines
Quoted 6 lines
Quoted 2 lines
It would need a @data_size in addition to @data_fd in
vfio_device_feature_mig_state, or getting fseek supported over the fdOk, we can decided how to do it, but I think that putting fseek into it will only make things more complicated.
fseek()was just a suggestion as a way to calculate file length (device state length) with current file APIs:fseek(data_fd, 0L, SEEK_END); size = ftell(data_fd);
Quoted 8 lines
Quoted 4 lines
@data_size way is likely better (or simpler), but it would need to get an extra u64 added into
VFIO_DEVICE_FEATURE_MIG_DEVICE_STATEioctlI am sure there are other alternatives
My understanding from NVidia folks was that newer firmware have an ioctl to return than information.
Maybe there's something new. I was thinking from this here:
https://github.com/torvalds/linux/blob/master/drivers/vfio/pci/mlx5/cmd.c#L47
mlx5vf_cmd_query_vhca_migration_state()
The hisilicon one looks to be always the same size
What both probably assume is that the device has been suspended prior to making this call. We would use those interface to return this @data_size as said above or whatever reasonable alternative folks had discussed.
Quoted 74 lines
Quoted 74 lines
Quoted 14 lines
Quoted 9 lines
Quoted 8 lines
So we need to stop the vm "before" we
cal the functions.It is a hack because:
- we are "starting" the guest again to stop it inmigration_complete()I know, I know, but it is not trivial to get all the information easily tomigration_complete(), so this hack.Quoted 3 lines
Could you expand on that? Naively, I was assuming that by 'all information' the locally stored counters in
migration_iteration_run()that aren't present in MigrateState?This is not related to vfio at all.
Quoted 9 lines
Quoted 1 line
The problem is that current code assumes that the guest is still
running, and then do
qemu_mutex_lock_iothread()andunlock()inside the pending handlers. To stop the guest, we need to lock the iothread first. So this was going to hang. I fixed it doing the lock/unlock twice. That is the hack. I will change the callers once that we decide what is the right path ahead. This is not a problem related to vfio. it is a problem related about how we can stop/resume guests programatically in the middle of qemu code./me nods
Quoted 8 lines
Quoted 3 lines
Couldn't we just have an extra patch that just stores
pend_preandpending_sizein MigrateState, which would allow all this check to be moved intomigration_completion(). Or maybe that wasn't an option for some other reason?This is not an option, because we don't have a way to get back from
migration_completion()tomigrate_iteration_run()if there is not enough space to send all the state.Quoted 9 lines
Quoted 5 lines
Additionally what about having a migration helper function that
vfio_save_complete_precopy()callback needs to use into to check if the expected-device state size meets the threshold/downtime as it is saving the device state and otherwise fail earlier accordingly when saving beyond the threshold?That is what I tried to do with the code.
See patch 4.ram.cSo what I was saying earlier was to have something like a:
migration_check_pending(ms, device_state_size)Which would call into migration core to check the SLA is still met. But callable from the client (hw/vfio/migration) as opposed to the core calling into the client. This allows that the client controls when to stop the VF
The copy to userspace one could probably be amortized via
pread()at at an arbritary offset to read 1 byte, and get an estimate size. Say you could check that the size is readable with a @threshold_size + 1 offset without necessarily copying the whole thing to userspace. If it reads succesfully it would bailing off earlier (failing the migration) -- and it would avoid doing the full copy to userspace.But the one gotcha is the STOP ->
STOP_COPYneeds to
happen and that is what triggers the transfer the device state into kernel-managed pages before userspace decides to do anything to access/copy said state.Quoted 7 lines
How I have two functions:
-ram_state_pending_estimate()
-ram_state_pending_exact()1st should work without any locking, i.e. just best estimation without too much work, second should give the real value.
Right -- I did notice that
Quoted 3 lines
What we had discussed before for vfio is that the device will "cache" the value returned from previous
ram_state_pending_exact().
Quoted 9 lines
Quoted 3 lines
A concern I see is that if we stop and resume the VF on a regular basis to accommodate a calculation just to be made available throughout all migration flow -- it is going to be a little invasive from guest performance/behaviour PoV?
It is *kind* of invasive (make things slower), but we already have the problem that current code, we are not counting the size of the devices state on calculation, and we should. This adds a hook for all devices to include this information.
I think one difference here is that the vmstate is all self-contained in Qemu/VMM (except for accel-related state obtained from KVM). Here we are making calls into hardware, stopping the VF, get the state to resume it again.
Quoted 5 lines
I see two options:
- we stop the guest for the calculations (it makes the last iteration downtime faster), but it makes the rest of the end of iterations slower. Notice that we should not have so many iterations to start with.
Quoted 7 lines
Quoted 3 lines
Perhaps this check ought to be amortized at different major stage transitions of migration (as opposed to any iteration) as this can end up happening very often as soon as non-VFIO state + dirty pages get to a small enough threshold?
This is the reason why we add the estimate size for the vfio. if the estimate is good enough, we shouldn't stop so many times.
I suppose, yes
Quoted 25 lines
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
It would allow supporting both the (current UAPI) case where you need to transfer the state to get device state size (so checking against
threshold_sizepending_preconstantly would allow to not violate the SLA) as well as any other UAPI improvement to fseek()/data_size that lets you fail even earlier.Seems like at least it keeps some of the rules (both under iothread lock) as this patch
Quoted 8 lines
Quoted 7 lines
Coming to worse thing, you need to read the state into a local buffer and then calculate the size in exact? Looks overkill, but in your case, I can't see other way to do it.
My understanding was that for new hardware you have an easy way to calculate this value "if the guest was stopped".
s/guest/VF
The use case that I was discussing the whole card was assigned to the guest, not a VF. I have no clue if that makes the problem easier of more difficult.
Quoted 4 lines
Quoted 3 lines
My next series are a way to do in parallel the read/send of the state with respect to the
migration_thread(), but that is a different problem.
Quoted 6 lines
Quoted 1 line
There's also non-blocking reads not sure it helps towards the asynchronous transfer?
My current "cunning" plan is to create a new channel for each vfio device, hat allow the device to do whatever they want, and using a blocking interface.
Looks sensible
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
I need a way to calculate sizes to start with,
otherwise I
have no way to decide if I can enter the completion stage (or for old devices one can lie and assume than size is zero,to be fair that's what happens right now with migration v1 protocol -- it's not unprecedented IIUC
Ok, thanks for the comments.
Likewise
It would be nice if we could still move forward with v2 support, while newfound gaps are addressed towards the road of turning it into a non experimental feature. It would allow exercising a lot of the new interface, as the ecosystem is a bit limiting :(
Re: [RFC 7/7] migration: call qemu_savevm_state_pending_exact() with the guest stopped
Quoted 25 lines · Joao Martins
Quoted 24 lines · Juan Quintela
Quoted 3 lines · Joao Martins
Quoted 2 lines · Juan Quintela
Oops. My understanding was that once the guest is stopped you can say how big is it.
Hi
Quoted 5 lines
It's worth keeping in mind that conceptually a VF won't stop (e.g. DMA) until really told through VFIO. So, stopping CPUs (guest) just means that guest code does not arm the VF for more I/O but still is a weak guarantee as VF still has outstanding I/O to deal with until VFIO tells it to quiesce DMA (for devices that support it).
How can we make sure about that?
i.e. I know I have a vfio device. I need two things:
- in the iterative stage, I eed to check the size, but a estimate is ok. for example with RAM, we use whatever is the size of the dirty bitmap at that moment.
If the estimated size is smaller than the theshold, we
* stop the guest
* sync dirty bitmap
* now we test the (real) dirty bitmap size
Quoted 5 lines
Quoted 2 lines
How can we do something like that with a vfio device.
You would have an extra intermediate step that stops the VF prior to asking the device state length. What I am not sure is whether stopping vCPUs can be skipped as an optimization.
It cannot, if you want to stop the VFIO device you must also stop the vCPUs because the device is not required to respond properly to MMIO operations when stopped.
Quoted 4 lines
Quoted 2 lines
My understanding from NVidia folks was that newer firmware have an ioctl to return than information.
Maybe there's something new. I was thinking from this here:
Juan is talking about the ioctl we had in the pre-copy series.
I expect it to come into some different form to support this RFC.
Jason
RE: [RFC 7/7] migration: call qemu_savevm_state_pending_exact() with the guest stopped
Quoted 55 lines
From: Qemu-devel <qemu-devel- [email protected]> On Behalf Of Jason Gunthorpe
Sent: Tuesday, 18 October 2022 15:23
To: Joao Martins <[email protected]>
Cc: [email protected]; Alex Williamson <[email protected]>; Eric Blake <[email protected]>; Stefan Hajnoczi <[email protected]>; Fam Zheng <[email protected]>; [email protected]; Cornelia Huck <[email protected]>; Thomas Huth <[email protected]>; Vladimir Sementsov-Ogievskiy <[email protected]>; Laurent Vivier <[email protected]>; John Snow <[email protected]>; Dr. David Alan Gilbert <[email protected]>; Christian Borntraeger <[email protected]>; Halil Pasic <[email protected]>; Paolo Bonzini <[email protected]>; [email protected]; Eric Farman <[email protected]>; Richard Henderson <[email protected]>; David Hildenbrand <[email protected]>; Avihai Horon <[email protected]>; [email protected]
Subject: Re: [RFC 7/7] migration: callqemu_savevm_state_pending_exact()with the guest stoppedQuoted 25 lines · Joao Martins
Quoted 24 lines · Juan Quintela
Quoted 3 lines · Joao Martins
Quoted 2 lines · Juan Quintela
Oops. My understanding was that once the guest is stopped you can say how big is it.
Hi
Quoted 5 lines
It's worth keeping in mind that conceptually a VF won't stop (e.g. DMA) until really told through VFIO. So, stopping CPUs (guest) just means that guest code does not arm the VF for more I/O but still is a weak guarantee as VF still has outstanding I/O to deal with until VFIO tells it to quiesce DMA (for devices that support it).
How can we make sure about that?
i.e. I know I have a vfio device. I need two things:
- in the iterative stage, I eed to check the size, but a estimate is ok. for example with RAM, we use whatever is the size of the dirty bitmap at that moment.
If the estimated size is smaller than the theshold, we
* stop the guest
* sync dirty bitmap
* now we test the (real) dirty bitmap sizeQuoted 5 lines
Quoted 2 lines
How can we do something like that with a vfio device.
You would have an extra intermediate step that stops the VF prior to asking the device state length. What I am not sure is whether stopping vCPUs can be skipped as an optimization.
It cannot, if you want to stop the VFIO device you must also stop the vCPUs because the device is not required to respond properly to MMIO operations when stopped.
Quoted 9 lines
Quoted 4 lines
Quoted 2 lines
My understanding from NVidia folks was that newer firmware have an ioctl to return than information.
Maybe there's something new. I was thinking from this here:
Juan is talking about the ioctl we had in the pre-copy series.
I expect it to come into some different form to support this RFC.
Do we really need to STOP the VM to get the exact data length that will be required to complete stop copy ?
Can't we simply go with some close estimation when the device is running and drop all the complexity in QEMU/Kernel to STOP and then RE-START the VM if the threshold didn't meet, etc.?
Yishai
Re: [RFC 7/7] migration: call qemu_savevm_state_pending_exact() with the guest stopped
In reply to Joao MartinsQuoted 4 lines · Joao Martins
It would allow supporting both the (current UAPI) case where you need to transfer the state to get device state size (so checking against
threshold_sizepending_preconstantly would allow to not violate the SLA) as well as any other UAPI improvement to fseek()/data_size that lets you fail even earlier.
We should not get fixated on missing part of the current kernel support, if we need a new query or something to make qemu happy then we will add it. We don't need to worry about supporting the kernel-with-no-query case in qemu.
Jason
Quoted 18 lines
From: Qemu-devel <qemu-devel- [email protected]> On Behalf Of Juan Quintela
Sent: Monday, 3 October 2022 6:16
To: [email protected]
Cc: Alex Williamson <[email protected]>; Eric Blake <[email protected]>; Stefan Hajnoczi <[email protected]>; Fam Zheng <[email protected]>; [email protected]; Cornelia Huck <[email protected]>; Thomas Huth <[email protected]>; Vladimir Sementsov-Ogievskiy <[email protected]>; Laurent Vivier <[email protected]>; John Snow <[email protected]>; Dr. David Alan Gilbert <[email protected]>; Christian Borntraeger <[email protected]>; Halil Pasic <[email protected]>; Juan Quintela <[email protected]>; Paolo Bonzini <[email protected]>; [email protected]; Eric Farman <[email protected]>; Richard Henderson <[email protected]>; David Hildenbrand <[email protected]>
Subject: [RFC 0/7] migration patches for VFIO
Quoted 4 lines
Hi
VFIO migration has several requirements:
- the size of the state is only known when the guest is stopped
As was discussed in the conference call, I just sent a patch to the kernel mailing list to be able to get the state size in each state.
See:
https://patchwork.kernel.org/project/kvm/patch/[email protected]/
This can drop the need to stop the guest and ask for that data.
So, I assume that you can drop some complexity and hacks from your RFC once you'll send the next series.
Specifically,
No need to stop the VM and re-start it in case the SLA can't meet, just read upon RUNNING the estimated data length that will be required to complete STOP_COPY and use it.
Yishai
Quoted 58 lines
- they need to send possible lots of data.
this series only address the 1st set of problems.
What they do:
-res_compatibleparameter was not used anywhere, just add that information tores_postcopy.
- Remove QEMUFILE parameter fromsave_live_pending
- Splitsave_live_pendinginto
*save_pending_estimate(): the pending state size without trying too hard
*save_pending_exact(): the real pending state size, it is called with the
guest stopped.
- Now save_pending_* don't need the threshold parameter
- HACK a way to stop the guest before moving there.ToDo:
- autoconverge test is broken, no real clue why, but it is possible that the test is wrong.- Make an artifact to be able to send massive amount of data in the save state stage (probably more multifd channels).
- Be able to not having to start the guest between cheking the state pending size and
migration_completion().Please review.
Thanks, Juan.
Juan Quintela (7):
migration: Removeres_compatibleparameter
migration: Nosave_live_pending()method uses the QEMUFile parameter
migration: Block migration comment or code is wrong
migration: Splitsave_live_pending()into state_pending_*
migration: Remove unusedthreshold_sizeparameter
migration: simplifymigration_iteration_run()
migration: callqemu_savevm_state_pending_exact()with the guest
stoppeddocs/devel/migration.rst | 18 ++++++------ docs/devel/vfio-migration.rst | 4 +-- include/migration/register.h | 29 ++++++++++--------- migration/savevm.h | 8 +++--- hw/s390x/s390-stattrib.c | 11 ++++--- hw/vfio/migration.c | 17 +++++------ migration/block-dirty-bitmap.c | 14 ++++----- migration/block.c | 17 ++++++----- migration/migration.c | 52 ++++++++++++++++++++++------------ migration/ram.c | 35 ++++++++++++++++------- migration/savevm.c | 37 +++++++++++++++++------- tests/qtest/migration-test.c | 3 +- hw/vfio/trace-events | 2 +- migration/trace-events | 7 +++-- 14 files changed, 148 insertions(+), 106 deletions(-)--
2.37.2