From: Takashi Iwai Subject: Re: [PATCH] Support for ESI Miditerminal 4140 Date: Tue, 25 Apr 2006 15:00:41 +0200 Message-ID: References: <87wtdeevlh.fsf@zebra.localdomain> <87wtde56js.fsf@zebra.localdomain> <874q0hvohs.fsf@zebra.localdomain> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Return-path: In-Reply-To: <874q0hvohs.fsf@zebra.localdomain> 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: Matthias Koenig Cc: alsa-devel@lists.sourceforge.net List-Id: alsa-devel@alsa-project.org At Tue, 25 Apr 2006 14:17:03 +0200, Matthias Koenig wrote: > > Takashi Iwai writes: > > At Tue, 25 Apr 2006 11:49:11 +0200, > > Matthias Koenig wrote: > >> Yes, these long delays have caused me some bellyache. > >> I got the information about the device from reverse engineering the Windows > >> driver and the delay times are exactly taken from there (actually there is a > >> function which repeatedly calls KeStallExecutionProcessor with an argument > >> of 50us until the given time is elapsed). > > > > Hm, but you call mdelay(50), not udelay(50). > > I won't care about the latter case but mdelay(50) is definitely to be > > avoided. > > Yes, it's 50ms of _total_ time to wait. > The Code does something like this (roughly translated to C): > > void wait_some_time(long long interval) /* interval is in ms */ > { > long long time = PcGetTimeInterval(0); /* Current time in 100ns ticks */ > interval *= 10000; /* translate to 100ns ticks */ > do { > KeStallExecutionProcessor(50); /* This is us */ > } while (interval < PcGetTimeInterval(time)); > } > > > If it's really mdelay(50), change spin_lock to mutex_lock and replace > > mdelay to msleep() -- at least, for open/close calls, where you can > > sleep safely. > > I totally overlooked the following sentence in "Writing an ALSA Driver": > "The open and close callbacks of a rawmidi device are serialized with a > mutex, and can sleep." > > So, if I understand this correctly, there is already a mutex held by the > ALSA core and it is guaranteed that there are no multiple accesses of > open/close callbacks? The mutex belongs to the rawmidi device, so open/close is mutual as long as the same rawmidi device is used no matter which substream is used. It doesn't care open/close of another rawmidi device, though. > Hmm, then why should I hold an additional mutex? Well, I just thought of something as a replacement of mts->lock, but regarding open/close, yes, you can get rid of an extra mutex. You might still need a spinlock somewhere, but definitely not together with mdelay(). Takashi ------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642