Skip to content

Commit

Permalink
add plot for chap22.
Browse files Browse the repository at this point in the history
  • Loading branch information
tobyatgithub committed Oct 26, 2022
1 parent 5d1c05f commit 08760a5
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
.vs_code
*/.idea
*/cmake-build-*
ls-trace.txt
vpn.txt
result.txt
1 change: 1 addition & 0 deletions Homework7/chap22/Chapter22Simulator.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,4 @@ LRU was performing pretty well with locality. And RAND is not too bad compared t
> Use a program like `valgrind` to instrument a real application and generate a virtual page reference stream. For example, running `valgrind --tool=lackey --trace-mem=yes ls` will output a nearly-complete reference trace of every instruction and data reference made by the program `ls`. To make this useful for the simulator above, you’ll have to first transform each virtual memory reference into a virtual page-number reference (done by masking off the offset and shifting the resulting bits downward). How big of a cache is needed for your application trace in order to satisfy a large fraction of requests? Plot a graph of its working set as the size of the cache increases.
**Answer:**
![](hitrate-compare.png)
Binary file added Homework7/chap22/hitrate-compare.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified Homework7/chap22/paging-policy.py
100644 → 100755
Empty file.
21 changes: 21 additions & 0 deletions Homework7/chap22/plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import numpy as np
import matplotlib.pyplot as plt

cacheSizes = np.arange(1, 5)
policies = ["FIFO", "LRU", "OPT", "UNOPT", "RAND", "CLOCK"]
hitRate = [
[60.67, 86.24, 94.39, 98.72],
[60.79, 90.73, 95.76, 99.11],
[60.79, 90.77, 97.49, 99.41],
[60.79, 61.04, 61.10, 61.34],
[60.79, 86.75, 95.34, 98.08],
[60.79, 87.72, 95.89, 98.84]
]

for i in range(len(policies)):
plt.plot(cacheSizes, hitRate[i])

plt.legend(policies)
plt.xlabel("Cache sizes")
plt.ylabel("Hitrate")
plt.savefig("hitrate-compare.png")
11 changes: 11 additions & 0 deletions Homework7/chap22/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
POLICIES=("FIFO" "LRU" "OPT" "UNOPT" "RAND" "CLOCK")

for policy in "${POLICIES[@]}"
do
for i in 1 2 3 4
do
./paging-policy.py -c -f ./vpn.txt -p "$policy" -N -C "$i"
done
echo "$policy Done with Cache size = $i.\n"
done
11 changes: 11 additions & 0 deletions Homework7/chap22/transform.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#! /usr/bin/env python3

traceFile = open('./ls-trace.txt', 'r')
vpnFile = open('./vpn.txt', 'w')

for line in traceFile:
if (not line.startswith('=')):
vpnFile.write(str((int("0x" + line[3:11], 16) & 0xfffff000) >> 12) + "\n")

traceFile.close()
vpnFile.close()

0 comments on commit 08760a5

Please sign in to comment.