qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 1/2] audio: honor QEMU_AUDIO_TIMER_PERIOD instead of waking up every *nano* second
@ 2013-10-09 19:42 Hans de Goede
  2013-10-09 19:42 ` [Qemu-devel] [PATCH 2/2] audio: Lower default wakeup rate to 100 times / second Hans de Goede
                   ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Hans de Goede @ 2013-10-09 19:42 UTC (permalink / raw)
  To: malc; +Cc: Paolo Bonzini, qemu-stable, qemu-devel, Alex Bligh, Hans de Goede

Now that we no longer have MIN_REARM_TIMER_NS a bug in the audio subsys has
clearly shown it self by trying to make a timer fire every nano second.

Note we have a similar problem in 1.6, 1.5 and older but there
MIN_REARM_TIMER_NS limits the wakeups caused by audio being active to
4000 times / second. This still causes a host cpu load of 50 % for simply
playing audio, where as with this patch git master is at 13%, so we should
backport this to 1.5 and 1.6 too.

Note this will not apply to 1.5 and 1.6 as is.

Cc: qemu-stable@nongnu.org
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 audio/audio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/audio/audio.c b/audio/audio.c
index af4cdf6..b3db679 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1124,7 +1124,8 @@ static int audio_is_timer_needed (void)
 static void audio_reset_timer (AudioState *s)
 {
     if (audio_is_timer_needed ()) {
-        timer_mod (s->ts, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 1);
+        timer_mod (s->ts,
+            qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + conf.period.ticks);
     }
     else {
         timer_del (s->ts);
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [Qemu-devel] [PATCH 2/2] audio: Lower default wakeup rate to 100 times / second
  2013-10-09 19:42 [Qemu-devel] [PATCH 1/2] audio: honor QEMU_AUDIO_TIMER_PERIOD instead of waking up every *nano* second Hans de Goede
@ 2013-10-09 19:42 ` Hans de Goede
  2013-10-10  6:31 ` [Qemu-devel] [PATCH 1/2] audio: honor QEMU_AUDIO_TIMER_PERIOD instead of waking up every *nano* second Alex Bligh
  2013-12-03 20:03 ` [Qemu-devel] [Qemu-stable] " Michael Roth
  2 siblings, 0 replies; 10+ messages in thread
From: Hans de Goede @ 2013-10-09 19:42 UTC (permalink / raw)
  To: malc; +Cc: Paolo Bonzini, qemu-devel, Alex Bligh, Hans de Goede

This is more then plenty to keep audio card fifos filles / emptied.

This drops host cpu-load for audio playback inside a linux vm from
13% to 9%.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
---
 audio/audio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/audio/audio.c b/audio/audio.c
index b3db679..fc77511 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -95,7 +95,7 @@ static struct {
         }
     },
 
