qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Sebastian Tanase <sebastian.tanase@openwide.fr>
To: Paolo Bonzini <pbonzini@redhat.com>
Cc: kwolf@redhat.com, peter maydell <peter.maydell@linaro.org>,
	aliguori@amazon.com, wenchaoqemu@gmail.com, quintela@redhat.com,
	qemu-devel@nongnu.org, mst@redhat.com, stefanha@redhat.com,
	armbru@redhat.com, lcapitulino@redhat.com, michael@walle.cc,
	camille begue <camille.begue@openwide.fr>,
	alex@alex.org.uk, crobinso@redhat.com, afaerber@suse.de,
	rth@twiddle.net
Subject: Re: [Qemu-devel] [RFC PATCH V4 6/6] monitor: Add drift info to 'info jit'
Date: Tue, 22 Jul 2014 11:58:04 +0200 (CEST)	[thread overview]
Message-ID: <601871010.20021638.1406023084319.JavaMail.root@openwide.fr> (raw)
In-Reply-To: <53C67BA9.50009@redhat.com>



----- Mail original -----
> De: "Paolo Bonzini" <pbonzini@redhat.com>
> À: "Sebastian Tanase" <sebastian.tanase@openwide.fr>, qemu-devel@nongnu.org
> Cc: aliguori@amazon.com, afaerber@suse.de, rth@twiddle.net, "peter maydell" <peter.maydell@linaro.org>,
> michael@walle.cc, alex@alex.org.uk, stefanha@redhat.com, lcapitulino@redhat.com, crobinso@redhat.com,
> armbru@redhat.com, wenchaoqemu@gmail.com, quintela@redhat.com, kwolf@redhat.com, mst@redhat.com, "camille begue"
> <camille.begue@openwide.fr>
> Envoyé: Mercredi 16 Juillet 2014 15:18:33
> Objet: Re: [RFC PATCH V4 6/6] monitor: Add drift info to 'info jit'
> 
> Il 16/07/2014 14:18, Sebastian Tanase ha scritto:
> > -    static int64_t clocks_offset;
> > -    if (!icount_align_option) {
> > -        return;
> > +    static int64_t realtime_clock_value;
> 
> Does this really need to be static?
> 
> > +    if (icount_align_option || !realtime_clock_value) {
> > +        realtime_clock_value =
> > qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
> >      }
> > -    sc->realtime_clock = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
> >      /* Compute offset between the 2 clocks. */
> >      if (!clocks_offset) {
> > -        clocks_offset = sc->realtime_clock -
> > +        clocks_offset = realtime_clock_value -
> >                          qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
> >      }
> 
> Isn't clocks_offset roughly the same as
> -timers_state.cpu_clock_offset?
>   If so, you could be some simplification in the code.  Feel free to
> move the TimersState struct definition to include/sysemu/cpus.h and
> make
> timers_state public.


-timers_state.cpu_clock_offset contains the offset between the real and virtual clocks.
However, when using the value of the virtual clock (qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL)),
qemu_icount_bias already includes this offset because, on ARM, qemu_clock_warp (which 
then calls icount_warp_rt) is called for the first time in tcg_exec_all, making
qemu_icount_bias take the value of qemu_clock_get_ns(QEMU_CLOCK_REALTIME)

    static void icount_warp_rt(void *opaque) {
        if (atomic_read(&vm_clock_warp_start) == -1) {
            return;
        }

        seqlock_write_lock(&timers_state.vm_clock_seqlock);
        if (runstate_is_running()) {
            int64_t clock = qemu_clock_get_ns(QEMU_CLOCK_REALTIME);
            int64_t warp_delta;
            ...
            warp_delta = clock - vm_clock_warp_start; //vm_clock_warp_start is 0 the very first time
            qemu_icount_bias += warp_delta;
        }
        vm_clock_warp_start = -1;
        seqlock_write_unlock(&timers_state.vm_clock_seqlock);

        if (qemu_clock_expired(QEMU_CLOCK_VIRTUAL)) {
            qemu_clock_notify(QEMU_CLOCK_VIRTUAL);
        }
    }


Also, the first time qemu_clock_warp -> icount_warp_rt are called (on ARM), qemu_clock_expired(QEMU_CLOCK_VIRTUAL) 
is false because there are no active timers on the vm clock timer list; I'll explain why I bring this up
below.

