Re: Spinlocks under uniprocessor running non preemptible kernel



Josef Moellers <josef.moellers@xxxxxxxxxxxxxxxxxxx> writes:
MAx wrote:
Does that mean spinlocks do not do the job they are meant to do on a
uniprocessor system with
linux 2.4.x(non-preemptible kernel)

On a uniprocessor, either a spinlock() call will succeed immediately
or hang infinitely.

It can only 'hang indefinitely' if an attempt to lock a locked
spinlock which can never be preempted by the lock holder can occur.

For a non-preempable MP kernel running on an uniprocessor, there is
exactly one situation when this could occur:

a) a spin lock is used for synchronization among code running
at different 'interrupt levels' (hard irq, soft irq, process
context)

b) the 'higher-level' code does not disable execution of the
'lower level' code before trying to lock the spin lock.

An example would be an interrupt handler interrupting code running in
process context which acquired a spin lock but didn't disable
interrupts. The interrupt handler code will then just spin forever.

But the same issue can happen on a multiprocessor if this interrupt
handler would interrupt a process holding ... running on the same
CPU, meaning this would be a programming error.




.



Relevant Pages

  • Re: KeQueryPerformanceCounter
    ... code running in a VM can be preempted in times when ... it can not be preempted on a real machine. ... Once we get the tick we schedule a DPC. ... In it we check we query the performance counter of the processor to see how many times the processor has ticked since the last time we got a tick from that interrupt source. ...
    (microsoft.public.development.device.drivers)
  • Re: FreeBSD memguard + spinlocks
    ... When in interrupt context malloc must be called with M_NOWAIT, this is because I can't sleep inside a interrupt. ... So I think fundamental memguard is flawed and should be using MTX_SPIN instead of MTX_DEF otherwise it can't be called from inside a interrupt or when a spin lock is held. ... Fast interrupt handlers are allowed unlock to acquire spinlocks so as to avoid deadlock because of the borrowed context. ...
    (freebsd-hackers)
  • FreeBSD memguard + spinlocks
    ... When in interrupt context malloc must be called with M_NOWAIT, ... So I assume while holding a spin lock any mallocs I ... spinlock, and then I'm calling malloc with M_NOWAIT. ...
    (freebsd-hackers)
  • Re: spin lock
    ... Elizabeth D Rather wrote Re: spin lock ... run before asking for the resource. ... has it they get a chance to release it. ... Wasn't there an *interrupt* involved in the OP's question? ...
    (comp.lang.forth)