Question and patch about spinlocks (x86)

From: Mark Zealey (
Date: Thu Oct 11 2001 - 15:36:55 EST

Just looking through at the spinlock assembly I noticed a few things which I
think are bugs:
         "js 2f\n" \
         ".section .text.lock,\"ax\"\n" \
         "2:\t" \
        "cmpb $0,%0\n\t" \
         "rep;nop\n\t" \
        "jle 2b\n\t" \
         "jmp 1b\n" \

We do the cmp loop as a 'soft' check, as the lock operand locks the whole system
bus, stopping the system for a while (as much as 70 cycles, I believe). However,
I don't understand why it was put before the 'rep; nop' which just sets the
processor to wait for a bit. Surely it would be better to test *after* we have
waited, as then we have a better chance of it being correct.

Any comments? Attached is a patch to fix it.


Mark Zealey (aka JALH on #zealos and many more)

UL++++>$ G!>(GCM/GCS/GS/GM) dpu? s:-@ a16! C++++>$ P++++>+++++$ L+++>+++++$ !E---? W+++>$ N- !o? !w--- O? !M? !V? !PS !PE--@ PGP+? r++ !t---?@ !X---? !R- b+ !tv b+ DI+ D+? G+++ e>+++++ !h++* r!-- y--


- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to More majordomo info at Please read the FAQ at

This archive was generated by hypermail 2b29 : Mon Oct 15 2001 - 21:00:41 EST