qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Osipenko <digetx@gmail.com>
To: QEMU Developers <qemu-devel@nongnu.org>, qemu-arm@nongnu.org
Cc: Peter Crosthwaite <crosthwaitepeter@gmail.com>,
	Peter Maydell <peter.maydell@linaro.org>
Subject: [Qemu-devel] [PATCH v15 02/15] hw/ptimer: Fix counter - 1 returned by ptimer_get_count for the active timer
Date: Thu, 21 Jul 2016 17:31:13 +0300	[thread overview]
Message-ID: <2592778c5f9be74a63c50647075843f13e6e24f6.1469110137.git.digetx@gmail.com> (raw)
In-Reply-To: <cover.1469110137.git.digetx@gmail.com>
In-Reply-To: <cover.1469110137.git.digetx@gmail.com>

Due to rounding down performed by ptimer_get_count, it returns counter - 1 for
the enabled timer. That's incorrect because counter should decrement only after
period been expired, not before. I.e. if running timer has been loaded with
value X, then timer counter should stay with X until period expired.
Fix this by adding 1 to the counter value.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 hw/core/ptimer.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c
index 9dc2bb0..461b91c 100644
--- a/hw/core/ptimer.c
+++ b/hw/core/ptimer.c
@@ -89,6 +89,7 @@ uint64_t ptimer_get_count(ptimer_state *s)
     if (s->enabled) {
         int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
         int64_t next = s->next_event;
+        int64_t last = s->last_event;
         bool expired = (now - next >= 0);
         bool oneshot = (s->enabled == 2);
 
@@ -97,6 +98,8 @@ uint64_t ptimer_get_count(ptimer_state *s)
             /* Prevent timer underflowing if it should already have
                triggered.  */
             counter = 1;
+        } else if (now == last) {
+            counter = s->delta;
         } else {
             uint64_t rem;
             uint64_t div;
@@ -139,7 +142,7 @@ uint64_t ptimer_get_count(ptimer_state *s)
                 if ((uint32_t)(period_frac << shift))
                     div += 1;
             }
-            counter = rem / div;
+            counter = rem / div + 1;
         }
     } else {
         counter = s->delta;
-- 
2.9.2

  parent reply	other threads:[~2016-07-21 14:32 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-07-21 14:31 [Qemu-devel] [PATCH v15 00/15] PTimer fixes/features and ARM MPTimer conversion Dmitry Osipenko
2016-07-21 14:31 ` [Qemu-devel] [PATCH v15 01/15] hw/ptimer: Change ptimer_get_count to return "1" for the expired timer Dmitry Osipenko
2016-07-21 14:31 ` Dmitry Osipenko [this message]
2016-07-21 14:31 ` [Qemu-devel] [PATCH v15 03/15] hw/ptimer: Actually stop timer in case of error Dmitry Osipenko
2016-07-21 14:31 ` [Qemu-devel] [PATCH v15 04/15] hw/ptimer: Introduce timer policy feature Dmitry Osipenko
2016-07-21 14:31 ` [Qemu-devel] [PATCH v15 05/15] tests: Add ptimer tests Dmitry Osipenko
2016-07-21 14:31 ` [Qemu-devel] [PATCH v15 06/15] hw/ptimer: Add "wraparound after one period" policy Dmitry Osipenko
2016-07-21 14:31 ` [Qemu-devel] [PATCH v15 07/15] tests: ptimer: Add tests for " Dmitry Osipenko
2016-07-21 14:31 ` [Qemu-devel] [PATCH v15 08/15] hw/ptimer: Add "continuous trigger" policy Dmitry Osipenko
2016-07-21 14:31 ` [Qemu-devel] [PATCH v15 09/15] tests: ptimer: Add tests for " Dmitry Osipenko
2016-07-21 14:31 ` [Qemu-devel] [PATCH v15 10/15] hw/ptimer: Add "no immediate " Dmitry Osipenko
2016-07-21 14:31 ` [Qemu-devel] [PATCH v15 11/15] tests: ptimer: Add tests for " Dmitry Osipenko
2016-07-21 14:31 ` [Qemu-devel] [PATCH v15 12/15] hw/ptimer: Add "no immediate reload" policy Dmitry Osipenko
2016-07-21 14:31 ` [Qemu-devel] [PATCH v15 13/15] tests: ptimer: Add tests for " Dmitry Osipenko
2016-07-21 14:31 ` [Qemu-devel] [PATCH v15 14/15] arm_mptimer: Convert to use ptimer Dmitry Osipenko
2016-07-21 14:31 ` [Qemu-devel] [PATCH v15 15/15] tests: Add tests for the ARM MPTimer Dmitry Osipenko
2016-09-05 18:14 ` [Qemu-devel] [PATCH v15 00/15] PTimer fixes/features and ARM MPTimer conversion Peter Maydell
2016-09-05 21:52   ` Dmitry Osipenko
2016-09-05 22:12     ` Peter Maydell
2016-09-06 10:32       ` Dmitry Osipenko
2016-09-06 10:36         ` Peter Maydell

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=2592778c5f9be74a63c50647075843f13e6e24f6.1469110137.git.digetx@gmail.com \
    --to=digetx@gmail.com \
    --cc=crosthwaitepeter@gmail.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.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).