summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndreas Hansson <andreas.hansson@arm.com>2014-12-02 06:07:43 -0500
committerAndreas Hansson <andreas.hansson@arm.com>2014-12-02 06:07:43 -0500
commit41846cb61b0f511099eb9a203f11885de328ab45 (patch)
tree7563b309ba914ea57dd12e6cfba3ea33817ab1b1 /src
parent5df96cb690168d750ab0fafffd11fb51624374d2 (diff)
downloadgem5-41846cb61b0f511099eb9a203f11885de328ab45.tar.xz
mem: Assume all dynamic packet data is array allocated
This patch simplifies how we deal with dynamically allocated data in the packet, always assuming that it is array allocated, and hence should be array deallocated (delete[] as opposed to delete). The only uses of dataDynamic was in the Ruby testers. The ARRAY_DATA flag in the packet is removed accordingly. No defragmentation of the flags is done at this point, leaving a gap in the bit masks. As the last part the patch, it renames dataDynamicArray to dataDynamic.
Diffstat (limited to 'src')
-rw-r--r--src/cpu/minor/lsq.cc2
-rw-r--r--src/cpu/o3/fetch_impl.hh2
-rw-r--r--src/cpu/simple/timing.cc4
-rw-r--r--src/cpu/testers/directedtest/InvalidateGenerator.cc4
-rw-r--r--src/cpu/testers/directedtest/SeriesRequestGenerator.cc4
-rw-r--r--src/cpu/testers/memtest/memtest.cc4
-rw-r--r--src/cpu/testers/networktest/networktest.cc2
-rw-r--r--src/cpu/testers/rubytest/Check.cc6
-rw-r--r--src/cpu/testers/traffic_gen/generators.cc2
-rw-r--r--src/mem/packet.hh33
10 files changed, 21 insertions, 42 deletions
diff --git a/src/cpu/minor/lsq.cc b/src/cpu/minor/lsq.cc
index fca580085..75dbb804a 100644
--- a/src/cpu/minor/lsq.cc
+++ b/src/cpu/minor/lsq.cc
@@ -1558,7 +1558,7 @@ makePacketForRequest(Request &request, bool isLoad,
if (isLoad)
ret->allocate();
else
- ret->dataDynamicArray(data);
+ ret->dataDynamic(data);
return ret;
}
diff --git a/src/cpu/o3/fetch_impl.hh b/src/cpu/o3/fetch_impl.hh
index 47a64a9bf..d3b0b3ac5 100644
--- a/src/cpu/o3/fetch_impl.hh
+++ b/src/cpu/o3/fetch_impl.hh
@@ -669,7 +669,7 @@ DefaultFetch<Impl>::finishTranslation(const Fault &fault, RequestPtr mem_req)
// Build packet here.
PacketPtr data_pkt = new Packet(mem_req, MemCmd::ReadReq);
- data_pkt->dataDynamicArray(new uint8_t[fetchBufferSize]);
+ data_pkt->dataDynamic(new uint8_t[fetchBufferSize]);
fetchBufferPC[tid] = fetchBufferBlockPC;
fetchBufferValid[tid] = false;
diff --git a/src/cpu/simple/timing.cc b/src/cpu/simple/timing.cc
index 2d0ab330e..c2bcdee63 100644
--- a/src/cpu/simple/timing.cc
+++ b/src/cpu/simple/timing.cc
@@ -271,7 +271,7 @@ TimingSimpleCPU::sendData(RequestPtr req, uint8_t *data, uint64_t *res,
{
PacketPtr pkt;
buildPacket(pkt, req, read);
- pkt->dataDynamicArray<uint8_t>(data);
+ pkt->dataDynamic<uint8_t>(data);
if (req->getFlags().isSet(Request::NO_ACCESS)) {
assert(!dcache_pkt);
pkt->makeResponse();
@@ -379,7 +379,7 @@ TimingSimpleCPU::buildSplitPacket(PacketPtr &pkt1, PacketPtr &pkt2,
req->setPhys(req1->getPaddr(), req->getSize(), req1->getFlags(), dataMasterId());
PacketPtr pkt = new Packet(req, pkt1->cmd.responseCommand());
- pkt->dataDynamicArray<uint8_t>(data);
+ pkt->dataDynamic<uint8_t>(data);
pkt1->dataStatic<uint8_t>(data);
pkt2->dataStatic<uint8_t>(data + req1->getSize());
diff --git a/src/cpu/testers/directedtest/InvalidateGenerator.cc b/src/cpu/testers/directedtest/InvalidateGenerator.cc
index 84a90844f..61c3f5972 100644
--- a/src/cpu/testers/directedtest/InvalidateGenerator.cc
+++ b/src/cpu/testers/directedtest/InvalidateGenerator.cc
@@ -76,9 +76,7 @@ InvalidateGenerator::initiate()
} else {
panic("initiate was unexpectedly called\n");
}
- uint8_t* dummyData = new uint8_t;
- *dummyData = 0;
- pkt->dataDynamic(dummyData);
+ pkt->allocate();
if (port->sendTimingReq(pkt)) {
DPRINTF(DirectedTest, "initiating request - successful\n");
diff --git a/src/cpu/testers/directedtest/SeriesRequestGenerator.cc b/src/cpu/testers/directedtest/SeriesRequestGenerator.cc
index 80523280b..2356fb47a 100644
--- a/src/cpu/testers/directedtest/SeriesRequestGenerator.cc
+++ b/src/cpu/testers/directedtest/SeriesRequestGenerator.cc
@@ -69,9 +69,7 @@ SeriesRequestGenerator::initiate()
}
PacketPtr pkt = new Packet(req, cmd);
- uint8_t* dummyData = new uint8_t;
- *dummyData = 0;
- pkt->dataDynamic(dummyData);
+ pkt->allocate();
if (port->sendTimingReq(pkt)) {
DPRINTF(DirectedTest, "initiating request - successful\n");
diff --git a/src/cpu/testers/memtest/memtest.cc b/src/cpu/testers/memtest/memtest.cc
index 082737f8a..53c01b7f7 100644
--- a/src/cpu/testers/memtest/memtest.cc
+++ b/src/cpu/testers/memtest/memtest.cc
@@ -327,7 +327,7 @@ MemTest::tick()
blockAddr(req->getPaddr()), *result);
PacketPtr pkt = new Packet(req, MemCmd::ReadReq);
- pkt->dataDynamicArray(new uint8_t[req->getSize()]);
+ pkt->dataDynamic(new uint8_t[req->getSize()]);
MemTestSenderState *state = new MemTestSenderState(result);
pkt->senderState = state;
@@ -349,7 +349,7 @@ MemTest::tick()
PacketPtr pkt = new Packet(req, MemCmd::WriteReq);
uint8_t *pkt_data = new uint8_t[req->getSize()];
- pkt->dataDynamicArray(pkt_data);
+ pkt->dataDynamic(pkt_data);
memcpy(pkt_data, &data, req->getSize());
MemTestSenderState *state = new MemTestSenderState(result);
pkt->senderState = state;
diff --git a/src/cpu/testers/networktest/networktest.cc b/src/cpu/testers/networktest/networktest.cc
index 94dedf648..8ad32d140 100644
--- a/src/cpu/testers/networktest/networktest.cc
+++ b/src/cpu/testers/networktest/networktest.cc
@@ -261,7 +261,7 @@ NetworkTest::generatePkt()
destination, req->getPaddr());
PacketPtr pkt = new Packet(req, requestType);
- pkt->dataDynamicArray(new uint8_t[req->getSize()]);
+ pkt->dataDynamic(new uint8_t[req->getSize()]);
pkt->senderState = NULL;
sendPkt(pkt);
diff --git a/src/cpu/testers/rubytest/Check.cc b/src/cpu/testers/rubytest/Check.cc
index 19d0623c0..b320ca61d 100644
--- a/src/cpu/testers/rubytest/Check.cc
+++ b/src/cpu/testers/rubytest/Check.cc
@@ -113,7 +113,7 @@ Check::initiatePrefetch()
// despite the oddity of the 0 size (questionable if this should
// even be allowed), a prefetch is still a read and as such needs
// a place to store the result
- uint8_t *data = new uint8_t;
+ uint8_t *data = new uint8_t[1];
pkt->dataDynamic(data);
// push the subblock onto the sender state. The sequencer will
@@ -192,7 +192,7 @@ Check::initiateAction()
// }
PacketPtr pkt = new Packet(req, cmd);
- uint8_t *writeData = new uint8_t;
+ uint8_t *writeData = new uint8_t[1];
*writeData = m_value + m_store_count;
pkt->dataDynamic(writeData);
@@ -246,7 +246,7 @@ Check::initiateCheck()
req->setThreadContext(index, 0);
PacketPtr pkt = new Packet(req, MemCmd::ReadReq);
uint8_t *dataArray = new uint8_t[CHECK_SIZE];
- pkt->dataDynamicArray(dataArray);
+ pkt->dataDynamic(dataArray);
// push the subblock onto the sender state. The sequencer will
// update the subblock on the return
diff --git a/src/cpu/testers/traffic_gen/generators.cc b/src/cpu/testers/traffic_gen/generators.cc
index 5e19384bc..f0cf14206 100644
--- a/src/cpu/testers/traffic_gen/generators.cc
+++ b/src/cpu/testers/traffic_gen/generators.cc
@@ -62,7 +62,7 @@ BaseGen::getPacket(Addr addr, unsigned size, const MemCmd& cmd,
PacketPtr pkt = new Packet(req, cmd);
uint8_t* pkt_data = new uint8_t[req->getSize()];
- pkt->dataDynamicArray(pkt_data);
+ pkt->dataDynamic(pkt_data);
if (cmd.isWrite()) {
memset(pkt_data, 0xA, req->getSize());
diff --git a/src/mem/packet.hh b/src/mem/packet.hh
index e8fb00680..19423db58 100644
--- a/src/mem/packet.hh
+++ b/src/mem/packet.hh
@@ -247,11 +247,9 @@ class Packet : public Printable
/// when the packet is destroyed?
static const FlagsType STATIC_DATA = 0x00001000;
/// The data pointer points to a value that should be freed when
- /// the packet is destroyed.
+ /// the packet is destroyed. The pointer is assumed to be pointing
+ /// to an array, and delete [] is consequently called
static const FlagsType DYNAMIC_DATA = 0x00002000;
- /// the data pointer points to an array (thus delete []) needs to
- /// be called on it rather than simply delete.
- static const FlagsType ARRAY_DATA = 0x00004000;
/// suppress the error if this packet encounters a functional
/// access failure.
static const FlagsType SUPPRESS_FUNC_ERROR = 0x00008000;
@@ -813,7 +811,7 @@ class Packet : public Printable
void
dataStatic(T *p)
{
- assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA));
+ assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA));
data = (PacketDataPtr)p;
flags.set(STATIC_DATA);
}
@@ -830,7 +828,7 @@ class Packet : public Printable
void
dataStaticConst(const T *p)
{
- assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA));
+ assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA));
data = const_cast<PacketDataPtr>(p);
flags.set(STATIC_DATA);
}
@@ -841,22 +839,9 @@ class Packet : public Printable
*/
template <typename T>
void
- dataDynamicArray(T *p)
- {
- assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA));
- data = (PacketDataPtr)p;
- flags.set(DYNAMIC_DATA|ARRAY_DATA);
- }
-
- /**
- * set the data pointer to a value that should have delete called
- * on it.
- */
- template <typename T>
- void
dataDynamic(T *p)
{
- assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA));
+ assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA));
data = (PacketDataPtr)p;
flags.set(DYNAMIC_DATA);
}
@@ -938,12 +923,10 @@ class Packet : public Printable
void
deleteData()
{
- if (flags.isSet(ARRAY_DATA))
+ if (flags.isSet(DYNAMIC_DATA))
delete [] data;
- else if (flags.isSet(DYNAMIC_DATA))
- delete data;
- flags.clear(STATIC_DATA|DYNAMIC_DATA|ARRAY_DATA);
+ flags.clear(STATIC_DATA|DYNAMIC_DATA);
data = NULL;
}
@@ -952,7 +935,7 @@ class Packet : public Printable
allocate()
{
assert(flags.noneSet(STATIC_DATA|DYNAMIC_DATA));
- flags.set(DYNAMIC_DATA|ARRAY_DATA);
+ flags.set(DYNAMIC_DATA);
data = new uint8_t[getSize()];
}