Domain Crossings at Chip Level

A signal that passes between unrelated clocks can be caught halfway. Simulation cannot show that; it can show whether each crossing keeps the protocol that makes it harmless. This lesson says what each tool can prove, and measures one crossing of ap_soc.

You Will Be Able To

  • Read a crossing inventory and say how each kind of crossing is made safe.
  • Explain what simulation can and cannot show about a crossing.
  • Say what a structural clock-crossing tool checks, and why a chip team runs one.
  • Measure the latency of a crossing across all phases of its two clocks.
Lesson
V9.5
Time
28 min
Runs on
Your browser
Check
5 questions

No simulator models a flop caught between 0 and 1, so a bad crossing can pass every simulation. ap_soc lists its 74 crossings. This lesson measures one of them, the always-on bridge.

The Crossing Inventory of ap_socEvery signal between two domains is a row of the inventory: 74 rows, each with how it is made safe.
  • Bus
  • Clock / reset
  • Debug
  • Pads
  • Data
  • Interrupt
  • Control
  • Clock
The Crossing Inventory of ap_socEvery signal between two domains is a row of the inventory: 74 rows, each with how it is made safe. bus clk_sys domain core, fabric, fastperipherals clock reset clk_aon domain watchdog, ap_pwrctl,reset control debug TCK domain the JTAG TAP pads Pads no clock at all clock reset RC and PLL clk_sys sources always-on bridge: req,ack (sync2), payload(handshake)interrupts 6 and 9(sync2)debug commands(toggle andhandshake)UART RX, GPIO in(sync2)wake pad (threeflops)the clock switch(grants on eachsource)
  1. bus clk_sys domaincore, fabric, fast peripherals
    • always-on bridge: req, ack (sync2), payload (handshake) → clk_aon domain
  2. clock reset clk_aon domainwatchdog, ap_pwrctl, reset control
    • interrupts 6 and 9 (sync2) → clk_sys domain
  3. debug TCK domainthe JTAG TAP
    • debug commands (toggle and handshake) → clk_sys domain
  4. pads Padsno clock at all
    • UART RX, GPIO in (sync2) → clk_sys domain
    • wake pad (three flops) → clk_aon domain
  5. clock reset RC and PLLclk_sys sources
    • the clock switch (grants on each source) → clk_sys domain
  1. Domains

    clk_sys and clk_aon come from unrelated oscillators; TCK comes from the debugger; the pads have no clock.

  2. Levels

    A single bit that stays long enough crosses through two flip-flops: sync2.

  3. Words

    A word crosses beside a synchronized level that says when it is still: a handshake.

  4. Clocks

    Even the clock mux is a crossing: each source's grant passes flops on that source.

Read the diagram as text
  • clk_sys domain: core, fabric, fast peripherals
  • clk_aon domain: watchdog, ap_pwrctl, reset control
  • TCK domain: the JTAG TAP
  • Pads: no clock at all
  • RC and PLL: clk_sys sources
  • clk_sys domain → clk_aon domain: always-on bridge: req, ack (sync2), payload (handshake)
  • clk_aon domain → clk_sys domain: interrupts 6 and 9 (sync2)
  • TCK domain → clk_sys domain: debug commands (toggle and handshake)
  • Pads → clk_sys domain: UART RX, GPIO in (sync2)
  • Pads → clk_aon domain: wake pad (three flops)
  • RC and PLL → clk_sys domain: the clock switch (grants on each source)

tools/soc/ap_soc/gen/ap_soc_crossings.csv, generated at stage E4. Rows by kind: reset 31, sync2 24, level 3, static 5, async 6, handshake 5.

Before You Start

Read Release Order and Reset in the Middle of Work first. Synchronizers are taught in Metastability and MTBF, The Two-Flop Synchronizer and Pulse, Toggle and Handshake Synchronizers. Clock domains are in Planning Clock Domains.

Five questions this page answers
Question
1What is a crossing inventory, and why is it kept as data?
2What can simulation show about a crossing, and what can it not?
3What does a structural clock-crossing tool check?
4How long does a level take to cross into clk_aon, and why does it vary?
5How is metastability modelled in a simulation, and what is the model worth?

The Idea: Three Tools for One Risk

A crossing is safe when three things hold. Its structure is right: a single bit through two flops, a word beside a synchronized level. Never a word through flops one bit at a time. Its protocol is kept: the level stays long enough, the word stays still while it is sampled. And its timing leaves the first flop time to settle, which sets the mean time between failures.

No single tool checks all three. A structural clock-crossing tool reads the netlist or RTL, finds every path between domains and checks its structure, with no stimulus. Simulation checks the protocol, in the scenarios the tests make, and shows the latency at each phase. The mean time between failures is a calculation from the flop's data and the clock rates.

