S9.2.1 The Reservation Register

MediumImplement45 minIcarus Verilog · serverReview the topic

Build the exclusive access monitor that decides whether a store-conditional from either hart may write the SRAM.

Hardware context: ap_soc exclusive monitor and bus arbiter. Spin locks and shared counters on a multi-manager bus

In the dual-hart ap_soc, a load-reserved becomes an exclusive read on the bus and a store-conditional becomes an exclusive write. A monitor beside the SRAM remembers one reservation per hart and answers every exclusive write.

Implement that monitor. Get one rule wrong and two harts can both believe they won the same lock.

Signals in the Timeline

SignalWidthRole
sample11input of each check
Full specification
Event at an accepted transferEffect
Exclusive read from hart hRecord a reservation for hart h on the 8-byte granule of haddr, replacing any older one. Respond hexokay.
Exclusive write from hart hSucceeds if hart h holds a reservation on this granule: respond hexokay and commit. Otherwise neither, and no other reservation changes. Either way, hart h's reservation ends.
Any write that commitsEnds every reservation on its granule, including one held by the writer.
Exclusive read or write from DMA or debugNever monitored. No hexokay. An exclusive write from them does not commit and changes no reservation.
Plain readChanges no reservation.

A transfer is accepted at a rising edge where hsel is 1 and htrans is NONSEQ (10) or SEQ (11). IDLE and BUSY transfers, and edges with hsel low, change nothing. An exclusive transfer is always a single NONSEQ beat (IHI 0033 issue C §10.4). So the bench never marks a SEQ transfer exclusive. The SRAM answers with no wait states, so every transfer is accepted on its edge.

Decide at the accepting edge and update the reservations there. Register hexokay and commit at that edge, so both describe the accepted transfer during its data phase. With no accepted transfer, both are 0 in the next cycle. Plain writes commit; reads never do.

A synchronous active-low reset clears both reservations and both outputs.

The monitor role and the HEXOKAY response follow Arm AMBA AHB Protocol Specification IHI 0033 issue C, sections 10.1 to 10.4. These are ap_soc design choices: the 8-byte granule and the hmaster numbering. So are the rule that only the two harts are exclusive-capable and the effect of the writer's own plain store. Section 10.1 leaves that last one implementation defined. Ending the reservation at every exclusive write, pass or fail, follows the RISC-V store-conditional rule (RISC-V ISA manual, not in our library).

The S9.2 lab bench holds a word-sized reservation model for two harts. You may start from it; the AHB acceptance, the granule, the data-phase timing and the other managers are yours to add.

Examples

Example 1

Reset
Input
reset, hmaster=0, haddr=0x0000, hsel=0, htrans=00
Output
commit = 0, hexokay = 0

No transfer is in its data phase, so both outputs are 0.

Example 2

Load-Reserved by Hart 0
Input
exclusive read, hmaster=0, haddr=0x0104, hsel=1, htrans=10
Output
commit = 0, hexokay = 1

The exclusive read is recorded. hexokay rises in its data phase; a read never commits.

Example 3

Store-Conditional by Hart 0
Input
exclusive write, hmaster=0, haddr=0x0104, hsel=1, htrans=10
Output
commit = 1, hexokay = 1

Hart 0 still holds the granule, so the exclusive write succeeds and commits.

Constraints and Contract

  • Keep module excl_monitor and its ports. Inputs are known binary values. hexokay and commit are registered.
  • Reach the bench only through your ports. force, release, defparam, bind, $root and bench names are refused before the run.

Hints

Hint 1

Write down the four kinds of accepted transfer and what each does to each reservation.

Hint 2

A failed exclusive write must leave the SRAM and the other reservation alone.

Hint 3

Compare the granule, not the whole address: 0x0104 and 0x0100 share one.

What the grader checks: Directed sequences cover each rule for both harts, DMA and debug, every transfer type and reset. Each address bit is flipped alone, inside and outside the granule. A random sequence mixes all of them. A final group uses an address that differs per submission.

554 checks on Icarus Verilog · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain your source only; samples require the simulation service. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 2 problems on this path

Report a problem with this page

Your code SystemVerilogSaved locally
Ln 1, Col 1Tab indents · Ctrl/⌘ + Enter runs samples
Not run yet

Reset

Input
reset, hmaster=0, haddr=0x0000, hsel=0, htrans=00
Expected output
commit = 0, hexokay = 0

No transfer is in its data phase, so both outputs are 0.

Run samples executes all 3 public checks. Check all tests runs 554 checks on the server.

Icarus Verilog · server