From owner-freebsd-scsi@FreeBSD.ORG Fri Feb 24 17:54:39 2012 Return-Path: Delivered-To: freebsd-scsi@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 26920106566B; Fri, 24 Feb 2012 17:54:39 +0000 (UTC) (envelope-from jhb@freebsd.org) Received: from cyrus.watson.org (cyrus.watson.org [65.122.17.42]) by mx1.freebsd.org (Postfix) with ESMTP id DC1B58FC15; Fri, 24 Feb 2012 17:54:38 +0000 (UTC) Received: from bigwig.baldwin.cx (bigwig.baldwin.cx [96.47.65.170]) by cyrus.watson.org (Postfix) with ESMTPSA id 78B2E46B23; Fri, 24 Feb 2012 12:54:38 -0500 (EST) Received: from jhbbsd.localnet (unknown [209.249.190.124]) by bigwig.baldwin.cx (Postfix) with ESMTPSA id 06E54B96E; Fri, 24 Feb 2012 12:54:38 -0500 (EST) From: John Baldwin To: freebsd-stable@freebsd.org Date: Thu, 23 Feb 2012 09:58:05 -0500 User-Agent: KMail/1.13.5 (FreeBSD/8.2-CBSD-20110714-p10; KDE/4.5.5; amd64; ; ) References: <20120223092457.GB55074@deviant.kiev.zoral.com.ua> In-Reply-To: MIME-Version: 1.0 Content-Type: Text/Plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <201202230958.05667.jhb@freebsd.org> X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.2.7 (bigwig.baldwin.cx); Fri, 24 Feb 2012 12:54:38 -0500 (EST) Cc: "Desai, Kashyap" , "Kenneth D. Merry" , "freebsd-scsi@freebsd.org" , "Justin T. Gibbs" , "McConnell, Stephen" Subject: Re: mpslsi0 : Trying sleep, but thread marked as sleeping prohibited X-BeenThere: freebsd-scsi@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SCSI subsystem List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 24 Feb 2012 17:54:39 -0000 On Thursday, February 23, 2012 8:22:07 am Desai, Kashyap wrote: > > > -----Original Message----- > > From: Konstantin Belousov [mailto:kostikbel@gmail.com] > > Sent: Thursday, February 23, 2012 2:55 PM > > To: Desai, Kashyap > > Cc: freebsd-scsi@freebsd.org; freebsd-stable; Justin T. Gibbs; Kenneth > > D. Merry; McConnell, Stephen > > Subject: Re: mpslsi0 : Trying sleep, but thread marked as sleeping > > prohibited > > > > On Thu, Feb 23, 2012 at 05:52:12AM +0530, Desai, Kashyap wrote: > > > > > > > > > > -----Original Message----- > > > > From: Konstantin Belousov [mailto:kostikbel@gmail.com] > > > > Sent: Thursday, February 23, 2012 12:45 AM > > > > To: Desai, Kashyap > > > > Cc: freebsd-scsi@freebsd.org; freebsd-stable; Justin T. Gibbs; > > > > Kenneth D. Merry; McConnell, Stephen > > > > Subject: Re: mpslsi0 : Trying sleep, but thread marked as sleeping > > > > prohibited > > > > > > > > On Wed, Feb 22, 2012 at 07:36:42PM +0530, Desai, Kashyap wrote: > > > > > Hi, > > > > > > > > > > I am doing some code changes in mps dirver. While working on those > > > > changes, I come to know about something which is new to me. > > > > > Some expert help is required to clarify my doubt. > > > > > > > > > > 1. When any irq is register with FreeBSD OS, it sets " > > TDP_NOSLEEPING" > > > > > pflag. It means though irq in freebsd is treated as thread, We > > > > > cannot > > > > sleep in IRQ because of " "TDP_NOSLEEPING " set. > > > > > 2. In mps driver we have below code snippet in ISR routine. > > > > > > > > > > > > > > > mps_dprint(sc, MPS_TRACE, "%s\n", __func__); > > > > > mps_lock(sc); > > > > > mps_intr_locked(data); > > > > > mps_unlock(sc); > > > > > > > > > > I wonder why there is no issue with above code ? Theoretical we > > > > > cannot sleep in ISR. (as explained in #1) Any thoughts ? > > > > > > > > > > > > > > > 3. I recently added few place msleep() instead of DELAY in ISR > > > > > context and I see " Trying sleep, but thread marked as sleeping > > prohibited". > > > > > > > > > FreeBSD has several basic ways to prevent a thread from executing on > > > > CPU. > > > > They mostly fall into two categories: bounded sleep, sometimes > > > > called blocking, and unbounded sleep, usually abbreviated as sleep. > > > > The bounded there refers to amount of code executed by other thread > > > > that hold resource preventing blocked thread from making a progress. > > > > > > > > Examples of the blocking primitives are mutexes, rw locks and rm > > locks. > > > > The blocking is not counted as sleeping, so interrupt threads, which > > > > are designated as non-sleeping, still can lock mutexes. > > > Thanks for the tech help. . > > > > > > As per you comment, So now I understood as "TDP_NOSLEEPING" is only > > > for unbounded sleep restriction. Just curious to know, What is a > > > reason that thread can do blocking sleep but can't do unbounded sleep > > > ? Since technically we introduced sleeping restriction on interrupt > > > thread is to avoid starvation and that can be fit with either of the > > > sleep type. Is this not true ? > > No, not to avoid starvation. > > > > The intent of the blocking primitives is to acquire resources for > > limited amount of time. In other words, you never take a mutex for > > undefinitely long computation process. On the other hand, msleep sleep > > usually has no limitations. > > I got same reply from Ed Schouten. I agree and understood your note. Thanks for poring knowledge on this area. > _but_ only query is when thread take mutex, we don't know when it will release. So holding time of mutex is really not known. > In case of some bad code, where thread took mutex and not release within short time. This can eventually match upto msleep restriction as well. > Do we have any checks that thread took long time holding mutext ? Similar to linux where spinlock has been not release in some specific time, they dump warnings with backtrace. We don't allow code to do unbounded sleeps while holding mutexes either, and WITNESS warns about doing so. That ensures that barring an infinite loop-type bug, mutexes should be held for a bounded amount of time. -- John Baldwin