Skip to contentSkip to conversation

ASoC: core: Add card mutex locking subclasses

PATCH Applied Liam Girdwood 2 participants 7 messages Mar 7, 2012 – Mar 8, 2012

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 ASoC: core: Add card mutex locking subclasses

This is the first part of a change that is intended to improve ASoC locking protection for DAPM and PCM operations.

This part of the series adds a mutex class for the soc_card mutex. The SND_SOC_CARD_CLASS_INIT class is used for card initialisation only whilst the SND_SOC_CARD_CLASS_PCM class is used for the forth coming Dynamic PCM operations. The new mutex classes are required otherwise we will see a false positive mutex deadlock warning between the card initialisation and the PCM operations (something that would never deadlock in real life).

---
 include/sound/soc.h  |    5 +++++
 sound/soc/soc-core.c |    2 +-
 2 files changed, 6 insertions(+), 1 deletions(-)
include/sound/soc.h +5 -0
index 2ebf787..70de2f8 100644
@@ -288,6 +288,11 @@ enum snd_soc_pcm_subclass {
 	SND_SOC_PCM_CLASS_BE	= 1,
 };
 
+enum snd_soc_card_subclass {
+	SND_SOC_CARD_CLASS_INIT	= 0,
+	SND_SOC_CARD_CLASS_PCM	= 1,
+};
+
 int snd_soc_codec_set_sysclk(struct snd_soc_codec *codec, int clk_id,
 			     int source, unsigned int freq, int dir);
 int snd_soc_codec_set_pll(struct snd_soc_codec *codec, int pll_id, int source,
sound/soc/soc-core.c +1 -1
index c90bb01..acd0d93 100644
@@ -1416,7 +1416,7 @@ static void snd_soc_instantiate_card(struct snd_soc_card *card)
 	struct snd_soc_dai_link *dai_link;
 	int ret, i, order;
 
-	mutex_lock(&card->mutex);
+	mutex_lock_nested(&card->mutex, SND_SOC_CARD_CLASS_INIT);
 
 	if (card->instantiated) {
 		mutex_unlock(&card->mutex);
Signature · 1 line
1.7.5.4
#1 lore raw

PATCH 2/3 ASoC: dapm: Use DAPM mutex for DAPM ops instead of codec mutex.

It has now become necessary to use a DAPM mutex instead of the codec mutex to lock the DAPM operations. This is due to the recent multi component support and forth coming Dynamic PCM updates.

Currently we lock DAPM operations with the codec mutex of the calling RTD context. However, DAPM operations can span the whole card context and all components.

This patch updates the DAPM operations that use the codec mutex to now use the DAPM mutex PCM subclass for all DAPM ops.

We also add a mutex subclass for DAPM init and PCM operations.

---
 include/sound/soc-dapm.h |    5 ++++
 include/sound/soc.h      |    1 +
 sound/soc/soc-core.c     |    1 +
 sound/soc/soc-dapm.c     |   59 ++++++++++++++++++++++++++++++---------------
 4 files changed, 46 insertions(+), 20 deletions(-)
include/sound/soc-dapm.h +5 -0
index e46107f..6727384 100644
@@ -431,6 +431,11 @@ enum snd_soc_dapm_type {
 	snd_soc_dapm_dai,		/* link to DAI structure */
 };
 
+enum snd_soc_dapm_subclass {
+	SND_SOC_DAPM_CLASS_INIT	= 0,
+	SND_SOC_DAPM_CLASS_PCM	= 1,
+};
+
 /*
  * DAPM audio route definition.
  *
include/sound/soc.h +1 -0
index 70de2f8..66fd9bc 100644
@@ -805,6 +805,7 @@ struct snd_soc_card {
 
 	struct list_head list;
 	struct mutex mutex;
+	struct mutex dapm_mutex;
 
 	bool instantiated;
 
sound/soc/soc-core.c +1 -0
index acd0d93..5aef34a 100644
@@ -3125,6 +3125,7 @@ int snd_soc_register_card(struct snd_soc_card *card)
 	INIT_LIST_HEAD(&card->dapm_dirty);
 	card->instantiated = 0;
 	mutex_init(&card->mutex);
+	mutex_init(&card->dapm_mutex);
 
 	mutex_lock(&client_mutex);
 	list_add(&card->list, &card_list);
sound/soc/soc-dapm.c +39 -20

228 lines not on this page · raw message

Signature · 1 line
1.7.5.4
Applied
#2 lore raw

Re: [PATCH 2/3] ASoC: dapm: Use DAPM mutex for DAPM ops instead of codec mutex.

On Wed, Mar 07, 2012 at 10:38:26AM +0000, Liam Girdwood wrote:

Applied, thanks.

include/sound/soc-dapm.h enum snd_soc_dapm_type { · line 436

Quoted 3 lines
include/sound/soc-dapm.h +3 -0
+enum snd_soc_dapm_subclass {
+	SND_SOC_DAPM_CLASS_INIT	= 0,
+	SND_SOC_DAPM_CLASS_PCM	= 1,

I think I'd rather this were called _RUNTIME or something, we may not have a stream involved at all in some cases.

#3 lore raw

Re: [PATCH 2/3] ASoC: dapm: Use DAPM mutex for DAPM ops instead of codec mutex.

Quoted 10 lines · Mark Brown

On Wed, Mar 07, 2012 at 10:38:26AM +0000, Liam Girdwood wrote:

Applied, thanks.

include/sound/soc-dapm.h enum snd_soc_dapm_type { · line 436

Quoted 3 lines
include/sound/soc-dapm.h +3 -0
+enum snd_soc_dapm_subclass {
+	SND_SOC_DAPM_CLASS_INIT	= 0,
+	SND_SOC_DAPM_CLASS_PCM	= 1,

I think I'd rather this were called _RUNTIME or something, we may not have a stream involved at all in some cases.

I'll update this incrementally.

Liam

#4 lore raw

PATCH 3/3 ASoC: dapm: lock mixer & mux update power with DAPM mutex.

In reply to Liam Girdwood

Both snd_soc_dapm_mux_update_power() and snd_soc_dapm_mixer_update_power() can be called internally within DAPM core (with DAPM mutex held) and externally.

Provide some wrappers so that external users of both functions do not have to remeber and hold the DAPM mutex.

---
 sound/soc/soc-dapm.c |   36 ++++++++++++++++++++++++++++++------
 1 files changed, 30 insertions(+), 6 deletions(-)
sound/soc/soc-dapm.c +30 -6
index 5beaa3e..5c83b83 100644
@@ -1741,7 +1741,7 @@ static inline void dapm_debugfs_cleanup(struct snd_soc_dapm_context *dapm)
 #endif
 
 /* test and update the power status of a mux widget */
-int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
+static int soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
 				 struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e)
 {
 	struct snd_soc_dapm_path *path;
@@ -1780,10 +1780,22 @@ int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
 
 	return 0;
 }
+
+int snd_soc_dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
+		struct snd_kcontrol *kcontrol, int mux, struct soc_enum *e)
+{
+	struct snd_soc_card *card = widget->dapm->card;
+	int ret;
+
+	mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_PCM);
+	ret = soc_dapm_mux_update_power(widget, kcontrol, mux, e);
+	mutex_unlock(&card->dapm_mutex);
+	return ret;
+}
 EXPORT_SYMBOL_GPL(snd_soc_dapm_mux_update_power);
 
 /* test and update the power status of a mixer or switch widget */
