Skip to contentSkip to conversation

ASoC force running of delayed PM work at suspend() and remove()

PATCH Applied Liam Girdwood 2 participants 5 messages Jan 31, 2007 – Feb 1, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ASoC force running of delayed PM work at suspend() and remove()

This patch fixes a bug whereby the power management delayed work would never be run at driver suspend() or module remove(). Delayed work would be created (after audio had finished) with a long delay (~5 secs) and was sometimes never queued before flush_scheduled_work() was being called at suspend or module remove. This caused the delayed work to queued after the module had been removed or after resume.

This patch forces any delayed work to complete by cancelling it (timer cannot fire and add it to queue later), scheduling it for now and waiting on it's completion.

This is something I probably would like to add to workqueue.c in the next merge window, however it's here atm because it can oops.

soc/soc-core.c +22 -1
diff -r b4265ee02e26 soc/soc-core.c
@@ -76,6 +76,25 @@ static int pmdown_time = 5000;
 static int pmdown_time = 5000;
 module_param(pmdown_time, int, 0);
 MODULE_PARM_DESC(pmdown_time, "DAPM stream powerdown time (msecs)");
+
+/*
+ * This function forces any delayed work to be queued and run.
+ */
+static int run_delayed_work(struct delayed_work *dwork)
+{
+	int ret;
+
+	/* cancel any work waiting to be queued. */
+	ret = cancel_delayed_work(dwork);
+
+	/* if there was any work waiting then we run it now and
+	 * wait for it's completion */
+	if (ret) {
+		schedule_delayed_work(dwork, 0);
+		flush_scheduled_work();
+	}
+	return ret;
+}
 
 #ifdef CONFIG_SND_SOC_AC97_BUS
 /* unregister ac97 codec */
@@ -1101,7 +1120,7 @@ static int soc_suspend(struct platform_d
 	}
 
 	/* close any waiting streams and save state */
