cpu: Share the send functionality between traffic generators
This patch moves the packet creating and sending to a member function in the shared base class to avoid code duplication.
This commit is contained in:
parent
1da209140c
commit
ccb6c64047
|
@ -352,6 +352,27 @@ TrafficGen::StateGraph::BaseGen::BaseGen(QueuedMasterPort& _port,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
TrafficGen::StateGraph::BaseGen::send(Addr addr, unsigned size,
|
||||||
|
const MemCmd& cmd)
|
||||||
|
{
|
||||||
|
// Create new request
|
||||||
|
Request::Flags flags;
|
||||||
|
Request *req = new Request(addr, size, flags, masterID);
|
||||||
|
|
||||||
|
// Embed it in a packet
|
||||||
|
PacketPtr pkt = new Packet(req, cmd);
|
||||||
|
|
||||||
|
uint8_t* pkt_data = new uint8_t[req->getSize()];
|
||||||
|
pkt->dataDynamicArray(pkt_data);
|
||||||
|
|
||||||
|
if (cmd.isWrite()) {
|
||||||
|
memset(pkt_data, 0xA, req->getSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
port.schedTimingReq(pkt, curTick());
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
TrafficGen::StateGraph::LinearGen::enter()
|
TrafficGen::StateGraph::LinearGen::enter()
|
||||||
{
|
{
|
||||||
|
@ -380,21 +401,7 @@ TrafficGen::StateGraph::LinearGen::execute()
|
||||||
DPRINTF(TrafficGen, "LinearGen::execute: %c to addr %x, size %d\n",
|
DPRINTF(TrafficGen, "LinearGen::execute: %c to addr %x, size %d\n",
|
||||||
isRead ? 'r' : 'w', nextAddr, blocksize);
|
isRead ? 'r' : 'w', nextAddr, blocksize);
|
||||||
|
|
||||||
// Create new request
|
send(nextAddr, blocksize, isRead ? MemCmd::ReadReq : MemCmd::WriteReq);
|
||||||
Request::Flags flags;
|
|
||||||
Request *req = new Request(nextAddr, blocksize, flags, masterID);
|
|
||||||
|
|
||||||
PacketPtr pkt = new Packet(req, isRead ? MemCmd::ReadReq :
|
|
||||||
MemCmd::WriteReq);
|
|
||||||
|
|
||||||
uint8_t* pkt_data = new uint8_t[req->getSize()];
|
|
||||||
pkt->dataDynamicArray(pkt_data);
|
|
||||||
|
|
||||||
if (!isRead) {
|
|
||||||
memset(pkt_data, 0xA, req->getSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
port.schedTimingReq(pkt, curTick());
|
|
||||||
|
|
||||||
// increment the address
|
// increment the address
|
||||||
nextAddr += blocksize;
|
nextAddr += blocksize;
|
||||||
|
@ -459,21 +466,8 @@ TrafficGen::StateGraph::RandomGen::execute()
|
||||||
DPRINTF(TrafficGen, "RandomGen::execute: %c to addr %x, size %d\n",
|
DPRINTF(TrafficGen, "RandomGen::execute: %c to addr %x, size %d\n",
|
||||||
isRead ? 'r' : 'w', addr, blocksize);
|
isRead ? 'r' : 'w', addr, blocksize);
|
||||||
|
|
||||||
// create new request packet
|
// send a new request packet
|
||||||
Request::Flags flags;
|
send(addr, blocksize, isRead ? MemCmd::ReadReq : MemCmd::WriteReq);
|
||||||
Request *req = new Request(addr, blocksize, flags, masterID);
|
|
||||||
|
|
||||||
PacketPtr pkt = new Packet(req, isRead ? MemCmd::ReadReq :
|
|
||||||
MemCmd::WriteReq);
|
|
||||||
|
|
||||||
uint8_t* pkt_data = new uint8_t[req->getSize()];
|
|
||||||
pkt->dataDynamicArray(pkt_data);
|
|
||||||
|
|
||||||
if (!isRead) {
|
|
||||||
memset(pkt_data, 0xA, req->getSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
port.schedTimingReq(pkt, curTick());
|
|
||||||
|
|
||||||
// Add the amount of data manipulated to the total
|
// Add the amount of data manipulated to the total
|
||||||
dataManipulated += blocksize;
|
dataManipulated += blocksize;
|
||||||
|
@ -596,20 +590,8 @@ TrafficGen::StateGraph::TraceGen::execute() {
|
||||||
currElement.blocksize,
|
currElement.blocksize,
|
||||||
currElement.tick);
|
currElement.tick);
|
||||||
|
|
||||||
Request::Flags flags;
|
send(currElement.addr + addrOffset, currElement.blocksize,
|
||||||
Request *req = new Request(currElement.addr + addrOffset,
|
currElement.cmd);
|
||||||
currElement.blocksize, flags, masterID);
|
|
||||||
|
|
||||||
PacketPtr pkt = new Packet(req, currElement.cmd);
|
|
||||||
|
|
||||||
uint8_t* pkt_data = new uint8_t[req->getSize()];
|
|
||||||
pkt->dataDynamicArray(pkt_data);
|
|
||||||
|
|
||||||
if (currElement.cmd.isWrite()) {
|
|
||||||
memset(pkt_data, 0xA, req->getSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
port.schedTimingReq(pkt, curTick());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -171,6 +171,16 @@ class TrafficGen : public MemObject
|
||||||
/** The MasterID used for generating requests */
|
/** The MasterID used for generating requests */
|
||||||
const MasterID masterID;
|
const MasterID masterID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new request and associated packet and schedule
|
||||||
|
* it to be sent in the current tick.
|
||||||
|
*
|
||||||
|
* @param addr Physical address to use
|
||||||
|
* @param size Size of the request
|
||||||
|
* @param cmd Memory command to send
|
||||||
|
*/
|
||||||
|
void send(Addr addr, unsigned size, const MemCmd& cmd);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
/** Time to spend in this state */
|
/** Time to spend in this state */
|
||||||
|
|
Loading…
Reference in a new issue