Skip to content

Commit 2065150

Browse files
author
Paul Rosenfeld
committed
Initial import for release
0 parents  commit 2065150

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+701882
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
results/

Bank.cpp

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
//Bank.cpp
2+
//
3+
//Class file for bank object
4+
//
5+
6+
#include "Bank.h"
7+
#include "BusPacket.h"
8+
9+
using namespace std;
10+
using namespace DRAMSim;
11+
12+
Bank::Bank():
13+
rowEntries(NUM_COLS)
14+
{}
15+
16+
/* The bank class is just a glorified sparse storage data structure
17+
* that keeps track of written data in case the simulator wants a
18+
* function DRAM model
19+
*
20+
* A vector of size NUM_COLS keeps a linked list of rows and their
21+
* associated values.
22+
*
23+
* write() adds an entry to the proper linked list or replaces the
24+
* value in a row that was already written
25+
*
26+
* read() searches for a node with the right row value, if not found
27+
* returns the tracer value 0xDEADBEEF
28+
*/
29+
30+
31+
32+
Bank::DataStruct *Bank::searchForRow(uint row, DataStruct *head)
33+
{
34+
while(head != NULL)
35+
{
36+
if(head->row == row)
37+
{
38+
//found it
39+
return head;
40+
}
41+
//keep looking
42+
head = head->next;
43+
}
44+
//if we get here, didn't find it
45+
return NULL;
46+
}
47+
48+
void Bank::read(BusPacket &busPacket)
49+
{
50+
DataStruct *rowHeadNode = rowEntries[busPacket.column];
51+
DataStruct *foundNode = NULL;
52+
53+
if ((foundNode = Bank::searchForRow(busPacket.row, rowHeadNode)) == NULL)
54+
{
55+
// the row hasn't been written before, so it isn't in the list
56+
//if(SHOW_SIM_OUTPUT) DEBUG("== Warning - Read from previously unwritten row " << busPacket.row);
57+
void *garbage = calloc(BL * JEDEC_DATA_BUS_WIDTH,1);
58+
((long *)garbage)[0] = 0xdeadbeef; // tracer value
59+
busPacket.data = garbage;
60+
}
61+
else // found it
62+
{
63+
busPacket.data = foundNode->data;
64+
}
65+
66+
//the return packet should be a data packet, not a read packet
67+
busPacket.busPacketType = DATA;
68+
}
69+
70+
71+
void Bank::write(const BusPacket &busPacket)
72+
{
73+
//TODO: move all the error checking to BusPacket so once we have a bus packet,
74+
// we know the fields are all legal
75+
76+
if (busPacket.column >= NUM_COLS)
77+
{
78+
ERROR("== Error - Bus Packet column "<< busPacket.column <<" out of bounds");
79+
exit(-1);
80+
}
81+
82+
// head of the list we need to search
83+
DataStruct *rowHeadNode = rowEntries[busPacket.column];
84+
DataStruct *foundNode = NULL;
85+
86+
if ((foundNode = Bank::searchForRow(busPacket.row, rowHeadNode)) == NULL)
87+
{
88+
//not found
89+
DataStruct *newRowNode = (DataStruct *)malloc(sizeof(DataStruct));
90+
91+
//insert at the head for speed
92+
//TODO: Optimize this data structure for speedier lookups?
93+
newRowNode->row = busPacket.row;
94+
newRowNode->data = busPacket.data;
95+
newRowNode->next = rowHeadNode;
96+
rowEntries[busPacket.column] = newRowNode;
97+
}
98+
else
99+
{
100+
// found it, just plaster in the new data
101+
foundNode->data = busPacket.data;
102+
if (DEBUG_BANKS) {
103+
PRINTN(" -- Bank "<<busPacket.bank<<" writing to physical address 0x" << hex << busPacket.physicalAddress<<dec<<":");
104+
BusPacket::printData(busPacket.data);
105+
PRINT("");
106+
}
107+
}
108+
}
109+

