Re: spinlock

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

 



On Fri, Feb 28, 2003 at 08:44:07PM +0100, Frank A. Uepping wrote:
> On Friday 28 February 2003 11:41, you wrote:
> > 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>
> 
> For clarification.
> When I have a struct that I access from proc and int context I have
> to use the _irqsave() variant in the proc context (in order to prevent
> an irq to be happen) but in the int context I stick to the common variant.
> Further a spinlock in not allowed to hold while the current proc sleeps.
> Semaphores are not allowed to use in int context because they might
> sleep/block.
> /FAU

Yes. Except you should probably use _irqsave/_irqrestore in int context
too (it saves flags and restores them un unlock so it does not matter if
interrupts were enabled befor). IIRC in bottomhalves/tasklets interrupts
are enabled, so you need irqsave there.

-------------------------------------------------------------------------------
						 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