]> xenbits.xensource.com Git - qemu-xen.git/commitdiff
hw/ptimer: Add "no counter round down" policy
authorDmitry Osipenko <digetx@gmail.com>
Mon, 24 Oct 2016 15:26:52 +0000 (16:26 +0100)
committerPeter Maydell <peter.maydell@linaro.org>
Mon, 24 Oct 2016 15:26:52 +0000 (16:26 +0100)
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 <digetx@gmail.com>
Message-id: ef39622d0ebfdc32a0877e59ffdf6910dc3db688.1475421224.git.digetx@gmail.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
hw/core/ptimer.c
include/hw/ptimer.h

index 2a69dafca6edee153f5b660c5699e979e82346fa..3af82afe781014e3b8a780929c09753fc27e8c7a 100644 (file)
@@ -231,6 +231,15 @@ uint64_t ptimer_get_count(ptimer_state *s)
                 }
             }
         }
+
+        if (s->policy_mask & PTIMER_POLICY_NO_COUNTER_ROUND_DOWN) {
+            /* If now == last then delta == limit, i.e. the counter already
+               represents the correct value. It would be rounded down a 1ns
+               later.  */
+            if (now != last) {
+                counter += 1;
+            }
+        }
     } else {
         counter = s->delta;
     }
index 5455340187a8da298622a51a44dde800b520093c..48cccbdb51b71d05aa862c004192f947aa00a000 100644 (file)
  * immediately, but after a one period.  */
 #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);