From patchwork Mon Jul 29 03:16:08 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: pingfan liu X-Patchwork-Id: 262656 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CCF3C2C0105 for ; Mon, 29 Jul 2013 13:20:20 +1000 (EST) Received: from localhost ([::1]:38640 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3e0Q-0004Sl-Qt for incoming@patchwork.ozlabs.org; Sun, 28 Jul 2013 23:20:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45312) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3dzc-0003kw-2f for qemu-devel@nongnu.org; Sun, 28 Jul 2013 23:19:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1V3dzT-0002r8-Lm for qemu-devel@nongnu.org; Sun, 28 Jul 2013 23:19:28 -0400 Received: from mail-oa0-x22c.google.com ([2607:f8b0:4003:c02::22c]:60857) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1V3dzT-0002r4-Ho for qemu-devel@nongnu.org; Sun, 28 Jul 2013 23:19:19 -0400 Received: by mail-oa0-f44.google.com with SMTP id l20so8355808oag.31 for ; Sun, 28 Jul 2013 20:19:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=yr0do2NH+SJ5aTF8x+h4eIA+weIxFIDy0oaQ0CWEifg=; b=rEyLcsDLD6xxGEyUS7pu7tfNxY0WZ9I2P/MyIOSfO4cOAqIUDBPFELPsHSvbAkCQhP xImLKxrv/mILy2P6muaIsBmTSkezJW7ZMhK/u71GrLzx3nrSUBzz9HliVl3EtvS3S9OQ v1q0gIcDlryp7qq7c/+HtF/RknpRnpxy9KVNnTPDhy5oTYtvsyGJq9sMha6A87cgfbg2 NXSIas9Wgslr2fc6SWl0xAnz8UhYhtXImirns8MhaZw6A9ghDFppnGM79AJqezzv/AVL jlDyEwdvNrWtlHvrSXxSprYZ2xHnq9+SurtSDY5/JRuA9SmNJb8QOd9HqGUF0XSWNf2h 9OTQ== X-Received: by 10.60.79.3 with SMTP id f3mr56825260oex.50.1375067959032; Sun, 28 Jul 2013 20:19:19 -0700 (PDT) Received: from localhost ([202.108.130.138]) by mx.google.com with ESMTPSA id tv3sm85162088obb.8.2013.07.28.20.19.12 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Sun, 28 Jul 2013 20:19:18 -0700 (PDT) From: Liu Ping Fan To: qemu-devel@nongnu.org Date: Mon, 29 Jul 2013 11:16:08 +0800 Message-Id: <1375067768-11342-6-git-send-email-pingfank@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1375067768-11342-1-git-send-email-pingfank@linux.vnet.ibm.com> References: <1375067768-11342-1-git-send-email-pingfank@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2607:f8b0:4003:c02::22c Cc: Kevin Wolf , Stefan Hajnoczi , Jan Kiszka , Alex Bligh , Anthony Liguori , Paolo Bonzini Subject: [Qemu-devel] [RFC v2 5/5] timer: run timers on aio_poll X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Stop call timers in main loop and let each mini event-loop run its own timers. Signed-off-by: Liu Ping Fan --- aio-posix.c | 2 ++ include/qemu/timer.h | 4 ++-- main-loop.c | 2 -- qemu-timer.c | 15 ++++++++++----- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/aio-posix.c b/aio-posix.c index b68eccd..53fdb1a 100644 --- a/aio-posix.c +++ b/aio-posix.c @@ -191,6 +191,8 @@ bool aio_poll(AioContext *ctx, bool blocking) progress = true; } + progress |= qemu_run_all_timers(); + if (progress && !blocking) { return true; } diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 3e5016b..9ff8a68 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -61,8 +61,8 @@ bool qemu_timer_pending(QEMUTimer *ts); bool qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time); uint64_t qemu_timer_expire_time_ns(QEMUTimer *ts); -void qemu_run_timers(QEMUClock *clock); -void qemu_run_all_timers(void); +bool qemu_run_timers(QEMUClock *clock); +bool qemu_run_all_timers(void); void configure_alarms(char const *opt); void init_clocks(void); int init_timer_alarm(void); diff --git a/main-loop.c b/main-loop.c index 5fbdd4a..0214ed6 100644 --- a/main-loop.c +++ b/main-loop.c @@ -471,8 +471,6 @@ int main_loop_wait(int nonblocking) slirp_pollfds_poll(gpollfds, (ret < 0)); #endif - qemu_run_all_timers(); - return ret; } diff --git a/qemu-timer.c b/qemu-timer.c index f15c3e6..8331e18 100644 --- a/qemu-timer.c +++ b/qemu-timer.c @@ -463,12 +463,13 @@ bool qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time) return qemu_timer_expired_ns(timer_head, current_time * timer_head->scale); } -void qemu_run_timers(QEMUClock *clock) +bool qemu_run_timers(QEMUClock *clock) { QEMUTimer *ts; int64_t current_time; TimerList *tlist; AioContext *ctx; + bool process = false; atomic_inc(&clock->using); if (unlikely(!clock->enabled)) { @@ -494,6 +495,7 @@ void qemu_run_timers(QEMUClock *clock) /* run the callback (the timer list can be modified) */ ts->cb(ts->opaque); + process = true; } exit: @@ -504,6 +506,7 @@ exit: } } qemu_mutex_unlock(&clock->lock); + return process; } int64_t qemu_get_clock_ns(QEMUClock *clock) @@ -555,16 +558,17 @@ uint64_t qemu_timer_expire_time_ns(QEMUTimer *ts) return qemu_timer_pending(ts) ? ts->expire_time : -1; } -void qemu_run_all_timers(void) +bool qemu_run_all_timers(void) { bool timer_modified; + bool process = false; alarm_timer->pending = false; /* vm time timers */ - qemu_run_timers(vm_clock); - qemu_run_timers(rt_clock); - qemu_run_timers(host_clock); + process |= qemu_run_timers(vm_clock); + process |= qemu_run_timers(rt_clock); + process |= qemu_run_timers(host_clock); /* Check if qemu_mod_timer_ns() has been called */ qemu_mutex_lock(&alarm_timer->timer_modified_lock); @@ -580,6 +584,7 @@ void qemu_run_all_timers(void) qemu_rearm_alarm_timer(alarm_timer); } + return process; } #ifdef _WIN32