Skip to content

Commit

Permalink
hw/ptimer: Add "no immediate trigger" policy
Browse files Browse the repository at this point in the history
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>
Message-id: 72c0319.1475421224.git.digetx@gmail.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
digetx authored and pm215 committed Oct 24, 2016
1 parent 2e74583 commit 22471b8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
20 changes: 16 additions & 4 deletions hw/core/ptimer.c
Expand Up @@ -13,7 +13,8 @@
#include "sysemu/replay.h"
#include "sysemu/qtest.h"

#define DELTA_ADJUST 1
#define DELTA_ADJUST 1
#define DELTA_NO_ADJUST -1

struct ptimer_state
{
Expand Down Expand Up @@ -43,8 +44,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;
}

Expand All @@ -58,7 +62,9 @@ static void ptimer_reload(ptimer_state *s, int delta_adjust)
}

if (s->policy_mask & PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD) {
delta += delta_adjust;
if (delta_adjust != DELTA_NO_ADJUST) {
delta += delta_adjust;
}
}

if (delta == 0 && (s->policy_mask & PTIMER_POLICY_CONTINUOUS_TRIGGER)) {
Expand All @@ -67,6 +73,12 @@ static void ptimer_reload(ptimer_state *s, int delta_adjust)
}
}

if (delta == 0 && (s->policy_mask & PTIMER_POLICY_NO_IMMEDIATE_TRIGGER)) {
if (delta_adjust != DELTA_NO_ADJUST) {
delta = 1;
}
}

if (delta == 0) {
if (!qtest_enabled()) {
fprintf(stderr, "Timer with delta zero, disabling\n");
Expand Down Expand Up @@ -111,7 +123,7 @@ static void ptimer_tick(void *opaque)
if (s->limit == 0) {
/* If a "continuous trigger" policy is not used and limit == 0,
we should error out. */
delta_adjust = 0;
delta_adjust = DELTA_NO_ADJUST;
}

ptimer_reload(s, delta_adjust);
Expand Down
4 changes: 4 additions & 0 deletions include/hw/ptimer.h
Expand Up @@ -43,6 +43,10 @@
* re-trigger every period. */
#define PTIMER_POLICY_CONTINUOUS_TRIGGER (1 << 1)

/* Starting to run with/setting counter to "0" won't trigger immediately,
* but after a one period for both oneshot and periodic modes. */
#define PTIMER_POLICY_NO_IMMEDIATE_TRIGGER (1 << 2)

/* ptimer.c */
typedef struct ptimer_state ptimer_state;
typedef void (*ptimer_cb)(void *opaque);
Expand Down

0 comments on commit 22471b8

Please sign in to comment.