Re: Spinlock on single-processor machines

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 7/26/06, Om. <om.turyx@xxxxxxxxx> wrote:
On 7/25/06, Grob Team <grobteam@xxxxxxxxx> wrote:
> On 7/25/06, s prashant <sprashant16@xxxxxxxxx> wrote:
> > On 7/25/06, Gaurav Dhiman < gauravd.chd@xxxxxxxxx> wrote:
> >
> > > May I know where you read this. It does not seems ok to me.
> > > I agree with your view point.
> > >
> > > Gaurav
> > There are quite a few variants of spin locks.
> > 1.spin_lock
> >   spin_unlock
> >
> >  The above ones are used when you know the critical section that
> >  you are protecting will not accessed from an interrupt handler.
> >  In case of uniprocessor  m/c  these locks are not effective as they
> >  compile away to nothing.
> >
> > 2.spin_lock_irqsave
> >   spin_unlock_irqrestore
> >  These locks also disable the interrrupts.
I agree with you that there are multiple types of spin locks and
various methods of locking and unlocking spin locks. But, your
explanation is not true.
All the spin locks when locked disables (local cpu) interrupts. But,
the *_irqsave version saves the current flags governing the interrupts
-- which of them are masked, which are enabled..etc is stored in the
flags variable. When *_irqrestore() function is called with the
previously saved value in flags variable, it is restored so that the
previous state of interrupt flags are restored.

hi om,

here is a  snap shot of spin_lock macro in 2.6 kernel
#define spin_lock(lock) \
do { \
        preempt_disable(); \
        if (unlikely(!_raw_spin_trylock(lock))) \
                __preempt_spin_lock(lock); \
} while (0)

in the above the irq_disable is not called. The local interrupts
are still enabled. where as an spin_lock_irq or spin_lock_irqsave
is as follows

#define spin_lock_irq(lock) \
do { \
        local_irq_disable(); \  <=== local interrupts are disabled.
        preempt_disable(); \
        _raw_spin_lock(lock); \
} while (0)

#define spin_lock_irqsave(lock, flags) \
do { \
        local_irq_save(flags); \
        preempt_disable(); \
        _raw_spin_lock(lock); \
} while (0)

do correct me if i am wrong!

regards
prashant.


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux