All of lore.kernel.org
 help / color / mirror / Atom feed
* azx_get_pos_skl() induced system slowness
@ 2021-08-24 17:38 Jens Axboe
  2021-08-25  6:14 ` Takashi Iwai
  0 siblings, 1 reply; 4+ messages in thread
From: Jens Axboe @ 2021-08-24 17:38 UTC (permalink / raw)
  To: perex, tiwai, kai.vehmanen, alsa-devel

Hi,

Got a new notebook recently, it's a Lenovo X1 Carbon 9th gen. Sound
works fine, but sometimes I get really stuttering playback from nestopia
and I finally decided to look into it. When this happens,
azx_get_pos_skl() is seemingly called a lot, at least it uses a ton of
CPU cycles. This comes and goes, sometimes 1 minute in between,
sometimes 2, and sometimes 30 seconds.

If I comment out the udelay() in that function it does seems to be
noticeably better, though it's not a complete fix. I guess it just
reduces the pain of calling it so many times?

This is running 5.14-rc7, but it's not a recent regression.

Any clues as to what this might be?

diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 470753b36c8a..3c1f233e463f 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -878,7 +878,9 @@ static unsigned int azx_get_pos_skl(struct azx *chip, struct azx_dev *azx_dev)
 	 * for the possible boundary overlap; the read of DPIB fetches the
 	 * actual posbuf
 	 */
+#if 0
 	udelay(20);
+#endif
 	azx_skl_get_dpib_pos(chip, azx_dev);
 	return azx_get_pos_posbuf(chip, azx_dev);
 }

-- 
Jens Axboe


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: azx_get_pos_skl() induced system slowness
  2021-08-24 17:38 azx_get_pos_skl() induced system slowness Jens Axboe
@ 2021-08-25  6:14 ` Takashi Iwai
  2021-08-25 12:33   ` Jens Axboe
  0 siblings, 1 reply; 4+ messages in thread
From: Takashi Iwai @ 2021-08-25  6:14 UTC (permalink / raw)
  To: Jens Axboe; +Cc: alsa-devel, tiwai, kai.vehmanen

On Tue, 24 Aug 2021 19:38:08 +0200,
Jens Axboe wrote:
> 
> Hi,
> 
> Got a new notebook recently, it's a Lenovo X1 Carbon 9th gen. Sound
> works fine, but sometimes I get really stuttering playback from nestopia
> and I finally decided to look into it. When this happens,
> azx_get_pos_skl() is seemingly called a lot, at least it uses a ton of
> CPU cycles. This comes and goes, sometimes 1 minute in between,
> sometimes 2, and sometimes 30 seconds.
> 
> If I comment out the udelay() in that function it does seems to be
> noticeably better, though it's not a complete fix. I guess it just
> reduces the pain of calling it so many times?
>
> This is running 5.14-rc7, but it's not a recent regression.
> 
> Any clues as to what this might be?

Are you using PulseAudio?  Or pipewire?  The former might cause lots
of position update calls when the device doesn't give back the stable
(or consistent) position report.

The code there was borrowed from the ASoC Intel Skylake driver
(sound/soc/intel/skylake/skl-pcm.c), and the same is also carried to
the recent ASoC SOF HDA driver, too.
As far as I understand from the comment, the udelay() itself could be
reduced only for the case right after the interrupt wakeup.  That is,
a hackish patch like below might help.

But, as far as I see with PulseAudio, it still results in a lot of
register read -- so PA seems repeatedly reading the position.

A better result (only from the CPU usage POV) could be gained on my
machine by just switching to another position inquiry; namely, pass
position_fix=1 option to snd-hda-intel module.  But I checked this
only for a short period, so am not sure about the long run.


thanks,

Takashi

--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -614,6 +614,7 @@ static int azx_position_check(struct azx *chip, struct azx_dev *azx_dev)
 	struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
 	int ok;
 
+	hda->in_irq_handling = 1;
 	ok = azx_position_ok(chip, azx_dev);
 	if (ok == 1) {
 		azx_dev->irq_pending = 0;
@@ -870,6 +871,8 @@ static unsigned int azx_skl_get_dpib_pos(struct azx *chip,
 /* get the current DMA position with correction on SKL+ chips */
 static unsigned int azx_get_pos_skl(struct azx *chip, struct azx_dev *azx_dev)
 {
+	struct hda_intel *hda = container_of(chip, struct hda_intel, chip);
+
 	/* DPIB register gives a more accurate position for playback */
 	if (azx_dev->core.substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
 		return azx_skl_get_dpib_pos(chip, azx_dev);
@@ -878,7 +881,10 @@ static unsigned int azx_get_pos_skl(struct azx *chip, struct azx_dev *azx_dev)
 	 * for the possible boundary overlap; the read of DPIB fetches the
 	 * actual posbuf
 	 */
-	udelay(20);
+	if (hda->in_irq_handling) {
+		udelay(20);
+		hda->in_irq_handling = 0;
+	}
 	azx_skl_get_dpib_pos(chip, azx_dev);
 	return azx_get_pos_posbuf(chip, azx_dev);
 }
diff --git a/sound/pci/hda/hda_intel.h b/sound/pci/hda/hda_intel.h
index 3fb119f09040..79ea81535a00 100644
--- a/sound/pci/hda/hda_intel.h
+++ b/sound/pci/hda/hda_intel.h
@@ -22,6 +22,7 @@ struct hda_intel {
 	/* extra flags */
 	unsigned int irq_pending_warned:1;
 	unsigned int probe_continued:1;
+	unsigned int in_irq_handling:1;
 
 	/* vga_switcheroo setup */
 	unsigned int use_vga_switcheroo:1;

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: azx_get_pos_skl() induced system slowness
  2021-08-25  6:14 ` Takashi Iwai
