Skip to contentSkip to conversation

.hw_free() while audio is running ??

DISCUSSION Giuliano Pochini 2 participants 6 messages Aug 8, 2004 – Aug 26, 2004

lore
Share & tools
lore
#0 lore raw

It happened that the hw_free() callback was called for a running substream. System freezed. I had a look to the other drivers and none of them seems to take into account this possibility and my driver also doesn't support it. If it's my fault, please ignore the following.

Some details:

The call sequence in the logs is:

pcm_trigger (start) - of two synced ss's
pcm_hw_free (playback ss)
Crash, nothing more in the logs :(

trigger(stop) wasn't called before hw_free.

I was attempting to write a program that plays and records at the same time with synced substreams and that program is an awful pile of bugs :)

Alsa-lib 1.0.4
Alsa-driver 1.0.6rc1
Linux 2.6.7
Gcc 3.4.1 (ppc 7455)

--
Giuliano.

-------------------------------------------------------
This SF.Net email is sponsored by OSTG. Have you noticed the changes on Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now, one more big change to announce. We are now OSTG- Open Source Technology Group. Come see the changes on the new OSTG site. www.ostg.com

#1 lore raw
Quoted 7 lines · Giuliano Pochini

It happened that the hw_free() callback was called for a running substream. System freezed. I had a look to the other drivers and none of them seems to take into account this possibility and my driver also doesn't support it. If it's my fault, please ignore the following.

Some details:

Quoted 7 lines

The call sequence in the logs is:

