Re: spinlocks.

From: Tigran Aivazian (tigran@sco.COM)
Date: Tue Feb 08 2000 - 08:32:46 EST


Hi Ashutosh,

You asked if it is safe to do something like this:

lock_kernel();
spin_lock_irqsave(&lock, flags);

/* critical section ... */

spin_unlock_irqrestore(&lock, flags);
unlock_kernel();

Yes, it is safe, but if you really need big kernel lock why do you also
use spinlocks, unless you have some old code which you are porting to be
more scalable and gradually remove the need for big kernel lock?

Also, please do this:

a) Read Documentation/spinlocks.txt file, please. For example, in the
above you use the strong form of spinlocks which disables/enables irqs as
well, i.e. assumes that your shared resource must be protected from access
in both process and interrupt context.

b) If you have a case where both interrupt and non-interrupt (e.g.
ioctl()) code access the same data structures then you should use
spin_lock_irqsave() in the non-interrupt code and spin_lock() in the
interrupt handler as in:

my_ioctl()
{
       spin_lock_irqsave(&lock, flags);
       ...
       spin_unlock_irqrestore(&lock, flags);
}

my_irq_handler()
{
       spin_lock(&lock);
       ...
       spin_unlock(&lock);
}

Regards,
------
Tigran A. Aivazian | http://www.sco.com
Escalations Research Group | tel: +44-(0)1923-813796
Santa Cruz Operation Ltd | http://www.ocston.org/~tigran

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



This archive was generated by hypermail 2b29 : Tue Feb 15 2000 - 21:00:12 EST