From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52558) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJzPx-0000SX-Ec for qemu-devel@nongnu.org; Thu, 12 Sep 2013 01:26:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VJzPo-0007mX-Vd for qemu-devel@nongnu.org; Thu, 12 Sep 2013 01:26:13 -0400 Received: from mail-oa0-x231.google.com ([2607:f8b0:4003:c02::231]:54136) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VJzPo-0007mS-PV for qemu-devel@nongnu.org; Thu, 12 Sep 2013 01:26:04 -0400 Received: by mail-oa0-f49.google.com with SMTP id i7so10229823oag.22 for ; Wed, 11 Sep 2013 22:26:04 -0700 (PDT) From: Liu Ping Fan Date: Thu, 12 Sep 2013 13:24:53 +0800 Message-Id: <1378963493-559-6-git-send-email-pingfank@linux.vnet.ibm.com> In-Reply-To: <1378963493-559-1-git-send-email-pingfank@linux.vnet.ibm.com> References: <1378963493-559-1-git-send-email-pingfank@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 5/5] hpet: run on dedicate thread List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Stefan Hajnoczi , Anthony Liguori , Jan Kiszka migration is not supported yet. Signed-off-by: Liu Ping Fan --- 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