Skip to content
HUBrisOrigami project journal
Color Schemes
Color Scheme Browser
Desktop SchemesBase · gamma 1.7
Monitor gamma
Chrome type · pointer

/usr/lib/X11/schemes · x_eoe_6530m

IRIS InSight: HUBris Library

HUBris Library / Engineering Notes / The Faithful Lock That Serialised the Machinepage 48 of 97

NavigatorHUBris Library
Engineering Notespage 48 of 97

Engineering Notes Origin 2000

The Faithful Lock That Serialised the Machine

Modelling the R10000 manual's store-conditional rule exactly serialised an eight-processor Origin 2000, so the project went back to compare-exchange and recorded the three cases it now gets wrong.

The R10000 manual says exactly when a store-conditional fails. We modelled the rule as written, and an eight-processor Origin 2000 running IRIX was serialised. The fix was to model less, on purpose, and to write down what that gives up.

The rule

Load-linked and store-conditional are the pair of instructions guest locks are built from. Load the word with LL, compute, store it back with SC, and SC fails if anything touched the word in between. The R10000 manual (version 2.0, October 1996) lists what counts. Between the LL and the SC there must be no exception, no ERET, and no load, store, SYNC, CACHE or PREF, or the SC fails. It also fails on an external intervention, an exclusive or invalidate request, hitting the secondary-cache block that holds the linked address. On the modelled machines that block is 128 bytes.

The first half of that stays inside one processor: note the link at LL, clear it when the same processor does something on the list. The second half is not. Another processor’s store anywhere in the 128-byte block must fail your SC, so something has to look at every store from every other processor.

Doing it faithfully

On 11 September 2026 we added both halves to our QEMU branch. The peer-store half tracked the 128-byte block for each link and cleared it after any peer store. To give link publication, invalidation and SC retirement a defined order, every R10000 LL and SC ran through QEMU’s exclusive section, the mechanism that stops every other processor thread so one can run alone.

Under multi-threaded emulation each guest processor is a host thread, and the exclusive section is the one place they all stop. A guest lock acquisition is an LL and an SC. So each lock attempt, as far as the code shows, sent the processor through that section twice, and while one thread ran inside it the others waited. That is an inference from the mechanism, not a timing.

We profiled an eight-processor Origin 2000 booting IRIX. Stack samples caught processor threads inside the single-step path while their peers waited in the exclusive section, with about 45,000 voluntary context switches per second per processor and 97,000 futex calls per second across the process. Those figures come from sampling, not a controlled measurement, and we have no before-and-after timing of the boot.

Going back

On 12 September we reverted the peer-store rule. The reasoning was about what it bought. No supported guest had been shown to depend on a peer-store failure, and IRIX had reached a multiuser login on four processors across two Origin 200 chassis before the rule landed. It reached one on eight processors the same day, after the revert. QEMU’s own design notes on multi-threaded emulation already treat a compare-exchange as the accepted approximation for every LL/SC target, with its known ABA hole.

The replacement is what every other QEMU LL/SC target does. LL records the address and the value it read. SC succeeds only if the address matches and an atomic compare-and-swap finds the recorded value still in memory. The link breaks on exception entry and on ERET. An exception handler that returns without ERET still fails the SC, which matches the manual, which lists the exception itself as an event.

The same-processor half, and a wrong rationale

We kept the same-processor rule, the intervening load or store, at first. Then on 2 October we removed it on a rationale that turned out to be wrong: we said MIPS only breaks links on exceptions, ERET and external invalidations, and that is not what the R10000 manual says. A later change restored the rule citing the manual, but it never landed. Instead we compared the rule with how QEMU handles the same instruction pair on other architectures. No other target in the comparison clears a reservation on an intervening same-processor load, store or barrier. We followed the comparison, not either side of the argument: the rule had been added for fidelity and removed for cost, and the removal was then challenged for the reason it gave rather than for what it did.

The manual does not forbid the intervening operations. It says SC fails if one occurs. A retry loop that contained one could never succeed on the real processor, so working LL/SC code does not contain them, and for working code the rule changes nothing. That is an inference from the failure rule, not a statement in the manual.

What the model now gives up

We recorded the approximation with its limitation. Store-conditional can succeed where the processor would fail it in three cases:

  1. An intervening same-processor load, store, SYNC, CACHE or PREF.
  2. Another agent’s store, or a coherent I/O write, to a different word of the same 128-byte block.
  3. Another agent writing the linked word and putting the original value back before the SC (the ABA case).

Case 2 can arise in working code but the hardware failure there would be spurious: the linked word still holds what LL read. Case 3 is the one that matters for lock-free algorithms that depend on seeing the intermediate write.

This does not show that no guest needs the stricter rule. It shows that none has been shown to. What would reopen it is a supported guest that misbehaves only because an SC succeeded after an intervening operation or a neighbouring store.

Cases 2 and 3 have no test. We deleted the peer-store test when the CPU tests moved to the Origin 200, where the two aliases of a node’s memory cannot express one shared cached block. A two-processor test on a machine that shares the block is still to write.

Nothing here describes the hardware. The model does not claim accuracy for LL/SC and must not be called hardware-accurate. The bounded claim is smaller: concurrent LL/SC increments on four R10000s across two nodes, run under multi-threaded emulation, lose no counts.