-    .period = { .hertz = 250 },
+    .period = { .hertz = 100 },
     .plive = 0,
     .log_to_monitor = 0,
     .try_poll_in = 1,
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] audio: honor QEMU_AUDIO_TIMER_PERIOD instead of waking up every *nano* second
  2013-10-09 19:42 [Qemu-devel] [PATCH 1/2] audio: honor QEMU_AUDIO_TIMER_PERIOD instead of waking up every *nano* second Hans de Goede
  2013-10-09 19:42 ` [Qemu-devel] [PATCH 2/2] audio: Lower default wakeup rate to 100 times / second Hans de Goede
@ 2013-10-10  6:31 ` Alex Bligh
  2013-10-10  6:58   ` Hans de Goede
  2013-10-10  9:23   ` Hans de Goede
  2013-12-03 20:03 ` [Qemu-devel] [Qemu-stable] " Michael Roth
  2 siblings, 2 replies; 10+ messages in thread
From: Alex Bligh @ 2013-10-10  6:31 UTC (permalink / raw)
  To: Hans de Goede; +Cc: Paolo Bonzini, malc, qemu-stable, Alex Bligh, qemu-devel


On 9 Oct 2013, at 20:42, Hans de Goede wrote:

> Now that we no longer have MIN_REARM_TIMER_NS a bug in the audio subsys has
> clearly shown it self by trying to make a timer fire every nano second.
> 
> Note we have a similar problem in 1.6, 1.5 and older but there
> MIN_REARM_TIMER_NS limits the wakeups caused by audio being active to
> 4000 times / second. This still causes a host cpu load of 50 % for simply
> playing audio, where as with this patch git master is at 13%, so we should
> backport this to 1.5 and 1.6 too.
> 
> Note this will not apply to 1.5 and 1.6 as is.
> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
> audio/audio.c | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/audio/audio.c b/audio/audio.c
> index af4cdf6..b3db679 100644
> --- a/audio/audio.c
> +++ b/audio/audio.c
> @@ -1124,7 +1124,8 @@ static int audio_is_timer_needed (void)
> static void audio_reset_timer (AudioState *s)
> {
>     if (audio_is_timer_needed ()) {
> -        timer_mod (s->ts, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 1);
> +        timer_mod (s->ts,
> +            qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + conf.period.ticks);

This assumes conf.period.ticks is in nanoseconds. That seems wrong.
Suggest multiplying by SCALE_US or SCALE_MS.

Alex

>     }
>     else {
>         timer_del (s->ts);
> -- 
> 1.8.3.1
> 
> 
> 

-- 
Alex Bligh

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] audio: honor QEMU_AUDIO_TIMER_PERIOD instead of waking up every *nano* second
  2013-10-10  6:31 ` [Qemu-devel] [PATCH 1/2] audio: honor QEMU_AUDIO_TIMER_PERIOD instead of waking up every *nano* second Alex Bligh
@ 2013-10-10  6:58   ` Hans de Goede
  2013-10-10  7:02     ` Alex Bligh
  2013-10-10  9:23   ` Hans de Goede
  1 sibling, 1 reply; 10+ messages in thread
From: Hans de Goede @ 2013-10-10  6:58 UTC (permalink / raw)
  To: Alex Bligh; +Cc: Paolo Bonzini, malc, qemu-stable, qemu-devel

Hi,

On 10/10/2013 08:31 AM, Alex Bligh wrote:
>
> On 9 Oct 2013, at 20:42, Hans de Goede wrote:
>
>> Now that we no longer have MIN_REARM_TIMER_NS a bug in the audio subsys has
>> clearly shown it self by trying to make a timer fire every nano second.
>>
>> Note we have a similar problem in 1.6, 1.5 and older but there
>> MIN_REARM_TIMER_NS limits the wakeups caused by audio being active to
>> 4000 times / second. This still causes a host cpu load of 50 % for simply
>> playing audio, where as with this patch git master is at 13%, so we should
>> backport this to 1.5 and 1.6 too.
>>
>> Note this will not apply to 1.5 and 1.6 as is.
>>
>> Cc: qemu-stable@nongnu.org
>> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
>> ---
>> audio/audio.c | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/audio/audio.c b/audio/audio.c
>> index af4cdf6..b3db679 100644
>> --- a/audio/audio.c
>> +++ b/audio/audio.c
>> @@ -1124,7 +1124,8 @@ static int audio_is_timer_needed (void)
>> static void audio_reset_timer (AudioState *s)
>> {
>>      if (audio_is_timer_needed ()) {
>> -        timer_mod (s->ts, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 1);
>> +        timer_mod (s->ts,
>> +            qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + conf.period.ticks);
>
> This assumes conf.period.ticks is in nanoseconds. That seems wrong.
> Suggest multiplying by SCALE_US or SCALE_MS.

Which it is, quoting from higher up in the same file:

         conf.period.ticks =
             muldiv64 (1, get_ticks_per_sec (), conf.period.hertz);

And get_ticks_per_sec () returns ns .

Regards,

Hans



>
> Alex
>
>>      }
>>      else {
>>          timer_del (s->ts);
>> --
>> 1.8.3.1
>>
>>
>>
>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] audio: honor QEMU_AUDIO_TIMER_PERIOD instead of waking up every *nano* second
  2013-10-10  6:58   ` Hans de Goede
