Re: possible spinlock optimization

Lennert Buytenhek (lbuijten@cs.leidenuniv.nl)
Wed, 29 Sep 1999 12:16:40 +0200 (CEST)


"On a uniprocessor queued spinlocks work exactly like normal spinlocks."

Huh? Anyone clues on this? "... exactly like normal spinlocks, that is:
they don't do anything" ?

"KeAcquireQueuedSpinlock" works like this: the function attempts to
acquire the spinlock by using the interlocked-exchange CPU instruction to
place the address of the current processor's PCR in the spinlock."

Surely there are machines without an atomic xchg instruction? And you
can't emulate the atomic behaviour with a spinlock, as we are implementing
one... :-)

"If the spinlock ....... from the spinlock."

1. %eax = pcr_of_this_processor
2. xchg (%eax, &spinlock);
3. if (%eax) return; /* we have the lock */
4. pcr_of_this_processor->waiting = 1
5. %eax->queue = pcr; /* %eax = pcr_of_other_processor */

How do they guarantee that steps 2,4,5 operate atomically?

CPU#0 CPU#1
grab the lock release lock

eax = pcr eax = 0
spinlock <-> eax
spinlock <-> eax
return;

eax = PCR_of_CPU#1

Now CPU#0 has in %eax the PCR of a processor which has just released the
lock, no? So CPU#0 will happily queue itself.... Am I missing something
here?

Greetings,
Lennert Buytenhek

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