RE: design with spin_locks

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

 



 

> -----Original Message-----
> From: kernelnewbies-bounce@xxxxxxxxxxxx 
> [mailto:kernelnewbies-bounce@xxxxxxxxxxxx] On Behalf Of 
> anubhav rakshit
> Sent: Thursday, March 22, 2007 6:10 PM
> To: kernel mail
> Subject: design with spin_locks
> 
> I am writing a driver,it has a data structure which is 
> modified in both interrupt context and user context.My 
> current design is some thing like this:
> 
> struct shared_data;
> 
> interrupt_context{
>                              spin_lock_irqsave(&xxx_lock,flags);
>                                   ....modify shared_data....
>                              spin_unlock_irqrestore(&xxx_lock, flags);
> 
> }
> 
> user_context{
>                              spin_lock_irqsave(&xxx_lock,flags);
>                                   ....modify shared_data....
>                              
> spin_unlock_irqrestore(&xxx_lock, flags); }
> 
> 
> Now when user_context has the ability to sleep,i am wondering 
> if there is a way to safely sleep in the user context while 
> waiting for the spinlock to be released by the 
> interrupt_context?Something like this
> 
> interrupt_context{
>                              spin_lock_irqsave(&xxx_lock,flags);
>                                   ....modify shared_data....
>                              spin_unlock_irqrestore(&xxx_lock, flags);
>                              wake_up_interruptible(&wait_queue);
> }
> 
> 
> 
> user_context{
> 
>                             if(wait_event_interruptible(&wait_queue,\
> 
> spin_trylock_irqsave(&xxx_lock,flags))
>                                 return -ERESTARTSYS;
>                                   ....modify shared_data....
>                              
> spin_unlock_irqrestore(&xxx_lock, flags); }
> 
> 
> Here the function spin_trylock_irqsave() will try to grab the 
> spinlock  if it succeeds it returns true and behaves just 
> like spin_lock_irqsave(),if  it is unable to grab the 
> spinlock,the function returns false and the process is put to sleep.
> This way i dont waste cpu cycles,by spinning uselessly.Is 
> this possible and will it be more efficient than the previous case?
Not sure if this is possible but spinning for short duration may be more
efficient than first sleeping and then waking up and resuming again.
Spinlocks are meant to be hold for very short duration and if you are
holding them for long in any context then you may want to go back and
look closely at your critical section.
> 
> 
> 
> 
> --
> Anubhav Rakshit
> 
> --
> To unsubscribe from this list: send an email with 
> "unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx Please 
> read the FAQ at http://kernelnewbies.org/FAQ
> 

--
To unsubscribe from this list: send an email with
"unsubscribe kernelnewbies" to ecartis@xxxxxxxxxxxx
Please read the FAQ at 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