Bank.h

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#ifndef BANK_H
2+
#define BANK_H
3+
4+
//Bank.h
5+
//
6+
//Header file for bank class
7+
//
8+
9+
#include "SystemConfiguration.h"
10+
#include "SimulatorObject.h"
11+
#include "BankState.h"
12+
#include "BusPacket.h"
13+
14+
namespace DRAMSim
15+
{
16+
class Bank
17+
{
18+
typedef struct _DataStruct
19+
{
20+
uint row;
21+
void *data;
22+
struct _DataStruct *next;
23+
} DataStruct;
24+
25+
public:
26+
//functions
27+
Bank();
28+
void read(BusPacket &busPacket);
29+
void write(const BusPacket &busPacket);
30+
31+
//fields
32+
BankState currentState;
33+
34+
private:
35+
// private member
36+
std::vector<DataStruct *> rowEntries;
37+
38+
static DataStruct *searchForRow(uint row, DataStruct *head);
39+
};
40+
}
41+
42+
#endif
43+

BankState.cpp

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//BankState.cpp
2+
//
3+
//Class file for bank state object
4+
//
5+
6+
#include "BankState.h"
7+
8+
using namespace std;
9+
using namespace DRAMSim;
10+
11+
//All banks start precharged
12+
BankState::BankState():
13+
currentBankState(Idle),
14+
openRowAddress(0),
15+
nextRead(0),
16+
nextWrite(0),
17+
nextActivate(0),
18+
nextPrecharge(0),
19+
nextPowerUp(0),
20+
lastCommand(READ),
21+
stateChangeCountdown(0)
22+
{}
23+
24+
void BankState::print()
25+
{
26+
PRINT(" == Bank State ");
27+
if(currentBankState == Idle)
28+
{
29+
PRINT(" State : Idle" );
30+
}
31+
else if(currentBankState == RowActive)
32+
{
33+
PRINT(" State : Active" );
34+
}
35+
else if(currentBankState == Refreshing)
36+
{
37+
PRINT(" State : Refreshing" );
38+
}
39+
else if(currentBankState == PowerDown)
40+
{
41+
PRINT(" State : Power Down" );
42+
}
43+
44+
PRINT(" OpenRowAddress : " << openRowAddress );
45+
PRINT(" nextRead : " << nextRead );
46+
PRINT(" nextWrite : " << nextWrite );
47+
PRINT(" nextActivate : " << nextActivate );
48+
PRINT(" nextPrecharge : " << nextPrecharge );
49+
PRINT(" nextPowerUp : " << nextPowerUp );
50+
}

BankState.h

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#ifndef BANKSTATE_H
2+
#define BANKSTATE_H
3+
4+
//BankState.h
5+
//
6+
//Header file for bank state class
7+
//
8+
9+
#include "SystemConfiguration.h"
10+
#include "BusPacket.h"
11+
12+
namespace DRAMSim
13+
{
14+
enum CurrentBankState
15+
{
16+
Idle,
17+
RowActive,
18+
Precharging,
19+
Refreshing,
20+
PowerDown
21+
};
22+
23+
class BankState
24+
{
25+
public:
26+
//Fields
27+
CurrentBankState currentBankState;
28+
uint openRowAddress;
29+
uint64_t nextRead;
30+
uint64_t nextWrite;
31+
uint64_t nextActivate;
32+
uint64_t nextPrecharge;
33+
uint64_t nextPowerUp;
34+
35+
BusPacketType lastCommand;
36+
uint stateChangeCountdown;
37+
38+
//Functions
39+
BankState();
40+
void print();
41+
};
42+
}
43+
44+
#endif
45+

BusPacket.cpp

