All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrew Jeffery <andrew@aj.id.au>
To: openbmc@lists.ozlabs.org
Cc: joel@jms.id.au, clg@kaod.org, geissonator@gmail.com,
	Andrew Jeffery <andrew@aj.id.au>
Subject: [RFC qemu legoater/aspeed-3.1 3/4] timer: aspeed: Fix match calculations
Date: Fri, 11 Jan 2019 14:26:37 +1030	[thread overview]
Message-ID: <20190111035638.19725-4-andrew@aj.id.au> (raw)
In-Reply-To: <20190111035638.19725-1-andrew@aj.id.au>

If the match value exceeds reload then we don't want to include it in
calculations for the next event.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
---
 hw/timer/aspeed_timer.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/hw/timer/aspeed_timer.c b/hw/timer/aspeed_timer.c
index 6adc14d62034..35b40a7c4010 100644
--- a/hw/timer/aspeed_timer.c
+++ b/hw/timer/aspeed_timer.c
@@ -107,6 +107,11 @@ static inline uint64_t calculate_time(struct AspeedTimer *t, uint32_t ticks)
     return t->start + delta_ns;
 }
 
+static inline uint32_t calculate_match(struct AspeedTimer *t, int i)
+{
+    return t->match[i] < t->reload ? t->match[i] : 0;
+}
+
 static uint64_t calculate_next(struct AspeedTimer *t)
 {
     uint64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
@@ -116,11 +121,11 @@ static uint64_t calculate_next(struct AspeedTimer *t)
      * registers, so sort using MAX/MIN/zero. We sort in that order as the
      * timer counts down to zero. */
 
-    next = calculate_time(t, MAX(t->match[0], t->match[1]));
+    next = calculate_time(t, MAX(calculate_match(t, 0), calculate_match(t, 1)));
     if (now < next)
         return next;
 
-    next = calculate_time(t, MIN(t->match[0], t->match[1]));
+    next = calculate_time(t, MIN(calculate_match(t, 0), calculate_match(t, 1)));
     if (now < next)
         return next;
 
@@ -136,8 +141,10 @@ static uint64_t calculate_next(struct AspeedTimer *t)
         qemu_set_irq(t->irq, t->level);
     }
 
+    next = MAX(MAX(calculate_match(t, 0), calculate_match(t, 1)), 0);
     t->start = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
-    return calculate_time(t, MAX(MAX(t->match[0], t->match[1]), 0));
+
+    return calculate_time(t, next);
 }
 
 static void aspeed_timer_mod(AspeedTimer *t)
-- 
2.19.1

  parent reply	other threads:[~2019-01-11  3:57 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-11  3:56 [RFC qemu legoater/aspeed-3.1 0/4] Handle short timer periods Andrew Jeffery
2019-01-11  3:56 ` [RFC qemu legoater/aspeed-3.1 1/4] timer: aspeed: Fire interrupt on failure to meet deadline Andrew Jeffery
2019-01-11  8:44   ` Cédric Le Goater
2019-01-11  8:52     ` Andrew Jeffery
2019-01-11  3:56 ` [RFC qemu legoater/aspeed-3.1 2/4] timer: aspeed: Status register contains reload for stopped timer Andrew Jeffery
2019-01-11  9:58   ` Cédric Le Goater
2019-01-11  3:56 ` Andrew Jeffery [this message]
2019-01-11 10:00   ` [RFC qemu legoater/aspeed-3.1 3/4] timer: aspeed: Fix match calculations Cédric Le Goater
2019-01-11  3:56 ` [RFC qemu legoater/aspeed-3.1 4/4] timer: aspeed: Provide back-pressure information for short periods Andrew Jeffery
2019-01-11 10:10   ` Cédric Le Goater
2019-01-13 23:07     ` Andrew Jeffery
2019-01-14  8:55       ` Cédric Le Goater
2019-01-11 10:14 ` [RFC qemu legoater/aspeed-3.1 0/4] Handle short timer periods Cédric Le Goater
2019-01-14  1:43   ` Andrew Jeffery

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=20190111035638.19725-4-andrew@aj.id.au \
    --to=andrew@aj.id.au \
    --cc=clg@kaod.org \
    --cc=geissonator@gmail.com \
    --cc=joel@jms.id.au \
    --cc=openbmc@lists.ozlabs.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.