Re: spinlocks dont work

From: Richard B. Johnson
Date: Fri Feb 13 2004 - 11:52:45 EST


On Fri, 13 Feb 2004 RANDAZZO@xxxxxxxxxxx wrote:

> On my uniprocessor system, I have two LKM's
>
> driver1 takes hold of the spinlock....but does not release it...
> driver2 attempts to take hold, and is allowed!!!!
> how come spin locks don't work?????
> how can I restrict access (to hardware) to only one driver at a time???
> should I use semaphores, etc...
>

Spin-locks do work. However, you need to use the same lock-object
for each execution path. A common error is to do:

static spinlock_t device_lock;

... in one file, and...

static spinlock_t device_lock;

... in another...

There is also a possibility that the kernel you are using does not
impliment spin-locks if it's not compiled for SMP. To make sure,
compile your uniprocessor machine for SMP.

Basically, you use semaphores when the particular execution path
can sleep, and spin-locks when they can't. You can never sleep
in an ISR, so you need to use spin-lock protection where something
could change as a result of an interrupt.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.24 on an i686 machine (797.90 BogoMips).
Note 96.31% of all statistics are fiction.


-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/