From patchwork Wed Apr 3 19:22:24 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brad Smith X-Patchwork-Id: 233574 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 80CB92C00A3 for ; Thu, 4 Apr 2013 06:22:57 +1100 (EST) Received: from localhost ([::1]:36943 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UNTGp-0001gM-GG for incoming@patchwork.ozlabs.org; Wed, 03 Apr 2013 15:22:55 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48997) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UNTGY-0001gH-Oa for qemu-devel@nongnu.org; Wed, 03 Apr 2013 15:22:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UNTGW-0006QP-Dj for qemu-devel@nongnu.org; Wed, 03 Apr 2013 15:22:38 -0400 Received: from speedy.comstyle.com ([2001:470:1d:8c::2]:11369 helo=mail.comstyle.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UNTGW-0006PG-9m for qemu-devel@nongnu.org; Wed, 03 Apr 2013 15:22:36 -0400 Received: from rox.home.comstyle.com (unknown [IPv6:2001:470:b01e:3:58c5:df1d:6651:71cf]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) (Authenticated sender: brad) by mail.comstyle.com (Postfix) with ESMTPSA id 8B26D3F736; Wed, 3 Apr 2013 15:22:25 -0400 (EDT) Date: Wed, 3 Apr 2013 15:22:24 -0400 From: Brad Smith To: Paolo Bonzini Message-ID: <20130403192223.GC326@rox.home.comstyle.com> References: <20130402154214.GJ26146@rox.home.comstyle.com> <515B0B1D.9050202@redhat.com> <515BE5EB.7040200@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <515BE5EB.7040200@redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) X-comstyle-MailScanner-Information: Please contact the ISP for more information X-comstyle-MailScanner-ID: 8B26D3F736.A6DA1 X-comstyle-MailScanner: Found to be clean X-comstyle-MailScanner-SpamCheck: not spam (whitelisted), SpamAssassin (not cached, score=-2.9, required 6, autolearn=not spam, ALL_TRUSTED -1.00, BAYES_00 -1.90) X-comstyle-MailScanner-From: brad@comstyle.com X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2001:470:1d:8c::2 Cc: Peter Maydell , qemu-devel@nongnu.org Subject: Re: [Qemu-devel] [PATCH] Add configure clock_gettime() monotonic time test 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 On Wed, Apr 03, 2013 at 10:18:51AM +0200, Paolo Bonzini wrote: > Il 03/04/2013 00:52, Peter Maydell ha scritto: > > On 2 April 2013 17:45, Paolo Bonzini wrote: > >> Il 02/04/2013 17:42, Brad Smith ha scritto: > >>> Replace the hardcoded list of OS's utilizing clock_gettime() for monotonic > >>> time with a configure test. This is to fix the use of monotonic time on > >>> OpenBSD but allows for other POSIX compliant OS's such as NetBSD to also > >>> utilize clock_gettime(). > >> > >> I thought the list of OSes was supposed to filter out those that somehow > >> had a broken CLOCK_MONOTONIC. > > > > Judging from wading through git history, it's mostly just > > historic accretion from an initial #ifdef __linux__ which was > > put in by Fabrice way back when configure was barely doing > > compile-this-code checks at all. > > > > Google does suggest that some OSes do provide a CLOCK_MONOTONIC > > but clock_gettime(CLOCK_MONOTONIC) always fails, eg Centos 3. > > It would already fail, and no one reported it. > > CentOS 3 has a 2.4 kernel. I doubt anyone is using it with a recent QEMU. > > Paolo > > >> Otherwise, you might as well use "#ifdef CLOCK_MONOTONIC" and skip the > >> configure test completely. > > > > Tempting. > > > > -- PMM Then how about the following? This looks like it should be good for Linux, *BSD's, Solaris. Reviewed-by: Paolo Bonzini Signed-off-by: Brad Smith diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 1766b2d..c363190 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -117,8 +117,7 @@ extern int use_rt_clock; static inline int64_t get_clock(void) { -#if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD_version >= 500000) \ - || defined(__DragonFly__) || defined(__FreeBSD_kernel__) +#ifdef CLOCK_MONOTONIC if (use_rt_clock) { struct timespec ts; clock_gettime(CLOCK_MONOTONIC, &ts); diff --git a/util/qemu-timer-common.c b/util/qemu-timer-common.c index 16f5e75..95e0847 100644 --- a/util/qemu-timer-common.c +++ b/util/qemu-timer-common.c @@ -49,9 +49,7 @@ int use_rt_clock; static void __attribute__((constructor)) init_get_clock(void) { use_rt_clock = 0; -#if defined(__linux__) || (defined(__FreeBSD__) && __FreeBSD_version >= 500000) \ - || defined(__DragonFly__) || defined(__FreeBSD_kernel__) \ - || defined(__OpenBSD__) +#ifdef CLOCK_MONOTONIC { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {