Subject: Re: how to detect if kernel is running in interrupt ctx
To: None <tech-kern@netbsd.org>
From: David Young <dyoung@pobox.com>
List: tech-kern
Date: 06/30/2003 02:06:20
On Sun, Jun 29, 2003 at 10:25:42PM -0700, Ming Lei wrote:
> sometimes a code segment may be used by both ISR or normal kernel code. ISR
> 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.
> 
> Is there any way to detect if the code is running in interrupt, even in a
> archtect dependent way, such as, cpu register?

  As others have said, I think that the answer in general is
  "no." However, there are device drivers that track whether they are
  in an ISR.

  IIRC, awi(4) keeps state variables to help it decide whether it is
  appropriate to sleep or not. If it follows a certain execution path
  in an ioctl(), for example, it will tsleep(). However, it will not
  tsleep() when it follows the same execution path to handle an interrupt.

Dave

-- 
David Young             OJC Technologies
dyoung@ojctech.com      Urbana, IL * (217) 278-3933