A solution to not compute the initial offset in qemu_icount_bias would be to initialize 
vm_clock_warp_start to -1. The result  will be that qemu_icount_bias will start counting when
the vcpu goes from active to inactive. At that time, vm_clock_warp_start will already store the realtime clock 
value and a timer on the real clock will be set to expire at clock + deadline, making qemu_icount_bias increment
by deadline.
A consequence of initializing vm_clock_warp_start to -1 is also 
the fact that we'll skip the first check for a virtual expired timer. As I mentioned above, in ARM case, 
it's not dangerous because there are no timers active the first time we perform this check. However, this 
is just a potential scenario and I cannot guarantee that on other target architectures there won't be 
an expired timer pending the first time we check.

I also tested on x86:
qemu_clock_warp -> icount_warp_rt are first called on "pit_reset" after a virtual timer is set to expire.
However, in this case, the qemu_clock_expired(QEMU_CLOCK_VIRTUAL) fails because the current virtual clock is 0
so the timer doesn't have to expire yet. In this case also the above solution would work without breaking anything.


So, do you think it is worth taking this solution into account or it will cause more harm than good?

Sebastian

> 
> > +    cpu_fprintf(f, "Host - Guest clock  %ld(ms)\n",
> > +                (qemu_clock_get_ns(QEMU_CLOCK_REALTIME) -
> > clocks_offset -
> > +                 qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL))/SCALE_MS);
> 
> I think this is (cpu_get_clock() - cpu_get_icount()) / SCALE_MS.
> 
> Paolo
> 

  reply	other threads:[~2014-07-22  9:58 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-16 12:18 [Qemu-devel] [RFC PATCH V4 0/6] icount: Implement delay algorithm between guest and host clocks Sebastian Tanase
2014-07-16 12:18 ` [Qemu-devel] [RFC PATCH V4 1/6] icount: Add QemuOpts for icount Sebastian Tanase
2014-07-16 12:18 ` [Qemu-devel] [RFC PATCH V4 2/6] icount: Add align option to icount Sebastian Tanase
2014-07-16 12:18 ` [Qemu-devel] [RFC PATCH V4 3/6] icount: Make icount_time_shift available everywhere Sebastian Tanase
2014-07-16 12:18 ` [Qemu-devel] [RFC PATCH V4 4/6] cpu_exec: Add sleeping algorithm Sebastian Tanase
2014-07-16 12:18 ` [Qemu-devel] [RFC PATCH V4 5/6] cpu_exec: Print to console if the guest is late Sebastian Tanase
2014-07-16 12:18 ` [Qemu-devel] [RFC PATCH V4 6/6] monitor: Add drift info to 'info jit' Sebastian Tanase
2014-07-16 13:18   ` Paolo Bonzini
2014-07-22  9:58     ` Sebastian Tanase [this message]
2014-07-22 10:19       ` Paolo Bonzini
2014-07-22 13:55         ` Sebastian Tanase
2014-07-16 13:20 ` [Qemu-devel] [RFC PATCH V4 0/6] icount: Implement delay algorithm between guest and host clocks Paolo Bonzini
2014-07-22 14:02   ` Sebastian Tanase
2014-07-22 14:59     ` Paolo Bonzini
2014-07-22 15:17       ` Sebastian Tanase
2014-07-22 15:22         ` Paolo Bonzini
2014-07-22 15:28           ` Sebastian Tanase
2014-07-22 15:44             ` Paolo Bonzini
2014-07-16 13:40 ` Luiz Capitulino

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=601871010.20021638.1406023084319.JavaMail.root@openwide.fr \
    --to=sebastian.tanase@openwide.fr \
    --cc=afaerber@suse.de \
    --cc=alex@alex.org.uk \
    --cc=aliguori@amazon.com \
    --cc=armbru@redhat.com \
    --cc=camille.begue@openwide.fr \
    --cc=crobinso@redhat.com \
    --cc=kwolf@redhat.com \
    --cc=lcapitulino@redhat.com \
    --cc=michael@walle.cc \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=rth@twiddle.net \
    --cc=stefanha@redhat.com \
    --cc=wenchaoqemu@gmail.com \
    /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).