Linux Sound subsystem development
 help / color / mirror / Atom feed
From: "Péter Ujfalusi" <peter.ujfalusi@linux.intel.com>
To: Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.de>
Cc: lgirdwood@gmail.com, broonie@kernel.org, tiwai@suse.com,
	linux-sound@vger.kernel.org, kai.vehmanen@linux.intel.com,
	ranjani.sridharan@linux.intel.com,
	yung-chuan.liao@linux.intel.com, pierre-louis.bossart@linux.dev,
	liam.r.girdwood@intel.com
Subject: Re: [PATCH] ALSA: pcm: Release paused streams before suspend if resume is not supported
Date: Tue, 8 Apr 2025 10:03:46 +0300	[thread overview]
Message-ID: <d084dff6-6a25-4f84-879c-15c108c9c141@linux.intel.com> (raw)
In-Reply-To: <b9d457b9-4645-4876-b6a1-82bb658a3b8f@perex.cz>



On 03/04/2025 22:05, Jaroslav Kysela wrote:
> On 03. 04. 25 18:09, Takashi Iwai wrote:
> 
>> Last but not least, the ASoC PCM core has its own DPCM state, and the
>> trigger-SUSPEND skips the operation unless the stream has been
>> running.  I believe that's the very starting point of the problem
>> Peter's patch tries to address.
> 
> Unfortunately, after all discussions, I'm not convinced about Peter's
> patch. It smells like an workaround rather than a fix for forever. The
> problem is there for years so we should not concentrate on a quick fix.
> 
>>> Also, I would consider to call suspend/resume triggers (depending on a
>>> flag like can_pause_release_stop) when the stream is paused, too. Some
>>> drivers may want this scheme.
>>
>> Do you mean drivers that do share the same operation for
>> suspend/resume and pause?
> 
> Many drivers supporting pause may use it when we allow PAUSE -> SUSPEND
> and SUSPEND -> PAUSE transitions.
> 
> Something like:
> 
> diff --git a/include/sound/pcm.h b/include/sound/pcm.h
> index ac8f3aef9205..6d6882973883 100644
> --- a/include/sound/pcm.h
> +++ b/include/sound/pcm.h
> @@ -541,6 +541,8 @@ struct snd_pcm {
>         bool internal; /* pcm is for internal use only */
>         bool nonatomic; /* whole PCM operations are in non-atomic
> context */
>         bool no_device_suspend; /* don't invoke device PM suspend */
> +       bool do_suspend_and_resume_in_pause; /* allow direct PAUSED ->
> SUSPENDED and
> +                                               SUSPENDED -> PAUSED
> transitions */

I think the issue is bit different than this.
What needs to be flagged is that the driver is not treating the PAUSE
trigger in the same way as it treats the STOP or SUSPEND, in other
worlds, the PAUSED state is not equal to STOPPED/SUSPENDED.

If the PAUSED state is equal to SUSPENDED state, then the trigger could
be skipped (as it is ignored before my patch unconditionally), but if
the two states are not equal then the SUSPEND must be sent, but the
patches from me and Takashi-san stil can be used as fallback in case the
RESUME is not supported as in that case the driver will certainly not
going to be able to resume to PAUSE_RESUME, so stopping a stream in that
case is appropriate.

Side note: I think we might also have broken case when we stop a PAUSED
stream if the driver's PAUSED state is not equal to STOPPED/SUSPENDED.
It is just that applications never do this, at least I ave never seen a
missing STOP trigger. aplay is doing a pause release before stop at least.


>  #if IS_ENABLED(CONFIG_SND_PCM_OSS)
>         struct snd_pcm_oss oss;
>  #endif
> diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
> index 4057f9f10aee..3ec4ef7809ea 100644
> --- a/sound/core/pcm_native.c
> +++ b/sound/core/pcm_native.c
> @@ -1694,8 +1694,11 @@ static int snd_pcm_do_suspend(struct
> snd_pcm_substream *substream,
>         struct snd_pcm_runtime *runtime = substream->runtime;
>         if (runtime->trigger_master != substream)
>                 return 0;
> -       if (! snd_pcm_running(substream))
> -               return 0;
> +       if (! snd_pcm_running(substream)) {
> +               if (!runtime->do_suspend_and_resume_in_pause ||
> +                   runtime->state != SNDRV_PCM_STATE_PAUSED)
> +                       return 0;
> +       }
>         substream->ops->trigger(substream, SNDRV_PCM_TRIGGER_SUSPEND);
>         runtime->stop_operating = true;
>         return 0; /* suspend unconditionally */
> @@ -1798,8 +1801,11 @@ static int snd_pcm_do_resume(struct
> snd_pcm_substream *substream,
>         /* DMA not running previously? */
>         if (runtime->suspended_state != SNDRV_PCM_STATE_RUNNING &&
>             (runtime->suspended_state != SNDRV_PCM_STATE_DRAINING ||
> -            substream->stream != SNDRV_PCM_STREAM_PLAYBACK))
> -               return 0;
> +            substream->stream != SNDRV_PCM_STREAM_PLAYBACK)) {
> +               if (!runtime->do_suspend_and_resume_in_pause ||
> +                   runtime->suspend_state != SNDRV_PCM_STATE_PAUSED)
> +                       return 0;
> +       }
>         return substream->ops->trigger(substream,
> SNDRV_PCM_TRIGGER_RESUME);
>  }
> 
> This will allow to address this problem correctly without any pause
> release just to put all parts to the running state and immediately stop
> the stream. Ideally, all drivers should be migrated to this state scheme
> and the condition may be removed at the end.
> 
>                     Jaroslav
> 

