From: Marc-André Lureau <[email protected]> Use more correct GTimer, specific for each backend, with a trace event.
Reviewed-by: Mark Cave-Ayland <[email protected]> Reviewed-by: Akihiko Odaki <[email protected]> Signed-off-by: Marc-André Lureau <[email protected]> --- audio/audio_int.h | 1 + include/qemu/timer.h | 1 + audio/audio-mixeng-be.c | 25 +++++++++---------------- audio/trace-events | 1 + 4 files changed, 12 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/include/qemu/timer.h b/include/qemu/timer.h index 7c18da16525..b931181f53d 100644 --- a/include/qemu/timer.h +++ b/include/qemu/timer.h @@ -6,6 +6,7 @@ #include "qemu/host-utils.h" #define NANOSECONDS_PER_SECOND 1000000000LL +#define MICROSECONDS_PER_SECOND 1000000LL /* timers */ diff --git a/audio/audio-mixeng-be.c b/audio/audio-mixeng-be.c index 84e4d136de3..2aeb05ba37e 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) * MICROSECONDS_PER_SECOND; + 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" -- 2.53.0
