From: Takashi Iwai Subject: Re: Linux 2.6.14: Total lockup using aplaymidi Date: Wed, 02 Nov 2005 21:06:49 +0100 Message-ID: References: <20051102182951.13206.qmail@web52912.mail.yahoo.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: multipart/mixed; boundary="Multipart_Wed_Nov__2_21:06:49_2005-1" Return-path: In-Reply-To: Sender: alsa-devel-admin@lists.sourceforge.net Errors-To: alsa-devel-admin@lists.sourceforge.net List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , List-Archive: To: Chris Rankin Cc: Lee Revell , alsa-devel@lists.sourceforge.net List-Id: alsa-devel@alsa-project.org --Multipart_Wed_Nov__2_21:06:49_2005-1 Content-Type: text/plain; charset=ISO-2022-JP At Wed, 02 Nov 2005 19:41:48 +0100, 私 wrote: > > At Wed, 2 Nov 2005 18:29:51 +0000 (GMT), > Chris Rankin wrote: > > > > --- Takashi Iwai wrote: > > > Which rmmod triggers the oops? > > > Apparently, the udev is who starts asfxload during rmmod. Please show > > > up the configuration, too, in order to check the condition. > > > > $ cat /etc/dev.d/snd/controlC0/alsa.dev > > #!/bin/sh -e > > exec /usr/sbin/alsactl restore 0 > > > > $ cat /etc/dev.d/snd/midiC0D1/alsa.dev > > #!/bin/sh -e > > exec /usr/bin/asfxload /usr/lib/sfbank/8mbgmsfx.sf2 > > Hmm, it means that the device is recreated again at unloading? > IOW, the module is re-inserted during or shortly after unloading. > > I remember such behavior is triggered when alsa-lib is built without > --disable-aload configure option once on my system. > > Anyway, could you run rmmod manually just like your script and check > the soft lockup at each rmmod? Above all, please check whether the problem at unloading happens, too, if the system timer is used instead of rtctimer. I guess it's related to rtctimer, though. Also, the below is an improved patch for the timer deadlock. Please give a shot. Takashi --Multipart_Wed_Nov__2_21:06:49_2005-1 Content-Type: application/octet-stream; type=patch Content-Disposition: attachment; filename="timer-deadlock-fix2.diff" Content-Transfer-Encoding: 7bit Index: alsa-kernel/core/timer.c =================================================================== RCS file: /home/iwai/cvs/alsa/alsa-kernel/core/timer.c,v retrieving revision 1.67 diff -u -r1.67 timer.c --- alsa-kernel/core/timer.c 12 Oct 2005 16:36:55 -0000 1.67 +++ alsa-kernel/core/timer.c 2 Nov 2005 20:04:48 -0000 @@ -421,9 +421,20 @@ spin_unlock_irqrestore(&timer->lock, flags); } +#define call_timer_hw(action,timer,flags) do { \ + if ((timer)->hw.flags & SNDRV_TIMER_HW_NONATOMIC) \ + spin_unlock_irqrestore(&(timer)->lock, flags); \ + (timer)->hw.action(timer); \ + if ((timer)->hw.flags & SNDRV_TIMER_HW_NONATOMIC) \ + spin_lock_irqsave(&(timer)->lock, flags); \ +} while (0) + static int snd_timer_start1(snd_timer_t *timer, snd_timer_instance_t *timeri, unsigned long sticks) { + unsigned long flags; + + spin_lock_irqsave(&timer->lock, flags); list_del(&timeri->active_list); list_add_tail(&timeri->active_list, &timer->active_list_head); if (timer->running) { @@ -431,13 +442,18 @@ goto __start_now; timer->flags |= SNDRV_TIMER_FLG_RESCHED; timeri->flags |= SNDRV_TIMER_IFLG_START; + spin_unlock_irqrestore(&timer->lock, flags); return 1; /* delayed start */ } else { timer->sticks = sticks; - timer->hw.start(timer); + if (timer->state == SNDRV_TIMER_STATE_RUNNING) + call_timer_hw(stop, timer, flags); + call_timer_hw(start, timer, flags); + timer->state = SNDRV_TIMER_STATE_RUNNING; __start_now: timer->running++; timeri->flags |= SNDRV_TIMER_IFLG_RUNNING; + spin_unlock_irqrestore(&timer->lock, flags); return 0; } } @@ -477,8 +493,8 @@ spin_lock_irqsave(&timer->lock, flags); timeri->ticks = timeri->cticks = ticks; timeri->pticks = 0; - result = snd_timer_start1(timer, timeri, ticks); spin_unlock_irqrestore(&timer->lock, flags); + result = snd_timer_start1(timer, timeri, ticks); snd_timer_notify1(timeri, SNDRV_TIMER_EVENT_START); return result; } @@ -488,6 +504,7 @@ { snd_timer_t *timer; unsigned long flags; + int state; snd_assert(timeri != NULL, return -ENXIO); @@ -505,21 +522,28 @@ spin_lock_irqsave(&timer->lock, flags); list_del_init(&timeri->ack_list); list_del_init(&timeri->active_list); - if ((timeri->flags & SNDRV_TIMER_IFLG_RUNNING) && - !(--timer->running)) { - timer->hw.stop(timer); - if (timer->flags & SNDRV_TIMER_FLG_RESCHED) { + state = timer->state; + if (timeri->flags & SNDRV_TIMER_IFLG_RUNNING) + timer->running--; + if (! timer->running) { + state = SNDRV_TIMER_STATE_STOP; + if (timer->state != state && + (timer->flags & SNDRV_TIMER_FLG_RESCHED)) { timer->flags &= ~SNDRV_TIMER_FLG_RESCHED; snd_timer_reschedule(timer, 0); if (timer->flags & SNDRV_TIMER_FLG_CHANGE) { timer->flags &= ~SNDRV_TIMER_FLG_CHANGE; - timer->hw.start(timer); + state = SNDRV_TIMER_STATE_RUNNING; } } } if (!keep_flag) timeri->flags &= ~(SNDRV_TIMER_IFLG_RUNNING | SNDRV_TIMER_IFLG_START); + if (state != timer->state) { + call_timer_hw(stop, timer, flags); + timer->state = SNDRV_TIMER_STATE_STOP; + } spin_unlock_irqrestore(&timer->lock, flags); __end: if (event != SNDRV_TIMER_EVENT_RESOLUTION) @@ -569,8 +593,8 @@ if (!timeri->cticks) timeri->cticks = 1; timeri->pticks = 0; - result = snd_timer_start1(timer, timeri, timer->sticks); spin_unlock_irqrestore(&timer->lock, flags); + result = snd_timer_start1(timer, timeri, timer->sticks); snd_timer_notify1(timeri, SNDRV_TIMER_EVENT_CONTINUE); return result; } @@ -719,17 +743,24 @@ snd_timer_reschedule(timer, ticks_left); if (timer->running) { if (timer->hw.flags & SNDRV_TIMER_HW_STOP) { - timer->hw.stop(timer); + if (! (timer->hw.flags & SNDRV_TIMER_HW_NONATOMIC)) { + timer->hw.stop(timer); + timer->state = SNDRV_TIMER_STATE_STOP; + } timer->flags |= SNDRV_TIMER_FLG_CHANGE; } if (!(timer->hw.flags & SNDRV_TIMER_HW_AUTO) || (timer->flags & SNDRV_TIMER_FLG_CHANGE)) { /* restart timer */ timer->flags &= ~SNDRV_TIMER_FLG_CHANGE; - timer->hw.start(timer); + if (! (timer->hw.flags & SNDRV_TIMER_HW_NONATOMIC)) { + timer->hw.start(timer); + timer->state = SNDRV_TIMER_STATE_RUNNING; + } } - } else { + } else if (! (timer->hw.flags & SNDRV_TIMER_HW_NONATOMIC)) { timer->hw.stop(timer); + timer->state = SNDRV_TIMER_STATE_STOP; } /* now process all fast callbacks */ Index: alsa-kernel/include/timer.h =================================================================== RCS file: /home/iwai/cvs/alsa/alsa-kernel/include/timer.h,v retrieving revision 1.14 diff -u -r1.14 timer.h --- alsa-kernel/include/timer.h 12 Oct 2005 16:36:55 -0000 1.14 +++ alsa-kernel/include/timer.h 2 Nov 2005 20:04:48 -0000 @@ -51,6 +51,10 @@ #define SNDRV_TIMER_HW_SLAVE 0x00000004 /* only slave timer (variable resolution) */ #define SNDRV_TIMER_HW_FIRST 0x00000008 /* first tick can be incomplete */ #define SNDRV_TIMER_HW_TASKLET 0x00000010 /* timer is called from tasklet */ +#define SNDRV_TIMER_HW_NONATOMIC 0x00000020 /* start/stop are non-atomic */ + +#define SNDRV_TIMER_STATE_STOP 0 +#define SNDRV_TIMER_STATE_RUNNING 1 #define SNDRV_TIMER_IFLG_SLAVE 0x00000001 #define SNDRV_TIMER_IFLG_RUNNING 0x00000002 @@ -95,6 +99,7 @@ char name[80]; unsigned int flags; int running; /* running instances */ + int state; /* running state */ unsigned long sticks; /* schedule ticks */ void *private_data; void (*private_free) (snd_timer_t *timer); --Multipart_Wed_Nov__2_21:06:49_2005-1-- ------------------------------------------------------- SF.Net email is sponsored by: Tame your development challenges with Apache's Geronimo App Server. Download it for free - -and be entered to win a 42" plasma tv or your very own Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php