On 14/02/2026 10:24, Marc-André Lureau wrote:

Hi

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

Sorry I was probably a little bit vague here: the part I was unsure about was what was happening with the conversion from gdouble to int64_t without an explicit cast? I was expecting the compiler to complain.


+        trace_audio_run_poll(msg, elapsed_us);
+        g_timer_start(s->run_timer);
       }
-#endif
   }

   void audio_generic_run_buffer_in(HWVoiceIn *hw)
@@ -1545,6 +1535,7 @@ static void audio_mixeng_backend_init(Object *obj)
       QLIST_INIT(&s->hw_head_in);
       QLIST_INIT(&s->cap_head);
       s->ts = timer_new_ns(QEMU_CLOCK_VIRTUAL, audio_timer, s);
+    s->run_timer = g_timer_new();

       s->vmse = 
qemu_add_vm_change_state_handler(audio_vm_change_state_handler, s);
       assert(s->vmse != NULL);
@@ -1596,6 +1587,8 @@ static void audio_mixeng_backend_finalize(Object *obj)
           s->ts = NULL;
       }

+    g_clear_pointer(&s->run_timer, g_timer_destroy);
+
       if (s->vmse) {
           qemu_del_vm_change_state_handler(s->vmse);
           s->vmse = NULL;
diff --git a/audio/trace-events b/audio/trace-events
index 4749c54fc04..d66a712e871 100644
--- a/audio/trace-events
+++ b/audio/trace-events
@@ -61,6 +61,7 @@ audio_timer_delayed(int interval) "interval %d ms"

   # audio-mixeng-be.c
   audio_get_avail(const char *name, size_t live, uint32_t frontend_frames) "%s: 
get_avail live %zu frontend frames %u"
+audio_run_poll(const char *msg, int64_t elapsed_us) "Elapsed since last %s: %" PRId64 
" us"

   # audio_template.h
   audio_open_out(const char *name, int freq, int nchannels, int fmt) "open %s, freq 
%d, nchannels %d, fmt %d"


ATB,

Mark.


Reply via email to