On Sat, 14 Feb 2026, Marc-André Lureau wrote:
On Fri, Feb 13, 2026 at 4:50 PM Mark Cave-Ayland
<[email protected]> wrote:

On 27/01/2026 18:25, [email protected] wrote:

From: Marc-André Lureau <[email protected]>

Use more correct GTimer, specific for each backend, with a trace event.

Signed-off-by: Marc-André Lureau <[email protected]>
---
  audio/audio_int.h       |  1 +
  audio/audio-mixeng-be.c | 25 +++++++++----------------
  audio/trace-events      |  1 +
  3 files changed, 11 insertions(+), 16 deletions(-)

diff --git a/audio/audio_int.h b/audio/audio_int.h
index dd5f2220d75..e0ed6af67ed 100644
--- a/audio/audio_int.h
+++ b/audio/audio_int.h
@@ -224,6 +224,7 @@ struct AudioMixengBackend {
      Audiodev *dev;

      QEMUTimer *ts;
+    GTimer *run_timer;
      QLIST_HEAD (hw_in_listhead, HWVoiceIn) hw_head_in;
      QLIST_HEAD (hw_out_listhead, HWVoiceOut) hw_head_out;
      QLIST_HEAD (cap_listhead, CaptureVoiceOut) cap_head;
diff --git a/audio/audio-mixeng-be.c b/audio/audio-mixeng-be.c
index 343f6ec181e..1b2c1fafa87 100644
--- a/audio/audio-mixeng-be.c
+++ b/audio/audio-mixeng-be.c
@@ -24,13 +24,13 @@
  #include "system/replay.h"
  #include "system/runstate.h"
  #include "trace.h"
+#include "trace/control.h"

  #define AUDIO_CAP "audio"
  #include "audio_int.h"

  /* #define DEBUG_OUT */
  /* #define DEBUG_CAPTURE */
-/* #define DEBUG_POLL */

  #define SW_NAME(sw) (sw)->name ? (sw)->name : "unknown"

@@ -1269,22 +1269,12 @@ void audio_run(AudioMixengBackend *s, const char *msg)
      audio_run_in(s);
      audio_run_capture(s);

-#ifdef DEBUG_POLL
-    {
-        static double prevtime;
-        double currtime;
-        struct timeval tv;
-
-        if (gettimeofday (&tv, NULL)) {
-            perror ("audio_run: gettimeofday");
-            return;
-        }
-
-        currtime = tv.tv_sec + tv.tv_usec * 1e-6;
-        dolog ("Elapsed since last %s: %f\n", msg, currtime - prevtime);
-        prevtime = currtime;
+    if (trace_event_get_state(TRACE_AUDIO_RUN_POLL)) {
+        /* Convert seconds to microseconds for trace event */
+        int64_t elapsed_us = g_timer_elapsed(s->run_timer, NULL) * 1000000;

Not being familiar with g_timer_elapsed() I had a look at the glib docs,
and it seems that g_timer_elapsed() returns a gdouble as opposed to an
int64_t?

yes, as seconds. So it is multiplied by 1000000 to get back usec, as before

There's #define NANOSECONDS_PER_SECOND 1000000000LL in qemu/timer.h. Do we need a MICROSECONDS_PER_SECOND constant there (or defined here) to make it more obvious?

Regards,
BALATON Zoltan

Reply via email to