Skip to contentSkip to conversation

ASoC: core: Init pcm runtime work early to avoid warnings

PATCH Superseded Curtis Malainey 3 participants 3 messages Dec 2, 2019 – Dec 3, 2019

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC: core: Init pcm runtime work early to avoid warnings

There are cases where we fail before we reach soc_new_pcm which would init the workqueue. When we fail we attempt to flush the queue which generates warnings from the workqueue subsystem when we have not inited the queue. Solution is to use a proxy function to get around this issue.

---
 include/sound/soc.h  |  1 +
 sound/soc/soc-core.c | 10 ++++++++++
 sound/soc/soc-pcm.c  | 11 ++++-------
 3 files changed, 15 insertions(+), 7 deletions(-)
include/sound/soc.h +1 -0
index c28a1ed5e8df9..2628967998264 100644
@@ -1150,6 +1150,7 @@ struct snd_soc_pcm_runtime {
 	unsigned int num_codecs;
 
 	struct delayed_work delayed_work;
+	void (*close_delayed_work_func)(struct snd_soc_pcm_runtime *rtd);
 #ifdef CONFIG_DEBUG_FS
 	struct dentry *debugfs_dpcm_root;
 #endif
sound/soc/soc-core.c +10 -0
index 062653ab03a37..0e2e628302f1d 100644
@@ -435,6 +435,15 @@ static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
 	device_unregister(rtd->dev);
 }
 
