* interrupt - spin lock question
@ 2002-03-04 5:18 sridharv
2002-03-04 5:27 ` Robert Love
2002-03-04 6:32 ` Kittur Sameer
0 siblings, 2 replies; 5+ messages in thread
From: sridharv @ 2002-03-04 5:18 UTC (permalink / raw)
To: linux-kernel
I have a question related to spin locking on UP systems.Before that I would
like to point out my understanding of the background stuff
1. spinlocks shud be used in intr handlers
2. interrupts can preempt kernel code
3. spinlocks are turned to empty when kernel is compiled without SMP support.
If a particular driver is running( not the intr handler part) and at this time
an interrupt occurs. The handler has to be invoked now. Won't the preemption
cause race conditions/inconsistencies? Is any other mechanism used?
Pl correct me if I have not understood any part of this correctly
-sridhar
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: interrupt - spin lock question
2002-03-04 5:18 interrupt - spin lock question sridharv
@ 2002-03-04 5:27 ` Robert Love
2002-03-04 6:33 ` sridharv
2002-03-04 7:19 ` Robert Love
2002-03-04 6:32 ` Kittur Sameer
1 sibling, 2 replies; 5+ messages in thread
From: Robert Love @ 2002-03-04 5:27 UTC (permalink / raw)
To: sridharv; +Cc: linux-kernel
On Mon, 2002-03-04 at 00:18, sridharv@ufl.edu wrote:
> I have a question related to spin locking on UP systems.Before that I would
> like to point out my understanding of the background stuff
> 1. spinlocks shud be used in intr handlers
> 2. interrupts can preempt kernel code
> 3. spinlocks are turned to empty when kernel is compiled without SMP support.
This is right.
> If a particular driver is running( not the intr handler part) and at this time
> an interrupt occurs. The handler has to be invoked now. Won't the preemption
> cause race conditions/inconsistencies? Is any other mechanism used?
> Pl correct me if I have not understood any part of this correctly
> -sridhar
Right, that is why you would use a spin_lock ! :)
Further, you would want to use a spin_lock_irq and related friends. The
irq disable prevents the race wrt interrupts and the spin_lock prevents
racing wrt SMP.
Robert Love
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: interrupt - spin lock question
2002-03-04 5:18 interrupt - spin lock question sridharv
2002-03-04 5:27 ` Robert Love
@ 2002-03-04 6:32 ` Kittur Sameer
1 sibling, 0 replies; 5+ messages in thread
From: Kittur Sameer @ 2002-03-04 6:32 UTC (permalink / raw)
To: sridharv, linux-kernel
On Sunday 03 March 2002 09:18 pm, sridharv@ufl.edu wrote:
> I have a question related to spin locking on UP systems.Before that I would
> like to point out my understanding of the background stuff
> 1. spinlocks shud be used in intr handlers
It should be used in the interrupt handler, if you need to prevent any race
conditions with other interrupt/non-interrupt context code that may be
executing on some other CPU on an SMP system. Thus spinlocks need to be held
for as short a duration as possible. You would need to use the
spin_lock_irqsave/spin_unlock_irqrestore variant pair to prevent your
interrupt handler from running on the same processor while holding the lock.
This may be needed if the interrupt handler may try to acquire the same lock
thus causing a deadlock.
> 2. interrupts can preempt kernel code
> 3. spinlocks are turned to empty when kernel is compiled without SMP
> support.
>
> If a particular driver is running( not the intr handler part) and at this
> time an interrupt occurs. The handler has to be invoked now. Won't the
> preemption cause race conditions/inconsistencies? Is any other mechanism
> used? Pl correct me if I have not understood any part of this correctly
On a UP kernel the spin_lock_irqsave/spin_unlock_irqrestore pair expand to
save_flags(flag); cli()/restore_flags(flag).
The masking of interrupts on the processor between spin_lock_irqsave and
spin_unlock_irqrestore pair prevent the user context code from being
preempted by the interrupt handler.
Sameer.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: interrupt - spin lock question
2002-03-04 5:27 ` Robert Love
@ 2002-03-04 6:33 ` sridharv
2002-03-04 7:19 ` Robert Love
1 sibling, 0 replies; 5+ messages in thread
From: sridharv @ 2002-03-04 6:33 UTC (permalink / raw)
To: linux-kernel
> Right, that is why you would use a spin_lock ! :)
>
> Further, you would want to use a spin_lock_irq and related friends. The
> irq disable prevents the race wrt interrupts and the spin_lock prevents
> racing wrt SMP.
>
ok things are clear now. so the spin_lock_irq friends are actually for 2
purposes - preventing racing from interrupts and from SMP. so if SMP is not
chosen only the local_irq_disable() part works right??
do { local_irq_disable(); spin_lock(lock); } while (0)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: interrupt - spin lock question
2002-03-04 5:27 ` Robert Love
2002-03-04 6:33 ` sridharv
@ 2002-03-04 7:19 ` Robert Love
1 sibling, 0 replies; 5+ messages in thread
From: Robert Love @ 2002-03-04 7:19 UTC (permalink / raw)
To: sridharv; +Cc: linux-kernel
On Mon, 2002-03-04 at 01:33, sridharv@ufl.edu wrote:
> ok things are clear now. so the spin_lock_irq friends are actually for 2
> purposes - preventing racing from interrupts and from SMP. so if SMP is not
> chosen only the local_irq_disable() part works right??
>
> do { local_irq_disable(); spin_lock(lock); } while (0)
Correct. Although, you would want to use spin_lock_irqsave most of the
time, not spin_lock_irq (difference is, the stored flags value is used
to restore interrupts to there previous condition instead of
unconditionally reenable them).
Btw, Go Gators!
Robert Love
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2002-03-04 7:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-03-04 5:18 interrupt - spin lock question sridharv
2002-03-04 5:27 ` Robert Love
2002-03-04 6:33 ` sridharv
2002-03-04 7:19 ` Robert Love
2002-03-04 6:32 ` Kittur Sameer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).