Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Feb 2012 11:24:57 +0200
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        "Desai, Kashyap" <Kashyap.Desai@lsi.com>
Cc:        "freebsd-scsi@freebsd.org" <freebsd-scsi@freebsd.org>, "Kenneth D. Merry" <ken@freebsd.org>, "Justin T. Gibbs" <gibbs@freebsd.org>, freebsd-stable <freebsd-stable@freebsd.org>, "McConnell, Stephen" <Stephen.McConnell@lsi.com>
Subject:   Re: mpslsi0 : Trying sleep, but thread marked as sleeping prohibited
Message-ID:  <20120223092457.GB55074@deviant.kiev.zoral.com.ua>
In-Reply-To: <B2FD678A64EAAD45B089B123FDFC3ED72B96D34854@inbmail01.lsi.com>
References:  <B2FD678A64EAAD45B089B123FDFC3ED72B96D34836@inbmail01.lsi.com> <20120222191519.GT55074@deviant.kiev.zoral.com.ua> <B2FD678A64EAAD45B089B123FDFC3ED72B96D34854@inbmail01.lsi.com>

next in thread | previous in thread | raw e-mail | index | archive | help

--ATYltwmfWCpDp8Ax
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Thu, Feb 23, 2012 at 05:52:12AM +0530, Desai, Kashyap wrote:
>=20
>=20
> > -----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
> >=20
> > 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.
> >=20
> > 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.  .=20
>=20
> 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.

You do not want the interrupt thread to be put off the processor for
undefined time, so sleep is prohibited.

Another issue is that sleeping locks do not do priority propagation
to the resource owners, while turnstiles used for blocking do. This way,
interrupt thread waiting for mutex donates its priority to the current
mutex owner, or at least it shall do.

>=20
> I will be able to progress on my work based on your comment. A much thank=
s for correcting my doubt.
>=20
> ~ Kashyap
>=20
> >=20
> > Examples of the sleeping primitives are msleep(), sx locks, lockmgr
> > locks and conditional variables.
> >=20
> > In essence, the locking facilities are split into several classes that
> > form the hierarchy, and you cannot legally obtain the lock of higher
> > class while holding a lock of lower class:
> > 	spin mutexes -> blocking locks -> sleeping locks.
> > It establishes some meta-order on the all locks.
> >=20
> > Does this make sense ?
>=20

--ATYltwmfWCpDp8Ax
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (FreeBSD)

iEYEARECAAYFAk9GBekACgkQC3+MBN1Mb4gWYACdF0VYEz9/Zlgfb3xdfANWWZar
j6IAoPD8FnxUrm+aokl/YQqtevqYMLrU
=4uF7
-----END PGP SIGNATURE-----

--ATYltwmfWCpDp8Ax--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120223092457.GB55074>