hw/ptimer: Add "continuous trigger" policy
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> Message-id: 632b23dd11055d9bd5e338d66b38fac0bd51462e.1475421224.git.digetx@gmail.com Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
parent
293130aa91
commit
ef0a9984aa
@ -47,7 +47,8 @@ static void ptimer_reload(ptimer_state *s, int delta_adjust)
|
|||||||
ptimer_trigger(s);
|
ptimer_trigger(s);
|
||||||
delta = s->delta = s->limit;
|
delta = s->delta = s->limit;
|
||||||
}
|
}
|
||||||
if (delta == 0 || s->period == 0) {
|
|
||||||
|
if (s->period == 0) {
|
||||||
if (!qtest_enabled()) {
|
if (!qtest_enabled()) {
|
||||||
fprintf(stderr, "Timer with period zero, disabling\n");
|
fprintf(stderr, "Timer with period zero, disabling\n");
|
||||||
}
|
}
|
||||||
@ -60,6 +61,21 @@ static void ptimer_reload(ptimer_state *s, int delta_adjust)
|
|||||||
delta += delta_adjust;
|
delta += delta_adjust;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (delta == 0 && (s->policy_mask & PTIMER_POLICY_CONTINUOUS_TRIGGER)) {
|
||||||
|
if (s->enabled == 1 && s->limit == 0) {
|
||||||
|
delta = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (delta == 0) {
|
||||||
|
if (!qtest_enabled()) {
|
||||||
|
fprintf(stderr, "Timer with delta zero, disabling\n");
|
||||||
|
}
|
||||||
|
timer_del(s->timer);
|
||||||
|
s->enabled = 0;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Artificially limit timeout rate to something
|
* Artificially limit timeout rate to something
|
||||||
* achievable under QEMU. Otherwise, QEMU spends all
|
* achievable under QEMU. Otherwise, QEMU spends all
|
||||||
@ -90,7 +106,15 @@ static void ptimer_tick(void *opaque)
|
|||||||
if (s->enabled == 2) {
|
if (s->enabled == 2) {
|
||||||
s->enabled = 0;
|
s->enabled = 0;
|
||||||
} else {
|
} else {
|
||||||
ptimer_reload(s, DELTA_ADJUST);
|
int delta_adjust = DELTA_ADJUST;
|
||||||
|
|
||||||
|
if (s->limit == 0) {
|
||||||
|
/* If a "continuous trigger" policy is not used and limit == 0,
|
||||||
|
we should error out. */
|
||||||
|
delta_adjust = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
ptimer_reload(s, delta_adjust);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -98,7 +122,7 @@ uint64_t ptimer_get_count(ptimer_state *s)
|
|||||||
{
|
{
|
||||||
uint64_t counter;
|
uint64_t counter;
|
||||||
|
|
||||||
if (s->enabled) {
|
if (s->enabled && s->delta != 0) {
|
||||||
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
|
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
|
||||||
int64_t next = s->next_event;
|
int64_t next = s->next_event;
|
||||||
int64_t last = s->last_event;
|
int64_t last = s->last_event;
|
||||||
|
@ -39,6 +39,10 @@
|
|||||||
* around. */
|
* around. */
|
||||||
#define PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD (1 << 0)
|
#define PTIMER_POLICY_WRAP_AFTER_ONE_PERIOD (1 << 0)
|
||||||
|
|
||||||
|
/* Running periodic timer that has counter = limit = 0 would continuously
|
||||||
|
* re-trigger every period. */
|
||||||
|
#define PTIMER_POLICY_CONTINUOUS_TRIGGER (1 << 1)
|
||||||
|
|
||||||
/* ptimer.c */
|
/* ptimer.c */
|
||||||
typedef struct ptimer_state ptimer_state;
|
typedef struct ptimer_state ptimer_state;
|
||||||
typedef void (*ptimer_cb)(void *opaque);
|
typedef void (*ptimer_cb)(void *opaque);
|
||||||
|
Loading…
Reference in New Issue
Block a user