All of lore.kernel.org
 help / color / mirror / Atom feed
* cmipci and sound skipping ?
@ 2010-03-13 20:11 Matija Nalis
  2010-03-15 12:17 ` Clemens Ladisch
  0 siblings, 1 reply; 5+ messages in thread
From: Matija Nalis @ 2010-03-13 20:11 UTC (permalink / raw)
  To: alsa-devel

My card is "Asonic C-Media8738, 4 channel" and mostly works with snd_cmipci
driver - it is just that (even on completely unloaded system) the sound is
(very annoyingly) skipping. The speaker-test application throws out "Write
error: -32,Broken pipe" errors on every skip (usually every 5-30 times a
wav is played). mpg321 is much worse (every few seconds it clips the sample)
making the listening to music unedurable.

I'm using Debian Lenny with kernel 2.6.26 (also tried 2.6.32, no change)
I've upgraded to the latest snapshot of driver, lib and utils as
recommended, the bug is still there. When driver is compiled with debug, on
every skip it throws out lines in dmesg with info as:

ALSA pcm_lib.c:316: BUG: pcmC0D0p:0, pos = 4294918144, buffer size = 16384, period size = 1024

Note that the pos is *always* the same (4294918144 = 0xffff4000 = -16384) which might be important.

I've reported the problem in bug #4899 at
https://bugtrack.alsa-project.org/alsa-bug/view.php?id=4899
(alsa-info.sh and more is attached there)

There I got pointer to contact the alsa-devel list with XRUN_Debug info.

So here it is. When I enable it with "echo 101 > /proc/asound/card0/pcm0p/xrun_debug"
I get the following output :

[33802.573395] ALSA pcm_lib.c:249: hwptr log: pcmC0D0p:0: j=4302816904, pos=1037/1024/16384, hwptr=230413/229376
[33802.573395] ALSA pcm_lib.c:249: hwptr log: pcmC0D0p:0: j=4302816909, pos=2052/1024/16384, hwptr=230413/229376
[33802.573395] ALSA pcm_lib.c:249: hwptr log: pcmC0D0p:0: j=4302816909, pos=2053/1024/16384, hwptr=231428/229376
[33802.573395] ALSA pcm_lib.c:249: hwptr log: pcmC0D0p:0: j=4302816909, pos=2053/1024/16384, hwptr=231429/229376
[33802.573395] ALSA pcm_lib.c:249: hwptr log: pcmC0D0p:0: j=4302816909, pos=2053/1024/16384, hwptr=231429/229376
[33802.573395] ALSA pcm_lib.c:249: hwptr log: pcmC0D0p:0: j=4302816909, pos=2053/1024/16384, hwptr=231429/229376
[33802.573395] ALSA pcm_lib.c:249: hwptr log: pcmC0D0p:0: j=4302816909, pos=2061/1024/16384, hwptr=231429/229376
[33802.573395] ALSA pcm_lib.c:249: hwptr log: pcmC0D0p:0: j=4302816909, pos=2061/1024/16384, hwptr=231437/229376
[33802.573395] ALSA pcm_lib.c:249: hwptr log: pcmC0D0p:0: j=4302816914, pos=3076/1024/16384, hwptr=231437/229376
[33802.573395] ALSA pcm_lib.c:249: hwptr log: pcmC0D0p:0: j=4302816914, pos=3076/1024/16384, hwptr=232452/229376
[33802.573395] ALSA pcm_lib.c:316: BUG: pcmC0D0p:0, pos = 4294918144, buffer size = 16384, period size = 1024
[33802.573395] ALSA pcm_lib.c:415: PCM: hw_ptr skipping! (pos=0, delta=13308, period=1024, jdelta=0/69/0, hw_ptr=232452/232452)
[33806.867658] ALSA pcm_lib.c:316: BUG: pcmC0D0p:0, pos = 4294918144, buffer size = 16384, period size = 1024
[33806.867666] ALSA pcm_lib.c:415: PCM: hw_ptr skipping! (pos=0, delta=16380, period=1024, jdelta=0/85/0, hw_ptr=425988/425988)

Also it seems that enabling xrun_debug kludges around the bug - the
annoying skipping (and "Write error: -32,Broken pipe" errors in
speaker-test) disappears or at least becomes almost inaudiable.

Would some other xrun_debug setting be more useful to give better insight ?
Anything else I can provide or test to help debug the problem ?

Please CC: me as I'm not subscribed to the list.

-- 
Opinions above are GNU-copylefted.

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

* Re: cmipci and sound skipping ?
  2010-03-13 20:11 cmipci and sound skipping ? Matija Nalis
@ 2010-03-15 12:17 ` Clemens Ladisch
  2010-03-15 19:35   ` Matija Nalis
  0 siblings, 1 reply; 5+ messages in thread
From: Clemens Ladisch @ 2010-03-15 12:17 UTC (permalink / raw)
  To: Matija Nalis; +Cc: alsa-devel

Matija Nalis wrote:
> My card is "Asonic C-Media8738, 4 channel" and mostly works with snd_cmipci
> driver - it is just that (even on completely unloaded system) the sound is
> (very annoyingly) skipping.
> ...
> ALSA pcm_lib.c:316: BUG: pcmC0D0p:0, pos = 4294918144, buffer size = 16384, period size = 1024
> 
> Note that the pos is *always* the same (4294918144 = 0xffff4000 = -16384) which might be important.

This looks like a hardware bug.

It's possible that we can get a valid pointer by reading the register
multiple times.  Please try the patch below.


Regards
Clemens


diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index 1ded64e..8416b8a 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -941,13 +941,21 @@ static snd_pcm_uframes_t snd_cmipci_pcm_pointer(struct cmipci *cm, struct cmipci
 						struct snd_pcm_substream *substream)
 {
 	size_t ptr;
-	unsigned int reg;
+	unsigned int reg, rem, tries;
+
 	if (!rec->running)
 		return 0;
 #if 1 // this seems better..
 	reg = rec->ch ? CM_REG_CH1_FRAME2 : CM_REG_CH0_FRAME2;
-	ptr = rec->dma_size - (snd_cmipci_read_w(cm, reg) + 1);
-	ptr >>= rec->shift;
+	for (tries = 0; tries < 5; tries++) {
+		rem = snd_cmipci_read_w(cm, reg);
+		if (rem < rec->dma_size)
+			goto ok;
+	} 
+	printk(KERN_ERR "cmipci: invalid PCM pointer: %#x\n", rem);
+	return SNDRV_PCM_POS_XRUN;
+ok:
+	ptr = (rec->dma_size - (rem + 1)) >> rec->shift;
 #else
 	reg = rec->ch ? CM_REG_CH1_FRAME1 : CM_REG_CH0_FRAME1;
 	ptr = snd_cmipci_read(cm, reg) - rec->offset;

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

* Re: cmipci and sound skipping ?
  2010-03-15 12:17 ` Clemens Ladisch
