LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   A little question about SMP synchronization (https://www.linuxquestions.org/questions/programming-9/a-little-question-about-smp-synchronization-488334/)

queuebil 09-30-2006 05:36 PM

A little question about SMP synchronization
 
Hi all!
I need to synchronize some kernel routines in accessing a shared variable. I would use semaphores (like sema_init(), down_interruptible(), up(), etc.). In order to make it work also on SMP architectures, should I use spinlocks too? Or are semaphores sufficient?
Thank you and sorry for bad english

paulsm4 09-30-2006 08:27 PM

kernel primitives are SMP-aware
 
Hi -

The short answer is that, with current versions of Linux (certainly 2.6.x) you can safely use either kernel spinlocks or kernel semaphores with a multi-CPU (or multi-core) SMP system. the same restrictions now apply for SMP as for uniprocessors: if you cannot block, then you need a spinlock. Otherwise, you can (and usually should) use kernel semaphores.

Much more detailed info can be found in this excellent article from Linux Magazine:

Concurrency in the Kernel, Linux Magazine, November 2005
http://www.linux-mag.com/content/view/2360/0/1/6/

'Hope that helps .. PSM

queuebil 10-01-2006 03:59 AM

Thank you for aswering, it was very helpful. The article covers almost everything I need to know for now, but...

Quote:

with current versions of Linux (certainly 2.6.x) you can safely use either kernel spinlocks or kernel semaphores with a multi-CPU (or multi-core) SMP system. the same restrictions now apply for SMP as for uniprocessors: if you cannot block, then you need a spinlock. Otherwise, you can (and usually should) use kernel semaphores.
I forgot to say i'm not working on kernel 2.6.x, but on 2.4.25. Is it still safe to use only semaphores with this old version?


All times are GMT -5. The time now is 03:55 PM.