Re: Spinlock query

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

 




In your driver, the critical section __disables__ interrupts,
does work in a critical section, then enables them with this:

int critical_section(struct global *params,...){
     unsigned long flags;
     spin_lock_irqsave(&params->lock, flags);
         do_critical_uninterruptible_code();
     spin_unlock_irqrestore(&params->lock flags);
  }

The interrupts are disabled on the current CPU and the flags
have been saved. The critical section of code executes without
being interrupted. In the event that another CPU tries to execute
the same code path, it will busy-wait until the spin-lock is
unlocked.



In the interrupt service routine, you do this:

irqreturn_t isr(.....) {
     spin_lock(&params->lock);
     ....
     ....
     spin_unlock(&params->lock);
     return WHATEVER;
}

Since an interrupt on the current CPU cannot occur if a spin-lock has
been taken, any other CPU will busy-wait until the lock is released.
You do not need to save/restore the flags because you know what they
are (interrupts are disabled) and they will not be changed by the
code.




Make sure you initialize any spin-locks before use. Also make sure
the spin-lock is the same one being used everywhere in your driver!
A spin-lock, private to a procedure (common newbie mistake), will not
work!

init(...)
{
     spin_lock_init(&params->lock);

}


Cheers,
Dick Johnson
Penguin : Linux version 2.6.16.24 on an i686 machine (5592.62 BogoMips).
New book: http://www.AbominableFirebug.com/
_


****************************************************************
The information transmitted in this message is confidential and may be privileged.  Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited.  If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to DeliveryErrors@xxxxxxxxxxxx - and destroy all copies of this information, including any attachments, without reading or disclosing them.

Thank you.

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/



[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