Subject: Re: how do I tell if I'm on the interrupt stack?
To: None <tech-kern@netbsd.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-kern
Date: 09/07/2001 01:45:28
>> [enough state to do a "may_i_tsleep()" call]

> Basically, it's a single instruction in the interrupt stub (increment
> interrupt nesting level) and another in the return (decrement),

On CISC architectures, perhaps (i386, vax, 68k).  SPARC, I can't see
how to get it down below four instructions (sethi, ld, add/sub, st),
and as I recall it, the PowerPC is similar.  On some such
architectures, there's also a classic race between the ld-add/sub-st
sequence and other interrupts occurring, a race which if it goes wrong
will corrupt the count; on the SPARC, ISTR something about double error
halts which would mean it's not an issue, but can't recall whether that
applies to interrupts or just traps.  If you have to splhigh() around
that, the instruction count goes up: rd, nop, nop, nop, or, wr, nop,
nop, nop, sethi, ld, add/sub, st, wr, nop, nop, nop.

Of course, that's still no more than 17 instructions, only two of which
access memory (which the SPARC, at least, hates to do).  The details
will vary on other architectures, of course, but even 34 instructions
and two four references (per interrupt, naturally) may end up being
judged worth it....

/~\ The ASCII				der Mouse
\ / Ribbon Campaign
 X  Against HTML	       mouse@rodents.montreal.qc.ca
/ \ Email!	     7D C8 61 52 5D E7 2D 39  4E F1 31 3E E8 B3 27 4B