Skip to content

idma_channel_coupler: don't consume coupled-AW credit when popping a …#98

Open
flaviens wants to merge 1 commit into
pulp-platform:masterfrom
flaviens:fix/i003-channel-coupler-decoupled
Open

idma_channel_coupler: don't consume coupled-AW credit when popping a …#98
flaviens wants to merge 1 commit into
pulp-platform:masterfrom
flaviens:fix/i003-channel-coupler-decoupled

Conversation

@flaviens
Copy link
Copy Markdown

@flaviens flaviens commented May 8, 2026

Hi there!

proc_credit_cnt could incorrectly consume a coupled-AW credit while popping a decoupled AW at the FIFO head. That left the later coupled AW with no saved credit and no arriving first beat, causing the AW master channel to deadlock.

This PR gates the first-consuming and credit-decrement paths on ~aw_decoupled_head, so decoupled AWs are handled only by the default pop path and never modify the coupled-AW credit counter. This is a minimal fix for master; the larger upstream decouple_rw_fix refactor remains separate.

Thanks!
Flavien

Copilot AI review requested due to automatic review settings May 8, 2026 16:05
@flaviens flaviens requested a review from thommythomaso as a code owner May 8, 2026 16:05
…decoupled head

The credit counter `aw_to_send_q` in `proc_credit_cnt` tracks coupled
AWs whose `first` R beat has arrived but that have not yet been
handshaken on the AW master channel. The default
`aw_sent = aw_decoupled_head & aw_valid` correctly pops a decoupled
AW from the head without touching the counter, but the surrounding
if/else-if chain does not check whether the head is decoupled. This
leads to two related bugs:

1. The third else-if (`aw_ready_decoupled & !first & aw_to_send_q != 0`)
   decrements the counter and asserts `aw_sent` whenever the downstream
   is ready and a credit is pending — even when the AW currently being
   popped is a decoupled head. The credit (which was earned by a
   *coupled* AW further back in the FIFO) is consumed by the decoupled
   pop, so when the coupled AW reaches the head later it has neither a
   credit nor an arriving `first` and the AW master channel deadlocks.

2. The first if-branch (`aw_ready_decoupled & first`) consumes a
   `first` even when the head is decoupled. The `first` belonged to a
   future coupled AW; it is silently lost.

Reproducer (seclang `examples/idma/i003_verilator/`):

    1. Push AW0 (decoupled).         FIFO=[AW0(dec)]              ready=0
    2. first arrives for upcoming AW1. ready=0, credit++ -> 1
    3. Push AW1 (coupled).            FIFO=[AW0(dec), AW1(coup)]  ready=0
    4. Release ready=1.

    Pre-fix:  cycle 0 handshakes AW0 and decrements credit to 0.
              cycle 1+ AW1 head, no credit, no `first` -> deadlock.
    Post-fix: cycle 0 handshakes AW0 (default path), credit stays at 1.
              cycle 1 handshakes AW1, credit drains to 0.

Fix: gate the first-consuming branch and the credit-decrement branch
on `~aw_decoupled_head`, and rephrase the increment branch to fire
on any unhandled `first`. Decoupled AWs are popped only by the
default `aw_sent = aw_decoupled_head & aw_valid` path and do not
interact with the credit counter.

A more comprehensive fix exists upstream on branch
`decouple_rw_fix` (commit a7bbc83, "Fix channel_coupler to handle
decoupled", 2025-08-21) which introduces a separate `aw_to_stall_q`
counter; that branch also touches other parts of the legalizer and
has not been merged. This patch is the minimal change that resolves
the deadlock against `master` without the larger refactor.
@flaviens flaviens force-pushed the fix/i003-channel-coupler-decoupled branch from 72919ba to cdb3afd Compare May 8, 2026 16:06
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a deadlock in the AW master channel by ensuring the coupled-AW credit counter is never consumed or decremented when the FIFO head entry is a decoupled AW. This keeps decoupled AW popping on the default path and preserves credits for coupled AWs further back in the queue.

Changes:

  • Clarifies the meaning of aw_to_send_q as a credit counter for coupled AWs only, and documents why decoupled head AWs must not consume credits.
  • Gates the “send-on-first” and “drain-credit” paths with ~aw_decoupled_head so only coupled head AWs can affect the credit counter.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants