-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimulator.cpp
More file actions
77 lines (67 loc) · 2.45 KB
/
Copy pathsimulator.cpp
File metadata and controls
77 lines (67 loc) · 2.45 KB
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
#include "LRU.hpp"
#include "memory.hpp"
#include "Exclusive.cpp"
#include "deadblock.hpp"
#include <iostream>
#include "config.hpp"
using namespace std;
int main(int argc,char *argv[])
{
int cmd;
ulong address;
//initialize the simulator
Config config;
config.initialize(argc, argv);
ulong blockSize = config.blockSize;
L1Exclusive L1 = L1Exclusive(config.L1CacheSize / blockSize, blockSize);
L2ExclusivePrefetch L2 = L2ExclusivePrefetch(config.L2CacheSize / blockSize, blockSize);
DeadBlockLRUCache L3 = DeadBlockLRUCache(config.L3CacheSize / blockSize, blockSize);
Memory memory = Memory();
L1.setUpperCache(&L2);
L2.setUpperCache(&L3);
L2.setLowerCache(&L1);
L3.setUpperCache(&memory);
L3.setLowerCache(&L2);
L1Exclusive L1n2 = L1Exclusive(config.L1CacheSize / blockSize, blockSize);
L2Exclusive L2n2 = L2Exclusive(config.L2CacheSize / blockSize, blockSize);
DeadBlockLRUCache L3n2 = DeadBlockLRUCache(config.L3CacheSize / blockSize, blockSize);
Memory memoryn2 = Memory();
L1n2.setUpperCache(&L2n2);
L2n2.setUpperCache(&L3n2);
L2n2.setLowerCache(&L1n2);
L3n2.setUpperCache(&memoryn2);
L3n2.setLowerCache(&L2n2);
L1Exclusive L1n3 = L1Exclusive(config.L1CacheSize / blockSize, blockSize);
L2Exclusive L2n3 = L2Exclusive(config.L2CacheSize / blockSize, blockSize);
LRUCache L3n3 = LRUCache(config.L3CacheSize / blockSize, blockSize);
Memory memoryn3 = Memory();
L1n3.setUpperCache(&L2n3);
L2n3.setUpperCache(&L3n3);
L2n3.setLowerCache(&L1n3);
L3n3.setUpperCache(&memoryn3);
L3n3.setLowerCache(&L2n3);
cout << blockSize << endl;
cout << config.L1CacheSize << endl;
while(cin >> dec >> cmd >> hex >> address)
{
ulong lineAddress = (address / blockSize) * blockSize;
//if(cmd != 2) cout << cmd << " " << lineAddress << endl;
switch(cmd)
{
case 0: L1.read(lineAddress); L1n2.read(lineAddress); L1n3.read(lineAddress); break;
case 1: L1.write(lineAddress); L1n2.write(lineAddress); L1n3.write(lineAddress); break;
}
}
cout << "L1 " << L1 << endl;
cout << "L2 " << L2 << endl;
cout << "L3 " << L3 << endl;
cout << "Memory " << memory << endl << endl;
cout << "L1n2 " << L1n2 << endl;
cout << "L2n2 " << L2n2 << endl;
cout << "L3n2 " << L3n2 << endl;
cout << "Memoryn2 " << memoryn2 << endl << endl;
cout << "L1n3 " << L1n3 << endl;
cout << "L2n3 " << L2n3 << endl;
cout << "L3n3 " << L3n3 << endl;
cout << "Memoryn3 " << memoryn3 << endl << endl;
}