From patchwork Mon Dec 21 08:09:29 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 41536 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 43D89B6F08 for ; Mon, 21 Dec 2009 20:08:18 +1100 (EST) Received: from localhost ([127.0.0.1]:43444 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NMeFT-00068W-VP for incoming@patchwork.ozlabs.org; Mon, 21 Dec 2009 04:08:15 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NMdL4-0002q4-15 for qemu-devel@nongnu.org; Mon, 21 Dec 2009 03:09:58 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NMdKy-0002n8-U4 for qemu-devel@nongnu.org; Mon, 21 Dec 2009 03:09:56 -0500 Received: from [199.232.76.173] (port=52827 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NMdKw-0002mI-94 for qemu-devel@nongnu.org; Mon, 21 Dec 2009 03:09:50 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52280) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NMdKv-0003pS-Ny for qemu-devel@nongnu.org; Mon, 21 Dec 2009 03:09:50 -0500 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nBL89nFP030921 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 21 Dec 2009 03:09:49 -0500 Received: from localhost.localdomain (vpn2-10-119.ams2.redhat.com [10.36.10.119]) by int-mx01.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nBL89V3c011460 for ; Mon, 21 Dec 2009 03:09:48 -0500 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Mon, 21 Dec 2009 09:09:29 +0100 Message-Id: <1261382970-23251-19-git-send-email-pbonzini@redhat.com> In-Reply-To: <1261382970-23251-1-git-send-email-pbonzini@redhat.com> References: <1261382970-23251-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.11 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Subject: [Qemu-devel] [PATCH 18/19] introduce qemu_clock_enable X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org By adding the possibility to turn on/off a clock, yet another incestuous relationship between timers and CPUs can be disentangled. This also needs qemu_run_timers to accept a QEMUClock, and nicely simplifies host_alarm_handler. Signed-off-by: Paolo Bonzini --- vl.c | 32 +++++++++++++++++++++----------- 1 files changed, 21 insertions(+), 11 deletions(-) diff --git a/vl.c b/vl.c index 204b6a0..17ad374 100644 --- a/vl.c +++ b/vl.c @@ -569,6 +569,7 @@ void cpu_disable_ticks(void) struct QEMUClock { int type; + int enabled; /* XXX: add frequency */ }; @@ -799,9 +800,15 @@ static QEMUClock *qemu_new_clock(int type) QEMUClock *clock; clock = qemu_mallocz(sizeof(QEMUClock)); clock->type = type; + clock->enabled = 1; return clock; } +static void qemu_clock_enable(QEMUClock *clock, int enabled) +{ + clock->enabled = enabled; +} + QEMUTimer *qemu_new_timer(QEMUClock *clock, QEMUTimerCB *cb, void *opaque) { QEMUTimer *ts; @@ -890,10 +897,16 @@ int qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time) return (timer_head->expire_time <= current_time); } -static void qemu_run_timers(QEMUTimer **ptimer_head, int64_t current_time) +static void qemu_run_timers(QEMUClock *clock) { - QEMUTimer *ts; + QEMUTimer **ptimer_head, *ts; + int64_t current_time; + + if (!clock->enabled) + return; + current_time = qemu_get_clock (clock); + ptimer_head = &active_timers[clock->type]; for(;;) { ts = *ptimer_head; if (!ts || ts->expire_time > current_time) @@ -1032,17 +1045,11 @@ static void qemu_timer_bh(void *opaque) /* vm time timers */ if (vm_running) { - if (!cur_cpu || likely(!(cur_cpu->singlestep_enabled & SSTEP_NOTIMER))) - qemu_run_timers(&active_timers[QEMU_CLOCK_VIRTUAL], - qemu_get_clock(vm_clock)); + qemu_run_timers(vm_clock); } - /* real time timers */ - qemu_run_timers(&active_timers[QEMU_CLOCK_REALTIME], - qemu_get_clock(rt_clock)); - - qemu_run_timers(&active_timers[QEMU_CLOCK_HOST], - qemu_get_clock(host_clock)); + qemu_run_timers(rt_clock); + qemu_run_timers(host_clock); } #ifdef _WIN32 @@ -3907,6 +3914,9 @@ static bool tcg_cpu_exec(void) for (; next_cpu != NULL; next_cpu = next_cpu->next_cpu) { CPUState *env = cur_cpu = next_cpu; + qemu_clock_enable(vm_clock, + (cur_cpu->singlestep_enabled & SSTEP_NOTIMER) != 0); + if (!vm_running) return false; if (qemu_alarm_pending())