spin_lock doesn't work?!?

6 messages, 4 authors, 2007-08-30 · open the first message on its own page

spin_lock doesn't work?!?

From: melinda develey <hidden>
Date: 2007-08-29 21:32:57

I discovered that I called spin_lock two times consecutively without calling spin_unlock but my code didn't lock (I was managing an ioctl). 
Probably I didn't understand how spin_lock works!!!!

Any help?

       
---------------------------------
Need a vacation? Get great deals to amazing places on Yahoo! Travel. 

Re: spin_lock doesn't work?!?

From: Scott Wood <hidden>
Date: 2007-08-29 21:38:33

On Wed, Aug 29, 2007 at 02:26:15PM -0700, melinda develey wrote: I
discovered that I called spin_lock two times consecutively without
calling spin_unlock but my code didn't lock (I was managing an ioctl). 
Probably I didn't understand how spin_lock works!!!!
spinlocks are no-ops on uniprocessor without preemption.

-Scott

Re: spin_lock doesn't work?!?

From: Wolfgang Reissnegger <hidden>
Date: 2007-08-29 21:40:53

Hi Melinda,

depending on how your kernel is configured spin_locks will compileinto
nothing. For example, if you are compiling a kernel for a single
processor platform without preemptive scheduling then the spin_lock()
calls will be compiled into no-op as they are unnecessary on a non-SMP,
non-preemptive system.

You should still put the spin_lock calls into your code because you
never know if someone else will compile it and for another target. If
someone would, for example, compile the same code for a SMP machine then
the spin_lock will actually lock.

Cheers,
   Wolfgang

melinda develey wrote:
I discovered that I called spin_lock two times consecutively without
calling spin_unlock but my code didn't lock (I was managing an ioctl).
Probably I didn't understand how spin_lock works!!!!

Any help?

------------------------------------------------------------------------
Need a vacation? Get great deals to amazing places
<http://us.rd.yahoo.com/evt=48256/*http://travel.yahoo.com/;_ylc=X3oDMTFhN2hucjlpBF9TAzk3NDA3NTg5BHBvcwM1BHNlYwNncm91cHMEc2xrA2VtYWlsLW5jbQ-->on
Yahoo! Travel.


------------------------------------------------------------------------

_______________________________________________
Linuxppc-embedded mailing list
Linuxppc-embedded@ozlabs.org
https://ozlabs.org/mailman/listinfo/linuxppc-embedded

Re: spin_lock doesn't work?!?

From: melinda develey <hidden>
Date: 2007-08-30 06:30:24

  >You should still put the spin_lock calls into your code because >you
never know if someone else will compile it and for another >target. If
someone would, for example, compile the same code for a SMP >machine then
the spin_lock will actually lock.
  I used the spinlock both in an interrupt handler to protect a group of variables (because in an interrupt I can't use a semaphore) and the same spinlock in a ioctl handler where the same group of variables is accessed. Is this wrong? I have a 2.6.19.2 linux kernel.
   
  Thank you,
  Melinda.
   
   
   

       
---------------------------------
Ready for the edge of your seat? Check out tonight's top picks on Yahoo! TV. 

Re: spin_lock doesn't work?!?

From: Josh Boyer <hidden>
Date: 2007-08-30 11:53:13

On Wed, 29 Aug 2007 23:30:22 -0700 (PDT)
melinda develey [off-list ref] wrote:
  >You should still put the spin_lock calls into your code because >you
quoted
never know if someone else will compile it and for another >target. If
someone would, for example, compile the same code for a SMP >machine then
the spin_lock will actually lock.
  I used the spinlock both in an interrupt handler to protect a group of variables (because in an interrupt I can't use a semaphore) and the same spinlock in a ioctl handler where the same group of variables is accessed. Is this wrong? I have a 2.6.19.2 linux kernel.
You might want to use spin_lock_irq instead.  That will disable
interrupts in the critical section in the ioctl.  Seems more like what
you are trying to do.

josh

Re: spin_lock doesn't work?!?

From: Wolfgang Reissnegger <hidden>
Date: 2007-08-30 15:36:58

Hi Melinda,

I agree with Josh, you should use spin_lock_irqsave(), especially in
your ioctl() routine. spin_lock_irqsave will not compile into a no-op,
even on a single processor machine and will at least disable interrupts.
On SMP machines they will also spin.

Depending on the type of access of the variables in your ioctl()
routine, you might want to consider using read/write spin-locks.

It is not wrong to use spin_locks the way use want to use them.
spin_locks are the right tool to protect a short section in your code.

Cheers,
   Wolfgang

melinda develey wrote:
    >You should still put the spin_lock calls into your code because >you
    >never know if someone else will compile it and for another >target. If
    >someone would, for example, compile the same code for a SMP
    >machine then
    >the spin_lock will actually lock.
    I used the spinlock both in an interrupt handler to protect a group
    of variables (because in an interrupt I can't use a semaphore) and
    the same spinlock in a ioctl handler where the same group of
    variables is accessed. Is this wrong? I have a 2.6.19.2 linux kernel.
     
    Thank you,
    Melinda.
     
     
     

------------------------------------------------------------------------
Ready for the edge of your seat? Check out tonight's top picks
<http://us.rd.yahoo.com/evt=48220/*http://tv.yahoo.com/> on Yahoo! TV.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help