Solved

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

Posted on 2004-09-10
8
326 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

911 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now