THINK FIRST·CODE LATER

← All labs

TLB simulator and effective access time

Problem

Simulate a fully associative TLB with LRU replacement.

Input: entries pageSize tlbNs memNs levels, then logical addresses until the end of input.

For each address, compute its page; a TLB hit if the page is in the TLB (it becomes most recently used), otherwise a miss (insert it, evicting the least recently used entry if the TLB is full).

Print Trace: MHHH… (one letter per access), Hits: h/n, hit ratio X% (one decimal), and EAT: Y ns (no TLB: Z ns) with one decimal, where a hit costs tlb + mem and a miss costs tlb + (levels + 1) × mem; "no TLB" costs (levels + 1) × mem.

Data for this lab

Your program reads its data from standard input. Download the file, then give it to your program as shown below. Start with data set 1: its expected output is given.

os9-3-data-1.txt

4 4096 1 100 4
0 1024 2048 3072 4096 5120 6144 7168 8192 9216 10240 11264 12288 13312 14336 15360
What your program must print for os9-3-data-1.txt
Trace: MHHHMHHHMHHHMHHH
Hits: 12/16, hit ratio 75.0%
EAT: 201.0 ns (no TLB: 500.0 ns)

Run your program first, then open this and compare line by line: your output must contain these lines exactly.

How to give the file to my program

Terminal (macOS, Linux, or Windows Command Prompt), after compiling:

java Main < os9-3-data-1.txt

Windows PowerShell does not understand <:

Get-Content os9-3-data-1.txt | java Main

IntelliJ IDEA: Run → Edit Configurations → Redirect input from. Or simply paste the content of the file into the console when the program waits for input.

Write it here or in your IDE, then paste it. Compile and test it yourself before comparing. Your code stays in your browser — it is never sent to or stored on the server.