From patchwork Tue Apr 2 15:42:17 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brad Smith X-Patchwork-Id: 233066 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 A9F322C012B for ; Wed, 3 Apr 2013 02:43:01 +1100 (EST) Received: from localhost ([::1]:45437 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UN3MR-00068c-TZ for incoming@patchwork.ozlabs.org; Tue, 02 Apr 2013 11:42:59 -0400 Received: from eggs.gnu.org ([208.118.235.92]:48377) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UN3M9-00067z-Qk for qemu-devel@nongnu.org; Tue, 02 Apr 2013 11:42:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UN3M8-0001k9-3Y for qemu-devel@nongnu.org; Tue, 02 Apr 2013 11:42:41 -0400 Received: from speedy.comstyle.com ([2001:470:1d:8c::2]:23539 helo=mail.comstyle.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UN3M7-0001gJ-VV for qemu-devel@nongnu.org; Tue, 02 Apr 2013 11:42:40 -0400 Received: from rox.home.comstyle.com (unknown [IPv6:2001:470:b01e:3:74d6:bfdc:d79a:d94d]) (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 5C19A3F679 for ; Tue, 2 Apr 2013 11:42:25 -0400 (EDT) Date: Tue, 2 Apr 2013 11:42:17 -0400 From: Brad Smith To: qemu-devel@nongnu.org Message-ID: <20130402154214.GJ26146@rox.home.comstyle.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-comstyle-MailScanner-Information: Please contact the ISP for more information X-comstyle-MailScanner-ID: 5C19A3F679.A58FA 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 Subject: [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 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(). Signed-off-by: Brad Smith diff --git a/configure b/configure index fbea75e..352d6a6 100755 --- a/configure +++ b/configure @@ -2896,6 +2896,21 @@ if test "$darwin" != "yes" -a "$mingw32" != "yes" -a "$solaris" != yes -a \ fi ########################################## +# clock_gettime() probe, used for monotonic time +clock_monotonic="no" +cat > $TMPC << EOF +#include +int main(void) +{ + clock_gettime(CLOCK_MONOTONIC, NULL); + return 0; +} +EOF +if compile_prog "" "" ; then + clock_monotonic="yes" +fi + +########################################## # spice probe if test "$spice" != "no" ; then cat > $TMPC << EOF @@ -3671,6 +3686,9 @@ fi if test "$bswap_h" = "yes" ; then echo "CONFIG_MACHINE_BSWAP_H=y" >> $config_host_mak fi +if test "$clock_monotonic" = "yes" ; then + echo "CONFIG_CLOCK_MONOTONIC=y" >> $config_host_mak +fi if test "$curl" = "yes" ; then echo "CONFIG_CURL=y" >> $config_host_mak echo "CURL_CFLAGS=$curl_cflags" >> $config_host_mak diff --git a/include/qemu/timer.h b/include/qemu/timer.h index 1766b2d..d87dfa4 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 CONFIG_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..1506942 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 CONFIG_CLOCK_MONOTONIC { struct timespec ts; if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {