Credit-based flow control explained
Valid/ready needs the consumer's ready to reach the producer in the same cycle. On a long link —
across a chip, through pipeline registers, or between dies — that is impossible. Credit-based flow control solves
it with accounting:
- The receiver has a buffer of
DEPTHentries. - The sender starts with
DEPTHcredits — one per free slot it is allowed to fill. - Sending one item costs one credit. With zero credits the sender must wait.
- When the receiver frees a slot (its consumer pops an entry), it sends a credit back.
The sender never asks whether the receiver is ready: it knows there is space, because it holds a credit for it.
A credit link in action
Below, DEPTH = 2, the sender always has data, and the receiver pops every other tick. There is one register in
each direction.
Sizing: credits and round-trip time
A credit returns only after a full round trip: forward link latency + time in the buffer + return latency. To send every cycle, the sender needs at least as many credits (buffer entries) as cycles in that round trip. With too few credits the link still works — it just stalls, as in the waveform. This is why credit bugs are so often performance bugs: nothing breaks, the link is merely slower than designed.
The conservation invariant
Every credit is always in exactly one place: held by the sender, travelling as data on the forward link, occupying a receiver slot, or travelling back as a returned credit. So at every tick:
credits + data_in_flight + buffer_occupancy + credits_in_flight == DEPTH
This single equation implies no buffer overflow (the buffer can never hold more than DEPTH) and no credit creation. It is also inductive: if it holds now, each update keeps it true, so formal engines prove it quickly even for large DEPTH.