S4.13.1 Follow the Lock

EasyImplement12 minIcarus Verilog · serverReview the topic

Follow two read-modify-write sequences through one SRAM port, and find what the lock costs and saves.

Hardware context: Two managers sharing one SRAM port through a round-robin arbiter with a lock. Debugging a shared counter on a multi-manager bus

This capture comes from the lab of lesson S4.13. The counter in SRAM starts at 7. The cpu adds 2 and the dma adds 30. Both raise HMASTLOCK for their read and their write. The arbiter is round robin, and the cpu wins the first tie.

This worksheet uses named constants. The first three entries show how to record your decisions.

Signals in the Timeline

SignalWidthRole
question8input of each check
Full specification
EdgeWaiting, cpuWaiting, dmaHMASTLOCK, cpuHMASTLOCK, dmaPort locked byServed at this edgeCounter before the edge
0nonenone00nobodynobody7
1nonenone11nobodynobody7
2READREAD11nobodycpu READ 77
3noneREAD11cpunobody7
4WRITEREAD11cpucpu WRITE 97
5noneREAD01cpunobody9
6noneREAD01nobodydma READ 99
7nonenone01dmanobody9
8noneWRITE01dmadma WRITE 399
9nonenone00dmanobody39
10nonenone00nobodynobody39

Each row is what one rising clock edge sees. A request waits in the input stage until the port serves it. The port is locked after a served transfer with HMASTLOCK at 1. It is unlocked after a cycle in which the manager that holds it shows HMASTLOCK at 0. Enter edges and values as plain numbers.

EntryYour decision
CPU_READ_EDGEEdge that serves the read of the cpu.
CPU_READ_VALUEValue that the cpu reads.
FIRST_LOCKEDFirst edge that sees the port locked.
CPU_WRITE_EDGEEdge that serves the write of the cpu.
CPU_WRITE_VALUEValue that the cpu writes.
DMA_WAITSNumber of edges that see the read of the dma waiting and do not serve it.
UNLOCK_SEENEdge that sees the HMASTLOCK of the cpu at 0 while the port is still locked.
DMA_READ_EDGEEdge that serves the read of the dma.
DMA_READ_VALUEValue that the dma reads.
DMA_WRITE_VALUEValue that the dma writes.
RACE_RESULTValue of the counter at the end if neither manager raised HMASTLOCK. The reads are then served at edges 2 and 3, and the writes at edges 4 and 5.
LOCKED_RESULTWhat does the counter hold at the end if the dma adds N in place of 30, with both managers locking as in the capture?

Examples

Example 1

CPU READ EDGE
Input
Edge that serves the read of the cpu.
Output
matches = 1

Edge 2 has both reads waiting. The cpu wins the first tie.

Example 2

CPU READ VALUE
Input
Value that the cpu reads.
Output
matches = 1

The counter is 7 before edge 2.

Example 3

FIRST LOCKED
Input
First edge that sees the port locked.
Output
matches = 1

The read served at edge 2 had HMASTLOCK at 1, so the port is locked from then on.

Constraints and Contract

  • Keep the parameter and named constants. Use the numeric codes and units on this page.
  • For LOCKED_RESULT, enter a constant expression using N. Only this entry changes with the parameter. The supported integer range is 0 through 31, inclusive.

Hints

Hint 1

Find the edge that serves its read and the edge that serves its write.

Hint 2

The port is locked from the edge after a served locked transfer. It opens one cycle after HMASTLOCK falls.

Hint 3

Without the lock the two reads come first. Both managers then add to the same old value.

What the grader checks: Each check compares the full eight-bit answer. Parameter trials change one condition and keep the other decisions fixed.

12 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 1 problem 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

CPU READ EDGE

Input
Edge that serves the read of the cpu.
Expected output
matches = 1

Edge 2 has both reads waiting. The cpu wins the first tie.

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

Icarus Verilog · server