Mahyar Samani has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/31855 )
Change subject: mem: Adding DRAMSim3 source code
......................................................................
mem: Adding DRAMSim3 source code
Change-Id: I3e435732a495759a4001c620d89a97572041338a
---
M .gitignore
A ext/dramsim3/README
A ext/dramsim3/SConscript
A src/mem/DRAMSim3.py
A src/mem/dramsim3.cc
A src/mem/dramsim3.hh
A src/mem/dramsim3_wrapper.cc
A src/mem/dramsim3_wrapper.hh
8 files changed, 1,049 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore
index a195609..679c9f7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -10,6 +10,7 @@
m5out
/src/doxygen/html
/ext/dramsim2/DRAMSim2
+/ext/dramsim3/DRAMSim3
/ext/mcpat/regression/*/*.out
/util/m5/*.o
/util/m5/*.a
diff --git a/ext/dramsim3/README b/ext/dramsim3/README
new file mode 100644
index 0000000..8fd503c
--- /dev/null
+++ b/ext/dramsim3/README
@@ -0,0 +1,15 @@
+Follow these steps to get DRAMSim3 as part of gem5
+
+1. Download DRAMSim3
+ 1.1 Go to ext/dramsim3 (this directory)
+ 1.2 Clone DRAMSim3: git clone [email protected]:shavvn/DRAMSim3.git
+ 1.3 mkdir build
+ 1.4 cd build
+ 1.5 cmake ../
+ 1.6 make
+
+2. Compile gem5
+ 2.1 Business as usual
+
+3. Run gem5 with DRAMSim3
+ 3.1 Use --mem-type=dramsim3 and set the device and system configuration
diff --git a/ext/dramsim3/SConscript b/ext/dramsim3/SConscript
new file mode 100644
index 0000000..510cf4d
--- /dev/null
+++ b/ext/dramsim3/SConscript
@@ -0,0 +1,66 @@
+# -*- mode:python -*-
+
+# Copyright (c) 2013 ARM Limited
+# All rights reserved.
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder. You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Authors: Andreas Hansson
+
+import os
+
+Import('main')
+
+# See if we got a cloned DRAMSim3 repo as a subdirectory and set the
+# HAVE_DRAMSIM flag accordingly
+if not os.path.exists(Dir('.').srcnode().abspath + '/DRAMSim3'):
+ main['HAVE_DRAMSIM3'] = False
+ Return()
+
+# We have got the folder, so add the library and build the wrappers
+main['HAVE_DRAMSIM3'] = True
+
+# Add the appropriate files. We leave out the trace driven simulator
+dram_files = []
+
+dram_path = os.path.join(Dir('#').abspath, 'ext/dramsim3/DRAMSim3')
+
+dramsim_lib_path = os.path.join(dram_path, 'build')
+superlu_path = os.path.join(dram_path, 'ext/SuperLU_MT_3.1/lib')
+
+
+main.Prepend(CPPPATH=Dir('.'))
+main.Append(LIBS=['dramsim3', 'superlu_mt_OPENMP', 'm', 'f77blas',
+ 'atlas', 'gomp'],
+ LIBPATH=[dramsim_lib_path, superlu_path])
+
diff --git a/src/mem/DRAMSim3.py b/src/mem/DRAMSim3.py
new file mode 100644
index 0000000..45feab0
--- /dev/null
+++ b/src/mem/DRAMSim3.py
@@ -0,0 +1,52 @@
+# Copyright (c) 2013 ARM Limited
+# All rights reserved.
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder. You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+# Authors: Andreas Hansson
+
+from m5.params import *
+from AbstractMemory import *
+
+# A wrapper for DRAMSim2 multi-channel memory controller
+class DRAMSim3(AbstractMemory):
+ type = 'DRAMSim3'
+ cxx_header = "mem/dramsim3.hh"
+
+ # A single port for now
+ port = SlavePort("Slave port")
+
+ deviceConfigFile = Param.String("configs/DDR4_8Gb_x8_2400.ini",
+ "One configuration file")
+ filePath = Param.String("ext/dramsim3/DRAMSim3/",
+ "Directory to prepend to file names")
diff --git a/src/mem/dramsim3.cc b/src/mem/dramsim3.cc
new file mode 100644
index 0000000..26212e3
--- /dev/null
+++ b/src/mem/dramsim3.cc
@@ -0,0 +1,395 @@
+/*
+ * Copyright (c) 2013 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Andreas Hansson
+ */
+
+#include "mem/dramsim3.hh"
+
+#include "base/callback.hh"
+#include "base/trace.hh"
+#include "debug/DRAMSim3.hh"
+#include "debug/Drain.hh"
+#include "sim/system.hh"
+
+DRAMSim3::DRAMSim3(const Params* p) :
+ AbstractMemory(p),
+ port(name() + ".port", *this),
+ wrapper(p->deviceConfigFile, p->filePath, NULL, NULL),
+ retryReq(false), retryResp(false), startTick(0),
+ nbrOutstandingReads(0), nbrOutstandingWrites(0),
+ sendResponseEvent([this]{ sendResponse(); }, name()),
+ tickEvent([this]{ tick(); }, name())
+{
+ read_cb =
+ std::bind(&DRAMSim3::readComplete, this, 0, std::placeholders::_1);
+ write_cb =
+ std::bind(&DRAMSim3::writeComplete, this, 0,
std::placeholders::_1);
+ wrapper.setCallbacks(read_cb, write_cb);
+
+ DPRINTF(DRAMSim3,
+ "Instantiated DRAMSim3 with clock %d ns and queue size %d\n",
+ wrapper.clockPeriod(), wrapper.queueSize());
+
+ // Register a callback to compensate for the destructor not
+ // being called. The callback prints the DRAMSim3 stats.
+ Callback* cb = new MakeCallback<DRAMSim3Wrapper,
+ &DRAMSim3Wrapper::printStats>(wrapper);
+ registerExitCallback(cb);
+}
+
+void
+DRAMSim3::init()
+{
+ AbstractMemory::init();
+
+ if (!port.isConnected()) {
+ fatal("DRAMSim3 %s is unconnected!\n", name());
+ } else {
+ port.sendRangeChange();
+ }
+
+ if (system()->cacheLineSize() != wrapper.burstSize())
+ fatal("DRAMSim3 burst size %d does not match cache line size %d\n",
+ wrapper.burstSize(), system()->cacheLineSize());
+}
+
+void
+DRAMSim3::startup()
+{
+ startTick = curTick();
+
+ // kick off the clock ticks
+ schedule(tickEvent, clockEdge());
+}
+
+void
+DRAMSim3::sendResponse()
+{
+ assert(!retryResp);
+ assert(!responseQueue.empty());
+
+ DPRINTF(DRAMSim3, "Attempting to send response\n");
+
+ bool success = port.sendTimingResp(responseQueue.front());
+ if (success) {
+ responseQueue.pop_front();
+
+ DPRINTF(DRAMSim3, "Have %d read, %d write, %d responses
outstanding\n",
+ nbrOutstandingReads, nbrOutstandingWrites,
+ responseQueue.size());
+
+ if (!responseQueue.empty() && !sendResponseEvent.scheduled())
+ schedule(sendResponseEvent, curTick());
+
+ if (nbrOutstanding() == 0)
+ signalDrainDone();
+ } else {
+ retryResp = true;
+
+ DPRINTF(DRAMSim3, "Waiting for response retry\n");
+
+ assert(!sendResponseEvent.scheduled());
+ }
+}
+
+unsigned int
+DRAMSim3::nbrOutstanding() const
+{
+ return nbrOutstandingReads + nbrOutstandingWrites +
responseQueue.size();
+}
+
+void
+DRAMSim3::tick()
+{
+ wrapper.tick();
+
+ // is the connected port waiting for a retry, if so check the
+ // state and send a retry if conditions have changed
+ if (retryReq && nbrOutstanding() < wrapper.queueSize()) {
+ retryReq = false;
+ port.sendRetryReq();
+ }
+
+ schedule(tickEvent, curTick() + wrapper.clockPeriod() *
SimClock::Int::ns);
+}
+
+Tick
+DRAMSim3::recvAtomic(PacketPtr pkt)
+{
+ access(pkt);
+
+ // 50 ns is just an arbitrary value at this point
+ return pkt->cacheResponding() ? 0 : 50000;
+}
+
+void
+DRAMSim3::recvFunctional(PacketPtr pkt)
+{
+ pkt->pushLabel(name());
+
+ functionalAccess(pkt);
+
+ // potentially update the packets in our response queue as well
+ for (auto i = responseQueue.begin(); i != responseQueue.end(); ++i)
+ pkt->checkFunctional(*i);
+
+ pkt->popLabel();
+}
+
+bool
+DRAMSim3::recvTimingReq(PacketPtr pkt)
+{
+ // if a cache is responding, sink the packet without further action
+ if (pkt->cacheResponding()) {
+ pendingDelete.reset(pkt);
+ return true;
+ }
+
+ // we should not get a new request after committing to retry the
+ // current one, but unfortunately the CPU violates this rule, so
+ // simply ignore it for now
+ if (retryReq)
+ return false;
+
+ // if we cannot accept we need to send a retry once progress can
+ // be made
+ bool can_accept = nbrOutstanding() < wrapper.queueSize();
+
+ // keep track of the transaction
+ if (pkt->isRead()) {
+ if (can_accept) {
+ outstandingReads[pkt->getAddr()].push(pkt);
+
+ // we count a transaction as outstanding until it has left the
+ // queue in the controller, and the response has been sent
+ // back, note that this will differ for reads and writes
+ ++nbrOutstandingReads;
+ }
+ } else if (pkt->isWrite()) {
+ if (can_accept) {
+ outstandingWrites[pkt->getAddr()].push(pkt);
+
+ ++nbrOutstandingWrites;
+
+ // perform the access for writes
+ accessAndRespond(pkt);
+ }
+ } else {
+ // keep it simple and just respond if necessary
+ accessAndRespond(pkt);
+ return true;
+ }
+
+ if (can_accept) {
+ // we should never have a situation when we think there is space,
+ // and there isn't
+ assert(wrapper.canAccept());
+
+ DPRINTF(DRAMSim3, "Enqueueing address %lld\n", pkt->getAddr());
+
+ // @todo what about the granularity here, implicit assumption that
+ // a transaction matches the burst size of the memory (which we
+ // cannot determine without parsing the ini file ourselves)
+ wrapper.enqueue(pkt->isWrite(), pkt->getAddr());
+
+ return true;
+ } else {
+ retryReq = true;
+ return false;
+ }
+}
+
+void
+DRAMSim3::recvRespRetry()
+{
+ DPRINTF(DRAMSim3, "Retrying\n");
+
+ assert(retryResp);
+ retryResp = false;
+ sendResponse();
+}
+
+void
+DRAMSim3::accessAndRespond(PacketPtr pkt)
+{
+ DPRINTF(DRAMSim3, "Access for address %lld\n", pkt->getAddr());
+
+ bool needsResponse = pkt->needsResponse();
+
+ // do the actual memory access which also turns the packet into a
+ // response
+ access(pkt);
+
+ // turn packet around to go back to requester if response expected
+ if (needsResponse) {
+ // access already turned the packet into a response
+ assert(pkt->isResponse());
+ // Here we pay for xbar additional delay and to process the payload
+ // of the packet.
+ Tick time = curTick() + pkt->headerDelay + pkt->payloadDelay;
+ // Reset the timings of the packet
+ pkt->headerDelay = pkt->payloadDelay = 0;
+
+ DPRINTF(DRAMSim3, "Queuing response for address %lld\n",
+ pkt->getAddr());
+
+ // queue it to be sent back
+ responseQueue.push_back(pkt);
+
+ // if we are not already waiting for a retry, or are scheduled
+ // to send a response, schedule an event
+ if (!retryResp && !sendResponseEvent.scheduled())
+ schedule(sendResponseEvent, time);
+ } else {
+ // queue the packet for deletion
+ pendingDelete.reset(pkt);
+ }
+}
+
+void DRAMSim3::readComplete(unsigned id, uint64_t addr)
+{
+ // assert(cycle == divCeil(curTick() - startTick,
+ // wrapper.clockPeriod() * SimClock::Int::ns));
+
+ DPRINTF(DRAMSim3, "Read to address %lld complete\n", addr);
+
+ // get the outstanding reads for the address in question
+ auto p = outstandingReads.find(addr);
+ assert(p != outstandingReads.end());
+
+ // first in first out, which is not necessarily true, but it is
+ // the best we can do at this point
+ PacketPtr pkt = p->second.front();
+ p->second.pop();
+
+ if (p->second.empty())
+ outstandingReads.erase(p);
+
+ // no need to check for drain here as the next call will add a
+ // response to the response queue straight away
+ assert(nbrOutstandingReads != 0);
+ --nbrOutstandingReads;
+
+ // perform the actual memory access
+ accessAndRespond(pkt);
+}
+
+void DRAMSim3::writeComplete(unsigned id, uint64_t addr)
+{
+ // assert(cycle == divCeil(curTick() - startTick,
+ // wrapper.clockPeriod() * SimClock::Int::ns));
+
+ DPRINTF(DRAMSim3, "Write to address %lld complete\n", addr);
+
+ // get the outstanding reads for the address in question
+ auto p = outstandingWrites.find(addr);
+ assert(p != outstandingWrites.end());
+
+ // we have already responded, and this is only to keep track of
+ // what is outstanding
+ p->second.pop();
+ if (p->second.empty())
+ outstandingWrites.erase(p);
+
+ assert(nbrOutstandingWrites != 0);
+ --nbrOutstandingWrites;
+
+ if (nbrOutstanding() == 0)
+ signalDrainDone();
+}
+
+BaseSlavePort&
+DRAMSim3::getSlavePort(const std::string &if_name, PortID idx)
+{
+ if (if_name != "port") {
+ return MemObject::getSlavePort(if_name, idx);
+ } else {
+ return port;
+ }
+}
+
+DrainState
+DRAMSim3::drain()
+{
+ // check our outstanding reads and writes and if any they need to
+ // drain
+ return nbrOutstanding() != 0 ? DrainState::Draining :
DrainState::Drained;
+}
+
+DRAMSim3::MemoryPort::MemoryPort(const std::string& _name,
+ DRAMSim3& _memory)
+ : SlavePort(_name, &_memory), memory(_memory)
+{ }
+
+AddrRangeList
+DRAMSim3::MemoryPort::getAddrRanges() const
+{
+ AddrRangeList ranges;
+ ranges.push_back(memory.getAddrRange());
+ return ranges;
+}
+
+Tick
+DRAMSim3::MemoryPort::recvAtomic(PacketPtr pkt)
+{
+ return memory.recvAtomic(pkt);
+}
+
+void
+DRAMSim3::MemoryPort::recvFunctional(PacketPtr pkt)
+{
+ memory.recvFunctional(pkt);
+}
+
+bool
+DRAMSim3::MemoryPort::recvTimingReq(PacketPtr pkt)
+{
+ // pass it to the memory controller
+ return memory.recvTimingReq(pkt);
+}
+
+void
+DRAMSim3::MemoryPort::recvRespRetry()
+{
+ memory.recvRespRetry();
+}
+
+DRAMSim3*
+DRAMSim3Params::create()
+{
+ return new DRAMSim3(this);
+}
diff --git a/src/mem/dramsim3.hh b/src/mem/dramsim3.hh
new file mode 100644
index 0000000..48c28d6
--- /dev/null
+++ b/src/mem/dramsim3.hh
@@ -0,0 +1,216 @@
+/*
+ * Copyright (c) 2013 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Andreas Hansson
+ */
+
+/**
+ * @file
+ * DRAMSim3
+ */
+#ifndef __MEM_DRAMSIM3_HH__
+#define __MEM_DRAMSIM3_HH__
+
+#include <functional>
+#include <queue>
+#include <unordered_map>
+
+#include "mem/abstract_mem.hh"
+#include "mem/dramsim3_wrapper.hh"
+#include "mem/qport.hh"
+#include "params/DRAMSim3.hh"
+
+class DRAMSim3 : public AbstractMemory
+{
+ private:
+
+ /**
+ * The memory port has to deal with its own flow control to avoid
+ * having unbounded storage that is implicitly created in the port
+ * itself.
+ */
+ class MemoryPort : public SlavePort
+ {
+
+ private:
+
+ DRAMSim3& memory;
+
+ public:
+
+ MemoryPort(const std::string& _name, DRAMSim3& _memory);
+
+ protected:
+
+ Tick recvAtomic(PacketPtr pkt);
+
+ void recvFunctional(PacketPtr pkt);
+
+ bool recvTimingReq(PacketPtr pkt);
+
+ void recvRespRetry();
+
+ AddrRangeList getAddrRanges() const;
+
+ };
+
+ MemoryPort port;
+
+ /**
+ * The actual DRAMSim3 wrapper
+ */
+ DRAMSim3Wrapper wrapper;
+
+ /**
+ * Is the connected port waiting for a retry from us
+ */
+ bool retryReq;
+
+ /**
+ * Are we waiting for a retry for sending a response.
+ */
+ bool retryResp;
+
+ /**
+ * Keep track of when the wrapper is started.
+ */
+ Tick startTick;
+
+ /**
+ * Keep track of what packets are outstanding per
+ * address, and do so separately for reads and writes. This is
+ * done so that we can return the right packet on completion from
+ * DRAMSim.
+ */
+ std::unordered_map<Addr, std::queue<PacketPtr> > outstandingReads;
+ std::unordered_map<Addr, std::queue<PacketPtr> > outstandingWrites;
+
+ /**
+ * Count the number of outstanding transactions so that we can
+ * block any further requests until there is space in DRAMSim3 and
+ * the sending queue we need to buffer the response packets.
+ */
+ unsigned int nbrOutstandingReads;
+ unsigned int nbrOutstandingWrites;
+
+ /**
+ * Queue to hold response packets until we can send them
+ * back. This is needed as DRAMSim3 unconditionally passes
+ * responses back without any flow control.
+ */
+ std::deque<PacketPtr> responseQueue;
+
+ /**
+ * Callback functions
+ */
+ std::function<void(uint64_t)> read_cb;
+ std::function<void(uint64_t)> write_cb;
+
+ unsigned int nbrOutstanding() const;
+
+ /**
+ * When a packet is ready, use the "access()" method in
+ * AbstractMemory to actually create the response packet, and send
+ * it back to the outside world requestor.
+ *
+ * @param pkt The packet from the outside world
+ */
+ void accessAndRespond(PacketPtr pkt);
+
+ void sendResponse();
+
+ /**
+ * Event to schedule sending of responses
+ */
+ EventFunctionWrapper sendResponseEvent;
+
+ /**
+ * Progress the controller one clock cycle.
+ */
+ void tick();
+
+ /**
+ * Event to schedule clock ticks
+ */
+ EventFunctionWrapper tickEvent;
+
+ /**
+ * Upstream caches need this packet until true is returned, so
+ * hold it for deletion until a subsequent call
+ */
+ std::unique_ptr<Packet> pendingDelete;
+
+ public:
+
+ typedef DRAMSim3Params Params;
+ DRAMSim3(const Params *p);
+
+ /**
+ * Read completion callback.
+ *
+ * @param id Channel id of the responder
+ * @param addr Address of the request
+ * @param cycle Internal cycle count of DRAMSim3
+ */
+ void readComplete(unsigned id, uint64_t addr);
+
+ /**
+ * Write completion callback.
+ *
+ * @param id Channel id of the responder
+ * @param addr Address of the request
+ * @param cycle Internal cycle count of DRAMSim3
+ */
+ void writeComplete(unsigned id, uint64_t addr);
+
+ DrainState drain() override;
+
+ virtual BaseSlavePort& getSlavePort(const std::string& if_name,
+ PortID idx = InvalidPortID)
override;
+
+ void init() override;
+ void startup() override;
+
+ protected:
+
+ Tick recvAtomic(PacketPtr pkt);
+ void recvFunctional(PacketPtr pkt);
+ bool recvTimingReq(PacketPtr pkt);
+ void recvRespRetry();
+
+};
+
+#endif // __MEM_DRAMSIM3_HH__
diff --git a/src/mem/dramsim3_wrapper.cc b/src/mem/dramsim3_wrapper.cc
new file mode 100644
index 0000000..08f78aa
--- /dev/null
+++ b/src/mem/dramsim3_wrapper.cc
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2013 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Andreas Hansson
+ */
+
+#include <cassert>
+
+/**
+ * When building the debug binary, we need to undo the command-line
+ * definition of DEBUG not to clash with DRAMSim3 print macros that
+ * are included for no obvious reason.
+ */
+#ifdef DEBUG
+#undef DEBUG
+#endif
+
+#include "mem/dramsim3_wrapper.hh"
+
+#include <fstream>
+
+#include "DRAMSim3/src/memory_system.h"
+#include "base/compiler.hh"
+#include "base/logging.hh"
+
+DRAMSim3Wrapper::DRAMSim3Wrapper(const std::string& config_file,
+ const std::string& working_dir,
+ std::function<void(uint64_t)> read_cb,
+ std::function<void(uint64_t)> write_cb) :
+ dramsim(new dramsim3::MemorySystem(config_file, working_dir,
+ read_cb, write_cb)),
+ _clockPeriod(0.0), _queueSize(0), _burstSize(0)
+{
+ // there is no way of getting DRAMSim3 to tell us what frequency
+ // it is assuming, so we have to extract it ourselves
+ _clockPeriod = dramsim->GetTCK();
+
+ if (!_clockPeriod)
+ fatal("DRAMSim3 wrapper failed to get clock\n");
+
+ // we also need to know what transaction queue size DRAMSim3 is
+ // using so we can stall when responses are blocked
+ _queueSize = dramsim->GetQueueSize();
+
+ if (!_queueSize)
+ fatal("DRAMSim3 wrapper failed to get queue size\n");
+
+
+ // finally, get the data bus bits and burst length so we can add a
+ // sanity check for the burst size
+ unsigned int dataBusBits = dramsim->GetBusBits();
+ unsigned int burstLength = dramsim->GetBurstLength();
+
+ if (!dataBusBits || !burstLength)
+ fatal("DRAMSim3 wrapper failed to get burst size\n");
+
+ _burstSize = dataBusBits * burstLength / 8;
+}
+
+DRAMSim3Wrapper::~DRAMSim3Wrapper()
+{
+ delete dramsim;
+}
+
+
+void
+DRAMSim3Wrapper::printStats()
+{
+ dramsim->PrintStats();
+}
+
+void
+DRAMSim3Wrapper::setCallbacks(std::function<void(uint64_t)> read_complete,
+ std::function<void(uint64_t)> write_complete)
+{
+ dramsim->RegisterCallbacks(read_complete, write_complete);
+}
+
+bool
+DRAMSim3Wrapper::canAccept() const
+{
+ return dramsim->IsInsertable();
+}
+
+void
+DRAMSim3Wrapper::enqueue(bool is_write, uint64_t addr)
+{
+ bool success M5_VAR_USED = dramsim->InsertRequest(is_write, addr);
+ assert(success);
+}
+
+double
+DRAMSim3Wrapper::clockPeriod() const
+{
+ return _clockPeriod;
+}
+
+unsigned int
+DRAMSim3Wrapper::queueSize() const
+{
+ return _queueSize;
+}
+
+unsigned int
+DRAMSim3Wrapper::burstSize() const
+{
+ return _burstSize;
+}
+
+void
+DRAMSim3Wrapper::tick()
+{
+ dramsim->ClockTick();
+}
+
diff --git a/src/mem/dramsim3_wrapper.hh b/src/mem/dramsim3_wrapper.hh
new file mode 100644
index 0000000..03e0ad5
--- /dev/null
+++ b/src/mem/dramsim3_wrapper.hh
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2013 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are
+ * met: redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer;
+ * redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution;
+ * neither the name of the copyright holders nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Authors: Andreas Hansson
+ */
+
+/**
+ * @file
+ * DRAMSim3Wrapper declaration
+ */
+
+#ifndef __MEM_DRAMSIM3_WRAPPER_HH__
+#define __MEM_DRAMSIM3_WRAPPER_HH__
+
+#include <functional>
+#include <string>
+
+/**
+ * Forward declaration to avoid includes
+ */
+namespace dramsim3 {
+
+class MemorySystem;
+
+}
+
+/**
+ * Wrapper class to avoid having DRAMSim3 names like ClockDomain etc
+ * clashing with the normal gem5 world. Many of the DRAMSim3 headers
+ * do not make use of namespaces, and quite a few also open up
+ * std. The only thing that needs to be exposed externally are the
+ * callbacks. This wrapper effectively avoids clashes by not including
+ * any of the conventional gem5 headers (e.g. Packet or SimObject).
+ */
+class DRAMSim3Wrapper
+{
+
+ private:
+
+ dramsim3::MemorySystem* dramsim;
+
+ double _clockPeriod;
+
+ unsigned int _queueSize;
+
+ unsigned int _burstSize;
+
+ template <typename T>
+ T extractConfig(const std::string& field_name,
+ const std::string& file_name) const;
+
+ public:
+
+ /**
+ * Create an instance of the DRAMSim3 multi-channel memory
+ * controller using a specific config and system description.
+ *
+ * @param config_file Memory config file
+ * @param working_dir Path pre-pended to config files
+ */
+ DRAMSim3Wrapper(const std::string& config_file,
+ const std::string& working_dir,
+ std::function<void(uint64_t)> read_cb,
+ std::function<void(uint64_t)> write_cb);
+ ~DRAMSim3Wrapper();
+
+ /**
+ * Print the stats gathered in DRAMsim3.
+ */
+ void printStats();
+
+ /**
+ * Set the callbacks to use for read and write completion.
+ *
+ * @param read_callback Callback used for read completions
+ * @param write_callback Callback used for write completions
+ */
+ void setCallbacks(std::function<void(uint64_t)> read_complete,
+ std::function<void(uint64_t)> write_complete);
+
+ /**
+ * Determine if the controller can accept a new packet or not.
+ *
+ * @return true if the controller can accept transactions
+ */
+ bool canAccept() const;
+
+ /**
+ * Enqueue a packet. This assumes that canAccept has returned true.
+ *
+ * @param pkt Packet to turn into a DRAMSim3 transaction
+ */
+ void enqueue(bool is_write, uint64_t addr);
+
+ /**
+ * Get the internal clock period used by DRAMSim3, specified in
+ * ns.
+ *
+ * @return The clock period of the DRAM interface in ns
+ */
+ double clockPeriod() const;
+
+ /**
+ * Get the transaction queue size used by DRAMSim3.
+ *
+ * @return The queue size counted in number of transactions
+ */
+ unsigned int queueSize() const;
+
+ /**
+ * Get the burst size in bytes used by DRAMSim3.
+ *
+ * @return The burst size in bytes (data width * burst length)
+ */
+ unsigned int burstSize() const;
+
+ /**
+ * Progress the memory controller one cycle
+ */
+ void tick();
+};
+
+#endif //__MEM_DRAMSIM3_WRAPPER_HH__
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/31855
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I3e435732a495759a4001c620d89a97572041338a
Gerrit-Change-Number: 31855
Gerrit-PatchSet: 1
Gerrit-Owner: Mahyar Samani <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s