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

8.8 Caches at power transitions

This is the book’s one deep treatment of what happens to caches when a PE, a cluster or the system loses power. PSCI mechanics (CPU_ON, CPU_SUSPEND, the warm-boot entry point) are in 17.4. The MMU-on sequence and the invalidate-at-reset rules are in 9.3. This section covers the data in the caches, and why the order of the steps decides whether it survives.

The problem has two parts. When a cache loses power, its dirty lines are lost unless they were written back. And while a PE is leaving or entering coherency, there is a window where it holds lines that the rest of the system cannot snoop, or where it can see stale lines it was never told to drop.

Cache enable and disable, architecturally

  • SCTLR_ELx.C controls data and unified cacheability for the translation regime. With C == 0, data accesses to Normal memory in that regime are treated as Non-cacheable. With the MMU off (SCTLR_ELx.M == 0), data accesses are Device-nGnRnE regardless. SCTLR_ELx.I controls instruction cacheability in the same way.
  • Clearing C stops new allocations by that regime’s accesses. It does not clean, invalidate or disable the cache. Lines already there stay, dirty lines stay dirty, and the cache keeps answering snoops from coherent observers. A Non-cacheable access to a location that still has a line in the cache is a mismatched-attribute case. Don’t rely on it either hitting or missing (6.6).
  • Speculative accesses through other regimes, or through cacheable translations still in the TLB, can still allocate. Clearing C at EL3 does not stop EL1&0 allocation, though at the point where EL3 powers down the core nothing else runs.

The consequence: “turn the cache off, then clean it” is the only order that leaves a cache with no dirty lines. “Clean, then turn it off” leaves a window in which new writes, including the cleaning routine’s own stack spills, allocate new dirty lines.

Clean to PoC before power-off

Data that must survive the PE’s power-off must be at the PoC, or at least past any cache that loses power:

  • This PE’s private caches (L1, and L2 on most cores) are lost when the core powers down. Every dirty line must be written back.
  • Data that the warm-boot path reads with caches off. On pre-DynamIQ TF-A builds, the warm-boot entry runs with SCTLR_EL3.C == 0 until the MMU is re-enabled. Any variable it reads before then must be clean to PoC: the per-CPU PSCI state, the entry point and context ID, the platform’s power-state target. TF-A cleans these explicitly with flush_dcache_range() (look for psci_flush_cpu_data). With HW_ASSISTED_COHERENCY and WARMBOOT_ENABLE_DCACHE_EARLY, the design changes so caches can come on early in the warm-boot path.
  • The cluster’s shared cache (DSU L3 or a pre-DynamIQ cluster L2) is lost only when the last core of the cluster goes down and the cluster power domain turns off. That core cleans or flushes the shared level, or hardware does it.
  • A system-level cache in the interconnect (for example a CMN HN-F SLC) is below every PE’s set/way reach. It is flushed through IMPLEMENTATION DEFINED means, usually by the SCP or power controller, as part of system suspend.

Set/way: only for the local hierarchy, only here

8.5 explains why DC CISW and friends are unsafe as coherency tools: they act on this PE’s view of one cache level, lines can migrate between ways while you iterate, and other PEs’ caches are untouched. Power-down is the one place they are the right tool, because all of the following are true here:

  1. The PE has stopped allocating, since SCTLR_ELx.C is clear.
  2. Other PEs may still snoop this cache. A line they take while you iterate is simply no longer your problem, as long as you leave coherency after the loop.
  3. The goal is “empty this physical cache before it loses power”, not “make address X visible”. Set/way is exactly that operation, and by-VA maintenance would need a mapping for every PA that might be cached.

Use set/way only for the levels that lose power with this PE or cluster: up to CLIDR_EL1.LoUIS for a core, and the cluster’s shared level for the last core. TF-A’s dcsw_op_louis and dcsw_op_all take the level range from CLIDR_EL1 (8.1) and iterate sets and ways using CCSIDR_EL1. The cache-level limits come from CLIDR; never hard-code them.

Leaving coherency: pre-DynamIQ cores

On Cortex-A53, A57, A72 (and A35, A73 and similar), each core’s participation in cluster coherency is controlled by CPUECTLR_EL1.SMPEN. This is an IMPLEMENTATION DEFINED register (S3_1_C15_C2_1), bit 6 on these cores. While SMPEN == 1, the core’s L1D receives coherency requests from the SCU/L2. When it is 0, it does not. Software must set it before enabling caches and the MMU, and clear it only when the L1 is empty.

TF-A’s cortex_a53_core_pwr_dwn and cortex_a53_cluster_pwr_dwn show the order:

// Core power-down on a Cortex-A53-class core, at EL3 (sketch of TF-A's sequence)
    mrs     x0, sctlr_el3
    bic     x0, x0, #(1 << 2)     // SCTLR_EL3.C = 0: stop allocating
    msr     sctlr_el3, x0
    isb
    // (A57/A72: also disable L2 prefetch via CPUECTLR_EL1 and wait, per TRM)
    mov     x0, #DCCISW
    bl      dcsw_op_level1        // clean+invalidate L1 by set/way
    // last core in cluster only: bl dcsw_op_level2 (clean+invalidate L2)
    mrs     x0, S3_1_C15_C2_1     // CPUECTLR_EL1
    bic     x0, x0, #(1 << 6)     // SMPEN = 0: leave coherency
    msr     S3_1_C15_C2_1, x0
    isb
    dsb     sy
    // program the power controller, then:
    wfi

Each ordering constraint has a reason:

If you……this breaks
clean before clearing CStack spills and the routine’s own stores allocate new dirty lines after the clean; they are lost at power-off.
clear SMPEN before the cleanThe core is outside coherency but holds dirty lines. Other cores’ reads of those addresses get the stale DRAM copy, and the dirty lines vanish at power-off. Their writes no longer invalidate this core’s copies either, but those copies are about to be discarded anyway.
do any cacheable access after SMPEN = 0It may allocate a line the system cannot see or invalidate.
omit the final DSB before WFIThe writebacks and the power-controller register write may still be in flight when the core asks to power down.

The reverse on wake-up: SMPEN must be set before the D-cache and MMU are enabled. That is why TF-A’s Cortex-A53/A57/A72 reset handlers set it in reset_func early in BL31 entry.

Leaving coherency: DynamIQ cores

DynamIQ cores (Cortex-A55, A75, A76 and later, Neoverse N1 and later, with a DSU) have no SMPEN. Coherency entry and exit and the private-cache flush are done by hardware, under the control of the core’s Power Policy Unit (PPU). Software’s job shrinks to:

// Core power-down on a DynamIQ core (TF-A cortex_a76_core_pwr_dwn)
    mrs     x0, S3_0_C15_C2_7     // CPUPWRCTLR_EL1
    orr     x0, x0, #1            // CORE_PWRDN_EN: next WFI requests power-down
    msr     S3_0_C15_C2_7, x0
    isb
    // PSCI layer: program the power controller (often via SCP), dsb sy, wfi

With CPUPWRCTLR_EL1.CORE_PWRDN_EN == 1, the core’s next WFI becomes a power-down request. Once the PPU accepts it, the core cleans and invalidates its L1 and L2, leaves coherency with the DSU, and powers off. TF-A platforms built only from such cores can set HW_ASSISTED_COHERENCY=1, which removes the software set/way flush from the PSCI power-down path. The software rule “don’t allocate dirty data you need after the request” still applies to data the warm-boot path reads before caches come back. With WARMBOOT_ENABLE_DCACHE_EARLY that data is cache-coherent anyway.

For the cluster, the DSU’s IMPLEMENTATION DEFINED registers give the power controller hints:

  • CLUSTERPWRDN_EL1 (S3_0_C15_C3_6). Bit 0 tells the power controller whether cluster power is still required when all cores are down. Bit 1 (memory retention) requests that the L3 RAMs be kept in retention instead of being flushed and powered off. These are advisory: the cluster PPU and the SCP decide, and the DSU flushes the L3 itself before a full cluster power-off.
  • CLUSTERPWRCTLR_EL1 (S3_0_C15_C3_5) controls L3 cache-portion power-down (powering off some L3 ways at run time) and functional-retention behaviour.

Check the field layouts for your DSU revision in the DSU TRM. TF-A’s drivers/arm/dsu code programs these from platform data.

Bring-up note: Cache maintenance has a long errata history, and power-down and CMO sequences are where it shows up. Cortex-A53 has several errata in which a clean by VA may not be honoured: 819472, 824069, 826319 and 827319 are grouped under Linux’s ARM64_WORKAROUND_CLEAN_CACHE, which upgrades DC CVAC/DC CVAU to DC CIVAC. Cortex-A53 erratum 855873 (“an eviction might overtake a cache clean operation”) is handled in TF-A on r0p3 and later by setting CPUACTLR_EL1.ENDCCASCI (bit 44), which makes hardware perform cleans as clean+invalidate. For any new core, read the SDEN’s cache, CMO and power-down categories before trusting the TRM sequence, and enable the matching ERRATA_* build flags in TF-A (1.3). A missing errata workaround in this area typically shows up as corruption only after many thousands of suspend cycles.

