Received: from eggs.gnu.org ([2001:4830:134:3::10]:57633) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1boQ1L-0001gC-11 for qemu-devel@nongnu.org; Mon, 26 Sep 2016 03:08:12 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1boQ1G-0007EF-Vp for qemu-devel@nongnu.org; Mon, 26 Sep 2016 03:08:10 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:36360) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1boQ1G-0007E1-PC for qemu-devel@nongnu.org; Mon, 26 Sep 2016 03:08:06 -0400 Received: by mail-wm0-f67.google.com with SMTP id b184so12579787wma.3 for ; Mon, 26 Sep 2016 00:08:06 -0700 (PDT) Sender: Paolo Bonzini References: <201609201519044580729@sangfor.com.cn> <67acae98-2704-22e8-1953-b2ae6714a41c@redhat.com> <2016092020541069238849@sangfor.com.cn> <20160921153601537436131@sangfor.com.cn> <68f9c490-2d10-8270-f936-949a1e70462e@redhat.com> <20160926113748142744182@sangfor.com.cn> From: Paolo Bonzini Message-ID: Date: Mon, 26 Sep 2016 09:07:05 +0200 MIME-Version: 1.0 In-Reply-To: <20160926113748142744182@sangfor.com.cn> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2]MC146818 RTC: coordinate guest clock base to destination host after migration List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "zhongjun@sangfor.com.cn" , qemu-devel Cc: "Michael S. Tsirkin" On 26/09/2016 05:37, zhongjun@sangfor.com.cn wrote: > Hi, Paolo > This is a simplified patch according to your advice. Would you please reiview it again. > > > ------------------------------------separation line-------------------------------------------- > > > MC146818 RTC: coordinate guest clock base to destination host after migration > > 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 > --- > hw/timer/mc146818rtc.c | 15 ++++++++++----- > 1 file changed, 10 insertions(+), 5 deletions(-) > > diff --git a/hw/timer/mc146818rtc.c b/hw/timer/mc146818rtc.c > index ea625f2..1df17af 100644 > --- a/hw/timer/mc146818rtc.c > +++ b/hw/timer/mc146818rtc.c > @@ -717,15 +717,20 @@ 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) { > - rtc_set_time(s); > - s->offset = 0; > - check_update_timer(s); > - } > + rtc_set_time(s); > + s->offset = 0; > + check_update_timer(s); This is wrong if rtc_clock is not QEMU_CLOCK_REALTIME. Paolo