Solved

How to invoke Spin Locks methods or macros in Red Hat Linux?

Posted on 2004-09-10
8
332 Views
Last Modified: 2010-08-05
Hi,

I need to implement some section of code in Linux that I must use Spin Locks. My box is Red Hat AS Enterprise 3.0.

If you've known about the Spin Locks in Red Hat Linux: how to use them, how to invoke their library functions or system calls, please give some help.

Thanks a lot,

Rfr1tz

0
Comment
Question by:rfr1tz
  • 3
  • 2
8 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12033351
Hi Rfr1tz,

Spinlocks are available inside the kernel but I do not think they are provided in the user library ... What are you trying to accomplish? Won't smeaphores and/or conditional variables of some help?

sunnycoder
0
 
LVL 8

Expert Comment

by:manish_regmi
ID: 12037349
hi,
  If you are In user space you need spinlocks if you are writing multithreaded apps.
 So you might be using pthreads. Pthreads have a righ locking mechanisms including mutex, condvars, barriers, semaphores etc.

I think pthread mutex is what you are looking for.
int   pthread_mutex_lock(pthread_mutex_t *);
int   pthread_mutex_unlock(pthread_mutex_t *);

http://www.opengroup.org/onlinepubs/007908799/xsh/pthread.h.html

google for a tut on pthreads.
http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html
 
regards manish
 
0
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12041295
Hi Manish,

I would not recommend using pthreads just for using their locking mechanisms. A lot of things can go wrong with an application which uses threads while there is no need. :)
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 3

Author Comment

by:rfr1tz
ID: 12044795
Hi sunnycoder and manish_regmi,

Our system is SMP (symmetric multiple processors). And The assignment requires that we must implement spin locks so that it would be polled coninuously to eb able to get the lock in the shortest period of time in some special cases whre the waiting time is very short.
 
I read into some articles of internets and found that some functions of spin locks are amentioned like:
-spin_lock_irq()
-spin_unlock_irq()
- spin_lock_irqsave()
- spin_unlock_irqrestore()

...

I don't know whether we can called these functions at user levels or not? If you alrready have experiences with these, please help.
I also looked into /usr/include/asm/spinlocks.h

I found the file there but the file is empty. Do you have any idea why the file is empty? And also, if I'd liek to look into the file spinlock.c. Do you know where this file is, which directory the file resides?

Thanks a lot,

Rfr1tz

0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 125 total points
ID: 12051582
Look for

documentation/spinlocks.txt  ... It will give information about the spinlocks in your kernel.

-spin_lock_irq()
-spin_unlock_irq()
- spin_lock_irqsave()
- spin_unlock_irqrestore()

These are available at kernel level only. An names suggest, they are used for interrupt request handling
0
 
LVL 8

Assisted Solution

by:manish_regmi
manish_regmi earned 125 total points
ID: 12051590
hi,
 Spinlocks in SMP are more difficult to implement. You cannot just implement traditional test_and_set() mechanism. I have never used spinlocks in user space. The function you gave is for kernel.
 I think it will be better you copy linux spinlock code from linux kernel tree (and remember include those with #ifdef CONFIG_SMP). And there are a lot of things you need to omit.

http://lxr.linux.no/source/include/linux/spinlock.h
http://lxr.linux.no/source/include/asm-i386/spinlock.h

CAn you extract what you require?

regards manish
 
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Expect & sshpass package for Solaris 10 x86 15 964
mysql server issue in linux server 5 64
read a word from a file in linux shell script 4 79
Embeded Linux on Router 9 109
Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question