Fix a descriptor-ownership model that lets software edit a descriptor after handing it to the hardware.
Hardware context: Memory-to-memory DMA with owned descriptors and bounded bus bursts. Enforce the descriptor handoff from software ownership to active DMA hardware and back.
A driver model let software edit a descriptor after publishing it, as long as the engine was not copying yet. Real hardware may read a published descriptor at any moment, so that edit is a race.
The function descriptor_ownership models four descriptor slots. Each slot has an owner state and a generation number. It also has a payload that software edits and a snapshot that hardware uses. The function applies up to 32 commands in order and reports every slot after each one.
The tests replay 27 command lists: three short directed lists and 24 random lists of 24 commands. The random commands use every action, often in the wrong state or with the wrong token. The whole report is compared.
Find the bug and fix it. The rule in brief: software owns a slot only in state SOFTWARE. Hardware owns it from publication until software acknowledges DONE.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
operation_count | 6 | input of each check |
Full specification
function automatic string descriptor_ownership(input logic [1023:0] operations, input int count);
| Bits of a command | Holds |
|---|---|
| 1:0 | Slot, 0 to 3. |
| 4:2 | Action, 0 to 7. |
| 12:5 | Token: the generation the command is meant for. |
| 28:13 | Payload for an edit. |
| 31:29 | Always 0. |
Command t sits in bits 32t + 31 down to 32t of operations. count is the number of commands, at most 32.
| State | Meaning |
|---|---|
| 0, SOFTWARE | Software owns the slot and may edit it. |
| 1, READY | Published. Hardware may pick it up at any time. |
| 2, ACTIVE | Hardware is working on it. |
| 3, DONE | Finished or canceled. It waits for software to acknowledge. |
| Action | Accepted when | Effect |
|---|---|---|
| 0, edit | State is SOFTWARE. | payload = the command payload. |
| 1, publish | State is SOFTWARE. | generation + 1, snapshot = payload, state READY. |
| 2, dispatch | State is READY and token = generation. | State ACTIVE. |
| 3, complete | State is ACTIVE and token = generation. | State DONE. |
| 4, acknowledge | State is DONE and token = generation. | State SOFTWARE. |
| 5, cancel | State is READY or ACTIVE and token = generation. | State DONE. |
| 6 or 7 | Never. | None. |
A rejected command changes nothing. Every slot starts in SOFTWARE with generation, payload and snapshot all 0. With at most 32 commands, the generation never wraps.
Each command adds the accepted bit (1 or 0) and a colon. Then, for slots 0 to 3 in order, it adds state/generation/payload/snapshot and a comma. State and generation are decimal; payload and snapshot are four lowercase hex digits. A semicolon ends the entry. An example is 0:1/1/1234/1234,0/0/0000/0000,0/0/0000/0000,0/0/0000/0000,;.
The whole report string is compared with the expected one. The result shows the length of your report, the expected length and whether the two match.
Examples
Example 1
An Edit After Publishing- Input
Slot 0: edit 0x1234, publish, edit 0xffff, dispatch with token 1, complete with token 1, acknowledge with token 1.
- Output
report_length = 354, expected_length = 354, match = yes
Publishing copies 0x1234 into the snapshot and moves to READY. The edit of 0xffff comes while hardware owns the slot, so its accepted bit is 0. The slot then goes ACTIVE, DONE and back to SOFTWARE in generation 1.
Example 2
A Late Token After Reuse- Input
Slot 1: publish, dispatch with token 1, cancel with token 1, acknowledge with token 1, publish, dispatch with token 2, complete with token 1, complete with token 2.
- Output
report_length = 472, expected_length = 472, match = yes
The second publish starts generation 2. The completion with token 1 belongs to the old lifetime, so it is rejected. The completion with token 2 moves the slot to DONE.
Example 3
Two Slots at Once- Input
Publish slot 0, publish slot 1, dispatch slot 0 with token 1, cancel slot 1 with token 1, complete slot 0 with token 1, acknowledge slot 1 with token 1.
- Output
report_length = 354, expected_length = 354, match = yes
Each slot moves on its own. Slot 1 is canceled from READY and needs its own acknowledge. At the end, slot 0 waits in DONE and slot 1 is back in SOFTWARE.
Constraints and Contract
- A token names one lifetime of a slot, not the slot itself. A token from an earlier generation must be rejected.
- Completion does not give the slot back to software. Only an acknowledge does.
- Keep the function name, its arguments and the return type.
Hints
Hint 1
For each state, ask who owns the slot. Software may touch the payload only while it owns the slot.
Hint 2
Trace the first example: edit 0x1234, publish, then edit 0xffff. Which state is slot 0 in at the second edit? Should that edit be accepted?
Hint 3
Look at action 0 in the case statement. It accepts an edit in every state except ACTIVE. It should accept state 0, SOFTWARE, only.
What the grader checks: The tests replay three directed lists and 24 random lists over four slots. They compare every slot after every command. Cache flushes, memory barriers and bus timing are not modeled.
27 checks on Icarus · browser samples / server checks. 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 8 steps and the final capstone