From patchwork Wed Sep 29 04:18:41 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: kbuild test robot X-Patchwork-Id: 66042 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E7302B7117 for ; Wed, 29 Sep 2010 14:21:13 +1000 (EST) Received: from localhost ([127.0.0.1]:38493 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P0oAH-00058x-NT for incoming@patchwork.ozlabs.org; Wed, 29 Sep 2010 00:21:09 -0400 Received: from [140.186.70.92] (port=49540 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P0o8X-0004Na-F0 for qemu-devel@nongnu.org; Wed, 29 Sep 2010 00:19:23 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1P0o86-0003ad-Mc for qemu-devel@nongnu.org; Wed, 29 Sep 2010 00:19:21 -0400 Received: from mga01.intel.com ([192.55.52.88]:57821) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1P0o86-0003aI-EF for qemu-devel@nongnu.org; Wed, 29 Sep 2010 00:18:54 -0400 Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 28 Sep 2010 21:18:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.57,251,1283756400"; d="scan'208";a="611432379" Received: from unknown (HELO localhost.localdomain) ([10.255.20.28]) by fmsmga002.fm.intel.com with ESMTP; 28 Sep 2010 21:18:44 -0700 Received: from wfg by localhost.localdomain with local (Exim 4.69) (envelope-from ) id 1P0o7t-0004Rn-6I; Wed, 29 Sep 2010 12:18:41 +0800 Date: Wed, 29 Sep 2010 12:18:41 +0800 From: Wu Fengguang To: malc Message-ID: <20100929041841.GA16868@localhost> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. Cc: "Anvin, H Peter" , qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH] pulse-audio: fix bug on updating rpos X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Signed-off-by: Wu Fengguang --- 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; }