Peter Fors

Blocked dispatch and execution time on Zen 4 and Zen 5

A dependency rewrite in mknes reduced the AL-token stall share from 23.90% to 11–12% on a Ryzen 9 9950X3D. Performance changed by 0.1%, within the measurement noise. The change reduced the reported dispatch stalls without measurably shortening execution time. Original mknes profile

AMD defines event 0xaf, unit mask 0x01, on Zen 5 as cycles in which a valid dispatch group is blocked because ALU tokens are unavailable. Operations already in the scheduler can continue to issue during those cycles. The runtime effect depends on what work the blocked group delays. AMD counter definitions

A second load behind the dependency

The experiment puts a second independent load behind a block of arithmetic instructions. Its address is available before the first load completes, allowing the two misses to overlap. If blocked dispatch delays the second load far enough, the overlap can decrease and the iteration can take longer.

Each iteration flushes two lines on separate pages, loads the first line, executes 128 LEAs, and loads the second line. In the dependent variant, the last N LEAs use the first load’s result. The remaining LEAs use a ready register containing the same value. The ready-source control uses that register throughout. The instruction count and layout are fixed, including the address of the second load. A CPUID after that load serializes successive iterations.

Each point is a median across three rounds, with pinned user-mode counters and full coverage. The Zen 5 test ran on CPU 9 of the Ryzen 9 9950X3D. The Zen 4 test ran on isolated CPU 7 of the Ryzen 9 7950X. Boost was enabled on both. Assembly kernel · Measurement runner

Zen 5

Read these two figures at 83 and 87 dependent LEAs. In the first, the stall count jumps from 89 to 438 cycles per iteration at 83. In the second, iteration time is still in the range of the ready-source control at 83. The sustained timing increase starts at 87. Zen 5 raw measurements

Zen 5 sustained AL-token stall counts jump above 400 cycles per iteration at 83 load-dependent LEAs. The ready-source control remains near zero.
The large rise in AL-token stalls starts at 83 dependent LEAs. Full-size figure
Zen 5 iteration time shows a sustained increase at 87 load-dependent LEAs, after the increase in AL-token stalls at 83.
The sustained rise in total cycles starts at 87 dependent LEAs. Full-size figure

The table gives median cycles per iteration. Core and AL stalls are for the dependent variant. Ready gives the core cycles for the ready-source control. Share divides the unrounded AL-stall median by the unrounded core-cycle median.

LEAs AL stalls Core Ready Share
82 89 1,281 1,279 6.95%
83 438 1,232 1,280 35.53%
87 485 1,607 1,252 30.19%

From 83 to 87, the median stall count rose by about 47 cycles and the median iteration cost rose by about 375 cycles. Stall share fell by more than five percentage points because total cycles grew faster than stall cycles.

Zen 4

Read the Zen 4 figures at 89 and 91 dependent LEAs. At 89, SQ1 recorded about 412 stall cycles per iteration, and each other queue recorded about one cycle or less. The sustained runtime increase starts at 91, where the iteration takes 1,622 cycles. The stall figure shows the largest individual queue count in each sample. The dashed reference marks the 96 entries across all four queues. The horizontal axis counts instructions that use the delayed operand. AMD Zen 4 Software Optimization Guide, §2.10 · Zen 4 raw measurements

The largest per-queue stall count on Zen 4 rises above 400 cycles per iteration at 89 dependent LEAs.
The largest per-queue stall count rises at 89 dependent LEAs. Full-size figure
The dependent series on Zen 4 shows a sustained rise in core cycles per iteration at 91 dependent LEAs.
The sustained rise in total cycles starts at 91 dependent LEAs. Full-size figure

The code pattern worth testing

Look for an independent operation after a block of instructions that wait on a long-latency result. The test deliberately creates that instruction order.

load a from p
arithmetic dependent on a
load b from q
use both results

Here q is available before the first load completes. Where aliasing and ordering permit it, moving the second load ahead of the dependent arithmetic is a concrete scheduling change to test. Keep the work fixed, confirm the generated instruction order, and measure cycles per iteration. The control here changes operand readiness. A separate load-reordering test would check whether earlier issue of the second miss accounts for the timing step.

In an emulator, compare AL stall cycles and total core cycles per frame or guest instruction. The first measures the change in blocked dispatch for the same work. The second measures the change in execution cost.

Interpreting AL-token stalls

The two sweeps establish that blocked dispatch can rise substantially before it adds measurable execution cost. The original mknes result remains a before-and-after observation. The standalone tests give a specific code pattern to investigate and leave open which work determined runtime in those mknes builds. A throughput improvement requires a measured reduction in cycles per unit of work.

Reproduction instructions · Source and scripts · Raw measurements