Re: spinlock

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, Feb 28, 2003 at 12:29:54AM +0100, Rok Papež wrote:
> Hello!
> 
> Dne četrtek 27. februar 2003 20:47 je Frank A. Uepping napisal(a):
> 
> > Is that true that a spinlock gets undefined when compiled
> > on a uniprocessor system?
> 
> No.

YES, IT DOES. Except _irqsave/_irqrestore variants (they reduce to
cli/sti). And for 2.4, that is. With preempt patched (IIRC they are
included in late 2.5) they become magic.

> > Thus spinlocks can't be used to provide mutual exclusion between
> > concurrently executing processes on a uniprocessor system, isn't is?
> 
> No.

There is a limitation. You must not, under penalty of complete machine
freeze, call schedule() with spinlock locked. You can never be
interrupted except by interrupt unless you call schedule() [except with
preept patches. Think of a preempt kernel as always running SMP].

You however must always write code for SMP and on UP spinlocks reduce so
that they guarantee the same as on SMP taking into account that running
on UP guarantees some things itself.

> I use them on UP as mutexes.. heavily. You use spinlock if structures you are 
> protecting are being accessed from interrupt/timer/softirq context.

Only _irqsave/_irqrestore variants! Unsing the normal variant to lock
against interrupt is a bug under penalty of complete machine freeze.

> Mutexes are to be used when structures are accessed *only* from process 
> context.

Yes, semaphores can only be manipulated in process context.

-------------------------------------------------------------------------------
						 Jan 'Bulb' Hudec <bulb@ucw.cz>
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux