changeset 1cfcc2960e9f in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=1cfcc2960e9f
description:
        cpu: Move traffic generator sending out of generator states

        This patch moves the responsibility for sending packets out of the
        generator states and leaves it with the top-level traffic
        generator. The main aim of this patch is to enable a transition to
        non-queued ports, i.e. with send/retry flow control, and to do so it
        is much more convenient to not wrap the port interactions and instead
        leave it all local to the traffic generator.

        The generator states now only govern when they are ready to send
        something new, and the generation of the packets to send. They thus
        have no knowledge of the port that is used.

diffstat:

 src/cpu/testers/traffic_gen/generators.cc  |  73 +++++++++++-------------
 src/cpu/testers/traffic_gen/generators.hh  |  88 ++++++++++++++---------------
 src/cpu/testers/traffic_gen/traffic_gen.cc |  30 ++++++---
 src/cpu/testers/traffic_gen/traffic_gen.hh |  14 ++--
 4 files changed, 104 insertions(+), 101 deletions(-)

diffs (truncated from 543 to 300 lines):

diff -r dd2e46b239c1 -r 1cfcc2960e9f src/cpu/testers/traffic_gen/generators.cc
--- a/src/cpu/testers/traffic_gen/generators.cc Thu May 30 12:54:03 2013 -0400
+++ b/src/cpu/testers/traffic_gen/generators.cc Thu May 30 12:54:04 2013 -0400
@@ -40,18 +40,19 @@
  */
 
 #include "base/random.hh"
+#include "base/trace.hh"
 #include "cpu/testers/traffic_gen/generators.hh"
 #include "debug/TrafficGen.hh"
 #include "proto/packet.pb.h"
 
-BaseGen::BaseGen(QueuedMasterPort& _port, MasterID master_id, Tick _duration)
-    : port(_port), masterID(master_id), duration(_duration)
+BaseGen::BaseGen(const std::string& _name, MasterID master_id, Tick _duration)
+    : _name(_name), masterID(master_id), duration(_duration)
 {
 }
 
-void
-BaseGen::send(Addr addr, unsigned size, const MemCmd& cmd,
-              Request::FlagsType flags)
+PacketPtr
+BaseGen::getPacket(Addr addr, unsigned size, const MemCmd& cmd,
+                   Request::FlagsType flags)
 {
     // Create new request
     Request *req = new Request(addr, size, flags, masterID);
@@ -66,7 +67,7 @@
         memset(pkt_data, 0xA, req->getSize());
     }
 
-    port.schedTimingReq(pkt, curTick());
+    return pkt;
 }
 
 void
@@ -75,16 +76,10 @@
     // reset the address and the data counter
     nextAddr = startAddr;
     dataManipulated = 0;
-
-    // this test only needs to happen once, but cannot be performed
-    // before init() is called and the ports are connected
-    if (port.deviceBlockSize() && blocksize > port.deviceBlockSize())
-        fatal("TrafficGen %s block size (%d) is larger than port"
-              " block size (%d)\n", blocksize, port.deviceBlockSize());
 }
 
