From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paolo Bonzini Subject: Re: UIP flag not cleared Date: Tue, 03 Jul 2012 15:28:08 +0200 Message-ID: <4FF2F368.2050101@redhat.com> References: <2097433711.249908057.1339773258139.JavaMail.root@spooler3-g27.priv.proxad.net> <1795528294.249975120.1339774728128.JavaMail.root@spooler3-g27.priv.proxad.net> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: kvm@vger.kernel.org To: nicolas.ochem@free.fr Return-path: Received: from mail-yx0-f174.google.com ([209.85.213.174]:45904 "EHLO mail-yx0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932938Ab2GCN2V (ORCPT ); Tue, 3 Jul 2012 09:28:21 -0400 Received: by yenl2 with SMTP id l2so5244731yen.19 for ; Tue, 03 Jul 2012 06:28:20 -0700 (PDT) In-Reply-To: <1795528294.249975120.1339774728128.JavaMail.root@spooler3-g27.priv.proxad.net> Sender: kvm-owner@vger.kernel.org List-ID: Il 15/06/2012 17:38, nicolas.ochem@free.fr ha scritto: > Hi list, > > > I am having troubles porting my os to qemu/kvm environment. It's > about the RTC (real-time clock) > > There is a flag (UIP flag) which is supposed to show when RTC can be > read or not. > > We wait 10ms for that flag to be cleared, but sometimes it's not > enough with qemu/kvm. You need to wait more than 10ms then. :( This will be fixed in QEMU 1.2, but you cannot rule out delays due to bad scheduling of the virtual machine monitor (aka QEMU itself). > Is it necessary to check this flag at all ? or can I always read the > RTC regardless of the status of the flag ? If the latter is true, why > then is this flag not always clear ? Unlike real hardware, QEMU updates the time atomically; there are no "invalid states" during the update of the RTC. However, _reads_ of the RTC are not atomic so you do need UIP. UIP triggers 220 us *before* the invalid state, so that if UIP=0 you have 220 us to read the RTC. If your reads take less than 220 us, they are guaranteed to be atomic. If you need a workaround you can do the following (but it will break on bare metal): old_UIP = UIP read RTC if old_UIP = 1 and UIP = 0 read RTC again i.e. accept the old read if both old_UIP and UIP are 1 (and of course if old_UIP was 0). Paolo