Le 05/03/2022 à 20:17, Marc-André Lureau a écrit :
On Sat, Mar 5, 2022 at 1:18 AM <marcandre.lur...@redhat.com> wrote:
From: Marc-André Lureau <marcandre.lur...@redhat.com>
GLib g_get_real_time() is an alternative to gettimeofday() which allows
to simplify our code.
For semihosting, a few bits are lost on POSIX host, but this shouldn't
be a big concern.
Signed-off-by: Marc-André Lureau <marcandre.lur...@redhat.com>
Reviewed-by: Laurent Vivier <laur...@vivier.eu>
---
blockdev.c | 8 ++++----
hw/rtc/m41t80.c | 6 +++---
hw/virtio/virtio-balloon.c | 9 +--------
qapi/qmp-event.c | 12 +++++-------
qemu-img.c | 8 ++++----
target/m68k/m68k-semi.c | 22 ++++++++++------------
target/nios2/nios2-semi.c | 23 ++++++++++-------------
7 files changed, 37 insertions(+), 51 deletions(-)
...
index 19d3cd003833..025716b3ec37 100644
--- a/qapi/qmp-event.c
+++ b/qapi/qmp-event.c
@@ -20,15 +20,13 @@
static void timestamp_put(QDict *qdict)
{
- int err;
QDict *ts;
- qemu_timeval tv;
+ int64_t rt = g_get_real_time();
- err = qemu_gettimeofday(&tv);
- /* Put -1 to indicate failure of getting host time */
- ts = qdict_from_jsonf_nofail("{ 'seconds': %lld, 'microseconds': %lld }",
- err < 0 ? -1LL : (long long)tv.tv_sec,
- err < 0 ? -1LL : (long long)tv.tv_usec);
+ ts = qdict_from_jsonf_nofail("{ 'seconds': %" G_GINT64_FORMAT
+ ", 'microseconds': %" G_GINT64_FORMAT "}",
+ rt / G_USEC_PER_SEC,
+ rt % G_USEC_PER_SEC);
NACK this, fixed in v3
Why keeping the %lld is better than moving to %G_GINT64_FORMAT?
Thanks,
Laurent