* spin_lock doesn't work?!?
@ 2007-08-29 21:26 melinda develey
2007-08-29 21:38 ` Scott Wood
2007-08-29 21:40 ` Wolfgang Reissnegger
0 siblings, 2 replies; 6+ messages in thread
From: melinda develey @ 2007-08-29 21:26 UTC (permalink / raw)
To: linuxppc-embedded
[-- Attachment #1: Type: text/plain, Size: 317 bytes --]
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.
[-- Attachment #2: Type: text/html, Size: 468 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: spin_lock doesn't work?!?
2007-08-29 21:26 spin_lock doesn't work?!? melinda develey
@ 2007-08-29 21:38 ` Scott Wood
2007-08-29 21:40 ` Wolfgang Reissnegger
1 sibling, 0 replies; 6+ messages in thread
From: Scott Wood @ 2007-08-29 21:38 UTC (permalink / raw)
To: melinda develey; +Cc: linuxppc-embedded
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: spin_lock doesn't work?!?
2007-08-29 21:26 spin_lock doesn't work?!? melinda develey
2007-08-29 21:38 ` Scott Wood
@ 2007-08-29 21:40 ` Wolfgang Reissnegger
2007-08-30 6:30 ` melinda develey
1 sibling, 1 reply; 6+ messages in thread
From: Wolfgang Reissnegger @ 2007-08-29 21:40 UTC (permalink / raw)
To: melinda develey; +Cc: linuxppc-embedded
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: spin_lock doesn't work?!?
2007-08-29 21:40 ` Wolfgang Reissnegger
@ 2007-08-30 6:30 ` melinda develey
2007-08-30 11:50 ` Josh Boyer
2007-08-30 15:36 ` Wolfgang Reissnegger
0 siblings, 2 replies; 6+ messages in thread
From: melinda develey @ 2007-08-30 6:30 UTC (permalink / raw)
To: Wolfgang Reissnegger; +Cc: linuxppc-embedded
[-- Attachment #1: Type: text/plain, Size: 683 bytes --]
>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.
[-- Attachment #2: Type: text/html, Size: 985 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: spin_lock doesn't work?!?
2007-08-30 6:30 ` melinda develey
@ 2007-08-30 11:50 ` Josh Boyer
2007-08-30 15:36 ` Wolfgang Reissnegger
1 sibling, 0 replies; 6+ messages in thread
From: Josh Boyer @ 2007-08-30 11:50 UTC (permalink / raw)
To: melinda develey; +Cc: linuxppc-embedded
On Wed, 29 Aug 2007 23:30:22 -0700 (PDT)
melinda develey <melinda.develey70@yahoo.com> 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.
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: spin_lock doesn't work?!?
2007-08-30 6:30 ` melinda develey
2007-08-30 11:50 ` Josh Boyer
@ 2007-08-30 15:36 ` Wolfgang Reissnegger
1 sibling, 0 replies; 6+ messages in thread
From: Wolfgang Reissnegger @ 2007-08-30 15:36 UTC (permalink / raw)
To: melinda develey; +Cc: linuxppc-embedded
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.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2007-08-30 15:36 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-08-29 21:26 spin_lock doesn't work?!? melinda develey
2007-08-29 21:38 ` Scott Wood
2007-08-29 21:40 ` Wolfgang Reissnegger
2007-08-30 6:30 ` melinda develey
2007-08-30 11:50 ` Josh Boyer
2007-08-30 15:36 ` Wolfgang Reissnegger
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).