mem: Refactor assignment of Packet types
authorCurtis Dunham <Curtis.Dunham@arm.com>
Tue, 13 May 2014 17:20:48 +0000 (12:20 -0500)
committerCurtis Dunham <Curtis.Dunham@arm.com>
Tue, 13 May 2014 17:20:48 +0000 (12:20 -0500)
Put the packet type swizzling (that is currently done in a lot of places)
into a refineCommand() member function.

src/cpu/checker/cpu.cc
src/cpu/inorder/resources/cache_unit.cc
src/cpu/o3/lsq_unit.hh
src/cpu/o3/lsq_unit_impl.hh
src/cpu/ozone/lw_lsq.hh
src/cpu/ozone/lw_lsq_impl.hh
src/cpu/simple/atomic.cc
src/cpu/simple/timing.cc
src/mem/packet.hh

index de9945af1f56561f08ade830917a5bebfd507391..b02c0701fe4248d7206d7f42241d14c34486481e 100644 (file)
@@ -170,10 +170,7 @@ CheckerCPU::readMem(Addr addr, uint8_t *data, unsigned size, unsigned flags)
         // Now do the access
         if (fault == NoFault &&
             !memReq->getFlags().isSet(Request::NO_ACCESS)) {
-            PacketPtr pkt = new Packet(memReq,
-                                       memReq->isLLSC() ?
-                                       MemCmd::LoadLockedReq :
-                                       MemCmd::ReadReq);
+            PacketPtr pkt = Packet::createRead(memReq);
 
             pkt->dataStatic(data);
 
index c71678a916ecc7f22cfbf1d92eb85ccf5eaa13da..dea4f91fba22eb6ecc39a888b725a3e800a7bcfa 100644 (file)
@@ -812,21 +812,11 @@ CacheUnit::finishCacheUnitReq(DynInstPtr inst, CacheRequest *cache_req)
 void
 CacheUnit::buildDataPacket(CacheRequest *cache_req)
 {
-    // Check for LL/SC and if so change command
-    if (cache_req->memReq->isLLSC() && cache_req->pktCmd == MemCmd::ReadReq) {
-        cache_req->pktCmd = MemCmd::LoadLockedReq;
-    }
-
-    if (cache_req->pktCmd == MemCmd::WriteReq) {
-        cache_req->pktCmd =
-            cache_req->memReq->isSwap() ? MemCmd::SwapReq :
-            (cache_req->memReq->isLLSC() ? MemCmd::StoreCondReq 
-             : MemCmd::WriteReq);
-    }
-
     cache_req->dataPkt = new CacheReqPacket(cache_req,
                                             cache_req->pktCmd,
                                             cache_req->instIdx);
+    cache_req->dataPkt->refineCommand(); // handle LL/SC, etc.
+
     DPRINTF(InOrderCachePort, "[slot:%i]: Slot marked for %x\n",
             cache_req->getSlot(),
             cache_req->dataPkt->getAddr());
index cb892a4fd11f36c15c27ca302b1d73720015a5d7..cfb9b82886a6a31b127754cf4cb5c329fe8d083a 100644 (file)
@@ -776,8 +776,7 @@ LSQUnit<Impl>::read(Request *req, Request *sreqLow, Request *sreqHigh,
 
     // if we the cache is not blocked, do cache access
     bool completedFirst = false;
-    MemCmd command = req->isLLSC() ? MemCmd::LoadLockedReq : MemCmd::ReadReq;
-    PacketPtr data_pkt = new Packet(req, command);
+    PacketPtr data_pkt = Packet::createRead(req);
     PacketPtr fst_data_pkt = NULL;
     PacketPtr snd_data_pkt = NULL;
 
@@ -794,8 +793,8 @@ LSQUnit<Impl>::read(Request *req, Request *sreqLow, Request *sreqHigh,
         fst_data_pkt = data_pkt;
     } else {
         // Create the split packets.
-        fst_data_pkt = new Packet(sreqLow, command);
-        snd_data_pkt = new Packet(sreqHigh, command);
+        fst_data_pkt = Packet::createRead(sreqLow);
+        snd_data_pkt = Packet::createRead(sreqHigh);
 
         fst_data_pkt->dataStatic(load_inst->memData);
         snd_data_pkt->dataStatic(load_inst->memData + sreqLow->getSize());
index 90092cf0e947efd86876855cf7ac629d53b0d4e6..b63a590fbfaafa7e93a89ba3d3d423d868fd2279 100644 (file)
@@ -839,9 +839,6 @@ LSQUnit<Impl>::writebackStores()
         else
             memcpy(inst->memData, storeQueue[storeWBIdx].data, req->getSize());
 
-        MemCmd command =
-            req->isSwap() ? MemCmd::SwapReq :
-            (req->isLLSC() ? MemCmd::StoreCondReq : MemCmd::WriteReq);
         PacketPtr data_pkt;
         PacketPtr snd_data_pkt = NULL;
 
@@ -853,13 +850,13 @@ LSQUnit<Impl>::writebackStores()
         if (!TheISA::HasUnalignedMemAcc || !storeQueue[storeWBIdx].isSplit) {
 
             // Build a single data packet if the store isn't split.
-            data_pkt = new Packet(req, command);
+            data_pkt = Packet::createWrite(req);
             data_pkt->dataStatic(inst->memData);
             data_pkt->senderState = state;
         } else {
             // Create two packets if the store is split in two.
-            data_pkt = new Packet(sreqLow, command);
-            snd_data_pkt = new Packet(sreqHigh, command);
+            data_pkt = Packet::createWrite(sreqLow);
+            snd_data_pkt = Packet::createWrite(sreqHigh);
 
             data_pkt->dataStatic(inst->memData);
             snd_data_pkt->dataStatic(inst->memData + sreqLow->getSize());
index 855e5a97cd4734accca3832463765db02037a3a9..514c4b01ab602e1c0642279e35c0fea48080885d 100644 (file)
@@ -631,10 +631,7 @@ OzoneLWLSQ<Impl>::read(RequestPtr req, T &data, int load_idx)
     DPRINTF(OzoneLSQ, "Doing timing access for inst PC %#x\n",
             inst->readPC());
 
-    PacketPtr data_pkt =
-        new Packet(req,
-                   (req->isLLSC() ?
-                    MemCmd::LoadLockedReq : Packet::ReadReq));
+    PacketPtr data_pkt = Packet::createRead(req);
     data_pkt->dataStatic(inst->memData);
 
     LSQSenderState *state = new LSQSenderState;
index ed036d664e0acc4797295d49e5f8ca19ebe315e5..37c164a1cee62b53ab3467c97409a972c0f7c68a 100644 (file)
@@ -577,10 +577,7 @@ OzoneLWLSQ<Impl>::writebackStores()
         memcpy(inst->memData, (uint8_t *)&(*sq_it).data,
                req->getSize());
 
-        MemCmd command =
-            req->isSwap() ? MemCmd::SwapReq :
-            (req->isLLSC() ? MemCmd::WriteReq : MemCmd::StoreCondReq);
-        PacketPtr data_pkt = new Packet(req, command);
+        PacketPtr data_pkt = Packet::createWrite(req);
         data_pkt->dataStatic(inst->memData);
 
         LSQSenderState *state = new LSQSenderState;
index f62f891f7bb7bf80d8b4c5e3f781028882a3d76a..219e940431e4e0dcd25e860fc71bccffaf5cd254 100644 (file)
@@ -340,9 +340,8 @@ AtomicSimpleCPU::readMem(Addr addr, uint8_t * data,
 
         // Now do the access.
         if (fault == NoFault && !req->getFlags().isSet(Request::NO_ACCESS)) {
-            Packet pkt = Packet(req,
-                                req->isLLSC() ? MemCmd::LoadLockedReq :
-                                MemCmd::ReadReq);
+            Packet pkt(req, MemCmd::ReadReq);
+            pkt.refineCommand();
             pkt.dataStatic(data);
 
             if (req->isMmappedIpr())
index 3b4f0e7d8fd301e8a53289b3800ad7c24e9500e0..f572fc26847f094fca3f37a4cf193bfaff79d937 100644 (file)
@@ -349,20 +349,7 @@ TimingSimpleCPU::translationFault(Fault fault)
 void
 TimingSimpleCPU::buildPacket(PacketPtr &pkt, RequestPtr req, bool read)
 {
-    MemCmd cmd;
-    if (read) {
-        cmd = MemCmd::ReadReq;
-        if (req->isLLSC())
-            cmd = MemCmd::LoadLockedReq;
-    } else {
-        cmd = MemCmd::WriteReq;
-        if (req->isLLSC()) {
-            cmd = MemCmd::StoreCondReq;
-        } else if (req->isSwap()) {
-            cmd = MemCmd::SwapReq;
-        }
-    }
-    pkt = new Packet(req, cmd);
+    pkt = read ? Packet::createRead(req) : Packet::createWrite(req);
 }
 
 void
index 7b9e05945680c4efdc1421db1cdb3318555ab90f..0c6abe909cf198883c16d60edd1c741042b2ea2d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012-2013 ARM Limited
+ * Copyright (c) 2012-2014 ARM Limited
  * All rights reserved
  *
  * The license below extends only to copyright in the software and shall
@@ -666,7 +666,46 @@ class Packet : public Printable
 
         flags.set(pkt->flags & (VALID_ADDR|VALID_SIZE));
         flags.set(pkt->flags & STATIC_DATA);
+    }
+
+    /**
+     * Change the packet type based on request type.
+     */
+    void
+    refineCommand()
+    {
+        if (cmd == MemCmd::ReadReq) {
+            if (req->isLLSC()) {
+                cmd = MemCmd::LoadLockedReq;
+            }
+        } else if (cmd == MemCmd::WriteReq) {
+            if (req->isLLSC()) {
+                cmd = MemCmd::StoreCondReq;
+            } else if (req->isSwap()) {
+                cmd = MemCmd::SwapReq;
+            }
+        }
+    }
+
+    /**
+     * Constructor-like methods that return Packets based on Request objects.
+     * Will call refineCommand() to fine-tune the Packet type if it's not a
+     * vanilla read or write.
+     */
+    static PacketPtr
+    createRead(Request *req)
+    {
+        PacketPtr pkt = new Packet(req, MemCmd::ReadReq);
+        pkt->refineCommand();
+        return pkt;
+    }
 
+    static PacketPtr
+    createWrite(Request *req)
+    {
+        PacketPtr pkt = new Packet(req, MemCmd::WriteReq);
+        pkt->refineCommand();
+        return pkt;
     }
 
     /**