Spurious wake‑up latency observed with AArch64 WFE timeout when event and timeout coincide
0 reputation · 17 Jun 2020, 12:42 UTC
0 reputation · 17 Jun 2020, 12:42 UTC
When using the AArch64 Wait For Event with Timeout (WFxT) feature (FEAT_WFxT), the core may wake either due to an external event or after the programmed timeout expires. If both conditions become true at the same cycle, the architecture leaves the priority decision to the implementation, which can lead to inconsistent latency across different cores.
The timeout counter is driven by the generic timer clock (CNTVCT), but the specification does not strictly define its resolution or overflow behaviour, making it difficult to predict whether a wake‑up occurs early, late, or exactly on the programmed value.
Goal: Determine how cancellation and timeout conditions are handled in WFxT implementations, especially the simultaneous event/timeout case and the effective timeout resolution.
35775 reputation · 17 Jun 2020, 14:56 UTC
The ARM Architecture Reference Manual states that when an external event and a WFxT timeout become true in the same cycle, the wake‑up reason is implementation‑defined. No architectural priority is mandated, so the observed latency depends on how a particular core resolves the race.
CNTVCT_EL0.CNTVCT relative to the core clock, nor the exact pipeline stage at which the WFxT comparator samples the timer.CNTVCT wraps around correctly on overflow, but the comparator and event monitor may sample the counter at different points, creating a race window of a few cycles.Because the priority is implementation‑defined, each core may:
The effective timeout resolution is therefore limited by the timer‑clock period; a single tick can represent multiple core cycles, introducing an uncertainty of ±1–2 ticks (or more if the timer clock is divided). The race window can add another 1–3 cycles of jitter.
ID_AA64ISAR1_EL1 and check the WFxT field; read CNTFRQ_EL0 to obtain the generic‑timer frequency in Hz. ISB
WFET #<N> // N = timeout in timer ticks
ISB
MRS <x0>, PMCCNTR_EL0 // capture wake‑up time
Ensure an ISB before and after WFET to prevent speculative execution from affecting the counter.SEV at a cycle‑accurate offset calculated from N and the timer frequency read in step 1.WFET PMCCNTR_EL0 value from the post‑value to obtain the elapsed core cycles. Repeat the experiment ≥10 000 times and build a histogram.cpufreq-set -g performance) and disable idle‑state deep‑sleep if possible.If you have access to the core’s Technical Reference Manual or silicon errata that specifies the exact comparator sampling point for WFxT, please provide that information; it would allow a more precise prediction of the race window and could shift the measurement methodology (e.g., adjusting the SEV offset).
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.