-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrgen.cc
89 lines (80 loc) · 2.33 KB
/
rgen.cc
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
/**
* Copyright (C) 2017 CAMELab
*
* This file is part of SimpleSSD.
*
* SimpleSSD is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* SimpleSSD is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with SimpleSSD. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Jie Zhang <[email protected]>
* Miryoung Kwon <[email protected]>
* Donghyun Gouk <[email protected]>
*/
#include "rgen.hh"
RequestGenerator::RequestGenerator(Config &cfg) {
cur_page = cfg.MaxRequest;
MAX_REQ = cfg.MaxRequest;
cur_REQ = 0;
start_PPN = cfg.StartPPN;
REQ_SIZE = cfg.RequestSize;
curRequest.PPN = 0;
curRequest.REQ_SIZE = 0;
curRequest.Oper = OPER_READ;
curRequest.IOGEN = 0;
readratio.fraction = cfg.ReadFraction;
readratio.denominator = cfg.ReadDenominator;
randomratio.fraction = cfg.RandomFraction;
randomratio.denominator = cfg.RandomDenominator;
srand(cfg.RandomSeed);
IOGEN = cfg.IOGEN;
if (cfg.Enable) {
fn = cfg.TraceFile;
tr = new TraceReader(fn);
}
else {
tr = nullptr;
}
}
RequestGenerator::~RequestGenerator() {
if (tr) {
delete tr;
}
}
bool RequestGenerator::generate_request(){
if (!tr) {
if (cur_REQ >= MAX_REQ) {
return false;
}
if (cur_REQ % randomratio.denominator < randomratio.fraction) { //random access
int cmd = rand() % 100; //for testing
curRequest.PPN = (uint64_t)((uint64_t)(rand() % (MAX_REQ * REQ_SIZE / 2)) * (uint64_t)8192);
}
else {
curRequest.PPN = start_PPN; //8192 is default page size
start_PPN += 4096*REQ_SIZE;
}
if (cur_REQ % readratio.denominator < readratio.fraction) {
curRequest.Oper = OPER_READ;
}
else {
curRequest.Oper = OPER_WRITE;
}
curRequest.REQ_SIZE = REQ_SIZE;
curRequest.IOGEN = IOGEN;
cur_REQ++;
}
else {
return tr->ReadIO(curRequest.PPN, curRequest.Oper, curRequest.REQ_SIZE);
}
return true;
}