qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Bug 893208 <893208@bugs.launchpad.net>,
	Laszlo Ersek <lersek@redhat.com>,
	QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [Bug 893208] Re: qemu on ARM hosts can't boot i386 image
Date: Mon, 21 Sep 2015 16:50:55 +0100	[thread overview]
Message-ID: <20150921155055.GE2629@work-vm> (raw)
In-Reply-To: <CAFEAcA_2erpZnuBZZwko5Lekruszi3Jv-VpMH8Wd4oA6T8Y_wg@mail.gmail.com>

* Peter Maydell (peter.maydell@linaro.org) wrote:
> On 21 September 2015 at 08:12, Laszlo Ersek <lersek@redhat.com> wrote:
> > Where does the division by zero come from then? Well grub fetches and
> > stashes the TSC, then programs the PIT to sleep for some time, then
> > re-fetches the TSC, and uses the TSC difference as denominator when
> > calculating the "TSC rate". (It has a solid idea of the real time
> > passed, due to the PIT frequency being a given.)
> 
> I was wondering rereading the bug report whether this was down
> to our lousy RDTSC implementation...thanks for digging in and
> confirming what's going on.
> 
> > Now, the cpu_get_real_ticks() implementation is *host* specific. You can
> > find it implemented for a bunch of host architectures in
> > "include/qemu/timer.h".
> 
> > I applied the following extremely sophisticated patch (with the motto
> > "it cannot get more wronger"):
> >
> >> diff --git a/include/qemu/timer.h b/include/qemu/timer.h
> >> index 9939246..def22de 100644
> >> --- a/include/qemu/timer.h
> >> +++ b/include/qemu/timer.h
> >> @@ -1003,8 +1003,7 @@ static inline int64_t cpu_get_real_ticks(void)
> >>     totally wrong, but hopefully better than nothing.  */
> >>  static inline int64_t cpu_get_real_ticks (void)
> >>  {
> >> -    static int64_t ticks = 0;
> >> -    return ticks++;
> >> +    return get_clock();
> >>  }
> >>  #endif
> >>
> >
> > get_clock() is CLOCK_MONOTONIC based, has (theoretical) nanosecond
> > resolution, and a nice flat int64_t encoding that should suffice for
> > approx. 329 years. This should provide grub with a larger denominator.
> >
> > This "fix" allowed me to boot the i386 Debian image on the AARCH64 host.
> >
> > For a real fix... I think on AARCH64 hosts at least, a "real" cycle
> > counter should be available, and someone who knows AARCH64 could write a
> > function that fetches it.
> >
> > For 32-bit ARM, I presume the Raspberry Pi 2 and the Odroid C1 are
> > advanced enough for a similar cycle counter reading function.
> 
> There isn't a user-space readable cycle counter on ARM.
> (There is a counter which might be accessible to userspace
> depending on kernel config, but the kernel doesn't guarantee
> its availability as an ABI thing.)
> 
> Probably we should figure out a sane way to emulate guest
> cycle counters that isn't dependent on the host CPU architecture.
> I think having QEMU's behaviour as seen by the guest vary like
> this is a recipe for confusion.

Time is always hard though;  what are the requirements for that
particular view of time:

   1) It must be monotonic - which get_clock() is iff the host
      supports it (which I guess most do?)
   2) It's got to be within a few orders of magnitude of sane
      with respect to wall clock, so that if someone measures
      it over a second or a 1/100th of a second or whatever then
      it's still seen to go up.

get_clock() isn't that bad if it's monotonic; if not I'd suggest
for TCG a multiple of the number of TBs executed (if that's
already stored somewhere), or something similar.

Dave

> thanks
> -- PMM
--
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK

  reply	other threads:[~2015-09-21 15:51 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20111121171820.16487.92704.malonedeb@chaenomeles.canonical.com>
2011-12-10 13:40 ` [Qemu-devel] [Bug 893208] Re: qemu on ARM hosts can't boot i386 image Peter Maydell
2012-01-05  0:58 ` Michael Hope
2012-01-12 10:14 ` Peter Maydell
2015-09-16 23:12 ` PeteVine
2015-09-17  1:23 ` PeteVine
2015-09-19 10:54 ` Marina Kovalevna
2015-09-21 15:12   ` Laszlo Ersek
2015-09-21 15:37     ` Peter Maydell
2015-09-21 15:50       ` Dr. David Alan Gilbert [this message]
2015-09-21 17:12         ` Laszlo Ersek
2015-09-22  2:02     ` Marina Kovalevna
2015-09-21 17:43 ` PeteVine
2015-09-21 18:01 ` Dr. David Alan Gilbert
2015-09-29 11:07 ` Paolo Bonzini
2015-10-14  1:27 ` PeteVine
2015-11-07 20:31 ` PeteVine
2015-11-08 18:20 ` Marina Kovalevna
2015-12-21 18:45 ` PeteVine
2016-01-12 21:58 ` pranith
2016-02-28  1:12 ` Zack Callendish
2016-02-28 15:22 ` Peter Maydell
2016-02-29 15:23 ` Zack Callendish
2016-02-29 16:24 ` Peter Maydell
2016-03-11  9:15 ` PeteVine
2016-03-18 20:56   ` [Qemu-devel] [RFC] Use cpu_get_icount as cpu_get_host_ticks fallback Christopher Covington
2016-03-19 10:44 ` [Qemu-devel] [Bug 893208] Re: qemu on ARM hosts can't boot i386 image PeteVine
2016-03-19 14:24 ` PeteVine
2017-06-13 17:23 ` Thomas Huth
2017-06-13 22:17 ` PeteVine
2017-08-30 20:08 ` Thomas Huth
2020-08-12 12:35 ` Laszlo Ersek (Red Hat)

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=20150921155055.GE2629@work-vm \
    --to=dgilbert@redhat.com \
    --cc=893208@bugs.launchpad.net \
    --cc=lersek@redhat.com \
    --cc=peter.maydell@linaro.org \
    --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).