Re:locking structures in the kernel

Tigran Aivazian (tigran@sco.COM)
Fri, 1 Oct 1999 09:01:51 +0100 (BST)


Hi,

You said (in particular):

> Another technique I have seen is to wrap the code in cli() sti() pairs
> to protect it from being used while being modified, but I understand
> this is a uniprocessor technique which should be deprecated? Also, I
> have most often seen it used in conjunction with saving and restoring
> flags. Details? Opinions?

All the details are in Documentation/spinlocks.txt which every honest
individual should study (Three Lessons of Linus). Specifically, 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);
}

In UP case, these will be reduced to save_flags(),cli/restore_flags() that
you mentioned.

This was asked recently and Alan Cox explained what to do and I even made
a simple patch to spinlocks.txt to clarify this:

http://www.ocston.org/~tigran/patches/spinlocks-2.3.17.patch

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/