-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSCIC.h
197 lines (163 loc) · 5.92 KB
/
SCIC.h
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
/****************************************************************************
* SCIC: A System C Interface Converter for DRAMSim
*
* Copyright (C) 2011 Myoungsoo Jung
* Pennsylvania State University
* David Donofrio
* John Shalf
* Lawrence Berkeley National Lab.
*
*
* This program 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.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
*
*****************************************************************************/
#ifndef _SCIC_h__
#define _SCIC_h__
#include "MemorySystem.h"
#include <systemc.h>
#ifndef NULL_SIG64
#define NULL_SIG64 ((1 << 64) -1)
#endif
#ifdef USE_DEBUG_SYSTEMC
#define SCIC_PRINT(str) std::cout << str << std::endl
#else
#define SCIC_PRINT(str)
#endif
#define USE_CALIBRATION_1CYCLE (1)
#if (USE_SCIC_MEMSYS_QUERY == 1)
typedef enum {
SCIC_ENERGY_BACKGROUND,
SCIC_ENERGY_BURST,
SCIC_ENERGY_PRECHARGE,
SCIC_ENERGY_REFRESH,
SCIC_NUMS_ENERGY_TYPE,
SCIC_ENERGY_AVERAGE
} SCIC_ENERGY_QUERY;
typedef enum {
SCIC_PERF_LATENCY,
SCIC_PERF_BANDWIDTH,
SCIC_NUMS_PERF_TYPE
} SCIC_PERF_QUERY;
typedef enum {
SCIC_STAT_READ,
SCIC_STAT_WRITE
} SCIC_STAT_QUERY;
#ifndef SEQUENTIAL
#define SEQUENTIAL(rank,bank) (rank*NUM_BANKS)+bank
#endif
#endif
SC_MODULE(SCIC)
{
class ScoreBoardElement {
uint64_t *_pAllocatedMem;
bool _bWrite;
unsigned int _nRefCnts;
public:
uint64_t* AllocatedMem() const { return _pAllocatedMem; }
bool WasWrite() const { return _bWrite; }
void Free() {delete _pAllocatedMem;};
unsigned int RefCnts() const { return _nRefCnts; }
void RefCnts(unsigned int val) { _nRefCnts = val; }
void IncRefCnt() {_nRefCnts++;};
void DecRefCnt() {_nRefCnts--;};
ScoreBoardElement(uint64_t *pAllocatedMem, bool bWrite) {_pAllocatedMem = pAllocatedMem; bWrite; _nRefCnts = 1;};
};
/************************************************************************/
/* system C primitive */
/************************************************************************/
sc_in<bool> _prtWE;
sc_in<uint64_t> _prtDA;
//sc_in<bool> _prtCLK;
sc_port <sc_signal_in_if<bool> > _prtCLK;
sc_in<bool> _prtDE;
sc_out<uint64_t> _prtAO;
sc_out<bool> _prtWO;
sc_out<bool> _prtCA;
sc_out<uint64_t> _prtReqTransID;
sc_out<uint64_t> _prtRespTransID;
//
// RB will be high when the queue in legacy memory does not have any available room.
//
sc_out<bool> _prtRB;
//
// Data I/O port
//
sc_out<uint64_t> _prtDOUT[4];
sc_in<uint64_t> _prtDIN[4];
sc_event* m_ptrCompAckEvent;
/************************************************************************/
/* internal states */
/************************************************************************/
MemorySystem *_pLegacyMemorySystem;
uint64_t _nCurrentClk;
bool _bUserDataHandlingFault;
bool _bInitialTime;
#if (USE_SCIC_MEMSYS_QUERY == 1)
vector<uint64_t>* _vctpEnergy[SCIC_NUMS_ENERGY_TYPE];
vector<uint64_t> _vctRtLatencyReport;
//
// For measuring real-time performance
// this tracker check interval time between request begins and completes for each memory transaction.
//
uint64_t _nCycleTracker;
#endif
//
// For minimizing modification of DRAMSim, this member filed explicitly helps to manage memory resource.
// The key of scoreboard is destination address
//
typedef multimap<uint64_t, ScoreBoardElement> ScoreBoard;
ScoreBoard _scoreBoard;
/************************************************************************/
/* private member
Even though users don't need to care about these functions starting
from small letter (private member), For compatibility to SystemC kernel
, I do not use private keyword here*/
/************************************************************************/
void runSystem();
uint64_t* getDataFromPort();
void setDataOutPort(uint64_t key);
void resetDataOut() {setDataOutPort(NULL_SIG64);}
void freeMemoryElement(uint64_t key, bool bWrite);
void alignTransactionAddress(Transaction &trans);
void initializeInterface();
void readComplete(uint nSystemId, uint64_t nTargatAddr, uint64_t nClockCycle, uint64_t nTransID);
void writeComplete(uint nSystemId, uint64_t nTargatAddr, uint64_t nClockCycle, uint64_t nTransID);
/************************************************************************/
/* public */
/************************************************************************/
void AttachLegacyMemorySystem(MemorySystem *pMemorySystem); // methods for compatibility with DRAMSim and a CPU model
void Reset();
#if (USE_SCIC_MEMSYS_QUERY == 1)
uint64_t GetLatencyandMarkTimepoint(vector<uint64_t> &perfInfo);
uint64_t GetNumsElapsedIo(vector<uint64_t> &perfInfo, SCIC_STAT_QUERY queryType);
double GetElapsedPerfromanceInfo(vector<double> &perfInfo, SCIC_PERF_QUERY queryType);
double GetElapsedEnergyInfo(vector<double> &energyInfos, SCIC_ENERGY_QUERY queryType);
uint64_t GetTotalNumsTransactions();
uint GetBytePerTransaction();
//
// callback, this is not exported to public
//
void measureIndividualLatency(uint nLatency, uint nRank, uint nBank);
#endif
SC_CTOR(SCIC)
{
initializeInterface();
SC_THREAD(runSystem);
//
// double data rate
//
sensitive << _prtCLK;
}
};
#endif // _SCIC_h__