Skip to contentSkip to conversation

ALSA: hda: Use RIRB waitq commonly

PATCH In review Takashi Iwai 2 participants 5 messages Dec 12, 2019 – Dec 13, 2019

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

cover ALSA: hda: Use RIRB waitq commonly

Hi,

this is a follow-up patch set for adapting the RIRB waitq to HD-audio core, and a cleanup with it.

Takashi

===

Takashi Iwai (2):
ALSA: hda: Use waitqueue for RIRB in HDA-core helper, too
ALSA: hda: Unify get_response handling

 include/sound/hda_codec.h      |  1 -
 include/sound/hdaudio.h        |  1 +
 sound/hda/hdac_controller.c    | 25 +++++++++++++++++++--
 sound/pci/hda/hda_controller.c | 49 ++++--------------------------------------
 sound/pci/hda/hda_intel.c      |  2 +-
 sound/pci/hda/hda_tegra.c      |  2 +-
 sound/pci/hda/patch_ca0110.c   |  2 +-
 sound/pci/hda/patch_sigmatel.c |  2 +-
 8 files changed, 32 insertions(+), 52 deletions(-)
Signature · 6 lines
2.16.4

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

PATCH 1/2 ALSA: hda: Use waitqueue for RIRB in HDA-core helper, too

This patch implements the same logic that was done for the legacy HD-audio controller driver by the commit 88452da92ba2 ("ALSA: hda: Use standard waitqueue for RIRB wakeup") to the HDA-core helper code, too. This makes snd_hdac_bus_get_response() waiting for the response with bus->rirb_wq instead of polling when bus->polling is false. It'll save both CPU time and response latency.

---
 sound/hda/hdac_controller.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
sound/hda/hdac_controller.c +14 -2
index cd1c3b282657..61950b83b8c9 100644
@@ -241,30 +241,42 @@ int snd_hdac_bus_get_response(struct hdac_bus *bus, unsigned int addr,
 {
 	unsigned long timeout;
 	unsigned long loopcounter;
+	wait_queue_entry_t wait;
 
+	init_wait_entry(&wait, 0);
 	timeout = jiffies + msecs_to_jiffies(1000);
 
 	for (loopcounter = 0;; loopcounter++) {
 		spin_lock_irq(&bus->reg_lock);
+		if (!bus->polling_mode)
+			prepare_to_wait(&bus->rirb_wq, &wait,
+					TASK_UNINTERRUPTIBLE);
 		if (bus->polling_mode)
 			snd_hdac_bus_update_rirb(bus);
 		if (!bus->rirb.cmds[addr]) {
 			if (res)
 				*res = bus->rirb.res[addr]; /* the last value */
+			if (!bus->polling_mode)
+				finish_wait(&bus->rirb_wq, &wait);
 			spin_unlock_irq(&bus->reg_lock);
 			return 0;
 		}
 		spin_unlock_irq(&bus->reg_lock);
 		if (time_after(jiffies, timeout))
 			break;
-		if (loopcounter > 3000)
+		if (!bus->polling_mode) {
+			schedule_timeout(msecs_to_jiffies(2));
+		} else if (loopcounter > 3000) {
 			msleep(2); /* temporary workaround */
-		else {
+		} else {
 			udelay(10);
 			cond_resched();
 		}
 	}
 
+	if (!bus->polling_mode)
+		finish_wait(&bus->rirb_wq, &wait);
+
 	return -EIO;
 }
 EXPORT_SYMBOL_GPL(snd_hdac_bus_get_response);
Signature · 6 lines
2.16.4

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Reviewed-by on v1 1/2
#2 lore raw

Re: [alsa-devel] [PATCH 1/2] ALSA: hda: Use waitqueue for RIRB in HDA-core helper, too

Hi,

Quoted 2 lines · Takashi Iwai

This patch implements the same logic that was done for the legacy HD-audio controller driver by the commit 88452da92ba2 ("ALSA: hda: Use

looks good to me. Code review ok, SOF CI shows no regressions [1] and I did a local test with a large amount of suspend/resyme cycles on a HDA machine and no errors seen. So for these two patches:

[1] https://github.com/thesofproject/linux/pull/1625

     -> https://sof-ci.01.org/linuxpr/PR1625/build2716/devicetest/

Br, Kai

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

#3 lore raw

Re: [alsa-devel] [PATCH 1/2] ALSA: hda: Use waitqueue for RIRB in HDA-core helper, too

Quoted 8 lines · Kai Vehmanen

Hi,

Quoted 2 lines · Takashi Iwai

This patch implements the same logic that was done for the legacy HD-audio controller driver by the commit 88452da92ba2 ("ALSA: hda: Use

Quoted 8 lines

looks good to me. Code review ok, SOF CI shows no regressions [1] and I did a local test with a large amount of suspend/resyme cycles on a HDA machine and no errors seen. So for these two patches:

[1] https://github.com/thesofproject/linux/pull/1625

     -> https://sof-ci.01.org/linuxpr/PR1625/build2716/devicetest/

Thanks for quick testing! Now queued these patches.

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

#4 lore raw

PATCH 2/2 ALSA: hda: Unify get_response handling

In reply to Takashi Iwai

Now most of the get_response handling became quite similar between HDA-core and legacy drivers, and the only differences are:

- the handling of extra-long polling delay for some codecs
- the debug message for the stalled communication

and both are worth to share in the common code.

This patch unifies the code into snd_hdac_bus_get_response(), and use this from the legacy get_response callback. It results in a good amount of code reduction in the end.

---
 include/sound/hda_codec.h      |  1 -
 include/sound/hdaudio.h        |  1 +
 sound/hda/hdac_controller.c    | 11 +++++++++-
 sound/pci/hda/hda_controller.c | 49 ++++--------------------------------------
 sound/pci/hda/hda_intel.c      |  2 +-
 sound/pci/hda/hda_tegra.c      |  2 +-
 sound/pci/hda/patch_ca0110.c   |  2 +-
 sound/pci/hda/patch_sigmatel.c |  2 +-
 8 files changed, 19 insertions(+), 51 deletions(-)
include/sound/hda_codec.h +0 -1
index ac18f428eda6..3ee8036f5436 100644
@@ -51,7 +51,6 @@ struct hda_bus {
 	DECLARE_BITMAP(pcm_dev_bits, SNDRV_PCM_DEVICES);
 
 	/* misc op flags */
-	unsigned int needs_damn_long_delay :1;
 	unsigned int allow_bus_reset:1;	/* allow bus reset at fatal error */
 	/* status for codec/controller */
 	unsigned int shutdown :1;	/* being unloaded */
include/sound/hdaudio.h +1 -0
index 81373a2efd96..bc2f77a6f17b 100644
@@ -338,6 +338,7 @@ struct hdac_bus {
 	bool reverse_assign:1;		/* assign devices in reverse order */
 	bool corbrp_self_clear:1;	/* CORBRP clears itself after reset */
 	bool polling_mode:1;
+	bool needs_damn_long_delay:1;
 
 	int poll_count;
 
sound/hda/hdac_controller.c +10 -1
index 61950b83b8c9..01787081552d 100644
@@ -242,6 +242,7 @@ int snd_hdac_bus_get_response(struct hdac_bus *bus, unsigned int addr,
 	unsigned long timeout;
 	unsigned long loopcounter;
 	wait_queue_entry_t wait;
+	bool warned = false;
 
 	init_wait_entry(&wait, 0);
 	timeout = jiffies + msecs_to_jiffies(1000);
@@ -264,9 +265,17 @@ int snd_hdac_bus_get_response(struct hdac_bus *bus, unsigned int addr,
 		spin_unlock_irq(&bus->reg_lock);
 		if (time_after(jiffies, timeout))
 			break;
+#define LOOP_COUNT_MAX	3000
 		if (!bus->polling_mode) {
 			schedule_timeout(msecs_to_jiffies(2));
-		} else if (loopcounter > 3000) {
+		} else if (bus->needs_damn_long_delay ||
+			   loopcounter > LOOP_COUNT_MAX) {
+			if (loopcounter > LOOP_COUNT_MAX && !warned) {
+				dev_dbg_ratelimited(bus->dev,
+						    "too slow response, last cmd=%#08x\n",
+						    bus->last_cmd[addr]);
+				warned = true;
+			}
 			msleep(2); /* temporary workaround */
 		} else {
 			udelay(10);
sound/pci/hda/hda_controller.c +4 -45

57 lines not on this page · raw message

sound/pci/hda/hda_intel.c +1 -1
index c86539cdbd4b..c7efb6f66bdc 100644
@@ -1809,7 +1809,7 @@ static int azx_create(struct snd_card *card, struct pci_dev *pci,
 
 	if (chip->driver_type == AZX_DRIVER_NVIDIA) {
 		dev_dbg(chip->card->dev, "Enable delay in RIRB handling\n");
-		chip->bus.needs_damn_long_delay = 1;
+		chip->bus.core.needs_damn_long_delay = 1;
 	}
 
 	err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
sound/pci/hda/hda_tegra.c +1 -1
index 269f242fcbfd..9d0784aed9e4 100644
@@ -394,7 +394,7 @@ static int hda_tegra_create(struct snd_card *card,
 	if (err < 0)
 		return err;
 
-	chip->bus.needs_damn_long_delay = 1;
+	chip->bus.core.needs_damn_long_delay = 1;
 
 	err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
 	if (err < 0) {
sound/pci/hda/patch_ca0110.c +1 -1
index e780922a1190..1818ce67f761 100644
@@ -53,7 +53,7 @@ static int patch_ca0110(struct hda_codec *codec)
 	codec->patch_ops = ca0110_patch_ops;
 
 	spec->multi_cap_vol = 1;
-	codec->bus->needs_damn_long_delay = 1;
+	codec->bus->core.needs_damn_long_delay = 1;
 
 	err = ca0110_parse_auto_config(codec);
 	if (err < 0)
sound/pci/hda/patch_sigmatel.c +1 -1
index 894f3f509e76..8ecb53bce509 100644
@@ -4908,7 +4908,7 @@ static int patch_stac927x(struct hda_codec *codec)
 	 * The below flag enables the longer delay (see get_response
 	 * in hda_intel.c).
 	 */
-	codec->bus->needs_damn_long_delay = 1;
+	codec->bus->core.needs_damn_long_delay = 1;
 
 	snd_hda_apply_fixup(codec, HDA_FIXUP_ACT_PROBE);
 
Signature · 6 lines
2.16.4

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