Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 3 Nov 2010 19:11:01 +0200
From:      Kostik Belousov <kostikbel@gmail.com>
To:        mdf@freebsd.org
Cc:        freebsd-current@freebsd.org, Andriy Gapon <avg@icyb.net.ua>
Subject:   Re: MTX_DEF versus MTX_SPIN
Message-ID:  <20101103171101.GS2392@deviant.kiev.zoral.com.ua>
In-Reply-To: <AANLkTimmiQ9VH=cr%2BPJ4Hz=h1Oua%2Bouj7CAv8L__JeNn@mail.gmail.com>
References:  <AANLkTi=12-dSAZ21DbZgw36YbRGiUq4KZbyCx3SjucPG@mail.gmail.com> <4CD190EF.5080600@icyb.net.ua> <AANLkTimmiQ9VH=cr%2BPJ4Hz=h1Oua%2Bouj7CAv8L__JeNn@mail.gmail.com>

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

--diyAeELN2I8WbrL0
Content-Type: text/plain; charset=koi8-r
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Wed, Nov 03, 2010 at 10:04:13AM -0700, mdf@freebsd.org wrote:
> On Wed, Nov 3, 2010 at 9:42 AM, Andriy Gapon <avg@icyb.net.ua> wrote:
> > on 03/11/2010 18:27 mdf@FreeBSD.org said the following:
> >> It's not clear to me from the man pages (perhaps I didn't look at the
> >> right one?) in which environments I need a spinlock. =9AFor example, I
> >> wouldn't think it's safe to use a MTX_DEF in a hard interrupt handler
> >> (i.e one that was registered with BUS_SETUP_INTR), but I see some code
> >> lying around here that does it and nothing I'm aware of has broken.
> >
> > Such a handler runs in an interrupt thread.
> > The "harder" interrupt handler is called interrupt filter in FreeBSD te=
rminology.
> > =9AI think that it was formerly known as fast interrupt.
>=20
> So a MTX_DEF is okay in that environment?
>=20
> What would "best practices" be considered for what code should be run
> in the interrupt handler versus a soft interrupt?  In this case the
> kinds of things we have to do at some level of interrupt are:
>=20
>  - handle a heartbeat interrupt from firmware a few times a second
Doing this in the filter would only assert that interrupts are not
disabled. If you perform the heartbeat notification from the interrupt
thread instead, you have some assurance that scheduling works.

>  - get a DMA completion interrupt (completely handling this requires
> calling biodone on all the associated bios)
Calling into geom and possibly fs/VFS level should be done from the
interrupt thread. I thought that g_up thread is used to handle
the finish of i/o ?

>  - receive an ECC interrupt (this requires reading registers off the
> card for details)
>=20
> At the moment we're on stable/7, but we will be migrating the code
> base to something more recent in another year or so, if that affects
> the answer.
>=20
> Is there any documentation on best practices for writing a FreeBSD driver?
Not that I am aware of. You can read locking(9) in HEAD to get the answer
on your question about spin mutexes.

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

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

iEYEARECAAYFAkzRl6QACgkQC3+MBN1Mb4gEZACeNKCeEXlf4nRVQ5E1Q0TGW75j
2kAAn1Po3Xe0Tb8AOOlWVhurL/VCZDpE
=grq6
-----END PGP SIGNATURE-----

--diyAeELN2I8WbrL0--



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