From patchwork Mon May 15 08:41:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oswald Buddenhagen X-Patchwork-Id: 13240963 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 90E31C77B7D for ; Mon, 15 May 2023 08:42:38 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 7B0BC822; Mon, 15 May 2023 10:41:45 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 7B0BC822 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684140155; bh=GCjBjR6Wy4GKDSV/RsKMrw7IJIr1jrKGwN8maZkTeyA=; h=From:To:Cc:Subject:Date:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=iHI8YsNjKf80s4Fx5BEpcoZAybXlIHWDQJvXdhT4NfWo26IssIPePdkE3C5jlL14t nN5a4kOqpNN1VwsOz923JlaV0uv/ELh2nwmCPDDAl2bEj1DohP8a3OH4Vrd78tNytY dqG0rm9NLY+KRDZNqK6I3OyhV4HMREId13+edTD0= Received: by alsa1.perex.cz (Postfix, from userid 50401) id 64E63F80272; Mon, 15 May 2023 10:41:19 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 17705F802E8; Mon, 15 May 2023 10:41:19 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 7E4B4F80272; Mon, 15 May 2023 10:41:14 +0200 (CEST) Received: from bluemchen.kde.org (bluemchen.kde.org [209.51.188.41]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 6CD8FF8024E for ; Mon, 15 May 2023 10:41:09 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 6CD8FF8024E Received: from ugly.fritz.box (localhost [127.0.0.1]) by bluemchen.kde.org (Postfix) with ESMTP id F0FCA24060; Mon, 15 May 2023 04:41:06 -0400 (EDT) Received: by ugly.fritz.box (masqmail 0.3.4, from userid 1000) id 1pyTlS-StX-00; Mon, 15 May 2023 10:41:06 +0200 From: Oswald Buddenhagen To: alsa-devel@alsa-project.org Cc: Jaroslav Kysela , Takashi Iwai Subject: [PATCH 1/2] pcm: hw: reinterpret the drain_silence setting Date: Mon, 15 May 2023 10:41:05 +0200 Message-Id: <20230515084106.3447657-1-oswald.buddenhagen@gmx.de> X-Mailer: git-send-email 2.40.0.152.g15d061e6df MIME-Version: 1.0 Message-ID-Hash: JQEJ73KVE4WEKLSJ3ZVD5477RFB23Z6Q X-Message-ID-Hash: JQEJ73KVE4WEKLSJ3ZVD5477RFB23Z6Q X-MailFrom: ossi@kde.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: It makes no sense to have a config option which determines the entire silencing time, because useful values strongly depend on the period size runtime setting. So instead we interpret the setting as an override for the "overhang" which is used to compensate FIFOs and IRQ delays. The reasonable worst case of this is determined by the hardware, so it makes sense to have this as a config option. In a next step, we may want to derive the default value from the declared FIFO size (whiche few drivers do) and the minimal period size (which is generally linked to the FIFO size). Signed-off-by: Oswald Buddenhagen --- src/pcm/pcm_hw.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c index 8ffebed9..ecc47a76 100644 --- a/src/pcm/pcm_hw.c +++ b/src/pcm/pcm_hw.c @@ -737,18 +737,19 @@ static int snd_pcm_hw_drain(snd_pcm_t *pcm) { snd_pcm_hw_t *hw = pcm->private_data; snd_pcm_sw_params_t sw_params; + snd_pcm_uframes_t silence_slack; snd_pcm_uframes_t silence_size; int err; if (pcm->stream != SND_PCM_STREAM_PLAYBACK) goto __skip_silence; if (hw->drain_silence == 0 || hw->perfect_drain) goto __skip_silence; snd_pcm_sw_params_current_no_lock(pcm, &sw_params); - if (hw->drain_silence > 0) { - silence_size = (pcm->rate * hw->drain_silence) / 1000; - goto __manual_silence; - } + if (hw->drain_silence > 0) + silence_slack = (pcm->rate * hw->drain_silence) / 1000; + else + silence_slack = pcm->rate / 10; /* 1/10th of second */ /* compute end silence size, align to period size + extra time */ if ((pcm->boundary % pcm->period_size) == 0) { silence_size = pcm->period_size - (*pcm->appl.ptr % pcm->period_size); @@ -761,8 +762,7 @@ static int snd_pcm_hw_drain(snd_pcm_t *pcm) */ silence_size = pcm->period_size; } - silence_size += pcm->rate / 10; /* 1/10th of second */ -__manual_silence: + silence_size += silence_slack; if (sw_params.silence_size < silence_size) { /* fill the silence soon as possible (in the bellow ioctl * or the next period wake up) From patchwork Mon May 15 08:41:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oswald Buddenhagen X-Patchwork-Id: 13240964 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 77186C77B7D for ; Mon, 15 May 2023 08:43:03 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id E7E49836; Mon, 15 May 2023 10:42:10 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz E7E49836 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1684140181; bh=g87RweiRVYEUQN9Oo8a04W6MJeIdKddNLYZCLONeNys=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=kmJzFU6fIrSuDsT/t6sf4HnjCn8rWqaEXzZheWPdcxdtiIJ+5B326cixhUqn38m/P cp1nnAPG8UjUdh4khmbZenhqZ8q88AX90HwtX0qJHT4DWBKhCsUiH8th0BROhJ2cLr SKpzDGkrKJpHbUItiBy/uDOJbUO6uY0m4fDkuv0g= Received: by alsa1.perex.cz (Postfix, from userid 50401) id E387FF80553; Mon, 15 May 2023 10:41:21 +0200 (CEST) Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 876D4F80552; Mon, 15 May 2023 10:41:21 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id E13D4F80272; Mon, 15 May 2023 10:41:17 +0200 (CEST) Received: from bluemchen.kde.org (bluemchen.kde.org [IPv6:2001:470:142:8::100]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id BF1A0F8024E for ; Mon, 15 May 2023 10:41:14 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz BF1A0F8024E Received: from ugly.fritz.box (localhost [127.0.0.1]) by bluemchen.kde.org (Postfix) with ESMTP id 050E62424B; Mon, 15 May 2023 04:41:07 -0400 (EDT) Received: by ugly.fritz.box (masqmail 0.3.4, from userid 1000) id 1pyTlS-Std-00; Mon, 15 May 2023 10:41:06 +0200 From: Oswald Buddenhagen To: alsa-devel@alsa-project.org Cc: Jaroslav Kysela , Takashi Iwai Subject: [PATCH 2/2] pcm: hw: fix excessive silence fill on drain Date: Mon, 15 May 2023 10:41:06 +0200 Message-Id: <20230515084106.3447657-2-oswald.buddenhagen@gmx.de> X-Mailer: git-send-email 2.40.0.152.g15d061e6df In-Reply-To: <20230515084106.3447657-1-oswald.buddenhagen@gmx.de> References: <20230515084106.3447657-1-oswald.buddenhagen@gmx.de> MIME-Version: 1.0 Message-ID-Hash: RLIMAND3XSZAPWLMHN3MX3RNONQ772AI X-Message-ID-Hash: RLIMAND3XSZAPWLMHN3MX3RNONQ772AI X-MailFrom: ossi@kde.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: <> List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Setting the threshold to the size of the buffer results in additional filling each time a period elapses. As draining is usually initiated with a rather full buffer, this would usually result in filling way in excess of what was intended. A sufficient threshold is the required worst-case fill, that is, one period size plus the "overhang". Signed-off-by: Oswald Buddenhagen --- This patch is entirely untested! But it's derived from my previously posted v3 kernel patch, which was successfully tested. --- src/pcm/pcm_hw.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/pcm/pcm_hw.c b/src/pcm/pcm_hw.c index ecc47a76..a5f87215 100644 --- a/src/pcm/pcm_hw.c +++ b/src/pcm/pcm_hw.c @@ -764,12 +764,11 @@ static int snd_pcm_hw_drain(snd_pcm_t *pcm) } silence_size += silence_slack; if (sw_params.silence_size < silence_size) { - /* fill the silence soon as possible (in the bellow ioctl - * or the next period wake up) - */ - sw_params.silence_threshold = pcm->buffer_size; - if (silence_size > pcm->buffer_size) - silence_size = pcm->buffer_size; + sw_params.silence_threshold = pcm->period_size + silence_slack; + if (sw_params.silence_threshold > pcm->buffer_size) + sw_params.silence_threshold = pcm->buffer_size; + if (silence_size > sw_params.silence_threshold) + silence_size = sw_params.silence_threshold; sw_params.silence_size = silence_size; if (ioctl(hw->fd, SNDRV_PCM_IOCTL_SW_PARAMS, &sw_params) < 0) { err = -errno;