From mboxrd@z Thu Jan 1 00:00:00 1970 From: Takashi Iwai Subject: Re: ALSA + jack + xrun = kernel crash Date: Wed, 21 May 2003 12:33:50 +0200 Sender: alsa-devel-admin@lists.sourceforge.net Message-ID: References: <3ECAC902.4050903@student.kuleuven.ac.be> Mime-Version: 1.0 (generated by SEMI 1.14.4 - "Hosorogi") Content-Type: multipart/mixed; boundary="Multipart_Wed_May_21_12:33:50_2003-1" Return-path: In-Reply-To: <3ECAC902.4050903@student.kuleuven.ac.be> Errors-To: alsa-devel-admin@lists.sourceforge.net List-Help: List-Post: List-Subscribe: , List-Unsubscribe: , List-Archive: To: Pieter Palmers Cc: Paul Davis , Arthur Peters , Alsa dev list List-Id: alsa-devel@alsa-project.org --Multipart_Wed_May_21_12:33:50_2003-1 Content-Type: text/plain; charset=US-ASCII At Wed, 21 May 2003 02:32:02 +0200, Pieter Palmers wrote: > > Ok, second try: > > alsa 0.9.3c fresh from CVS > --------------------------------------- > /proc/asound/version: > Advanced Linux Sound Architecture Driver Version 0.9.3c. > Compiled on May 21 2003 for kernel 2.4.20-LL with versioned symbols. > > /proc/asound/cards: > 0 [AudioPCI ]: ENS1371 - Ensoniq AudioPCI > Ensoniq AudioPCI ENS1371 at 0xb000, irq 5 > > --------------------------------------- how about this one? this should fix another deadlock (including the simplified expression of stream lock) Takashi --Multipart_Wed_May_21_12:33:50_2003-1 Content-Type: application/octet-stream Content-Disposition: attachment; filename="pcm-lock-fix.dif" Content-Transfer-Encoding: 7bit Index: alsa-kernel/include/pcm.h =================================================================== RCS file: /suse/tiwai/cvs/alsa/alsa-kernel/include/pcm.h,v retrieving revision 1.35 diff -u -r1.35 pcm.h --- alsa-kernel/include/pcm.h 15 May 2003 09:46:39 -0000 1.35 +++ alsa-kernel/include/pcm.h 21 May 2003 09:54:41 -0000 @@ -388,7 +388,7 @@ snd_pcm_substream_t *next; /* -- linked substreams -- */ struct list_head link_list; /* linked list member */ - snd_pcm_group_t self_group; /* fake group for non linked substream (with substream lock inside) */ + spinlock_t lock; /* lock per stream */ snd_pcm_group_t *group; /* pointer to current group */ /* -- assigned files -- */ snd_pcm_file_t *file; @@ -578,42 +578,42 @@ static inline int snd_pcm_stream_linked(snd_pcm_substream_t *substream) { - return substream->group != &substream->self_group; + return substream->group != NULL; } static inline void snd_pcm_stream_lock(snd_pcm_substream_t *substream) { read_lock(&snd_pcm_link_rwlock); - spin_lock(&substream->self_group.lock); + spin_lock(&substream->lock); } static inline void snd_pcm_stream_unlock(snd_pcm_substream_t *substream) { - spin_unlock(&substream->self_group.lock); + spin_unlock(&substream->lock); read_unlock(&snd_pcm_link_rwlock); } static inline void snd_pcm_stream_lock_irq(snd_pcm_substream_t *substream) { read_lock_irq(&snd_pcm_link_rwlock); - spin_lock(&substream->self_group.lock); + spin_lock(&substream->lock); } static inline void snd_pcm_stream_unlock_irq(snd_pcm_substream_t *substream) { - spin_unlock(&substream->self_group.lock); + spin_unlock(&substream->lock); read_unlock_irq(&snd_pcm_link_rwlock); } #define snd_pcm_stream_lock_irqsave(substream, flags) \ do { \ read_lock_irqsave(&snd_pcm_link_rwlock, (flags)); \ - spin_lock(&substream->self_group.lock); \ + spin_lock(&substream->lock); \ } while (0) #define snd_pcm_stream_unlock_irqrestore(substream, flags) \ do { \ - spin_unlock(&substream->self_group.lock); \ + spin_unlock(&substream->lock); \ read_unlock_irqrestore(&snd_pcm_link_rwlock, (flags)); \ } while (0) Index: alsa-kernel/core/pcm.c =================================================================== RCS file: /suse/tiwai/cvs/alsa/alsa-kernel/core/pcm.c,v retrieving revision 1.28 diff -u -r1.28 pcm.c --- alsa-kernel/core/pcm.c 5 May 2003 10:09:09 -0000 1.28 +++ alsa-kernel/core/pcm.c 21 May 2003 10:06:04 -0000 @@ -593,10 +593,8 @@ snd_magic_kfree(substream); return err; } - substream->group = &substream->self_group; - spin_lock_init(&substream->self_group.lock); - INIT_LIST_HEAD(&substream->self_group.substreams); - list_add_tail(&substream->link_list, &substream->self_group.substreams); + substream->group = NULL; + INIT_LIST_HEAD(&substream->link_list); spin_lock_init(&substream->timer_lock); prev = substream; } Index: alsa-kernel/core/pcm_native.c =================================================================== RCS file: /suse/tiwai/cvs/alsa/alsa-kernel/core/pcm_native.c,v retrieving revision 1.52 diff -u -r1.52 pcm_native.c --- alsa-kernel/core/pcm_native.c 20 May 2003 08:43:44 -0000 1.52 +++ alsa-kernel/core/pcm_native.c 21 May 2003 10:27:21 -0000 @@ -624,7 +624,7 @@ snd_pcm_group_for_each(pos, substream) { s = snd_pcm_group_substream_entry(pos); if (s != substream) - spin_lock(&s->self_group.lock); + spin_lock(&s->lock); res = ops->pre_action(s, state); if (res < 0) break; @@ -640,7 +640,7 @@ ops->post_action(s, state); } if (s != substream) - spin_unlock(&s->self_group.lock); + spin_unlock(&s->lock); } } else { snd_pcm_substream_t *s1; @@ -648,7 +648,7 @@ snd_pcm_group_for_each(pos, substream) { s1 = snd_pcm_group_substream_entry(pos); if (s1 != substream) - spin_unlock(&s1->self_group.lock); + spin_unlock(&s1->lock); if (s1 == s) /* end */ break; } @@ -686,9 +686,9 @@ if (snd_pcm_stream_linked(substream)) { if (!spin_trylock(&substream->group->lock)) { - spin_unlock(&substream->self_group.lock); + spin_unlock(&substream->lock); spin_lock(&substream->group->lock); - spin_lock(&substream->self_group.lock); + spin_lock(&substream->lock); } res = snd_pcm_action_group(ops, substream, state); spin_unlock(&substream->group->lock); @@ -710,14 +710,14 @@ read_lock_irq(&snd_pcm_link_rwlock); if (snd_pcm_stream_linked(substream)) { spin_lock(&substream->group->lock); - spin_lock(&substream->self_group.lock); + spin_lock(&substream->lock); res = snd_pcm_action_group(ops, substream, state); - spin_unlock(&substream->self_group.lock); + spin_unlock(&substream->lock); spin_unlock(&substream->group->lock); } else { - spin_lock(&substream->self_group.lock); + spin_lock(&substream->lock); res = snd_pcm_action_single(ops, substream, state); - spin_unlock(&substream->self_group.lock); + spin_unlock(&substream->lock); } read_unlock_irq(&snd_pcm_link_rwlock); return res; @@ -1136,23 +1136,17 @@ if (snd_pcm_stream_linked(substream)) { if (!spin_trylock(&substream->group->lock)) { - spin_unlock(&substream->self_group.lock); + spin_unlock(&substream->lock); spin_lock(&substream->group->lock); - spin_lock(&substream->self_group.lock); + spin_lock(&substream->lock); } snd_pcm_group_for_each(pos, substream) { s = snd_pcm_group_substream_entry(pos); if (s != substream) - spin_lock(&substream->self_group.lock); - } - snd_pcm_group_for_each(pos, substream) { - s = snd_pcm_group_substream_entry(pos); + spin_lock(&s->lock); s->runtime->status->state = state; - } - snd_pcm_group_for_each(pos, substream) { - s = snd_pcm_group_substream_entry(pos); if (s != substream) - spin_unlock(&substream->self_group.lock); + spin_unlock(&s->lock); } spin_unlock(&substream->group->lock); } else { @@ -1485,13 +1479,6 @@ return res; } -static void relink_to_local(snd_pcm_substream_t *substream) -{ - substream->group = &substream->self_group; - INIT_LIST_HEAD(&substream->self_group.substreams); - list_add_tail(&substream->link_list, &substream->self_group.substreams); -} - static int snd_pcm_unlink(snd_pcm_substream_t *substream) { struct list_head *pos; @@ -1509,12 +1496,13 @@ } if (count == 1) { /* detach the last stream, too */ snd_pcm_group_for_each(pos, substream) { - relink_to_local(snd_pcm_group_substream_entry(pos)); + snd_pcm_substream_t *s = snd_pcm_group_substream_entry(pos); + s->group = NULL; break; } kfree(substream->group); } - relink_to_local(substream); + substream->group = NULL; _end: write_unlock_irq(&snd_pcm_link_rwlock); return 0; --Multipart_Wed_May_21_12:33:50_2003-1-- ------------------------------------------------------- This SF.net email is sponsored by: ObjectStore. If flattening out C++ or Java code to make your application fit in a relational database is painful, don't do it! Check out ObjectStore. Now part of Progress Software. http://www.objectstore.net/sourceforge