@ 2021-08-25 12:33   ` Jens Axboe
  2021-08-26  6:08     ` Takashi Iwai
  0 siblings, 1 reply; 4+ messages in thread
From: Jens Axboe @ 2021-08-25 12:33 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel, tiwai, kai.vehmanen

On 8/25/21 12:14 AM, Takashi Iwai wrote:
> On Tue, 24 Aug 2021 19:38:08 +0200,
> Jens Axboe wrote:
>>
>> Hi,
>>
>> Got a new notebook recently, it's a Lenovo X1 Carbon 9th gen. Sound
>> works fine, but sometimes I get really stuttering playback from nestopia
>> and I finally decided to look into it. When this happens,
>> azx_get_pos_skl() is seemingly called a lot, at least it uses a ton of
>> CPU cycles. This comes and goes, sometimes 1 minute in between,
>> sometimes 2, and sometimes 30 seconds.
>>
>> If I comment out the udelay() in that function it does seems to be
>> noticeably better, though it's not a complete fix. I guess it just
>> reduces the pain of calling it so many times?
>>
>> This is running 5.14-rc7, but it's not a recent regression.
>>
>> Any clues as to what this might be?
> 
> Are you using PulseAudio?  Or pipewire?  The former might cause lots
> of position update calls when the device doesn't give back the stable
> (or consistent) position report.

I'm using the default (mint) which is pulseaudio. But after reading your
reply, I switched to pipewire - hopefully that'll work better!

> The code there was borrowed from the ASoC Intel Skylake driver
> (sound/soc/intel/skylake/skl-pcm.c), and the same is also carried to
> the recent ASoC SOF HDA driver, too.
> As far as I understand from the comment, the udelay() itself could be
> reduced only for the case right after the interrupt wakeup.  That is,
> a hackish patch like below might help.
> 
> But, as far as I see with PulseAudio, it still results in a lot of
> register read -- so PA seems repeatedly reading the position.
> 
> A better result (only from the CPU usage POV) could be gained on my
> machine by just switching to another position inquiry; namely, pass
> position_fix=1 option to snd-hda-intel module.  But I checked this
> only for a short period, so am not sure about the long run.

Let me know if you want to test the patch or using that option, for now
I just went with pipewire and will see if that works any better.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: azx_get_pos_skl() induced system slowness
  2021-08-25 12:33   ` Jens Axboe
@ 2021-08-26  6:08     ` Takashi Iwai
  0 siblings, 0 replies; 4+ messages in thread
From: Takashi Iwai @ 2021-08-26  6:08 UTC (permalink / raw)
  To: Jens Axboe; +Cc: alsa-devel, tiwai, kai.vehmanen

On Wed, 25 Aug 2021 14:33:30 +0200,
Jens Axboe wrote:
> 
> On 8/25/21 12:14 AM, Takashi Iwai wrote:
> > On Tue, 24 Aug 2021 19:38:08 +0200,
> > Jens Axboe wrote:
> >>
> >> Hi,
> >>
> >> Got a new notebook recently, it's a Lenovo X1 Carbon 9th gen. Sound
> >> works fine, but sometimes I get really stuttering playback from nestopia
> >> and I finally decided to look into it. When this happens,
> >> azx_get_pos_skl() is seemingly called a lot, at least it uses a ton of
> >> CPU cycles. This comes and goes, sometimes 1 minute in between,
> >> sometimes 2, and sometimes 30 seconds.
> >>
> >> If I comment out the udelay() in that function it does seems to be
> >> noticeably better, though it's not a complete fix. I guess it just
> >> reduces the pain of calling it so many times?
> >>
> >> This is running 5.14-rc7, but it's not a recent regression.
> >>
> >> Any clues as to what this might be?
> > 
> > Are you using PulseAudio?  Or pipewire?  The former might cause lots
> > of position update calls when the device doesn't give back the stable
> > (or consistent) position report.
> 
> I'm using the default (mint) which is pulseaudio. But after reading your
> reply, I switched to pipewire - hopefully that'll work better!
> 
> > The code there was borrowed from the ASoC Intel Skylake driver
> > (sound/soc/intel/skylake/skl-pcm.c), and the same is also carried to
> > the recent ASoC SOF HDA driver, too.
> > As far as I understand from the comment, the udelay() itself could be
> > reduced only for the case right after the interrupt wakeup.  That is,
> > a hackish patch like below might help.
> > 
> > But, as far as I see with PulseAudio, it still results in a lot of
> > register read -- so PA seems repeatedly reading the position.
> > 
> > A better result (only from the CPU usage POV) could be gained on my
> > machine by just switching to another position inquiry; namely, pass
> > position_fix=1 option to snd-hda-intel module.  But I checked this
> > only for a short period, so am not sure about the long run.
> 
> Let me know if you want to test the patch or using that option, for now
> I just went with pipewire and will see if that works any better.

Well, I'm interested in whether pipewire really works better in this
regard, so please let me know your experience with PW, too ;)

I'm going to check this issue on my machine, and will ask you if any
test patch is ready.


thanks,

Takashi

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-08-26  6:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-24 17:38 azx_get_pos_skl() induced system slowness Jens Axboe
2021-08-25  6:14 ` Takashi Iwai
2021-08-25 12:33   ` Jens Axboe
2021-08-26  6:08     ` Takashi Iwai

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.