[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-arm] [PATCH v16 13/16] hw/ptimer: Add "no counter round down" poli
From: |
Dmitry Osipenko |
Subject: |
[Qemu-arm] [PATCH v16 13/16] hw/ptimer: Add "no counter round down" policy |
Date: |
Wed, 7 Sep 2016 16:22:24 +0300 |
For most of the timers counter starts to decrement after first period
expires. Due to rounding down performed by the ptimer_get_count, it returns
counter - 1 for the running timer, so that for the ptimer user it looks
like counter gets decremented immediately after running the timer. Add "no
counter round down" policy that provides correct behaviour for those timers.
Signed-off-by: Dmitry Osipenko <address@hidden>
---
hw/core/ptimer.c | 9 +++++++--
include/hw/ptimer.h | 4 ++++
2 files changed, 11 insertions(+), 2 deletions(-)
diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c
index f7f5538..88a1fe2 100644
--- a/hw/core/ptimer.c
+++ b/hw/core/ptimer.c
@@ -119,11 +119,14 @@ static void ptimer_tick(void *opaque)
uint64_t ptimer_get_count(ptimer_state *s)
{
+ bool no_round_down =
+ !!(s->policy_mask & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN);
uint64_t counter;
if (s->enabled && s->delta != 0) {
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);
@@ -131,7 +134,9 @@ uint64_t ptimer_get_count(ptimer_state *s)
if (expired) {
/* Prevent timer underflowing if it should already have
triggered. */
- counter = 0;
+ counter = no_round_down ? 1 : 0;
+ } else if (now == last && no_round_down) {
+ counter = s->delta;
} else {
uint64_t rem;
uint64_t div;
@@ -174,7 +179,7 @@ uint64_t ptimer_get_count(ptimer_state *s)
if ((uint32_t)(period_frac << shift))
div += 1;
}
- counter = rem / div;
+ counter = rem / div + (no_round_down ? 1 : 0);
if (!oneshot && s->delta == s->limit) {
/* Before wrapping around, timer should stay with counter = 0
diff --git a/include/hw/ptimer.h b/include/hw/ptimer.h
index 131fed1..5ce3270 100644
--- a/include/hw/ptimer.h
+++ b/include/hw/ptimer.h
@@ -49,6 +49,10 @@
/* Starting to run with/setting counter = 0 won't re-load counter. */
#define PTIMER_POLICY_NO_IMMEDIATE_RELOAD (1 << 3)
+/* Make counter value of the running timer represent the actual value and
+ * not the one less. */
+#define PTIMER_POLICY_NO_COUNTER_ROUND_DOWN (1 << 4)
+
/* ptimer.c */
typedef struct ptimer_state ptimer_state;
typedef void (*ptimer_cb)(void *opaque);
--
2.9.3
- Re: [Qemu-arm] [PATCH v16 05/16] hw/ptimer: Add "wraparound after one period" policy, (continued)
- [Qemu-arm] [PATCH v16 02/16] hw/ptimer: Introduce timer policy feature, Dmitry Osipenko, 2016/09/07
- [Qemu-arm] [PATCH v16 04/16] hw/ptimer: Suppress error messages under qtest, Dmitry Osipenko, 2016/09/07
- [Qemu-arm] [PATCH v16 10/16] tests: ptimer: Add tests for "no immediate trigger" policy, Dmitry Osipenko, 2016/09/07
- [Qemu-arm] [PATCH v16 07/16] hw/ptimer: Add "continuous trigger" policy, Dmitry Osipenko, 2016/09/07
- [Qemu-arm] [PATCH v16 12/16] tests: ptimer: Add tests for "no immediate reload" policy, Dmitry Osipenko, 2016/09/07
- [Qemu-arm] [PATCH v16 06/16] tests: ptimer: Add tests for "wraparound after one period" policy, Dmitry Osipenko, 2016/09/07
- [Qemu-arm] [PATCH v16 13/16] hw/ptimer: Add "no counter round down" policy,
Dmitry Osipenko <=
- [Qemu-arm] [PATCH v16 03/16] tests: Add ptimer tests, Dmitry Osipenko, 2016/09/07
[Qemu-arm] [PATCH v16 15/16] arm_mptimer: Convert to use ptimer, Dmitry Osipenko, 2016/09/07
[Qemu-arm] [PATCH v16 09/16] hw/ptimer: Add "no immediate trigger" policy, Dmitry Osipenko, 2016/09/07
[Qemu-arm] [PATCH v16 11/16] hw/ptimer: Add "no immediate reload" policy, Dmitry Osipenko, 2016/09/07
[Qemu-arm] [PATCH v16 14/16] tests: ptimer: Add tests for "no counter round down" policy, Dmitry Osipenko, 2016/09/07
[Qemu-arm] [PATCH v16 16/16] tests: Add tests for the ARM MPTimer, Dmitry Osipenko, 2016/09/07