10.10.1 Interleave Reads and Writes

HardImplementVerilator · serverReview the topic

Write a scenario generator that mixes a write burst and a read burst, stops at a budget and drops chosen reads.

Hardware context: Memory controller that collects write bursts while reads arrive. Generate interleaved write and read bursts with a budget and dropped reads.

A memory controller returned stale data when a read arrived in the middle of a write burst. The directed test sent every write and then every read, so it never produced that pattern. You will write the generator that does.

Write the task scenario(nw, nr, budget, skip) with one randsequence block. It sends write 0 to write nw - 1 in that order, and read 0 to read nr - 1 in that order. The two bursts must mix at random: over many calls, different orders must appear.

The tests check the scenarios your task builds, not how you wrote it. Use randsequence anyway: this problem practises rand join, break and return.

Two things cut a scenario. A read whose bit in skip is 1 is dropped, and the rest still runs. Once budget operations have been sent, the whole scenario ends. A dropped read does not use the budget.

Send an operation by calling emit(0, i) for write i or emit(1, i) for read i. With nw = 3, nr = 3 and budget = 4, one legal scenario is W0 R0 R1 W1.

Signals in the Timeline

SignalWidthRole
nw8input of each check
nr8input of each check
budget8input of each check
Full specification
What you write (keep the name and arguments)
task automatic scenario(input int nw, input int nr, input int budget, input bit [3:0] skip);
What the fixture gives you
function automatic void emit(input bit is_read, input int index);
RuleMeaning
OrderWrites appear as W0, W1, ... and reads as R0, R1, ..., each burst in its own order.
MixThe bursts interleave at random. A fixed order such as all writes first is not enough.
Dropped readsRead i is never sent when skip[i] is 1. It does not count as sent.
BudgetAfter budget operations, nothing more is sent. A budget of 0 sends nothing.
LengthA scenario has min(budget, nw + reads that are not dropped) operations.

Each case calls scenario 24 times with 24 seeds. It counts the scenarios with a wrong length, with an operation that should not exist, and with a burst out of order. It also checks that enough different orders appeared: 3 when that many exist, fewer when the inputs allow fewer.

The judge runs Verilator 5.052. On it, the productions that rand join mixes must take no arguments. Pass arguments one production lower, as in writes : wr(0) wr(1) wr(2) wr(3).

Examples

Example 1

Two Full Bursts
Input
nw = 3, nr = 3, budget = 8, skip = 4'b0000, 24 scenarios
Output
enough_different_orders = yes, scenarios_wrong_length = 0, scenarios_wrong_operation = 0, scenarios_out_of_order = 0

Every scenario has six operations, both bursts are in order, and at least three different orders appear.

Example 2

The Budget Ends the Scenario
Input
nw = 3, nr = 3, budget = 4, skip = 4'b0000, 24 scenarios
Output
enough_different_orders = yes, scenarios_wrong_length = 0, scenarios_wrong_operation = 0, scenarios_out_of_order = 0

Every scenario stops after four operations. Which four depends on the mix, for example W0 R0 R1 W1.

Example 3

One Read Is Dropped
Input
nw = 3, nr = 3, budget = 8, skip = 4'b0010, 24 scenarios
Output
enough_different_orders = yes, scenarios_wrong_length = 0, scenarios_wrong_operation = 0, scenarios_out_of_order = 0

Read 1 never appears. The other five operations still run, so R2 follows R0 directly.

Constraints and Contract

  • nw and nr are 0 to 4. budget is 0 to 9. skip has one bit per read.
  • scenario takes no simulation time and calls emit once per operation.
  • Keep the task name and its four arguments.

Hints

Hint 1

Start with two productions, one per burst, each a fixed list of four steps. Which production control mixes two productions and keeps the order inside each?

Hint 2

Write 3 should not exist when nw is 2. Such a step has to end quietly while the scenario goes on. A scenario that has used its budget has to end completely. Which statement fits each?

Hint 3

Count an operation only when you really send it. Check the dropped read before the budget, so that a dropped read never ends the scenario.

What the grader checks: Each case builds 24 scenarios from 24 seeds and checks every one for length, legal operations and burst order. The cases cover burst lengths 0 to 4, budgets 0 to 9 and many skip masks. Different orders must appear, but no particular order is required. A generator that mixes the bursts without randsequence would also pass.

24 checks on Verilator · server. Run the examples first, then check the full regression. Full checks use the server judge. Downloads contain public samples only. A passing result establishes the tested cases, not a proof for all possible inputs.

See all 2 steps and the final capstone

Report a problem with this page

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

Two Full Bursts

Input
nw = 3, nr = 3, budget = 8, skip = 4'b0000, 24 scenarios
Expected output
enough_different_orders = yes, scenarios_wrong_length = 0, scenarios_wrong_operation = 0, scenarios_out_of_order = 0

Every scenario has six operations, both bursts are in order, and at least three different orders appear.

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

Verilator · server