forked from tactcomplabs/HBM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MemorySystem.cpp
170 lines (141 loc) · 5.31 KB
/
MemorySystem.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
/*********************************************************************************
* 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 "MemorySystem.h"
#include "IniReader.h"
#include <unistd.h>
using namespace std;
namespace HBMDRAMSim {
unsigned NUM_RANKS;
unsigned NUM_RANKS_LOG;
unsigned NUM_BANKS_PER_BANKGROUP;
MemorySystem::MemorySystem(unsigned sid, unsigned cid) :
ReturnReadData(NULL),
WriteDataDone(NULL),
stackID(sid),
channelID(cid)
{
currentClockCycle = 0;
DEBUG("====== Stack " << stackID << " - Channel" << channelID << " ======");
/*
* In legacy mode, each read or write transaction transfers 256 bits in a burst that consists of 2
* cycles of 128 bits each.
* In pseudo-channel mode, the 128-bit bus is split into 2 individual 64-bit segments. On each
* segment, a read or write transaction transfers 256 bits as well, but in a burst that lasts 4
* cycles (of 64 bits each).
*
* The pseudo channel concept essentially divides the memory of a single channel in half and
* assigns each half to a fixed pseudo channel.
*
* Note that pseudo channel share the same address and command bus: you can send a command and
* adresses to one pseudo channel or the other, but not to both.
*/
if (operationMode == LegacyMode) {
// One rank with 128-bits bus width and burst length of 2.
NUM_RANKS = 1;
} else { // operationMode == PseudoChannelMode
// Each rank is regarded as a pseudo channel in PseudoChannelMode.
// Two ranks, each with 64-bits bus width and burst length of 4.
NUM_RANKS = 2;
}
NUM_RANKS_LOG = log2(NUM_RANKS);
NUM_BANKS_PER_BANKGROUP = NUM_BANKS / NUM_BANKGROUPS;
memoryController = new MemoryController(stackID, channelID, this);
ranks = new vector<Rank *>();
for (unsigned i = 0; i < NUM_RANKS; ++i) {
Rank *r = new Rank();
r->setId(i);
r->attachMemoryController(memoryController);
ranks->push_back(r);
}
memoryController->attachRanks(ranks);
}
MemorySystem::~MemorySystem()
{
delete memoryController;
for (unsigned i = 0; i < NUM_RANKS; ++i)
delete (*ranks)[i];
delete ranks;
}
bool MemorySystem::WillAcceptTransaction()
{
return memoryController->WillAcceptTransaction();
}
bool MemorySystem::addTransaction(bool isWrite, uint64_t addr)
{
TransactionType type = isWrite ? DATA_WRITE : DATA_READ;
Transaction *trans = new Transaction(type, addr, NULL);
if (memoryController->WillAcceptTransaction()) {
return memoryController->addTransaction(trans);
} else {
pendingTransactions.push_back(trans);
return true;
}
}
bool MemorySystem::getStats( double *stat, DSIM_STAT metric ){
return memoryController->getStats(stat, metric);
}
bool MemorySystem::getStats( uint64_t *stat, DSIM_STAT metric ){
return memoryController->getStats(stat, metric);
}
void MemorySystem::printStats(bool finalStats)
{
memoryController->printStats(finalStats);
}
//update the memory systems state
void MemorySystem::update()
{
for (unsigned i = 0; i < NUM_RANKS; ++i)
(*ranks)[i]->update();
if (pendingTransactions.size() > 0 && memoryController->WillAcceptTransaction()) {
memoryController->addTransaction(pendingTransactions.front());
pendingTransactions.pop_front();
}
memoryController->update();
for (unsigned i = 0; i < NUM_RANKS; ++i)
(*ranks)[i]->step();
memoryController->step();
this->step();
}
void MemorySystem::RegisterCallbacks(Callback_t* readCB, Callback_t* writeCB)
{
ReturnReadData = readCB;
WriteDataDone = writeCB;
}
} /*namespace HBMDRAMSim */
// This function can be used by autoconf AC_CHECK_LIB since
// apparently it can't detect C++ functions.
// Basically just an entry in the symbol table
extern "C"
{
void libhbmdramsim_is_present(void)
{
;
}
}