From: Takashi Iwai <tiwai@suse.de>
To: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Cc: alsa-devel@alsa-project.org,
Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>,
Sameer Pujar <spujar@nvidia.com>,
vkoul@kernel.org, broonie@kernel.org,
Gyeongtaek Lee <gt82.lee@samsung.com>,
Peter Ujfalusi <peter.ujfalusi@linux.intel.com>
Subject: Re: [RFC PATCH v2 0/5] ASoC: soc-pcm: fix trigger race conditions with shared BE
Date: Thu, 07 Oct 2021 13:06:00 +0200 [thread overview]
Message-ID: <s5hk0ip9js7.wl-tiwai@suse.de> (raw)
In-Reply-To: <11257d77-9975-3b00-94da-5dc1b5c95fc6@linux.intel.com>
On Wed, 06 Oct 2021 21:47:33 +0200,
Pierre-Louis Bossart wrote:
>
>
> > I tested this further. It appears that things work fine till 'patch 3/5'
> > of yours. After I take 'patch 4/5', the print "BUG: scheduling while
> > atomic: aplay" started showing up and I see a hang. This failure was
> > seen for 2x1 mixer test itself.
> >
> > The 'patch 4/5' introduces mutex_lock/unlock() in dpcm_be_dai_trigger().
> > This seems to be the problem, since trigger() runs in atomic context
> > depending on the PCM 'nonatomic' flag. I am not sure if your design sets
> > 'nonatomic' flag by default and that is why the issue is not seen at
> > your end?
> >
> > With below (just for testing purpose), tests ran well. I was able to run
> > 2x1, 3x1 ... 10x1 mixer tests.
>
> This is useful information, thanks a lot Sameer for your time.
>
> Unfortunately removing the lines below will not work, that's
> precisely what's needed to prevent multiple triggers from being sent to
> the same shared BE.
>
> I don't have a clear idea why we see different results, and now I have
> even less understanding of the ALSA/ASoC/DPCM locking model. We use
> card->mutex, card->pcm_mutex, card->dpcm_lock,
> substream->self_group.mutex or lock, client_mutex, dapm_mutex....
>
> I don't think any of the DPCM code is ever called from an interrupt
> context, so the errors you reported seem more like a card configuration,
> specifically the interaction with 'aplay'/userspace will happen for FEs.
> BEs are mostly hidden to userspace.
>
> One possible difference is that all our DPCM solutions are based on
> non-atomic FEs (since they all involve an IPC with a DSP), so we would
> always use the top banch of these tests:
>
> if (nonatomic) \
> mutex_ ## mutex_action(&group->mutex); \
> else \
> spin_ ## action(&group->lock);
>
> I don't see this nonatomic flag set anywhere in the sound/soc/tegra
> code, so it's possible that in your case the spin_lock/spin_lock_irq is
> used before triggering the FE, and using a mutex before the BE trigger
> throws errors? I think Takashi mentioned that the BEs inherit the
> properties of the FE to some extent.
>
> Looking at the code, I see that only Intel legacy, SOF and Qualcomm
> drivers set nonatomic=1, so maybe we can assume that that FEs for a card
> are either all atomic or all non-atomic, maybe we could then use a
> spinlock or a mutex. But if the FEs can be different then I am not sure
> what locking model might work, we can't have a BE protected by a
> spinlock or a mutex depending on the property of the FE. We need one
> method only to guarantee a mutual exclusion.
>
> Takashi, Mark, do you think that an all/none assumption on FE nonatomic
> properties would make sense?
As long as BE's are updated from FE's PCM callback, BE has to follow
the atomicity of its FE, so we can't assume all or none globally.
How is the expected lock granularity and the protection context? Do
we need a card global lock/mutex, or is it specific to each BE
substream?
thanks,
Takashi
next prev parent reply other threads:[~2021-10-07 11:07 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-04 22:54 [RFC PATCH v2 0/5] ASoC: soc-pcm: fix trigger race conditions with shared BE Pierre-Louis Bossart
2021-10-04 22:54 ` [RFC PATCH v2 1/5] ASoC: soc-pcm: remove snd_soc_dpcm_fe_can_update() Pierre-Louis Bossart
2021-10-04 22:54 ` Pierre-Louis Bossart
2021-10-04 22:54 ` [RFC PATCH v2 2/5] ASoC: soc-pcm: don't export local functions, use static Pierre-Louis Bossart
2021-10-04 22:54 ` Pierre-Louis Bossart
2021-10-04 22:54 ` [RFC PATCH v2 3/5] ASoC: soc-pcm: replace dpcm_lock with dpcm_mutex Pierre-Louis Bossart
2021-10-04 22:54 ` Pierre-Louis Bossart
2021-10-04 22:54 ` [RFC PATCH v2 4/5] ASoC: soc-pcm: protect for_each_dpcm_be() loops " Pierre-Louis Bossart
2021-10-04 22:54 ` Pierre-Louis Bossart
2021-10-04 22:54 ` [RFC PATCH v2 5/5] ASoC: soc-pcm: test refcount before triggering Pierre-Louis Bossart
2021-10-04 22:54 ` Pierre-Louis Bossart
2021-10-05 6:36 ` [RFC PATCH v2 0/5] ASoC: soc-pcm: fix trigger race conditions with shared BE Sameer Pujar
2021-10-05 13:17 ` Pierre-Louis Bossart
2021-10-06 14:22 ` Sameer Pujar
2021-10-06 19:47 ` Pierre-Louis Bossart
2021-10-07 11:06 ` Takashi Iwai [this message]
2021-10-07 13:31 ` Pierre-Louis Bossart
2021-10-07 14:59 ` Takashi Iwai
2021-10-07 15:24 ` Pierre-Louis Bossart
2021-10-07 15:44 ` Takashi Iwai
2021-10-07 18:13 ` Pierre-Louis Bossart
2021-10-07 21:11 ` Takashi Iwai
2021-10-07 21:27 ` Pierre-Louis Bossart
2021-10-08 6:13 ` Takashi Iwai
2021-10-08 14:41 ` Pierre-Louis Bossart
2021-10-08 14:51 ` Takashi Iwai
2021-10-08 15:41 ` Pierre-Louis Bossart
2021-10-08 19:09 ` Pierre-Louis Bossart
2021-10-11 20:06 ` Pierre-Louis Bossart
2021-10-12 6:34 ` Takashi Iwai
2021-10-12 10:42 ` Takashi Iwai
2021-10-12 13:45 ` Pierre-Louis Bossart
2021-10-12 15:07 ` 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=s5hk0ip9js7.wl-tiwai@suse.de \
--to=tiwai@suse.de \
--cc=alsa-devel@alsa-project.org \
--cc=broonie@kernel.org \
--cc=gt82.lee@samsung.com \
--cc=kuninori.morimoto.gx@renesas.com \
--cc=peter.ujfalusi@linux.intel.com \
--cc=pierre-louis.bossart@linux.intel.com \
--cc=spujar@nvidia.com \
--cc=vkoul@kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.