+118
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
//BusPacket.cpp
2+
//
3+
//Class file for bus packet object
4+
//
5+
6+
#include "BusPacket.h"
7+
8+
using namespace DRAMSim;
9+
using namespace std;
10+
11+
BusPacket::BusPacket(BusPacketType packtype, uint64_t physicalAddr, uint col, uint rw, uint r, uint b, void *dat)
12+
{
13+
physicalAddress = physicalAddr;
14+
busPacketType = packtype;
15+
data = dat;
16+
rank = r;
17+
bank = b;
18+
column = col;
19+
row = rw;
20+
}
21+
22+
BusPacket::BusPacket() {}
23+
void BusPacket::print(uint64_t currentClockCycle, bool dataStart)
24+
{
25+
if (this == NULL) {
26+
return;
27+
}
28+
29+
if (VERIFICATION_OUTPUT)
30+
{
31+
switch(busPacketType)
32+
{
33+
case READ:
34+
cmd_verify_out << currentClockCycle << ": read ("<<rank<<","<<bank<<","<<column<<",0);"<<endl;
35+
break;
36+
case READ_P:
37+
cmd_verify_out << currentClockCycle << ": read ("<<rank<<","<<bank<<","<<column<<",1);"<<endl;
38+
break;
39+
case WRITE:
40+
cmd_verify_out << currentClockCycle << ": write ("<<rank<<","<<bank<<","<<column<<",0 , 0, 'h0);"<<endl;
41+
break;
42+
case WRITE_P:
43+
cmd_verify_out << currentClockCycle << ": write ("<<rank<<","<<bank<<","<<column<<",1, 0, 'h0);"<<endl;
44+
break;
45+
case ACTIVATE:
46+
cmd_verify_out << currentClockCycle <<": activate (" << rank << "," << bank << "," << row <<");"<<endl;
47+
break;
48+
case PRECHARGE:
49+
cmd_verify_out << currentClockCycle <<": precharge (" << rank << "," << bank << "," << row <<");"<<endl;
50+
break;
51+
case REFRESH:
52+
cmd_verify_out << currentClockCycle <<": refresh (" << rank << ");"<<endl;
53+
break;
54+
case DATA:
55+
//TODO: data verification?
56+
break;
57+
default:
58+
ERROR("Trying to print unknown kind of bus packet");
59+
exit(-1);
60+
}
61+
}
62+
}
63+
void BusPacket::print()
64+
{
65+
if (this == NULL) //pointer use makes this a necessary precaution
66+
{
67+
return;
68+
}
69+
else {
70+
switch(busPacketType)
71+
{
72+
case READ:
73+
PRINT("BP [READ] pa[0x"<<hex<<physicalAddress<<dec<<"] r["<<rank<<"] b["<<bank<<"] row["<<row<<"] col["<<column<<"]");
74+
break;
75+
case READ_P:
76+
PRINT("BP [READ_P] pa[0x"<<hex<<physicalAddress<<dec<<"] r["<<rank<<"] b["<<bank<<"] row["<<row<<"] col["<<column<<"]");
77+
break;
78+
case WRITE:
79+
PRINT("BP [WRITE] pa[0x"<<hex<<physicalAddress<<dec<<"] r["<<rank<<"] b["<<bank<<"] row["<<row<<"] col["<<column<<"]");
80+
break;
81+
case WRITE_P:
82+
PRINT("BP [WRITE_P] pa[0x"<<hex<<physicalAddress<<dec<<"] r["<<rank<<"] b["<<bank<<"] row["<<row<<"] col["<<column<<"]");
83+
break;
84+
case ACTIVATE:
85+
PRINT("BP [ACT] pa[0x"<<hex<<physicalAddress<<dec<<"] r["<<rank<<"] b["<<bank<<"] row["<<row<<"] col["<<column<<"]");
86+
break;
87+
case PRECHARGE:
88+
PRINT("BP [PRE] pa[0x"<<hex<<physicalAddress<<dec<<"] r["<<rank<<"] b["<<bank<<"] row["<<row<<"] col["<<column<<"]");
89+
break;
90+
case REFRESH:
91+
PRINT("BP [REF] pa[0x"<<hex<<physicalAddress<<dec<<"] r["<<rank<<"] b["<<bank<<"] row["<<row<<"] col["<<column<<"]");
92+
break;
93+
case DATA:
94+
PRINTN("BP [DATA] pa[0x"<<hex<<physicalAddress<<dec<<"] r["<<rank<<"] b["<<bank<<"] row["<<row<<"] col["<<column<<"] data["<<data<<"]=");
95+
BusPacket::printData(data);
96+
PRINT("");
97+
break;
98+
default:
99+
ERROR("Trying to print unknown kind of bus packet");
100+
exit(-1);
101+
}
102+
}
103+
}
104+
105+
void BusPacket::printData(const void *data)
106+
{
107+
if (data == NULL)
108+
{
109+
PRINTN("NO DATA");
110+
return;
111+
}
112+
PRINTN("'" << hex);
113+
for (int i=0; i < 4; i++)
114+
{
115+
PRINTN(((uint64_t *)data)[i]);
116+
}
117+
PRINTN("'" << dec);
118+
}

0 commit comments

Comments
 (0)