Peter Fors

An idle-sensitive load/store dependency on Zen 5

On a Ryzen 9 9950X3D, an AVX2 UTF-16LE to UTF-8 conversion could continue to run hundreds of cycles slower per call after a preceding ASCII workload. The slow regime survived serialization and busy context switches. A brief entry into C1 cleared it. Instruction-Based Sampling (IBS) recorded long tag-to-completion intervals for some input loads that still hit L1D. Which regime appeared depended on the preceding workload, physical backing, and the addresses used by the conversion.

Distinct execution regimes

The discrepancy appeared in a comparison of FFUTF and simdutf on a 4 KiB UTF-16LE CJK fixture. Between two published matrices, aligned simdutf went from 465.78 to 375.92 ns per call. FFUTF went from 245.30 to 250.44 ns. Most of the change in the ratio between implementations came from simdutf. Both builds used release 9.5.0, so the comparison alone gave little information about what changed. The exact published rows are included with the supporting data. Matrix evidence

To reproduce both timings with a single executable, the diagnostic used simdutf’s AVX2 Haswell implementation and converted the same CJK bytes from the same virtual addresses backed by the same pages. The input and aligned output began at page offsets 0x240 and 0x280. A third case shifted only the output pointer by 128 B within its mapping. It exercised the same instructions on the same input while changing the page-offset relationships between loads and stores.

The independent reproduction ran on logical CPU 9 with boost disabled and normal scheduling. A prefix of stock ASCII and Latin reverse-conversion cases was sufficient to induce the slow regime, although induction and persistence varied by launch. Of 648 aligned batches, 150 exceeded 1,800 cycles per call and 498 were below 1,700. The +128 B batches all fell below 1,700. Each point in the figure is a batch of 131,072 calls. The aligned fast and slow medians were 1,617 and 1,867 cycles per call, respectively. Median AL-token stall counts were 71 and 349 cycles per call.

Core cycles and AL-token stall cycles per call separate into fast and slow groups for aligned CJK conversion. The shifted output stays in the fast cycle range.
Core and AL-token stall cycles in the independent reproduction. Select the figure for the full-size SVG.

Physical backing changes the result

Shifting a virtual pointer also changes load/store overlap and alignment, so a separate control held both pointers fixed. In that earlier experiment, input and output were mapped from a resident 2 MiB shared allocation. The output mapping usually began 1 MiB from the input mapping in that allocation. After the ASCII workload, the aligned median was 1,847 cycles per call. Remapping only the output to the 8 KiB offset brought it to 1,619 cycles. Restoring the 1 MiB offset raised it again to 1,890 cycles. The code and virtual addresses stayed fixed. The probe with +128 B output stayed near its fast timing through the same sequence. These are phase medians from the original terminal capture. Backing swap record

The file offsets identify which backing was used, and the comparison changes physical placement independently of virtual placement. It leaves the relevant physical address bits and the processor’s use of them unresolved. An IBS attempt that changed only physical backing caught too few slow input loads to compare latency distributions across the swap. The latency evidence below therefore comes from the same-backing phase comparison.

IBS identifies delayed L1D-hit input loads

Core counters establish the size of the slowdown. To localize it, the experiment sampled operations at their recorded instruction pointers and checked the input load’s linear operand address. The CJK loop loads 32 B with vmovdqu and passes the vector to vptest. The input-load distribution includes only samples in the 4 KiB input with a clear L1D miss flag. The reported interval is tag-to-retire minus completion-to-retire. It includes time waiting after tagging, so an L1 hit can still have a long interval. AMD IBS definitions

The median input load took 11 cycles in each cohort. The difference was in the tail. Five of 58 slow aligned samples exceeded 50 cycles, reaching 93 cycles. Three of those five came from the first KiB. The fast aligned and shifted cohorts had zero over 50 cycles in 231 and 74 input-load samples. Every sampled input vector in the three cohorts had an L1D hit. The dependent vptest also acquired a tail, with 14 of 126 samples exceeding 50 cycles in the slow cohort and zero of 626 across the two fast cohorts.

Fraction of L1-hit input loads above a latency threshold. Only the slow aligned series extends beyond 50 cycles.
Empirical tail of the input-load distribution. Counts in the legend are sampled loads. Select the figure for the full-size SVG.

The sampler was rearmed every batch. Kernel throttling terminated the first nine store-drain launches at the original period. The retry doubled the period in dispatched operations, retaining the batch size and workload. The rejected captures, samples excluded by IP and address checks, and unsuccessful training attempts remain in the data bundle. Fast and slow distributions are selected by the observed batch timing. Raw captures and selection

Draining stores before the next call

With consecutive calls, a delayed load may encounter stores from the previous call or earlier stores from the current call. A separate diagnostic loop inserts MFENCE before entering the unchanged converter so prior stores must complete. The shifted placement measures the cost of fencing when the placement-related penalty is absent. AMD64 fence semantics

Thirty adjacent ordinary/fenced pairs stayed slow in both batches. The median core-cycle cost went from 2,103 to 2,144 cycles per call. The median paired increase was 46 cycles, and the shifted control increased by 77 cycles between the two medians. Comparing each aligned median with its own shifted control gives gaps of 458 cycles ordinary and 423 cycles fenced. Those gaps are comparisons with separate matched-placement controls. The fence can also change overlap between calls.

Core cycles for aligned slow and shifted CJK calls with and without a store drain. The aligned case remains slow after fencing.
Median cycle cost in the independent store-drain comparison. Select the figure for the full-size SVG.