This site has no structural clock-crossing tool. ap_soc keeps its crossings as data instead. The inventory, generated from the chip's tables, lists all 74 and how each is made safe. A review reads it; the tests of this module check the protocols.

New Words

New words on this page
WordMeaning
Clock-domain crossing (CDC)A signal launched by a flop on one clock and sampled by a flop on another, unrelated clock.
MetastabilityA flop caught by a changing input, hanging between 0 and 1 before it settles. Real and analog; not modelled by simulators.
sync2Two flip-flops on the receiving clock. The first may go metastable; only the second is used.
Handshake crossingA word held still beside a request level and an acknowledge level, each through sync2.
Crossing inventoryA list of every crossing with its source, destination, clocks and how it is made safe.
Structural CDC toolA tool that finds every crossing in the design and checks its synchronizer structure without simulation.
Metastability injectionA simulation model that, near a clock edge, lets a synchronizer's first flop take the old or the new value at random.

The Smallest Example: The Edge That Takes It

A level changes at 30 ns. clk_aon rises at 7, 21, 35, 49 ns. Through two flops, when does the receiver see it? And if it changed exactly at 35 ns?

Two cases, by hand
Change atFirst flop takes itq shows itLatency
30 ns35 ns49 ns19 ns
35 ns, on the edge35 ns or 49 ns49 ns or 63 ns14 or 28 ns

The second row is where metastability lives. A simulator picks one answer; silicon may take either, or hang a while before it settles.

So the latency of a two-flop crossing is not one number. It is one to two periods of the receiving clock, plus one when the first flop is caught. A design that needs one exact latency is wrong.

The Rules

  1. Rule 1: Keep every crossing in an inventory.

    Each row says what crosses, between which clocks, and how it is safe. A crossing that is not in the list has not been reviewed.

  2. Rule 2: Check the structure with a structural tool.

    Only a tool that reads the whole design finds a crossing nobody listed. The same holds for a word that crosses one bit at a time. Commercial examples are Synopsys SpyGlass CDC and Siemens Questa CDC. This site runs neither.

  3. Rule 3: Check the protocol in simulation, with assertions.

    For a handshake: the word holds while the request is up, the request waits for the acknowledge, each request is taken once. Check each rule on the clock of the side that owns it.

  4. Rule 4: Run every crossing at many phases.

    Two unrelated clocks meet at every phase. Tests with different ratios, offsets and seeds show the spread of latency and a design that leans on one phase.

  5. Rule 5: Model metastability, and say it is a model.

    A cell that picks the old or the new value at random near an edge moves the latency by one edge. It shows designs that need an exact latency; it does not show the physics.

  6. Rule 6: Never count on an exact crossing latency.

    Software and hardware that wait for the other side must wait for its answer, not for a number of cycles.

Sources for These Rules

Simulation does not model metastability. CDC checks are structural, protocol and reconvergence checks. Models that vary synchronizer delays at random: MEHTA-DV 8.5 (p185 to p188).

Assertions as checks of a crossing's protocol in simulation: MEHTA-DV 8.4 (p183 to p185).

Tools named: MEHTA-DV 8.7 (p189) names Synopsys SpyGlass CDC and Mentor (now Siemens) Questa CDC. This site uses neither.

The inventory: tools/soc/ap_soc/gen/ap_soc_crossings.csv (stage E4, facts 27.11); the bridge: tools/soc/ap_soc/rtl/ap_apb_async_bridge.sv.

The Lab: One Crossing, Seven Phases

The always-on bridge carries a register access from clk_sys (10 ns) to clk_aon (14 ns) and back. The two clocks line up again only every 70 ns, seven cycles of clk_sys. The bus-manager seat reads PWRCTL STATUS seven times, each after a gap one cycle longer, so each read starts at another phase.

Measured from the bench's sample window of the seat's data port.
slow reads (cycles of clk_sys, address phase to answer): 12, 14, 11, 10, 11, 11, 11
one fast read of CHIP_ID: 2

Rule 4 at work: the same access took 10 to 14 cycles. Only the phase of the two clocks, when its request crossed, made the difference. The request passes two flops of clk_aon; the slow side runs its APB transfer; the acknowledge passes two flops of clk_sys. Each crossing waits for the next edge of the other clock, so the total moves by a few cycles.

A fast register on the same bus answered in 2 cycles. Software that times a slow access by counting cycles would work at one phase and fail at another. It must wait for the answer, which the bus does for it.

The example below runs a level through two flops, with the metastability model of rule 5. One change lands right on an edge of clk_aon:

The same change with two seeds of the model (lines 3 of the example's output and of the predict question's).
change at 175 ns reached q at 189 ns: 14 ns later
change at 175 ns reached q at 203 ns: 28 ns later

With one seed the first flop took the new value at that edge. With the other it took the old one and caught up an edge later. Both are legal; a design must work with either.

Why It Is Built This Way

Why a handshake and not a synchronizer on every bit of the word? Each bit would cross at its own edge. So the receiver could see half of an old word and half of a new one. A handshake synchronizes one bit and holds the word still: the word needs no synchronizer at all.

Why keep the inventory as data? It is generated from the chip's tables with the top level. It cannot fall out of step with the design, and a review or a script can read it, row by row.

Traps

The first trap is a passing simulation taken as proof that a crossing is safe. The simulator never let a flop go metastable. A word synchronized bit by bit passes every test and fails in silicon.

The second is a test bench whose two clocks have a fixed phase, for example one derived from the other. Every crossing is then tested at one phase only; lesson V3.2 showed why soc_tb gives each clock its own generator.

The third is a checker that expects the other side at a fixed time. The acknowledge legally comes one or two edges later from run to run. A checker that expects it at once cries wolf.

At Scale

ap_soc~12 blocks
Phone-class SoChundreds of blocks

This section looks ahead. ap_soc has four domains and a few dozen crossings.

  1. Thousands of crossings

    Large chips have tens of clock domains. Only a structural tool can list every crossing; the inventory is its report, reviewed and waived row by row.

  2. Reconvergence

    Two signals synchronized separately and combined later can disagree for a cycle. Structural tools look for it; simulation with injection can show it.

  3. Formal protocol checks

    The assertions of rule 3 can be proved by a formal tool for every input sequence, not only the tested ones.

Try It

Run it: each change of the level, and when q showed it.

Find the change that landed on an edge of clk_aon. Why is its latency 14 ns here?

Change the seed. Which line changes, and why only that one?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: change at 20 ns reached q at 49 ns: 29 ns later change at 100 ns reached q at 119 ns: 19 ns later change at 175 ns reached q at 189 ns: 14 ns later change at 246 ns reached q at 273 ns: 27 ns later change at 320 ns reached q at 343 ns: 23 ns later change at 397 ns reached q at 413 ns: 16 ns later

Check Yourself

Predict the outputThe model now uses seed 5. What is the last line printed?
// A level from clk_sys (10 ns) into clk_aon (14 ns, rising at 7, 21, 35 ns) through two flip-flops, as ap_sync2.
// A model of metastability: when D changed less than 2 ns before a rising edge, the first flip-flop takes the
// old or the new value at random (seed 5). Real metastability is analog; a simulator can only model its effect.
module tb;
  logic clk = 0, d = 0, meta = 0, q = 0;
  realtime changed = -100, moved;
  int seed = 5;
  initial begin #7; forever begin clk = 1; #7; clk = 0; #7; end end
  always @(d) changed = $realtime;
  always @(posedge clk) begin
    if ($realtime - changed < 2) meta <= ($urandom(seed) & 1) ? d : meta;   // inside the window: either value
    else meta <= d;
    seed = seed + 1;
    q <= meta;
  end
  always @(q) $display("change at %0.0f ns reached q at %0.0f ns: %0.0f ns later", moved, $realtime, $realtime - moved);
  task automatic change_at(input realtime t);
    #(t - $realtime);
    d = ~d; moved = $realtime;
  endtask
  initial begin
    change_at(20); change_at(100); change_at(175); change_at(246); change_at(320); change_at(397);
    #60 $finish;
  end
endmodule
ConceptWhat can simulation show about a crossing?
ConceptIn the lab, why did the same slow read take 10 to 14 cycles?
ConceptWhat does a structural clock-crossing tool find that simulation cannot?
ConceptWhat is the metastability model in the example worth?

Common Mistakes

Wrong Take a passing simulation as proof a crossing is safe.

Simulators do not model metastability; a wrong structure passes.

Fix Check the structure with a structural tool and the inventory; check the protocol in simulation.

Wrong Synchronize each bit of a word through its own two flops.

The bits cross at different edges, so the receiver can see a mix of two words.

Fix Hold the word still beside one synchronized request level.

Wrong Count cycles to wait for the other side of a crossing.

The latency moves with the phase of the clocks.

Fix Wait for the other side's answer.

Remember

  • A crossing is safe when its structure, its protocol and its settling time are all right; each needs its own tool.
  • Simulation checks the protocol and shows the latency across phases; it never shows metastability.
  • ap_soc keeps its 74 crossings in a generated inventory; this site has no structural CDC tool.
  • A read across the always-on bridge took 10 to 14 cycles by phase: wait for answers, never count cycles.

Practice

Report a problem with this page