Replace qemu_gettimeofday() with g_get_real_time()

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.lureau@redhat.com>
Reviewed-by: Laurent Vivier <laurent@vivier.eu>
Message-Id: <20220307070401.171986-5-marcandre.lureau@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Marc-André Lureau 2022-03-07 11:04:00 +04:00 committed by Paolo Bonzini
parent 287698e50f
commit f793dde091
7 changed files with 35 additions and 50 deletions

View file

@ -20,15 +20,12 @@
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);
(long long)rt / G_USEC_PER_SEC,
(long long)rt % G_USEC_PER_SEC);
qdict_put(qdict, "timestamp", ts);
}