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=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 1C285C433DF for ; Fri, 15 May 2020 10:39:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E9FDC2065C for ; Fri, 15 May 2020 10:39:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728219AbgEOKjg (ORCPT ); Fri, 15 May 2020 06:39:36 -0400 Received: from mx2.suse.de ([195.135.220.15]:46016 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728013AbgEOKjf (ORCPT ); Fri, 15 May 2020 06:39:35 -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 D4CD4AC5F; Fri, 15 May 2020 10:39:35 +0000 (UTC) Date: Fri, 15 May 2020 12:39:32 +0200 Message-ID: From: Takashi Iwai To: Jaroslav Kysela Cc: "Lu, Brent" , Greg Kroah-Hartman , "alsa-devel@alsa-project.org" , Takashi Iwai , Baolin Wang , Arnd Bergmann , Richard Fontana , Thomas Gleixner , paulhsia , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH] ALSA: pcm: fix incorrect hw_base increase In-Reply-To: References: <1589515779-20987-1-git-send-email-brent.lu@intel.com> <20200515070446.GA1226131@kroah.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 11:30:54 +0200, Jaroslav Kysela wrote: > > Dne 15. 05. 20 v 11:04 Lu, Brent napsal(a): > >> > >> Is this a bugfix needed for older kernels as well? When did this issue show > >> up? > >> > >> thanks, > >> > >> greg k-h > > > > It happens when DMA stop moving data from host to DSP/DAI for a long time > > (> half of buffer time). I know host driver should do something about it. But if > > not, the HWSYNC will keep increasing the hw_base and hw_ptr and confuses > > user space program. > > I'm afraid, but with this code, you turn off the hw_ptr jiffies > code. It would be better to fix the driver in this case (return the > updated / estimated DMA pointer, increase DMA buffer size etc.). This > "lag" is unacceptable. The problem is obviously in the driver's side and it's best to be addressed there. But, I think it's still worth to apply this change. The hw_ptr jiffies check is performed basically in two places: one is snd_pcm_period_elapsed() call from ISR, and another is with the no_period_wakeup flag. In both cases, it calculates the diff of jiffies from the previous update, and corrects the hw_ptr_base if that exceeds the threshold. And the bug here is that the "previous" jiffies is kept as long as the hwptr itself is updated. What we need is the correction of the base when it really has processed the period size; i.e. hwptr got the same value (with no_period_wakeup) and yet the jiffies diff is big. For this check, it's correct to update hw_ptr_jiffies at each call no matter whether hwptr moved or not; we need to evaluate from the previous update, after all. But I might overlook something. Jaroslav, could you check it again? The jiffies check code is your black magic :) thanks, Takashi