Questions on semaphores
Hi people, I have two question regarding the i386 semaphore implementation in kernel 2.4.19.
Please dont blame me if they are too obvius; i'm a newbie in kernel hacking :)
The functions __down, __down_interruptible and __down_trylock (defined in arch/i386/kernel/semaphore.c) use the global spinlock 'semaphore_lock' to access some fields of the semaphore they are working on:
1) Is there any reason to do this?
2) Wouldn't it be more scalable to use a per-semaphore lock instead a global spinlock?
The function __down_trylock try to get the spinlock using spin_lock_irqsave, instead of using spin_lock_irq:
1) why? :)
Thanks in advance,
Juanma
Signature · 1 line
/jm
Quoted 7 lines · Juan M. de la Torre
Hi people, I have two question regarding the i386 semaphore implementation in kernel 2.4.19.
Please dont blame me if they are too obvius; i'm a newbie in kernel hacking :)
Quoted 6 lines
The functions
__down,__down_interruptibleand__down_trylock(defined inarch/i386/kernel/semaphore.c) use the global spinlock 'semaphore_lock' to access some fields of the semaphore they are working on:1) Is there any reason to do this?
It was easy to do.
Quoted 3 lines
2) Wouldn't it be more scalable to use a per-semaphore lock instead a global spinlock?
Yes it would be more scalable, but not as much as you would think. The __down, __down_interruptible and __down_trylock code only gets invoked when the semaphore is contended for.
Quoted 5 lines
The function
__down_trylocktry to get the spinlock usingspin_lock_irqsave, instead of usingspin_lock_irq:1) why? :)
The __down_trylock() code can be called with another lock held. The spin_lock_irqsave()/spin_lock_irqrestore() interface is used to restore the irq value for the lock that may already be held.
Quoted 3 lines
Thanks in advance,
Juanma
The code in the 2.5 tree was changed a while back to use the spinlock in the wait_queue_head_t to replace the global semaphore spin lock. So, this has been "FIXED" in 2.5.
Signature · 2 lines
Bob Miller Email: [email protected] Open Source Development Lab Phone: 503.626.2455 Ext. 17