qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Paolo Bonzini <pbonzini@redhat.com>
To: Marcelo Tosatti <mtosatti@redhat.com>
Cc: qemu-devel@nongnu.org, kvm@vger.kernel.org
Subject: Re: [Qemu-devel] [PATCH 3/3] stop the periodic RTC update timer
Date: Thu, 12 Jan 2012 11:43:10 +0100	[thread overview]
Message-ID: <4F0EB93E.9090908@redhat.com> (raw)
In-Reply-To: <20120112102031.GA31635@amt.cnet>

On 01/12/2012 11:20 AM, Marcelo Tosatti wrote:
>> >
>> >  The point is not_correctness_.  It is_atomicity_.
> Quoting you earlier
>
> "This is incorrect, for two reasons.  First, the UIP is in the spec,
> and we have to implement it.  Second, reading the clock is not atomic,
> and waiting for UIP=0 gives you 220 microseconds during which you know
> that the read will appear atomic."

(The actual figure is 244, not 220; my mistake).

> Agree with the first point, but the second, the emulated RTC never
> returns a bogus read.

That's true: the update cycle takes 1984 us on the real RTC, and 0 us on 
QEMU.

However, the data sheet says that the update cycle begins 244 us _after_ 
the rising edge of UIP.  In other words, UIP is set for 1984 + 244 us on 
the real RTC, and should be set for 0 + 244 us on the emulated RTC.

This is done on purpose: the data sheet says, "if a low is read on the 
UIP bit, the user has at least 244 us before the time/calendar data will 
be changed".  As long as you read the time within 244 us, the following 
cannot happen:

    read UIP     => 0
    read HOURS   => 10
    read MINUTES => 59
    read SECONDS => 59
    ...
    read UIP     => 0
    read HOURS   => 10
    read MINUTES => 59
                       update happens! (on real RTC: update cycle starts)
    read SECONDS => 0                  (on real RTC: undefined)

You are a kernel junkie and as such you are too much accustomed to 
seqlocks. ;)

If you know the read will take more than 244 us, the data sheet suggests 
that you use the update-ended interrupt.  But you can also wait for the 
falling edge of UIP, like Xen does.  The falling edge of UIP will never 
happen if the emulated RTC always returns 0 for UIP.

Paolo

  reply	other threads:[~2012-01-12 10:43 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-06  7:37 [Qemu-devel] [PATCH 3/3] stop the periodic RTC update timer Zhang, Yang Z
2012-01-06 17:26 ` Jan Kiszka
2012-01-09  7:10   ` Zhang, Yang Z
2012-01-09  8:19 ` Paolo Bonzini
2012-01-10  6:37   ` Zhang, Yang Z
2012-01-10  9:24     ` Paolo Bonzini
2012-01-11  0:56       ` Zhang, Yang Z
2012-01-11  7:24         ` Paolo Bonzini
2012-01-12  0:51           ` Zhang, Yang Z
2012-01-11  7:25         ` Philipp Hahn
2012-01-11 13:10 ` Marcelo Tosatti
2012-01-12  0:00   ` Zhang, Yang Z
2012-01-12  9:26     ` Paolo Bonzini
2012-01-12 10:20       ` Marcelo Tosatti
2012-01-12 10:43         ` Paolo Bonzini [this message]
2012-01-12  9:59     ` Marcelo Tosatti
2012-01-12 10:03       ` Marcelo Tosatti
2012-01-12 10:12         ` Zhang, Yang Z

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4F0EB93E.9090908@redhat.com \
    --to=pbonzini@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=mtosatti@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).