Repository navigation
Expand file tree
/
Copy pathMain.cpp
More file actions
191 lines (156 loc) · 5.53 KB
/
Copy pathMain.cpp
File metadata and controls
191 lines (156 loc) · 5.53 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
LRU Cache Simulator
3/4/19
Developers: Bruno E. Gracia Villalobos
Ryan Walker
*/
#include <iostream>
#include <stdint.h>
#include <vector> //array of cache sets
#include <list> //for the cache sets
#include <iterator> //iterating through lists
#include <algorithm> //for find function
#include <unordered_map>
#include <utility>
#include "Cache.h"
using namespace G;
using namespace std;
//Returns a 4 byte vector with the lowest index at the MSB
/*vector<unsigned char> memBytes(unsigned int a)
{
int size = sizeof(a);
vector<unsigned char> address(sizeof(a));
unsigned char temp;
unsigned int tempint;
unsigned char built;
//To print an unsigned char in hex:
//cout << (unsigned int)*memarray << endl;
for(int i = 0; i < size; i++)
{
temp = (a>>(i*8)) & 0xFF;
address.at(3-i) = temp;
cout << "TEMP:" << temp << hex << endl;
// cout << sizeof(address.at(i)) << endl;
// cout << sizeof((a>>(i*8)) & 0xFF) << endl;
cout << hex << ((a>>(i*8)) & 0xFF) << endl;
// cout << "SIZE:" << address.size() << endl;
}
return address;
}
//Returns a char* array of bytes given an int
unsigned char* bytes(unsigned int &a)
{
unsigned char* ret = (unsigned char*)malloc(sizeof(a));
memcpy(ret, (unsigned char*)&a, sizeof(a));
return ret;
}*/
/*Reads in cache config file*/
void readCacheConfig(int& cacheSize, int& blockSize, int& associativity) {
/*VARIABLE DECLARATIONS*/
ifstream file;
string line;
size_t found;
string file_name;
/*FLUSH COUT*/
cout << flush;
cout.flush();
cout << dec;
cout<<"Enter name of the file for cache parameters: ";
cin>>file_name;
/*Begin configuration file read*/
// file.open("example.cfg", ios::in);
file.open(file_name+".cfg", ios::in);
if (file.is_open())
{
/*READ FIRST CONFIG LINE - CACHE SIZE */
getline(file,line);
found = line.find("=");
cacheSize = stoi(line.substr(found+1, line.length()),nullptr,0);
/*READ SECOND CONFIG LINE - BLOCK SIZE */
getline(file, line);
found = line.find("=");
blockSize = stoi(line.substr(found+1, line.length()),nullptr,0);
/*READ Third Config Line - ASSOCIATIVITY*/
getline(file, line);
found = line.find("=");
associativity = stoi(line.substr(found+1, line.length()),nullptr,0);
}
file.close();
}
/*Sinashan: Reads in IO config file*/
void readConfig(int& nodes, vector<int>& VMs, string& cachingMode, string& SMC, string& resDistrib, string& migScheme, int& steps, int& reqSteps) {
/*VARIABLE DECLARATIONS*/
ifstream file;
string file_name, line;
int vm; //Sinashan: To keep number of VMs at each line
/*FLUSH COUT*/
cout << flush;
cout.flush();
cout << dec;
cout<<"Enter name of the file for the HCI parameters: ";
cin>>file_name;
/*Begin configuration file read*/
// file.open("example.cfg", ios::in);
file.open(file_name+".cfg", ios::in);
if (file.is_open())
{
file >> line;
file >> nodes >> line;
for(int i=0;i<nodes;i++)
{
file >> vm;
VMs.push_back(vm);
}
file >> line >> cachingMode;
file >> line >> SMC;
file >> line >> resDistrib;
file >> line >> migScheme;
file >> line >> steps;
file >> line >> reqSteps;
/*Sinashan: Print out the config information on the screen*/
cout << "Number of Nodes: " << nodes << endl;
for(int i=0;i<VMs.size();i++)
cout << "Node " << i+1 << " has " << VMs[i] << " virtual machines." << endl;
cout << "Caching mode is set to " << cachingMode << endl;
cout << "Split Mirrored Cache (SMC) is " << SMC << endl;
if(resDistrib == "Traffic") cout << "Resources will be distributed in a way to minimize network traffic." << endl;
else if(resDistrib == "Load") cout << "Resources will be distributed in a way to balance load." << endl;
if(migScheme == "Gradual") cout << "Migration scheme is gradual." << endl;
else if(migScheme == "Instant") cout << "Migration scheme is instant." << endl;
cout << "Cache metrics checked after every " << reqSteps << " requests, in a total of " << steps << " steps." << endl;
}
file.close();
}
/*Sinashan: Assigning initial cache values to each VM*/
void initializeCache(vector<int>& m_VMs, vector<vector<int> >& m_vmCacheSize, int cSize, int bSize, int assoc){
int numBlocks, temp, i, j, sum;
for(i=0;i<m_VMs.size();i++){
numBlocks = cSize / bSize;
temp = numBlocks / m_VMs[i];
sum = 0;
for(j=0;j<m_VMs[i];j++){
}
}
}
int main(int argc, char** argv)
{
int cacheSize,blockSize,associativiy; //Sinashan: Just changed names for clarity!
int nodes, steps,reqSteps;
string cachingMode, SMC, resDistrib, migScheme; //Sinashan: HCIConfig file
vector<int> VMs; //Sinashan: VMs per node
vector<vector<int> > vmCacheSize; //Sinashan: A vector to store cache sizes for each VM
readConfig(nodes,VMs,cachingMode,SMC,resDistrib,migScheme,steps,reqSteps); //Sinashan: Read in HCI config file
readCacheConfig(cacheSize,blockSize,associativiy); //Sinashan: Read in cache configuration values from file
initializeCache(VMs,vmCacheSize,cacheSize,blockSize,associativiy);
for(int i=0;i<vmCacheSize.size();i++){
for(int j=0;j<vmCacheSize[i].size();j++){
cout << vmCacheSize[i][j] << endl;
}
cout << endl;
}
/*Instantiate cache class with config file params*/
Cache cache2(cacheSize,blockSize,associativiy);
cache2.readMemory(); //Sinashan: Workload's name
cache2.testMem();
return 0;
}