* [Qemu-devel] [PATCH v2] migration: Do not re-read the clock on pre_save in case of paused guest
@ 2019-07-11 19:47 Maxiwell S. Garcia
2019-07-12 6:48 ` David Gibson
0 siblings, 1 reply; 2+ messages in thread
From: Maxiwell S. Garcia @ 2019-07-11 19:47 UTC (permalink / raw)
To: qemu-devel; +Cc: open list:PowerPC TCG CPUs, Maxiwell S. Garcia, David Gibson
Re-read the timebase before migrate was ported from x86 commit:
6053a86fe7bd: kvmclock: reduce kvmclock difference on migration
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 timebase in case of paused state (cold migration).
Signed-off-by: Maxiwell S. Garcia <maxiwell@linux.ibm.com>
---
hw/ppc/ppc.c | 13 +++++++++----
target/ppc/cpu-qom.h | 1 +
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c
index a9e508c496..8572e45274 100644
--- a/hw/ppc/ppc.c
+++ b/hw/ppc/ppc.c
@@ -1008,6 +1008,8 @@ static void timebase_save(PPCTimebase *tb)
* there is no need to update it from KVM here
*/
tb->guest_timebase = ticks + first_ppc_cpu->env.tb_env->tb_offset;
+
+ tb->runstate_paused = runstate_check(RUN_STATE_PAUSED);
}
static void timebase_load(PPCTimebase *tb)
@@ -1051,9 +1053,9 @@ void cpu_ppc_clock_vm_state_change(void *opaque, int running,
}
/*
- * 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()
* *
@@ -1068,7 +1070,10 @@ static int timebase_pre_save(void *opaque)
{
PPCTimebase *tb = opaque;
- timebase_save(tb);
+ /* guest_timebase won't be overridden in case of paused guest */
+ if (!tb->runstate_paused) {
+ timebase_save(tb);
+ }
return 0;
}
diff --git a/target/ppc/cpu-qom.h b/target/ppc/cpu-qom.h
index be9b4c30c3..5fbcdee9c9 100644
--- a/target/ppc/cpu-qom.h
+++ b/target/ppc/cpu-qom.h
@@ -201,6 +201,7 @@ typedef struct PowerPCCPUClass {
typedef struct PPCTimebase {
uint64_t guest_timebase;
int64_t time_of_the_day_ns;
+ bool runstate_paused;
} PPCTimebase;
extern const struct VMStateDescription vmstate_ppc_timebase;
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH v2] migration: Do not re-read the clock on pre_save in case of paused guest
2019-07-11 19:47 [Qemu-devel] [PATCH v2] migration: Do not re-read the clock on pre_save in case of paused guest Maxiwell S. Garcia
@ 2019-07-12 6:48 ` David Gibson
0 siblings, 0 replies; 2+ messages in thread
From: David Gibson @ 2019-07-12 6:48 UTC (permalink / raw)
To: Maxiwell S. Garcia; +Cc: open list:PowerPC TCG CPUs, qemu-devel
[-- Attachment #1: Type: text/plain, Size: 2850 bytes --]
On Thu, Jul 11, 2019 at 04:47:02PM -0300, Maxiwell S. Garcia wrote:
> Re-read the timebase before migrate was ported from x86 commit:
> 6053a86fe7bd: kvmclock: reduce kvmclock difference on migration
>
> 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 timebase in case of paused state (cold migration).
>
> Signed-off-by: Maxiwell S. Garcia <maxiwell@linux.ibm.com>
I've applied this to ppc-for-4.2. I think it probably is a correct
fix, but this could have subtle impacts on things that are mostly
working at the moment, so I don't want to risk it during hard freeze.
> ---
> hw/ppc/ppc.c | 13 +++++++++----
> target/ppc/cpu-qom.h | 1 +
> 2 files changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/hw/ppc/ppc.c b/hw/ppc/ppc.c
> index a9e508c496..8572e45274 100644
> --- a/hw/ppc/ppc.c
> +++ b/hw/ppc/ppc.c
> @@ -1008,6 +1008,8 @@ static void timebase_save(PPCTimebase *tb)
> * there is no need to update it from KVM here
> */
> tb->guest_timebase = ticks + first_ppc_cpu->env.tb_env->tb_offset;
> +
> + tb->runstate_paused = runstate_check(RUN_STATE_PAUSED);
> }
>
> static void timebase_load(PPCTimebase *tb)
> @@ -1051,9 +1053,9 @@ void cpu_ppc_clock_vm_state_change(void *opaque, int running,
> }
>
> /*
> - * 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()
> * *
> @@ -1068,7 +1070,10 @@ static int timebase_pre_save(void *opaque)
> {
> PPCTimebase *tb = opaque;
>
> - timebase_save(tb);
> + /* guest_timebase won't be overridden in case of paused guest */
> + if (!tb->runstate_paused) {
> + timebase_save(tb);
> + }
>
> return 0;
> }
> diff --git a/target/ppc/cpu-qom.h b/target/ppc/cpu-qom.h
> index be9b4c30c3..5fbcdee9c9 100644
> --- a/target/ppc/cpu-qom.h
> +++ b/target/ppc/cpu-qom.h
> @@ -201,6 +201,7 @@ typedef struct PowerPCCPUClass {
> typedef struct PPCTimebase {
> uint64_t guest_timebase;
> int64_t time_of_the_day_ns;
> + bool runstate_paused;
> } PPCTimebase;
>
> extern const struct VMStateDescription vmstate_ppc_timebase;
--
David Gibson | I'll have my music baroque, and my code
david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_
| _way_ _around_!
http://www.ozlabs.org/~dgibson
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-07-12 7:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-11 19:47 [Qemu-devel] [PATCH v2] migration: Do not re-read the clock on pre_save in case of paused guest Maxiwell S. Garcia
2019-07-12 6:48 ` David Gibson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).