Why the order matters at system scale

On a multi-cluster or multi-chiplet system, the same reasoning repeats one level up. Before a cluster’s CHI port is taken out of the snoop domain, for example by removing it from the HN-F snoop filter or DVM domain through the interconnect’s IMPLEMENTATION DEFINED controls, everything the cluster held must already be written back. After the cluster leaves, no DVM messages or snoops are sent to it. TLBI broadcasts from other clusters therefore don’t reach it, which is why a cluster coming back up must invalidate its TLBs and caches as if from reset (8.3, 17.5).

Validation note: The core test is a suspend-resume stress with checker patterns. Before each CPU_SUSPEND (power-down state) or CPU_OFF/CPU_ON cycle, the target core writes a unique pattern to a few hundred lines, including lines on the stack the power-down path uses. After it resumes, another core and the resumed core both verify the patterns. Add a variant where another core continuously reads and writes lines the target holds dirty during its power-down sequence. That variant catches the clear-SMPEN-too-early bug. On FVP, enable cache state modelling (-C cache_state_modelled=1); without it, the model has no dirty lines to lose and every sequence “passes”. On silicon, PMU L1D_CACHE_WB (0x15) on the target before WFI confirms the flush happened. Interconnect counters confirm that snoops stopped arriving after the core left coherency.

Checkpoint

Q8.8.1 On a Cortex-A53, a vendor power-down routine does: DC CISW loop over L1; clear SCTLR_EL3.C; ISB; clear CPUECTLR_EL1.SMPEN; DSB SY; WFI. Corruption appears after many suspend cycles. Which change fixes the ordering bug?

  • A. Clear SMPEN before the DC CISW loop, so the loop is not disturbed by snoops
  • B. Replace the DC CISW loop with DC CIVAC over all of DRAM
  • C. Clear SCTLR_EL3.C (and ISB) before the DC CISW loop
  • D. Add an IC IALLU after clearing SMPEN
Answer

C. With C still set during the loop, the routine’s own stores and stack spills (and any other cacheable writes) can allocate dirty lines after the set/way pass has already visited their sets. Those lines are lost at power-off. Option A is the classic opposite mistake: leaving coherency while holding dirty lines makes other cores read stale data. Option B is impractical, and it still leaves the allocation window.

Read more: Arm ARM (DDI0487), SCTLR_EL3.C; data cache maintenance by set/way; Cortex-A53 TRM, CPUECTLR_EL1

Q8.8.2 A TF-A port for a DynamIQ core uses HW_ASSISTED_COHERENCY=1. The core’s power-down path sets CPUPWRCTLR_EL1.CORE_PWRDN_EN and executes WFI, with no software cache flush. Which statement is correct?

  • A. This is a bug: the L1 and L2 must be cleaned by set/way before the WFI
  • B. This is the intended design: once the power-down request is accepted, the core’s hardware sequence cleans its private caches and exits coherency
  • C. This works only if the DSU’s CLUSTERPWRDN_EL1 is also written
  • D. This works only because DynamIQ caches are write-through
Answer

B. On DynamIQ cores the private-cache clean and coherency exit are part of the hardware power-down sequence, triggered by WFI with CORE_PWRDN_EN == 1, under control of the PPU. CLUSTERPWRDN_EL1 is an advisory hint for cluster power, not a requirement for a core power-down. The caches are write-back.

Read more: Cortex-A76 TRM (or your core’s TRM), CPUPWRCTLR_EL1 and core power-down; TF-A cortex_a76_core_pwr_dwn

Q8.8.3 The warm-boot entry point on a pre-DynamIQ platform reads a per-CPU “target power state” variable before enabling the MMU and D-cache. The variable was written by the core itself, with caches on, just before suspending. Sometimes the resumed core reads an old value. Why?

  • A. The write reached only the core’s cache. The warm-boot path reads with caches off, so it reads DRAM, and the variable was not cleaned to PoC after it was written
  • B. The read needs a DMB because Device-nGnRnE reads are not ordered
  • C. The core’s L1 retained the value but SCTLR_EL3.C == 0 disables cache hits
  • D. The TLB still held the old translation from before suspend
Answer

A. With the MMU off, the read is Device-nGnRnE, which goes to memory. Any data the caches-off path consumes must be cleaned to PoC by the writer. TF-A does this with explicit flush_dcache_range() calls on PSCI per-CPU data. Option C is tempting but misses the point: after a power-down the L1 contents are gone anyway, and the only question is whether DRAM was updated before that.

Read more: Arm ARM (DDI0487), Behavior of caches when the MMU is disabled; TF-A PSCI library design, cache maintenance on power-down