-- 
Péter


  parent reply	other threads:[~2025-04-08  7:02 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-01 13:36 [PATCH] ALSA: pcm: Release paused streams before suspend if resume is not supported Peter Ujfalusi
2025-04-01 14:49 ` Takashi Iwai
2025-04-01 16:58   ` Jaroslav Kysela
2025-04-01 17:19     ` Takashi Iwai
2025-04-01 18:46       ` Jaroslav Kysela
2025-04-01 19:27         ` Takashi Iwai
2025-04-02  6:41           ` Péter Ujfalusi
2025-04-02  8:14             ` Jaroslav Kysela
2025-04-02  8:09           ` Jaroslav Kysela
2025-04-02  8:39             ` Takashi Iwai
2025-04-02  8:52               ` Jaroslav Kysela
2025-04-02  9:16                 ` Takashi Iwai
2025-04-02 10:45                   ` Jaroslav Kysela
2025-04-02 11:21                     ` Takashi Iwai
2025-04-02 11:43                       ` Péter Ujfalusi
2025-04-02 11:50                         ` Takashi Iwai
2025-04-02 12:52                           ` Péter Ujfalusi
2025-04-02 13:23                             ` Takashi Iwai
2025-04-03 10:13                               ` Péter Ujfalusi
2025-04-03 14:01                                 ` Takashi Iwai
2025-04-03 15:24                                   ` Jaroslav Kysela
2025-04-03 16:09                                     ` Takashi Iwai
2025-04-03 19:05                                       ` Jaroslav Kysela
2025-04-04 10:44                                         ` Takashi Iwai
2025-04-04 11:33                                           ` Jaroslav Kysela
2025-04-04 14:44                                             ` Takashi Iwai
2025-04-08  7:03                                         ` Péter Ujfalusi [this message]
2025-04-08  8:51                                           ` Jaroslav Kysela
2025-04-08  9:45                                             ` Péter Ujfalusi
2025-04-04  8:58                                     ` Péter Ujfalusi
2025-04-04  9:08                                       ` Jaroslav Kysela
2025-04-08  6:35                                   ` Péter Ujfalusi
2025-04-02 12:55                           ` Jaroslav Kysela
2025-04-02  9:28                 ` Péter Ujfalusi
2025-04-02 11:27                   ` Takashi Iwai
2025-04-02 11:53                     ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=d084dff6-6a25-4f84-879c-15c108c9c141@linux.intel.com \
    --to=peter.ujfalusi@linux.intel.com \
    --cc=broonie@kernel.org \
    --cc=kai.vehmanen@linux.intel.com \
    --cc=lgirdwood@gmail.com \
    --cc=liam.r.girdwood@intel.com \
    --cc=linux-sound@vger.kernel.org \
    --cc=perex@perex.cz \
    --cc=pierre-louis.bossart@linux.dev \
    --cc=ranjani.sridharan@linux.intel.com \
    --cc=tiwai@suse.com \
    --cc=tiwai@suse.de \
    --cc=yung-chuan.liao@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox