tech-kern archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: when can we tsleep() ?



On Sun, Oct 26, 2008 at 09:26:13AM +0000, Andrew Doran wrote:
> On Sat, Oct 18, 2008 at 10:25:17PM +0200, Manuel Bouyer wrote:
> 
> > this is related to kern/39725. We have cpu_intr_p() which tells us
> > if we're in interrupt context or not. But there's other cases where
> > it's not safe to call tsleep (e.g. from soft interrupt context, maybe
> > others). If there a function or check that can tell us if it's safe
> > to use tsleep() or not ?
> 
> There is no function directly available to do that. I don't believe it is
> something you should need to check on the fly other than for an assertion.
> 
> It is safe to sleep with condition variables or tsleep when running within a
> kthread or a user lwp. So if you are running because of kthread_create(), or
> are running because a user process called into the kernel (a system call or
> trap) then you can sleep. Otherwise it is not permitted.

the problem is that in my case, this part of code can be called from different
context: hardware interrupt, software interrupt, kernel thread or user
thread. I hoped there would be a simple way to know if tsleep is allowed
from the code, or if I have to use delay (or return asking to come back from
a kernel thread). Passing a flag to indicate the context is not so easy in
my case.

-- 
Manuel Bouyer <bouyer%antioche.eu.org@localhost>
     NetBSD: 26 ans d'experience feront toujours la difference
--


Home | Main Index | Thread Index | Old Index