PPC arch and spinlocks

Garcia Jérémie GARCIAJ at 3il.fr
Thu Jun 9 00:29:38 EST 2005

Hi everybody, I need your help one more time.
I'm new to kernel device driver (linux newbie) and I'd like to control concurrent access
to our hardware resources. (I'm working on a ppc405EP platform uniprocessor)
Reading the Allessandro Rubini book (Linux device drivers) and many lists and guides on the web,
I concluded that spinlocks were very adapted to my expectations.
So, I decided to declare a spinlock in my module and offer, via ioctl, the possibilty to user
space programs to handle it with spin_trylock(), spin_lock() and spin_unlock().
Unfortunately I saw that was not working properly and so, I wanted to debug the "spinlock-process"
printing the value of it after calling one of the above routine: 

spinlock_t my_spinlock = SPIN_UNLOCKED;
printk("value: %d\n",my_spinlock.lock);

At compile time, I had an error that told me no "lock" member for this type of structure.
And it was write, cause I investigated and noticed that the definition used for "spinlock_t" 
structure was the following in <linux/spinlock.h>:

#if (__GNUC__ > 2 || __GNUC_MINOR__ > 95)  
  typedef struct { } spinlock_t;
  #define SPIN_LOCK_UNLOCKED (spinlock_t) { }   //  empty structure...

I don't understand cause I thought that spinlocks were recommended for SMP platforms but could be
safely used in uni-processor platforms too. 
So did I miss something to be able to use them (in config?? is it specific to PPC arch??)?
If not, is there a way to get a similar behavior with others technics (mutex??). I saw Posix mutex? Are they
usable in kernel mode?
I really need to have an equivalent of the spin_trylock() routine in order not to have the processus waiting till
the semaphore is available when tryin to get it. (ask and take if available, but not sleep).

Please give me some tips.
Tks a lot for your precious help!!

More information about the Linuxppc-dev mailing list