@ 2013-10-10  7:02     ` Alex Bligh
  0 siblings, 0 replies; 10+ messages in thread
From: Alex Bligh @ 2013-10-10  7:02 UTC (permalink / raw)
  To: Hans de Goede; +Cc: Paolo Bonzini, malc, qemu-stable, Alex Bligh, qemu-devel


On 10 Oct 2013, at 07:58, Hans de Goede wrote:

> Which it is, quoting from higher up in the same file:
> 
>        conf.period.ticks =
>            muldiv64 (1, get_ticks_per_sec (), conf.period.hertz);
> 
> And get_ticks_per_sec () returns ns .

Doh! I confused .hertz & .ticks.

-- 
Alex Bligh

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] audio: honor QEMU_AUDIO_TIMER_PERIOD instead of waking up every *nano* second
  2013-10-10  6:31 ` [Qemu-devel] [PATCH 1/2] audio: honor QEMU_AUDIO_TIMER_PERIOD instead of waking up every *nano* second Alex Bligh
  2013-10-10  6:58   ` Hans de Goede
@ 2013-10-10  9:23   ` Hans de Goede
  2013-10-10  9:35     ` Paolo Bonzini
  1 sibling, 1 reply; 10+ messages in thread
From: Hans de Goede @ 2013-10-10  9:23 UTC (permalink / raw)
  To: Alex Bligh; +Cc: Paolo Bonzini, malc, qemu-stable, qemu-devel

Hi,

On 9 Oct 2013, at 20:42, Hans de Goede wrote:
>
> Now that we no longer have MIN_REARM_TIMER_NS a bug in the audio subsys has
> clearly shown it self by trying to make a timer fire every nano second.
>
> Note we have a similar problem in 1.6, 1.5 and older but there
> MIN_REARM_TIMER_NS limits the wakeups caused by audio being active to
> 4000 times / second. This still causes a host cpu load of 50 % for simply
> playing audio, where as with this patch git master is at 13%, so we should
> backport this to 1.5 and 1.6 too.

I'm still not sure when this actually started happening, but looking at
RHEL-6 qemu sources to see if that has the issue too, I've learned how
this problem was introduced, the audio_timer callback used to do this:

     qemu_mod_timer (s->ts, qemu_get_clock (vm_clock) + conf.period.ticks);

instead of calling audio_reset_timer(), so in the past there were 2 mod_timer
calls, one from audio_reset_timer(), which scheduled the callback to run
ASAP, and one from the audio_timer callback honering conf.period.hertz.

Then at some point the qemu_mod_timer call in audio_timer was replaced
with calling audio_reset_timer() and we got the problem my patch fixes.

Regards,

Hans

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [PATCH 1/2] audio: honor QEMU_AUDIO_TIMER_PERIOD instead of waking up every *nano* second
  2013-10-10  9:23   ` Hans de Goede
