Solved

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

Posted on 2004-09-10
8
323 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 3

Author Comment

by:rfr1tz
Comment Utility
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
Comment Utility
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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

6 Experts available now in Live!

Get 1:1 Help Now