From: Takashi Iwai <tiwai@suse.de>
To: Jaroslav Kysela <perex@perex.cz>
Cc: "Takashi Iwai" <tiwai@suse.de>,
"Péter Ujfalusi" <peter.ujfalusi@linux.intel.com>,
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: Fri, 04 Apr 2025 16:44:10 +0200 [thread overview]
Message-ID: <87iknk2dhh.wl-tiwai@suse.de> (raw)
In-Reply-To: <a70bf80b-d8e3-40f7-9bf5-e59bca57da15@perex.cz>
On Fri, 04 Apr 2025 13:33:10 +0200,
Jaroslav Kysela wrote:
>
> On 04. 04. 25 12:44, Takashi Iwai wrote:
> > On Thu, 03 Apr 2025 21:05:51 +0200,
> > 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 */
> >> #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.
> >
> > OK, this should work, too.
> > If we deal with another corner case such as PAUSED -> STOP, a new flag
> > can be added, too. (Or make one flag indicating both meanings.)
> >
> > Or, there can be a driver that wants to receive trigger SUSPEND even
> > for the non-running substreams, too. We need to check the details
> > before moving forward...
> >
> > And, if there can be multiple flags, I'd rather introduce a new field
> > to snd_pcm_hardware, e.g. extra_flags field to keep the internal bit
> > flags that aren't exposed to user-space. Otherwise the setup can be
> > cumbersome for each driver.
>
> I think that one flag for new suspend/pause/resume trigger behavior
> should be enough. We may reuse SNDRV_PCM_INFO_DRAIN_TRIGGER flag
> which is no longer used. It was probably implemented only in removed
> Intel SST drivers.
OK, this is a subtle detail and can be discussed later.
I believe the biggest obstacle in this route is the handling in ASoC
DPCM. AFAIUC, it has a refcount management of paused BEs, and this
transition can break it.
thanks,
Takashi
next prev parent reply other threads:[~2025-04-04 14:44 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 [this message]
2025-04-08 7:03 ` Péter Ujfalusi
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=87iknk2dhh.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--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=peter.ujfalusi@linux.intel.com \
--cc=pierre-louis.bossart@linux.dev \
--cc=ranjani.sridharan@linux.intel.com \
--cc=tiwai@suse.com \
--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