qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Crosthwaite <crosthwaitepeter@gmail.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, digetx@gmail.com,
	Peter Crosthwaite <crosthwaite.peter@gmail.com>
Subject: [Qemu-devel] [RFC v1 1/2] timer: arm_mp: Factor out timer value calculation
Date: Sun,  5 Jul 2015 13:26:39 -0700	[thread overview]
Message-ID: <1436128000-16262-2-git-send-email-crosthwaite.peter@gmail.com> (raw)
In-Reply-To: <1436128000-16262-1-git-send-email-crosthwaite.peter@gmail.com>

Factor out the code that calculates the runtime value of the timer.
Updates tb->count to the calculated value. Prepares support for pausing
the timer where the timer disable event should sync the counter to its
current value.

Signed-off-by: Peter Crosthwaite <crosthwaite.peter@gmail.com>
---
 hw/timer/arm_mptimer.c | 29 ++++++++++++++++++-----------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/hw/timer/arm_mptimer.c b/hw/timer/arm_mptimer.c
index 8b93b3c..04dfb63 100644
--- a/hw/timer/arm_mptimer.c
+++ b/hw/timer/arm_mptimer.c
@@ -72,25 +72,32 @@ static void timerblock_tick(void *opaque)
     timerblock_update_irq(tb);
 }
 
+static void timerblock_sync(TimerBlock *tb)
+{
+    int64_t val;
+
+    if (((tb->control & 1) == 0) || (tb->count == 0)) {
+        return;
+    }
+    /* Slow and ugly, but hopefully won't happen too often.  */
+    val = tb->tick - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
+    val /= timerblock_scale(tb);
+    if (val < 0) {
+        val = 0;
+    }
+    tb->count = val;
+}
+
 static uint64_t timerblock_read(void *opaque, hwaddr addr,
                                 unsigned size)
 {
     TimerBlock *tb = (TimerBlock *)opaque;
-    int64_t val;
     switch (addr) {
     case 0: /* Load */
         return tb->load;
     case 4: /* Counter.  */
-        if (((tb->control & 1) == 0) || (tb->count == 0)) {
-            return 0;
-        }
-        /* Slow and ugly, but hopefully won't happen too often.  */
-        val = tb->tick - qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
-        val /= timerblock_scale(tb);
-        if (val < 0) {
-            val = 0;
-        }
-        return val;
+        timerblock_sync(tb);
+        return tb->count;
     case 8: /* Control.  */
         return tb->control;
     case 12: /* Interrupt status.  */
-- 
1.9.1

  reply	other threads:[~2015-07-05 20:26 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-05 20:26 [Qemu-devel] [RFC v1 0/2] ARM MPTimer fixes and refactoring Peter Crosthwaite
2015-07-05 20:26 ` Peter Crosthwaite [this message]
2015-07-05 20:26 ` [Qemu-devel] [RFC v1 2/2] timer: arm_mp: consolidate control and counter write logic Peter Crosthwaite
2015-07-05 20:47 ` [Qemu-devel] [RFC v1 0/2] ARM MPTimer fixes and refactoring Dmitry Osipenko
2015-07-05 20:58   ` Peter Crosthwaite
2015-07-05 21:01     ` Peter Crosthwaite
2015-07-05 21:06       ` Peter Maydell
2015-07-05 21:12         ` Peter Crosthwaite
2015-07-05 21:21         ` Dmitry Osipenko
2015-09-20 17:48     ` Peter Crosthwaite
2015-10-03 13:11       ` Dmitry Osipenko
2015-10-05 16:07         ` Dmitry Osipenko
2015-10-05 16:27           ` Peter Crosthwaite
2015-10-05 16:43             ` 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=1436128000-16262-2-git-send-email-crosthwaite.peter@gmail.com \
    --to=crosthwaitepeter@gmail.com \
    --cc=crosthwaite.peter@gmail.com \
    --cc=digetx@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).