From patchwork Wed Oct 15 10:10:01 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Igor Mammedov X-Patchwork-Id: 399912 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D3A4B1400BB for ; Wed, 15 Oct 2014 21:19:02 +1100 (EST) Received: from localhost ([::1]:43629 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeLfZ-0006xN-07 for incoming@patchwork.ozlabs.org; Wed, 15 Oct 2014 06:19:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:46849) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeLX5-0000bk-Td for qemu-devel@nongnu.org; Wed, 15 Oct 2014 06:10:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XeLWy-0006VJ-JR for qemu-devel@nongnu.org; Wed, 15 Oct 2014 06:10:15 -0400 Received: from mx1.redhat.com ([209.132.183.28]:52847) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XeLWy-0006Uu-Bp for qemu-devel@nongnu.org; Wed, 15 Oct 2014 06:10:08 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s9FAA6mu007786 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 15 Oct 2014 06:10:06 -0400 Received: from Igors-MacBook-Pro.local.com (vpn-233-6.phx2.redhat.com [10.3.233.6]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s9FAA4tQ028060; Wed, 15 Oct 2014 06:10:05 -0400 From: Igor Mammedov To: qemu-devel@nongnu.org Date: Wed, 15 Oct 2014 12:10:01 +0200 Message-Id: <1413367801-39580-1-git-send-email-imammedo@redhat.com> In-Reply-To: <1413357868-31569-1-git-send-email-stefanha@redhat.com> References: <1413357868-31569-1-git-send-email-stefanha@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: peter.maydell@linaro.org, dgilbert@redhat.com, stefanha@redhat.com Subject: [Qemu-devel] [PATCH v2] glib: add compatibility interface for g_get_monotonic_time() 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 From: Stefan Hajnoczi This patch fixes compilation errors when building against glib <2.28.0 due to the missing g_get_monotonic_time() function. The compilation error in tests/libqos/virtio.c was introduced in commit 70556264a89a268efba1d7e8e341adcdd7881eb4 ("libqos: use microseconds instead of iterations for virtio timeout"). Add a simple g_get_monotonic_time() implementation to compat-glib.h based on code from vhost-user-test.c. Signed-off-by: Stefan Hajnoczi Signed-off-by: Igor Mammedov --- v2: fix ibuild break beacuse of missing G_TIME_SPAN_SECOND in header --- include/glib-compat.h | 19 +++++++++++++++++++ tests/vhost-user-test.c | 23 +---------------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/include/glib-compat.h b/include/glib-compat.h index 4ae0671..e29bf69 100644 --- a/include/glib-compat.h +++ b/include/glib-compat.h @@ -18,6 +18,11 @@ #include +/* GLIB version compatibility flags */ +#if !GLIB_CHECK_VERSION(2, 26, 0) +#define G_TIME_SPAN_SECOND (G_GINT64_CONSTANT(1000000)) +#endif + #if !GLIB_CHECK_VERSION(2, 14, 0) static inline guint g_timeout_add_seconds(guint interval, GSourceFunc function, gpointer data) @@ -26,6 +31,20 @@ static inline guint g_timeout_add_seconds(guint interval, GSourceFunc function, } #endif +#if !GLIB_CHECK_VERSION(2, 28, 0) +static inline gint64 g_get_monotonic_time(void) +{ + /* g_get_monotonic_time() is best-effort so we can use the wall clock as a + * fallback. + */ + + GTimeVal time; + g_get_current_time(&time); + + return time.tv_sec * G_TIME_SPAN_SECOND + time.tv_usec; +} +#endif + #ifdef _WIN32 /* * g_poll has a problem on Windows when using diff --git a/tests/vhost-user-test.c b/tests/vhost-user-test.c index 75fedf0..fdf91e7 100644 --- a/tests/vhost-user-test.c +++ b/tests/vhost-user-test.c @@ -21,15 +21,6 @@ #include #include -/* GLIB version compatibility flags */ -#if !GLIB_CHECK_VERSION(2, 26, 0) -#define G_TIME_SPAN_SECOND (G_GINT64_CONSTANT(1000000)) -#endif - -#if GLIB_CHECK_VERSION(2, 28, 0) -#define HAVE_MONOTONIC_TIME -#endif - #if GLIB_CHECK_VERSION(2, 32, 0) #define HAVE_MUTEX_INIT #define HAVE_COND_INIT @@ -116,18 +107,6 @@ static VhostUserMemory memory; static GMutex *data_mutex; static GCond *data_cond; -static gint64 _get_time(void) -{ -#ifdef HAVE_MONOTONIC_TIME - return g_get_monotonic_time(); -#else - GTimeVal time; - g_get_current_time(&time); - - return time.tv_sec * G_TIME_SPAN_SECOND + time.tv_usec; -#endif -} - static GMutex *_mutex_new(void) { GMutex *mutex; @@ -210,7 +189,7 @@ static void read_guest_mem(void) g_mutex_lock(data_mutex); - end_time = _get_time() + 5 * G_TIME_SPAN_SECOND; + end_time = g_get_monotonic_time() + 5 * G_TIME_SPAN_SECOND; while (!fds_num) { if (!_cond_wait_until(data_cond, data_mutex, end_time)) { /* timeout has passed */