mem-ruby: Use Packet writing functions instead of memcpy
authorDaniel R. Carvalho <odanrc@yahoo.com.br>
Mon, 15 Oct 2018 10:25:25 +0000 (12:25 +0200)
committerDaniel Carvalho <odanrc@yahoo.com.br>
Wed, 7 Nov 2018 19:34:55 +0000 (19:34 +0000)
Classes were using memcpy instead of the Packet functions
created for writing to/from the packet. This allows these
writes to be better checked and tracked.

Change-Id: Iae3fba1351330916ee1d4103809c71e151b1639e
Signed-off-by: Daniel R. Carvalho <odanrc@yahoo.com.br>
Reviewed-on: https://gem5-review.googlesource.com/c/13915
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Nikos Nikoleris <nikos.nikoleris@arm.com>

src/mem/ruby/slicc_interface/AbstractController.cc
src/mem/ruby/system/GPUCoalescer.cc
src/mem/ruby/system/Sequencer.cc

index de7e03dd7dda958d2605ba51eda6ae5e4ebfdaca..101a4ce7f9ad2ee3edad0687af8c736448e97f84 100644 (file)
@@ -268,10 +268,8 @@ AbstractController::queueMemoryWrite(const MachineID &id, Addr addr,
         addr, RubySystem::getBlockSizeBytes(), 0, m_masterId);
 
     PacketPtr pkt = Packet::createWrite(req);
-    uint8_t *newData = new uint8_t[RubySystem::getBlockSizeBytes()];
-    pkt->dataDynamic(newData);
-    memcpy(newData, block.getData(0, RubySystem::getBlockSizeBytes()),
-           RubySystem::getBlockSizeBytes());
+    pkt->allocate();
+    pkt->setData(block.getData(0, RubySystem::getBlockSizeBytes()));
 
     SenderState *s = new SenderState(id);
     pkt->pushSenderState(s);
@@ -295,9 +293,8 @@ AbstractController::queueMemoryWritePartial(const MachineID &id, Addr addr,
     RequestPtr req = std::make_shared<Request>(addr, size, 0, m_masterId);
 
     PacketPtr pkt = Packet::createWrite(req);
-    uint8_t *newData = new uint8_t[size];
-    pkt->dataDynamic(newData);
-    memcpy(newData, block.getData(getOffset(addr), size), size);
+    pkt->allocate();
+    pkt->setData(block.getData(getOffset(addr), size));
 
     SenderState *s = new SenderState(id);
     pkt->pushSenderState(s);
index e17bf63fdd78125f30bfcd01dfd07839dfb7b11c..8b8c9566f6c36147b4a2df318dd080ef0e0940c3 100644 (file)
@@ -640,10 +640,8 @@ GPUCoalescer::hitCallback(GPUCoalescerRequest* srequest,
                 (type == RubyRequestType_RMW_Read) ||
                 (type == RubyRequestType_Locked_RMW_Read) ||
                 (type == RubyRequestType_Load_Linked)) {
-                memcpy(pkt->getPtr<uint8_t>(),
-                       data.getData(getOffset(request_address),
-                                    pkt->getSize()),
-                       pkt->getSize());
+                pkt->setData(
+                    data.getData(getOffset(request_address), pkt->getSize()));
             } else {
                 data.setData(pkt->getPtr<uint8_t>(),
                              getOffset(request_address), pkt->getSize());
@@ -1097,10 +1095,8 @@ GPUCoalescer::atomicCallback(Addr address,
         if (pkt->getPtr<uint8_t>() &&
             srequest->m_type != RubyRequestType_ATOMIC_NO_RETURN) {
             /* atomics are done in memory, and return the data *before* the atomic op... */
-            memcpy(pkt->getPtr<uint8_t>(),
-                   data.getData(getOffset(request_address),
-                                pkt->getSize()),
-                   pkt->getSize());
+            pkt->setData(
+                data.getData(getOffset(request_address), pkt->getSize()));
         } else {
             DPRINTF(MemoryAccess,
                     "WARNING.  Data not transfered from Ruby to M5 for type " \
index f3036971091986e97d9fa4574d6c795a9a7a1b53..41ec6ea6c9c1ae6be6c6b789b0ebb32ac926996f 100644 (file)
@@ -476,17 +476,14 @@ Sequencer::hitCallback(SequencerRequest* srequest, DataBlock& data,
             (type == RubyRequestType_RMW_Read) ||
             (type == RubyRequestType_Locked_RMW_Read) ||
             (type == RubyRequestType_Load_Linked)) {
-            memcpy(pkt->getPtr<uint8_t>(),
-                   data.getData(getOffset(request_address), pkt->getSize()),
-                   pkt->getSize());
+            pkt->setData(
+                data.getData(getOffset(request_address), pkt->getSize()));
             DPRINTF(RubySequencer, "read data %s\n", data);
         } else if (pkt->req->isSwap()) {
             std::vector<uint8_t> overwrite_val(pkt->getSize());
-            memcpy(&overwrite_val[0], pkt->getConstPtr<uint8_t>(),
-                   pkt->getSize());
-            memcpy(pkt->getPtr<uint8_t>(),
-                   data.getData(getOffset(request_address), pkt->getSize()),
-                   pkt->getSize());
+            pkt->writeData(&overwrite_val[0]);
+            pkt->setData(
+                data.getData(getOffset(request_address), pkt->getSize()));
             data.setData(&overwrite_val[0],
                          getOffset(request_address), pkt->getSize());
             DPRINTF(RubySequencer, "swap data %s\n", data);