2012-09-21 17:48:13 +02:00
|
|
|
/*
|
2013-08-19 09:52:31 +02:00
|
|
|
* Copyright (c) 2010-2013 ARM Limited
|
2012-09-21 17:48:13 +02:00
|
|
|
* 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.
|
|
|
|
*
|
2013-08-19 09:52:30 +02:00
|
|
|
* Copyright (c) 2013 Amin Farmahini-Farahani
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
2012-09-21 17:48:13 +02:00
|
|
|
* 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
|
|
|
|
* Ani Udipi
|
2013-11-01 16:56:20 +01:00
|
|
|
* Neha Agarwal
|
2012-09-21 17:48:13 +02:00
|
|
|
*/
|
|
|
|
|
2013-11-01 16:56:20 +01:00
|
|
|
#include "base/bitfield.hh"
|
2014-03-23 16:12:12 +01:00
|
|
|
#include "base/trace.hh"
|
2012-09-21 17:48:13 +02:00
|
|
|
#include "debug/DRAM.hh"
|
2014-03-23 16:12:12 +01:00
|
|
|
#include "debug/Drain.hh"
|
|
|
|
#include "mem/dram_ctrl.hh"
|
2013-07-18 14:31:16 +02:00
|
|
|
#include "sim/system.hh"
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::DRAMCtrl(const DRAMCtrlParams* p) :
|
2012-09-21 17:48:13 +02:00
|
|
|
AbstractMemory(p),
|
|
|
|
port(name() + ".port", *this),
|
|
|
|
retryRdReq(false), retryWrReq(false),
|
2013-11-01 16:56:22 +01:00
|
|
|
rowHitFlag(false), stopReads(false),
|
2012-09-21 17:48:13 +02:00
|
|
|
writeEvent(this), respondEvent(this),
|
2012-11-02 17:32:01 +01:00
|
|
|
refreshEvent(this), nextReqEvent(this), drainManager(NULL),
|
2013-08-19 09:52:30 +02:00
|
|
|
deviceBusWidth(p->device_bus_width), burstLength(p->burst_length),
|
|
|
|
deviceRowBufferSize(p->device_rowbuffer_size),
|
|
|
|
devicesPerRank(p->devices_per_rank),
|
|
|
|
burstSize((devicesPerRank * burstLength * deviceBusWidth) / 8),
|
|
|
|
rowBufferSize(devicesPerRank * deviceRowBufferSize),
|
2014-03-23 16:12:01 +01:00
|
|
|
columnsPerRowBuffer(rowBufferSize / burstSize),
|
2012-09-21 17:48:13 +02:00
|
|
|
ranksPerChannel(p->ranks_per_channel),
|
2013-03-01 19:20:22 +01:00
|
|
|
banksPerRank(p->banks_per_rank), channels(p->channels), rowsPerBank(0),
|
2012-09-21 17:48:13 +02:00
|
|
|
readBufferSize(p->read_buffer_size),
|
|
|
|
writeBufferSize(p->write_buffer_size),
|
2014-03-23 16:12:01 +01:00
|
|
|
writeHighThreshold(writeBufferSize * p->write_high_thresh_perc / 100.0),
|
|
|
|
writeLowThreshold(writeBufferSize * p->write_low_thresh_perc / 100.0),
|
2014-03-23 16:12:14 +01:00
|
|
|
minWritesPerSwitch(p->min_writes_per_switch),
|
|
|
|
writesThisTime(0), readsThisTime(0),
|
2012-09-21 17:48:13 +02:00
|
|
|
tWTR(p->tWTR), tBURST(p->tBURST),
|
2013-11-01 16:56:16 +01:00
|
|
|
tRCD(p->tRCD), tCL(p->tCL), tRP(p->tRP), tRAS(p->tRAS),
|
2013-11-01 16:56:24 +01:00
|
|
|
tRFC(p->tRFC), tREFI(p->tREFI), tRRD(p->tRRD),
|
2013-01-31 13:49:14 +01:00
|
|
|
tXAW(p->tXAW), activationLimit(p->activation_limit),
|
2012-09-21 17:48:13 +02:00
|
|
|
memSchedPolicy(p->mem_sched_policy), addrMapping(p->addr_mapping),
|
|
|
|
pageMgmt(p->page_policy),
|
2014-03-23 16:12:03 +01:00
|
|
|
maxAccessesPerRow(p->max_accesses_per_row),
|
2013-05-30 18:54:12 +02:00
|
|
|
frontendLatency(p->static_frontend_latency),
|
|
|
|
backendLatency(p->static_backend_latency),
|
2014-03-23 16:12:06 +01:00
|
|
|
busBusyUntil(0), prevArrival(0),
|
2014-03-23 16:12:01 +01:00
|
|
|
newTime(0), startTickPrechargeAll(0), numBanksActive(0)
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
|
|
|
// create the bank states based on the dimensions of the ranks and
|
|
|
|
// banks
|
|
|
|
banks.resize(ranksPerChannel);
|
2013-11-01 16:56:22 +01:00
|
|
|
actTicks.resize(ranksPerChannel);
|
2012-09-21 17:48:13 +02:00
|
|
|
for (size_t c = 0; c < ranksPerChannel; ++c) {
|
|
|
|
banks[c].resize(banksPerRank);
|
2013-11-01 16:56:22 +01:00
|
|
|
actTicks[c].resize(activationLimit, 0);
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
|
2014-03-23 16:12:01 +01:00
|
|
|
// perform a basic check of the write thresholds
|
|
|
|
if (p->write_low_thresh_perc >= p->write_high_thresh_perc)
|
|
|
|
fatal("Write buffer low threshold %d must be smaller than the "
|
|
|
|
"high threshold %d\n", p->write_low_thresh_perc,
|
|
|
|
p->write_high_thresh_perc);
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
// determine the rows per bank by looking at the total capacity
|
2013-03-01 19:20:24 +01:00
|
|
|
uint64_t capacity = ULL(1) << ceilLog2(AbstractMemory::size());
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
DPRINTF(DRAM, "Memory capacity %lld (%lld) bytes\n", capacity,
|
|
|
|
AbstractMemory::size());
|
2013-08-19 09:52:30 +02:00
|
|
|
|
|
|
|
DPRINTF(DRAM, "Row buffer size %d bytes with %d columns per row buffer\n",
|
|
|
|
rowBufferSize, columnsPerRowBuffer);
|
|
|
|
|
|
|
|
rowsPerBank = capacity / (rowBufferSize * banksPerRank * ranksPerChannel);
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-03-01 19:20:22 +01:00
|
|
|
if (range.interleaved()) {
|
|
|
|
if (channels != range.stripes())
|
2014-03-23 16:12:06 +01:00
|
|
|
fatal("%s has %d interleaved address stripes but %d channel(s)\n",
|
2013-03-01 19:20:22 +01:00
|
|
|
name(), range.stripes(), channels);
|
|
|
|
|
2014-03-23 16:11:53 +01:00
|
|
|
if (addrMapping == Enums::RoRaBaChCo) {
|
2013-08-19 09:52:30 +02:00
|
|
|
if (rowBufferSize != range.granularity()) {
|
2014-03-23 16:12:06 +01:00
|
|
|
fatal("Interleaving of %s doesn't match RoRaBaChCo "
|
2014-03-23 16:11:53 +01:00
|
|
|
"address map\n", name());
|
2013-03-01 19:20:22 +01:00
|
|
|
}
|
2014-03-23 16:11:53 +01:00
|
|
|
} else if (addrMapping == Enums::RoRaBaCoCh) {
|
|
|
|
if (system()->cacheLineSize() != range.granularity()) {
|
2014-03-23 16:12:06 +01:00
|
|
|
fatal("Interleaving of %s doesn't match RoRaBaCoCh "
|
2014-03-23 16:11:53 +01:00
|
|
|
"address map\n", name());
|
2013-04-22 19:20:34 +02:00
|
|
|
}
|
2014-03-23 16:11:53 +01:00
|
|
|
} else if (addrMapping == Enums::RoCoRaBaCh) {
|
|
|
|
if (system()->cacheLineSize() != range.granularity())
|
2014-03-23 16:12:06 +01:00
|
|
|
fatal("Interleaving of %s doesn't match RoCoRaBaCh "
|
2014-03-23 16:11:53 +01:00
|
|
|
"address map\n", name());
|
2013-03-01 19:20:22 +01:00
|
|
|
}
|
|
|
|
}
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
|
2014-03-23 16:12:01 +01:00
|
|
|
void
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::init()
|
2014-03-23 16:12:01 +01:00
|
|
|
{
|
|
|
|
if (!port.isConnected()) {
|
2014-03-23 16:12:12 +01:00
|
|
|
fatal("DRAMCtrl %s is unconnected!\n", name());
|
2014-03-23 16:12:01 +01:00
|
|
|
} else {
|
|
|
|
port.sendRangeChange();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-21 17:48:13 +02:00
|
|
|
void
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::startup()
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
2014-03-23 16:12:06 +01:00
|
|
|
// update the start tick for the precharge accounting to the
|
|
|
|
// current tick
|
|
|
|
startTickPrechargeAll = curTick();
|
|
|
|
|
2012-09-21 17:48:13 +02:00
|
|
|
// print the configuration of the controller
|
|
|
|
printParams();
|
|
|
|
|
|
|
|
// kick off the refresh
|
2013-03-01 19:20:24 +01:00
|
|
|
schedule(refreshEvent, curTick() + tREFI);
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Tick
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::recvAtomic(PacketPtr pkt)
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
|
|
|
DPRINTF(DRAM, "recvAtomic: %s 0x%x\n", pkt->cmdString(), pkt->getAddr());
|
|
|
|
|
|
|
|
// do the actual memory access and turn the packet into a response
|
|
|
|
access(pkt);
|
|
|
|
|
|
|
|
Tick latency = 0;
|
|
|
|
if (!pkt->memInhibitAsserted() && pkt->hasData()) {
|
|
|
|
// this value is not supposed to be accurate, just enough to
|
|
|
|
// keep things going, mimic a closed page
|
|
|
|
latency = tRP + tRCD + tCL;
|
|
|
|
}
|
|
|
|
return latency;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::readQueueFull(unsigned int neededEntries) const
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
2013-08-19 09:52:30 +02:00
|
|
|
DPRINTF(DRAM, "Read queue limit %d, current size %d, entries needed %d\n",
|
|
|
|
readBufferSize, readQueue.size() + respQueue.size(),
|
|
|
|
neededEntries);
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-08-19 09:52:30 +02:00
|
|
|
return
|
|
|
|
(readQueue.size() + respQueue.size() + neededEntries) > readBufferSize;
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::writeQueueFull(unsigned int neededEntries) const
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
2013-08-19 09:52:30 +02:00
|
|
|
DPRINTF(DRAM, "Write queue limit %d, current size %d, entries needed %d\n",
|
|
|
|
writeBufferSize, writeQueue.size(), neededEntries);
|
|
|
|
return (writeQueue.size() + neededEntries) > writeBufferSize;
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::DRAMPacket*
|
|
|
|
DRAMCtrl::decodeAddr(PacketPtr pkt, Addr dramPktAddr, unsigned size,
|
2014-03-23 16:12:06 +01:00
|
|
|
bool isRead)
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
2013-04-22 19:20:34 +02:00
|
|
|
// decode the address based on the address mapping scheme, with
|
2014-03-23 16:11:53 +01:00
|
|
|
// Ro, Ra, Co, Ba and Ch denoting row, rank, column, bank and
|
|
|
|
// channel, respectively
|
2012-09-21 17:48:13 +02:00
|
|
|
uint8_t rank;
|
2013-11-01 16:56:20 +01:00
|
|
|
uint8_t bank;
|
2012-09-21 17:48:13 +02:00
|
|
|
uint16_t row;
|
|
|
|
|
|
|
|
// truncate the address to the access granularity
|
2013-08-19 09:52:30 +02:00
|
|
|
Addr addr = dramPktAddr / burstSize;
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-01-31 13:49:18 +01:00
|
|
|
// we have removed the lowest order address bits that denote the
|
2013-08-19 09:52:30 +02:00
|
|
|
// position within the column
|
2014-03-23 16:11:53 +01:00
|
|
|
if (addrMapping == Enums::RoRaBaChCo) {
|
2013-01-31 13:49:18 +01:00
|
|
|
// the lowest order bits denote the column to ensure that
|
|
|
|
// sequential cache lines occupy the same row
|
2013-08-19 09:52:30 +02:00
|
|
|
addr = addr / columnsPerRowBuffer;
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-04-22 19:20:34 +02:00
|
|
|
// take out the channel part of the address
|
|
|
|
addr = addr / channels;
|
|
|
|
|
|
|
|
// after the channel bits, get the bank bits to interleave
|
|
|
|
// over the banks
|
|
|
|
bank = addr % banksPerRank;
|
|
|
|
addr = addr / banksPerRank;
|
|
|
|
|
|
|
|
// after the bank, we get the rank bits which thus interleaves
|
|
|
|
// over the ranks
|
|
|
|
rank = addr % ranksPerChannel;
|
|
|
|
addr = addr / ranksPerChannel;
|
|
|
|
|
|
|
|
// lastly, get the row bits
|
|
|
|
row = addr % rowsPerBank;
|
|
|
|
addr = addr / rowsPerBank;
|
2014-03-23 16:11:53 +01:00
|
|
|
} else if (addrMapping == Enums::RoRaBaCoCh) {
|
2013-04-22 19:20:34 +02:00
|
|
|
// take out the channel part of the address
|
2013-03-01 19:20:22 +01:00
|
|
|
addr = addr / channels;
|
|
|
|
|
2013-04-22 19:20:34 +02:00
|
|
|
// next, the column
|
2013-08-19 09:52:30 +02:00
|
|
|
addr = addr / columnsPerRowBuffer;
|
2013-04-22 19:20:34 +02:00
|
|
|
|
|
|
|
// after the column bits, we get the bank bits to interleave
|
2013-01-31 13:49:18 +01:00
|
|
|
// over the banks
|
2012-09-21 17:48:13 +02:00
|
|
|
bank = addr % banksPerRank;
|
|
|
|
addr = addr / banksPerRank;
|
|
|
|
|
2013-01-31 13:49:18 +01:00
|
|
|
// after the bank, we get the rank bits which thus interleaves
|
|
|
|
// over the ranks
|
2012-09-21 17:48:13 +02:00
|
|
|
rank = addr % ranksPerChannel;
|
|
|
|
addr = addr / ranksPerChannel;
|
|
|
|
|
2013-01-31 13:49:18 +01:00
|
|
|
// lastly, get the row bits
|
2012-09-21 17:48:13 +02:00
|
|
|
row = addr % rowsPerBank;
|
|
|
|
addr = addr / rowsPerBank;
|
2014-03-23 16:11:53 +01:00
|
|
|
} else if (addrMapping == Enums::RoCoRaBaCh) {
|
2013-01-31 13:49:18 +01:00
|
|
|
// optimise for closed page mode and utilise maximum
|
|
|
|
// parallelism of the DRAM (at the cost of power)
|
|
|
|
|
2013-03-01 19:20:22 +01:00
|
|
|
// take out the channel part of the address, not that this has
|
|
|
|
// to match with how accesses are interleaved between the
|
|
|
|
// controllers in the address mapping
|
|
|
|
addr = addr / channels;
|
|
|
|
|
2013-01-31 13:49:18 +01:00
|
|
|
// start with the bank bits, as this provides the maximum
|
|
|
|
// opportunity for parallelism between requests
|
2012-09-21 17:48:13 +02:00
|
|
|
bank = addr % banksPerRank;
|
|
|
|
addr = addr / banksPerRank;
|
|
|
|
|
2013-01-31 13:49:18 +01:00
|
|
|
// next get the rank bits
|
2012-09-21 17:48:13 +02:00
|
|
|
rank = addr % ranksPerChannel;
|
|
|
|
addr = addr / ranksPerChannel;
|
|
|
|
|
2013-01-31 13:49:18 +01:00
|
|
|
// next the column bits which we do not need to keep track of
|
|
|
|
// and simply skip past
|
2013-08-19 09:52:30 +02:00
|
|
|
addr = addr / columnsPerRowBuffer;
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-01-31 13:49:18 +01:00
|
|
|
// lastly, get the row bits
|
2012-09-21 17:48:13 +02:00
|
|
|
row = addr % rowsPerBank;
|
|
|
|
addr = addr / rowsPerBank;
|
|
|
|
} else
|
|
|
|
panic("Unknown address mapping policy chosen!");
|
|
|
|
|
|
|
|
assert(rank < ranksPerChannel);
|
|
|
|
assert(bank < banksPerRank);
|
|
|
|
assert(row < rowsPerBank);
|
|
|
|
|
|
|
|
DPRINTF(DRAM, "Address: %lld Rank %d Bank %d Row %d\n",
|
2013-08-19 09:52:30 +02:00
|
|
|
dramPktAddr, rank, bank, row);
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
// create the corresponding DRAM packet with the entry time and
|
2013-03-01 19:20:24 +01:00
|
|
|
// ready time set to the current tick, the latter will be updated
|
|
|
|
// later
|
2013-11-01 16:56:20 +01:00
|
|
|
uint16_t bank_id = banksPerRank * rank + bank;
|
|
|
|
return new DRAMPacket(pkt, isRead, rank, bank, row, bank_id, dramPktAddr,
|
|
|
|
size, banks[rank][bank]);
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::addToReadQueue(PacketPtr pkt, unsigned int pktCount)
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
|
|
|
// only add to the read queue here. whenever the request is
|
|
|
|
// eventually done, set the readyTime, and call schedule()
|
|
|
|
assert(!pkt->isWrite());
|
|
|
|
|
2013-08-19 09:52:30 +02:00
|
|
|
assert(pktCount != 0);
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-08-19 09:52:30 +02:00
|
|
|
// if the request size is larger than burst size, the pkt is split into
|
|
|
|
// multiple DRAM packets
|
|
|
|
// Note if the pkt starting address is not aligened to burst size, the
|
|
|
|
// address of first DRAM packet is kept unaliged. Subsequent DRAM packets
|
|
|
|
// are aligned to burst size boundaries. This is to ensure we accurately
|
|
|
|
// check read packets against packets in write queue.
|
|
|
|
Addr addr = pkt->getAddr();
|
|
|
|
unsigned pktsServicedByWrQ = 0;
|
|
|
|
BurstHelper* burst_helper = NULL;
|
|
|
|
for (int cnt = 0; cnt < pktCount; ++cnt) {
|
|
|
|
unsigned size = std::min((addr | (burstSize - 1)) + 1,
|
|
|
|
pkt->getAddr() + pkt->getSize()) - addr;
|
|
|
|
readPktSize[ceilLog2(size)]++;
|
|
|
|
readBursts++;
|
|
|
|
|
|
|
|
// First check write buffer to see if the data is already at
|
|
|
|
// the controller
|
|
|
|
bool foundInWrQ = false;
|
2013-08-19 09:52:32 +02:00
|
|
|
for (auto i = writeQueue.begin(); i != writeQueue.end(); ++i) {
|
2013-08-19 09:52:31 +02:00
|
|
|
// check if the read is subsumed in the write entry we are
|
|
|
|
// looking at
|
|
|
|
if ((*i)->addr <= addr &&
|
|
|
|
(addr + size) <= ((*i)->addr + (*i)->size)) {
|
2013-08-19 09:52:30 +02:00
|
|
|
foundInWrQ = true;
|
|
|
|
servicedByWrQ++;
|
|
|
|
pktsServicedByWrQ++;
|
|
|
|
DPRINTF(DRAM, "Read to addr %lld with size %d serviced by "
|
|
|
|
"write queue\n", addr, size);
|
2013-11-01 16:56:28 +01:00
|
|
|
bytesReadWrQ += burstSize;
|
2013-08-19 09:52:30 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
|
2013-08-19 09:52:30 +02:00
|
|
|
// If not found in the write q, make a DRAM packet and
|
|
|
|
// push it onto the read queue
|
|
|
|
if (!foundInWrQ) {
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-08-19 09:52:30 +02:00
|
|
|
// Make the burst helper for split packets
|
|
|
|
if (pktCount > 1 && burst_helper == NULL) {
|
|
|
|
DPRINTF(DRAM, "Read to addr %lld translates to %d "
|
|
|
|
"dram requests\n", pkt->getAddr(), pktCount);
|
|
|
|
burst_helper = new BurstHelper(pktCount);
|
|
|
|
}
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-11-01 16:56:19 +01:00
|
|
|
DRAMPacket* dram_pkt = decodeAddr(pkt, addr, size, true);
|
2013-08-19 09:52:30 +02:00
|
|
|
dram_pkt->burstHelper = burst_helper;
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-08-19 09:52:30 +02:00
|
|
|
assert(!readQueueFull(1));
|
|
|
|
rdQLenPdf[readQueue.size() + respQueue.size()]++;
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-08-19 09:52:30 +02:00
|
|
|
DPRINTF(DRAM, "Adding to read queue\n");
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-08-19 09:52:30 +02:00
|
|
|
readQueue.push_back(dram_pkt);
|
|
|
|
|
|
|
|
// Update stats
|
|
|
|
avgRdQLen = readQueue.size() + respQueue.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Starting address of next dram pkt (aligend to burstSize boundary)
|
|
|
|
addr = (addr | (burstSize - 1)) + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If all packets are serviced by write queue, we send the repsonse back
|
|
|
|
if (pktsServicedByWrQ == pktCount) {
|
|
|
|
accessAndRespond(pkt, frontendLatency);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Update how many split packets are serviced by write queue
|
|
|
|
if (burst_helper != NULL)
|
|
|
|
burst_helper->burstsServiced = pktsServicedByWrQ;
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-03-01 19:20:24 +01:00
|
|
|
// If we are not already scheduled to get the read request out of
|
|
|
|
// the queue, do so now
|
2012-09-21 17:48:13 +02:00
|
|
|
if (!nextReqEvent.scheduled() && !stopReads) {
|
2013-03-01 19:20:24 +01:00
|
|
|
DPRINTF(DRAM, "Request scheduled immediately\n");
|
|
|
|
schedule(nextReqEvent, curTick());
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::processWriteEvent()
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
2013-03-01 19:20:24 +01:00
|
|
|
assert(!writeQueue.empty());
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-11-01 16:56:25 +01:00
|
|
|
DPRINTF(DRAM, "Beginning DRAM Write\n");
|
2012-09-21 17:48:13 +02:00
|
|
|
Tick temp1 M5_VAR_USED = std::max(curTick(), busBusyUntil);
|
|
|
|
Tick temp2 M5_VAR_USED = std::max(curTick(), maxBankFreeAt());
|
|
|
|
|
2013-11-01 16:56:25 +01:00
|
|
|
chooseNextWrite();
|
|
|
|
DRAMPacket* dram_pkt = writeQueue.front();
|
|
|
|
// sanity check
|
|
|
|
assert(dram_pkt->size <= burstSize);
|
|
|
|
doDRAMAccess(dram_pkt);
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-11-01 16:56:25 +01:00
|
|
|
writeQueue.pop_front();
|
|
|
|
delete dram_pkt;
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2014-03-23 16:12:01 +01:00
|
|
|
DPRINTF(DRAM, "Writing, bus busy for %lld ticks, banks busy "
|
|
|
|
"for %lld ticks\n", busBusyUntil - temp1, maxBankFreeAt() - temp2);
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2014-03-23 16:12:14 +01:00
|
|
|
// If we emptied the write queue, or got sufficiently below the
|
|
|
|
// threshold (using the minWritesPerSwitch as the hysteresis) and
|
2014-03-23 16:12:01 +01:00
|
|
|
// are not draining, or we have reads waiting and have done enough
|
|
|
|
// writes, then switch to reads. The retry above could already
|
|
|
|
// have caused it to be scheduled, so first check
|
|
|
|
if (writeQueue.empty() ||
|
2014-03-23 16:12:14 +01:00
|
|
|
(writeQueue.size() + minWritesPerSwitch < writeLowThreshold &&
|
|
|
|
!drainManager) ||
|
2014-03-23 16:12:01 +01:00
|
|
|
(!readQueue.empty() && writesThisTime >= minWritesPerSwitch)) {
|
2013-11-01 16:56:25 +01:00
|
|
|
// turn the bus back around for reads again
|
|
|
|
busBusyUntil += tWTR;
|
|
|
|
stopReads = false;
|
2014-03-23 16:12:14 +01:00
|
|
|
|
|
|
|
DPRINTF(DRAM, "Switching to reads after %d writes with %d writes "
|
|
|
|
"waiting\n", writesThisTime, writeQueue.size());
|
|
|
|
|
|
|
|
wrPerTurnAround.sample(writesThisTime);
|
2014-03-23 16:12:01 +01:00
|
|
|
writesThisTime = 0;
|
2013-11-01 16:56:25 +01:00
|
|
|
|
|
|
|
if (!nextReqEvent.scheduled())
|
|
|
|
schedule(nextReqEvent, busBusyUntil);
|
|
|
|
} else {
|
|
|
|
assert(!writeEvent.scheduled());
|
|
|
|
DPRINTF(DRAM, "Next write scheduled at %lld\n", newTime);
|
|
|
|
schedule(writeEvent, newTime);
|
|
|
|
}
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
if (retryWrReq) {
|
|
|
|
retryWrReq = false;
|
|
|
|
port.sendRetry();
|
|
|
|
}
|
|
|
|
|
|
|
|
// if there is nothing left in any queue, signal a drain
|
2013-03-01 19:20:24 +01:00
|
|
|
if (writeQueue.empty() && readQueue.empty() &&
|
|
|
|
respQueue.empty () && drainManager) {
|
2012-11-02 17:32:01 +01:00
|
|
|
drainManager->signalDrainDone();
|
|
|
|
drainManager = NULL;
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-01 16:56:19 +01:00
|
|
|
|
2012-09-21 17:48:13 +02:00
|
|
|
void
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::triggerWrites()
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
2014-03-23 16:12:14 +01:00
|
|
|
DPRINTF(DRAM, "Switching to writes after %d reads with %d reads "
|
|
|
|
"waiting\n", readsThisTime, readQueue.size());
|
|
|
|
|
2012-09-21 17:48:13 +02:00
|
|
|
// Flag variable to stop any more read scheduling
|
|
|
|
stopReads = true;
|
|
|
|
|
2014-03-23 16:12:06 +01:00
|
|
|
Tick write_start_time = std::max(busBusyUntil, curTick()) + tWTR;
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2014-03-23 16:12:06 +01:00
|
|
|
DPRINTF(DRAM, "Writes scheduled at %lld\n", write_start_time);
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2014-03-23 16:12:14 +01:00
|
|
|
// there is some danger here as there might still be reads
|
|
|
|
// happening before the switch actually takes place
|
|
|
|
rdPerTurnAround.sample(readsThisTime);
|
|
|
|
readsThisTime = 0;
|
|
|
|
|
2014-03-23 16:12:06 +01:00
|
|
|
assert(write_start_time >= curTick());
|
2012-09-21 17:48:13 +02:00
|
|
|
assert(!writeEvent.scheduled());
|
2014-03-23 16:12:06 +01:00
|
|
|
schedule(writeEvent, write_start_time);
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::addToWriteQueue(PacketPtr pkt, unsigned int pktCount)
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
|
|
|
// only add to the write queue here. whenever the request is
|
|
|
|
// eventually done, set the readyTime, and call schedule()
|
|
|
|
assert(pkt->isWrite());
|
|
|
|
|
2013-08-19 09:52:30 +02:00
|
|
|
// if the request size is larger than burst size, the pkt is split into
|
|
|
|
// multiple DRAM packets
|
|
|
|
Addr addr = pkt->getAddr();
|
|
|
|
for (int cnt = 0; cnt < pktCount; ++cnt) {
|
|
|
|
unsigned size = std::min((addr | (burstSize - 1)) + 1,
|
|
|
|
pkt->getAddr() + pkt->getSize()) - addr;
|
|
|
|
writePktSize[ceilLog2(size)]++;
|
|
|
|
writeBursts++;
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-08-19 09:52:31 +02:00
|
|
|
// see if we can merge with an existing item in the write
|
2013-08-19 09:52:36 +02:00
|
|
|
// queue and keep track of whether we have merged or not so we
|
|
|
|
// can stop at that point and also avoid enqueueing a new
|
|
|
|
// request
|
2013-08-19 09:52:31 +02:00
|
|
|
bool merged = false;
|
|
|
|
auto w = writeQueue.begin();
|
|
|
|
|
|
|
|
while(!merged && w != writeQueue.end()) {
|
|
|
|
// either of the two could be first, if they are the same
|
|
|
|
// it does not matter which way we go
|
|
|
|
if ((*w)->addr >= addr) {
|
2013-08-19 09:52:36 +02:00
|
|
|
// the existing one starts after the new one, figure
|
|
|
|
// out where the new one ends with respect to the
|
|
|
|
// existing one
|
2013-08-19 09:52:31 +02:00
|
|
|
if ((addr + size) >= ((*w)->addr + (*w)->size)) {
|
|
|
|
// check if the existing one is completely
|
|
|
|
// subsumed in the new one
|
|
|
|
DPRINTF(DRAM, "Merging write covering existing burst\n");
|
|
|
|
merged = true;
|
|
|
|
// update both the address and the size
|
|
|
|
(*w)->addr = addr;
|
|
|
|
(*w)->size = size;
|
|
|
|
} else if ((addr + size) >= (*w)->addr &&
|
|
|
|
((*w)->addr + (*w)->size - addr) <= burstSize) {
|
|
|
|
// the new one is just before or partially
|
|
|
|
// overlapping with the existing one, and together
|
|
|
|
// they fit within a burst
|
|
|
|
DPRINTF(DRAM, "Merging write before existing burst\n");
|
|
|
|
merged = true;
|
|
|
|
// the existing queue item needs to be adjusted with
|
|
|
|
// respect to both address and size
|
|
|
|
(*w)->size = (*w)->addr + (*w)->size - addr;
|
2014-01-29 01:00:49 +01:00
|
|
|
(*w)->addr = addr;
|
2013-08-19 09:52:31 +02:00
|
|
|
}
|
|
|
|
} else {
|
2013-08-19 09:52:36 +02:00
|
|
|
// the new one starts after the current one, figure
|
|
|
|
// out where the existing one ends with respect to the
|
|
|
|
// new one
|
2013-08-19 09:52:31 +02:00
|
|
|
if (((*w)->addr + (*w)->size) >= (addr + size)) {
|
|
|
|
// check if the new one is completely subsumed in the
|
|
|
|
// existing one
|
|
|
|
DPRINTF(DRAM, "Merging write into existing burst\n");
|
|
|
|
merged = true;
|
|
|
|
// no adjustments necessary
|
|
|
|
} else if (((*w)->addr + (*w)->size) >= addr &&
|
|
|
|
(addr + size - (*w)->addr) <= burstSize) {
|
|
|
|
// the existing one is just before or partially
|
|
|
|
// overlapping with the new one, and together
|
|
|
|
// they fit within a burst
|
|
|
|
DPRINTF(DRAM, "Merging write after existing burst\n");
|
|
|
|
merged = true;
|
|
|
|
// the address is right, and only the size has
|
|
|
|
// to be adjusted
|
|
|
|
(*w)->size = addr + size - (*w)->addr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
++w;
|
|
|
|
}
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-08-19 09:52:31 +02:00
|
|
|
// if the item was not merged we need to create a new write
|
|
|
|
// and enqueue it
|
|
|
|
if (!merged) {
|
2013-11-01 16:56:19 +01:00
|
|
|
DRAMPacket* dram_pkt = decodeAddr(pkt, addr, size, false);
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-08-19 09:52:31 +02:00
|
|
|
assert(writeQueue.size() < writeBufferSize);
|
|
|
|
wrQLenPdf[writeQueue.size()]++;
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-08-19 09:52:31 +02:00
|
|
|
DPRINTF(DRAM, "Adding to write queue\n");
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-08-19 09:52:31 +02:00
|
|
|
writeQueue.push_back(dram_pkt);
|
2013-08-19 09:52:30 +02:00
|
|
|
|
2013-08-19 09:52:31 +02:00
|
|
|
// Update stats
|
|
|
|
avgWrQLen = writeQueue.size();
|
2013-11-01 16:56:31 +01:00
|
|
|
} else {
|
|
|
|
// keep track of the fact that this burst effectively
|
|
|
|
// disappeared as it was merged with an existing one
|
|
|
|
mergedWrBursts++;
|
2013-08-19 09:52:31 +02:00
|
|
|
}
|
2013-08-19 09:52:30 +02:00
|
|
|
|
|
|
|
// Starting address of next dram pkt (aligend to burstSize boundary)
|
|
|
|
addr = (addr | (burstSize - 1)) + 1;
|
|
|
|
}
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
// we do not wait for the writes to be send to the actual memory,
|
|
|
|
// but instead take responsibility for the consistency here and
|
|
|
|
// snoop the write queue for any upcoming reads
|
2013-08-19 09:52:30 +02:00
|
|
|
// @todo, if a pkt size is larger than burst size, we might need a
|
|
|
|
// different front end latency
|
2013-05-30 18:54:12 +02:00
|
|
|
accessAndRespond(pkt, frontendLatency);
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
// If your write buffer is starting to fill up, drain it!
|
2013-11-01 16:56:25 +01:00
|
|
|
if (writeQueue.size() >= writeHighThreshold && !stopReads){
|
2012-09-21 17:48:13 +02:00
|
|
|
triggerWrites();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::printParams() const
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
|
|
|
// Sanity check print of important parameters
|
|
|
|
DPRINTF(DRAM,
|
|
|
|
"Memory controller %s physical organization\n" \
|
2013-08-19 09:52:30 +02:00
|
|
|
"Number of devices per rank %d\n" \
|
|
|
|
"Device bus width (in bits) %d\n" \
|
2014-03-23 16:12:06 +01:00
|
|
|
"DRAM data bus burst (bytes) %d\n" \
|
|
|
|
"Row buffer size (bytes) %d\n" \
|
2013-08-19 09:52:30 +02:00
|
|
|
"Columns per row buffer %d\n" \
|
|
|
|
"Rows per bank %d\n" \
|
|
|
|
"Banks per rank %d\n" \
|
|
|
|
"Ranks per channel %d\n" \
|
2014-03-23 16:12:06 +01:00
|
|
|
"Total mem capacity (bytes) %u\n",
|
2013-08-19 09:52:30 +02:00
|
|
|
name(), devicesPerRank, deviceBusWidth, burstSize, rowBufferSize,
|
|
|
|
columnsPerRowBuffer, rowsPerBank, banksPerRank, ranksPerChannel,
|
|
|
|
rowBufferSize * rowsPerBank * banksPerRank * ranksPerChannel);
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
string scheduler = memSchedPolicy == Enums::fcfs ? "FCFS" : "FR-FCFS";
|
2014-03-23 16:11:53 +01:00
|
|
|
string address_mapping = addrMapping == Enums::RoRaBaChCo ? "RoRaBaChCo" :
|
|
|
|
(addrMapping == Enums::RoRaBaCoCh ? "RoRaBaCoCh" : "RoCoRaBaCh");
|
2013-11-01 16:56:26 +01:00
|
|
|
string page_policy = pageMgmt == Enums::open ? "OPEN" :
|
2014-03-23 16:12:08 +01:00
|
|
|
(pageMgmt == Enums::open_adaptive ? "OPEN (adaptive)" :
|
|
|
|
(pageMgmt == Enums::close_adaptive ? "CLOSE (adaptive)" : "CLOSE"));
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
DPRINTF(DRAM,
|
|
|
|
"Memory controller %s characteristics\n" \
|
|
|
|
"Read buffer size %d\n" \
|
|
|
|
"Write buffer size %d\n" \
|
2014-03-23 16:12:01 +01:00
|
|
|
"Write high thresh %d\n" \
|
|
|
|
"Write low thresh %d\n" \
|
2012-09-21 17:48:13 +02:00
|
|
|
"Scheduler %s\n" \
|
|
|
|
"Address mapping %s\n" \
|
|
|
|
"Page policy %s\n",
|
2013-11-01 16:56:25 +01:00
|
|
|
name(), readBufferSize, writeBufferSize, writeHighThreshold,
|
2014-03-23 16:12:01 +01:00
|
|
|
writeLowThreshold, scheduler, address_mapping, page_policy);
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
DPRINTF(DRAM, "Memory controller %s timing specs\n" \
|
2013-03-01 19:20:24 +01:00
|
|
|
"tRCD %d ticks\n" \
|
|
|
|
"tCL %d ticks\n" \
|
|
|
|
"tRP %d ticks\n" \
|
|
|
|
"tBURST %d ticks\n" \
|
|
|
|
"tRFC %d ticks\n" \
|
|
|
|
"tREFI %d ticks\n" \
|
|
|
|
"tWTR %d ticks\n" \
|
|
|
|
"tXAW (%d) %d ticks\n",
|
|
|
|
name(), tRCD, tCL, tRP, tBURST, tRFC, tREFI, tWTR,
|
|
|
|
activationLimit, tXAW);
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::printQs() const {
|
2012-09-21 17:48:13 +02:00
|
|
|
DPRINTF(DRAM, "===READ QUEUE===\n\n");
|
2013-08-19 09:52:32 +02:00
|
|
|
for (auto i = readQueue.begin() ; i != readQueue.end() ; ++i) {
|
2012-09-21 17:48:13 +02:00
|
|
|
DPRINTF(DRAM, "Read %lu\n", (*i)->addr);
|
|
|
|
}
|
|
|
|
DPRINTF(DRAM, "\n===RESP QUEUE===\n\n");
|
2013-08-19 09:52:32 +02:00
|
|
|
for (auto i = respQueue.begin() ; i != respQueue.end() ; ++i) {
|
2012-09-21 17:48:13 +02:00
|
|
|
DPRINTF(DRAM, "Response %lu\n", (*i)->addr);
|
|
|
|
}
|
|
|
|
DPRINTF(DRAM, "\n===WRITE QUEUE===\n\n");
|
2013-08-19 09:52:32 +02:00
|
|
|
for (auto i = writeQueue.begin() ; i != writeQueue.end() ; ++i) {
|
2012-09-21 17:48:13 +02:00
|
|
|
DPRINTF(DRAM, "Write %lu\n", (*i)->addr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::recvTimingReq(PacketPtr pkt)
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
2012-11-02 17:50:16 +01:00
|
|
|
/// @todo temporary hack to deal with memory corruption issues until
|
|
|
|
/// 4-phase transactions are complete
|
|
|
|
for (int x = 0; x < pendingDelete.size(); x++)
|
|
|
|
delete pendingDelete[x];
|
|
|
|
pendingDelete.clear();
|
|
|
|
|
2012-09-21 17:48:13 +02:00
|
|
|
// This is where we enter from the outside world
|
2013-03-01 19:20:24 +01:00
|
|
|
DPRINTF(DRAM, "recvTimingReq: request %s addr %lld size %d\n",
|
2013-08-19 09:52:30 +02:00
|
|
|
pkt->cmdString(), pkt->getAddr(), pkt->getSize());
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-03-01 19:20:24 +01:00
|
|
|
// simply drop inhibited packets for now
|
|
|
|
if (pkt->memInhibitAsserted()) {
|
2014-03-23 16:12:06 +01:00
|
|
|
DPRINTF(DRAM, "Inhibited packet -- Dropping it now\n");
|
2013-03-01 19:20:24 +01:00
|
|
|
pendingDelete.push_back(pkt);
|
|
|
|
return true;
|
|
|
|
}
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
// Calc avg gap between requests
|
|
|
|
if (prevArrival != 0) {
|
|
|
|
totGap += curTick() - prevArrival;
|
|
|
|
}
|
|
|
|
prevArrival = curTick();
|
|
|
|
|
2013-08-19 09:52:30 +02:00
|
|
|
|
|
|
|
// Find out how many dram packets a pkt translates to
|
|
|
|
// If the burst size is equal or larger than the pkt size, then a pkt
|
|
|
|
// translates to only one dram packet. Otherwise, a pkt translates to
|
|
|
|
// multiple dram packets
|
2012-09-21 17:48:13 +02:00
|
|
|
unsigned size = pkt->getSize();
|
2013-08-19 09:52:30 +02:00
|
|
|
unsigned offset = pkt->getAddr() & (burstSize - 1);
|
|
|
|
unsigned int dram_pkt_count = divCeil(offset + size, burstSize);
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
// check local buffers and do not accept if full
|
|
|
|
if (pkt->isRead()) {
|
2013-03-01 19:20:24 +01:00
|
|
|
assert(size != 0);
|
2013-08-19 09:52:30 +02:00
|
|
|
if (readQueueFull(dram_pkt_count)) {
|
2013-03-01 19:20:24 +01:00
|
|
|
DPRINTF(DRAM, "Read queue full, not accepting\n");
|
2012-09-21 17:48:13 +02:00
|
|
|
// remember that we have to retry this port
|
|
|
|
retryRdReq = true;
|
|
|
|
numRdRetry++;
|
|
|
|
return false;
|
|
|
|
} else {
|
2013-08-19 09:52:30 +02:00
|
|
|
addToReadQueue(pkt, dram_pkt_count);
|
2012-09-21 17:48:13 +02:00
|
|
|
readReqs++;
|
2013-11-01 16:56:31 +01:00
|
|
|
bytesReadSys += size;
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
} else if (pkt->isWrite()) {
|
2013-03-01 19:20:24 +01:00
|
|
|
assert(size != 0);
|
2013-08-19 09:52:30 +02:00
|
|
|
if (writeQueueFull(dram_pkt_count)) {
|
2013-03-01 19:20:24 +01:00
|
|
|
DPRINTF(DRAM, "Write queue full, not accepting\n");
|
2012-09-21 17:48:13 +02:00
|
|
|
// remember that we have to retry this port
|
|
|
|
retryWrReq = true;
|
|
|
|
numWrRetry++;
|
|
|
|
return false;
|
|
|
|
} else {
|
2013-08-19 09:52:30 +02:00
|
|
|
addToWriteQueue(pkt, dram_pkt_count);
|
2012-09-21 17:48:13 +02:00
|
|
|
writeReqs++;
|
2013-11-01 16:56:31 +01:00
|
|
|
bytesWrittenSys += size;
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
DPRINTF(DRAM,"Neither read nor write, ignore timing\n");
|
|
|
|
neitherReadNorWrite++;
|
2013-05-30 18:54:12 +02:00
|
|
|
accessAndRespond(pkt, 1);
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::processRespondEvent()
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
|
|
|
DPRINTF(DRAM,
|
|
|
|
"processRespondEvent(): Some req has reached its readyTime\n");
|
|
|
|
|
2013-08-19 09:52:30 +02:00
|
|
|
DRAMPacket* dram_pkt = respQueue.front();
|
|
|
|
|
|
|
|
if (dram_pkt->burstHelper) {
|
|
|
|
// it is a split packet
|
|
|
|
dram_pkt->burstHelper->burstsServiced++;
|
|
|
|
if (dram_pkt->burstHelper->burstsServiced ==
|
2014-03-23 16:12:06 +01:00
|
|
|
dram_pkt->burstHelper->burstCount) {
|
2013-08-19 09:52:30 +02:00
|
|
|
// we have now serviced all children packets of a system packet
|
|
|
|
// so we can now respond to the requester
|
|
|
|
// @todo we probably want to have a different front end and back
|
|
|
|
// end latency for split packets
|
|
|
|
accessAndRespond(dram_pkt->pkt, frontendLatency + backendLatency);
|
|
|
|
delete dram_pkt->burstHelper;
|
|
|
|
dram_pkt->burstHelper = NULL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// it is not a split packet
|
|
|
|
accessAndRespond(dram_pkt->pkt, frontendLatency + backendLatency);
|
|
|
|
}
|
|
|
|
|
|
|
|
delete respQueue.front();
|
|
|
|
respQueue.pop_front();
|
|
|
|
|
|
|
|
if (!respQueue.empty()) {
|
|
|
|
assert(respQueue.front()->readyTime >= curTick());
|
|
|
|
assert(!respondEvent.scheduled());
|
|
|
|
schedule(respondEvent, respQueue.front()->readyTime);
|
|
|
|
} else {
|
|
|
|
// if there is nothing left in any queue, signal a drain
|
|
|
|
if (writeQueue.empty() && readQueue.empty() &&
|
|
|
|
drainManager) {
|
|
|
|
drainManager->signalDrainDone();
|
|
|
|
drainManager = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We have made a location in the queue available at this point,
|
|
|
|
// so if there is a read that was forced to wait, retry now
|
|
|
|
if (retryRdReq) {
|
|
|
|
retryRdReq = false;
|
|
|
|
port.sendRetry();
|
|
|
|
}
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::chooseNextWrite()
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
2013-03-01 19:20:24 +01:00
|
|
|
// This method does the arbitration between write requests. The
|
|
|
|
// chosen packet is simply moved to the head of the write
|
|
|
|
// queue. The other methods know that this is the place to
|
|
|
|
// look. For example, with FCFS, this method does nothing
|
|
|
|
assert(!writeQueue.empty());
|
|
|
|
|
|
|
|
if (writeQueue.size() == 1) {
|
2013-11-01 16:56:19 +01:00
|
|
|
DPRINTF(DRAM, "Single write request, nothing to do\n");
|
2012-09-21 17:48:13 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (memSchedPolicy == Enums::fcfs) {
|
|
|
|
// Do nothing, since the correct request is already head
|
|
|
|
} else if (memSchedPolicy == Enums::frfcfs) {
|
2013-11-01 16:56:27 +01:00
|
|
|
reorderQueue(writeQueue);
|
2012-09-21 17:48:13 +02:00
|
|
|
} else
|
|
|
|
panic("No scheduling policy chosen\n");
|
|
|
|
|
2013-11-01 16:56:19 +01:00
|
|
|
DPRINTF(DRAM, "Selected next write request\n");
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::chooseNextRead()
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
2013-03-01 19:20:24 +01:00
|
|
|
// This method does the arbitration between read requests. The
|
|
|
|
// chosen packet is simply moved to the head of the queue. The
|
|
|
|
// other methods know that this is the place to look. For example,
|
|
|
|
// with FCFS, this method does nothing
|
|
|
|
if (readQueue.empty()) {
|
|
|
|
DPRINTF(DRAM, "No read request to select\n");
|
2012-09-21 17:48:13 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-03-01 19:20:24 +01:00
|
|
|
// If there is only one request then there is nothing left to do
|
|
|
|
if (readQueue.size() == 1)
|
2012-09-21 17:48:13 +02:00
|
|
|
return true;
|
|
|
|
|
|
|
|
if (memSchedPolicy == Enums::fcfs) {
|
2013-03-01 19:20:24 +01:00
|
|
|
// Do nothing, since the request to serve is already the first
|
|
|
|
// one in the read queue
|
2012-09-21 17:48:13 +02:00
|
|
|
} else if (memSchedPolicy == Enums::frfcfs) {
|
2013-11-01 16:56:27 +01:00
|
|
|
reorderQueue(readQueue);
|
2012-09-21 17:48:13 +02:00
|
|
|
} else
|
|
|
|
panic("No scheduling policy chosen!\n");
|
|
|
|
|
2013-03-01 19:20:24 +01:00
|
|
|
DPRINTF(DRAM, "Selected next read request\n");
|
2012-09-21 17:48:13 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-11-01 16:56:27 +01:00
|
|
|
void
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::reorderQueue(std::deque<DRAMPacket*>& queue)
|
2013-11-01 16:56:27 +01:00
|
|
|
{
|
|
|
|
// Only determine this when needed
|
|
|
|
uint64_t earliest_banks = 0;
|
|
|
|
|
|
|
|
// Search for row hits first, if no row hit is found then schedule the
|
|
|
|
// packet to one of the earliest banks available
|
|
|
|
bool found_earliest_pkt = false;
|
|
|
|
auto selected_pkt_it = queue.begin();
|
|
|
|
|
|
|
|
for (auto i = queue.begin(); i != queue.end() ; ++i) {
|
|
|
|
DRAMPacket* dram_pkt = *i;
|
|
|
|
const Bank& bank = dram_pkt->bankRef;
|
|
|
|
// Check if it is a row hit
|
|
|
|
if (bank.openRow == dram_pkt->row) {
|
|
|
|
DPRINTF(DRAM, "Row buffer hit\n");
|
|
|
|
selected_pkt_it = i;
|
|
|
|
break;
|
|
|
|
} else if (!found_earliest_pkt) {
|
|
|
|
// No row hit, go for first ready
|
|
|
|
if (earliest_banks == 0)
|
|
|
|
earliest_banks = minBankFreeAt(queue);
|
|
|
|
|
|
|
|
// Bank is ready or is the first available bank
|
|
|
|
if (bank.freeAt <= curTick() ||
|
|
|
|
bits(earliest_banks, dram_pkt->bankId, dram_pkt->bankId)) {
|
|
|
|
// Remember the packet to be scheduled to one of the earliest
|
|
|
|
// banks available
|
|
|
|
selected_pkt_it = i;
|
|
|
|
found_earliest_pkt = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DRAMPacket* selected_pkt = *selected_pkt_it;
|
|
|
|
queue.erase(selected_pkt_it);
|
|
|
|
queue.push_front(selected_pkt);
|
|
|
|
}
|
|
|
|
|
2012-09-21 17:48:13 +02:00
|
|
|
void
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::accessAndRespond(PacketPtr pkt, Tick static_latency)
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
|
|
|
DPRINTF(DRAM, "Responding to Address %lld.. ",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());
|
|
|
|
|
2013-02-19 11:56:06 +01:00
|
|
|
// @todo someone should pay for this
|
|
|
|
pkt->busFirstWordDelay = pkt->busLastWordDelay = 0;
|
|
|
|
|
2013-05-30 18:54:12 +02:00
|
|
|
// queue the packet in the response queue to be sent out after
|
|
|
|
// the static latency has passed
|
|
|
|
port.schedTimingResp(pkt, curTick() + static_latency);
|
2012-09-21 17:48:13 +02:00
|
|
|
} else {
|
2013-03-18 10:22:45 +01:00
|
|
|
// @todo the packet is going to be deleted, and the DRAMPacket
|
|
|
|
// is still having a pointer to it
|
|
|
|
pendingDelete.push_back(pkt);
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
DPRINTF(DRAM, "Done\n");
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
pair<Tick, Tick>
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::estimateLatency(DRAMPacket* dram_pkt, Tick inTime)
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
|
|
|
// If a request reaches a bank at tick 'inTime', how much time
|
|
|
|
// *after* that does it take to finish the request, depending
|
|
|
|
// on bank status and page open policy. Note that this method
|
|
|
|
// considers only the time taken for the actual read or write
|
|
|
|
// to complete, NOT any additional time thereafter for tRAS or
|
|
|
|
// tRP.
|
|
|
|
Tick accLat = 0;
|
|
|
|
Tick bankLat = 0;
|
|
|
|
rowHitFlag = false;
|
2013-11-01 16:56:22 +01:00
|
|
|
Tick potentialActTick;
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-11-01 16:56:20 +01:00
|
|
|
const Bank& bank = dram_pkt->bankRef;
|
2014-03-23 16:12:08 +01:00
|
|
|
// open-page policy or close_adaptive policy
|
|
|
|
if (pageMgmt == Enums::open || pageMgmt == Enums::open_adaptive ||
|
|
|
|
pageMgmt == Enums::close_adaptive) {
|
2012-09-21 17:48:13 +02:00
|
|
|
if (bank.openRow == dram_pkt->row) {
|
|
|
|
// When we have a row-buffer hit,
|
|
|
|
// we don't care about tRAS having expired or not,
|
|
|
|
// but do care about bank being free for access
|
|
|
|
rowHitFlag = true;
|
|
|
|
|
2013-11-01 16:56:18 +01:00
|
|
|
// When a series of requests arrive to the same row,
|
|
|
|
// DDR systems are capable of streaming data continuously
|
|
|
|
// at maximum bandwidth (subject to tCCD). Here, we approximate
|
|
|
|
// this condition, and assume that if whenever a bank is already
|
|
|
|
// busy and a new request comes in, it can be completed with no
|
|
|
|
// penalty beyond waiting for the existing read to complete.
|
|
|
|
if (bank.freeAt > inTime) {
|
|
|
|
accLat += bank.freeAt - inTime;
|
2013-11-01 16:56:19 +01:00
|
|
|
bankLat += 0;
|
2013-11-01 16:56:18 +01:00
|
|
|
} else {
|
2012-09-21 17:48:13 +02:00
|
|
|
// CAS latency only
|
|
|
|
accLat += tCL;
|
|
|
|
bankLat += tCL;
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Row-buffer miss, need to close existing row
|
|
|
|
// once tRAS has expired, then open the new one,
|
|
|
|
// then add cas latency.
|
|
|
|
Tick freeTime = std::max(bank.tRASDoneAt, bank.freeAt);
|
|
|
|
|
|
|
|
if (freeTime > inTime)
|
|
|
|
accLat += freeTime - inTime;
|
|
|
|
|
2013-11-01 16:56:26 +01:00
|
|
|
// If the there is no open row (open adaptive), then there
|
|
|
|
// is no precharge delay, otherwise go with tRP
|
|
|
|
Tick precharge_delay = bank.openRow == -1 ? 0 : tRP;
|
|
|
|
|
2013-11-01 16:56:22 +01:00
|
|
|
//The bank is free, and you may be able to activate
|
2013-11-01 16:56:26 +01:00
|
|
|
potentialActTick = inTime + accLat + precharge_delay;
|
2013-11-01 16:56:22 +01:00
|
|
|
if (potentialActTick < bank.actAllowedAt)
|
|
|
|
accLat += bank.actAllowedAt - potentialActTick;
|
|
|
|
|
2013-11-01 16:56:26 +01:00
|
|
|
accLat += precharge_delay + tRCD + tCL;
|
|
|
|
bankLat += precharge_delay + tRCD + tCL;
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
} else if (pageMgmt == Enums::close) {
|
|
|
|
// With a close page policy, no notion of
|
|
|
|
// bank.tRASDoneAt
|
|
|
|
if (bank.freeAt > inTime)
|
|
|
|
accLat += bank.freeAt - inTime;
|
|
|
|
|
2013-11-01 16:56:22 +01:00
|
|
|
//The bank is free, and you may be able to activate
|
|
|
|
potentialActTick = inTime + accLat;
|
|
|
|
if (potentialActTick < bank.actAllowedAt)
|
|
|
|
accLat += bank.actAllowedAt - potentialActTick;
|
|
|
|
|
2012-09-21 17:48:13 +02:00
|
|
|
// page already closed, simply open the row, and
|
|
|
|
// add cas latency
|
|
|
|
accLat += tRCD + tCL;
|
|
|
|
bankLat += tRCD + tCL;
|
|
|
|
} else
|
|
|
|
panic("No page management policy chosen\n");
|
|
|
|
|
2013-01-31 13:49:13 +01:00
|
|
|
DPRINTF(DRAM, "Returning < %lld, %lld > from estimateLatency()\n",
|
|
|
|
bankLat, accLat);
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
return make_pair(bankLat, accLat);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::processNextReqEvent()
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
|
|
|
scheduleNextReq();
|
|
|
|
}
|
|
|
|
|
2013-01-31 13:49:14 +01:00
|
|
|
void
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::recordActivate(Tick act_tick, uint8_t rank, uint8_t bank)
|
2013-01-31 13:49:14 +01:00
|
|
|
{
|
2013-11-01 16:56:22 +01:00
|
|
|
assert(0 <= rank && rank < ranksPerChannel);
|
|
|
|
assert(actTicks[rank].size() == activationLimit);
|
2013-01-31 13:49:14 +01:00
|
|
|
|
|
|
|
DPRINTF(DRAM, "Activate at tick %d\n", act_tick);
|
|
|
|
|
2013-11-01 16:56:28 +01:00
|
|
|
// Tracking accesses after all banks are precharged.
|
|
|
|
// startTickPrechargeAll: is the tick when all the banks were again
|
|
|
|
// precharged. The difference between act_tick and startTickPrechargeAll
|
|
|
|
// gives the time for which DRAM doesn't get any accesses after refreshing
|
|
|
|
// or after a page is closed in closed-page or open-adaptive-page policy.
|
|
|
|
if ((numBanksActive == 0) && (act_tick > startTickPrechargeAll)) {
|
|
|
|
prechargeAllTime += act_tick - startTickPrechargeAll;
|
|
|
|
}
|
|
|
|
|
|
|
|
// No need to update number of active banks for closed-page policy as only 1
|
|
|
|
// bank will be activated at any given point, which will be instatntly
|
|
|
|
// precharged
|
2014-03-23 16:12:08 +01:00
|
|
|
if (pageMgmt == Enums::open || pageMgmt == Enums::open_adaptive ||
|
|
|
|
pageMgmt == Enums::close_adaptive)
|
2013-11-01 16:56:28 +01:00
|
|
|
++numBanksActive;
|
|
|
|
|
2013-11-01 16:56:24 +01:00
|
|
|
// start by enforcing tRRD
|
|
|
|
for(int i = 0; i < banksPerRank; i++) {
|
|
|
|
// next activate must not happen before tRRD
|
|
|
|
banks[rank][i].actAllowedAt = act_tick + tRRD;
|
|
|
|
}
|
|
|
|
// tRC should be added to activation tick of the bank currently accessed,
|
|
|
|
// where tRC = tRAS + tRP, this is just for a check as actAllowedAt for same
|
|
|
|
// bank is already captured by bank.freeAt and bank.tRASDoneAt
|
|
|
|
banks[rank][bank].actAllowedAt = act_tick + tRAS + tRP;
|
|
|
|
|
|
|
|
// next, we deal with tXAW, if the activation limit is disabled
|
|
|
|
// then we are done
|
2013-11-01 16:56:22 +01:00
|
|
|
if (actTicks[rank].empty())
|
2013-08-19 09:52:26 +02:00
|
|
|
return;
|
|
|
|
|
2013-01-31 13:49:14 +01:00
|
|
|
// sanity check
|
2013-11-01 16:56:22 +01:00
|
|
|
if (actTicks[rank].back() && (act_tick - actTicks[rank].back()) < tXAW) {
|
2013-08-19 09:52:26 +02:00
|
|
|
// @todo For now, stick with a warning
|
|
|
|
warn("Got %d activates in window %d (%d - %d) which is smaller "
|
2013-11-01 16:56:22 +01:00
|
|
|
"than %d\n", activationLimit, act_tick - actTicks[rank].back(),
|
|
|
|
act_tick, actTicks[rank].back(), tXAW);
|
2013-01-31 13:49:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// shift the times used for the book keeping, the last element
|
|
|
|
// (highest index) is the oldest one and hence the lowest value
|
2013-11-01 16:56:22 +01:00
|
|
|
actTicks[rank].pop_back();
|
2013-01-31 13:49:14 +01:00
|
|
|
|
|
|
|
// record an new activation (in the future)
|
2013-11-01 16:56:22 +01:00
|
|
|
actTicks[rank].push_front(act_tick);
|
2013-01-31 13:49:14 +01:00
|
|
|
|
|
|
|
// cannot activate more than X times in time window tXAW, push the
|
|
|
|
// next one (the X + 1'st activate) to be tXAW away from the
|
|
|
|
// oldest in our window of X
|
2013-11-01 16:56:22 +01:00
|
|
|
if (actTicks[rank].back() && (act_tick - actTicks[rank].back()) < tXAW) {
|
2013-01-31 13:49:14 +01:00
|
|
|
DPRINTF(DRAM, "Enforcing tXAW with X = %d, next activate no earlier "
|
2013-11-01 16:56:22 +01:00
|
|
|
"than %d\n", activationLimit, actTicks[rank].back() + tXAW);
|
2013-01-31 13:49:14 +01:00
|
|
|
for(int j = 0; j < banksPerRank; j++)
|
|
|
|
// next activate must not happen before end of window
|
2013-11-01 16:56:22 +01:00
|
|
|
banks[rank][j].actAllowedAt = actTicks[rank].back() + tXAW;
|
2013-01-31 13:49:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-21 17:48:13 +02:00
|
|
|
void
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::doDRAMAccess(DRAMPacket* dram_pkt)
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
DPRINTF(DRAM, "Timing access to addr %lld, rank/bank/row %d %d %d\n",
|
|
|
|
dram_pkt->addr, dram_pkt->rank, dram_pkt->bank, dram_pkt->row);
|
|
|
|
|
|
|
|
// estimate the bank and access latency
|
|
|
|
pair<Tick, Tick> lat = estimateLatency(dram_pkt, curTick());
|
|
|
|
Tick bankLat = lat.first;
|
|
|
|
Tick accessLat = lat.second;
|
2013-11-01 16:56:16 +01:00
|
|
|
Tick actTick;
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
// This request was woken up at this time based on a prior call
|
|
|
|
// to estimateLatency(). However, between then and now, both the
|
|
|
|
// accessLatency and/or busBusyUntil may have changed. We need
|
|
|
|
// to correct for that.
|
|
|
|
|
|
|
|
Tick addDelay = (curTick() + accessLat < busBusyUntil) ?
|
|
|
|
busBusyUntil - (curTick() + accessLat) : 0;
|
|
|
|
|
2013-11-01 16:56:20 +01:00
|
|
|
Bank& bank = dram_pkt->bankRef;
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
// Update bank state
|
2014-03-23 16:12:08 +01:00
|
|
|
if (pageMgmt == Enums::open || pageMgmt == Enums::open_adaptive ||
|
|
|
|
pageMgmt == Enums::close_adaptive) {
|
2012-09-21 17:48:13 +02:00
|
|
|
bank.freeAt = curTick() + addDelay + accessLat;
|
2013-05-30 18:54:13 +02:00
|
|
|
|
2012-09-21 17:48:13 +02:00
|
|
|
// If you activated a new row do to this access, the next access
|
2013-11-01 16:56:16 +01:00
|
|
|
// will have to respect tRAS for this bank.
|
2013-01-31 13:49:14 +01:00
|
|
|
if (!rowHitFlag) {
|
2013-11-01 16:56:16 +01:00
|
|
|
// any waiting for banks account for in freeAt
|
|
|
|
actTick = bank.freeAt - tCL - tRCD;
|
|
|
|
bank.tRASDoneAt = actTick + tRAS;
|
2013-11-01 16:56:24 +01:00
|
|
|
recordActivate(actTick, dram_pkt->rank, dram_pkt->bank);
|
2013-11-01 16:56:16 +01:00
|
|
|
|
2014-03-23 16:12:05 +01:00
|
|
|
// if we closed an open row as a result of this access,
|
|
|
|
// then sample the number of bytes accessed before
|
|
|
|
// resetting it
|
|
|
|
if (bank.openRow != -1)
|
|
|
|
bytesPerActivate.sample(bank.bytesAccessed);
|
|
|
|
|
|
|
|
// update the open row
|
|
|
|
bank.openRow = dram_pkt->row;
|
|
|
|
|
|
|
|
// start counting anew, this covers both the case when we
|
|
|
|
// auto-precharged, and when this access is forced to
|
|
|
|
// precharge
|
2013-05-30 18:54:13 +02:00
|
|
|
bank.bytesAccessed = 0;
|
2014-03-23 16:12:03 +01:00
|
|
|
bank.rowAccesses = 0;
|
2013-01-31 13:49:14 +01:00
|
|
|
}
|
2013-11-01 16:56:26 +01:00
|
|
|
|
2014-03-23 16:12:03 +01:00
|
|
|
// increment the bytes accessed and the accesses per row
|
|
|
|
bank.bytesAccessed += burstSize;
|
|
|
|
++bank.rowAccesses;
|
|
|
|
|
|
|
|
// if we reached the max, then issue with an auto-precharge
|
|
|
|
bool auto_precharge = bank.rowAccesses == maxAccessesPerRow;
|
|
|
|
|
|
|
|
// if we did not hit the limit, we might still want to
|
|
|
|
// auto-precharge
|
2014-03-23 16:12:08 +01:00
|
|
|
if (!auto_precharge &&
|
|
|
|
(pageMgmt == Enums::open_adaptive ||
|
|
|
|
pageMgmt == Enums::close_adaptive)) {
|
|
|
|
// a twist on the open and close page policies:
|
|
|
|
// 1) open_adaptive page policy does not blindly keep the
|
2013-11-01 16:56:26 +01:00
|
|
|
// page open, but close it if there are no row hits, and there
|
|
|
|
// are bank conflicts in the queue
|
2014-03-23 16:12:08 +01:00
|
|
|
// 2) close_adaptive page policy does not blindly close the
|
|
|
|
// page, but closes it only if there are no row hits in the queue.
|
|
|
|
// In this case, only force an auto precharge when there
|
|
|
|
// are no same page hits in the queue
|
2013-11-01 16:56:26 +01:00
|
|
|
bool got_more_hits = false;
|
|
|
|
bool got_bank_conflict = false;
|
|
|
|
|
|
|
|
// either look at the read queue or write queue
|
|
|
|
const deque<DRAMPacket*>& queue = dram_pkt->isRead ? readQueue :
|
|
|
|
writeQueue;
|
|
|
|
auto p = queue.begin();
|
|
|
|
// make sure we are not considering the packet that we are
|
|
|
|
// currently dealing with (which is the head of the queue)
|
|
|
|
++p;
|
|
|
|
|
2014-03-23 16:12:08 +01:00
|
|
|
// keep on looking until we have found required condition or
|
|
|
|
// reached the end
|
|
|
|
while (!(got_more_hits &&
|
|
|
|
(got_bank_conflict || pageMgmt == Enums::close_adaptive)) &&
|
2013-11-01 16:56:26 +01:00
|
|
|
p != queue.end()) {
|
|
|
|
bool same_rank_bank = (dram_pkt->rank == (*p)->rank) &&
|
|
|
|
(dram_pkt->bank == (*p)->bank);
|
|
|
|
bool same_row = dram_pkt->row == (*p)->row;
|
|
|
|
got_more_hits |= same_rank_bank && same_row;
|
|
|
|
got_bank_conflict |= same_rank_bank && !same_row;
|
|
|
|
++p;
|
|
|
|
}
|
|
|
|
|
2014-03-23 16:12:08 +01:00
|
|
|
// auto pre-charge when either
|
|
|
|
// 1) open_adaptive policy, we have not got any more hits, and
|
|
|
|
// have a bank conflict
|
|
|
|
// 2) close_adaptive policy and we have not got any more hits
|
|
|
|
auto_precharge = !got_more_hits &&
|
|
|
|
(got_bank_conflict || pageMgmt == Enums::close_adaptive);
|
2014-03-23 16:12:03 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// if this access should use auto-precharge, then we are
|
|
|
|
// closing the row
|
|
|
|
if (auto_precharge) {
|
|
|
|
bank.openRow = -1;
|
|
|
|
bank.freeAt = std::max(bank.freeAt, bank.tRASDoneAt) + tRP;
|
|
|
|
--numBanksActive;
|
|
|
|
if (numBanksActive == 0) {
|
|
|
|
startTickPrechargeAll = std::max(startTickPrechargeAll,
|
|
|
|
bank.freeAt);
|
|
|
|
DPRINTF(DRAM, "All banks precharged at tick: %ld\n",
|
|
|
|
startTickPrechargeAll);
|
2013-11-01 16:56:26 +01:00
|
|
|
}
|
2014-03-23 16:12:05 +01:00
|
|
|
|
|
|
|
// sample the bytes per activate here since we are closing
|
|
|
|
// the page
|
|
|
|
bytesPerActivate.sample(bank.bytesAccessed);
|
|
|
|
|
2014-03-23 16:12:03 +01:00
|
|
|
DPRINTF(DRAM, "Auto-precharged bank: %d\n", dram_pkt->bankId);
|
2013-11-01 16:56:26 +01:00
|
|
|
}
|
|
|
|
|
2013-11-01 16:56:24 +01:00
|
|
|
DPRINTF(DRAM, "doDRAMAccess::bank.freeAt is %lld\n", bank.freeAt);
|
2013-11-01 16:56:16 +01:00
|
|
|
} else if (pageMgmt == Enums::close) {
|
|
|
|
actTick = curTick() + addDelay + accessLat - tRCD - tCL;
|
2013-11-01 16:56:24 +01:00
|
|
|
recordActivate(actTick, dram_pkt->rank, dram_pkt->bank);
|
2013-11-01 16:56:16 +01:00
|
|
|
|
|
|
|
// If the DRAM has a very quick tRAS, bank can be made free
|
|
|
|
// after consecutive tCL,tRCD,tRP times. In general, however,
|
|
|
|
// an additional wait is required to respect tRAS.
|
|
|
|
bank.freeAt = std::max(actTick + tRAS + tRP,
|
|
|
|
actTick + tRCD + tCL + tRP);
|
2013-11-01 16:56:24 +01:00
|
|
|
DPRINTF(DRAM, "doDRAMAccess::bank.freeAt is %lld\n", bank.freeAt);
|
2013-08-19 09:52:30 +02:00
|
|
|
bytesPerActivate.sample(burstSize);
|
2013-11-01 16:56:28 +01:00
|
|
|
startTickPrechargeAll = std::max(startTickPrechargeAll, bank.freeAt);
|
2012-09-21 17:48:13 +02:00
|
|
|
} else
|
|
|
|
panic("No page management policy chosen\n");
|
|
|
|
|
|
|
|
// Update request parameters
|
|
|
|
dram_pkt->readyTime = curTick() + addDelay + accessLat + tBURST;
|
|
|
|
|
|
|
|
|
|
|
|
DPRINTF(DRAM, "Req %lld: curtick is %lld accessLat is %d " \
|
|
|
|
"readytime is %lld busbusyuntil is %lld. " \
|
|
|
|
"Scheduling at readyTime\n", dram_pkt->addr,
|
|
|
|
curTick(), accessLat, dram_pkt->readyTime, busBusyUntil);
|
|
|
|
|
|
|
|
// Make sure requests are not overlapping on the databus
|
|
|
|
assert (dram_pkt->readyTime - busBusyUntil >= tBURST);
|
|
|
|
|
|
|
|
// Update bus state
|
|
|
|
busBusyUntil = dram_pkt->readyTime;
|
|
|
|
|
|
|
|
DPRINTF(DRAM,"Access time is %lld\n",
|
|
|
|
dram_pkt->readyTime - dram_pkt->entryTime);
|
|
|
|
|
2013-11-01 16:56:25 +01:00
|
|
|
// Update the minimum timing between the requests
|
|
|
|
newTime = (busBusyUntil > tRP + tRCD + tCL) ?
|
|
|
|
std::max(busBusyUntil - (tRP + tRCD + tCL), curTick()) : curTick();
|
|
|
|
|
2013-11-01 16:56:31 +01:00
|
|
|
// Update the access related stats
|
|
|
|
if (dram_pkt->isRead) {
|
2014-03-23 16:12:14 +01:00
|
|
|
++readsThisTime;
|
2013-11-01 16:56:31 +01:00
|
|
|
if (rowHitFlag)
|
|
|
|
readRowHits++;
|
|
|
|
bytesReadDRAM += burstSize;
|
|
|
|
perBankRdBursts[dram_pkt->bankId]++;
|
|
|
|
} else {
|
2014-03-23 16:12:14 +01:00
|
|
|
++writesThisTime;
|
2013-11-01 16:56:31 +01:00
|
|
|
if (rowHitFlag)
|
|
|
|
writeRowHits++;
|
|
|
|
bytesWritten += burstSize;
|
|
|
|
perBankWrBursts[dram_pkt->bankId]++;
|
2013-11-01 16:56:19 +01:00
|
|
|
|
2013-11-01 16:56:31 +01:00
|
|
|
// At this point, commonality between reads and writes ends.
|
|
|
|
// For writes, we are done since we long ago responded to the
|
|
|
|
// requestor.
|
2013-11-01 16:56:19 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-11-01 16:56:31 +01:00
|
|
|
// Update latency stats
|
2012-09-21 17:48:13 +02:00
|
|
|
totMemAccLat += dram_pkt->readyTime - dram_pkt->entryTime;
|
|
|
|
totBankLat += bankLat;
|
|
|
|
totBusLat += tBURST;
|
|
|
|
totQLat += dram_pkt->readyTime - dram_pkt->entryTime - bankLat - tBURST;
|
|
|
|
|
|
|
|
|
|
|
|
// At this point we're done dealing with the request
|
|
|
|
// It will be moved to a separate response queue with a
|
|
|
|
// correct readyTime, and eventually be sent back at that
|
|
|
|
//time
|
|
|
|
moveToRespQ();
|
|
|
|
|
2013-11-01 16:56:25 +01:00
|
|
|
// Schedule the next read event
|
2014-03-23 16:12:06 +01:00
|
|
|
if (!nextReqEvent.scheduled() && !stopReads) {
|
2013-03-01 19:20:24 +01:00
|
|
|
schedule(nextReqEvent, newTime);
|
2012-09-21 17:48:13 +02:00
|
|
|
} else {
|
|
|
|
if (newTime < nextReqEvent.when())
|
2013-03-01 19:20:24 +01:00
|
|
|
reschedule(nextReqEvent, newTime);
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::moveToRespQ()
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
|
|
|
// Remove from read queue
|
2013-03-01 19:20:24 +01:00
|
|
|
DRAMPacket* dram_pkt = readQueue.front();
|
|
|
|
readQueue.pop_front();
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-08-19 09:52:31 +02:00
|
|
|
// sanity check
|
|
|
|
assert(dram_pkt->size <= burstSize);
|
|
|
|
|
2012-09-21 17:48:13 +02:00
|
|
|
// Insert into response queue sorted by readyTime
|
|
|
|
// It will be sent back to the requestor at its
|
|
|
|
// readyTime
|
2013-03-01 19:20:24 +01:00
|
|
|
if (respQueue.empty()) {
|
|
|
|
respQueue.push_front(dram_pkt);
|
2012-09-21 17:48:13 +02:00
|
|
|
assert(!respondEvent.scheduled());
|
|
|
|
assert(dram_pkt->readyTime >= curTick());
|
2013-03-01 19:20:24 +01:00
|
|
|
schedule(respondEvent, dram_pkt->readyTime);
|
2012-09-21 17:48:13 +02:00
|
|
|
} else {
|
|
|
|
bool done = false;
|
2013-08-19 09:52:32 +02:00
|
|
|
auto i = respQueue.begin();
|
2013-03-01 19:20:24 +01:00
|
|
|
while (!done && i != respQueue.end()) {
|
2012-09-21 17:48:13 +02:00
|
|
|
if ((*i)->readyTime > dram_pkt->readyTime) {
|
2013-03-01 19:20:24 +01:00
|
|
|
respQueue.insert(i, dram_pkt);
|
2012-09-21 17:48:13 +02:00
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!done)
|
2013-03-01 19:20:24 +01:00
|
|
|
respQueue.push_back(dram_pkt);
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
assert(respondEvent.scheduled());
|
|
|
|
|
2013-03-01 19:20:24 +01:00
|
|
|
if (respQueue.front()->readyTime < respondEvent.when()) {
|
|
|
|
assert(respQueue.front()->readyTime >= curTick());
|
|
|
|
reschedule(respondEvent, respQueue.front()->readyTime);
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::scheduleNextReq()
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
|
|
|
DPRINTF(DRAM, "Reached scheduleNextReq()\n");
|
|
|
|
|
2013-03-01 19:20:24 +01:00
|
|
|
// Figure out which read request goes next, and move it to the
|
|
|
|
// front of the read queue
|
|
|
|
if (!chooseNextRead()) {
|
2014-03-23 16:12:01 +01:00
|
|
|
// In the case there is no read request to go next, trigger
|
|
|
|
// writes if we have passed the low threshold (or if we are
|
|
|
|
// draining)
|
|
|
|
if (!writeQueue.empty() && !writeEvent.scheduled() &&
|
|
|
|
(writeQueue.size() > writeLowThreshold || drainManager))
|
2012-11-08 10:25:06 +01:00
|
|
|
triggerWrites();
|
|
|
|
} else {
|
2013-03-01 19:20:24 +01:00
|
|
|
doDRAMAccess(readQueue.front());
|
2012-11-08 10:25:06 +01:00
|
|
|
}
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Tick
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::maxBankFreeAt() const
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
|
|
|
Tick banksFree = 0;
|
|
|
|
|
|
|
|
for(int i = 0; i < ranksPerChannel; i++)
|
|
|
|
for(int j = 0; j < banksPerRank; j++)
|
|
|
|
banksFree = std::max(banks[i][j].freeAt, banksFree);
|
|
|
|
|
|
|
|
return banksFree;
|
|
|
|
}
|
|
|
|
|
2013-11-01 16:56:20 +01:00
|
|
|
uint64_t
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::minBankFreeAt(const deque<DRAMPacket*>& queue) const
|
2013-11-01 16:56:20 +01:00
|
|
|
{
|
|
|
|
uint64_t bank_mask = 0;
|
|
|
|
Tick freeAt = MaxTick;
|
|
|
|
|
|
|
|
// detemrine if we have queued transactions targetting the
|
|
|
|
// bank in question
|
|
|
|
vector<bool> got_waiting(ranksPerChannel * banksPerRank, false);
|
|
|
|
for (auto p = queue.begin(); p != queue.end(); ++p) {
|
|
|
|
got_waiting[(*p)->bankId] = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < ranksPerChannel; i++) {
|
|
|
|
for (int j = 0; j < banksPerRank; j++) {
|
|
|
|
// if we have waiting requests for the bank, and it is
|
|
|
|
// amongst the first available, update the mask
|
|
|
|
if (got_waiting[i * banksPerRank + j] &&
|
|
|
|
banks[i][j].freeAt <= freeAt) {
|
|
|
|
// reset bank mask if new minimum is found
|
|
|
|
if (banks[i][j].freeAt < freeAt)
|
|
|
|
bank_mask = 0;
|
|
|
|
// set the bit corresponding to the available bank
|
|
|
|
uint8_t bit_index = i * ranksPerChannel + j;
|
|
|
|
replaceBits(bank_mask, bit_index, bit_index, 1);
|
|
|
|
freeAt = banks[i][j].freeAt;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return bank_mask;
|
|
|
|
}
|
|
|
|
|
2012-09-21 17:48:13 +02:00
|
|
|
void
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::processRefreshEvent()
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
|
|
|
DPRINTF(DRAM, "Refreshing at tick %ld\n", curTick());
|
|
|
|
|
|
|
|
Tick banksFree = std::max(curTick(), maxBankFreeAt()) + tRFC;
|
|
|
|
|
|
|
|
for(int i = 0; i < ranksPerChannel; i++)
|
2013-11-01 16:56:28 +01:00
|
|
|
for(int j = 0; j < banksPerRank; j++) {
|
2012-09-21 17:48:13 +02:00
|
|
|
banks[i][j].freeAt = banksFree;
|
2013-11-01 16:56:28 +01:00
|
|
|
banks[i][j].openRow = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// updating startTickPrechargeAll, isprechargeAll
|
|
|
|
numBanksActive = 0;
|
|
|
|
startTickPrechargeAll = banksFree;
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-03-01 19:20:24 +01:00
|
|
|
schedule(refreshEvent, curTick() + tREFI);
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::regStats()
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
|
|
|
using namespace Stats;
|
|
|
|
|
|
|
|
AbstractMemory::regStats();
|
|
|
|
|
|
|
|
readReqs
|
|
|
|
.name(name() + ".readReqs")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Number of read requests accepted");
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
writeReqs
|
|
|
|
.name(name() + ".writeReqs")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Number of write requests accepted");
|
2013-08-19 09:52:30 +02:00
|
|
|
|
|
|
|
readBursts
|
|
|
|
.name(name() + ".readBursts")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Number of DRAM read bursts, "
|
|
|
|
"including those serviced by the write queue");
|
2013-08-19 09:52:30 +02:00
|
|
|
|
|
|
|
writeBursts
|
|
|
|
.name(name() + ".writeBursts")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Number of DRAM write bursts, "
|
|
|
|
"including those merged in the write queue");
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
servicedByWrQ
|
|
|
|
.name(name() + ".servicedByWrQ")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Number of DRAM read bursts serviced by the write queue");
|
|
|
|
|
|
|
|
mergedWrBursts
|
|
|
|
.name(name() + ".mergedWrBursts")
|
|
|
|
.desc("Number of DRAM write bursts merged with an existing one");
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
neitherReadNorWrite
|
2013-11-01 16:56:31 +01:00
|
|
|
.name(name() + ".neitherReadNorWriteReqs")
|
|
|
|
.desc("Number of requests that are neither read nor write");
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-11-01 16:56:31 +01:00
|
|
|
perBankRdBursts
|
2012-09-21 17:48:13 +02:00
|
|
|
.init(banksPerRank * ranksPerChannel)
|
2013-11-01 16:56:31 +01:00
|
|
|
.name(name() + ".perBankRdBursts")
|
|
|
|
.desc("Per bank write bursts");
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-11-01 16:56:31 +01:00
|
|
|
perBankWrBursts
|
2012-09-21 17:48:13 +02:00
|
|
|
.init(banksPerRank * ranksPerChannel)
|
2013-11-01 16:56:31 +01:00
|
|
|
.name(name() + ".perBankWrBursts")
|
|
|
|
.desc("Per bank write bursts");
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
avgRdQLen
|
|
|
|
.name(name() + ".avgRdQLen")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Average read queue length when enqueuing")
|
2012-09-21 17:48:13 +02:00
|
|
|
.precision(2);
|
|
|
|
|
|
|
|
avgWrQLen
|
|
|
|
.name(name() + ".avgWrQLen")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Average write queue length when enqueuing")
|
2012-09-21 17:48:13 +02:00
|
|
|
.precision(2);
|
|
|
|
|
|
|
|
totQLat
|
|
|
|
.name(name() + ".totQLat")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Total ticks spent queuing");
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
totBankLat
|
|
|
|
.name(name() + ".totBankLat")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Total ticks spent accessing banks");
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
totBusLat
|
|
|
|
.name(name() + ".totBusLat")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Total ticks spent in databus transfers");
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
totMemAccLat
|
|
|
|
.name(name() + ".totMemAccLat")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Total ticks spent from burst creation until serviced "
|
|
|
|
"by the DRAM");
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
avgQLat
|
|
|
|
.name(name() + ".avgQLat")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Average queueing delay per DRAM burst")
|
2012-09-21 17:48:13 +02:00
|
|
|
.precision(2);
|
|
|
|
|
2013-08-19 09:52:30 +02:00
|
|
|
avgQLat = totQLat / (readBursts - servicedByWrQ);
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
avgBankLat
|
|
|
|
.name(name() + ".avgBankLat")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Average bank access latency per DRAM burst")
|
2012-09-21 17:48:13 +02:00
|
|
|
.precision(2);
|
|
|
|
|
2013-08-19 09:52:30 +02:00
|
|
|
avgBankLat = totBankLat / (readBursts - servicedByWrQ);
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
avgBusLat
|
|
|
|
.name(name() + ".avgBusLat")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Average bus latency per DRAM burst")
|
2012-09-21 17:48:13 +02:00
|
|
|
.precision(2);
|
|
|
|
|
2013-08-19 09:52:30 +02:00
|
|
|
avgBusLat = totBusLat / (readBursts - servicedByWrQ);
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
avgMemAccLat
|
|
|
|
.name(name() + ".avgMemAccLat")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Average memory access latency per DRAM burst")
|
2012-09-21 17:48:13 +02:00
|
|
|
.precision(2);
|
|
|
|
|
2013-08-19 09:52:30 +02:00
|
|
|
avgMemAccLat = totMemAccLat / (readBursts - servicedByWrQ);
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
numRdRetry
|
|
|
|
.name(name() + ".numRdRetry")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Number of times read queue was full causing retry");
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
numWrRetry
|
|
|
|
.name(name() + ".numWrRetry")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Number of times write queue was full causing retry");
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
readRowHits
|
|
|
|
.name(name() + ".readRowHits")
|
|
|
|
.desc("Number of row buffer hits during reads");
|
|
|
|
|
|
|
|
writeRowHits
|
|
|
|
.name(name() + ".writeRowHits")
|
|
|
|
.desc("Number of row buffer hits during writes");
|
|
|
|
|
|
|
|
readRowHitRate
|
|
|
|
.name(name() + ".readRowHitRate")
|
|
|
|
.desc("Row buffer hit rate for reads")
|
|
|
|
.precision(2);
|
|
|
|
|
2013-08-19 09:52:30 +02:00
|
|
|
readRowHitRate = (readRowHits / (readBursts - servicedByWrQ)) * 100;
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
writeRowHitRate
|
|
|
|
.name(name() + ".writeRowHitRate")
|
|
|
|
.desc("Row buffer hit rate for writes")
|
|
|
|
.precision(2);
|
|
|
|
|
2013-11-01 16:56:31 +01:00
|
|
|
writeRowHitRate = (writeRowHits / (writeBursts - mergedWrBursts)) * 100;
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
readPktSize
|
2013-08-19 09:52:30 +02:00
|
|
|
.init(ceilLog2(burstSize) + 1)
|
2012-09-21 17:48:13 +02:00
|
|
|
.name(name() + ".readPktSize")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Read request sizes (log2)");
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
writePktSize
|
2013-08-19 09:52:30 +02:00
|
|
|
.init(ceilLog2(burstSize) + 1)
|
2012-09-21 17:48:13 +02:00
|
|
|
.name(name() + ".writePktSize")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Write request sizes (log2)");
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
rdQLenPdf
|
2013-03-01 19:20:24 +01:00
|
|
|
.init(readBufferSize)
|
2012-09-21 17:48:13 +02:00
|
|
|
.name(name() + ".rdQLenPdf")
|
|
|
|
.desc("What read queue length does an incoming req see");
|
|
|
|
|
|
|
|
wrQLenPdf
|
2013-03-01 19:20:24 +01:00
|
|
|
.init(writeBufferSize)
|
2012-09-21 17:48:13 +02:00
|
|
|
.name(name() + ".wrQLenPdf")
|
|
|
|
.desc("What write queue length does an incoming req see");
|
|
|
|
|
2013-05-30 18:54:13 +02:00
|
|
|
bytesPerActivate
|
2014-03-23 16:12:03 +01:00
|
|
|
.init(maxAccessesPerRow)
|
2013-05-30 18:54:13 +02:00
|
|
|
.name(name() + ".bytesPerActivate")
|
|
|
|
.desc("Bytes accessed per row activation")
|
|
|
|
.flags(nozero);
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2014-03-23 16:12:14 +01:00
|
|
|
rdPerTurnAround
|
|
|
|
.init(readBufferSize)
|
|
|
|
.name(name() + ".rdPerTurnAround")
|
|
|
|
.desc("Reads before turning the bus around for writes")
|
|
|
|
.flags(nozero);
|
|
|
|
|
|
|
|
wrPerTurnAround
|
|
|
|
.init(writeBufferSize)
|
|
|
|
.name(name() + ".wrPerTurnAround")
|
|
|
|
.desc("Writes before turning the bus around for reads")
|
|
|
|
.flags(nozero);
|
|
|
|
|
2013-11-01 16:56:28 +01:00
|
|
|
bytesReadDRAM
|
|
|
|
.name(name() + ".bytesReadDRAM")
|
|
|
|
.desc("Total number of bytes read from DRAM");
|
|
|
|
|
|
|
|
bytesReadWrQ
|
|
|
|
.name(name() + ".bytesReadWrQ")
|
|
|
|
.desc("Total number of bytes read from write queue");
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
bytesWritten
|
|
|
|
.name(name() + ".bytesWritten")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Total number of bytes written to DRAM");
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-11-01 16:56:31 +01:00
|
|
|
bytesReadSys
|
|
|
|
.name(name() + ".bytesReadSys")
|
|
|
|
.desc("Total read bytes from the system interface side");
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-11-01 16:56:31 +01:00
|
|
|
bytesWrittenSys
|
|
|
|
.name(name() + ".bytesWrittenSys")
|
|
|
|
.desc("Total written bytes from the system interface side");
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
avgRdBW
|
|
|
|
.name(name() + ".avgRdBW")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Average DRAM read bandwidth in MiByte/s")
|
2012-09-21 17:48:13 +02:00
|
|
|
.precision(2);
|
|
|
|
|
2013-11-01 16:56:31 +01:00
|
|
|
avgRdBW = (bytesReadDRAM / 1000000) / simSeconds;
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
avgWrBW
|
|
|
|
.name(name() + ".avgWrBW")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Average achieved write bandwidth in MiByte/s")
|
2012-09-21 17:48:13 +02:00
|
|
|
.precision(2);
|
|
|
|
|
|
|
|
avgWrBW = (bytesWritten / 1000000) / simSeconds;
|
|
|
|
|
2013-11-01 16:56:31 +01:00
|
|
|
avgRdBWSys
|
|
|
|
.name(name() + ".avgRdBWSys")
|
|
|
|
.desc("Average system read bandwidth in MiByte/s")
|
2012-09-21 17:48:13 +02:00
|
|
|
.precision(2);
|
|
|
|
|
2013-11-01 16:56:31 +01:00
|
|
|
avgRdBWSys = (bytesReadSys / 1000000) / simSeconds;
|
2012-09-21 17:48:13 +02:00
|
|
|
|
2013-11-01 16:56:31 +01:00
|
|
|
avgWrBWSys
|
|
|
|
.name(name() + ".avgWrBWSys")
|
|
|
|
.desc("Average system write bandwidth in MiByte/s")
|
2012-09-21 17:48:13 +02:00
|
|
|
.precision(2);
|
|
|
|
|
2013-11-01 16:56:31 +01:00
|
|
|
avgWrBWSys = (bytesWrittenSys / 1000000) / simSeconds;
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
peakBW
|
|
|
|
.name(name() + ".peakBW")
|
2013-11-01 16:56:31 +01:00
|
|
|
.desc("Theoretical peak bandwidth in MiByte/s")
|
2012-09-21 17:48:13 +02:00
|
|
|
.precision(2);
|
|
|
|
|
2013-08-19 09:52:30 +02:00
|
|
|
peakBW = (SimClock::Frequency / tBURST) * burstSize / 1000000;
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
busUtil
|
|
|
|
.name(name() + ".busUtil")
|
|
|
|
.desc("Data bus utilization in percentage")
|
|
|
|
.precision(2);
|
|
|
|
|
|
|
|
busUtil = (avgRdBW + avgWrBW) / peakBW * 100;
|
|
|
|
|
|
|
|
totGap
|
|
|
|
.name(name() + ".totGap")
|
|
|
|
.desc("Total gap between requests");
|
|
|
|
|
|
|
|
avgGap
|
|
|
|
.name(name() + ".avgGap")
|
|
|
|
.desc("Average gap between requests")
|
|
|
|
.precision(2);
|
|
|
|
|
|
|
|
avgGap = totGap / (readReqs + writeReqs);
|
2013-11-01 16:56:28 +01:00
|
|
|
|
|
|
|
// Stats for DRAM Power calculation based on Micron datasheet
|
|
|
|
busUtilRead
|
|
|
|
.name(name() + ".busUtilRead")
|
|
|
|
.desc("Data bus utilization in percentage for reads")
|
|
|
|
.precision(2);
|
|
|
|
|
|
|
|
busUtilRead = avgRdBW / peakBW * 100;
|
|
|
|
|
|
|
|
busUtilWrite
|
|
|
|
.name(name() + ".busUtilWrite")
|
|
|
|
.desc("Data bus utilization in percentage for writes")
|
|
|
|
.precision(2);
|
|
|
|
|
|
|
|
busUtilWrite = avgWrBW / peakBW * 100;
|
|
|
|
|
|
|
|
pageHitRate
|
|
|
|
.name(name() + ".pageHitRate")
|
|
|
|
.desc("Row buffer hit rate, read and write combined")
|
|
|
|
.precision(2);
|
|
|
|
|
2013-11-01 16:56:31 +01:00
|
|
|
pageHitRate = (writeRowHits + readRowHits) /
|
|
|
|
(writeBursts - mergedWrBursts + readBursts - servicedByWrQ) * 100;
|
2013-11-01 16:56:28 +01:00
|
|
|
|
|
|
|
prechargeAllPercent
|
|
|
|
.name(name() + ".prechargeAllPercent")
|
|
|
|
.desc("Percentage of time for which DRAM has all the banks in "
|
|
|
|
"precharge state")
|
|
|
|
.precision(2);
|
|
|
|
|
|
|
|
prechargeAllPercent = prechargeAllTime / simTicks * 100;
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::recvFunctional(PacketPtr pkt)
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
|
|
|
// rely on the abstract memory
|
|
|
|
functionalAccess(pkt);
|
|
|
|
}
|
|
|
|
|
2012-10-15 14:12:35 +02:00
|
|
|
BaseSlavePort&
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::getSlavePort(const string &if_name, PortID idx)
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
|
|
|
if (if_name != "port") {
|
|
|
|
return MemObject::getSlavePort(if_name, idx);
|
|
|
|
} else {
|
|
|
|
return port;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::drain(DrainManager *dm)
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
2012-11-02 17:32:01 +01:00
|
|
|
unsigned int count = port.drain(dm);
|
2012-09-21 17:48:13 +02:00
|
|
|
|
|
|
|
// if there is anything in any of our internal queues, keep track
|
|
|
|
// of that as well
|
2013-03-01 19:20:24 +01:00
|
|
|
if (!(writeQueue.empty() && readQueue.empty() &&
|
|
|
|
respQueue.empty())) {
|
2012-11-08 10:25:06 +01:00
|
|
|
DPRINTF(Drain, "DRAM controller not drained, write: %d, read: %d,"
|
2013-03-01 19:20:24 +01:00
|
|
|
" resp: %d\n", writeQueue.size(), readQueue.size(),
|
|
|
|
respQueue.size());
|
2012-09-21 17:48:13 +02:00
|
|
|
++count;
|
2012-11-02 17:32:01 +01:00
|
|
|
drainManager = dm;
|
2012-11-08 10:25:06 +01:00
|
|
|
// the only part that is not drained automatically over time
|
|
|
|
// is the write queue, thus trigger writes if there are any
|
|
|
|
// waiting and no reads waiting, otherwise wait until the
|
|
|
|
// reads are done
|
2013-03-01 19:20:24 +01:00
|
|
|
if (readQueue.empty() && !writeQueue.empty() &&
|
2012-11-08 10:25:06 +01:00
|
|
|
!writeEvent.scheduled())
|
|
|
|
triggerWrites();
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count)
|
2012-11-02 17:32:01 +01:00
|
|
|
setDrainState(Drainable::Draining);
|
2012-09-21 17:48:13 +02:00
|
|
|
else
|
2012-11-02 17:32:01 +01:00
|
|
|
setDrainState(Drainable::Drained);
|
2012-09-21 17:48:13 +02:00
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::MemoryPort::MemoryPort(const std::string& name, DRAMCtrl& _memory)
|
2012-09-21 17:48:13 +02:00
|
|
|
: QueuedSlavePort(name, &_memory, queue), queue(_memory, *this),
|
|
|
|
memory(_memory)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
AddrRangeList
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::MemoryPort::getAddrRanges() const
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
|
|
|
AddrRangeList ranges;
|
|
|
|
ranges.push_back(memory.getAddrRange());
|
|
|
|
return ranges;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::MemoryPort::recvFunctional(PacketPtr pkt)
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
|
|
|
pkt->pushLabel(memory.name());
|
|
|
|
|
|
|
|
if (!queue.checkFunctional(pkt)) {
|
|
|
|
// Default implementation of SimpleTimingPort::recvFunctional()
|
|
|
|
// calls recvAtomic() and throws away the latency; we can save a
|
|
|
|
// little here by just not calculating the latency.
|
|
|
|
memory.recvFunctional(pkt);
|
|
|
|
}
|
|
|
|
|
|
|
|
pkt->popLabel();
|
|
|
|
}
|
|
|
|
|
|
|
|
Tick
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::MemoryPort::recvAtomic(PacketPtr pkt)
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
|
|
|
return memory.recvAtomic(pkt);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl::MemoryPort::recvTimingReq(PacketPtr pkt)
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
|
|
|
// pass it to the memory controller
|
|
|
|
return memory.recvTimingReq(pkt);
|
|
|
|
}
|
|
|
|
|
2014-03-23 16:12:12 +01:00
|
|
|
DRAMCtrl*
|
|
|
|
DRAMCtrlParams::create()
|
2012-09-21 17:48:13 +02:00
|
|
|
{
|
2014-03-23 16:12:12 +01:00
|
|
|
return new DRAMCtrl(this);
|
2012-09-21 17:48:13 +02:00
|
|
|
}
|