Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 31 Jul 2012 12:59:22 +0300
From:      Konstantin Belousov <kostikbel@gmail.com>
To:        Alexander Motin <mav@freebsd.org>
Cc:        Attilio Rao <attilio@freebsd.org>, Davide Italiano <davide@freebsd.org>, src-committers@freebsd.org, svn-src-projects@freebsd.org
Subject:   Re: svn commit: r238907 - projects/calloutng/sys/kern
Message-ID:  <20120731095922.GC2676@deviant.kiev.zoral.com.ua>
In-Reply-To: <5017A82B.3040704@FreeBSD.org>
References:  <201207301350.q6UDobCI099069@svn.freebsd.org> <CAJ-FndBJNNBNDUEDsDBUvwoVExZpnXmoJmpY58gE3QQbw3hRGA@mail.gmail.com> <CACYV=-HmOwZ=E8Pw3-mUw0994SbvZaA3eMfcwM0fDTu_zykBJg@mail.gmail.com> <CAJ-FndBmXkyJJ=fCkEpVm84E56A2_EoM6kbch03e4RMEM6WCGQ@mail.gmail.com> <20120730143943.GY2676@deviant.kiev.zoral.com.ua> <CAJ-FndByYcZ%2BUhnkFT_n2=W=UheqUCi0%2BUAX%2BF07EqbVU=6iDQ@mail.gmail.com> <20120730145912.GZ2676@deviant.kiev.zoral.com.ua> <CAJ-FndAdyL5-29vjkS1deAhc4ewYTmA6tEhXUNh%2BqQzUCcTpGw@mail.gmail.com> <20120731093735.GB2676@deviant.kiev.zoral.com.ua> <5017A82B.3040704@FreeBSD.org>

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

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

On Tue, Jul 31, 2012 at 12:40:59PM +0300, Alexander Motin wrote:
> On 31.07.2012 12:37, Konstantin Belousov wrote:
> >On Mon, Jul 30, 2012 at 09:48:08PM +0100, Attilio Rao wrote:
> >>On Mon, Jul 30, 2012 at 3:59 PM, Konstantin Belousov
> >><kostikbel@gmail.com> wrote:
> >>>On Mon, Jul 30, 2012 at 03:51:22PM +0100, Attilio Rao wrote:
> >>>>On 7/30/12, Konstantin Belousov <kostikbel@gmail.com> wrote:
> >>>>>On Mon, Jul 30, 2012 at 03:24:26PM +0100, Attilio Rao wrote:
> >>>>>>On 7/30/12, Davide Italiano <davide@freebsd.org> wrote:
> >>>>>>>On Mon, Jul 30, 2012 at 4:02 PM, Attilio Rao <attilio@freebsd.org>
> >>>>>>>wrote:
> >>>>>>>Thanks for the comment, Attilio.
> >>>>>>>Yes, it's exactly what you thought. If direct flag is equal to one
> >>>>>>>you're sure you're processing a callout which runs directly from
> >>>>>>>hardware interrupt context. In this case, the running thread cannot
> >>>>>>>sleep and it's likely you have TDP_NOSLEEPING flags set, failing t=
he
> >>>>>>>KASSERT() in THREAD_NO_SLEEPING() and leading to panic if kernel is
> >>>>>>>compiled with INVARIANTS.
> >>>>>>>In case you're running from SWI context (direct equals to zero) co=
de
> >>>>>>>remains the same as before.
> >>>>>>>I think what I'm doing works due the assumption thread running nev=
er
> >>>>>>>sleeps. Do you suggest some other way to handle this?
> >>>>>>
> >>>>>>Possibly the quicker way to do this is to have a way to deal with t=
he
> >>>>>>TDP_NOSLEEPING flag in recursed way, thus implement the same logic =
as
> >>>>>>VFS_LOCK_GIANT() does, for example.
> >>>>>>You will need to change the few callers of THREAD_NO_SLEEPING(), but
> >>>>>>the patch should be no longer than 10/15 lines.
> >>>>>
> >>>>>There are already curthread_pflags_set/restore KPI designed exactly =
to
> >>>>>handle
> >>>>>nested private thread flags.
> >>>>
> >>>>Yes, however I would use curthread_pflags* KPI within
> >>>>THREAD_NO_SLEEPING() as this name is much more explicit.
> >>>>
> >>>Sure, hiding it in THREAD_NO_SLEEPING (THREAD_NO_SLEEP_ENTER/LEAVE ?)
> >>>is the way to use curthread_pflags_set there.
> >>>
> >>>As a second though, on the other hand, is it safe to modify td_flags
> >>>from the interrupt context at all ? Probably yes if interrupt handler
> >>>always leave td_pflags in the same state on leave as it was on entry,
> >>>but couldn't too smart compiler cause inconsistent view of td_pflags
> >>>inside the handler ?
> >>
> >>Can you think of any? Because I cannot think of a case where a nested
> >>interrupt can messup with already compiled code, unless it leaks a
> >>cleanup.
> >In principle, compiler might compile the
> >	x |=3D a;
> >into whatever it finds suitable, e.g. it could write 0 temporary into
> >x if the corresponding instruction sequence is considered faster.
> >
> >No sane compiler for x86 does this.
> >>
> >>I was more worried about the compiler reordering operations before
> >>locking could really see it, but I think in this case the functions
> >>call to sleepqueue (at least) works as a sequence point so we are
> >>safe.
> >>
> >>>
> >>>>>Also, I wonder, should you assert somehow that direct dispatch canno=
t=20
> >>>>>block
> >>>>>as well ?
> >>>>
> >>>>Yes, it would be optimal, but I don't think we have a flag for that
> >>>>right now, do we?
> >>>
> >>>I am not aware of such flag, this might be a good reason to introduce =
it,
> >>>if issue about td_pflags is just a product of my imagination.
> >>
> >>I think you should be good to go. Do you plan to work on such a patch?
> >
> >Ok, I looked closely at the direct dispatch and TD_NOBLOCKING. I now
> >think that such flag is not needed.
> >
> >Am I right that direct dispatch executes callback while owning cc_lock
> >spinlock ?
>=20
> No, does not now. It was so originally, but was fixed recently, as it=20
> caused LOR deadlocks.
Hm, ok. Probably I misread the diff.

Anyway, I believe that both direct interrupt dispatch and IPIs take
critical sections around handlers. This should have the same effect
for assertion in the mi_switch().

>=20
> >If true, then TD_NOBLOCKING is definitely not needed for
> >direct dispatch. For thread to be blocked, it shall be scheduled off the
> >CPU, going through mi_switch(). And mi_switch() asserts that critical
> >section level is exactly 1, which assertion fails due to direct dispatch
> >context owning spinlock.
>=20
> --=20
> Alexander Motin

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

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

iEYEARECAAYFAlAXrHoACgkQC3+MBN1Mb4g8fACeLrio17rJnv6l1ydVPnKbUuHB
NL4AmgOrwGM6JMEWFn/JGLbFP0hmlsdp
=HxrS
-----END PGP SIGNATURE-----

--P6FkfbahCsDDKxle--



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