From patchwork Fri Sep 11 15:34:40 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Liguori X-Patchwork-Id: 33468 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 45275B6F56 for ; Sat, 12 Sep 2009 01:35:34 +1000 (EST) Received: from localhost ([127.0.0.1]:60587 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mm89q-0003Ie-GC for incoming@patchwork.ozlabs.org; Fri, 11 Sep 2009 11:35:30 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mm89F-0003I2-JX for qemu-devel@nongnu.org; Fri, 11 Sep 2009 11:34:53 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mm899-0003HM-Ob for qemu-devel@nongnu.org; Fri, 11 Sep 2009 11:34:53 -0400 Received: from [199.232.76.173] (port=60860 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mm899-0003HF-Gu for qemu-devel@nongnu.org; Fri, 11 Sep 2009 11:34:47 -0400 Received: from mail-yx0-f190.google.com ([209.85.210.190]:34040) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mm899-0001uY-6c for qemu-devel@nongnu.org; Fri, 11 Sep 2009 11:34:47 -0400 Received: by yxe28 with SMTP id 28so1420026yxe.19 for ; Fri, 11 Sep 2009 08:34:45 -0700 (PDT) Received: by 10.91.161.34 with SMTP id n34mr1747187ago.78.1252683285380; Fri, 11 Sep 2009 08:34:45 -0700 (PDT) Received: from squirrel.codemonkey.ws ([24.174.33.212]) by mx.google.com with ESMTPS id 4sm5054731aga.29.2009.09.11.08.34.44 (version=TLSv1/SSLv3 cipher=RC4-MD5); Fri, 11 Sep 2009 08:34:44 -0700 (PDT) Message-ID: <4AAA6E10.6080308@codemonkey.ws> Date: Fri, 11 Sep 2009 10:34:40 -0500 From: Anthony Liguori User-Agent: Thunderbird 2.0.0.23 (X11/20090825) MIME-Version: 1.0 To: malc Subject: Re: [Qemu-devel] Re: [PATCH 05/26] Unexport ticks_per_sec variable. Create get_ticks_per_sec() function References: <4AA939B3.6000103@codemonkey.ws> <4AA978DB.90301@codemonkey.ws> In-Reply-To: X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Cc: qemu-devel@nongnu.org, Juan Quintela 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 malc wrote: > And generalizations are always true. Anyhow, i'm explicitly against the > patch, so first obtain the express acknowledgment from the leaders, > otherwise i'll revert it should it go in. > I'm adding the following patch to Juan's series. The result is that get_ticks_per_sec() should be optimized to a literal value. The result being that uses of it are faster than they were before (not it should matter). I think the result of this patch is that the refactoring is an undeniable improvement. Regards, Anthony Liguori Acked-by: Juan Quintela commit 1c7aff17af0ca9e1803b952ce455f096c5da8847 Author: Anthony Liguori Date: Fri Sep 11 10:28:26 2009 -0500 Make get_ticks_per_sec() a static inline ticks_per_sec is a constant. There's no need to store it as a variable as it never changes since our time is based on units. Convert get_ticks_per_sec() to a static inline and move the constant into qemu-timer.h. Remove all references to QEMU_TIMER_BASE so that we consistently use this interface. Signed-off-by: Anthony Liguori diff --git a/qemu-timer.h b/qemu-timer.h index 00b166d..e44c334 100644 --- a/qemu-timer.h +++ b/qemu-timer.h @@ -26,7 +26,10 @@ void qemu_mod_timer(QEMUTimer *ts, int64_t expire_time); int qemu_timer_pending(QEMUTimer *ts); int qemu_timer_expired(QEMUTimer *timer_head, int64_t current_time); -int64_t get_ticks_per_sec(void); +static inline int64_t get_ticks_per_sec(void) +{ + return 1000000000LL; +} void qemu_get_timer(QEMUFile *f, QEMUTimer *ts); void qemu_put_timer(QEMUFile *f, QEMUTimer *ts); diff --git a/vl.c b/vl.c index 6052b1c..c3c874d 100644 --- a/vl.c +++ b/vl.c @@ -528,8 +528,6 @@ uint64_t muldiv64(uint64_t a, uint32_t b, uint32_t c) /***********************************************************/ /* real time host monotonic timer */ -#define QEMU_TIMER_BASE 1000000000LL - #ifdef WIN32 static int64_t clock_freq; @@ -550,7 +548,7 @@ static int64_t get_clock(void) { LARGE_INTEGER ti; QueryPerformanceCounter(&ti); - return muldiv64(ti.QuadPart, QEMU_TIMER_BASE, clock_freq); + return muldiv64(ti.QuadPart, get_ticks_per_sec(), clock_freq); } #else @@ -758,7 +756,7 @@ static void rtc_stop_timer(struct qemu_alarm_timer *t); fairly approximate, so ignore small variation. When the guest is idle real and virtual time will be aligned in the IO wait loop. */ -#define ICOUNT_WOBBLE (QEMU_TIMER_BASE / 10) +#define ICOUNT_WOBBLE (get_ticks_per_sec() / 10) static void icount_adjust(void) { @@ -800,7 +798,7 @@ static void icount_adjust_rt(void * opaque) static void icount_adjust_vm(void * opaque) { qemu_mod_timer(icount_vm_timer, - qemu_get_clock(vm_clock) + QEMU_TIMER_BASE / 10); + qemu_get_clock(vm_clock) + get_ticks_per_sec() / 10); icount_adjust(); } @@ -816,7 +814,7 @@ static void init_icount_adjust(void) qemu_get_clock(rt_clock) + 1000); icount_vm_timer = qemu_new_timer(vm_clock, icount_adjust_vm, NULL); qemu_mod_timer(icount_vm_timer, - qemu_get_clock(vm_clock) + QEMU_TIMER_BASE / 10); + qemu_get_clock(vm_clock) + get_ticks_per_sec() / 10); } static struct qemu_alarm_timer alarm_timers[] = { @@ -1036,15 +1034,10 @@ int64_t qemu_get_clock(QEMUClock *clock) } } -int64_t get_ticks_per_sec(void) -{ - return timers_state.ticks_per_sec; -} - static void init_timers(void) { init_get_clock(); - timers_state.ticks_per_sec = QEMU_TIMER_BASE; + timers_state.ticks_per_sec = get_ticks_per_sec(); rt_clock = qemu_new_clock(QEMU_TIMER_REALTIME); vm_clock = qemu_new_clock(QEMU_TIMER_VIRTUAL); }