@ 2013-10-10  9:35     ` Paolo Bonzini
  0 siblings, 0 replies; 10+ messages in thread
From: Paolo Bonzini @ 2013-10-10  9:35 UTC (permalink / raw)
  To: Hans de Goede; +Cc: malc, qemu-stable, Alex Bligh, qemu-devel

Il 10/10/2013 11:23, Hans de Goede ha scritto:
> Hi,
> 
> On 9 Oct 2013, at 20:42, Hans de Goede wrote:
>>
>> Now that we no longer have MIN_REARM_TIMER_NS a bug in the audio
>> subsys has
>> clearly shown it self by trying to make a timer fire every nano second.
>>
>> Note we have a similar problem in 1.6, 1.5 and older but there
>> MIN_REARM_TIMER_NS limits the wakeups caused by audio being active to
>> 4000 times / second. This still causes a host cpu load of 50 % for simply
>> playing audio, where as with this patch git master is at 13%, so we
>> should
>> backport this to 1.5 and 1.6 too.
> 
> I'm still not sure when this actually started happening, but looking at
> RHEL-6 qemu sources to see if that has the issue too, I've learned how
> this problem was introduced, the audio_timer callback used to do this:
> 
>     qemu_mod_timer (s->ts, qemu_get_clock (vm_clock) + conf.period.ticks);
> 
> instead of calling audio_reset_timer(), so in the past there were 2
> mod_timer
> calls, one from audio_reset_timer(), which scheduled the callback to run
> ASAP, and one from the audio_timer callback honering conf.period.hertz.
> 
> Then at some point the qemu_mod_timer call in audio_timer was replaced
> with calling audio_reset_timer() and we got the problem my patch fixes.

The first broken version seems to be 0.14.0:

commit 39deb1e496de81957167daebf5cf5d1fbd5e47c2
Author: malc <av1474@comtv.ru>
Date:   Thu Nov 18 14:30:12 2010 +0300

    audio: Only use audio timer when necessary

    Originally proposed by Gerd Hoffmann.

    Signed-off-by: malc <av1474@comtv.ru>
    Acked-by: Gerd Hoffmann <kraxel@redhat.com>

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [Qemu-stable] [PATCH 1/2] audio: honor QEMU_AUDIO_TIMER_PERIOD instead of waking up every *nano* second
  2013-10-09 19:42 [Qemu-devel] [PATCH 1/2] audio: honor QEMU_AUDIO_TIMER_PERIOD instead of waking up every *nano* second Hans de Goede
  2013-10-09 19:42 ` [Qemu-devel] [PATCH 2/2] audio: Lower default wakeup rate to 100 times / second Hans de Goede
  2013-10-10  6:31 ` [Qemu-devel] [PATCH 1/2] audio: honor QEMU_AUDIO_TIMER_PERIOD instead of waking up every *nano* second Alex Bligh
@ 2013-12-03 20:03 ` Michael Roth
  2013-12-03 21:17   ` Alex Bligh
  2 siblings, 1 reply; 10+ messages in thread
From: Michael Roth @ 2013-12-03 20:03 UTC (permalink / raw)
  To: Hans de Goede, malc; +Cc: Paolo Bonzini, qemu-stable, Alex Bligh, qemu-devel

Quoting Hans de Goede (2013-10-09 14:42:37)
> Now that we no longer have MIN_REARM_TIMER_NS a bug in the audio subsys has
> clearly shown it self by trying to make a timer fire every nano second.
> 
> Note we have a similar problem in 1.6, 1.5 and older but there
> MIN_REARM_TIMER_NS limits the wakeups caused by audio being active to
> 4000 times / second. This still causes a host cpu load of 50 % for simply
> playing audio, where as with this patch git master is at 13%, so we should
> backport this to 1.5 and 1.6 too.
> 
> Note this will not apply to 1.5 and 1.6 as is.

What needs to be changed? Wouldn't this patch also restore the 250hz
frequency for 1.6, as it was pre-0.14?

> 
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Hans de Goede <hdegoede@redhat.com>
> ---
>  audio/audio.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/audio/audio.c b/audio/audio.c
> index af4cdf6..b3db679 100644
> --- a/audio/audio.c
> +++ b/audio/audio.c
> @@ -1124,7 +1124,8 @@ static int audio_is_timer_needed (void)
>  static void audio_reset_timer (AudioState *s)
>  {
>      if (audio_is_timer_needed ()) {
> -        timer_mod (s->ts, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + 1);
> +        timer_mod (s->ts,
> +            qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + conf.period.ticks);
>      }
>      else {
>          timer_del (s->ts);
> -- 
> 1.8.3.1

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [Qemu-stable] [PATCH 1/2] audio: honor QEMU_AUDIO_TIMER_PERIOD instead of waking up every *nano* second
  2013-12-03 20:03 ` [Qemu-devel] [Qemu-stable] " Michael Roth
@ 2013-12-03 21:17   ` Alex Bligh
  2013-12-03 22:00     ` Michael Roth
  0 siblings, 1 reply; 10+ messages in thread