-void
-LinearGen::execute()
+PacketPtr
+LinearGen::getNextPacket()
 {
     // choose if we generate a read or a write here
     bool isRead = readPercent != 0 &&
@@ -93,20 +88,23 @@
     assert((readPercent == 0 && !isRead) || (readPercent == 100 && isRead) ||
            readPercent != 100);
 
-    DPRINTF(TrafficGen, "LinearGen::execute: %c to addr %x, size %d\n",
+    DPRINTF(TrafficGen, "LinearGen::getNextPacket: %c to addr %x, size %d\n",
             isRead ? 'r' : 'w', nextAddr, blocksize);
 
-    send(nextAddr, blocksize, isRead ? MemCmd::ReadReq : MemCmd::WriteReq);
+    // Add the amount of data manipulated to the total
+    dataManipulated += blocksize;
+
+    PacketPtr pkt = getPacket(nextAddr, blocksize,
+                              isRead ? MemCmd::ReadReq : MemCmd::WriteReq);
 
     // increment the address
     nextAddr += blocksize;
 
-    // Add the amount of data manipulated to the total
-    dataManipulated += blocksize;
+    return pkt;
 }
 
 Tick
-LinearGen::nextExecuteTick()
+LinearGen::nextPacketTick()
 {
     // If we have reached the end of the address space, reset the
     // address to the start of the range
@@ -134,16 +132,10 @@
 {
     // reset the counter to zero
     dataManipulated = 0;
-
-    // this test only needs to happen once, but cannot be performed
-    // before init() is called and the ports are connected
-    if (port.deviceBlockSize() && blocksize > port.deviceBlockSize())
-        fatal("TrafficGen %s block size (%d) is larger than port"
-              " block size (%d)\n", blocksize, port.deviceBlockSize());
 }
 
-void
-RandomGen::execute()
+PacketPtr
+RandomGen::getNextPacket()
 {
     // choose if we generate a read or a write here
     bool isRead = readPercent != 0 &&
@@ -158,18 +150,19 @@
     // round down to start address of block
     addr -= addr % blocksize;
 
-    DPRINTF(TrafficGen, "RandomGen::execute: %c to addr %x, size %d\n",
+    DPRINTF(TrafficGen, "RandomGen::getNextPacket: %c to addr %x, size %d\n",
             isRead ? 'r' : 'w', addr, blocksize);
 
-    // send a new request packet
-    send(addr, blocksize, isRead ? MemCmd::ReadReq : MemCmd::WriteReq);
+    // add the amount of data manipulated to the total
+    dataManipulated += blocksize;
 
-    // Add the amount of data manipulated to the total
-    dataManipulated += blocksize;
+    // create a new request packet
+    return getPacket(addr, blocksize,
+                     isRead ? MemCmd::ReadReq : MemCmd::WriteReq);
 }
 
 Tick
-RandomGen::nextExecuteTick()
+RandomGen::nextPacketTick()
 {
     // Check to see if we have reached the data limit. If dataLimit is
     // zero we do not have a data limit and therefore we will keep
@@ -224,7 +217,7 @@
 }
 
 Tick
-TraceGen::nextExecuteTick() {
+TraceGen::nextPacketTick() {
     if (traceComplete)
         // We are at the end of the file, thus we have no more data in
         // the trace Return MaxTick to signal that there will be no
@@ -274,22 +267,22 @@
     traceComplete = false;
 }
 
-void
-TraceGen::execute()
+PacketPtr
+TraceGen::getNextPacket()
 {
-    // it is the responsibility of nextExecuteTick to prevent the
+    // it is the responsibility of nextPacketTick to prevent the
     // state graph from executing the state if it should not
     assert(currElement.isValid());
 
-    DPRINTF(TrafficGen, "TraceGen::execute: %c %d %d %d 0x%x\n",
+    DPRINTF(TrafficGen, "TraceGen::getNextPacket: %c %d %d %d 0x%x\n",
             currElement.cmd.isRead() ? 'r' : 'w',
             currElement.addr,
             currElement.blocksize,
             currElement.tick,
             currElement.flags);
 
-    send(currElement.addr + addrOffset, currElement.blocksize,
-         currElement.cmd, currElement.flags);
+    return getPacket(currElement.addr + addrOffset, currElement.blocksize,
+                     currElement.cmd, currElement.flags);
 }
 
 void
diff -r dd2e46b239c1 -r 1cfcc2960e9f src/cpu/testers/traffic_gen/generators.hh
--- a/src/cpu/testers/traffic_gen/generators.hh Thu May 30 12:54:03 2013 -0400
+++ b/src/cpu/testers/traffic_gen/generators.hh Thu May 30 12:54:04 2013 -0400
@@ -49,7 +49,7 @@
 #ifndef __CPU_TRAFFIC_GEN_GENERATORS_HH__
 #define __CPU_TRAFFIC_GEN_GENERATORS_HH__
 
-#include "mem/qport.hh"
+#include "mem/packet.hh"
 #include "proto/protoio.hh"
 
 /**
@@ -62,23 +62,22 @@
 
   protected:
 
-    /** Port used to send requests */
-    QueuedMasterPort& port;
+    /** Name to use for status and debug printing */
+    const std::string _name;
 
     /** The MasterID used for generating requests */
     const MasterID masterID;
 
     /**
-     * Create a new request and associated packet and schedule
-     * it to be sent in the current tick.
+     * Generate a new request and associated packet
      *
      * @param addr Physical address to use
      * @param size Size of the request
      * @param cmd Memory command to send
      * @param flags Optional request flags
      */
-    void send(Addr addr, unsigned size, const MemCmd& cmd,
-              Request::FlagsType flags = 0);
+    PacketPtr getPacket(Addr addr, unsigned size, const MemCmd& cmd,
+                        Request::FlagsType flags = 0);
 
   public:
 
@@ -88,21 +87,20 @@
     /**
      * Create a base generator.
      *
-     * @param _port port used to send requests
+     * @param _name Name to use for status and debug
      * @param master_id MasterID set on each request
      * @param _duration duration of this state before transitioning
      */
-    BaseGen(QueuedMasterPort& _port, MasterID master_id,
-            Tick _duration);
+    BaseGen(const std::string& _name, MasterID master_id, Tick _duration);
 
     virtual ~BaseGen() { }
 
     /**
      * Get the name, useful for DPRINTFs.
      *
-     * @return the port name
+     * @return the given name
      */
-    std::string name() const { return port.name(); }
+    std::string name() const { return _name; }
 
     /**
      * Enter this generator state.
@@ -110,9 +108,11 @@
     virtual void enter() = 0;
 
     /**
-     * Execute this generator state.
+     * Get the next generated packet.
+     *
+     * @return A packet to be sent at the current tick
      */
-    virtual void execute() = 0;
+    virtual PacketPtr getNextPacket() = 0;
 
     /**
      * Exit this generator state. By default do nothing.
@@ -120,13 +120,13 @@
     virtual void exit() { };
 
     /**
-     * Determine the next execute tick. MaxTick means that
-     * there will not be any further event in the current
-     * activation cycle of the state.
+     * Determine the tick when the next packet is available. MaxTick
+     * means that there will not be any further packets in the current
+     * activation cycle of the generator.
      *
-     * @return next tick when the state should be executed
+     * @return next tick when a packet is available
      */
-    virtual Tick nextExecuteTick() = 0;
+    virtual Tick nextPacketTick() = 0;
 
 };
 
@@ -138,16 +138,15 @@
 
   public:
 
-    IdleGen(QueuedMasterPort& _port, MasterID master_id,
-            Tick _duration)
-        : BaseGen(_port, master_id, _duration)
+    IdleGen(const std::string& _name, MasterID master_id, Tick _duration)
+        : BaseGen(_name, master_id, _duration)
     { }
 
     void enter() { }
 
-    void execute() { }
+    PacketPtr getNextPacket() { return NULL; }
 
-    Tick nextExecuteTick() { return MaxTick; }
+    Tick nextPacketTick() { return MaxTick; }
 };
 
 /**
@@ -167,7 +166,7 @@
      * min_period == max_period for a fixed inter-transaction
      * time.
      *
-     * @param _port port used to send requests
+     * @param _name Name to use for status and debug
      * @param master_id MasterID set on each request
      * @param _duration duration of this state before transitioning
      * @param start_addr Start address
@@ -178,11 +177,11 @@
      * @param read_percent Percent of transactions that are reads
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to