TDEB Top Bar

Trending
Semiconductor Industry News — The Digital Electronics Blog
Follow Us

TDEB Masthead

The Semiconductor Hub

Semiconductors.  Chips and Systems.  Innovation.

Indexed by leading Search Engines, AI and referenced by Engineers worldwide 500+ Articles 10M+ Pageviews 30+ Reports 50+ Citations

Cut-Through FIFO: Start Thresholds, Underrun and Late Errors (FIFO Series, Part 14)

The Semiconductor Hub
by
0
Share Facebook X LinkedIn WhatsApp Email
Hand-drawn cover card for FIFO Series Part 14, Cut-through FIFO, with a sketch of entries moving from push to pop.

Store-and-forward is safe but slow: every packet waits for its own last beat before the first beat may leave. For a 9,000-byte frame on a wide datapath that is a long wait, paid at every hop. A cut-through FIFO starts forwarding a packet as soon as enough of it has arrived, and keeps going while the rest streams in behind. Latency drops to a few beats, whatever the packet length.

This is Part 14 of the FIFO Series. Part 13 held each packet until it was complete. This part trades that guarantee for latency, and the engineering is in what has to be done about the two problems that come with it: the reader can overtake the writer, and an error found at the end of a packet arrives after the start has already gone.

Key takeaways

  • A cut-through FIFO starts a packet when a threshold number of its beats is stored, or when the whole packet is stored, whichever comes first.
  • Once a packet starts, the reader keeps going. If it finds the FIFO empty in the middle of the packet, that is an underrun.
  • Underrun is a rate problem. When the reader is faster than the writer, the threshold must cover the beats the reader gains over the length of the packet.
  • A bad packet cannot be dropped once it has started. The usual answer is to mark it bad on its last beat so the next stage drops it.
  • The threshold must not exceed the depth, or long packets never start and the FIFO deadlocks.

In this part

What problem a cut-through FIFO solves

The latency of a store-and-forward stage grows with the packet length. In a switch, a network-on-chip, or a chain of bridges, that latency is paid at every stage, so a long packet crossing several hops spends most of its time waiting for its own tail. Cut-through removes that dependency. A packet that enters a cut-through stage can leave a few cycles later, while its later beats are still arriving.

Hand-drawn comparison of an eight-beat packet arriving one beat per cycle: store-and-forward sends its first beat at cycle 8 after the whole packet has arrived, while cut-through with a threshold of 2 sends its first beat at cycle 2.

A cut-through FIFO also needs much less storage. It never has to hold a whole packet, only enough to cover rate differences and stalls, so jumbo packets do not set its size.

The interface

Hand-drawn block diagram of a cut-through FIFO: storage of eop, err and data, with a start rule box saying start a packet when count reaches THRESH or its eop is stored and then keep going, and an underrun box saying underrun is rd_active and empty, with out_err on the eop beat.

The write side uses valid and ready with in_eop and an in_err flag on the end beat. The read side uses valid and ready with out_eop and out_err. An underrun output is high when a packet has started and its next beat is not in the FIFO. Whether underrun is merely a bubble or a real failure depends on the reader. A network-on-chip link can usually tolerate a gap. A transmitter that has started a frame on a serial line usually cannot.

Micro-architecture: the start rule

The FIFO is the packet-aware FIFO of Part 12 with a gate on the output. The gate is closed between packets and opens when one of two things is true:

  • Enough beats are stored. The occupancy has reached THRESH. When the reader is between packets, every stored beat belongs to the packet at the head or to a later one, so if no end beat is stored, all of them belong to the head packet.
  • The whole packet is stored. A count of stored end beats, kept as in Part 12, is non-zero. Short packets, shorter than the threshold, start this way.

Once the reader takes the first beat, a flop called rd_active holds the gate open until the end beat leaves. The threshold is the only thing the reader checks at the start of a packet. After that it simply follows the writer.

