qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Wu Fengguang <fengguang.wu@intel.com>
To: malc <av1474@comtv.ru>
Cc: "Anvin, H Peter" <h.peter.anvin@intel.com>, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] pulse-audio: fix bug on updating rpos
Date: Wed, 29 Sep 2010 12:18:41 +0800	[thread overview]
Message-ID: <20100929041841.GA16868@localhost> (raw)

Fix a rpos coordination bug between qpa_run_out() and qpa_thread_out(),
which shows up as playback noises.

	qpa_run_out()
			qpa_thread_out loop N critical section 1
	qpa_run_out()   qpa_thread_out loop N doing pa_simple_write()
	qpa_run_out()	qpa_thread_out loop N doing pa_simple_write()
			qpa_thread_out loop N critical section 2
			qpa_thread_out loop N+1 critical section 1
	qpa_run_out()	qpa_thread_out loop N+1 doing pa_simple_write()

In the above scheme, "qpa_thread_out loop N+1 critical section 1" will
get the same rpos as the one used by "qpa_thread_out loop N critical
section 1". So it will be reading dead samples from the old rpos.

The rpos can only be updated back to qpa_thread_out when there is a
qpa_run_out() run between two qpa_thread_out loops.

normal sequence:
	qpa_thread_out:
			hw->rpos (X0) => local rpos => pa->rpos (X1)
	qpa_run_out:
			pa->rpos (X1) => hw->rpos (X1)
	qpa_thread_out:
			hw->rpos (X1) => local rpos => pa->rpos (X2)

buggy sequence:
	qpa_thread_out:
			hw->rpos (X0) => local rpos => pa->rpos (X1)
	qpa_thread_out:
			hw->rpos (X0) => local rpos => pa->rpos (X1')

Obviously qpa_run_out() shall be called at least once between any two
qpa_thread_out loops (after pa->rpos is set), in order for the new
qpa_thread_out loop to see the updated rpos.

Setting pa->live to 0 does the trick. The next loop will have to wait
for one qpa_run_out() invocation in order to get a non-zero pa->live
and proceed.

Signed-off-by: malc <av1474@comtv.ru>
Signed-off-by: Wu Fengguang <fengguang.wu@intel.com>
---
 audio/paaudio.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--- qemu-kvm.orig/audio/paaudio.c	2010-09-29 10:28:25.000000000 +0800
+++ qemu-kvm/audio/paaudio.c	2010-09-29 12:11:45.000000000 +0800
@@ -111,8 +111,8 @@ static void *qpa_thread_out (void *arg)
             return NULL;
         }
 
+        pa->live = 0;
         pa->rpos = rpos;
-        pa->live -= decr;
         pa->decr += decr;
     }
 

             reply	other threads:[~2010-09-29  4:19 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-09-29  4:18 Wu Fengguang [this message]
2010-09-29  4:25 ` [Qemu-devel] Re: [PATCH] pulse-audio: fix bug on updating rpos malc

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=20100929041841.GA16868@localhost \
    --to=fengguang.wu@intel.com \
    --cc=av1474@comtv.ru \
    --cc=h.peter.anvin@intel.com \
    --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).