migration is not supported yet. Signed-off-by: Liu Ping Fan <pingf...@linux.vnet.ibm.com> --- hw/timer/hpet.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-)
diff --git a/hw/timer/hpet.c b/hw/timer/hpet.c index ae54b87..8e32e36 100644 --- a/hw/timer/hpet.c +++ b/hw/timer/hpet.c @@ -91,6 +91,10 @@ typedef struct HPETState { uint32_t intcap; HPETTimer timer[HPET_MAX_TIMERS]; bool dedicate_mode; + AioContext *ctx; + bool created; + bool stop; + QemuThread t; /* Memory-mapped, software visible registers */ uint64_t capability; /* capabilities */ @@ -702,6 +706,16 @@ static const MemoryRegionOps hpet_ram_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; +static void *hpet_work_thread(void *opaque) +{ + HPETState *hpet = opaque; + + while (!hpet->stop) { + aio_poll(hpet->ctx, true); + } + return NULL; +} + static void hpet_reset(DeviceState *d) { HPETState *s = HPET(d); @@ -732,6 +746,11 @@ static void hpet_reset(DeviceState *d) /* to document that the RTC lowers its output on reset as well */ s->rtc_irq_level = 0; + if (!s->created) { + s->created = true; + qemu_thread_create(&s->t, hpet_work_thread, s, QEMU_THREAD_JOINABLE); + } + } static void hpet_handle_legacy_irq(void *opaque, int n, int level) @@ -788,10 +807,20 @@ static void hpet_realize(DeviceState *dev, Error **errp) } else if (s->num_timers > HPET_MAX_TIMERS) { s->num_timers = HPET_MAX_TIMERS; } + s->dedicate_mode = kvm_irqfds_enabled() ? true : false; + if (s->dedicate_mode) { + s->ctx = aio_context_new(); + } for (i = 0; i < HPET_MAX_TIMERS; i++) { timer = &s->timer[i]; - timer->qemu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, hpet_timer, timer); timer->tn = i; + if (s->dedicate_mode) { + timer->qemu_timer = aio_timer_new(s->ctx, QEMU_CLOCK_VIRTUAL, + SCALE_NS, hpet_timer, timer); + } else { + timer->qemu_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, + hpet_timer, timer); + } timer->state = s; } -- 1.8.1.4