S3.8.2 The Walker FSM

HardImplement50 minIcarus Verilog · serverReview the topic

Read two page-table entries from a memory that answers when it likes, and end each walk with a frame or with a fault.

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 a page table of two levels. Its TLB has missed. Write the state machine that walks the tables: it reads the entry of the root table, then the entry of the second table, and reports the result.

The memory and the tables are part of the bench. Memory answers a read in the cycle in which it raises mem_ready. That may be the first cycle of the read, or many cycles later.

Signals in the Timeline

SignalWidthRole
trial10input of each check
Full specification
The states
Statemem_reqmem_addrNext state
IDLE00start is 1: store vpn and go to LEVEL1
LEVEL11root_ppn, then bits 19 to 10 of the stored page number, then 00mem_ready is 1 and the entry is a pointer: store its frame and go to LEVEL0. mem_ready is 1 and it is anything else: IDLE
LEVEL01the stored frame, then bits 9 to 0 of the stored page number, then 00mem_ready is 1: IDLE
What an entry is. Bit 0 is V, bit 1 is R, bit 2 is W, bit 3 is X; bits 31 to 10 are a frame number
VX W RThe entry is
0anythingnot valid
10 0 0a pointer to the next table
1R is 1, or X is 1 with W at 0a page entry
1W is 1 and R is 0not legal

This walker has no large pages. A page entry in the root table is a fault here. A real walker for this table format would accept it.

How to read a result: "walks_ended" counts the cycles with done at 1, and "faults" those that also had fault at 1. "last_frame" and "last_bits" are ppn and bits of the last walk that ended without a fault.

Examples

Example 1

One Walk
Input
The root table is in frame 10. Memory holds 00004401 at 10004 and 0000245b at 1100c, and answers every read at once. One walk for page 00403
Output
walks_ended = 1, faults = 0, last_frame = 0x9, last_bits = 0x5b, signature = 0x78401220

The first read is at 10004 and gives a pointer to frame 11. The second read is at 1100c and gives a page entry: frame 000009 with the low byte 5b. One walk ends, with no fault.

Example 2

A Memory That Makes It Wait
Input
The same memory, but it lets the first read wait 2 cycles and the second read 3 cycles
Output
walks_ended = 1, faults = 0, last_frame = 0x9, last_bits = 0x5b, signature = 0xfbbfa2c9

The walker holds each read until memory answers. The result is the same as before, a few cycles later.

Example 3

Two Faults
Input
Memory holds only the pointer 00004401 at 10004. One walk for page 00403, then one for page 00800
Output
walks_ended = 2, faults = 2, last_frame = 0x0, last_bits = 0x0, signature = 0x5ce86221

Page 00403: the pointer is good, and the second table has no valid entry at 1100c. Page 00800: the root entry at 10008 is not valid. Two walks end, both with a fault.

Constraints and Contract

  • mem_req and mem_addr follow the state and the stored values only. They must not depend on mem_ready or mem_rdata.
  • In LEVEL1 and LEVEL0 the walker holds mem_req and mem_addr until a cycle with mem_ready at 1. In that cycle mem_rdata is the entry. In every other cycle mem_rdata holds junk.
  • done is 1 in the cycle in which a walk ends: in LEVEL1 with mem_ready and an entry that is not a pointer, or in LEVEL0 with mem_ready. It follows mem_ready and mem_rdata with no clock edge in between.
  • With done, fault is 0 only for a page entry read in LEVEL0. Then ppn is bits 31 to 10 of the entry and bits is its bits 7 to 0.
  • When done is 0, fault is 0. When done is 0 or fault is 1, ppn and bits are 0.
  • vpn is good only in the cycle of start. start is ignored while a walk runs, including the cycle in which it ends. mem_ready means nothing in IDLE.
  • At a rising edge with rst_n at 0 the walker goes to IDLE, whatever it was doing. The bench also resets in the middle of a walk.

Hints

Hint 1

Write the state register first: three states, and the input that each one waits for.

Hint 2

Two values must be stored on the way. Ask at which edge each of them is on the wires.

Hint 3

Write "pointer" and "page entry" as two wires on mem_rdata. Every output is then one line.

What the grader checks: All sixteen values of V, R, W and X at the last level, and at the first; page numbers with every index bit set or clear; root tables and frames with their highest bits set, so that mem_addr needs 34 bits; waits of 0 to 10 cycles at each level; mem_ready and junk data while idle; a page number that changes after start; a start during a walk and in its last cycle; walks back to back; a reset in each state and in the cycle of a start; random sequences of up to 32 cycles over random tables. Each check compares the counts, the last result and a signature over every output of every cycle.

108 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

One Walk

Input
The root table is in frame 10. Memory holds 00004401 at 10004 and 0000245b at 1100c, and answers every read at once. One walk for page 00403
Expected output
walks_ended = 1, faults = 0, last_frame = 0x9, last_bits = 0x5b, signature = 0x78401220

The first read is at 10004 and gives a pointer to frame 11. The second read is at 1100c and gives a page entry: frame 000009 with the low byte 5b. One walk ends, with no fault.

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

Icarus Verilog · server