pcm_trigger (start) - of two synced ss's
pcm_hw_free (playback ss)
Crash, nothing more in the logs :(

trigger(stop) wasn't called before hw_free.

You have an SMP machine? The hw_free is protected with the runtime->status->state checking, but the code is not protected with spinlock, so I suspect trouble here.

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SUSE Labs

-------------------------------------------------------
This SF.Net email is sponsored by OSTG. Have you noticed the changes on Linux.com, ITManagersJournal and NewsForge in the past few weeks? Now, one more big change to announce. We are now OSTG- Open Source Technology Group. Come see the changes on the new OSTG site. www.ostg.com

#2 lore raw
Quoted 11 lines · On Sun, 8 Aug 2004 22:39:57 +0200 (CEST) Jaroslav Kysela <[email protected]> wrote:
Quoted 7 lines

The call sequence in the logs is:

pcm_trigger (start) - of two synced ss's
pcm_hw_free (playback ss)
Crash, nothing more in the logs :(

trigger(stop) wasn't called before hw_free.

You have an SMP machine? The hw_free is protected with the runtime->status->state checking, but the code is not protected with spinlock, so I suspect trouble here.

Yes, this is a dual processor, but I booted with maxcpus=1 and preempt is not enabled.

--
Giuliano.

-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285

#3 lore raw
Quoted 9 lines · Giuliano Pochini
Quoted 6 lines · On Sun, 8 Aug 2004 22:39:57 +0200 (CEST) Jaroslav Kysela <[email protected]> wrote:
Quoted 6 lines

The call sequence in the logs is:

pcm_trigger (start) - of two synced ss's
pcm_hw_free (playback ss)
Crash, nothing more in the logs :(

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

trigger(stop) wasn't called before hw_free.

You have an SMP machine? The hw_free is protected with the runtime->status->state checking, but the code is not protected with spinlock, so I suspect trouble here.

Yes, this is a dual processor, but I booted with maxcpus=1 and preempt is not enabled.

Could you try the attached patch, if it helps?

Jaroslav

-----
Jaroslav Kysela <[email protected]>
Linux Kernel Sound Maintainer
ALSA Project, SUSE Labs

Index: pcm_native.c
===================================================================
RCS file: /cvsroot/alsa/alsa-kernel/core/pcm_native.c,v retrieving revision 1.102

pcm_native.c +22 -3
diff -u -r1.102 pcm_native.c
@@ -339,14 +339,17 @@
 	snd_assert(substream != NULL, return -ENXIO);
 	runtime = substream->runtime;
 	snd_assert(runtime != NULL, return -ENXIO);
+	snd_pcm_stream_lock_irq(substream);
 	switch (runtime->status->state) {
 	case SNDRV_PCM_STATE_OPEN:
 	case SNDRV_PCM_STATE_SETUP:
 	case SNDRV_PCM_STATE_PREPARED:
 		break;
 	default:
+		snd_pcm_stream_unlock_irq(substream);
 		return -EBADFD;
 	}
+	snd_pcm_stream_unlock_irq(substream);
 #if defined(CONFIG_SND_PCM_OSS) || defined(CONFIG_SND_PCM_OSS_MODULE)
 	if (!substream->oss.oss)
 #endif
@@ -452,13 +455,16 @@
 	snd_assert(substream != NULL, return -ENXIO);
 	runtime = substream->runtime;
 	snd_assert(runtime != NULL, return -ENXIO);
+	snd_pcm_stream_lock_irq(substream);
 	switch (runtime->status->state) {
 	case SNDRV_PCM_STATE_SETUP:
 	case SNDRV_PCM_STATE_PREPARED:
 		break;
 	default:
+		snd_pcm_stream_unlock_irq(substream);
 		return -EBADFD;
 	}
+	snd_pcm_stream_unlock_irq(substream);
 	if (atomic_read(&runtime->mmap_count))
 		return -EBADFD;
 	if (substream->ops->hw_free == NULL) {
@@ -473,11 +479,16 @@
 static int snd_pcm_sw_params(snd_pcm_substream_t * substream, snd_pcm_sw_params_t *params)
 {
 	snd_pcm_runtime_t *runtime;
+
 	snd_assert(substream != NULL, return -ENXIO);
 	runtime = substream->runtime;
 	snd_assert(runtime != NULL, return -ENXIO);
-	if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
+	snd_pcm_stream_unlock_irq(substream);
+	if (runtime->status->state == SNDRV_PCM_STATE_OPEN) {
+		snd_pcm_stream_unlock_irq(substream);
 		return -EBADFD;
+	}
+	snd_pcm_stream_unlock_irq(substream);
 
 	if (params->tstamp_mode > SNDRV_PCM_TSTAMP_LAST)
 		return -EINVAL;
@@ -605,8 +616,12 @@
 		return -EFAULT;
 	channel = info.channel;
 	runtime = substream->runtime;
-	if (runtime->status->state == SNDRV_PCM_STATE_OPEN)
+	snd_pcm_stream_lock_irq(substream);
+	if (runtime->status->state == SNDRV_PCM_STATE_OPEN) {
+		snd_pcm_stream_unlock_irq(substream);
 		return -EBADFD;
+	}
+	snd_pcm_stream_unlock_irq(substream);
 	if (channel >= runtime->channels)
 		return -EINVAL;
 	memset(&info, 0, sizeof(info));
@@ -1496,8 +1511,12 @@
 	snd_pcm_file_t *pcm_file;
 	snd_pcm_substream_t *substream1;
 
-	if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN)
+	snd_pcm_stream_lock_irq(substream);
+	if (substream->runtime->status->state == SNDRV_PCM_STATE_OPEN) {
+		snd_pcm_stream_unlock_irq(substream);
 		return -EBADFD;
+	}
+	snd_pcm_stream_unlock_irq(substream);
 	file = snd_pcm_file_fd(fd);
 	if (!file)
 		return -EBADFD;
#4 lore raw
Quoted 8 lines · On Tue, 10 Aug 2004 11:25:05 +0200 (CEST) Jaroslav Kysela <[email protected]> wrote:
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines

The call sequence in the logs is:

pcm_trigger (start) - of two synced ss's
pcm_hw_free (playback ss)
Crash, nothing more in the logs :(

trigger(stop) wasn't called before hw_free.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

You have an SMP machine? The hw_free is protected with the runtime->status->state checking, but the code is not protected with spinlock, so I suspect trouble here.

Yes, this is a dual processor, but I booted with maxcpus=1 and preempt is not enabled.

Could you try the attached patch, if it helps?

Nope, it freezes the box as soon as I try to play something. Anyway, the problem I reported is quite difficult to trigger because I wasn't able to make it happen again.

--
Giuliano.

-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media 100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33 Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285

#5 lore raw
In reply to Jaroslav Kysela
Quoted 7 lines · On Tue, 10 Aug 2004 11:25:05 +0200 (CEST) Jaroslav Kysela <[email protected]> wrote:
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

The call sequence in the logs is:

pcm_trigger (start) - of two synced ss's
pcm_hw_free (playback ss)
Crash, nothing more in the logs :(

trigger(stop) wasn't called before hw_free.

I investigated a little further. Attached is a version of my bugly program that crashes the system quite reliably. Usually less than 10 attempts are enough. The log above is dumped by my driver for Echoaudio cards which is not included in ALSA yet. When I use the snd-powermac driver it crashes, too, but it doesn't write anything in the logs. After a crash it's still possible to use sysctl- commands (except one time when it crashed with sig11 inside the irq handler, probably because it deallocated the substream structure).

Compile with: cc -lasound playrec.c
Crash with: ./a.out :))

I think it dies at the end of the loop at the "BOOM" comment, when the i/o buffers are full/empty.

My config:

Linux Jay 2.6.8.1 #2 SMP Wed Aug 18 15:14:51 CEST 2004 ppc unknown booted with maxcpus=1 and without preempt. alsa-driver-1.0.6a
alsa-lib-1.0.4
gcc 3.4.1

--
Giuliano.