audio/hda: improve windows guest audio quality.
v3 cover audio/hda: improve windows guest audio quality.
Based on a patch by Martin Schrodt.
v3: rebase to latest master, solve compat.h conflict.
v2: drop underrun detection, handle overruns only.
Gerd Hoffmann (4):
audio/hda: create millisecond timers that handle IO audio/hda: turn some dprintfs into trace points audio/hda: tweak timer adjust logic audio/hda: detect output buffer overruns
include/hw/compat.h | 7 +- hw/audio/hda-codec.c | 287 ++++++++++++++++++++++++++++++++++++++++++++------ hw/audio/intel-hda.c | 7 -- hw/audio/trace-events | 6 ++ 4 files changed, 268 insertions(+), 39 deletions(-)
Signature · 1 line
2.9.3
PATCH v3 1/4 audio/hda: create millisecond timers that handle IO
Currently, the HDA device tries to sync itself with the QEMU audio backend by waiting for the guest driver to handle buffer completion interrupts. This causes the backend to often read too much data from the device, as well as running out of data whenever the guest takes too long to handle the interrupt.
According to the HDA specification, the guest is also not required to use interrupts, but can also sync itself by polling the LPIB registers.
This patch will introduce high frequency (1000Hz) timers that interface with the device and allow for much smoother emulation of the LPIB registers. Since the timing is now provided by these timers, the need to wait for buffer completion interrupts also ceases.
Message-id: [email protected]
[ kraxel: keep old code for compatibility with older qemu versions,
add property to switch code paths at runtime ]
--- include/hw/compat.h | 7 +- hw/audio/hda-codec.c | 263 ++++++++++++++++++++++++++++++++++++++++++++++----- hw/audio/intel-hda.c | 7 -- 3 files changed, 243 insertions(+), 34 deletions(-)
include/hw/compat.h +6 -1
@@ -1,7 +1,12 @@#ifndef HW_COMPAT_H #define HW_COMPAT_H -#define HW_COMPAT_2_12 +#define HW_COMPAT_2_12 \ + {\ + .driver = "hda-audio",\ + .property = "use-timer",\ + .value = "false",\ + },#define HW_COMPAT_2_11 \ {\
hw/audio/hda-codec.c +237 -26
371 lines not on this page · raw message
hw/audio/intel-hda.c +0 -7
@@ -407,13 +407,6 @@ static bool intel_hda_xfer(HDACodecDevice *dev, uint32_t stnr, bool output,if (st->bpl ==NULL ) {return false; } -if (st->ctl & (1 <<26 )) { -/* -* Wait with the next DMA xfer until the guest -* has acked the buffer completion interrupt -*/ -return false; - } left = len; s = st->bentries;
Signature · 1 line
2.9.3
PATCH v3 2/4 audio/hda: turn some dprintfs into trace points
In reply to Gerd Hoffmann--- hw/audio/hda-codec.c | 9 ++++----- hw/audio/trace-events | 4 ++++ 2 files changed, 8 insertions(+), 5 deletions(-)
hw/audio/hda-codec.c +4 -5
@@ -24,6 +24,7 @@#include "intel-hda.h" #include "intel-hda-defs.h" #include "audio/audio.h" +#include "trace.h" /* -------------------------------------------------------------------------- */
@@ -394,8 +395,7 @@ static void hda_audio_set_running(HDAAudioStream *st, bool running)return ; } st->running = running; -dprint (st->state,1 ,"%s: %s (stream %d)\n" , st->node->name, - st->running ?"on" :"off" , st->stream); +trace_hda_audio_running (st->node->name, st->stream, st->running);if (st->state->use_timer) {if (running) {int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );
@@ -449,9 +449,8 @@ static void hda_audio_setup(HDAAudioStream *st)return ; } -dprint (st->state,1 ,"%s: format: %d x %s @ %d Hz\n" , - st->node->name, st->as.nchannels, - fmt2name[st->as.fmt], st->as.freq); +trace_hda_audio_format (st->node->name, st->as.nchannels, + fmt2name[st->as.fmt], st->as.freq);if (st->output) {if (use_timer) {
hw/audio/trace-events +4 -0
@@ -17,3 +17,7 @@ milkymist_ac97_in_cb(int avail, uint32_t remaining) "avail %d remaining %u" milkymist_ac97_in_cb_transferred(int transferred) "transferred %d" milkymist_ac97_out_cb(int free, uint32_t remaining) "free %d remaining %u" milkymist_ac97_out_cb_transferred(int transferred) "transferred %d" + +# hw/audio/hda-codec.c +hda_audio_running(const char *stream, int nr, bool running) "st %s, nr %d, run %d" +hda_audio_format(const char *stream, int chan, const char *fmt, int freq) "st %s, %d x %s @ %d Hz"
Signature · 1 line
2.9.3
Re: [Qemu-devel] [PATCH v3 2/4] audio/hda: turn some dprintfs into trace points
Quoted 1 line · Gerd Hoffmann
Signed-off-by Gerd Hoffmann <[email protected]>
Again:
Quoted 52 lines
--- hw/audio/hda-codec.c | 9 ++++----- hw/audio/trace-events | 4 ++++ 2 files changed, 8 insertions(+), 5 deletions(-)hw/audio/hda-codec.c +4
-5@@ -24,6 +24,7 @@#include "intel-hda.h" #include "intel-hda-defs.h" #include "audio/audio.h" +#include "trace.h" /* -------------------------------------------------------------------------- */ @@ -394,8 +395,7 @@ static void hda_audio_set_running(HDAAudioStream *st, bool running)return ; } st->running = running; -dprint (st->state,1 ,"%s: %s (stream %d)\n" , st->node->name, - st->running ?"on" :"off" , st->stream); +trace_hda_audio_running (st->node->name, st->stream, st->running);if (st->state->use_timer) {if (running) {int64_t now =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL );@@ -449,9 +449,8 @@ static void hda_audio_setup(HDAAudioStream *st)return ; } -dprint (st->state,1 ,"%s: format: %d x %s @ %d Hz\n" , - st->node->name, st->as.nchannels, - fmt2name[st->as.fmt], st->as.freq); +trace_hda_audio_format (st->node->name, st->as.nchannels, + fmt2name[st->as.fmt], st->as.freq);if (st->output) {if (use_timer) {hw/audio/trace-events +4
-0@@ -17,3 +17,7 @@ milkymist_ac97_in_cb(int avail, uint32_t remaining) "avail %d remaining %u" milkymist_ac97_in_cb_transferred(int transferred) "transferred %d" milkymist_ac97_out_cb(int free, uint32_t remaining) "free %d remaining %u" milkymist_ac97_out_cb_transferred(int transferred) "transferred %d" + +# hw/audio/hda-codec.c +hda_audio_running(const char *stream, int nr, bool running) "st %s, nr %d, run %d" +hda_audio_format(const char *stream, int chan, const char *fmt, int freq) "st %s, %d x %s @ %d Hz"
PATCH v3 3/4 audio/hda: tweak timer adjust logic
In reply to Gerd HoffmannWe have some jitter in the audio timer call frequency and buffer sizes. So it is rather pointless trying to be very exact, effect is a constant up+down adjustment. So adjust only in case we are off too much.
--- hw/audio/hda-codec.c | 20 +++++++++++++------- hw/audio/trace-events | 1 + 2 files changed, 14 insertions(+), 7 deletions(-)
hw/audio/hda-codec.c +13 -7
@@ -129,7 +129,6 @@ static void hda_codec_parse_fmt(uint32_t format, struct audsettings *as)#include "hda-codec-common.h" #define HDA_TIMER_TICKS (SCALE_MS) -#define MAX_CORR (SCALE_US * 100)#define B_SIZE sizeof(st->buf)#define B_MASK (sizeof(st->buf) - 1)
@@ -196,13 +195,20 @@ static inline int64_t hda_bytes_per_second(HDAAudioStream *st)static inline void hda_timer_sync_adjust (HDAAudioStream *st,int64_t target_pos) { -int64_t corr = -NANOSECONDS_PER_SECOND * target_pos /hda_bytes_per_second (st); -if (corr >MAX_CORR ) { - corr =MAX_CORR ; - }else if (corr < -MAX_CORR ) { - corr = -MAX_CORR ; +int64_t limit =B_SIZE /8 ; +int64_t corr =0 ; + +if (target_pos > limit) { + corr =HDA_TIMER_TICKS ; } +if (target_pos < -limit) { + corr = -HDA_TIMER_TICKS ; + } +if (corr ==0 ) { +return ; + } + +trace_hda_audio_adjust (st->node->name, target_pos);atomic_fetch_add (&st->buft_start, corr); }
hw/audio/trace-events +1 -0
@@ -21,3 +21,4 @@ milkymist_ac97_out_cb_transferred(int transferred) "transferred %d" # hw/audio/hda-codec.c hda_audio_running(const char *stream, int nr, bool running) "st %s, nr %d, run %d" hda_audio_format(const char *stream, int chan, const char *fmt, int freq) "st %s, %d x %s @ %d Hz" +hda_audio_adjust(const char *stream, int pos) "st %s, pos %d"
Signature · 1 line
2.9.3
PATCH v3 4/4 audio/hda: detect output buffer overruns
In reply to Gerd HoffmannIf some event caused some larger playback hickup the fine-grained timer adjust isn't able to recover. Use a buffer overruns as indicator for that. Reset timer adjust logic in case we detected one.
--- hw/audio/hda-codec.c | 9 +++++++++ hw/audio/trace-events | 1 + 2 files changed, 10 insertions(+)
hw/audio/hda-codec.c +9 -0
@@ -325,6 +325,15 @@ static void hda_audio_output_cb(void *opaque, int avail)int64_t to_transfer =audio_MIN (wpos - rpos, avail); +if (wpos - rpos ==B_SIZE ) { +/* drop buffer, reset timer adjust */ + st->rpos =0 ; + st->wpos =0 ; + st->buft_start =qemu_clock_get_ns (QEMU_CLOCK_VIRTUAL ); +trace_hda_audio_overrun (st->node->name); +return ; + } +hda_timer_sync_adjust (st, (wpos - rpos) - to_transfer - (B_SIZE >>1 ));while (to_transfer) {
hw/audio/trace-events +1 -0
@@ -22,3 +22,4 @@ milkymist_ac97_out_cb_transferred(int transferred) "transferred %d" hda_audio_running(const char *stream, int nr, bool running) "st %s, nr %d, run %d" hda_audio_format(const char *stream, int chan, const char *fmt, int freq) "st %s, %d x %s @ %d Hz" hda_audio_adjust(const char *stream, int pos) "st %s, pos %d" +hda_audio_overrun(const char *stream) "st %s"
Signature · 1 line
2.9.3