Two programs share a page, and one of them reads a word that the other has already replaced. Find the first wrong sample in the cache, name the cause, and repair it.
Hardware context: A direct-mapped cache with blocks of 16 bytes, indexed with virtual address bits while the TLB translates and tagged with the frame number, as test code. Sizing a level-1 cache that is looked up during address translation
A small processor has pages of 256 bytes. Its cache is looked up while the TLB translates: the line is picked from the virtual address at once, and the tag is compared with the frame number when the TLB delivers it. A team has just doubled this cache from 64 lines to 128.
Since then, two programs that share a page sometimes disagree about its contents. Run the failing bench. Select the first cycle and signal that differ from a correct cache, choose the cause, and then repair the cache.
Signals in the Timeline
| Signal | Width | Role |
|---|---|---|
trial | 10 | input of each check |
Full specification
| Part | Contract |
|---|---|
| A word | Two addresses with the same frame number and the same offset are the same word, whatever their page numbers are. A line holds one word of 4 bytes. |
| hit, rdata | No clock edge in between. hit is 1 when the cache holds the word of this address. rdata is that word, and 0 when hit is 0. |
| fill | At a rising edge with fill at 1, wdata becomes the word of this address in the cache. It replaces whatever word had the same offset. |
| write | At a rising edge with write at 1, fill at 0 and hit at 1, the word is replaced by wdata. With hit at 0 nothing changes. |
| Leaving the cache | A word leaves the cache only at a reset, or when a word with the same offset and another frame number is filled. |
| rst_n | At a rising edge with rst_n at 0 the cache becomes empty. The reset wins over fill and write. |
In the bench, pages 04, 06 and 07 are three names of frame 06. Page 05 is frame 07.
Diagnose the Failing Run
The test below runs the buggy design. Read its log, then find where it first goes wrong in the waveform.
Log
Waveform
Click a signal at a cycle to select it. Or focus the waveform and use the arrow keys: Left and Right move one cycle, Up and Down one signal.
Step 3 is optional: fix the code in the editor, then run the tests.
Examples
Example 1
One Word, Two Names- Input
fill 0410 with 11111111, then look up 0410, then look up 0710
- Output
hits = 2, last_word = 0x11111111, signature = 0xaaaabeaa
Addresses 0410 and 0710 are the same physical word: frame 06, offset 10. After the fill, a lookup through either name is a hit with 11111111.
Example 2
A Write Through the Other Name- Input
fill 0710 with 11111111, then write 22222222 to 0410, then look up 0710, then look up 0410
- Output
hits = 3, last_word = 0x22222222, signature = 0x77776277
The write goes through the other name of the word. It is a hit, so the word changes. Both names then read 22222222.
Example 3
Two Frames, One Offset- Input
fill 0410 with 11111111, then look up 0510, then fill 0510 with 55555555, then look up 0510, then look up 0410
- Output
hits = 1, last_word = 0x55555555, signature = 0xaaaaabaa
Address 0510 is another frame with the same offset. It misses, and its fill replaces the word of frame 06. The last lookup misses.
Constraints and Contract
- Keep module early_cache and its ports. The line must be picked from vaddr alone: ppn arrives too late for that. You may leave lines unused. The two lowest bits of vaddr pick a byte inside the word and play no part.
Hints
Hint 1
Find the first cycle in which the same word is looked up through a second name.
Hint 2
Ask which bits of an address a translation leaves alone.
Hint 3
Check where the line number comes from, bit by bit.
What the grader checks: The failing run shows one fault. The fix is checked on hidden sequences: every pair of names of one frame, in both orders, for fills and for writes; other frames at the same offset; every line of a page; a write that misses; a fill with a write; the two low address bits; a reset in the middle, alone and with a fill; random sequences. Each check compares a signature over hit and rdata of every cycle.
100 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