Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

6.1 A hardware mental model (non-architectural)

Everything in this section is non-architectural. DDI0487 does not describe pipelines, store buffers or line-fill buffers. It is deliberately abstract, and it defines only which outcomes are permitted, using observers, “observed by” and “complete” (7.1). A real core is one way of producing a subset of those outcomes.

So why build a hardware model at all? The abstract rules are hard to remember without one. Once you can picture where an access physically is at a given moment, most of Parts 7, 8 and 14 become predictable:

  • why the SB (store buffering) litmus outcome is allowed;
  • why a DMB is cheap and a DSB is not;
  • why a speculative load can leave a line in the cache.

The rule for using the model is simple. Use it to generate hypotheses, and use the architecture to decide correctness. If the model says “this can’t happen on my core” but the architecture allows it, the code is still wrong. The next core, or the next stepping, may do it.

The pipeline and speculation

A typical out-of-order A-profile core (for example Cortex-A7x, Cortex-X or Neoverse N/V) looks roughly like this:

 fetch ──► decode ──► rename ──► issue queues ──► execute ──► reorder buffer ──► commit (retire)
   ▲   branch predictors                          │                                │
   │   (BTB, history, return stack)              ▼                                ▼
 L1 I-cache / ITLB                        load/store unit ◄──── store buffer (post-commit)
                                                 │
                                          L1 D-cache, DTLB, line-fill buffers
                                                 │
                                          L2 (private) ─► DSU/L3 or interconnect
  • Front end. The predictors guess the next fetch address long before any branch resolves, so instruction fetch is speculative almost all the time. When the MMU is off, those fetches are treated as Normal memory (6.5). DDI0487 then limits speculative fetches to memory close to the code being executed (roughly the same or the next translation-granule-sized block), but anything in that window, such as MMIO placed right after the image, can still be fetched.
  • Out-of-order back end. Instructions execute when their operands are ready. The reorder buffer (ROB) commits them in program order. Anything that has not yet committed is speculative: it can be squashed after a mispredict, a fault on an older instruction, or an interrupt.
  • The squash is incomplete. On a squash the core restores architectural state (registers, PSTATE, memory as other observers see it). It does not restore microarchitectural state: cache lines filled by squashed loads, TLB entries, prefetcher training and predictor history. That gap is the whole of Part 14 (14.1).
  • In-order cores are not exempt. In-order cores such as Cortex-A53 and Cortex-A55 still predict branches, have non-blocking caches and buffer stores. They reorder memory accesses less, but the architecture gives them the same permissions.

The load path

  1. An address-generation unit (AGU) computes the VA. The DTLB (or a table walk, itself a sequence of memory reads) supplies the PA and the attributes.
  2. On an L1 D-cache hit, the value returns within a few cycles. On a miss, the core allocates a line-fill buffer (LFB, also called an MSHR) and sends a read request outward. Younger loads can hit under that miss, so loads return values out of program order.
  3. If the store buffer holds an older store to the same bytes, the load takes its value from the store buffer (store-to-load forwarding). The PE therefore sees its own store before any other observer can.
  4. The core tracks loads that executed early. If a snoop invalidates a line that an early load read, before that load commits, the core may replay the load. This is roughly how it enforces the ordering the architecture does require, such as same-address read-read coherence, and orderings created by barriers and acquire.

From the architecture’s point of view, a read is globally observed when its value can no longer be changed by a write to the same location from any observer. In the model, that moment is when the value is bound and the core no longer tracks the load against snoops.

The store path

A store has two buffering stages, and the difference between them matters:

StageCommitted?Visible to other PEs?What can remove it
Store queue (pre-commit)NoNeverSquash: the store simply vanishes
Store buffer (post-commit)YesNot yetNothing; it will drain
L1 D-cache line in a unique (writable) stateYesYes, through coherenceEviction or snoop moves it, but the value stays
  • Speculative stores never leave the core. Arm cores keep uncommitted stores in the store queue, and the architecture forbids speculative writes from becoming observable. Squashed stores leave no trace in memory. They can still affect timing, for example through forwarding, which is the basis of Spectre v4 (14.5).
  • Committed but not visible. A committed store waits in the store buffer until the core owns the line in a writable state. For a WB-cacheable line, this means a ReadUnique or MakeUnique transaction on CHI (8.3). Later loads to other addresses execute meanwhile. This is the store→load reordering that the SB litmus test exposes (7.3).
  • Merging. Adjacent stores can merge in the store buffer or in a write-combining buffer. For Normal Non-cacheable and Device-G* memory, that merging is the “Gathering” the attribute permits (6.2).
  • Evictions. A dirty line evicted from L1 or L2 goes through a write-back or eviction buffer. It is now “in the memory system”, but it has not necessarily reached DRAM. Data can sit in a system-level cache, or in a buffer at a home node, indefinitely.

Beyond the core: the interconnect

Outside the core, an access becomes one or more transactions: a request, possibly snoops to other caches, and a response.

  • In a DynamIQ cluster, the DSU (with an optional L3) is the first shared level.
  • In a server or AI SoC, a CMN-style mesh carries the transactions to a home node (HN-F). The home node holds the system-level cache slice and the snoop filter, and it serialises the accesses to each address.
  • Beyond the home node sit the memory controller and DRAM, or, for an MMIO address, an HN-I or bridge and then the peripheral.

The completion response for a write can come from different places:

  • Early acknowledgement. A buffer in the interconnect accepts the write and returns the response itself. This is what the “E” attribute permits.
  • Endpoint acknowledgement. The response comes from the peripheral itself, or from the point that guarantees visibility to it. nE asks for this.

The core cannot tell where a response came from. It only knows that the response has arrived.

Where is an access “in flight”?

The table below is the most useful part of this section. Keep it in mind when reading 7.5–7.9.

Location of the accessArchitecturally, roughlyWhich instruction waits for it
Uncommitted in the ROB or store queueSpeculative; not yet an architectural accessNothing needed; a squash removes it (stores only)
Post-commit store bufferExecuted; not yet observed by other PEsDMB orders later accesses behind it; DSB waits for it
L1/L2 in a coherent stateObserved by the observers in the coherence domainAlready visible to those observers
Interconnect buffer, pre-responseVisible at some point, but not completeDSB waits for the response
Endpoint (DRAM, peripheral)Complete; for nE, from the endpoint’s viewNothing further from the PE

The barrier intuitions follow from the table. They are intuitions, not definitions:

  • DMB. It stops later accesses from becoming observable before earlier ones, typically by holding or tagging them in the load/store unit and the store buffer. It does not have to wait for the buffers to drain (7.5).
  • DSB. It stalls execution until earlier accesses, and earlier cache, TLB and branch-predictor maintenance, are complete. That means waiting for responses from the far end of the interconnect, which is why a DSB can cost hundreds or thousands of cycles on a large mesh (7.6).
  • ISB. It flushes the pipeline so that later instructions are refetched under the current context. It says nothing about the memory buffers (7.8).

Bring-up note: On pre-silicon platforms the “in flight” window can be far longer or far shorter than on silicon. FVP executes each PE’s instructions in order and models no store buffer, and QEMU TCG shows at most the reorderings of its host, so both are close to sequentially consistent in practice. Emulators and FPGAs often have extreme interconnect latency ratios. A missing barrier that “works” on FVP proves nothing. A litmus run on emulation or silicon is the first real test (7.11).

Validation note: To show that the store buffer is real on a given core, run the SB litmus test (each thread does a store, then a load of the other thread’s location) without barriers. The relaxed outcome (both loads read 0) should appear within a few million iterations under litmus7 stress. If it never appears on an out-of-order core, suspect the test harness (threads not actually concurrent, or same-core affinity), not the hardware. On the PMU, L1D_CACHE_REFILL (0x0003) and BUS_ACCESS (0x0019) confirm that the lines are really ping-ponging between cores. Their absence means the test is not contending.

What this model does not cover

  • Prefetchers. Hardware prefetchers allocate lines that no instruction, speculative or otherwise, asked for. The architecture covers them under the general rule that a cacheable location can be allocated into a cache at any time (6.3).
  • Multi-copy atomicity. Whether a store becomes visible to all other observers at the same time. Armv8 is other-multi-copy atomic. In this model, that corresponds to a store buffer that is private to one PE and is not shared with siblings, whereas some POWER designs share it between SMT threads (7.2).
  • Coherence protocol details. MOESI states, snoop filters and directories are in 8.2. The mapping onto CHI transactions is in 8.3.

Checkpoint

Q6.1.1 Two cores run STR W1,[X0]; LDR W2,[X3] and STR W1,[X3]; LDR W2,[X0] respectively (both locations initially 0, W1=1). Both loads return 0. In the hardware model, what most directly explains this outcome?

  • A. Speculative execution of the loads before the branch predictor resolved
  • B. A non-coherent L1 D-cache that hid each store from the other core
  • C. Each committed store waiting in its core’s store buffer while the younger load to a different address read the coherent cache
  • D. The interconnect reordering the two stores at the home node
Answer

C. This is the SB litmus test. The architecture permits the outcome because store→load order to different addresses is not preserved without a barrier. Microarchitecturally, a post-commit store buffer causes it. B is tempting but wrong: the caches are coherent, and the stores simply have not reached them yet. There are no branches, so A does not apply.

Read more: Arm ARM (DDI0487), The AArch64 Application Level Memory Model, “Ordering relations”; herdtools aarch64.cat

Q6.1.2 A load executes speculatively down a mispredicted path, misses in L1 and allocates a line. The core then squashes it. Which statement is correct?

  • A. No architectural register or memory value changes, but the line may remain allocated in the cache
  • B. The core must evict the line on squash, or the architecture is violated
  • C. The line is allocated only if the location is Device memory
  • D. The load was never issued to the memory system, because loads are issued only at commit
Answer

A. A squash restores architectural state only. Cache allocation is microarchitectural, and the architecture permits allocating cacheable locations at any time. That is exactly the cache-timing channel behind Spectre. D describes a hypothetical “issue at commit” design, which would be far too slow; real cores issue loads early. C is backwards: Device memory is never accessed speculatively by data loads.

Read more: Arm ARM (DDI0487), “Speculative accesses” and “Cache behavior”; Arm Cache Speculation Side-channels whitepaper

Q6.1.3 A test passes on FVP and QEMU TCG but fails intermittently on an emulation platform. The failure goes away when a DMB is added between a data store and a flag store. What is the best conclusion?

  • A. The emulation platform has a coherency bug, because FVP is the Arm reference model
  • B. The DMB hides a timing difference, so the code was correct without it
  • C. FVP is wrong, because it should model the store buffer
  • D. The code depended on store→store order that the architecture does not guarantee; FVP and TCG simply never reorder those stores
Answer

D. FVP and TCG are architecturally conformant without exhibiting the reorderings the architecture permits. Passing on them is no evidence of correct ordering. A treats “the reference model never did it” as if it meant “it is forbidden”, which it does not. C is wrong because a model is not required to show every permitted behaviour.

Read more: Arm ARM (DDI0487), “Ordering requirements”; Fast Models documentation (FVP memory model limitations)