+static void close_delayed_work(struct work_struct *work) {
+	struct snd_soc_pcm_runtime *rtd =
+			container_of(work, struct snd_soc_pcm_runtime,
+				     delayed_work.work);
+
+	if (rtd->close_delayed_work_func)
+		rtd->close_delayed_work_func(rtd);
+}
+
 static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 	struct snd_soc_card *card, struct snd_soc_dai_link *dai_link)
 {
@@ -470,6 +479,7 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 
 	rtd->dev = dev;
 	dev_set_drvdata(dev, rtd);
+	INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
 
 	/*
 	 * for rtd->codec_dais
sound/soc/soc-pcm.c +4 -7
index 01eb8700c3de5..b78f6ff2b1d3f 100644
@@ -637,10 +637,8 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
  * This is to ensure there are no pops or clicks in between any music tracks
  * due to DAPM power cycling.
  */
-static void close_delayed_work(struct work_struct *work)
+static void close_delayed_work(struct snd_soc_pcm_runtime *rtd)
 {
-	struct snd_soc_pcm_runtime *rtd =
-			container_of(work, struct snd_soc_pcm_runtime, delayed_work.work);
 	struct snd_soc_dai *codec_dai = rtd->codec_dais[0];
 
 	mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
@@ -660,7 +658,7 @@ static void close_delayed_work(struct work_struct *work)
 	mutex_unlock(&rtd->card->pcm_mutex);
 }
 
-static void codec2codec_close_delayed_work(struct work_struct *work)
+static void codec2codec_close_delayed_work(struct snd_soc_pcm_runtime *rtd)
 {
 	/*
 	 * Currently nothing to do for c2c links
@@ -2974,10 +2972,9 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
 
 	/* DAPM dai link stream work */
 	if (rtd->dai_link->params)
-		INIT_DELAYED_WORK(&rtd->delayed_work,
-				  codec2codec_close_delayed_work);
+		rtd->close_delayed_work_func = codec2codec_close_delayed_work;
 	else
-		INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
+		rtd->close_delayed_work_func = close_delayed_work;
 
 	pcm->nonatomic = rtd->dai_link->nonatomic;
 	rtd->pcm = pcm;
Signature · 6 lines
2.24.0.393.g34dc348eaf-goog

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
#1 lore raw
Quoted 6 lines · Curtis Malainey

There are cases where we fail before we reach soc_new_pcm which would init the workqueue. When we fail we attempt to flush the queue which generates warnings from the workqueue subsystem when we have not inited the queue. Solution is to use a proxy function to get around this issue.

Quoted 7 lines
---
 include/sound/soc.h  |  1 +
 sound/soc/soc-core.c | 10 ++++++++++
 sound/soc/soc-pcm.c  | 11 ++++-------
 3 files changed, 15 insertions(+), 7 deletions(-)

Forgot the change in soc-compress.c?

thanks,

Takashi

Quoted 82 lines
include/sound/soc.h +1 -0
index c28a1ed5e8df9..2628967998264 100644
@@ -1150,6 +1150,7 @@ struct snd_soc_pcm_runtime {
 	unsigned int num_codecs;
 
 	struct delayed_work delayed_work;
+	void (*close_delayed_work_func)(struct snd_soc_pcm_runtime *rtd);
 #ifdef CONFIG_DEBUG_FS
 	struct dentry *debugfs_dpcm_root;
 #endif
sound/soc/soc-core.c +10 -0
index 062653ab03a37..0e2e628302f1d 100644
@@ -435,6 +435,15 @@ static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
 	device_unregister(rtd->dev);
 }
 
+static void close_delayed_work(struct work_struct *work) {
+	struct snd_soc_pcm_runtime *rtd =
+			container_of(work, struct snd_soc_pcm_runtime,
+				     delayed_work.work);
+
+	if (rtd->close_delayed_work_func)
+		rtd->close_delayed_work_func(rtd);
+}
+
 static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 	struct snd_soc_card *card, struct snd_soc_dai_link *dai_link)
 {
@@ -470,6 +479,7 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 
 	rtd->dev = dev;
 	dev_set_drvdata(dev, rtd);
+	INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
 
 	/*
 	 * for rtd->codec_dais
sound/soc/soc-pcm.c +4 -7
index 01eb8700c3de5..b78f6ff2b1d3f 100644
@@ -637,10 +637,8 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
  * This is to ensure there are no pops or clicks in between any music tracks
  * due to DAPM power cycling.
  */
-static void close_delayed_work(struct work_struct *work)
+static void close_delayed_work(struct snd_soc_pcm_runtime *rtd)
 {
-	struct snd_soc_pcm_runtime *rtd =
-			container_of(work, struct snd_soc_pcm_runtime, delayed_work.work);
 	struct snd_soc_dai *codec_dai = rtd->codec_dais[0];
 
 	mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
@@ -660,7 +658,7 @@ static void close_delayed_work(struct work_struct *work)
 	mutex_unlock(&rtd->card->pcm_mutex);
 }
 
-static void codec2codec_close_delayed_work(struct work_struct *work)
+static void codec2codec_close_delayed_work(struct snd_soc_pcm_runtime *rtd)
 {
 	/*
 	 * Currently nothing to do for c2c links
@@ -2974,10 +2972,9 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
 
 	/* DAPM dai link stream work */
 	if (rtd->dai_link->params)
-		INIT_DELAYED_WORK(&rtd->delayed_work,
-				  codec2codec_close_delayed_work);
+		rtd->close_delayed_work_func = codec2codec_close_delayed_work;
 	else
-		INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
+		rtd->close_delayed_work_func = close_delayed_work;
 
 	pcm->nonatomic = rtd->dai_link->nonatomic;
 	rtd->pcm = pcm;
Signature · 1 line
2.24.0.393.g34dc348eaf-goog

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#2 lore raw
Quoted 17 lines · Takashi Iwai
Quoted 6 lines · Curtis Malainey

There are cases where we fail before we reach soc_new_pcm which would init the workqueue. When we fail we attempt to flush the queue which generates warnings from the workqueue subsystem when we have not inited the queue. Solution is to use a proxy function to get around this issue.

Quoted 7 lines
---
 include/sound/soc.h  |  1 +
 sound/soc/soc-core.c | 10 ++++++++++
 sound/soc/soc-pcm.c  | 11 ++++-------
 3 files changed, 15 insertions(+), 7 deletions(-)
Quoted 7 lines

Forgot the change in soc-compress.c?

thanks,

Takashi

Thanks for spotting that, I'll send v2, I won't be able to test the compress path as we have no platforms setup for that.

Quoted 78 lines
Quoted 78 lines
include/sound/soc.h +1 -0
index c28a1ed5e8df9..2628967998264 100644
@@ -1150,6 +1150,7 @@ struct snd_soc_pcm_runtime {
      unsigned int num_codecs;
 
      struct delayed_work delayed_work;
+     void (*close_delayed_work_func)(struct snd_soc_pcm_runtime *rtd);
 #ifdef CONFIG_DEBUG_FS
      struct dentry *debugfs_dpcm_root;
 #endif
sound/soc/soc-core.c +10 -0
index 062653ab03a37..0e2e628302f1d 100644
@@ -435,6 +435,15 @@ static void soc_free_pcm_runtime(struct snd_soc_pcm_runtime *rtd)
      device_unregister(rtd->dev);
 }
 
+static void close_delayed_work(struct work_struct *work) {
+     struct snd_soc_pcm_runtime *rtd =
+                     container_of(work, struct snd_soc_pcm_runtime,
+                                  delayed_work.work);
+
+     if (rtd->close_delayed_work_func)
+             rtd->close_delayed_work_func(rtd);
+}
+
 static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
      struct snd_soc_card *card, struct snd_soc_dai_link *dai_link)
 {
@@ -470,6 +479,7 @@ static struct snd_soc_pcm_runtime *soc_new_pcm_runtime(
 
      rtd->dev = dev;
      dev_set_drvdata(dev, rtd);
+     INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
 
      /*
       * for rtd->codec_dais
sound/soc/soc-pcm.c +4 -7
index 01eb8700c3de5..b78f6ff2b1d3f 100644
@@ -637,10 +637,8 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
  * This is to ensure there are no pops or clicks in between any music tracks
  * due to DAPM power cycling.
  */
-static void close_delayed_work(struct work_struct *work)
+static void close_delayed_work(struct snd_soc_pcm_runtime *rtd)
 {
-     struct snd_soc_pcm_runtime *rtd =
-                     container_of(work, struct snd_soc_pcm_runtime, delayed_work.work);
      struct snd_soc_dai *codec_dai = rtd->codec_dais[0];
 
      mutex_lock_nested(&rtd->card->pcm_mutex, rtd->card->pcm_subclass);
@@ -660,7 +658,7 @@ static void close_delayed_work(struct work_struct *work)
      mutex_unlock(&rtd->card->pcm_mutex);
 }
 
-static void codec2codec_close_delayed_work(struct work_struct *work)
+static void codec2codec_close_delayed_work(struct snd_soc_pcm_runtime *rtd)
 {
      /*
       * Currently nothing to do for c2c links
@@ -2974,10 +2972,9 @@ int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
 
      /* DAPM dai link stream work */
      if (rtd->dai_link->params)
-             INIT_DELAYED_WORK(&rtd->delayed_work,
-                               codec2codec_close_delayed_work);
+             rtd->close_delayed_work_func = codec2codec_close_delayed_work;
      else
-             INIT_DELAYED_WORK(&rtd->delayed_work, close_delayed_work);
+             rtd->close_delayed_work_func = close_delayed_work;
 
Quoted 5 lines
Quoted 5 lines
sound/soc/soc-pcm.c +0 -1
      pcm->nonatomic = rtd->dai_link->nonatomic;
      rtd->pcm = pcm;
--

2.24.0.393.g34dc348eaf-goog

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel