Skip to contentSkip to conversation

ALSA - Replace msleep() with usleep_range() to save module loading time

PATCH In review Wang Xingchao 3 participants 3 messages Dec 10, 2012 – Dec 12, 2012 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ALSA - Replace msleep() with usleep_range() to save module loading time

msleep(1) is not so accurate and may cause almost 15ms delay in azx_reset(). usleep_range() can reduce ~30ms loading time for Intel Haswell which has two HDA controllers.

---
 sound/pci/hda/hda_intel.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
sound/pci/hda/hda_intel.c +4 -4
index eb48109..865df90 100644
@@ -1075,22 +1075,22 @@ static int azx_reset(struct azx *chip, int full_reset)
 
 	count = 50;
 	while (azx_readb(chip, GCTL) && --count)
-		msleep(1);
+		usleep_range(1000, 1500);
 
 	/* delay for >= 100us for codec PLL to settle per spec
 	 * Rev 0.9 section 5.5.1
 	 */
-	msleep(1);
+	usleep_range(1000, 1500);
 
 	/* Bring controller out of reset */
 	azx_writeb(chip, GCTL, azx_readb(chip, GCTL) | ICH6_GCTL_RESET);
 
 	count = 50;
 	while (!azx_readb(chip, GCTL) && --count)
-		msleep(1);
+		usleep_range(1000, 1500);
 
 	/* Brent Chartrand said to wait >= 540us for codecs to initialize */
-	msleep(1);
+	usleep_range(1000, 1500);
 
       __skip:
 	/* check to see if controller is ready */
Signature · 1 line
1.7.9.5
#1 lore raw

At Mon, 10 Dec 2012 14:20:32 +0800,

Quoted 6 lines · Wang Xingchao

msleep(1) is not so accurate and may cause almost 15ms delay in azx_reset(). usleep_range() can reduce ~30ms loading time for Intel Haswell which has two HDA controllers.

Actually 1m is chosen as the smallest positive number for msleep, and it doesn't mean that we need to wait for 1ms at least. It could be shorter than that if you care about the speed.

So, I'd suggest to change the value to a smaller one, and change the timeout check instead of counting the loop but a more objective way, e.g. checking jiffies, in order to get further reduction.

For example, in the code below...

Quoted 10 lines
---
 sound/pci/hda/hda_intel.c |    8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
sound/pci/hda/hda_intel.c +0 -0
index eb48109..865df90 100644
@@ -1075,22 +1075,22 @@ static int azx_reset(struct azx *chip, int full_reset)
 

sound/pci/hda/hda_intel.c static int azx_reset(struct azx *chip, int full_reset) · line 1083

Quoted 10 lines
sound/pci/hda/hda_intel.c +2 -2
 	count = 50;
 	while (azx_readb(chip, GCTL) && --count)
-		msleep(1);
+		usleep_range(1000, 1500);
 
 	/* delay for >= 100us for codec PLL to settle per spec
 	 * Rev 0.9 section 5.5.1
 	 */
-	msleep(1);
+	usleep_range(1000, 1500);

This can be reduced obviously, if we trust the comment.

thanks,

Takashi

Quoted 18 lines
sound/pci/hda/hda_intel.c +2 -2
 	/* Bring controller out of reset */
 	azx_writeb(chip, GCTL, azx_readb(chip, GCTL) | ICH6_GCTL_RESET);
 
 	count = 50;
 	while (!azx_readb(chip, GCTL) && --count)
-		msleep(1);
+		usleep_range(1000, 1500);
 
 	/* Brent Chartrand said to wait >= 540us for codecs to initialize */
-	msleep(1);
+	usleep_range(1000, 1500);
 
       __skip:
 	/* check to see if controller is ready */
Signature · 1 line
1.7.9.5
#2 lore raw
Quoted 5 lines

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Monday, December 10, 2012 4:18 PM

Quoted 8 lines

Actually 1m is chosen as the smallest positive number for msleep, and it doesn't mean that we need to wait for 1ms at least. It could be shorter than that if you care about the speed.

So, I'd suggest to change the value to a smaller one, and change the timeout check instead of counting the loop but a more objective way, e.g. checking jiffies, in order to get further reduction.

Hi Takashi,

The 2nd version of patch was sent according to your suggestion. Would you please have a check? The title is "[PATCH v2 1/1] ALSA: hda - use usleep_range in link reset and change timeout check".

The new patch
- reduced the time for each usleep to 500us
- set a 100ms timeout for both entering and exiting link reset.
- still leave a big margin for the codec PLL to settle and codec initialization for safety consideration.

Thanks
Mengdong