Subject: Re: how to detect if kernel is running in interrupt ctx
To: Ming Lei <>
From: Kamal R Prasad <>
List: tech-kern
Date: 06/30/2003 11:55:16
>sometimes a code segment may be used by both ISR or normal kernel code. 
>doesnt live in user context, so cannot block or sleep. In normal kernel
>code, the code can block or sleep. Malloc flag is one example.

neither the interrupt service routine nor rest of driver code is in user 
both are executing in supervisory mode (as far as NetBSD is concerned).

>Is there any way to detect if the code is running in interrupt, even in a
>archtect dependent way, such as, cpu register?

when executing within an interrupt, there is no per-process kernel stack 
and you cannot call yield to another process or sleep (actually can sleep 
but not supposed to).
curproc will most likely be set to an invalid value inside an interrupt 
service routine.

someone can correct me if Im wrong.


----- Original Message -----
From: "Jaromir Dolecek" <>
To: "Ming Lei" <>
Cc: <>
Sent: Sunday, June 29, 2003 7:08 AM
Subject: Re: how to detect if kernel is running in interrupt ctx

> Ming Lei wrote:
> > In linux, there is a macro called in_interrupt which can tell if the
> > is running in interrupt(including hardware or software) or not because
> > changes some flags when in or out of the interrupt. Is there any same
> > facility in netbsd?
> In NetBSD, the code needs to be structured so that the driver code
> would know whether it's running from interrupt or not. Normally
> you shouldn't even worry about this, typically most of driver code
> runs from within interrupt handler (driver's foo_intr() routine).
> Why would you need to distinguish the two cases?
> Jaromir
> --
> Jaromir Dolecek <>  
> -=- We should be mindful of the potential goal, but as the tantric -=-
> -=- Buddhist masters say, ``You may notice during meditation that you 
> -=- sometimes levitate or glow.   Do not let this distract you.'' -=-