mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* question about __raw_spin_lock()
@ 2006-09-06  8:25 Roland Kuhn
  2006-09-27 15:55 ` Steven Rostedt
  0 siblings, 1 reply; 2+ messages in thread
From: Roland Kuhn @ 2006-09-06  8:25 UTC (permalink / raw)
  To: Linux-Kernel@Vger. Kernel. Org

[-- Attachment #1: Type: text/plain, Size: 1420 bytes --]

Dear experts!

Trying to inform myself about the locking possibilities on i386, I  
read linux/include/asm-i386/spinlock.h. I'm no expert on inline  
assembly, so I'm asking myself what would happen on a very big system  
if more than 128 threads are waiting on the same raw_spinlock_t.  
Would the 129th locker erroneously succeed immediately?

As a side note: I was looking because I have to implement a simple  
lock between processes in shared memory, and unfortunately I cannot  
use the NPTL :-( SysV semaphores presumably are much too heavy to  
protect simple linked list operations (no scanning of the list under  
the lock, just inserting on one end and removing from the other).  
Does anybody have a better idea than spinning in user space---with a  
nanosleep now and then---or does this have problems I'm not aware of?

Thanks for your help,

                     Roland

--
TU Muenchen, Physik-Department E18, James-Franck-Str., 85748 Garching
Telefon 089/289-12575; Telefax 089/289-12570
--
CERN office: 892-1-D23 phone: +41 22 7676540 mobile: +41 76 487 4482
--
Any society that would give up a little liberty to gain a little
security will deserve neither and lose both.  - Benjamin Franklin
-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GS/CS/M/MU d-(++) s:+ a-> C+++ UL++++ P+++ L+++ E(+) W+ !N K- w--- M 
+ !V Y+
PGP++ t+(++) 5 R+ tv-- b+ DI++ e+++>++++ h---- y+++
------END GEEK CODE BLOCK------



[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 186 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: question about __raw_spin_lock()
  2006-09-06  8:25 question about __raw_spin_lock() Roland Kuhn
@ 2006-09-27 15:55 ` Steven Rostedt
  0 siblings, 0 replies; 2+ messages in thread
From: Steven Rostedt @ 2006-09-27 15:55 UTC (permalink / raw)
  To: Roland Kuhn; +Cc: Linux-Kernel@Vger. Kernel. Org

Trying to catchup on LKML (only 5234 messages to go :P)

On Wed, 2006-09-06 at 10:25 +0200, Roland Kuhn wrote:
> Dear experts!
> 
> Trying to inform myself about the locking possibilities on i386, I  
> read linux/include/asm-i386/spinlock.h. I'm no expert on inline  
> assembly, so I'm asking myself what would happen on a very big system  
> if more than 128 threads are waiting on the same raw_spinlock_t.  
> Would the 129th locker erroneously succeed immediately?

Any machine today that has 129 processors had better be a 64 bit
machine. And this is not an issue on x86_64.  If you do have a 128+ CPU
i386 machine, then modify the kernel yourself :)

> 
> As a side note: I was looking because I have to implement a simple  
> lock between processes in shared memory, and unfortunately I cannot  
> use the NPTL :-( SysV semaphores presumably are much too heavy to  
> protect simple linked list operations (no scanning of the list under  
> the lock, just inserting on one end and removing from the other).  
> Does anybody have a better idea than spinning in user space---with a  
> nanosleep now and then---or does this have problems I'm not aware of?

userspace spinlocks are really bad.  Unless you pin all the threads that
share that lock to their own CPU, you can have one thread preempting
another that owns the lock, and then spin waiting for the owner to
release the lock, while the owner is waiting to run on the processor
that has the spinning thread.  In the RT world, this can spell death.

Look into using futexes.  They are fast userspace mutexes.  I believe
the pthread mutex code uses these.  They are also robust and can also
include priority inheritance.  They run in userspace unless there is
contention, which they then go into the kernel.

-- Steve



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-09-27 15:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-09-06  8:25 question about __raw_spin_lock() Roland Kuhn
2006-09-27 15:55 ` Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®