forked from nykez/memory-simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimulationDeployer.cpp
124 lines (112 loc) · 4.31 KB
/
SimulationDeployer.cpp
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Project: GroupProject
// File Name: SimulationDeployer.cpp
// Description: Implementation of SimulationDeployer.h
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "SimulationDeployer.h"
/// <summary>
/// Deault construtor
/// </summary>
SimulationDeployer::SimulationDeployer() {
}
/// <summary>
/// Deconstructor
/// </summary>
SimulationDeployer::~SimulationDeployer() {
}
/// <summary>
/// Initialize our simulation deployer.
/// Read in config file, parse it, setup our MemoryOption
/// setup our Memory Controller, display config and trace header
/// </summary>
void SimulationDeployer::Initialize(const string& configFile, const string& traceFile) {
// Read config
///DAVID: READ IN MAP HERE inputReader.ReadConfigFile(configFile);
auto options = inputReader.ReadConfigFile(configFile); //read in config file map
// Setup config
///DAVID: Search through map, assinging things to our MO
MO.tlbEntries = stoi(options.at("Number of entries"));
MO.pageCount = stoi(options.at("Number of virtual pages"));
MO.frameCount = stoi(options.at("Number of physical pages"));
MO.pageSize = stoi(options.at("Page size"));
MO.dcEntries = stoi(options.at("Number of entries"));
MO.dcSetSize = stoi(options.at("Set size"));
MO.dcLineSize = stoi(options.at("Line size"));
string isWriteConf = options.at("Write through/no write allocate");
if (isWriteConf == "N" || isWriteConf == "n")
{
//TODO: use write through/no write memory option
}
string isVirtConf = options.at("Virtual addresses");
if (isVirtConf == "n" || isVirtConf == "n")
{
MO.useVirt = false;
}
string isTLBConf = options.at("TLB");
if (isTLBConf == "N" || isTLBConf == "n")
{
MO.useTLB = false;
}
// Setup Memory Controller
MC = (MO);
// Display config
outputDisplayer.FeedConfigOutput(MC.GetConfigOptions());
outputDisplayer.DisplayConfig();
// Setup trace file
outputDisplayer.DisplayTraceHeader();
inputReader.SetTraceFile(traceFile);
}
///<summary>
/// Directs inputReader to gather information from console.
///</summary>
void SimulationDeployer::GatherInput() {
traces.emplace_back(Trace(0,0xC84));
traces.emplace_back(Trace(0,0x81C));
traces.emplace_back(Trace(0,0x14C));
traces.emplace_back(Trace(0,0xC84));
traces.emplace_back(Trace(0,0x400));
traces.emplace_back(Trace(0,0x148));
traces.emplace_back(Trace(0,0x144));
traces.emplace_back(Trace(0,0xC80));
traces.emplace_back(Trace(0,0x008));
}
/// <summary>
/// Run our simulation. Start feeding in traces to the MemoryController.
/// Feed output to the OutputDisplayer.
/// </summary>
void SimulationDeployer::RunProgram() {
///DAVID: uncomment this next section. It should work. If it doesn't fix it.
/// This next section should
//For each address in inputReader.inputLines
// pass into MC, storing results in array
//*
while(true) {
std::pair<bool, std::pair<std::string, std::string>> fileInput = inputReader.ReadTrace();
if(fileInput.first == true) break; // if no more to read, finished.
int accessType = 0;
if(fileInput.second.first == "W") accessType = 1;
int hexaddr = std::stoi(fileInput.second.second, nullptr, 16); // get hex address
Trace trace(accessType,hexaddr); // create trace
TraceStats traceStats = MC.RunMemory(trace); // run
outputDisplayer.DisplayTraceLine(traceStats); // display
}
/**/
/* OLD
for(int i = 0; i < traces.size(); i++) {
outputDisplayer.DisplayTraceLine(MC.RunMemory(traces[i]));
}
/**/
// Get stats from components
HardwareStats TLBstats = MC.GetDTLBStats();
HardwareStats PTstats = MC.GetPTStats();
HardwareStats DCstats = MC.GetDCStats();
outputDisplayer.FeedPTStats(PTstats);
outputDisplayer.FeedTLBStats(TLBstats);
outputDisplayer.FeedDCStats(DCstats);
outputDisplayer.DisplayComponentStats();
ReferenceStats refStats = MC.GetReferenceCounts();
outputDisplayer.FeedReferenceOutput(refStats);
outputDisplayer.DisplayReferenceStats();
}