* [Qemu-devel] [PATCH] glib: add compatibility interface for g_get_monotonic_time()
@ 2014-10-15 7:24 Stefan Hajnoczi
2014-10-15 7:37 ` Igor Mammedov
2014-10-15 10:10 ` [Qemu-devel] [PATCH v2] " Igor Mammedov
0 siblings, 2 replies; 8+ messages in thread
From: Stefan Hajnoczi @ 2014-10-15 7:24 UTC (permalink / raw)
To: qemu-devel; +Cc: Peter Maydell, Dr. David Alan Gilbert, 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 <stefanha@redhat.com>
---
include/glib-compat.h | 14 ++++++++++++++
tests/vhost-user-test.c | 18 +-----------------
2 files changed, 15 insertions(+), 17 deletions(-)
diff --git a/include/glib-compat.h b/include/glib-compat.h
index 4ae0671..9343742 100644
--- a/include/glib-compat.h
+++ b/include/glib-compat.h
@@ -26,6 +26,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..af4012e 100644
--- a/tests/vhost-user-test.c
+++ b/tests/vhost-user-test.c
@@ -26,10 +26,6 @@
#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 +112,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 +194,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 */
--
1.9.3
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH] glib: add compatibility interface for g_get_monotonic_time()
2014-10-15 7:24 [Qemu-devel] [PATCH] glib: add compatibility interface for g_get_monotonic_time() Stefan Hajnoczi
@ 2014-10-15 7:37 ` Igor Mammedov
2014-10-15 10:10 ` [Qemu-devel] [PATCH v2] " Igor Mammedov
1 sibling, 0 replies; 8+ messages in thread
From: Igor Mammedov @ 2014-10-15 7:37 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: Peter Maydell, qemu-devel, Dr. David Alan Gilbert
On Wed, 15 Oct 2014 09:24:28 +0200
Stefan Hajnoczi <stefanha@redhat.com> wrote:
> 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 <stefanha@redhat.com>
> ---
> include/glib-compat.h | 14 ++++++++++++++
> tests/vhost-user-test.c | 18 +-----------------
> 2 files changed, 15 insertions(+), 17 deletions(-)
>
> diff --git a/include/glib-compat.h b/include/glib-compat.h
> index 4ae0671..9343742 100644
> --- a/include/glib-compat.h
> +++ b/include/glib-compat.h
> @@ -26,6 +26,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;
G_TIME_SPAN_SECOND needs to be moved from tests/vhost-user-test.c to
here as well.
> +}
> +#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..af4012e 100644
> --- a/tests/vhost-user-test.c
> +++ b/tests/vhost-user-test.c
> @@ -26,10 +26,6 @@
> #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 +112,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 +194,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 */
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH v2] glib: add compatibility interface for g_get_monotonic_time()
2014-10-15 7:24 [Qemu-devel] [PATCH] glib: add compatibility interface for g_get_monotonic_time() Stefan Hajnoczi
2014-10-15 7:37 ` Igor Mammedov
@ 2014-10-15 10:10 ` Igor Mammedov
2014-10-15 10:47 ` Peter Maydell
1 sibling, 1 reply; 8+ messages in thread
From: Igor Mammedov @ 2014-10-15 10:10 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, dgilbert, stefanha
From: Stefan Hajnoczi <stefanha@redhat.com>
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 <stefanha@redhat.com>
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
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.h>
+/* 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 <sys/vfs.h>
#include <qemu/sockets.h>
-/* 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 */
--
1.9.3 (Apple Git-50)
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH v2] glib: add compatibility interface for g_get_monotonic_time()
2014-10-15 10:10 ` [Qemu-devel] [PATCH v2] " Igor Mammedov
@ 2014-10-15 10:47 ` Peter Maydell
2014-10-15 12:29 ` [Qemu-devel] [PATCH v3] " Igor Mammedov
0 siblings, 1 reply; 8+ messages in thread
From: Peter Maydell @ 2014-10-15 10:47 UTC (permalink / raw)
To: Igor Mammedov; +Cc: QEMU Developers, Stefan Hajnoczi, Dr. David Alan Gilbert
On 15 October 2014 12:10, Igor Mammedov <imammedo@redhat.com> wrote:
> From: Stefan Hajnoczi <stefanha@redhat.com>
>
> 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 <stefanha@redhat.com>
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
Unfortunately this patch doesn't actually fix the test compile
failure, because it puts the replacement implementation in
compat-glib.h which is not included from the libqos sources.
Adding #include "compat-glib.h" to tests/libqtest.h seems to
fix this.
-- PMM
^ permalink raw reply [flat|nested] 8+ messages in thread
* [Qemu-devel] [PATCH v3] glib: add compatibility interface for g_get_monotonic_time()
2014-10-15 10:47 ` Peter Maydell
@ 2014-10-15 12:29 ` Igor Mammedov
2014-10-15 12:38 ` Stefan Hajnoczi
2014-10-15 19:38 ` Peter Maydell
0 siblings, 2 replies; 8+ messages in thread
From: Igor Mammedov @ 2014-10-15 12:29 UTC (permalink / raw)
To: qemu-devel; +Cc: peter.maydell, dgilbert, stefanha
From: Stefan Hajnoczi <stefanha@redhat.com>
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 glib-compat.h
based on code from vhost-user-test.c.
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Igor Mammedov <imammedo@redhat.com>
---
v3: include glib-compat.h into libqtest.h to fix another build breakage (Peter)
v2: fix build break beacuse of missing G_TIME_SPAN_SECOND in header
---
include/glib-compat.h | 19 +++++++++++++++++++
tests/libqtest.h | 1 +
tests/vhost-user-test.c | 23 +----------------------
3 files changed, 21 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.h>
+/* 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/libqtest.h b/tests/libqtest.h
index 3e12cab..e7413d5 100644
--- a/tests/libqtest.h
+++ b/tests/libqtest.h
@@ -23,6 +23,7 @@
#include <stdarg.h>
#include <sys/types.h>
#include "qapi/qmp/qdict.h"
+#include "glib-compat.h"
typedef struct QTestState QTestState;
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 <sys/vfs.h>
#include <qemu/sockets.h>
-/* 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 */
--
1.9.3 (Apple Git-50)
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH v3] glib: add compatibility interface for g_get_monotonic_time()
2014-10-15 12:29 ` [Qemu-devel] [PATCH v3] " Igor Mammedov
@ 2014-10-15 12:38 ` Stefan Hajnoczi
2014-10-15 12:47 ` Peter Maydell
2014-10-15 19:38 ` Peter Maydell
1 sibling, 1 reply; 8+ messages in thread
From: Stefan Hajnoczi @ 2014-10-15 12:38 UTC (permalink / raw)
To: Igor Mammedov; +Cc: peter.maydell, qemu-devel, dgilbert
[-- Attachment #1: Type: text/plain, Size: 1131 bytes --]
On Wed, Oct 15, 2014 at 02:29:30PM +0200, Igor Mammedov wrote:
> From: Stefan Hajnoczi <stefanha@redhat.com>
>
> 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 glib-compat.h
> based on code from vhost-user-test.c.
>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> v3: include glib-compat.h into libqtest.h to fix another build breakage (Peter)
> v2: fix build break beacuse of missing G_TIME_SPAN_SECOND in header
> ---
> include/glib-compat.h | 19 +++++++++++++++++++
> tests/libqtest.h | 1 +
> tests/vhost-user-test.c | 23 +----------------------
> 3 files changed, 21 insertions(+), 22 deletions(-)
Thanks Igor and Peter. I didn't have a machine with old glib for
testing :(.
Stefan
[-- Attachment #2: Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH v3] glib: add compatibility interface for g_get_monotonic_time()
2014-10-15 12:38 ` Stefan Hajnoczi
@ 2014-10-15 12:47 ` Peter Maydell
0 siblings, 0 replies; 8+ messages in thread
From: Peter Maydell @ 2014-10-15 12:47 UTC (permalink / raw)
To: Stefan Hajnoczi; +Cc: Igor Mammedov, QEMU Developers, Dr. David Alan Gilbert
On 15 October 2014 14:38, Stefan Hajnoczi <stefanha@redhat.com> wrote:
> Thanks Igor and Peter. I didn't have a machine with old glib for
> testing :(.
No problem. "Earliest supported glib version" is actually one of
the configs I'd like to buildtest before pushing but don't
conveniently have the ability to do. Maybe I could set up some
kind of chroot...
-- PMM
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Qemu-devel] [PATCH v3] glib: add compatibility interface for g_get_monotonic_time()
2014-10-15 12:29 ` [Qemu-devel] [PATCH v3] " Igor Mammedov
2014-10-15 12:38 ` Stefan Hajnoczi
@ 2014-10-15 19:38 ` Peter Maydell
1 sibling, 0 replies; 8+ messages in thread
From: Peter Maydell @ 2014-10-15 19:38 UTC (permalink / raw)
To: Igor Mammedov; +Cc: QEMU Developers, Stefan Hajnoczi, Dr. David Alan Gilbert
On 15 October 2014 14:29, Igor Mammedov <imammedo@redhat.com> wrote:
> From: Stefan Hajnoczi <stefanha@redhat.com>
>
> 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 glib-compat.h
> based on code from vhost-user-test.c.
>
> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> Signed-off-by: Igor Mammedov <imammedo@redhat.com>
> ---
> v3: include glib-compat.h into libqtest.h to fix another build breakage (Peter)
> v2: fix build break beacuse of missing G_TIME_SPAN_SECOND in header
> ---
Applied, thanks.
-- PMM
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2014-10-15 19:39 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-15 7:24 [Qemu-devel] [PATCH] glib: add compatibility interface for g_get_monotonic_time() Stefan Hajnoczi
2014-10-15 7:37 ` Igor Mammedov
2014-10-15 10:10 ` [Qemu-devel] [PATCH v2] " Igor Mammedov
2014-10-15 10:47 ` Peter Maydell
2014-10-15 12:29 ` [Qemu-devel] [PATCH v3] " Igor Mammedov
2014-10-15 12:38 ` Stefan Hajnoczi
2014-10-15 12:47 ` Peter Maydell
2014-10-15 19:38 ` Peter Maydell
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).