From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:53170) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RzNr1-0007yd-KJ for qemu-devel@nongnu.org; Mon, 20 Feb 2012 02:40:15 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RzNqx-00029p-HI for qemu-devel@nongnu.org; Mon, 20 Feb 2012 02:40:11 -0500 Received: from mail-ee0-f45.google.com ([74.125.83.45]:57685) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RzNqx-00029G-93 for qemu-devel@nongnu.org; Mon, 20 Feb 2012 02:40:07 -0500 Received: by eekd17 with SMTP id d17so2350076eek.4 for ; Sun, 19 Feb 2012 23:40:06 -0800 (PST) Sender: Paolo Bonzini Message-ID: <4F41F8D4.9080500@redhat.com> Date: Mon, 20 Feb 2012 08:40:04 +0100 From: Paolo Bonzini MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v2 4/4] RTC:Add UIP(update in progress) check logic List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Zhang, Yang Z" Cc: "aliguori@us.ibm.com" , Marcelo Tosatti , Jan Kiszka , "qemu-devel@nongnu.org" , "kvm@vger.kernel.org" On 02/20/2012 01:25 AM, Zhang, Yang Z wrote: > When time base is 32kHz, the update cycle takes 1984us at the end > of every second. And the update cycle begins 244us later after UIP > is set. So the UIP is set in 2228us at end of every second. I think we can keep UIP set only for 244us, since our update cycle is instantaneous. Otherwise looks good, thanks! Paolo > Signed-off-by: Yang Zhang > > --- > hw/mc146818rtc.c | 26 ++++++++++++++++++++++++++ > 1 files changed, 26 insertions(+), 0 deletions(-) > > diff --git a/hw/mc146818rtc.c b/hw/mc146818rtc.c > index 2445c6b..d4be8e9 100644 > --- a/hw/mc146818rtc.c > +++ b/hw/mc146818rtc.c > @@ -601,6 +601,29 @@ static void rtc_calibrate_time(RTCState *s) > s->current_tm = *ret; > } > > +static int update_in_progress(RTCState *s) > +{ > + struct timeval tv_now; > + int64_t host_usec, offset_usec, guest_usec; > + > + if (s->cmos_data[RTC_REG_B] & REG_B_SET) { > + return 0; > + } > + > + gettimeofday(&tv_now, NULL); > + host_usec = tv_now.tv_sec * USEC_PER_SEC + tv_now.tv_usec; > + offset_usec = s->offset_sec * USEC_PER_SEC + s->offset_usec; > + guest_usec = host_usec + offset_usec; > + > + /* UIP bit will be set at last 2228us of every second. > + * Only consider oscillator in 32.768kHz*/ > + if ((guest_usec % USEC_PER_SEC) >= (USEC_PER_SEC - 2228)) { > + return 1; > + }