Received: from eggs.gnu.org ([2001:4830:134:3::10]:60860) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsPwo-0004fs-Ci for qemu-devel@nongnu.org; Fri, 07 Oct 2016 03:52:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bsPwk-0003Cp-DX for qemu-devel@nongnu.org; Fri, 07 Oct 2016 03:52:01 -0400 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]:35779) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bsPwk-0003Be-6V for qemu-devel@nongnu.org; Fri, 07 Oct 2016 03:51:58 -0400 Received: by mail-wm0-x241.google.com with SMTP id f193so1625479wmg.2 for ; Fri, 07 Oct 2016 00:51:58 -0700 (PDT) Sender: Paolo Bonzini References: <20160926124101.2364-1-zhongjun@sangfor.com.cn> <20161007042417.3jyhamiwvqd3ttfx@redhat.com> From: Paolo Bonzini Message-ID: <4ef9716b-90dd-cfa9-135d-debb0eac6559@redhat.com> Date: Fri, 7 Oct 2016 09:51:55 +0200 MIME-Version: 1.0 In-Reply-To: <20161007042417.3jyhamiwvqd3ttfx@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v5] MC146818 RTC: coordinate guest clock base to destination host after migration List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" , Junlian Bell Cc: qemu-devel@nongnu.org On 07/10/2016 06:24, Michael S. Tsirkin wrote: > On Mon, Sep 26, 2016 at 08:41:01PM +0800, Junlian Bell wrote: >> qemu tracks guest time based on vector [base_rtc, last_update], in which >> last_update stands for a monotonic tick which is actually uptime of the >> host. >> according to rtc implementation codes of recent releases and upstream, >> after >> migration, the time base vector [base_rtc, last_update] isn't updated to >> coordinate with the destionation host, ie. qemu doesnt update last_update >> to >> uptime of the destination host. >> what problem have we got because of this bug? after migration, guest time >> may >> jump back to several days ago, that will make some critical business >> applications, >> such as lotus notes, malfunction. >> this patch is trying to fix the problem. first, when vmsave in progress, >> we >> rtc_update_time to refresh time stamp in cmos array, then during >> vmrestore, >> we rtc_set_time to update qemu base_rtc and last_update variable according >> to time >> stamp in cmos array. >> >> Signed-off-by: Junlian Bell > > Seems to make sense superficially but I'm not a good judge > of the timer code. > > Paolo, any comment on this? > > Acked-by: Michael S. Tsirkin Yes, I have it queued already. Paolo > >> --- >> hw/timer/mc146818rtc.c | 11 ++++++++++- >> 1 file changed, 10 insertions(+), 1 deletion(-) >> >> diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c >> index ea625f2..4e4af43 100644 >> --- a/hw/timer/mc146818rtc.c >> +++ b/hw/timer/mc146818rtc.c >> @@ -717,11 +717,19 @@ static void rtc_set_date_from_host(ISADevice *dev) >> rtc_set_cmos(s, &tm); >> } >> >> +static void rtc_pre_save(void *opaque) >> +{ >> + RTCState *s = opaque; >> + >> + rtc_update_time(s); >> +} >> + >> static int rtc_post_load(void *opaque, int version_id) >> { >> RTCState *s = opaque; >> >> - if (version_id <= 2) { >> + if (version_id <= 2 || >> + rtc_clock == QEMU_CLOCK_REALTIME){ >> rtc_set_time(s); >> s->offset = 0; >> check_update_timer(s); >> @@ -764,6 +772,7 @@ static const VMStateDescription vmstate_rtc = { >> .name = "mc146818rtc", >> .version_id = 3, >> .minimum_version_id = 1, >> + .pre_save = rtc_pre_save, >> .post_load = rtc_post_load, >> .fields = (VMStateField[]) { >> VMSTATE_BUFFER(cmos_data, RTCState), >> -- >> 2.9.0.windows.1 > >