migration: Do not re-read the clock on pre_save in case of paused guest
PATCH 1/1 migration: Do not re-read the clock on pre_save in case of paused guest
The clock move makes the guest knows about the paused time between the 'stop' and 'migrate' commands. This is an issue in an already-paused VM because some side effects, like process stalls, could happen after migration.
So, this patch checks the runstate of guest in the pre_save handler and do not re-reads the clock in case of paused state (cold migration).
--- hw/i386/kvm/clock.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
hw/i386/kvm/clock.c +11 -4
@@ -41,6 +41,9 @@ typedef struct KVMClockState {uint64_t clock;bool clock_valid; +/* whether the 'clock' value was obtained in the 'paused' state */ +bool runstate_paused; +/* whether machine type supports reliable KVM_GET_CLOCK */ bool mach_use_reliable_get_clock;
@@ -202,6 +205,8 @@ static void kvmclock_vm_state_change(void *opaque, int running,return ; } + s->runstate_paused =runstate_check (RUN_STATE_PAUSED ); +kvm_synchronize_all_tsc ();kvm_update_clock (s);
@@ -260,9 +265,9 @@ static int kvmclock_pre_load(void *opaque) }/* -* When migrating, read the clock just before migration, -* so that the guest clock counts during the events -* between: +* When migrating a running guest, read the clock just +* before migration, so that the guest clock counts +* during the events between: * * * vm_stop() * *
@@ -277,7 +282,9 @@ static int kvmclock_pre_save(void *opaque) {KVMClockState *s = opaque; -kvm_update_clock (s); +if (!s->runstate_paused) { +kvm_update_clock (s); + }return 0 ; }
Signature · 1 line
2.20.1
CCing Marcelo, who wrote kvm_update_clock() andkvmclock_pre_save().
Quoted 63 lines · Maxiwell S. Garcia
The clock move makes the guest knows about the paused time between the 'stop' and 'migrate' commands. This is an issue in an already-paused VM because some side effects, like process stalls, could happen after migration.
So, this patch checks the runstate of guest in the
pre_savehandler and do not re-reads the clock in case of paused state (cold migration).Signed-off-by Maxiwell S. Garcia <[email protected]>--- hw/i386/kvm/clock.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)hw/i386/kvm/clock.c +11
-4@@ -41,6 +41,9 @@ typedef struct KVMClockState {uint64_t clock;bool clock_valid; +/* whether the 'clock' value was obtained in the 'paused' state */ +bool runstate_paused; +/* whether machine type supports reliable KVM_GET_CLOCK */ bool mach_use_reliable_get_clock;@@ -202,6 +205,8 @@ static void kvmclock_vm_state_change(void *opaque, int running,return ; } + s->runstate_paused =runstate_check (RUN_STATE_PAUSED ); +kvm_synchronize_all_tsc ();kvm_update_clock (s);@@ -260,9 +265,9 @@ static int kvmclock_pre_load(void *opaque) }/* -* When migrating, read the clock just before migration, -* so that the guest clock counts during the events -* between: +* When migrating a running guest, read the clock just +* before migration, so that the guest clock counts +* during the events between: * * * vm_stop() * * @@ -277,7 +282,9 @@ static int kvmclock_pre_save(void *opaque) {KVMClockState *s = opaque; -kvm_update_clock (s); +if (!s->runstate_paused) { +kvm_update_clock (s); + }return 0 ; }Signature · 1 line
2.20.1
Signature · 1 line
Eduardo
Marcelo Tosatti
Reviewed-byLooks good.
Quoted 70 lines · Eduardo Habkost
CCing Marcelo, who wrote
kvm_update_clock()andkvmclock_pre_save().Quoted 63 lines · Maxiwell S. Garcia
The clock move makes the guest knows about the paused time between the 'stop' and 'migrate' commands. This is an issue in an already-paused VM because some side effects, like process stalls, could happen after migration.
So, this patch checks the runstate of guest in the
pre_savehandler and do not re-reads the clock in case of paused state (cold migration).Signed-off-by Maxiwell S. Garcia <[email protected]>--- hw/i386/kvm/clock.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)hw/i386/kvm/clock.c +11
-4@@ -41,6 +41,9 @@ typedef struct KVMClockState {uint64_t clock;bool clock_valid; +/* whether the 'clock' value was obtained in the 'paused' state */ +bool runstate_paused; +/* whether machine type supports reliable KVM_GET_CLOCK */ bool mach_use_reliable_get_clock;@@ -202,6 +205,8 @@ static void kvmclock_vm_state_change(void *opaque, int running,return ; } + s->runstate_paused =runstate_check (RUN_STATE_PAUSED ); +kvm_synchronize_all_tsc ();kvm_update_clock (s);@@ -260,9 +265,9 @@ static int kvmclock_pre_load(void *opaque) }/* -* When migrating, read the clock just before migration, -* so that the guest clock counts during the events -* between: +* When migrating a running guest, read the clock just +* before migration, so that the guest clock counts +* during the events between: * * * vm_stop() * * @@ -277,7 +282,9 @@ static int kvmclock_pre_save(void *opaque) {KVMClockState *s = opaque; -kvm_update_clock (s); +if (!s->runstate_paused) { +kvm_update_clock (s); + }return 0 ; }Signature · 1 line
2.20.1Signature · 1 line
Eduardo