S3.8.1 A Four-Entry TLB

MediumImplement40 minIcarus Verilog · serverReview the topic

Remember four translations, find a page among them in the same cycle, and refuse an access that the page does not allow.

Hardware context: A TLB of four entries in front of a two-level page table, as test code. Sizing and checking the TLB of a processor

A processor translates 32-bit virtual addresses with pages of 4096 bytes. A walker reads the page tables, which is slow. Write the block that remembers the last translations: a TLB of four entries.

The block has two sides. On the lookup side, the processor gives a page number and the kind of access, and wants the answer in the same cycle. On the refill side, the walker hands over one translation at a clock edge.

Signals in the Timeline

SignalWidthRole
trial10input of each check
Full specification
What one entry remembers
PartWidthMeaning
valid1 bitthe entry holds a translation
page number20 bitswhich virtual page
frame number22 bitswhere that page lies
rights3 bitsX, W and R of the page
The right that each kind of access needs
kindAccessNeeds
0fetchX, bit 2 of the rights
1loadR, bit 0
2storeW, bit 1

How to read a result: the bench looks up one page in each of 24 cycles. The field "hits" counts the cycles with hit at 1, and "faults" those with fault at 1. The field "last_frame" is ppn in the last cycle that hit. In the cycles after the sequence, the bench looks up page 00000 as a load.

Examples

Example 1

Miss, Fill, Hits
Input
fetch from page 00403, then fill page 00403 with frame 000009 and RX, then fetch from page 00403, then load from page 00403, then load from page 00404
Output
hits = 2, faults = 0, last_frame = 0x9, signature = 0x1b01800

The first lookup misses. After the fill, the fetch and the load of page 00403 both hit and give frame 000009. Page 00404 was never filled.

Example 2

Rights on a Hit
Input
fill page 00403 with frame 000009 and RX, then fill page 00404 with frame 000006 and RW, then store to page 00403, then store to page 00404, then fetch from page 00404, then fetch from page 00403
Output
hits = 4, faults = 2, last_frame = 0x9, signature = 0x1541400

Page 00403 has R and X: a store to it is a hit and a fault. Page 00404 has R and W: the store is allowed, and the fetch is a hit and a fault. Four hits, two faults.

Example 3

Five Pages, Four Entries
Input
fill page 00403 with frame 000010 and RWX, then fill page 00404 with frame 000011 and RWX, then fill page 00405 with frame 000012 and RWX, then fill page 00406 with frame 000013 and RWX, then fill page 00407 with frame 000014 and RWX, then load from page 00403, then load from page 00404, then load from page 00405, then load from page 00406, then load from page 00407
Output
hits = 4, faults = 0, last_frame = 0x14, signature = 0x3c81e0

Five pages are filled into four entries, so the fifth replaces the first. The lookup of page 00403 misses and the other four hit.

Constraints and Contract

  • hit is 1 when a valid entry holds the page number vpn. All four entries are compared in the same cycle.
  • ppn is the frame number of that entry. When hit is 0, ppn is 0 and fault is 0.
  • fault is 1 when hit is 1 and the rights of the entry do not allow this kind of access.
  • At a rising edge with fill at 1 and rst_n at 1, the translation on the fill inputs is stored. If a valid entry already holds fill_vpn, that entry is updated in place. Otherwise the entries are used in turn: 0, 1, 2, 3, and then 0 again.
  • An update in place does not use up a turn. So a new page always replaces the entry whose page was first filled longest ago.
  • The lookup shows the stored entries only. A fill is seen from the next cycle on.
  • At a rising edge with rst_n at 0, every entry becomes not valid and the turn starts again at entry 0. The reset wins over a fill in the same cycle. The bench also resets in the middle of a run.

Hints

Hint 1

Write one compare for each entry first: its valid bit, and its page number against vpn.

Hint 2

The outputs follow from those four compares. Decide what each output is when none of them is 1.

Hint 3

A fill needs a place. Ask first whether the page is already in an entry.

What the grader checks: One to eight pages through four entries; every combination of rights against every kind of access; a fill of a page that is already there, in every position, followed by enough new pages to show which entry goes next; page numbers that differ in a few high or low bits; a lookup in the cycle of its own fill; a reset in the middle, alone and with a fill; page 00000; random sequences of up to 24 cycles. Each check compares the counts, the last frame and a signature over the three outputs of every cycle.

92 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

Miss, Fill, Hits

Input
fetch from page 00403, then fill page 00403 with frame 000009 and RX, then fetch from page 00403, then load from page 00403, then load from page 00404
Expected output
hits = 2, faults = 0, last_frame = 0x9, signature = 0x1b01800

The first lookup misses. After the fill, the fetch and the load of page 00403 both hit and give frame 000009. Page 00404 was never filled.

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

Icarus Verilog · server