LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-30-2006, 05:36 PM   #1
queuebil
LQ Newbie
 
Registered: Feb 2006
Posts: 3

Rep: Reputation: 0
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
 
Old 09-30-2006, 08:27 PM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
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
 
Old 10-01-2006, 03:59 AM   #3
queuebil
LQ Newbie
 
Registered: Feb 2006
Posts: 3

Original Poster
Rep: Reputation: 0
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?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Slack 10.2, 2.6.13 kernel, SMP question Twister512 Slackware 18 11-28-2005 10:22 PM
email synchronization (not file synchronization) Moebius Linux - Software 6 10-05-2004 05:31 AM
Re:Simple smp question MunCH Slackware 3 06-23-2004 02:48 AM
Quick SMP kernel question Coldfirex Slackware 3 10-19-2003 11:05 AM
SMP box question icel0rd Linux - Hardware 3 10-19-2002 12:41 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration