forked from tactcomplabs/HBM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IniReader.cpp
426 lines (381 loc) · 13.6 KB
/
IniReader.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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/*********************************************************************************
* Copyright (c) 2010-2011, Elliott Cooper-Balis
* Paul Rosenfeld
* Bruce Jacob
* University of Maryland
* dramninjas [at] gmail [dot] com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*********************************************************************************/
#include "IniReader.h"
using namespace std;
namespace HBMDRAMSim
{
// these are the values that are extern'd in SystemConfig.h so that they
// have global scope even though they are set by IniReader
unsigned NUM_BANKGROUPS;
unsigned NUM_BANKS;
unsigned NUM_BANKS_LOG;
unsigned NUM_CHANS;
unsigned NUM_CHANS_LOG;
unsigned NUM_ROWS;
unsigned NUM_ROWS_LOG;
unsigned NUM_COLS;
unsigned NUM_COLS_LOG;
unsigned PREFETCH_SIZE;
unsigned PAGE_SIZE;
unsigned BYTE_OFFSET_WIDTH;
unsigned TRANSACTION_SIZE;
unsigned REFRESH_PERIOD;
float tCK;
unsigned CL;
unsigned AL;
unsigned BL;
unsigned tRAS;
unsigned tRCD;
unsigned tRRDS;
unsigned tRRDL;
unsigned tRC;
unsigned tRP;
unsigned tCCDS;
unsigned tCCDL;
unsigned tRTP;
unsigned tWTRS;
unsigned tWTRL;
unsigned tWR;
unsigned tRTRS;
unsigned tRFC;
unsigned tFAW;
unsigned tCKE;
unsigned tXP;
unsigned tCMD;
//in bytes
unsigned JEDEC_DATA_BUS_BITS;
//Memory Controller related parameters
unsigned TRANS_QUEUE_DEPTH;
unsigned CMD_QUEUE_DEPTH;
//cycles within an epoch
unsigned EPOCH_LENGTH;
//row accesses allowed before closing (open page)
unsigned TOTAL_ROW_ACCESSES;
// strings and their associated enums
string ROW_BUFFER_POLICY;
string SCHEDULING_POLICY;
string ADDRESS_MAPPING_SCHEME;
string OPERATION_MODE;
bool BANK_GROUPS_ENABLED;
bool DEBUG_TRANS_Q;
bool DEBUG_CMD_Q;
bool DEBUG_ADDR_MAP;
bool DEBUG_BANKSTATE;
bool DEBUG_BUS;
bool DEBUG_BANKS;
bool DEBUG_POWER;
bool DEBUG_INI_READER=false;
RowBufferPolicy rowBufferPolicy;
SchedulingPolicy schedulingPolicy;
AddressMappingScheme addressMappingScheme;
OperationMode operationMode;
//Map the string names to the variables they set
static ConfigMap configMap[] =
{
//DEFINE_UINT_PARAM -- see IniReader.h
DEFINE_UINT_PARAM(NUM_BANKGROUPS,DEV_PARAM),
DEFINE_UINT_PARAM(NUM_BANKS,DEV_PARAM),
DEFINE_UINT_PARAM(NUM_ROWS,DEV_PARAM),
DEFINE_UINT_PARAM(NUM_COLS,DEV_PARAM),
DEFINE_UINT_PARAM(PREFETCH_SIZE,DEV_PARAM),
DEFINE_UINT_PARAM(PAGE_SIZE,DEV_PARAM),
DEFINE_UINT_PARAM(REFRESH_PERIOD,DEV_PARAM),
DEFINE_FLOAT_PARAM(tCK,DEV_PARAM),
DEFINE_UINT_PARAM(CL,DEV_PARAM),
DEFINE_UINT_PARAM(AL,DEV_PARAM),
DEFINE_UINT_PARAM(BL,DEV_PARAM),
DEFINE_UINT_PARAM(tRAS,DEV_PARAM),
DEFINE_UINT_PARAM(tRCD,DEV_PARAM),
DEFINE_UINT_PARAM(tRRDS,DEV_PARAM),
DEFINE_UINT_PARAM(tRRDL,DEV_PARAM),
DEFINE_UINT_PARAM(tRC,DEV_PARAM),
DEFINE_UINT_PARAM(tRP,DEV_PARAM),
DEFINE_UINT_PARAM(tCCDS,DEV_PARAM),
DEFINE_UINT_PARAM(tCCDL,DEV_PARAM),
DEFINE_UINT_PARAM(tRTP,DEV_PARAM),
DEFINE_UINT_PARAM(tWTRS,DEV_PARAM),
DEFINE_UINT_PARAM(tWTRL,DEV_PARAM),
DEFINE_UINT_PARAM(tWR,DEV_PARAM),
DEFINE_UINT_PARAM(tRTRS,DEV_PARAM),
DEFINE_UINT_PARAM(tRFC,DEV_PARAM),
DEFINE_UINT_PARAM(tFAW,DEV_PARAM),
DEFINE_UINT_PARAM(tCKE,DEV_PARAM),
DEFINE_UINT_PARAM(tXP,DEV_PARAM),
DEFINE_UINT_PARAM(tCMD,DEV_PARAM),
DEFINE_UINT_PARAM(NUM_CHANS,SYS_PARAM),
DEFINE_UINT_PARAM(JEDEC_DATA_BUS_BITS,SYS_PARAM),
//Memory Controller related parameters
DEFINE_UINT_PARAM(TRANS_QUEUE_DEPTH,SYS_PARAM),
DEFINE_UINT_PARAM(CMD_QUEUE_DEPTH,SYS_PARAM),
DEFINE_UINT_PARAM(EPOCH_LENGTH,SYS_PARAM),
DEFINE_UINT_PARAM(TOTAL_ROW_ACCESSES,SYS_PARAM),
DEFINE_STRING_PARAM(ROW_BUFFER_POLICY,SYS_PARAM),
DEFINE_STRING_PARAM(SCHEDULING_POLICY,SYS_PARAM),
DEFINE_STRING_PARAM(ADDRESS_MAPPING_SCHEME,SYS_PARAM),
DEFINE_STRING_PARAM(OPERATION_MODE,SYS_PARAM),
DEFINE_BOOL_PARAM(BANK_GROUPS_ENABLED,SYS_PARAM),
// debug flags
DEFINE_BOOL_PARAM(DEBUG_TRANS_Q,SYS_PARAM),
DEFINE_BOOL_PARAM(DEBUG_CMD_Q,SYS_PARAM),
DEFINE_BOOL_PARAM(DEBUG_ADDR_MAP,SYS_PARAM),
DEFINE_BOOL_PARAM(DEBUG_BANKSTATE,SYS_PARAM),
DEFINE_BOOL_PARAM(DEBUG_BUS,SYS_PARAM),
DEFINE_BOOL_PARAM(DEBUG_BANKS,SYS_PARAM),
DEFINE_BOOL_PARAM(DEBUG_POWER,SYS_PARAM),
{"", NULL, UINT, SYS_PARAM, false} // tracer value to signify end of list; if you delete it, epic fail will result
};
void IniReader::SetKey(string key, string valueString, bool isSystemParam, size_t lineNumber)
{
size_t i;
unsigned intValue;
uint64_t int64Value;
float floatValue;
for (i=0; configMap[i].variablePtr != NULL; i++)
{
istringstream iss(valueString);
// match up the string in the config map with the key we parsed
if (key.compare(configMap[i].iniKey) == 0)
{
switch (configMap[i].variableType)
{
//parse and set each type of variable
case UINT:
if ((iss >> dec >> intValue).fail())
{
ERROR("could not parse line "<<lineNumber<<" (non-numeric value '"<<valueString<<"')?");
}
*((unsigned *)configMap[i].variablePtr) = intValue;
if (DEBUG_INI_READER)
{
DEBUG("\t - SETTING "<<configMap[i].iniKey<<"="<<intValue);
}
break;
case UINT64:
if ((iss >> dec >> int64Value).fail())
{
ERROR("could not parse line "<<lineNumber<<" (non-numeric value '"<<valueString<<"')?");
}
*((uint64_t *)configMap[i].variablePtr) = int64Value;
if (DEBUG_INI_READER)
{
DEBUG("\t - SETTING "<<configMap[i].iniKey<<"="<<int64Value);
}
break;
case FLOAT:
if ((iss >> dec >> floatValue).fail())
{
ERROR("could not parse line "<<lineNumber<<" (non-numeric value '"<<valueString<<"')?");
}
*((float *)configMap[i].variablePtr) = floatValue;
if (DEBUG_INI_READER)
{
DEBUG("\t - SETTING "<<configMap[i].iniKey<<"="<<floatValue);
}
break;
case STRING:
*((string *)configMap[i].variablePtr) = string(valueString);
if (DEBUG_INI_READER)
{
DEBUG("\t - SETTING "<<configMap[i].iniKey<<"="<<valueString);
}
break;
case BOOL:
if (valueString == "true" || valueString == "1")
{
*((bool *)configMap[i].variablePtr) = true;
}
else
{
*((bool *)configMap[i].variablePtr) = false;
}
}
// lineNumber == 0 implies that this is an override parameter from the command line, so don't bother doing these checks
if (lineNumber > 0)
{
if (isSystemParam && configMap[i].parameterType == DEV_PARAM)
{
DEBUG("WARNING: Found device parameter "<<configMap[i].iniKey<<" in system config file");
}
else if (!isSystemParam && configMap[i].parameterType == SYS_PARAM)
{
DEBUG("WARNING: Found system parameter "<<configMap[i].iniKey<<" in device config file");
}
}
// use the pointer stored in the config map to set the value of the variable
// to make sure all parameters are in the ini file
configMap[i].wasSet = true;
break;
}
}
if (configMap[i].variablePtr == NULL)
{
DEBUG("WARNING: UNKNOWN KEY '"<<key<<"' IN INI FILE");
}
}
void IniReader::ReadIniFile(string filename, bool isSystemFile)
{
ifstream iniFile;
string line;
string key,valueString;
size_t commentIndex, equalsIndex;
size_t lineNumber=0;
iniFile.open(filename.c_str());
if (iniFile.is_open()) {
while (!iniFile.eof()) {
lineNumber++;
getline(iniFile, line);
//this can happen if the filename is actually a directory
if (iniFile.bad()) {
ERROR("Cannot read ini file '"<<filename<<"'");
exit(-1);
}
// skip zero-length lines
if (line.size() == 0) {
// DEBUG("Skipping blank line "<<lineNumber);
continue;
}
//search for a comment char
if ((commentIndex = line.find_first_of(";")) != string::npos) {
//if the comment char is the first char, ignore the whole line
if (commentIndex == 0) {
//DEBUG("Skipping comment line "<<lineNumber);
continue;
}
//DEBUG("Truncating line at comment"<<line[commentIndex-1]);
//truncate the line at first comment before going on
line = line.substr(0,commentIndex);
}
// trim off the end spaces that might have been between the value and comment char
size_t whiteSpaceEndIndex;
if ((whiteSpaceEndIndex = line.find_last_not_of(" \t")) != string::npos) {
line = line.substr(0,whiteSpaceEndIndex+1);
}
// at this point line should be a valid, commentless string
// a line has to have an equals sign
if ((equalsIndex = line.find_first_of("=")) == string::npos) {
ERROR("Malformed Line "<<lineNumber<<" (missing equals)");
abort();
}
size_t strlen = line.size();
// all characters before the equals are the key
key = line.substr(0, equalsIndex);
// all characters after the equals are the value
valueString = line.substr(equalsIndex+1,strlen-equalsIndex);
IniReader::SetKey(key, valueString, isSystemFile, lineNumber);
// got to the end of the config map without finding the key
}
} else {
ERROR ("Unable to load ini file "<<filename);
abort();
}
/* precompute frequently used values */
NUM_BANKS_LOG = log2(NUM_BANKS);
NUM_CHANS_LOG = log2(NUM_CHANS);
NUM_ROWS_LOG = log2(NUM_ROWS);
NUM_COLS_LOG = log2(NUM_COLS);
// after system.ini is read
if (JEDEC_DATA_BUS_BITS > 0) {
BYTE_OFFSET_WIDTH = log2(PAGE_SIZE / NUM_COLS);
// DEPRECATED: TRANSACTION_SIZE = JEDEC_DATA_BUS_BITS / 8 * BL;
// TRANSACTION_SIZE SHOULD BE 128 bits (CHANNEL WIDTH)
// EXCEPT WHEN IN HBM2 (pseudo_channel_mode) WHERE IT IS
// 64 bits
TRANSACTION_SIZE = 128;
if (OPERATION_MODE == "pseudo_channel_mode")
TRANSACTION_SIZE /= 2;
}
}
bool IniReader::CheckIfAllSet()
{
// check to make sure all parameters that we exepected were set
for (size_t i = 0; configMap[i].variablePtr != NULL; ++i) {
if (!configMap[i].wasSet) {
DEBUG("WARNING: KEY " << configMap[i].iniKey << " NOT FOUND IN INI FILE.");
switch (configMap[i].variableType) {
//the string and bool values can be defaulted, but generally we need all the numeric values
//to be set to continue
case UINT:
case UINT64:
case FLOAT:
ERROR("Cannot continue without key '"<<configMap[i].iniKey<<"' set.");
return false;
break;
case BOOL:
*((bool *)configMap[i].variablePtr) = false;
DEBUG("\tSetting Default: "<<configMap[i].iniKey<<"=false");
break;
case STRING:
break;
}
}
}
return true;
}
void IniReader::InitEnumsFromStrings()
{
if (ADDRESS_MAPPING_SCHEME == "ChRaBaRoCo")
addressMappingScheme = ChRaBaRoCo;
else if (ADDRESS_MAPPING_SCHEME == "RoBaRaCoCh")
addressMappingScheme = RoBaRaCoCh;
else {
cout << "WARNING: unknown address mapping scheme '" << ADDRESS_MAPPING_SCHEME << "'; valid "
"values are 'ChRaBaRoCo' or 'RoBaRaCoCh', defaulting to RoBaRaCoCh" << endl;
addressMappingScheme = RoBaRaCoCh;
}
if (ROW_BUFFER_POLICY == "open_page")
rowBufferPolicy = OpenPage;
else if (ROW_BUFFER_POLICY == "close_page")
rowBufferPolicy = ClosePage;
else {
cout << "WARNING: unknown row buffer policy '" << ROW_BUFFER_POLICY << "'; valid values are "
"'open_page' or 'close_page', defaulting to Close Page." << endl;
rowBufferPolicy = ClosePage;
}
if (SCHEDULING_POLICY == "rank_then_bank_round_robin")
schedulingPolicy = RankThenBankRoundRobin;
else if (SCHEDULING_POLICY == "bank_then_rank_round_robin")
schedulingPolicy = BankThenRankRoundRobin;
else {
cout << "WARNING: Unknown scheduling policy '" << SCHEDULING_POLICY << "'; valid options are "
"'rank_then_bank_round_robin' or 'bank_then_rank_round_robin', defaulting to Bank Then Rank "
"Round Robin" << endl;
schedulingPolicy = BankThenRankRoundRobin;
}
if (OPERATION_MODE == "legacy_mode")
operationMode = LegacyMode;
else if (OPERATION_MODE == "pseudo_channel_mode")
operationMode = PseudoChannelMode;
else {
cout << "WARNING: unknown operation mode '" << OPERATION_MODE << "'; valid values are "
"'legacy_mode' or 'pseudo_channel_mode', defaulting to Legacy Mode." << endl;
operationMode = LegacyMode;
}
}
} // namespace HBMDRAMSim