From patchwork Mon Jun 25 08:29:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Brunet X-Patchwork-Id: 139813 Delivered-To: patch@linaro.org Received: by 2002:a2e:970d:0:0:0:0:0 with SMTP id r13-v6csp3710436lji; Mon, 25 Jun 2018 01:29:39 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcze8HAW2U+sLS/NUxmJCflBzdrBhBnbtHxPY0QvL6HfXiPzqSswCoByCXZWw8KE1qTrhZu X-Received: by 2002:a1c:894f:: with SMTP id l76-v6mr174775wmd.103.1529915379499; Mon, 25 Jun 2018 01:29:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529915379; cv=none; d=google.com; s=arc-20160816; b=oBMtFnbxUHedGckJBxCCLlGr746SdD9gZhXIWx9qUooT3nqdiAOqsY1rEiDN8BbgDg hChU2hjDL7bR5KnVVN1amil5FE2NHeN5cEH+MyD7bI0adyd2Tiijx5btTDBX25XV6zy9 exAV9nOvgdBLD6enwdVeG70hrqQIYQZBjA1rohBBAMNm+6sJYPs8K2uoaBhQmKtJDk7o 2nFzlLtdI0uE40F5PaS0tYJEfSbyct3VUtdxF9q9TplwCigD6jP+l/9uub19Nfcp9EM1 2vCdfkdgcat8OLS+PeJAwk8rVaZFj2XZnLLYR5tnhhKKis0sVSMAAhwZKOOPuH+ZKLdA YVFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:cc:message-id:date:to:from :dkim-signature:delivered-to:arc-authentication-results; bh=MDKaBYeS+y2hLsg0eBky9ngPPqneWLej8kBBacevNQg=; b=pfpyfAqXvtO5DIfTcGa34POyxrMRrnyyaBr8vJ+6d72+9O+kegkESRVHWAdWJGsQ5L ehBRdLwSVAzQGamDLCYSQGGcrS7Y/OkdkU39y8l9sEw+5AQVSKpViacYKvBJPZIU6RP8 YO/Knbw0Gbao3wkxeBK+eB3Z965KZ/Tu3HPfOjDvuFCLUlZauVre2BiK3Y9xA5BnKXRt njbcAW6SK6QUNIzAaYV6OUQaCEYSVhxNavXBJX2pDzrlIGukRHh7ztcbUmCQgCcOS/IP UfT1yl+Tt9xEleLMWErOoTYDCg6jekqiPH+Qcmv3nm6J8E7ntVPLxMb9odE64PgQkZhN CODQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=k5CxeZZL; spf=pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) smtp.mailfrom=alsa-devel-bounces@alsa-project.org Return-Path: Received: from alsa0.perex.cz (alsa0.perex.cz. [77.48.224.243]) by mx.google.com with ESMTP id m133-v6si7124700wma.134.2018.06.25.01.29.39; Mon, 25 Jun 2018 01:29:39 -0700 (PDT) Received-SPF: pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) client-ip=77.48.224.243; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@baylibre-com.20150623.gappssmtp.com header.s=20150623 header.b=k5CxeZZL; spf=pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 9340C267729; Mon, 25 Jun 2018 10:29:37 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id DC80E267730; Mon, 25 Jun 2018 10:29:34 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail1.perex.cz X-Spam-Level: * X-Spam-Status: No, score=1.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, PRX_BODY_30,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_SOFTFAIL,T_DKIMWL_WL_MED autolearn=disabled version=3.4.0 Received: from mail-wm0-f67.google.com (mail-wm0-f67.google.com [74.125.82.67]) by alsa0.perex.cz (Postfix) with ESMTP id 70A7A2675C8 for ; Mon, 25 Jun 2018 10:29:32 +0200 (CEST) Received: by mail-wm0-f67.google.com with SMTP id u18-v6so4442305wmc.1 for ; Mon, 25 Jun 2018 01:29:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=++TCHwl/guPvkMV1hf+DsB+4uPX30e9QVrZWiSpKN3s=; b=k5CxeZZLvF0JsvxpilbrH2zhJBl6YYRIMgjnjT60Io2ytkpyhR86zyug7IhkOMSzj7 EluTyMs31wN6XA6g9ZW+r0aMwCtA972bavAI//CybFXs3CE7cKejiyuH96uJHsoFFl0F tHn/oPg6Y062rbLM5GxHyjrZBibyNao6eepIbf9TxZ5IkIhzWDZZ/eUxAHCzY1745/8Z OoOY9D7me0lkFJMj3Jm0i10BNsop9WyFOYCp6KgGRmhNl89KsAK7XMoEUeS1eOAGXFXU vgnkYA6BDIEHacdxa8wU5vWSFL0Vperx/9Jlc4J85+0n9qzdxoXI41UeN7H0N3EXT6Ei REdA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=++TCHwl/guPvkMV1hf+DsB+4uPX30e9QVrZWiSpKN3s=; b=cQ4dKlTL0w7JDffQtV/dP2DNtNmcE1jYrjkGB65sxufmN2W8zykrekA1GapIrnwwiO oHHZi7ZCwCTtVCQSX0SVloM6Y1437M9NefpSnJ6C8NjmiT7QA+uuKCBP/9I9vWUbvoZ4 r0A8FdsicTCHAlc7X6RI/gIImQdXtGgiRUGq8IyzcijKkkreeQgGdeR1BaXeXSNJ4Kh9 P11rIKGeCko0fKMBN8j5Gt2AIKFbfM3H+WnzZS4WlkBDcRrzvFmJvS3DiweDJ/GWEI19 yevWSp1vJ/MsKEjADzpAc6DEilxqZEyWg3X1Yndc42tE06M/u2705aP624VoptC8y2yV E3Ew== X-Gm-Message-State: APt69E0XtFfgP4aHeL9dQ/KgWQpfQXaia9fSrxv20jRKEq8yiaxr0m0C z9zoV8FcuXYbfyMqWBJNOCTWaQ== X-Received: by 2002:a1c:9253:: with SMTP id u80-v6mr222956wmd.52.1529915371797; Mon, 25 Jun 2018 01:29:31 -0700 (PDT) Received: from boomer.baylibre.local ([90.63.244.31]) by smtp.googlemail.com with ESMTPSA id n17-v6sm12911855wmd.14.2018.06.25.01.29.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Jun 2018 01:29:31 -0700 (PDT) From: Jerome Brunet To: Liam Girdwood , Mark Brown Date: Mon, 25 Jun 2018 10:29:23 +0200 Message-Id: <20180625082923.25636-1-jbrunet@baylibre.com> X-Mailer: git-send-email 2.14.4 Cc: alsa-devel@alsa-project.org, linux-kernel@vger.kernel.org, Jerome Brunet Subject: [alsa-devel] [PATCH] ASoC: dpcm: improve runtime update predictability X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org As it is, dpcm_runtime_update() performs the old path and new path update of a frontend before going on to the next frontend DAI. Depending the order of the FEs within the rtd list, the result of the update might be different. For example: * Frontend A connected to backend C, with a 48kHz playback * Frontend B connected to backend D, with a 44.1kHz playback * FE A appears before FE B in the rtd list of the card. If we reparent BE C to FE B (disconnecting BE D): * old path update of FE A will run first, and BE C will get hw_free() and shutdown() * new path update of FE B will run after and BE C, which is stopped, so it will be configured at 44.1kHz, as expected If we reparent BE D to FE A (disconnecting BE C): * new path update of FE A will run first but since BE D is still running at 44.1kHz, it won't be reconfigured (no call to startup() or hw_params()) * old path update of FE B runs after, nothing happens * In this case, we end up with a BE playing at 44.1kHz a stream which is supposed to be played at 48Khz (too slow) To improve this situation, this patch performs all the FE old paths update before going on to update the new paths. With this, the result should no longer depend on the order of the FE within the card rtd list. Please note that there might be a small performance penalty since dpcm_process_paths() is called twice per stream direction. Signed-off-by: Jerome Brunet --- sound/soc/soc-pcm.c | 165 +++++++++++++++++++++++++++------------------------- 1 file changed, 86 insertions(+), 79 deletions(-) -- 2.14.4 _______________________________________________ Alsa-devel mailing list Alsa-devel@alsa-project.org http://mailman.alsa-project.org/mailman/listinfo/alsa-devel diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c index 5e7ae47a9658..5c2534414478 100644 --- a/sound/soc/soc-pcm.c +++ b/sound/soc/soc-pcm.c @@ -2543,106 +2543,113 @@ static int dpcm_run_old_update(struct snd_soc_pcm_runtime *fe, int stream) return ret; } -/* Called by DAPM mixer/mux changes to update audio routing between PCMs and - * any DAI links. - */ -int soc_dpcm_runtime_update(struct snd_soc_card *card) +int soc_dpcm_fe_runtime_update(struct snd_soc_pcm_runtime *fe, int new) { - struct snd_soc_pcm_runtime *fe; - int old, new, paths; + struct snd_soc_dapm_widget_list *list; + int count, paths; - mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_RUNTIME); - list_for_each_entry(fe, &card->rtd_list, list) { - struct snd_soc_dapm_widget_list *list; + if (!fe->dai_link->dynamic) + return 0; - /* make sure link is FE */ - if (!fe->dai_link->dynamic) - continue; + /* only check active links */ + if (!fe->cpu_dai->active) + return 0; - /* only check active links */ - if (!fe->cpu_dai->active) - continue; + /* DAPM sync will call this to update DSP paths */ + dev_dbg(fe->dev, "ASoC: DPCM %s runtime update for FE %s\n", + new ? "new" : "old", fe->dai_link->name); - /* DAPM sync will call this to update DSP paths */ - dev_dbg(fe->dev, "ASoC: DPCM runtime update for FE %s\n", - fe->dai_link->name); + /* skip if FE doesn't have playback capability */ + if (!fe->cpu_dai->driver->playback.channels_min || + !fe->codec_dai->driver->playback.channels_min) + goto capture; - /* skip if FE doesn't have playback capability */ - if (!fe->cpu_dai->driver->playback.channels_min - || !fe->codec_dai->driver->playback.channels_min) - goto capture; - - /* skip if FE isn't currently playing */ - if (!fe->cpu_dai->playback_active - || !fe->codec_dai->playback_active) - goto capture; - - paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_PLAYBACK, &list); - if (paths < 0) { - dev_warn(fe->dev, "ASoC: %s no valid %s path\n", - fe->dai_link->name, "playback"); - mutex_unlock(&card->mutex); - return paths; - } + /* skip if FE isn't currently playing */ + if (!fe->cpu_dai->playback_active || !fe->codec_dai->playback_active) + goto capture; - /* update any new playback paths */ - new = dpcm_process_paths(fe, SNDRV_PCM_STREAM_PLAYBACK, &list, 1); - if (new) { - dpcm_run_new_update(fe, SNDRV_PCM_STREAM_PLAYBACK); - dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_PLAYBACK); - dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_PLAYBACK); - } + paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_PLAYBACK, &list); + if (paths < 0) { + dev_warn(fe->dev, "ASoC: %s no valid %s path\n", + fe->dai_link->name, "playback"); + return paths; + } - /* update any old playback paths */ - old = dpcm_process_paths(fe, SNDRV_PCM_STREAM_PLAYBACK, &list, 0); - if (old) { + /* update any playback paths */ + count = dpcm_process_paths(fe, SNDRV_PCM_STREAM_PLAYBACK, &list, new); + if (count) { + if (new) + dpcm_run_new_update(fe, SNDRV_PCM_STREAM_PLAYBACK); + else dpcm_run_old_update(fe, SNDRV_PCM_STREAM_PLAYBACK); - dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_PLAYBACK); - dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_PLAYBACK); - } - dpcm_path_put(&list); + dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_PLAYBACK); + dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_PLAYBACK); + } + + dpcm_path_put(&list); + capture: - /* skip if FE doesn't have capture capability */ - if (!fe->cpu_dai->driver->capture.channels_min - || !fe->codec_dai->driver->capture.channels_min) - continue; + /* skip if FE doesn't have capture capability */ + if (!fe->cpu_dai->driver->capture.channels_min || + !fe->codec_dai->driver->capture.channels_min) + return 0; - /* skip if FE isn't currently capturing */ - if (!fe->cpu_dai->capture_active - || !fe->codec_dai->capture_active) - continue; + /* skip if FE isn't currently capturing */ + if (!fe->cpu_dai->capture_active || !fe->codec_dai->capture_active) + return 0; - paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_CAPTURE, &list); - if (paths < 0) { - dev_warn(fe->dev, "ASoC: %s no valid %s path\n", - fe->dai_link->name, "capture"); - mutex_unlock(&card->mutex); - return paths; - } + paths = dpcm_path_get(fe, SNDRV_PCM_STREAM_CAPTURE, &list); + if (paths < 0) { + dev_warn(fe->dev, "ASoC: %s no valid %s path\n", + fe->dai_link->name, "capture"); + return paths; + } - /* update any new capture paths */ - new = dpcm_process_paths(fe, SNDRV_PCM_STREAM_CAPTURE, &list, 1); - if (new) { + /* update any old capture paths */ + count = dpcm_process_paths(fe, SNDRV_PCM_STREAM_CAPTURE, &list, new); + if (count) { + if (new) dpcm_run_new_update(fe, SNDRV_PCM_STREAM_CAPTURE); - dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_CAPTURE); - dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_CAPTURE); - } - - /* update any old capture paths */ - old = dpcm_process_paths(fe, SNDRV_PCM_STREAM_CAPTURE, &list, 0); - if (old) { + else dpcm_run_old_update(fe, SNDRV_PCM_STREAM_CAPTURE); - dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_CAPTURE); - dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_CAPTURE); - } - dpcm_path_put(&list); + dpcm_clear_pending_state(fe, SNDRV_PCM_STREAM_CAPTURE); + dpcm_be_disconnect(fe, SNDRV_PCM_STREAM_CAPTURE); } - mutex_unlock(&card->mutex); + dpcm_path_put(&list); + return 0; } + +/* Called by DAPM mixer/mux changes to update audio routing between PCMs and + * any DAI links. + */ +int soc_dpcm_runtime_update(struct snd_soc_card *card) +{ + struct snd_soc_pcm_runtime *fe; + int ret = 0; + + mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_RUNTIME); + /* shutdown all old paths first */ + list_for_each_entry(fe, &card->rtd_list, list) { + ret = soc_dpcm_fe_runtime_update(fe, 0); + if (ret) + goto out; + } + + /* bring new paths up */ + list_for_each_entry(fe, &card->rtd_list, list) { + ret = soc_dpcm_fe_runtime_update(fe, 1); + if (ret) + goto out; + } + +out: + mutex_unlock(&card->mutex); + return ret; +} int soc_dpcm_be_digital_mute(struct snd_soc_pcm_runtime *fe, int mute) { struct snd_soc_dpcm *dpcm;