Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - InterruptLock(): (8 Items)
   
InterruptLock()  
Hi,

I'm not sure if this is the right place to ask, but still would appreciate if somebody could feed my inquisitive mind 
(Without getting into the debate of "Why would you want to do this..." et al) :-)

Can I call InterruptLock() recursively? Something like this:

InterruptLock(lock1);
InterruptLock(lock1);
/* do something */
InterruptUnlock(lock1);
InterruptUnlock(lock1);

Will lthe interrupts be enabled after first or second call to InterruptLock()?

And how about this:
InterruptLock(lock1);
InterruptLock(lock2);
/* do something */
InterruptUnlock(lock2);
InterruptUnlock(lock1);

Dan
Re: InterruptLock()  
On Thu, Nov 22, 2007 at 08:19:37AM -0500, Daniel Rodrick wrote:
> Can I call InterruptLock() recursively? Something like this:
> 
> InterruptLock(lock1);
> InterruptLock(lock1);
> /* do something */
> InterruptUnlock(lock1);
> InterruptUnlock(lock1);

Nope, InterruptLock() doesn't count (neither does InterruptDisable()). As 
as matter of fact, you'll permanently hang up on the spin lock of the
second InterruptLock.

> And how about this:
> InterruptLock(lock1);
> InterruptLock(lock2);
> /* do something */
> InterruptUnlock(lock2);
> InterruptUnlock(lock1);

You won't hang on this one, but interrupts will be re-enabled after
the first InterruptUnlock().

-- 
Brian Stecher (bstecher@qnx.com)        QNX Software Systems
phone: +1 (613) 591-0931 (voice)        175 Terence Matthews Cr.
       +1 (613) 591-3579 (fax)          Kanata, Ontario, Canada K2M 1W8
Re: InterruptLock()  
You can use InterruptStatus() to check to see if interrupts are 
currently disabled.

Brian Stecher wrote:
>
> On Thu, Nov 22, 2007 at 08:19:37AM -0500, Daniel Rodrick wrote:
> > Can I call InterruptLock() recursively? Something like this:
> >
> > InterruptLock(lock1);
> > InterruptLock(lock1);
> > /* do something */
> > InterruptUnlock(lock1);
> > InterruptUnlock(lock1);
>
> Nope, InterruptLock() doesn't count (neither does InterruptDisable()). As
> as matter of fact, you'll permanently hang up on the spin lock of the
> second InterruptLock.
>
> > And how about this:
> > InterruptLock(lock1);
> > InterruptLock(lock2);
> > /* do something */
> > InterruptUnlock(lock2);
> > InterruptUnlock(lock1);
>
> You won't hang on this one, but interrupts will be re-enabled after
> the first InterruptUnlock().
>
> -- 
> Brian Stecher (bstecher@qnx.com)        QNX Software Systems
> phone: +1 (613) 591-0931 (voice)        175 Terence Matthews Cr.
>        +1 (613) 591-3579 (fax)          Kanata, Ontario, Canada K2M 1W8
>
> _______________________________________________
> OSTech
> http://community.qnx.com/sf/go/post2846
>

-- 
cburgess@qnx.com

Re: InterruptLock()  
On Thu, Nov 22, 2007 at 09:53:33AM -0500, Colin Burgess wrote:
> You can use InterruptStatus() to check to see if interrupts are 
> currently disabled.

But that won't help in the second case, with two different lock variables.
On an SMP system, you could let multiple people into the critical region
if you try something like:

	InterruptLock(lock1);
	if(InterruptStatus() == 0) {
		InterruptLock(lock2);
	}
	....

-- 
Brian Stecher (bstecher@qnx.com)        QNX Software Systems
phone: +1 (613) 591-0931 (voice)        175 Terence Matthews Cr.
       +1 (613) 591-3579 (fax)          Kanata, Ontario, Canada K2M 1W8
Re: InterruptLock()  
True, but you could change the second InterruptLock to merely a 
spinlock, couldn't you?

eg

status = InterruptStatus();
if ( status ) {
    InterruptLock(&lock2);
} else {
    SPINLOCK(&lock2);
}

Brian Stecher wrote:
>
> On Thu, Nov 22, 2007 at 09:53:33AM -0500, Colin Burgess wrote:
> > You can use InterruptStatus() to check to see if interrupts are
> > currently disabled.
>
> But that won't help in the second case, with two different lock 
> variables.
> On an SMP system, you could let multiple people into the critical region
> if you try something like:
>
>         InterruptLock(lock1);
>         if(InterruptStatus() == 0) {
>                 InterruptLock(lock2);
>         }
>         ....
>
> -- 
> Brian Stecher (bstecher@qnx.com)        QNX Software Systems
> phone: +1 (613) 591-0931 (voice)        175 Terence Matthews Cr.
>        +1 (613) 591-3579 (fax)          Kanata, Ontario, Canada K2M 1W8
>
> _______________________________________________
> OSTech
> http://community.qnx.com/sf/go/post2853
>

-- 
cburgess@qnx.com

Re: InterruptLock()  
On Thu, Nov 22, 2007 at 10:05:36AM -0500, Colin Burgess wrote:
> True, but you could change the second InterruptLock to merely a 
> spinlock, couldn't you?
> 
> eg
> 
> status = InterruptStatus();
> if ( status ) {
>     InterruptLock(&lock2);
> } else {
>     SPINLOCK(&lock2);
> }

Yup, and the InterruptUnlock to a SPINUNLOCK in that case.

-- 
Brian Stecher (bstecher@qnx.com)        QNX Software Systems
phone: +1 (613) 591-0931 (voice)        175 Terence Matthews Cr.
       +1 (613) 591-3579 (fax)          Kanata, Ontario, Canada K2M 1W8
Re: InterruptLock()  
So what is the correct way (in a driver) to obtain two locks on an SMP machine? I don't find "SPINLOCK" macro / function
 anywhere!

[daniel@localhost qnx632]$ grep -Rn SPINLOCK /opt/qnx632/target/
[daniel@localhost qnx632]$ grep -Rn SPINLOCK /opt/qnx632/host/

Re: InterruptLock()  
On Fri, Nov 23, 2007 at 12:18:20AM -0500, Daniel Rodrick wrote:
> So what is the correct way (in a driver) to obtain two locks on an SMP
> machine? I don't find "SPINLOCK" macro / function anywhere!

Left as an exercise for the user :-).

It's just the tail end of the InterruptLock inline - the part after
interrupts have been disabled. Ditto with SPINUNLOCK - it's the part in
InterruptUnlock before enabling interrupts.

-- 
Brian Stecher (bstecher@qnx.com)        QNX Software Systems
phone: +1 (613) 591-0931 (voice)        175 Terence Matthews Cr.
       +1 (613) 591-3579 (fax)          Kanata, Ontario, Canada K2M 1W8