-int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
+static int soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
 				   struct snd_kcontrol *kcontrol, int connect)
 {
 	struct snd_soc_dapm_path *path;
@@ -1812,6 +1824,18 @@ int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
 
 	return 0;
 }
+
+int snd_soc_dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
+				struct snd_kcontrol *kcontrol, int connect)
+{
+	struct snd_soc_card *card = widget->dapm->card;
+	int ret;
+
+	mutex_lock_nested(&card->dapm_mutex, SND_SOC_DAPM_CLASS_PCM);
+	ret = soc_dapm_mixer_update_power(widget, kcontrol, connect);
+	mutex_unlock(&card->dapm_mutex);
+	return ret;
+}
 EXPORT_SYMBOL_GPL(snd_soc_dapm_mixer_update_power);
 
 /* show dapm widget status in sys fs */
@@ -2415,7 +2439,7 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
 			update.val = val;
 			widget->dapm->update = &update;
 
-			snd_soc_dapm_mixer_update_power(widget, kcontrol, connect);
+			soc_dapm_mixer_update_power(widget, kcontrol, connect);
 
 			widget->dapm->update = NULL;
 		}
@@ -2507,7 +2531,7 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
 			update.val = val;
 			widget->dapm->update = &update;
 
-			snd_soc_dapm_mux_update_power(widget, kcontrol, mux, e);
+			soc_dapm_mux_update_power(widget, kcontrol, mux, e);
 
 			widget->dapm->update = NULL;
 		}
@@ -2569,7 +2593,7 @@ int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
 
 			widget->value = ucontrol->value.enumerated.item[0];
 
-			snd_soc_dapm_mux_update_power(widget, kcontrol, widget->value, e);
+			soc_dapm_mux_update_power(widget, kcontrol, widget->value, e);
 		}
 	}
 
@@ -2673,7 +2697,7 @@ int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
 			update.val = val;
 			widget->dapm->update = &update;
 
-			snd_soc_dapm_mux_update_power(widget, kcontrol, mux, e);
+			soc_dapm_mux_update_power(widget, kcontrol, mux, e);
 
 			widget->dapm->update = NULL;
 		}
Signature · 1 line
1.7.5.4
#5 lore raw

Re: [PATCH 3/3] ASoC: dapm: lock mixer & mux update power with DAPM mutex.

Quoted 2 lines · Liam Girdwood

Both snd_soc_dapm_mux_update_power() and snd_soc_dapm_mixer_update_power() can be called internally within DAPM core (with DAPM mutex held) and externally.

Applied with typo fixes to the changelog.

Applied
#6 lore raw
In reply to Liam Girdwood
Quoted 2 lines · Liam Girdwood

This is the first part of a change that is intended to improve ASoC locking protection for DAPM and PCM operations.

Applied, thanks.