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 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 2186DC433F5 for ; Thu, 7 Apr 2022 13:58:33 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 24C971786; Thu, 7 Apr 2022 15:57:41 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 24C971786 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1649339911; bh=kk7NhQcAK/XdGiF/LKoqPfZ505ncylyO6/swBP7AGTM=; h=Date:Subject:To:References:From:In-Reply-To:Cc:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=JAiIQ8BPnGtacCGPcxk/oFYlPI0YZ0yUBpbFLM5LPan4yi8MYF4eqldhNb4/X8tsG e0K3G8muLkUev9sP+IDiyiLXuLcIQYrtmKxz/DoBgFm9mnMuyh/w4Y9LfZhJKOI6xA VADIK6I3o+W3ejvjDlTh08/Fb7Fil+AuVr/de1vs= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id B1A8DF80085; Thu, 7 Apr 2022 15:57:40 +0200 (CEST) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 09F9BF8024C; Thu, 7 Apr 2022 15:57:40 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 3F7B7F80085 for ; Thu, 7 Apr 2022 15:57:35 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 3F7B7F80085 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="Urabs4A7" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649339857; x=1680875857; h=message-id:date:mime-version:subject:to:cc:references: from:in-reply-to:content-transfer-encoding; bh=kk7NhQcAK/XdGiF/LKoqPfZ505ncylyO6/swBP7AGTM=; b=Urabs4A7i3TKJWAq2PTtPFnj13dzbr9QV02eRCsu48dFltUYtiBJj6n8 EmkBRMsf20ND8Tokhs4TVt0ZmfgDmHKwp7Tj3CFpLBBF3jttEmfpLHYg5 v5ktH7daDOGKTNKca2x7ic+dHvjEQjdq3jhsFU6L5Wm/388f8syrx44wV mvLvP61shqDg0qU7RTZkeJf0TvI2/Z+cH01Ae1FEKjDLsl+PlXp8qUDLG JgQMTKS4j+rrgNNVml3GpWsGywHH4by96tT5TSuVoJUzgx+qrKSiT7Vyp UCrygW6aFBJZZmbK3qAcOl3/67XNSBk7z6E1kzRUILCuKUpEO5dCfYNZd g==; X-IronPort-AV: E=McAfee;i="6400,9594,10309"; a="261320101" X-IronPort-AV: E=Sophos;i="5.90,242,1643702400"; d="scan'208";a="261320101" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 06:57:32 -0700 X-IronPort-AV: E=Sophos;i="5.90,242,1643702400"; d="scan'208";a="524373853" Received: from achordiy-mobl.amr.corp.intel.com (HELO [10.209.88.227]) ([10.209.88.227]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 06:57:31 -0700 Message-ID: Date: Thu, 7 Apr 2022 08:23:54 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0 Thunderbird/91.5.0 Subject: Re: [PATCH 1/2] ASoC: soc-pcm: improve BE transition for PAUSE_RELEASE Content-Language: en-US To: =?UTF-8?Q?Amadeusz_S=c5=82awi=c5=84ski?= , alsa-devel@alsa-project.org References: <20220406190056.233481-1-pierre-louis.bossart@linux.intel.com> <20220406190056.233481-2-pierre-louis.bossart@linux.intel.com> From: Pierre-Louis Bossart In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Cc: tiwai@suse.de, Bard Liao , Ranjani Sridharan , Rander Wang , broonie@kernel.org, =?UTF-8?Q?P=c3=a9ter_Ujfalusi?= X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" >> diff --git a/include/sound/soc-dpcm.h b/include/sound/soc-dpcm.h >> index 75b92d883976..5b689c663290 100644 >> --- a/include/sound/soc-dpcm.h >> +++ b/include/sound/soc-dpcm.h >> @@ -103,6 +103,8 @@ struct snd_soc_dpcm_runtime { >>       int trigger_pending; /* trigger cmd + 1 if pending, 0 if not */ >>       int be_start; /* refcount protected by BE stream pcm lock */ >> +    int be_pause; /* refcount protected by BE stream pcm lock */ >> +    bool fe_pause; /* used to track STOP after PAUSE */ >>   }; >>   #define for_each_dpcm_fe(be, stream, _dpcm)                \ >> diff --git a/sound/soc/soc-pcm.c b/sound/soc/soc-pcm.c >> index 11c9853e9e80..e8700dd1839f 100644 >> --- a/sound/soc/soc-pcm.c >> +++ b/sound/soc/soc-pcm.c >> @@ -2090,6 +2090,7 @@ int dpcm_be_dai_trigger(struct >> snd_soc_pcm_runtime *fe, int stream, >>                      int cmd) >>   { >>       struct snd_soc_pcm_runtime *be; >> +    bool pause_stop_transition; >>       struct snd_soc_dpcm *dpcm; >>       unsigned long flags; >>       int ret = 0; >> @@ -2148,10 +2149,12 @@ int dpcm_be_dai_trigger(struct >> snd_soc_pcm_runtime *fe, int stream, >>           case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: >>               if (!be->dpcm[stream].be_start && >>                   (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START) && >> -                (be->dpcm[stream].state != SND_SOC_DPCM_STATE_STOP) && >>                   (be->dpcm[stream].state != SND_SOC_DPCM_STATE_PAUSED)) >>                   goto next; >> +            fe->dpcm[stream].fe_pause = false; >> +            be->dpcm[stream].be_pause--; >> + >>               be->dpcm[stream].be_start++; >>               if (be->dpcm[stream].be_start != 1) >>                   goto next; >> @@ -2175,14 +2178,33 @@ int dpcm_be_dai_trigger(struct >> snd_soc_pcm_runtime *fe, int stream, >>               if (be->dpcm[stream].be_start != 0) >>                   goto next; >> -            ret = soc_pcm_trigger(be_substream, cmd); >> +            pause_stop_transition = false; >> +            if (fe->dpcm[stream].fe_pause) { > > As you access fe here anyway, any chance something like > if (fe->dpcm[stream].state == SND_SOC_DPCM_STATE_PAUSED) > can be used here instead of adding fe_pause to snd_soc_dpcm_runtime? I didn't want to make any assumption on whether the state of the FE is updated before or after the BE state, depending on the trigger order, so only used the trigger command to drive the state machine changes. >> +                pause_stop_transition = true; >> +                fe->dpcm[stream].fe_pause = false; >> +                be->dpcm[stream].be_pause--; >> +            } >> + >> +            if (be->dpcm[stream].be_pause != 0) >> +                ret = soc_pcm_trigger(be_substream, >> SNDRV_PCM_TRIGGER_PAUSE_PUSH); >> +            else >> +                ret = soc_pcm_trigger(be_substream, >> SNDRV_PCM_TRIGGER_STOP); >> + >>               if (ret) { >>                   if (be->dpcm[stream].state == SND_SOC_DPCM_STATE_START) >>                       be->dpcm[stream].be_start++; >> +                if (pause_stop_transition) { >> +                    fe->dpcm[stream].fe_pause = true; >> +                    be->dpcm[stream].be_pause++; >> +                } >>                   goto next; >>               } >> -            be->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP; >> +            if (be->dpcm[stream].be_pause != 0) >> +                be->dpcm[stream].state = SND_SOC_DPCM_STATE_PAUSED; >> +            else >> +                be->dpcm[stream].state = SND_SOC_DPCM_STATE_STOP; >> + >>               break; >>           case SNDRV_PCM_TRIGGER_SUSPEND: >>               if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START) >> @@ -2204,6 +2226,9 @@ int dpcm_be_dai_trigger(struct >> snd_soc_pcm_runtime *fe, int stream, >>               if (be->dpcm[stream].state != SND_SOC_DPCM_STATE_START) >>                   goto next; >> +            fe->dpcm[stream].fe_pause = true; >> +            be->dpcm[stream].be_pause++; >> + >>               be->dpcm[stream].be_start--; >>               if (be->dpcm[stream].be_start != 0) >>                   goto next; >