From owner-freebsd-drivers@FreeBSD.ORG Wed May 28 13:49:34 2008 Return-Path: Delivered-To: freebsd-drivers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 67296106566C for ; Wed, 28 May 2008 13:49:34 +0000 (UTC) (envelope-from ilya@po4ta.com) Received: from tom.kiev.farlep.net (tom.kiev.farlep.net [213.130.24.4]) by mx1.freebsd.org (Postfix) with ESMTP id 0DDBE8FC1A for ; Wed, 28 May 2008 13:49:33 +0000 (UTC) (envelope-from ilya@po4ta.com) Received: from ilya.kiev.farlep.net ([62.221.47.37]:3971 helo=[10.0.0.3]) by tom.kiev.farlep.net with esmtps (TLSv1:AES256-SHA:256) (Exim 4.66 (FreeBSD)) (envelope-from ) id 1K1M1f-000EDj-HR; Wed, 28 May 2008 16:49:12 +0300 Message-ID: <483D62D0.6070800@po4ta.com> Date: Wed, 28 May 2008 16:49:04 +0300 From: Ilya Bobir User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) MIME-Version: 1.0 To: Alexander Popov References: <600706.33129.qm@web51403.mail.re2.yahoo.com> In-Reply-To: <600706.33129.qm@web51403.mail.re2.yahoo.com> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Farlep-Data: Cc: freebsd-drivers@freebsd.org Subject: Re: Synchronization in drivers (after SMP improvements) X-BeenThere: freebsd-drivers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Writing device drivers for FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 May 2008 13:49:34 -0000 Alexander Popov wrote: > Hi, Benjamin, also Ilya, > > > Thanks for your quick responses. mtx_sleep() would > definitely help. Does it mean that user process executing in kernel space is > guaranteed not to be preempted between mtx_lock() and mtx_sleep()? Because then > I would get a sleeping thread with > non-sleepable mutex anyway... or have I been in application > development for too long? :-) > Regards, > > Alexander. > > According to locking(9) (" Context mode table." at the very bottom) the only type of mutex you can use in your interrupt handler is a spin mutex. And you are trying to synchronize with an interrupt handler. So, the sc->mtx ought to be a spin mutex. While a spin mutex is held all interrupts on the current CPU are blocked or deferred (mutex(9), DESCRIPTION fifth paragraph) and the thread holding the mutex will not be preempted. And you should use msleep_spin().