diff options
author | Giacomo Travaglini <giacomo.travaglini@arm.com> | 2018-06-04 09:40:19 +0100 |
---|---|---|
committer | Giacomo Travaglini <giacomo.travaglini@arm.com> | 2018-06-11 16:55:30 +0000 |
commit | f54020eb8155371725ab75b0fc5c419287eca084 (patch) | |
tree | 65d379f7603e689e083e9a58ff4c2e90abd19fbf /src/cpu/testers | |
parent | 2113b21996d086dab32b9fd388efe3df241bfbd2 (diff) | |
download | gem5-f54020eb8155371725ab75b0fc5c419287eca084.tar.xz |
misc: Using smart pointers for memory Requests
This patch is changing the underlying type for RequestPtr from Request*
to shared_ptr<Request>. Having memory requests being managed by smart
pointers will simplify the code; it will also prevent memory leakage and
dangling pointers.
Change-Id: I7749af38a11ac8eb4d53d8df1252951e0890fde3
Signed-off-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-on: https://gem5-review.googlesource.com/10996
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>
Diffstat (limited to 'src/cpu/testers')
-rw-r--r-- | src/cpu/testers/directedtest/InvalidateGenerator.cc | 3 | ||||
-rw-r--r-- | src/cpu/testers/directedtest/RubyDirectedTester.cc | 1 | ||||
-rw-r--r-- | src/cpu/testers/directedtest/SeriesRequestGenerator.cc | 3 | ||||
-rw-r--r-- | src/cpu/testers/garnet_synthetic_traffic/GarnetSyntheticTraffic.cc | 12 | ||||
-rw-r--r-- | src/cpu/testers/memtest/memtest.cc | 6 | ||||
-rw-r--r-- | src/cpu/testers/rubytest/Check.cc | 13 | ||||
-rw-r--r-- | src/cpu/testers/rubytest/RubyTester.cc | 1 | ||||
-rw-r--r-- | src/cpu/testers/traffic_gen/base_gen.cc | 2 | ||||
-rw-r--r-- | src/cpu/testers/traffic_gen/traffic_gen.cc | 2 |
9 files changed, 15 insertions, 28 deletions
diff --git a/src/cpu/testers/directedtest/InvalidateGenerator.cc b/src/cpu/testers/directedtest/InvalidateGenerator.cc index 3319e8400..9351d91c4 100644 --- a/src/cpu/testers/directedtest/InvalidateGenerator.cc +++ b/src/cpu/testers/directedtest/InvalidateGenerator.cc @@ -60,7 +60,7 @@ InvalidateGenerator::initiate() Packet::Command cmd; // For simplicity, requests are assumed to be 1 byte-sized - RequestPtr req = new Request(m_address, 1, flags, masterId); + RequestPtr req = std::make_shared<Request>(m_address, 1, flags, masterId); // // Based on the current state, issue a load or a store @@ -92,7 +92,6 @@ InvalidateGenerator::initiate() // If the packet did not issue, must delete // Note: No need to delete the data, the packet destructor // will delete it - delete pkt->req; delete pkt; DPRINTF(DirectedTest, "failed to issue request - sequencer not ready\n"); diff --git a/src/cpu/testers/directedtest/RubyDirectedTester.cc b/src/cpu/testers/directedtest/RubyDirectedTester.cc index ef133379d..be7f3c256 100644 --- a/src/cpu/testers/directedtest/RubyDirectedTester.cc +++ b/src/cpu/testers/directedtest/RubyDirectedTester.cc @@ -101,7 +101,6 @@ RubyDirectedTester::CpuPort::recvTimingResp(PacketPtr pkt) // // Now that the tester has completed, delete the packet, then return // - delete pkt->req; delete pkt; return true; } diff --git a/src/cpu/testers/directedtest/SeriesRequestGenerator.cc b/src/cpu/testers/directedtest/SeriesRequestGenerator.cc index 17ae04cdf..e5b7656d9 100644 --- a/src/cpu/testers/directedtest/SeriesRequestGenerator.cc +++ b/src/cpu/testers/directedtest/SeriesRequestGenerator.cc @@ -60,7 +60,7 @@ SeriesRequestGenerator::initiate() Request::Flags flags; // For simplicity, requests are assumed to be 1 byte-sized - RequestPtr req = new Request(m_address, 1, flags, masterId); + RequestPtr req = std::make_shared<Request>(m_address, 1, flags, masterId); Packet::Command cmd; bool do_write = (random_mt.random(0, 100) < m_percent_writes); @@ -81,7 +81,6 @@ SeriesRequestGenerator::initiate() // If the packet did not issue, must delete // Note: No need to delete the data, the packet destructor // will delete it - delete pkt->req; delete pkt; DPRINTF(DirectedTest, "failed to initiate request - sequencer not ready\n"); diff --git a/src/cpu/testers/garnet_synthetic_traffic/GarnetSyntheticTraffic.cc b/src/cpu/testers/garnet_synthetic_traffic/GarnetSyntheticTraffic.cc index be1921aad..0ced9df84 100644 --- a/src/cpu/testers/garnet_synthetic_traffic/GarnetSyntheticTraffic.cc +++ b/src/cpu/testers/garnet_synthetic_traffic/GarnetSyntheticTraffic.cc @@ -129,16 +129,13 @@ GarnetSyntheticTraffic::init() void GarnetSyntheticTraffic::completeRequest(PacketPtr pkt) { - RequestPtr req = pkt->req; - DPRINTF(GarnetSyntheticTraffic, "Completed injection of %s packet for address %x\n", pkt->isWrite() ? "write" : "read\n", - req->getPaddr()); + pkt->req->getPaddr()); assert(pkt->isResponse()); noResponseCycles = 0; - delete req; delete pkt; } @@ -296,17 +293,18 @@ GarnetSyntheticTraffic::generatePkt() if (injReqType == 0) { // generate packet for virtual network 0 requestType = MemCmd::ReadReq; - req = new Request(paddr, access_size, flags, masterId); + req = std::make_shared<Request>(paddr, access_size, flags, masterId); } else if (injReqType == 1) { // generate packet for virtual network 1 requestType = MemCmd::ReadReq; flags.set(Request::INST_FETCH); - req = new Request(0, 0x0, access_size, flags, masterId, 0x0, 0); + req = std::make_shared<Request>( + 0, 0x0, access_size, flags, masterId, 0x0, 0); req->setPaddr(paddr); } else { // if (injReqType == 2) // generate packet for virtual network 2 requestType = MemCmd::WriteReq; - req = new Request(paddr, access_size, flags, masterId); + req = std::make_shared<Request>(paddr, access_size, flags, masterId); } req->setContext(id); diff --git a/src/cpu/testers/memtest/memtest.cc b/src/cpu/testers/memtest/memtest.cc index 89b4d1159..09e7e88a1 100644 --- a/src/cpu/testers/memtest/memtest.cc +++ b/src/cpu/testers/memtest/memtest.cc @@ -136,7 +136,7 @@ MemTest::getMasterPort(const std::string &if_name, PortID idx) void MemTest::completeRequest(PacketPtr pkt, bool functional) { - RequestPtr req = pkt->req; + const RequestPtr &req = pkt->req; assert(req->getSize() == 1); // this address is no longer outstanding @@ -187,8 +187,6 @@ MemTest::completeRequest(PacketPtr pkt, bool functional) } } - delete pkt->req; - // the packet will delete the data delete pkt; @@ -246,7 +244,7 @@ MemTest::tick() bool do_functional = (random_mt.random(0, 100) < percentFunctional) && !uncacheable; - RequestPtr req = new Request(paddr, 1, flags, masterId); + RequestPtr req = std::make_shared<Request>(paddr, 1, flags, masterId); req->setContext(id); outstandingAddrs.insert(paddr); diff --git a/src/cpu/testers/rubytest/Check.cc b/src/cpu/testers/rubytest/Check.cc index 776d711a2..49332ab01 100644 --- a/src/cpu/testers/rubytest/Check.cc +++ b/src/cpu/testers/rubytest/Check.cc @@ -107,7 +107,7 @@ Check::initiatePrefetch() } // Prefetches are assumed to be 0 sized - RequestPtr req = new Request(m_address, 0, flags, + RequestPtr req = std::make_shared<Request>(m_address, 0, flags, m_tester_ptr->masterId(), curTick(), m_pc); req->setContext(index); @@ -127,7 +127,6 @@ Check::initiatePrefetch() } else { // If the packet did not issue, must delete delete pkt->senderState; - delete pkt->req; delete pkt; DPRINTF(RubyTest, @@ -146,7 +145,7 @@ Check::initiateFlush() Request::Flags flags; - RequestPtr req = new Request(m_address, CHECK_SIZE, flags, + RequestPtr req = std::make_shared<Request>(m_address, CHECK_SIZE, flags, m_tester_ptr->masterId(), curTick(), m_pc); Packet::Command cmd; @@ -179,8 +178,8 @@ Check::initiateAction() Addr writeAddr(m_address + m_store_count); // Stores are assumed to be 1 byte-sized - RequestPtr req = new Request(writeAddr, 1, flags, m_tester_ptr->masterId(), - curTick(), m_pc); + RequestPtr req = std::make_shared<Request>( + writeAddr, 1, flags, m_tester_ptr->masterId(), curTick(), m_pc); req->setContext(index); Packet::Command cmd; @@ -215,7 +214,6 @@ Check::initiateAction() // Note: No need to delete the data, the packet destructor // will delete it delete pkt->senderState; - delete pkt->req; delete pkt; DPRINTF(RubyTest, "failed to initiate action - sequencer not ready\n"); @@ -244,7 +242,7 @@ Check::initiateCheck() } // Checks are sized depending on the number of bytes written - RequestPtr req = new Request(m_address, CHECK_SIZE, flags, + RequestPtr req = std::make_shared<Request>(m_address, CHECK_SIZE, flags, m_tester_ptr->masterId(), curTick(), m_pc); req->setContext(index); @@ -269,7 +267,6 @@ Check::initiateCheck() // Note: No need to delete the data, the packet destructor // will delete it delete pkt->senderState; - delete pkt->req; delete pkt; DPRINTF(RubyTest, "failed to initiate check - cpu port not ready\n"); diff --git a/src/cpu/testers/rubytest/RubyTester.cc b/src/cpu/testers/rubytest/RubyTester.cc index 67c824806..93754467d 100644 --- a/src/cpu/testers/rubytest/RubyTester.cc +++ b/src/cpu/testers/rubytest/RubyTester.cc @@ -186,7 +186,6 @@ RubyTester::CpuPort::recvTimingResp(PacketPtr pkt) // Now that the tester has completed, delete the senderState // (includes sublock) and the packet, then return delete pkt->senderState; - delete pkt->req; delete pkt; return true; } diff --git a/src/cpu/testers/traffic_gen/base_gen.cc b/src/cpu/testers/traffic_gen/base_gen.cc index b5b4f5817..f25bfb08a 100644 --- a/src/cpu/testers/traffic_gen/base_gen.cc +++ b/src/cpu/testers/traffic_gen/base_gen.cc @@ -59,7 +59,7 @@ BaseGen::getPacket(Addr addr, unsigned size, const MemCmd& cmd, Request::FlagsType flags) { // Create new request - RequestPtr req = new Request(addr, size, flags, masterID); + RequestPtr req = std::make_shared<Request>(addr, size, flags, masterID); // Dummy PC to have PC-based prefetchers latch on; get entropy into higher // bits req->setPC(((Addr)masterID) << 2); diff --git a/src/cpu/testers/traffic_gen/traffic_gen.cc b/src/cpu/testers/traffic_gen/traffic_gen.cc index 2d4dd3752..d262fd9f7 100644 --- a/src/cpu/testers/traffic_gen/traffic_gen.cc +++ b/src/cpu/testers/traffic_gen/traffic_gen.cc @@ -213,7 +213,6 @@ TrafficGen::update() warn("%s suppressed %d packets with non-memory addresses\n", name(), numSuppressed); - delete pkt->req; delete pkt; pkt = nullptr; } @@ -575,7 +574,6 @@ TrafficGen::regStats() bool TrafficGen::TrafficGenPort::recvTimingResp(PacketPtr pkt) { - delete pkt->req; delete pkt; return true; |