qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Osipenko <digetx@gmail.com>
To: Peter Crosthwaite <crosthwaitepeter@gmail.com>
Cc: Peter Maydell <peter.maydell@linaro.org>,
	QEMU Developers <qemu-devel@nongnu.org>
Subject: Re: [Qemu-devel] [PATCH v7 1/2] hw/ptimer: Fix issues caused by artificially limited timer timeout
Date: Sun, 25 Oct 2015 01:22:06 +0300	[thread overview]
Message-ID: <562C048E.4020804@gmail.com> (raw)
In-Reply-To: <CAPokK=peXi=UJK7b7RsvRmS6f0GcM-j2vvnQmfvtObM9R3KPmQ@mail.gmail.com>

24.10.2015 22:45, Peter Crosthwaite пишет:
>
> This looks like a give-up without trying to get the correct value. If
> the calculated value (using the normal-path logic below) is sane, you
> should just use it. If it comes out bad then you should clamp to 1.
>
> I am wondering whether this clamping policy (as in original code as
> well) is correct at all though. The value of a free-running
> short-interval periodic timer (poor mans random number generator)
> without any actual interrupt generation will be affected by QEMUs
> asynchronous handling of timer events. So if I set limit to 100, then
> sample this timer every user keyboard stroke, I should get a uniform
> distribution on [0,100]. Instead in am going to get lots of 1s. This

Right, that's a good example. What about to scale ptimer period to match 
adjusted timer_mod interval?

> is more broken in the original code (as you state), as I will get >
> 100, but I think we have traded broken for slightly less broken. I
> think the correct semantic is to completely ignoring rate limitin
> except for the scheduling on event callbacks. That is, the timer

I'm missing you here. What event callbacks?

> interval is not rate limited, instead the timer_mod interval
> (next_event -last_event) just has a 10us clamp.
>
> The means the original code semantic of returning counter = 0 for an
> already triggered timer is wrong. It should handle in-the-past
> wrap-arounds as wraparounds by triggering the timer and redoing the
> math with the new interval values. So instead the logic would be
> something like:
>
> timer_val = -1;
>
> for(;;) {
>
>   if (!enabled) {
>      return delta;
>   }
>
>   timer_val = (next-event - now) *  scaling();
>   if (timer_val >=  0) {
>       return timer_val;
>   }
>   /* Timer has actually expired but we missed it, reload it and try again */
>   ptimer_tick();
> }

Why do you think that ptimer_get_count() == 0 in case of the running periodic 
timer that was expired while QEMU was "on the way" to ptimer code is bad and 
wrong? From the guest point of view it's okay (no?), do we really need to 
overengineer that corner case?

>
> ptimer_reload() then needs to be patched to make sure it always
> timer_mod()s in the future, otherwise this loop could iterate a large
> number of times.
>
> This means that when the qemu_timer() actually ticks, a large number
> or cycles may have occured, but we can justify that in that callback
> event latency (usually interrupts) is undefined anyway and coalescing
> of multiples may have happened as part of that. This usually matches
> expectations of real guests where interrupt latency is ultimately
> undefined.

ptimer_tick() is re-arm'ing the qemu_timer() in case of periodic mode. Hope I 
haven't missed your point here.

>
> Regards,
> Peter
>

-- 
Dmitry

  reply	other threads:[~2015-10-24 22:23 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-24 12:21 [Qemu-devel] [PATCH v7 0/2] PTimer fix and ARM MPTimer conversion Dmitry Osipenko
2015-10-24 12:21 ` [Qemu-devel] [PATCH v7 1/2] hw/ptimer: Fix issues caused by artificially limited timer timeout Dmitry Osipenko
2015-10-24 19:45   ` Peter Crosthwaite
2015-10-24 22:22     ` Dmitry Osipenko [this message]
2015-10-24 23:55       ` Peter Crosthwaite
2015-10-25 13:23         ` Dmitry Osipenko
2015-10-25 17:39           ` Peter Crosthwaite
2015-10-27 21:26             ` Dmitry Osipenko
2015-10-29  1:39               ` Peter Crosthwaite
2015-10-29 14:28                 ` Dmitry Osipenko
2015-10-30 16:14                   ` Dmitry Osipenko
2015-10-24 12:22 ` [Qemu-devel] [PATCH v7 2/2] arm_mptimer: Convert to use ptimer Dmitry Osipenko
2015-10-30 21:52 ` [Qemu-devel] [PATCH v7 0/2] PTimer fix and ARM MPTimer conversion Peter Maydell
2015-10-30 22:44   ` Dmitry Osipenko

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=562C048E.4020804@gmail.com \
    --to=digetx@gmail.com \
    --cc=crosthwaitepeter@gmail.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).