-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
110 lines (79 loc) · 2.3 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# this is where the main code will go
# input instructions, parse them into op - address - arrival time
# stall next instruction until returned from last
from Cache import Cache
# test case 1 (2 level write back):
programLatency = 0
c = Cache(2, 64, 1, 16, 4, 0)
c.CreateLevelCache(256, 50, 16, 8, 0)
# print empty contents
# warm up set 0
programLatency += c.read(0, programLatency) # miss
programLatency += c.read(16, programLatency) # miss
programLatency += c.read(32, programLatency) # miss
programLatency += c.read(1, programLatency) # hit!
programLatency += c.read(48, programLatency) # miss - L1 full
programLatency += c.read(64, programLatency) # miss - overwrite 16
programLatency += c.read(16, programLatency) # miss L1, hit L2
programLatency += c.read(80, programLatency) # miss
data = [123 for i in range(16)]
programLatency += c.write(0, data, programLatency) # write hit in L2 for write through, miss L1 (do nothing)
'''
# test case 2 (2 level write thru):
programLatency = 0
c = Cache(2, 32, 5, 4, 4, 1)
c.CreateLevelCache(64, 5, 4, 4, 0)
# print empty contents
c.printInfo()
# warm up
for i in range(32):
programLatency += c.read(i, i)
c.printInfo()
programLatency += c.write(0, 123, 32)
programLatency += c.write(1, 321, 33)
programLatency += c.write(2, 111, 34)
programLatency += c.write(0, 412, 35)
print('Program Latency:', programLatency)
c.printInfo()
'''
'''
# test case 3 (read miss):
programLatency = 0
c = Cache(2, 32, 5, 4, 4, 1)
c.CreateLevelCache(64, 5, 4, 4, 0)
# warm up
for i in range(32):
programLatency += c.read(i, i)
programLatency += c.read(33, 33)
print('Program Latency:', programLatency)
c.printInfo()
'''
'''
# test case 4 (read miss, then write, then read hit):
programLatency = 0
c = Cache(2, 32, 5, 4, 4, 0)
c.CreateLevelCache(64, 5, 4, 4, 0)
# warm up
for i in range(32):
programLatency += c.read(i, i)
programLatency += c.read(33, 33)
programLatency += c.write(33, 123, 34)
programLatency += c.read(33, 35)
print('Program Latency:', programLatency)
c.printInfo()
'''
'''
# test case 5 (miss L1 hit L2):
programLatency = 0
c = Cache(2, 32, 5, 4, 4, 1)
c.CreateLevelCache(64, 5, 4, 4, 0)
# warm up
for i in range(64):
programLatency += c.read(i, i)
# write to L2
c.write(45, 456, 33)
# read
c.read(45, 35)
print('Program Latency:', programLatency)
c.printInfo()
'''