The smaller fenced sample set still caught an 83-cycle L1-hit input load at input offset 704 B. Its lower 12 address bits overlapped output stores from earlier vector iterations of the same invocation. The latest matching store was nine iterations earlier. The original larger comparison captured nine delayed fenced input loads with same-call overlap. This shows that pending stores from the previous invocation are unnecessary for the slow regime. Page-offset overlap identifies possible interfering stores. IBS does not identify the dynamic store that delayed a particular load. Fence captures and correlation code

Persistence and C1 entry

The earlier persistence tests found that thousands of CPUID instructions and fences, unrelated integer computation, cache-line flushes, and large read and write sweeps could leave the slow regime active. A fork could preserve it as well. To separate elapsed time and context switching from idle entry, the independent reproduction compared short sleeps with active waiting and a busy helper pinned to the same logical CPU. It recorded the kernel’s idle residency before and after each intervention. The timing and AL-token criteria had to verify the slow state before an intervention entered the reset comparison.

All 26 verified slow trials with C1 residency and no deeper recorded state returned fast. The shortest recorded C1 residency was 2 microseconds. C1 entry was therefore sufficient to clear the slow state. Deeper idle states also cleared it in every verified trial, with all 32 trials that recorded C2 or C3 returning fast. The remaining interventions produced only slow or ambiguous outcomes.

Test Fast Slow Ambiguous
C1 26 0 0
C2 or C3 32 0 0
POLL 0 9 2
No recorded idle 0 15 0
Active spin 0 3 0
Busy helper 0 6 0
All C1 and C2 or C3 trials returned fast. POLL, no recorded idle, active spin, and busy-helper trials returned slow or ambiguous.
Outcomes for all 93 trials with a verified slow state before the intervention. Select the figure for the full-size SVG.

What the preceding workload changes

Holding a 4 MiB ASCII conversion and the number of calls constant, earlier tests changed only the set of buffers visited. Repeating calls across a small span produced fewer transitions than rotating across a larger span. The smallest input footprint observed to induce the state was 16 MiB. The least total input processed in a successful attempt was 64 MiB. The trials did not establish a deterministic byte threshold. Simple streaming reads, writes, and diagnostic load/store loops failed to induce it in the tested cases. Footprint evidence

The address-coverage follow-up used prepopulated page moves to compare backing diversity at the same remapping cadence. Rotating sixteen physical tiles through one virtual window induced the slow state in 7 of 16 trials. Rotating the physical and virtual tiles together induced it in 10 of 16. With a single physical tile, both the single-window and sixteen-window controls recorded zero transitions in 16 trials each. Physical address coverage can therefore matter while the virtual training addresses are constant.

Entering the original ASCII vector loop directly, without modifying its executable pages, still induced the state in 12 of 20 trials even with the setup and scalar tail bypassed. Keeping the same bytes in a privately rewritten executable page stopped the unchanged-byte control from inducing the state. That control limits what the code-removal trials on those pages establish about instructions inside the loop. Address and instruction evidence

CPU locality and transfer to other kernels

A migration comparison is informative only when the source still exhibits the slow state after the return. In five such transfers between distinct cores in the same CCD and four to the other CCD, the destination stayed fast. Waking the SMT sibling cleared the source effect in ten verified trials in both directions combined. That behavior leaves sharing within a physical core unresolved.

The state also affected simdutf’s Latin reverse conversion at +128 B. That workload went from 991 to 1,702 cycles per call in four tests bracketed by verified slow CJK probes. The same shift is a fast control for the CJK fixture. The FFUTF CJK reverse path, simdutf CJK forward path, and the independent same-page-offset kernel showed no comparable transition. The effect depends on the consumer instruction and address sequence as well as on the state of the CPU. Locality and transfer evidence

Interpreting the load delay and dispatch backpressure

AMD’s AL-token event, 0xaf with unit mask 0x01, counts cycles in which a valid dispatch group cannot dispatch because ALU tokens are unavailable. Operations already dispatched can continue to issue. In the CJK tests, the delayed input vector feeds vptest and the downstream packing path. An earlier IBS run sampled the converter after idle and recorded the disappearance of the long input-load tail along with the timing and AL-token penalty. In the store-drain comparison, the measured older-store conflict event stayed near 3.6–3.7 per call in both slow variants. That event covers a specific form of nonforwardable conflict and does not measure all cycles spent waiting. AMD core counter definitions

The evidence is consistent with an idle-sensitive change in how the core handles interference between older output stores and younger loads that share address bits. Waiting for those loads can hold up their dependents, increase scheduler occupancy, and block later dispatch. The IBS interval begins at tagging, so it cannot establish how long an independent later operation spent waiting to dispatch. The AL-token count cannot be subtracted from runtime to recover the initiating load delay. The specific processor structure that retains the history remains unidentified. Separate controls for AL-token stalls and execution time

What the two regimes establish

On this Zen 5 CPU, identical executable code and fixed buffers can produce distinct steady timings within a single launch. The active state interacts with the physical backing and same-call address relationships of the measured loop. It can persist through serialization and busy context switches, clear at C1 entry, and affect another conversion only at one of its placements. The combination of the load-level and drain evidence explains why a benchmark can report a large change without a new binary, while leaving the hardware mechanism open.

For measurements of this workload, a single median across fast and slow batches depends on how often each regime occurred. Reporting the measured regimes, the preceding workload, idle behavior, and placement controls makes that dependence visible and makes a repeat run interpretable.

Reproduction and evidence index · Independent raw captures and source (.zip) · Figure generator