From: Takashi Iwai Subject: Re: Application hangs with different period sizes Date: Fri, 08 Aug 2008 08:18:24 +0200 Message-ID: References: <2ee9e08d0807030019i1442729cyd241d72074791077@mail.gmail.com> <486CBAE9.60203@tet.com.br> <2ee9e08d0807030554t259c3b79x9023d901408a36e7@mail.gmail.com> <486CCD83.4040408@tet.com.br> <2ee9e08d0807030641g15a14349o8cce5a029f555132@mail.gmail.com> <486CF0B6.7090004@tet.com.br> <2ee9e08d0808070318s7cc6c971ibae1e9b6e5e179f8@mail.gmail.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx1.suse.de (cantor.suse.de [195.135.220.2]) by alsa0.perex.cz (Postfix) with ESMTP id D2A3224716 for ; Fri, 8 Aug 2008 08:18:26 +0200 (CEST) In-Reply-To: <2ee9e08d0808070318s7cc6c971ibae1e9b6e5e179f8@mail.gmail.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: alsa-devel-bounces@alsa-project.org Errors-To: alsa-devel-bounces@alsa-project.org To: anuj aggarwal Cc: alsa-devel@alsa-project.org, Gustavo da Silva Serra List-Id: alsa-devel@alsa-project.org At Thu, 7 Aug 2008 15:48:49 +0530, anuj aggarwal wrote: > > Hi, > > Regarding the below mentioned problem, we added some debugging in ALSA layer > and our audio codec driver to understand the problem. And I think, we > understand the root cause of the issue. > Whenever we call *snd_pcm_writei* function from application, it executes > kernel function *snd_pcm_lib_write1* from sound/core/pcm_lib.c. This > function copies the user buffer and updates some alsa variables > and trigger the DMA ( if alsa is in PREPARED state). And same thing is > done in snd_pcm_readi() function call. > > In case of DMA transfer, the DMA callback will update the hw_ptr depending > on the number of bytes xfered. So now two functions are updating the hw_ptr > (DMA callback and write/read function) and this is the problem. Only DMA > callback should update the hw_ptr because DMA is the one who is doing the > real transfer, not the write/read function. Read and write function should > only update the appl_ptr and leave the hw_ptr for DMA callback. > > After applying the below patch, my application works fine. Can someone look > into the patch provided below and confirm our understanding? The hw_ptr can be updated at any time. It can be updated at hwsync or other calls, too. And, the update is protected via a substream lock, it's no racy. I guess your problem is the implementation of pointer callback. The update of hw_ptr purely depends on the value returned from the pointer callback. Or, the driver assumes wrongly about the handling of hw_ptr... Takashi