lkml.org 
[lkml]   [2000]   [Feb]   [8]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: spinlocks.
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/

\
 
 \ /
  Last update: 2005-03-22 13:56    [W:0.035 / U:0.372 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site