Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp396586ybk; Fri, 15 May 2020 03:41:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxQONLqF7DGZCPeluumE0E3tPGWdg3a6xsf1sEIv/WvP4i8oY+dA0n0lkn1StylBhi453uV X-Received: by 2002:a17:906:f91:: with SMTP id q17mr2084922ejj.7.1589539316188; Fri, 15 May 2020 03:41:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589539316; cv=none; d=google.com; s=arc-20160816; b=scfrgiavrsWPCKjHwlTgFCIM/tgXccjqSmqFAPRTQcRTbQ01gN/gBZr7770QuW3Sc2 YDhX32z31mqdKGDvB0QlRomYdbe2ZkJAgDh9UxmpCm6Bi3ltHlyQSX7UYGZWszUJMbSs /WcC+c3sLQwKHRErzQElr96n8iC71CtP74PYn+rE3ocQwTOYJFFUTgp+Rkx9a3R57oIF fr8Ydpnv5gcKcE8Iysom81xg9gZ11Htrpv3SXA9gTIe/JasAlMg0Ysjawg2UjE56Ppt5 P5aJYw3wwqTBMdynUQA55oxo3xA6bd6KqHjPQoZF/v2c1C+/ocOg93Yg0ZDiN0QEe0YJ 9qRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:subject:cc:to:from:message-id:date; bh=T/7Eqz/PNdMsrlYv9VJXlQt0ildQAEZD2z6jFlsMM5I=; b=bN0pmXeyIx2tbAhVxWGg0PLlV9C71uIphuVGI9M9g19Yvn82QHDXDpiYvdhXDWlzW4 Mimws+sEebn1ksNiOm91kEoeFtJfVS9qged9ySSXQsXC1U9zX3ISZkAjAZsawAs4TxE5 DcwaoTm5C2MKzgjWbYEhe/I76VWzzfy7RU1BRkpW+burBw8qTJ3JERfA4fto48tmvnFp bfM0cgHG6WDD/CXFbyqKPfI9S9KT3d+E5Qm1v7naiP4onqzi4JX5VjGES92Ck1t8z0sg RggQIvc5j/fRboam+mxyCB9qTVsOzZaxmIUsnHPSCrQbi8iwigHRunYnEQaLGWeQFDWo xXjA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u13si973064edb.6.2020.05.15.03.41.32; Fri, 15 May 2020 03:41:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728209AbgEOKjf (ORCPT + 99 others); Fri, 15 May 2020 06:39:35 -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