-	flush_scheduled_work();
+	run_delayed_work(&socdev->delayed_work);
 	codec->suspend_dapm_state = codec->dapm_state;
 
 	for(i = 0; i < codec->num_dai; i++) {
@@ -1254,6 +1273,8 @@ static int soc_remove(struct platform_de
 	struct snd_soc_machine *machine = socdev->machine;
 	struct snd_soc_platform *platform = socdev->platform;
 	struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
+
+	run_delayed_work(&socdev->delayed_work);
 
 	if (platform->remove)
 		platform->remove(pdev);

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

Applied
#1 lore raw

At Wed, 31 Jan 2007 12:26:25 +0000,

Quoted 8 lines · Liam Girdwood

This patch fixes a bug whereby the power management delayed work would never be run at driver suspend() or module remove(). Delayed work would be created (after audio had finished) with a long delay (~5 secs) and was sometimes never queued before flush_scheduled_work() was being called at suspend or module remove. This caused the delayed work to queued after the module had been removed or after resume.

Quoted 8 lines

This patch forces any delayed work to complete by cancelling it (timer cannot fire and add it to queue later), scheduling it for now and waiting on it's completion.

This is something I probably would like to add to workqueue.c in the next merge window, however it's here atm because it can oops.

Applied. I guess we need to fix a similar (flush_delayed_work) in ac97 codec code, too.

thanks,

Takashi

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

#2 lore raw
Quoted 14 lines · Takashi Iwai

At Wed, 31 Jan 2007 12:26:25 +0000,

Quoted 12 lines · Liam Girdwood

This patch fixes a bug whereby the power management delayed work would never be run at driver suspend() or module remove(). Delayed work would be created (after audio had finished) with a long delay (~5 secs) and was sometimes never queued before flush_scheduled_work() was being called at suspend or module remove. This caused the delayed work to queued after the module had been removed or after resume.

This patch forces any delayed work to complete by cancelling it (timer cannot fire and add it to queue later), scheduling it for now and waiting on it's completion.

Quoted 7 lines
Quoted 4 lines

This is something I probably would like to add to workqueue.c in the next merge window, however it's here atm because it can oops.

Applied. I guess we need to fix a similar (flush_delayed_work) in ac97 codec code, too.

Patch attached for AC97 codec.

Signed-off-by Liam Girdwood <[email protected]>

Liam

pci/ac97/ac97_codec.c +18 -4
diff -r 2a5adb550155 pci/ac97/ac97_codec.c
@@ -965,6 +965,22 @@ AD18XX_PCM_BITS("LFE Playback Volume", 2
  *
  */
 
+static int run_ac97_delayed_work(struct delayed_work *dwork)
+{
+	int ret;
+
+	/* cancel any work waiting to be queued. */
+	ret = cancel_delayed_work(dwork);
+
+	/* if there was any work waiting then we run it now and
+	 * wait for it's completion */
+	if (ret) {
+		schedule_delayed_work(dwork, 0);
+		flush_scheduled_work();
+	}
+	return ret;
+}
+
 static void snd_ac97_powerdown(struct snd_ac97 *ac97);
 
 static int snd_ac97_bus_free(struct snd_ac97_bus *bus)
@@ -989,8 +1005,7 @@ static int snd_ac97_free(struct snd_ac97
 {
 	if (ac97) {
 #ifdef CONFIG_SND_AC97_POWER_SAVE
-		cancel_delayed_work(&ac97->power_work);
-		flush_scheduled_work();
+		run_ac97_delayed_work(&ac97->power_work);
 #endif
 		snd_ac97_proc_done(ac97);
 		if (ac97->bus)
@@ -2417,8 +2432,7 @@ void snd_ac97_suspend(struct snd_ac97 *a
 	if (ac97->build_ops->suspend)
 		ac97->build_ops->suspend(ac97);
 #ifdef CONFIG_SND_AC97_POWER_SAVE
-	cancel_delayed_work(&ac97->power_work);
-	flush_scheduled_work();
+	run_ac97_delayed_work(&ac97->power_work);
 #endif
 	snd_ac97_powerdown(ac97);
 }

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

#3 lore raw
Quoted 1 line · Liam Girdwood

Patch attached for AC97 codec.

Best use this one. I've now put the #ifdef CONFIG_SND_AC97_POWER_SAVE around the function.

Liam

pci/ac97/ac97_codec.c +19 -4
diff -r 2a5adb550155 pci/ac97/ac97_codec.c
@@ -964,6 +964,23 @@ AD18XX_PCM_BITS("LFE Playback Volume", 2
 /*
  *
  */
+#ifdef CONFIG_SND_AC97_POWER_SAVE
+static int run_ac97_delayed_work(struct delayed_work *dwork)
+{
+	int ret;
+
+	/* cancel any work waiting to be queued. */
+	ret = cancel_delayed_work(dwork);
+
+	/* if there was any work waiting then we run it now and
+	 * wait for it's completion */
+	if (ret) {
+		schedule_delayed_work(dwork, 0);
+		flush_scheduled_work();
+	}
+	return ret;
+}
+#endif
 
 static void snd_ac97_powerdown(struct snd_ac97 *ac97);
 
@@ -989,8 +1006,7 @@ static int snd_ac97_free(struct snd_ac97
 {
 	if (ac97) {
 #ifdef CONFIG_SND_AC97_POWER_SAVE
-		cancel_delayed_work(&ac97->power_work);
-		flush_scheduled_work();
+		run_ac97_delayed_work(&ac97->power_work);
 #endif
 		snd_ac97_proc_done(ac97);
 		if (ac97->bus)
@@ -2417,8 +2433,7 @@ void snd_ac97_suspend(struct snd_ac97 *a
 	if (ac97->build_ops->suspend)
 		ac97->build_ops->suspend(ac97);
 #ifdef CONFIG_SND_AC97_POWER_SAVE
-	cancel_delayed_work(&ac97->power_work);
-	flush_scheduled_work();
+	run_ac97_delayed_work(&ac97->power_work);
 #endif
 	snd_ac97_powerdown(ac97);
 }

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
Alsa-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/alsa-devel

#4 lore raw

At Wed, 31 Jan 2007 17:39:06 +0000,

Quoted 7 lines · Liam Girdwood
Quoted 1 line · Liam Girdwood

Patch attached for AC97 codec.

Best use this one. I've now put the #ifdef CONFIG_SND_AC97_POWER_SAVE around the function.

Well, in the case of ac97_codec.c, we don't have to put schedule_delayed_work() there. The work is only for power-off, and suspend/powerdown is the very place to force to turn off the power immediately afterward.

Takashi

Quoted 43 lines

Liam
[2 ac97-delayed-work.patch <text/x-patch; utf-8 (7bit)>] diff -r 2a5adb550155 pci/ac97/ac97_codec.c

pci/ac97/ac97_codec.c +18 -2
@@ -964,6 +964,23 @@ AD18XX_PCM_BITS("LFE Playback Volume", 2
 /*
  *
  */
+#ifdef CONFIG_SND_AC97_POWER_SAVE
+static int run_ac97_delayed_work(struct delayed_work *dwork)
+{
+	int ret;
+
+	/* cancel any work waiting to be queued. */
+	ret = cancel_delayed_work(dwork);
+
+	/* if there was any work waiting then we run it now and
+	 * wait for it's completion */
+	if (ret) {
+		schedule_delayed_work(dwork, 0);
+		flush_scheduled_work();
+	}
+	return ret;
+}
+#endif
 
 static void snd_ac97_powerdown(struct snd_ac97 *ac97);
 
@@ -989,8 +1006,7 @@ static int snd_ac97_free(struct snd_ac97
 {
 	if (ac97) {
 #ifdef CONFIG_SND_AC97_POWER_SAVE
-		cancel_delayed_work(&ac97->power_work);
-		flush_scheduled_work();
+		run_ac97_delayed_work(&ac97->power_work);
 #endif
 		snd_ac97_proc_done(ac97);
 		if (ac97->bus)

pci/ac97/ac97_codec.c void snd_ac97_suspend(struct snd_ac97 *a · line 2439

Quoted 9 lines
pci/ac97/ac97_codec.c +1 -2
@@ -2417,8 +2433,7 @@ void snd_ac97_suspend(struct snd_ac97 *a
 	if (ac97->build_ops->suspend)
 		ac97->build_ops->suspend(ac97);
 #ifdef CONFIG_SND_AC97_POWER_SAVE
-	cancel_delayed_work(&ac97->power_work);
-	flush_scheduled_work();
+	run_ac97_delayed_work(&ac97->power_work);
 #endif
 	snd_ac97_powerdown(ac97);
 }

-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier. Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642