Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8985FC433F5 for ; Fri, 19 Nov 2021 09:13:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 69F87611C0 for ; Fri, 19 Nov 2021 09:13:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233650AbhKSJQ5 (ORCPT ); Fri, 19 Nov 2021 04:16:57 -0500 Received: from smtp-out1.suse.de ([195.135.220.28]:54348 "EHLO smtp-out1.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232142AbhKSJQ4 (ORCPT ); Fri, 19 Nov 2021 04:16:56 -0500 Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out1.suse.de (Postfix) with ESMTP id 77D59212CB; Fri, 19 Nov 2021 09:13:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1637313234; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=p0FNsmCu12CGcSBrgmxCSHp4VXVsKt9zdX96iTqQRP0=; b=I/KjU/zD+rCIJJIJVm1qWcDclv/jKgwKet5yKG89+jBrLh274YbJsnr8+5Z4Ju7rnKqr1R 3VDidKmxLcwjb821M9hZDVRbn6v/ih2MVq45ki3GqgcWVL1zl42IB5nW+UHwxJg06qjyiS w1h9V5PjsFKjMZPvMdL0n2FbWkA+jpk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1637313234; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=p0FNsmCu12CGcSBrgmxCSHp4VXVsKt9zdX96iTqQRP0=; b=FKv7advt4OblXUHbFpDJQtYsAccAWyYfZcSm7vJ505LAX6X4SkY4kdJj79ca2rYg4qxlUz 4rMbtbPietwsRECg== Received: from alsa1.suse.de (alsa1.suse.de [10.160.4.42]) by relay2.suse.de (Postfix) with ESMTP id 68DB9A3B84; Fri, 19 Nov 2021 09:13:54 +0000 (UTC) Date: Fri, 19 Nov 2021 10:13:54 +0100 Message-ID: From: Takashi Iwai To: "Kirill A. Shutemov" Cc: Takashi Iwai , Linus Torvalds , Mark Brown , Liam Girdwood , Linux Kernel Mailing List Subject: Re: [GIT PULL] sound updates for 5.16-rc1 In-Reply-To: <20211118232628.hynb5vy6phsqj5oi@box.shutemov.name> References: <20211117161855.m45mxcqszkfcetai@box.shutemov.name> <20211117174826.23eakoivl33tawb2@box.shutemov.name> <20211118232628.hynb5vy6phsqj5oi@box.shutemov.name> 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: multipart/mixed; boundary="Multipart_Fri_Nov_19_10:13:54_2021-1" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --Multipart_Fri_Nov_19_10:13:54_2021-1 Content-Type: text/plain; charset=US-ASCII On Fri, 19 Nov 2021 00:26:28 +0100, Kirill A. Shutemov wrote: > > On Thu, Nov 18, 2021 at 05:57:35PM +0100, Takashi Iwai wrote: > > And it'd be helpful if you can gather the log (from tracing) with the > > patch below (from the start of speaker-test until the stall). > > The trace is attached. Thanks! From the previous log, I noticed that you're using dmix plugin, and that was the problem. The dmix plugin changes the PCM sw_params parameters at a late stage, and this confused the driver as if it were OK with the low-latency mode. And, while reviewing the code, I also found another bug. Below are two fix patches. Please give it a try. Takashi --Multipart_Fri_Nov_19_10:13:54_2021-1 Content-Type: application/octet-stream; type=patch Content-Disposition: attachment; filename="0001-ALSA-usb-audio-Switch-back-to-non-latency-mode-at-a-.patch" Content-Transfer-Encoding: 7bit From 4b9f4f8e236ef3b40ca4f3e0e59f6e094d090d59 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 19 Nov 2021 10:04:49 +0100 Subject: [PATCH 1/2] ALSA: usb-audio: Switch back to non-latency mode at a later point The recent regression report revealed that the judgment of the low-latency playback mode based on the runtime->stop_threshold cannot work reliably at the prepare stage, as sw_params call may happen at any time, and PCM dmix actually sets it up after the prepare call. This ended up with the stall of the stream as PCM ack won't be issued at all. For addressing this, check the free-wheeling mode again at the PCM trigger right before starting the stream again, and allow switching to the non-LL mode at a late stage. Fixes: d5f871f89e21 ("ALSA: usb-audio: Improved lowlatency playback support") Reported-by: Kirill A. Shutemov Signed-off-by: Takashi Iwai --- sound/usb/pcm.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c index 95ec8eec1bb0..57b046e73bfe 100644 --- a/sound/usb/pcm.c +++ b/sound/usb/pcm.c @@ -581,6 +581,12 @@ static int snd_usb_hw_free(struct snd_pcm_substream *substream) return 0; } +/* free-wheeling mode? (e.g. dmix) */ +static int in_free_wheeling_mode(struct snd_pcm_runtime *runtime) +{ + return runtime->stop_threshold > runtime->buffer_size; +} + /* check whether early start is needed for playback stream */ static int lowlatency_playback_available(struct snd_pcm_runtime *runtime, struct snd_usb_substream *subs) @@ -592,8 +598,7 @@ static int lowlatency_playback_available(struct snd_pcm_runtime *runtime, /* disabled via module option? */ if (!chip->lowlatency) return false; - /* free-wheeling mode? (e.g. dmix) */ - if (runtime->stop_threshold > runtime->buffer_size) + if (in_free_wheeling_mode(runtime)) return false; /* implicit feedback mode has own operation mode */ if (snd_usb_endpoint_implicit_feedback_sink(subs->data_endpoint)) @@ -1552,6 +1557,8 @@ static int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substrea subs); if (subs->lowlatency_playback && cmd == SNDRV_PCM_TRIGGER_START) { + if (in_free_wheeling_mode(substream->runtime)) + subs->lowlatency_playback = false; err = start_endpoints(subs); if (err < 0) { snd_usb_endpoint_set_callback(subs->data_endpoint, -- 2.31.1 --Multipart_Fri_Nov_19_10:13:54_2021-1 Content-Type: application/octet-stream; type=patch Content-Disposition: attachment; filename="0002-ALSA-usb-audio-Don-t-start-stream-for-capture-at-pre.patch" Content-Transfer-Encoding: 7bit From 2eeb527a4f3481452fd00263d8cee99d5297178a Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 19 Nov 2021 10:02:42 +0100 Subject: [PATCH 2/2] ALSA: usb-audio: Don't start stream for capture at prepare The recent change made mistakenly the stream for capture started at prepare stage. Add the stream direction check to avoid it. Fixes: 9c9a3b9da891 ("ALSA: usb-audio: Rename early_playback_start flag with lowlatency_playback") Signed-off-by: Takashi Iwai --- sound/usb/pcm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c index 57b046e73bfe..cec6e91afea2 100644 --- a/sound/usb/pcm.c +++ b/sound/usb/pcm.c @@ -640,7 +640,8 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream) runtime->delay = 0; subs->lowlatency_playback = lowlatency_playback_available(runtime, subs); - if (!subs->lowlatency_playback) + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && + !subs->lowlatency_playback) ret = start_endpoints(subs); unlock: -- 2.31.1 --Multipart_Fri_Nov_19_10:13:54_2021-1--