diff mbox

[v15,08/15] hw/ptimer: Add "continuous trigger" policy

Message ID e26bd83e8044e6d1a613a750b90a34b30c4f2b46.1469110137.git.digetx@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Dmitry Osipenko July 21, 2016, 2:31 p.m. UTC
Currently, periodic timer that has load = delta = 0 performs trigger
on timer reload and stops, printing a "period zero" error message.
Introduce new policy that makes periodic timer to continuously trigger
with a period interval in case of load = 0.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 hw/core/ptimer.c    | 16 +++++++++++++++-
 include/hw/ptimer.h |  3 +++
 2 files changed, 18 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c
index c697c08..8578861 100644
--- a/hw/core/ptimer.c
+++ b/hw/core/ptimer.c
@@ -44,7 +44,8 @@  static void ptimer_reload(ptimer_state *s, int delta_adjust)
         ptimer_trigger(s);
         delta = s->delta = s->limit;
     }
-    if (delta == 0 || s->period == 0) {
+
+    if (s->period == 0) {
         fprintf(stderr, "Timer with period zero, disabling\n");
         timer_del(s->timer);
         s->enabled = 0;
@@ -55,6 +56,19 @@  static void ptimer_reload(ptimer_state *s, int delta_adjust)
         delta += delta_adjust;
     }
 
+    if (delta == 0 && (s->policy_mask & PTIMER_POLICY_CONTINUOUS_TRIGGER)) {
+        if (s->enabled == 1) {
+            delta = 1;
+        }
+    }
+
+    if (delta == 0) {
+        fprintf(stderr, "Timer with delta zero, disabling\n");
+        timer_del(s->timer);
+        s->enabled = 0;
+        return;
+    }
+
     /*
      * Artificially limit timeout rate to something
      * achievable under QEMU.  Otherwise, QEMU spends all
diff --git a/include/hw/ptimer.h b/include/hw/ptimer.h
index e8de48d..c97f02e 100644
--- a/include/hw/ptimer.h
+++ b/include/hw/ptimer.h
@@ -16,6 +16,9 @@ 
 /* Periodic timer counter stays with "0" for a one period before wrapping
  * around.  */
 #define PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD (1 << 0)
+/* Periodic timer that has load = 0 would continuously re-trigger every
+ * period.  */
+#define PTIMER_POLICY_CONTINUOUS_TRIGGER    (1 << 1)
 
 /* ptimer.c */
 typedef struct ptimer_state ptimer_state;