@ 2010-03-15 19:35   ` Matija Nalis
  2010-03-23  8:36     ` Clemens Ladisch
  0 siblings, 1 reply; 5+ messages in thread
From: Matija Nalis @ 2010-03-15 19:35 UTC (permalink / raw)
  To: Clemens Ladisch; +Cc: alsa-devel

On Mon, Mar 15, 2010 at 01:17:20PM +0100, Clemens Ladisch wrote:
> Matija Nalis wrote:
> > My card is "Asonic C-Media8738, 4 channel" and mostly works with snd_cmipci
> > driver - it is just that (even on completely unloaded system) the sound is
> > (very annoyingly) skipping.
> > ...
> > ALSA pcm_lib.c:316: BUG: pcmC0D0p:0, pos = 4294918144, buffer size = 16384, period size = 1024
> > 
> > Note that the pos is *always* the same (4294918144 = 0xffff4000 = -16384) which might be important.
> 
> This looks like a hardware bug.
> 
> It's possible that we can get a valid pointer by reading the register
> multiple times.  Please try the patch below.

Thanks Clemens, that patch seems to have fixed it !

-- 
Opinions above are GNU-copylefted.

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

* Re: cmipci and sound skipping ?
  2010-03-15 19:35   ` Matija Nalis
@ 2010-03-23  8:36     ` Clemens Ladisch
       [not found]       ` <20100323201749.GA4675@eagle102.home.lan>
  0 siblings, 1 reply; 5+ messages in thread
From: Clemens Ladisch @ 2010-03-23  8:36 UTC (permalink / raw)
  To: Matija Nalis; +Cc: alsa-devel

Matija Nalis wrote:
> On Mon, Mar 15, 2010 at 01:17:20PM +0100, Clemens Ladisch wrote:
> > Please try the patch below.
> 
> Thanks Clemens, that patch seems to have fixed it !

Are you okay with your email address (which one?) to be published with
the patch:
  Reported-and-tested-by: Matija Nalis <...>


Regards,
Clemens

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

* Re: cmipci and sound skipping ?
       [not found]       ` <20100323201749.GA4675@eagle102.home.lan>
@ 2010-03-24  6:57         ` Clemens Ladisch
  0 siblings, 0 replies; 5+ messages in thread
From: Clemens Ladisch @ 2010-03-24  6:57 UTC (permalink / raw)
  To: Matija Nalis; +Cc: alsa-devel

Matija Nalis wrote:
> On Tue, Mar 23, 2010 at 09:36:01AM +0100, Clemens Ladisch wrote:
> > Are you okay with your email address (which one?) to be published with
> > the patch:
> >   Reported-and-tested-by: Matija Nalis <...>
> 
> Sure, mnalis-alsadev @ voyager.hr would be ok for e-mail.

Applied.


Thanks!
Clemens

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

end of thread, other threads:[~2010-03-24  6:57 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-13 20:11 cmipci and sound skipping ? Matija Nalis
2010-03-15 12:17 ` Clemens Ladisch
2010-03-15 19:35   ` Matija Nalis
2010-03-23  8:36     ` Clemens Ladisch
     [not found]       ` <20100323201749.GA4675@eagle102.home.lan>
2010-03-24  6:57         ` Clemens Ladisch

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.