diff mbox

[v15,10/15] hw/ptimer: Add "no immediate trigger" policy

Message ID 4f59caa4ce3786410b7d1afee30d480a8ff33aac.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
Performing trigger on setting (or starting to run with) counter = 0 could
be a wrong behaviour for some of the timers, provide "no immediate trigger"
policy to maintain correct behaviour for such timers.

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

Patch

diff --git a/hw/core/ptimer.c b/hw/core/ptimer.c
index 8578861..d37e8ab 100644
--- a/hw/core/ptimer.c
+++ b/hw/core/ptimer.c
@@ -40,8 +40,11 @@  static void ptimer_reload(ptimer_state *s, int delta_adjust)
     uint64_t period = s->period;
     uint64_t delta = s->delta;
 
-    if (delta == 0) {
+    if (delta == 0 && !(s->policy_mask & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER)) {
         ptimer_trigger(s);
+    }
+
+    if (delta == 0) {
         delta = s->delta = s->limit;
     }
 
@@ -62,6 +65,10 @@  static void ptimer_reload(ptimer_state *s, int delta_adjust)
         }
     }
 
+    if (delta == 0 && (s->policy_mask & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER)) {
+        delta = 1;
+    }
+
     if (delta == 0) {
         fprintf(stderr, "Timer with delta zero, disabling\n");
         timer_del(s->timer);
diff --git a/include/hw/ptimer.h b/include/hw/ptimer.h
index c97f02e..ec76183 100644
--- a/include/hw/ptimer.h
+++ b/include/hw/ptimer.h
@@ -19,6 +19,9 @@ 
 /* Periodic timer that has load = 0 would continuously re-trigger every
  * period.  */
 #define PTIMER_POLICY_CONTINUOUS_TRIGGER    (1 << 1)
+/* Starting to run with/setting counter = 0 won't perform immediate
+ * trigger.  */
+#define PTIMER_POLICY_NO_IMMEDIATE_TRIGGER  (1 << 2)
 
 /* ptimer.c */
 typedef struct ptimer_state ptimer_state;