Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 Jan 2009 02:51:40 -0800
From:      Alfred Perlstein <alfred@freebsd.org>
To:        Julian Elischer <julian@elischer.org>
Cc:        arch@freebsd.org, Kip Macy <kmacy@freebsd.org>
Subject:   Re: need for another mutex type/flag?
Message-ID:  <20090126105140.GL5889@elvis.mu.org>
In-Reply-To: <497D5DF8.8000706@elischer.org>
References:  <497BA91D.805@elischer.org> <3c1674c90901241956j244ed067p7ff4df5454beba82@mail.gmail.com> <497C235E.5090807@elischer.org> <20090124224716.X983@desktop> <20090125092838.GC87077@elvis.mu.org> <497D5DF8.8000706@elischer.org>

next in thread | previous in thread | raw e-mail | index | archive | help
* Julian Elischer <julian@elischer.org> [090125 22:53] wrote:
> Alfred Perlstein wrote:
> >
> >Jeff, I think that Julian really wants to prevent a sleep inside
> >his context.  Right now, I think we only check for mutexes held
> >before a sleep that arne't sleepable.  It might make sense to allow
> >one to just mark a thread non-sleepable even though no mutex is
> >held.
> >
> >Julian, is that right?
> 
> basically, though I don't know the details of implementation..
> I just know that mutexes per se aren't bad for netgraph but
> that node authors need some guidance on how to use them and
> some way to prove to them when they do the wrong thing.

The way to add the assertion you want would be to keep a count
inside of the thread structure "td_nosleep", set to 0 at thread
creation, then you can do this:

TD_SLEEP_NO(td);  /* td->td_nosleep++ */
call_some_untrusted_code();
TD_SLEEP_OK(td);  /* td->td_nosleep-- */

Then add this to subr_witness.c:witness_warn():

   if (flags & WARN_SLEEPOK && td->td_nosleep != 0) {
      printf("Sleeping in unsleepable context.\n");
      n++;   /* this variable is local to witness_warn() 
                and triggers an ASSERT at the end */
   }

I could have sworn we already had such a feature, but it appears
that it's only accessable if you're holding a lock, if you added
this counter, then you could catch sleeps without needing a lock
held.

-Alfred



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