From: Alex Bligh @ 2013-12-03 21:17 UTC (permalink / raw)
  To: Michael Roth, Hans de Goede, malc
  Cc: qemu-devel, Paolo Bonzini, qemu-stable, Alex Bligh



--On 3 December 2013 14:03:04 -0600 Michael Roth 
<mdroth@linux.vnet.ibm.com> wrote:

>> Note this will not apply to 1.5 and 1.6 as is.
>
> What needs to be changed? Wouldn't this patch also restore the 250hz
> frequency for 1.6, as it was pre-0.14?

The function names have changed as have the clock names.
At a guess (cut and paste diff, completely untested), you
need something like this:

diff --git a/audio/audio.c b/audio/audio.c
index 02bb886..45d146e 100644
--- a/audio/audio.c
+++ b/audio/audio.c
@@ -1124,7 +1124,8 @@ static int audio_is_timer_needed (void)
 static void audio_reset_timer (AudioState *s)
 {
     if (audio_is_timer_needed ()) {
-        qemu_mod_timer (s->ts, qemu_get_clock_ns (vm_clock) + 1);
+        qemu_mod_timer (s->ts, qemu_get_clock_ns (vm_clock) +
+                        conf.period.ticks);
     }
     else {
         qemu_del_timer (s->ts);

-- 
Alex Bligh

^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [Qemu-devel] [Qemu-stable] [PATCH 1/2] audio: honor QEMU_AUDIO_TIMER_PERIOD instead of waking up every *nano* second
  2013-12-03 21:17   ` Alex Bligh
@ 2013-12-03 22:00     ` Michael Roth
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Roth @ 2013-12-03 22:00 UTC (permalink / raw)
  To: Alex Bligh, Hans de Goede, malc; +Cc: Paolo Bonzini, qemu-devel, qemu-stable

Quoting Alex Bligh (2013-12-03 15:17:11)
> --On 3 December 2013 14:03:04 -0600 Michael Roth 
> <mdroth@linux.vnet.ibm.com> wrote:
> 
> >> Note this will not apply to 1.5 and 1.6 as is.
> >
> > What needs to be changed? Wouldn't this patch also restore the 250hz
> > frequency for 1.6, as it was pre-0.14?
> 
> The function names have changed as have the clock names.
> At a guess (cut and paste diff, completely untested), you
> need something like this:
> 
> diff --git a/audio/audio.c b/audio/audio.c
> index 02bb886..45d146e 100644
> --- a/audio/audio.c
> +++ b/audio/audio.c
> @@ -1124,7 +1124,8 @@ static int audio_is_timer_needed (void)
>  static void audio_reset_timer (AudioState *s)
>  {
>      if (audio_is_timer_needed ()) {
> -        qemu_mod_timer (s->ts, qemu_get_clock_ns (vm_clock) + 1);
> +        qemu_mod_timer (s->ts, qemu_get_clock_ns (vm_clock) +
> +                        conf.period.ticks);
>      }
>      else {
>          qemu_del_timer (s->ts);

Ah, thanks, this looks correct. Kept staring at 1.6/1.7 versions and wasn't
seeing a difference for some reason...

> 
> -- 
> Alex Bligh

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-12-03 22:00 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-09 19:42 [Qemu-devel] [PATCH 1/2] audio: honor QEMU_AUDIO_TIMER_PERIOD instead of waking up every *nano* second Hans de Goede
2013-10-09 19:42 ` [Qemu-devel] [PATCH 2/2] audio: Lower default wakeup rate to 100 times / second Hans de Goede
2013-10-10  6:31 ` [Qemu-devel] [PATCH 1/2] audio: honor QEMU_AUDIO_TIMER_PERIOD instead of waking up every *nano* second Alex Bligh
2013-10-10  6:58   ` Hans de Goede
2013-10-10  7:02     ` Alex Bligh
2013-10-10  9:23   ` Hans de Goede
2013-10-10  9:35     ` Paolo Bonzini
2013-12-03 20:03 ` [Qemu-devel] [Qemu-stable] " Michael Roth
2013-12-03 21:17   ` Alex Bligh
2013-12-03 22:00     ` Michael Roth

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).