From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 84F79C433E2 for ; Fri, 15 May 2020 07:22:15 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E42652065F for ; Fri, 15 May 2020 07:22:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="YSxnHt2W" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E42652065F Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 374521655; Fri, 15 May 2020 09:21:23 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 374521655 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1589527333; bh=Pm8sUSkOd5fbLB3ESsCstYH3fzoUjLYkmzCbVN2PCuc=; h=Date:From:To:Subject:In-Reply-To:References:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=YSxnHt2WIQTDfeVyq8kp+k9b0o0M5ADH7Pyuhox9z+3SQINZ2Zmr5y2fupLbrGrts KZK/4OYiqetqzkHAzS1AauqLgVWnI2hreWdQ9SfSDUGWBV2JylO6XB43Hxs4EGY9tI E2gamAAKizO2a1ZsYZT0BlVISi3NnX1plePAw+AU= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id A17D2F8022D; Fri, 15 May 2020 09:21:22 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 54D78F800E3; Fri, 15 May 2020 09:21:21 +0200 (CEST) Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id DE873F800E3 for ; Fri, 15 May 2020 09:21:14 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz DE873F800E3 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 3553AACC5; Fri, 15 May 2020 07:21:14 +0000 (UTC) Date: Fri, 15 May 2020 09:21:10 +0200 Message-ID: From: Takashi Iwai To: Brent Lu Subject: Re: [PATCH] ALSA: pcm: fix incorrect hw_base increase In-Reply-To: <1589515779-20987-1-git-send-email-brent.lu@intel.com> References: <1589515779-20987-1-git-send-email-brent.lu@intel.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Cc: alsa-devel@alsa-project.org, Arnd Bergmann , Baolin Wang , Greg Kroah-Hartman , Takashi Iwai , Richard Fontana , Thomas Gleixner , paulhsia , linux-kernel@vger.kernel.org X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" On Fri, 15 May 2020 06:09:39 +0200, Brent Lu wrote: > > The hw_base will be increased by runtime->buffer_size frames > unconditionally if the runtime->status->hw_ptr is not updated for over > half of buffer time. As the hw_base increases, so does the > runtime->status->hw_ptr which could lead to invalid return value when > user space program calls snd_pcm_avail() function. > > By updating runtime->hw_ptr_jiffies each time the HWSYNC is called, > the hw_base will keep the same when buffer stall happens, so does the > hw_ptr. Updating hw_ptr_jiffies at that code path looks correct, but it still leaves the question why this condition happens. It means that the actual hwptr isn't changed and yet only jiffies increase significantly; it means that the hardware can't report proper pointer, and it should have set SNDRV_PCM_INFO_BATCH flag, then the jiffies check is skipped. With which hardware and under which situation did it happen (and the patch fixed)? thanks, Takashi > > Signed-off-by: Brent Lu > --- > sound/core/pcm_lib.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c > index 872a852..d531e1b 100644 > --- a/sound/core/pcm_lib.c > +++ b/sound/core/pcm_lib.c > @@ -433,6 +433,7 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream, > > no_delta_check: > if (runtime->status->hw_ptr == new_hw_ptr) { > + runtime->hw_ptr_jiffies = curr_jiffies; > update_audio_tstamp(substream, &curr_tstamp, &audio_tstamp); > return 0; > } > -- > 2.7.4 > From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 20F35C433DF for ; Fri, 15 May 2020 07:21:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ED7662065F for ; Fri, 15 May 2020 07:21:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726645AbgEOHVN (ORCPT ); Fri, 15 May 2020 03:21:13 -0400 Received: from mx2.suse.de ([195.135.220.15]:49682 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726496AbgEOHVM (ORCPT ); Fri, 15 May 2020 03:21:12 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 3553AACC5; Fri, 15 May 2020 07:21:14 +0000 (UTC) Date: Fri, 15 May 2020 09:21:10 +0200 Message-ID: From: Takashi Iwai To: Brent Lu Cc: , Jaroslav Kysela , Takashi Iwai , Baolin Wang , Arnd Bergmann , Greg Kroah-Hartman , Richard Fontana , Thomas Gleixner , paulhsia , Subject: Re: [PATCH] ALSA: pcm: fix incorrect hw_base increase In-Reply-To: <1589515779-20987-1-git-send-email-brent.lu@intel.com> References: <1589515779-20987-1-git-send-email-brent.lu@intel.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI/1.14.6 (Maruoka) FLIM/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL/10.8 Emacs/25.3 (x86_64-suse-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 15 May 2020 06:09:39 +0200, Brent Lu wrote: > > The hw_base will be increased by runtime->buffer_size frames > unconditionally if the runtime->status->hw_ptr is not updated for over > half of buffer time. As the hw_base increases, so does the > runtime->status->hw_ptr which could lead to invalid return value when > user space program calls snd_pcm_avail() function. > > By updating runtime->hw_ptr_jiffies each time the HWSYNC is called, > the hw_base will keep the same when buffer stall happens, so does the > hw_ptr. Updating hw_ptr_jiffies at that code path looks correct, but it still leaves the question why this condition happens. It means that the actual hwptr isn't changed and yet only jiffies increase significantly; it means that the hardware can't report proper pointer, and it should have set SNDRV_PCM_INFO_BATCH flag, then the jiffies check is skipped. With which hardware and under which situation did it happen (and the patch fixed)? thanks, Takashi > > Signed-off-by: Brent Lu > --- > sound/core/pcm_lib.c | 1 + > 1 file changed, 1 insertion(+) > > diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c > index 872a852..d531e1b 100644 > --- a/sound/core/pcm_lib.c > +++ b/sound/core/pcm_lib.c > @@ -433,6 +433,7 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream, > > no_delta_check: > if (runtime->status->hw_ptr == new_hw_ptr) { > + runtime->hw_ptr_jiffies = curr_jiffies; > update_audio_tstamp(substream, &curr_tstamp, &audio_tstamp); > return 0; > } > -- > 2.7.4 >