qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Jan Kiszka <jan.kiszka@web.de>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [4249] Improve audio api use in WM8750.
Date: Fri, 25 Apr 2008 03:00:55 +0200	[thread overview]
Message-ID: <48112D47.6050500@web.de> (raw)
In-Reply-To: <48112992.2000602@web.de>

[-- Attachment #1: Type: text/plain, Size: 3307 bytes --]

Jan Kiszka wrote:
> andrzej zaborowski wrote:
>> On 25/04/2008, Jan Kiszka <jan.kiszka@web.de> wrote:
>>> Jan Kiszka wrote:
>>>  > Nothing is crawling here, just use a reasonable threshold for flushing
>>>  > _after_ the callback. Need to check, but maybe we can even wait the a
>>>  > full buffer.
>>>
>>>
>>> Of course not the full buffer, but its half is fine as it generally
>>>  leaves enough time to the guest to refill the other half:
>>>
>>>  Index: hw/wm8750.c
>>>  ===================================================================
>>>  --- hw/wm8750.c (Revision 4250)
>>>  +++ hw/wm8750.c (Arbeitskopie)
>>>  @@ -73,14 +73,10 @@ static void wm8750_audio_out_cb(void *op
>>>
>>>  {
>>>      struct wm8750_s *s = (struct wm8750_s *) opaque;
>>>
>>>
>>> -    if (s->idx_out >= free_b) {
>>>  -        s->idx_out = free_b;
>>>  -        s->req_out = 0;
>>>
>>> +    s->req_out = free_b;
>>>  +    s->data_req(s->opaque, free_b >> 2, s->req_in >> 2);
>>>
>>> +    if (s->idx_out >= sizeof(s->data_out)/2)
>> The checking of whether the guest filled enough data happens in
>> wm8750_dac_dat(), I don't see why do it second time here.  The only
>> place we need an additional check is before s->dat_req call, which you
>> remove.
> 
> True, that's redundant, let's fix it this way (this even obsoletes the
> flush in out_cb):
> 
> Index: hw/wm8750.c
> ===================================================================
> --- hw/wm8750.c	(Revision 4250)
> +++ hw/wm8750.c	(Arbeitskopie)
> @@ -73,14 +73,8 @@ static void wm8750_audio_out_cb(void *op
>  {
>      struct wm8750_s *s = (struct wm8750_s *) opaque;
>  
> -    if (s->idx_out >= free_b) {
> -        s->idx_out = free_b;
> -        s->req_out = 0;
> -        wm8750_out_flush(s);
> -    } else
> -        s->req_out = free_b - s->idx_out;
> - 
> -    s->data_req(s->opaque, s->req_out >> 2, s->req_in >> 2);
> +    s->req_out = free_b;
> +    s->data_req(s->opaque, free_b >> 2, s->req_in >> 2);
>  }
>  
>  struct wm_rate_s {
> @@ -623,7 +617,7 @@ void wm8750_dac_dat(void *opaque, uint32
>      *data = sample & s->outmask;
>      s->req_out -= 4;
>      s->idx_out += 4;
> -    if (s->idx_out >= sizeof(s->data_out) || s->req_out <= 0)
> +    if (s->idx_out >= sizeof(s->data_out)/2 || s->req_out <= 0)

OK, it's late... The real issue here is that the wm8750's internal cache
correlates with the MusicPal guest's internal buffering threshold - it
happens to be 4K as well. Thus, the line above just pushes the problem
to guests that play with 2K buffers. And this demonstrates nicely that
the current caching is fragile, only suitable for a subset of guests.

Back to square #1, only cache what piles up during controllable periods:
inside the callback. In my case, I _depend_ on flushing after the
callback, because this is where data gets transfered to the Wolfson, and
it gets transferred in larger chunks as well. Thus, flushing later
easily causes buffer underruns.

And for those scenarios where data arrives asynchronously in smaller
chunks between the callbacks, we may also flush before entering the
subordinated callback.

But, frankly, how may cycle does all this caching actually save us? Did
you measure it? I doubt it is relevant.

Jan


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 254 bytes --]

  reply	other threads:[~2008-04-25  1:01 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-04-24 21:01 [Qemu-devel] [4249] Improve audio api use in WM8750 Andrzej Zaborowski
2008-04-24 21:30 ` Jan Kiszka
2008-04-24 23:34   ` andrzej zaborowski
2008-04-24 23:57     ` Jan Kiszka
2008-04-25  0:09       ` Jan Kiszka
2008-04-25  0:23         ` andrzej zaborowski
2008-04-25  0:45           ` Jan Kiszka
2008-04-25  1:00             ` Jan Kiszka [this message]
2008-04-25  1:41               ` andrzej zaborowski
2008-04-25  1:05             ` andrzej zaborowski
2008-04-25  1:10               ` Jan Kiszka
2008-04-25  0:15       ` andrzej zaborowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48112D47.6050500@web.de \
    --to=jan.kiszka@web.de \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).