How large should THRESH be? If the writer delivers at least one beat per cycle once a packet starts, a threshold of one is enough, and the reader can never overtake it. If the writer is slower, the reader catches up. Say the writer sends one beat every K cycles and the reader takes one per cycle. For a packet of L beats, the reader avoids running dry only if

THRESH >= 1 + ceil((L - 1) * (K - 1) / K)

which is roughly the packet length times the fraction by which the writer is slower. For an 8-beat packet with the writer at half rate, that is 5. The timing diagram shows what happens with 3.

Hand-drawn timing diagram of an eight-beat packet written one beat every two cycles with a threshold of 3: the reader starts at cycle 5, catches up with the writer, and underrun pulses in cycles 10, 12 and 14 while out_valid drops.

When rates are not known in advance, as in a switch between ports of different speeds, many designs fall back to store-and-forward when the input is slower than the output, and use cut-through only when it is at least as fast.

RTL sketch

module ct_fifo #(
  parameter int W      = 64,
  parameter int DEPTH  = 32,                // power of two
  parameter int THRESH = 8,                 // 1 to DEPTH
  localparam int AW    = $clog2(DEPTH),
  localparam int CW    = $clog2(DEPTH + 1)
) (
  input  logic         clk,
  input  logic         rst_n,
  input  logic         in_valid,
  input  logic         in_eop,
  input  logic         in_err,              // valid with in_eop
  input  logic [W-1:0] in_data,
  output logic         in_ready,
  output logic         out_valid,
  output logic         out_eop,
  output logic         out_err,
  output logic [W-1:0] out_data,
  input  logic         out_ready,
  output logic         underrun
);
  logic [W+1:0]  mem [DEPTH];               // {eop, err, data}
  logic [AW:0]   wptr, rptr;
  logic [CW-1:0] eop_count;                 // end beats stored
  logic          rd_active;                 // a packet has started

  wire [AW:0] count = wptr - rptr;
  wire empty = (count == '0);
  wire full  = (count == (AW+1)'(DEPTH));

  assign in_ready = !full;
  wire do_push = in_valid && in_ready;

  wire start_ok = (count >= (AW+1)'(THRESH)) || (eop_count != '0);
  assign out_valid = !empty && (rd_active || start_ok);
  assign {out_eop, out_err, out_data} = mem[rptr[AW-1:0]];
  wire do_pop = out_valid && out_ready;

  assign underrun = rd_active && empty;

  always_ff @(posedge clk or negedge rst_n)
    if (!rst_n) begin
      wptr      <= '0;
      rptr      <= '0;
      eop_count <= '0;
      rd_active <= 1'b0;
    end else begin
      if (do_push) wptr <= wptr + 1'b1;
      if (do_pop)  rptr <= rptr + 1'b1;
      eop_count <= eop_count + CW'(do_push && in_eop) - CW'(do_pop && out_eop);
      if (do_pop) rd_active <= !out_eop;
    end

  always_ff @(posedge clk)
    if (do_push) mem[wptr[AW-1:0]] <= {in_eop, in_err, in_data};
endmodule

In this sketch the reader may pause when the FIFO runs dry, and underrun only reports it. A reader that cannot pause would use underrun to abort the packet, and the rest of it would have to be discarded at the input until its end beat, much like the oversize handling in Part 13.

Corner cases: underrun and late errors

  • Packets shorter than the threshold. They start when their end beat is stored, so they behave as store-and-forward. Without the end-beat term in the start rule, a short packet followed by a pause would wait forever.
  • Threshold larger than the depth. The count can never reach it, so a packet longer than the FIFO never starts: a deadlock. Keep THRESH at most DEPTH, and assert it.
  • Errors found at the end. By the time a CRC check fails on the last beat, the head of the packet has already left. The FIFO cannot drop it. It carries the error to the end beat with out_err, and the next stage, or the final receiver, drops the packet. Network equipment commonly ends such a frame with a deliberately corrupted checksum so that every later hop discards it.
  • Underrun with a reader that cannot pause. The packet is broken. The reader ends it with an error marker, and the remaining beats of that packet must be removed from the FIFO without being sent. A design that forgets this sends the tail of the broken packet as if it were a new one.
  • Back-to-back packets. When the end beat of one packet leaves, rd_active falls and the start rule applies again to the next one. If the next packet is already above the threshold, it follows without a gap.
  • A writer that stalls in the middle of a packet. From the reader's point of view, that is the same as a slow writer. Only a guarantee from the writer, or store-and-forward, prevents underrun in that case.

Timing, area and power

  • Timing. The start rule is a compare of the occupancy against a constant plus a zero check on a small counter, feeding out_valid. If that is too slow, register the start decision from next-state values, the same trick as registered full and empty flags.
  • Area. Much smaller than store-and-forward for long packets, since depth is set by rate differences and stalls rather than by the largest packet. The extra state is one counter and one flop.
  • Latency. About THRESH beats plus the FIFO pipeline, independent of packet length.
  • Power. The same as a plain FIFO. Packets that are later marked bad have been forwarded in full, so the cost of errors moves downstream.

Verification checklist

  • A scoreboard that checks every beat, with its end and error bits, in order. Unlike store-and-forward, bad packets do come out, so the scoreboard expects them with out_err set on the end beat.
  • An independent check of the start rule: when the reader takes the first beat of a packet, the testbench knows how many beats of that packet have arrived and whether its end beat has.
  • Assertions:
    a_thresh: assert property (@(posedge clk) disable iff (!rst_n)
                do_pop && !rd_active |-> count >= THRESH || eop_count != '0);
    a_param:  initial assert (THRESH >= 1 && THRESH <= DEPTH);
    a_no_ur:  assert property (@(posedge clk) disable iff (!rst_n)
                writer_full_rate |-> !underrun);
  • The last one holds only under a writer that never pauses inside a packet. Use it as an assumption-guarded check, and sweep the writer rate against the threshold formula above to find the boundary.
  • Coverage: packets shorter than, equal to and longer than the threshold, packets longer than the depth, back-to-back packets, underrun in the first and last beat positions, and error packets of every length.

Interview questions

1. When does a cut-through FIFO start sending a packet?

A strong answer gives both conditions, a threshold of stored beats or the whole packet present, and explains why the second one is needed for short packets.

2. How do you size the threshold?

A strong answer relates it to the rate difference between writer and reader over the packet length, derives a formula or works an example, and notes that a full-rate writer needs a threshold of only one.

3. A CRC error is found on the last beat after the packet has started. What now?

A strong answer says the packet cannot be recalled, marks it bad on its end beat, explains how downstream stages drop it, and compares this with store-and-forward.

4. What happens if the threshold is larger than the depth?

A strong answer spots the deadlock for packets longer than the FIFO and adds a parameter check.

5. Store-and-forward or cut-through between a slow port and a fast port?

A strong answer says cut-through from slow to fast underruns unless the threshold is close to the packet length, so store-and-forward is usually used in that direction and cut-through in the other.

Where it is used in real chips

Cut-through buffering is common in low-latency network switches, in network-on-chip routers, where wormhole and virtual cut-through switching move flits on before the whole message arrives, in bridges between on-chip protocols, and in streaming paths between DMA engines and accelerators where packets are long and latency matters. Many switch designs support both modes per port and choose based on port speeds.

The rest of the series

Part 13 covered the store-and-forward FIFO, which holds each packet until it is complete and good. Part 15 changes the shape of the data instead of its timing: the width-conversion FIFO, which packs narrow beats into wide ones and unpacks them again.

Share Facebook X LinkedIn WhatsApp Email

Post a Comment

0 Comments

Your comments will be moderated before it appears here.

Post a Comment (0)

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn more
Ok, Go it!