Skip to content

Commit 273f5b5

Browse files
committed
[ot] hw/opentitan: ot_aon_timer: use VIRTUAL_RT clock
Switch to QEMU_CLOCK_VIRTUAL_RT to avoid timing issues when using -icount option. Signed-off-by: Loïc Lefort <[email protected]>
1 parent e62c858 commit 273f5b5

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

hw/opentitan/ot_aon_timer.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ static void ot_aon_timer_update_irqs(OtAonTimerState *s)
199199

200200
static void ot_aon_timer_rearm_wkup(OtAonTimerState *s, bool reset_origin)
201201
{
202-
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
202+
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL_RT);
203203

204204
if (reset_origin) {
205205
s->wkup_origin_ns = now;
@@ -238,7 +238,7 @@ static void ot_aon_timer_wkup_cb(void *opaque)
238238

239239
static void ot_aon_timer_rearm_wdog(OtAonTimerState *s, bool reset_origin)
240240
{
241-
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
241+
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL_RT);
242242

243243
if (reset_origin) {
244244
s->wdog_origin_ns = now;
@@ -304,14 +304,14 @@ static uint64_t ot_aon_timer_read(void *opaque, hwaddr addr, unsigned size)
304304
break;
305305
case R_WKUP_COUNT: {
306306
uint64_t now = ot_aon_timer_is_wkup_enabled(s) ?
307-
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) :
307+
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL_RT) :
308308
s->wkup_origin_ns;
309309
val32 = ot_aon_timer_get_wkup_count(s, now);
310310
break;
311311
}
312312
case R_WDOG_COUNT: {
313313
uint64_t now = ot_aon_timer_is_wdog_enabled(s) ?
314-
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) :
314+
qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL_RT) :
315315
s->wdog_origin_ns;
316316
val32 = ot_aon_timer_get_wdog_count(s, now);
317317
break;
@@ -365,7 +365,7 @@ static void ot_aon_timer_write(void *opaque, hwaddr addr, uint64_t value,
365365
/* stop timer */
366366
timer_del(s->wkup_timer);
367367
/* save current count */
368-
uint32_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
368+
uint32_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL_RT);
369369
s->regs[R_WKUP_COUNT] = ot_aon_timer_get_wkup_count(s, now);
370370
s->wkup_origin_ns = now;
371371
}
@@ -398,7 +398,7 @@ static void ot_aon_timer_write(void *opaque, hwaddr addr, uint64_t value,
398398
/* stop timer */
399399
timer_del(s->wdog_timer);
400400
/* save current count */
401-
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
401+
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL_RT);
402402
s->regs[R_WDOG_COUNT] = ot_aon_timer_get_wdog_count(s, now);
403403
s->wdog_origin_ns = now;
404404
}
@@ -432,7 +432,7 @@ static void ot_aon_timer_write(void *opaque, hwaddr addr, uint64_t value,
432432
* schedule the timer for the next peripheral clock tick to check again
433433
* for interrupt condition
434434
*/
435-
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL);
435+
int64_t now = qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL_RT);
436436
int64_t next = ot_aon_timer_compute_next_timeout(s, now, 0);
437437
if (change & INTR_WKUP_TIMER_EXPIRED_MASK) {
438438
timer_mod_anticipate(s->wkup_timer, next);
@@ -500,8 +500,10 @@ static void ot_aon_timer_init(Object *obj)
500500
TYPE_OT_AON_TIMER, 0x400u);
501501
sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio);
502502

503-
s->wkup_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, &ot_aon_timer_wkup_cb, s);
504-
s->wdog_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, &ot_aon_timer_wdog_cb, s);
503+
s->wkup_timer =
504+
timer_new_ns(QEMU_CLOCK_VIRTUAL_RT, &ot_aon_timer_wkup_cb, s);
505+
s->wdog_timer =
506+
timer_new_ns(QEMU_CLOCK_VIRTUAL_RT, &ot_aon_timer_wdog_cb, s);
505507
}
506508

507509
static void ot_aon_timer_class_init(ObjectClass *klass, void *data)

0 commit comments

Comments
 (0)