base.cc revision 11484
16313Sgblack@eecs.umich.edu/*
27093Sgblack@eecs.umich.edu * Copyright (c) 2012-2013 ARM Limited
37093Sgblack@eecs.umich.edu * All rights reserved.
47093Sgblack@eecs.umich.edu *
57093Sgblack@eecs.umich.edu * The license below extends only to copyright in the software and shall
67093Sgblack@eecs.umich.edu * not be construed as granting a license to any other intellectual
77093Sgblack@eecs.umich.edu * property including but not limited to intellectual property relating
87093Sgblack@eecs.umich.edu * to a hardware implementation of the functionality of the software
97093Sgblack@eecs.umich.edu * licensed hereunder.  You may use the software subject to the license
107093Sgblack@eecs.umich.edu * terms below provided that you ensure that this notice is replicated
117093Sgblack@eecs.umich.edu * unmodified and in its entirety in all distributions of the software,
127093Sgblack@eecs.umich.edu * modified or unmodified, in source code or in binary form.
137093Sgblack@eecs.umich.edu *
146313Sgblack@eecs.umich.edu * Copyright (c) 2003-2005 The Regents of The University of Michigan
156313Sgblack@eecs.umich.edu * All rights reserved.
166313Sgblack@eecs.umich.edu *
176313Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without
186313Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are
196313Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright
206313Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer;
216313Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright
226313Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the
236313Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution;
246313Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its
256313Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from
266313Sgblack@eecs.umich.edu * this software without specific prior written permission.
276313Sgblack@eecs.umich.edu *
286313Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
296313Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
306313Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
316313Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
326313Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
336313Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
346313Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
356313Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
366313Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
376313Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
386313Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
396313Sgblack@eecs.umich.edu *
406313Sgblack@eecs.umich.edu * Authors: Erik Hallnor
416313Sgblack@eecs.umich.edu */
426313Sgblack@eecs.umich.edu
436313Sgblack@eecs.umich.edu/**
446313Sgblack@eecs.umich.edu * @file
456313Sgblack@eecs.umich.edu * Definition of BaseCache functions.
466333Sgblack@eecs.umich.edu */
476313Sgblack@eecs.umich.edu
486313Sgblack@eecs.umich.edu#include "debug/Cache.hh"
496333Sgblack@eecs.umich.edu#include "debug/Drain.hh"
506313Sgblack@eecs.umich.edu#include "mem/cache/tags/fa_lru.hh"
516313Sgblack@eecs.umich.edu#include "mem/cache/tags/lru.hh"
526313Sgblack@eecs.umich.edu#include "mem/cache/tags/random_repl.hh"
536313Sgblack@eecs.umich.edu#include "mem/cache/base.hh"
546313Sgblack@eecs.umich.edu#include "mem/cache/cache.hh"
556313Sgblack@eecs.umich.edu#include "mem/cache/mshr.hh"
566313Sgblack@eecs.umich.edu#include "sim/full_system.hh"
576313Sgblack@eecs.umich.edu
586333Sgblack@eecs.umich.eduusing namespace std;
596718Sgblack@eecs.umich.edu
606718Sgblack@eecs.umich.eduBaseCache::CacheSlavePort::CacheSlavePort(const std::string &_name,
616718Sgblack@eecs.umich.edu                                          BaseCache *_cache,
626718Sgblack@eecs.umich.edu                                          const std::string &_label)
636718Sgblack@eecs.umich.edu    : QueuedSlavePort(_name, _cache, queue), queue(*_cache, *this, _label),
646718Sgblack@eecs.umich.edu      blocked(false), mustSendRetry(false), sendRetryEvent(this)
656718Sgblack@eecs.umich.edu{
666718Sgblack@eecs.umich.edu}
676718Sgblack@eecs.umich.edu
686718Sgblack@eecs.umich.eduBaseCache::BaseCache(const BaseCacheParams *p, unsigned blk_size)
696718Sgblack@eecs.umich.edu    : MemObject(p),
706718Sgblack@eecs.umich.edu      cpuSidePort(nullptr), memSidePort(nullptr),
716718Sgblack@eecs.umich.edu      mshrQueue("MSHRs", p->mshrs, 0, p->demand_mshr_reserve), // see below
726718Sgblack@eecs.umich.edu      writeBuffer("write buffer", p->write_buffers, p->mshrs), // see below
736718Sgblack@eecs.umich.edu      blkSize(blk_size),
746718Sgblack@eecs.umich.edu      lookupLatency(p->hit_latency),
756718Sgblack@eecs.umich.edu      forwardLatency(p->hit_latency),
766718Sgblack@eecs.umich.edu      fillLatency(p->response_latency),
776718Sgblack@eecs.umich.edu      responseLatency(p->response_latency),
786723Sgblack@eecs.umich.edu      numTarget(p->tgts_per_mshr),
796723Sgblack@eecs.umich.edu      forwardSnoops(true),
806723Sgblack@eecs.umich.edu      isReadOnly(p->is_read_only),
816718Sgblack@eecs.umich.edu      blocked(0),
826718Sgblack@eecs.umich.edu      order(0),
836718Sgblack@eecs.umich.edu      noTargetMSHR(nullptr),
846718Sgblack@eecs.umich.edu      missCount(p->max_miss_count),
856718Sgblack@eecs.umich.edu      addrRanges(p->addr_ranges.begin(), p->addr_ranges.end()),
866718Sgblack@eecs.umich.edu      system(p->system)
876718Sgblack@eecs.umich.edu{
886718Sgblack@eecs.umich.edu    // the MSHR queue has no reserve entries as we check the MSHR
896718Sgblack@eecs.umich.edu    // queue on every single allocation, whereas the write queue has
906718Sgblack@eecs.umich.edu    // as many reserve entries as we have MSHRs, since every MSHR may
916313Sgblack@eecs.umich.edu    // eventually require a writeback, and we do not check the write
926313Sgblack@eecs.umich.edu    // buffer before committing to an MSHR
936333Sgblack@eecs.umich.edu
946333Sgblack@eecs.umich.edu    // forward snoops is overridden in init() once we can query
957400SAli.Saidi@ARM.com    // whether the connected master is actually snooping or not
967400SAli.Saidi@ARM.com}
976401Sgblack@eecs.umich.edu
986401Sgblack@eecs.umich.eduvoid
996719Sgblack@eecs.umich.eduBaseCache::CacheSlavePort::setBlocked()
1006401Sgblack@eecs.umich.edu{
1016718Sgblack@eecs.umich.edu    assert(!blocked);
1026735Sgblack@eecs.umich.edu    DPRINTF(CachePort, "Port is blocking new requests\n");
1036735Sgblack@eecs.umich.edu    blocked = true;
1047400SAli.Saidi@ARM.com    // if we already scheduled a retry in this cycle, but it has not yet
1057400SAli.Saidi@ARM.com    // happened, cancel it
1067400SAli.Saidi@ARM.com    if (sendRetryEvent.scheduled()) {
1076735Sgblack@eecs.umich.edu        owner.deschedule(sendRetryEvent);
1086735Sgblack@eecs.umich.edu        DPRINTF(CachePort, "Port descheduled retry\n");
1096735Sgblack@eecs.umich.edu        mustSendRetry = true;
1106735Sgblack@eecs.umich.edu    }
1117270Sgblack@eecs.umich.edu}
1127400SAli.Saidi@ARM.com
1137400SAli.Saidi@ARM.comvoid
1146735Sgblack@eecs.umich.eduBaseCache::CacheSlavePort::clearBlocked()
1157271Sgblack@eecs.umich.edu{
1167271Sgblack@eecs.umich.edu    assert(blocked);
1177271Sgblack@eecs.umich.edu    DPRINTF(CachePort, "Port is accepting new requests\n");
1187271Sgblack@eecs.umich.edu    blocked = false;
1197320Sgblack@eecs.umich.edu    if (mustSendRetry) {
1207320Sgblack@eecs.umich.edu        // @TODO: need to find a better time (next cycle?)
1217320Sgblack@eecs.umich.edu        owner.schedule(sendRetryEvent, curTick() + 1);
1227320Sgblack@eecs.umich.edu    }
1237320Sgblack@eecs.umich.edu}
1247271Sgblack@eecs.umich.edu
1257350SAli.Saidi@ARM.comvoid
1267350SAli.Saidi@ARM.comBaseCache::CacheSlavePort::processSendRetry()
1277350SAli.Saidi@ARM.com{
1287298Sgblack@eecs.umich.edu    DPRINTF(CachePort, "Port is sending retry\n");
1297298Sgblack@eecs.umich.edu
1307298Sgblack@eecs.umich.edu    // reset the flag and call retry
1317298Sgblack@eecs.umich.edu    mustSendRetry = false;
1327298Sgblack@eecs.umich.edu    sendRetryReq();
1337298Sgblack@eecs.umich.edu}
1347298Sgblack@eecs.umich.edu
1357298Sgblack@eecs.umich.eduvoid
1367298Sgblack@eecs.umich.eduBaseCache::init()
1377298Sgblack@eecs.umich.edu{
1387298Sgblack@eecs.umich.edu    if (!cpuSidePort->isConnected() || !memSidePort->isConnected())
1397298Sgblack@eecs.umich.edu        fatal("Cache ports on %s are not connected\n", name());
1407354Sgblack@eecs.umich.edu    cpuSidePort->sendRangeChange();
1417354Sgblack@eecs.umich.edu    forwardSnoops = cpuSidePort->isSnooping();
1427354Sgblack@eecs.umich.edu}
1437383Sgblack@eecs.umich.edu
1447383Sgblack@eecs.umich.eduBaseMasterPort &
1457383Sgblack@eecs.umich.eduBaseCache::getMasterPort(const std::string &if_name, PortID idx)
1467383Sgblack@eecs.umich.edu{
1477383Sgblack@eecs.umich.edu    if (if_name == "mem_side") {
1487383Sgblack@eecs.umich.edu        return *memSidePort;
1497383Sgblack@eecs.umich.edu    }  else {
1507383Sgblack@eecs.umich.edu        return MemObject::getMasterPort(if_name, idx);
1517383Sgblack@eecs.umich.edu    }
1527383Sgblack@eecs.umich.edu}
1537383Sgblack@eecs.umich.edu
1547383Sgblack@eecs.umich.eduBaseSlavePort &
1557383Sgblack@eecs.umich.eduBaseCache::getSlavePort(const std::string &if_name, PortID idx)
1567383Sgblack@eecs.umich.edu{
1577383Sgblack@eecs.umich.edu    if (if_name == "cpu_side") {
1587383Sgblack@eecs.umich.edu        return *cpuSidePort;
1597383Sgblack@eecs.umich.edu    } else {
1607383Sgblack@eecs.umich.edu        return MemObject::getSlavePort(if_name, idx);
1617383Sgblack@eecs.umich.edu    }
1627383Sgblack@eecs.umich.edu}
1637383Sgblack@eecs.umich.edu
1647390Sgblack@eecs.umich.edubool
1657390Sgblack@eecs.umich.eduBaseCache::inRange(Addr addr) const
1666401Sgblack@eecs.umich.edu{
1676333Sgblack@eecs.umich.edu    for (const auto& r : addrRanges) {
1686313Sgblack@eecs.umich.edu        if (r.contains(addr)) {
1696333Sgblack@eecs.umich.edu            return true;
1706333Sgblack@eecs.umich.edu       }
1716333Sgblack@eecs.umich.edu    }
1726333Sgblack@eecs.umich.edu    return false;
1736745Sgblack@eecs.umich.edu}
1746745Sgblack@eecs.umich.edu
1756745Sgblack@eecs.umich.eduvoid
1766745Sgblack@eecs.umich.eduBaseCache::regStats()
1776745Sgblack@eecs.umich.edu{
1786745Sgblack@eecs.umich.edu    using namespace Stats;
1796745Sgblack@eecs.umich.edu
1806745Sgblack@eecs.umich.edu    // Hit statistics
1816745Sgblack@eecs.umich.edu    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
1826745Sgblack@eecs.umich.edu        MemCmd cmd(access_idx);
1836745Sgblack@eecs.umich.edu        const string &cstr = cmd.toString();
1846745Sgblack@eecs.umich.edu
1856745Sgblack@eecs.umich.edu        hits[access_idx]
1866745Sgblack@eecs.umich.edu            .init(system->maxMasters())
1876745Sgblack@eecs.umich.edu            .name(name() + "." + cstr + "_hits")
1886745Sgblack@eecs.umich.edu            .desc("number of " + cstr + " hits")
1896745Sgblack@eecs.umich.edu            .flags(total | nozero | nonan)
1906745Sgblack@eecs.umich.edu            ;
1916745Sgblack@eecs.umich.edu        for (int i = 0; i < system->maxMasters(); i++) {
1926745Sgblack@eecs.umich.edu            hits[access_idx].subname(i, system->getMasterName(i));
1936745Sgblack@eecs.umich.edu        }
1946333Sgblack@eecs.umich.edu    }
1956333Sgblack@eecs.umich.edu
1966313Sgblack@eecs.umich.edu// These macros make it easier to sum the right subset of commands and
1976333Sgblack@eecs.umich.edu// to change the subset of commands that are considered "demand" vs
1986333Sgblack@eecs.umich.edu// "non-demand"
1996333Sgblack@eecs.umich.edu#define SUM_DEMAND(s) \
2007093Sgblack@eecs.umich.edu    (s[MemCmd::ReadReq] + s[MemCmd::WriteReq] + s[MemCmd::WriteLineReq] + \
2017093Sgblack@eecs.umich.edu     s[MemCmd::ReadExReq] + s[MemCmd::ReadCleanReq] + s[MemCmd::ReadSharedReq])
2027093Sgblack@eecs.umich.edu
2037093Sgblack@eecs.umich.edu// should writebacks be included here?  prior code was inconsistent...
2047093Sgblack@eecs.umich.edu#define SUM_NON_DEMAND(s) \
2057093Sgblack@eecs.umich.edu    (s[MemCmd::SoftPFReq] + s[MemCmd::HardPFReq])
2067093Sgblack@eecs.umich.edu
2077093Sgblack@eecs.umich.edu    demandHits
2087093Sgblack@eecs.umich.edu        .name(name() + ".demand_hits")
2097093Sgblack@eecs.umich.edu        .desc("number of demand (read+write) hits")
2107093Sgblack@eecs.umich.edu        .flags(total | nozero | nonan)
2117093Sgblack@eecs.umich.edu        ;
2127093Sgblack@eecs.umich.edu    demandHits = SUM_DEMAND(hits);
2137259Sgblack@eecs.umich.edu    for (int i = 0; i < system->maxMasters(); i++) {
2147259Sgblack@eecs.umich.edu        demandHits.subname(i, system->getMasterName(i));
2157259Sgblack@eecs.umich.edu    }
2167259Sgblack@eecs.umich.edu
2177259Sgblack@eecs.umich.edu    overallHits
2187273Sgblack@eecs.umich.edu        .name(name() + ".overall_hits")
2197273Sgblack@eecs.umich.edu        .desc("number of overall hits")
2207273Sgblack@eecs.umich.edu        .flags(total | nozero | nonan)
2217273Sgblack@eecs.umich.edu        ;
2227287Sgblack@eecs.umich.edu    overallHits = demandHits + SUM_NON_DEMAND(hits);
2237287Sgblack@eecs.umich.edu    for (int i = 0; i < system->maxMasters(); i++) {
2247287Sgblack@eecs.umich.edu        overallHits.subname(i, system->getMasterName(i));
2257287Sgblack@eecs.umich.edu    }
2267273Sgblack@eecs.umich.edu
2276745Sgblack@eecs.umich.edu    // Miss statistics
2286333Sgblack@eecs.umich.edu    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
2296333Sgblack@eecs.umich.edu        MemCmd cmd(access_idx);
2306333Sgblack@eecs.umich.edu        const string &cstr = cmd.toString();
2316333Sgblack@eecs.umich.edu
2326333Sgblack@eecs.umich.edu        misses[access_idx]
2336333Sgblack@eecs.umich.edu            .init(system->maxMasters())
2346745Sgblack@eecs.umich.edu            .name(name() + "." + cstr + "_misses")
2356745Sgblack@eecs.umich.edu            .desc("number of " + cstr + " misses")
2366745Sgblack@eecs.umich.edu            .flags(total | nozero | nonan)
2376745Sgblack@eecs.umich.edu            ;
2386745Sgblack@eecs.umich.edu        for (int i = 0; i < system->maxMasters(); i++) {
2396745Sgblack@eecs.umich.edu            misses[access_idx].subname(i, system->getMasterName(i));
2406745Sgblack@eecs.umich.edu        }
2416745Sgblack@eecs.umich.edu    }
2426745Sgblack@eecs.umich.edu
2436745Sgblack@eecs.umich.edu    demandMisses
2446745Sgblack@eecs.umich.edu        .name(name() + ".demand_misses")
2456745Sgblack@eecs.umich.edu        .desc("number of demand (read+write) misses")
2466745Sgblack@eecs.umich.edu        .flags(total | nozero | nonan)
2476745Sgblack@eecs.umich.edu        ;
2486745Sgblack@eecs.umich.edu    demandMisses = SUM_DEMAND(misses);
2496745Sgblack@eecs.umich.edu    for (int i = 0; i < system->maxMasters(); i++) {
2506745Sgblack@eecs.umich.edu        demandMisses.subname(i, system->getMasterName(i));
2516745Sgblack@eecs.umich.edu    }
2526745Sgblack@eecs.umich.edu
2536745Sgblack@eecs.umich.edu    overallMisses
2546745Sgblack@eecs.umich.edu        .name(name() + ".overall_misses")
2556745Sgblack@eecs.umich.edu        .desc("number of overall misses")
2566745Sgblack@eecs.umich.edu        .flags(total | nozero | nonan)
2576745Sgblack@eecs.umich.edu        ;
2586745Sgblack@eecs.umich.edu    overallMisses = demandMisses + SUM_NON_DEMAND(misses);
2596745Sgblack@eecs.umich.edu    for (int i = 0; i < system->maxMasters(); i++) {
2606745Sgblack@eecs.umich.edu        overallMisses.subname(i, system->getMasterName(i));
2616745Sgblack@eecs.umich.edu    }
2626745Sgblack@eecs.umich.edu
2636333Sgblack@eecs.umich.edu    // Miss latency statistics
2646333Sgblack@eecs.umich.edu    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
2656333Sgblack@eecs.umich.edu        MemCmd cmd(access_idx);
2666333Sgblack@eecs.umich.edu        const string &cstr = cmd.toString();
2676333Sgblack@eecs.umich.edu
2686333Sgblack@eecs.umich.edu        missLatency[access_idx]
2697271Sgblack@eecs.umich.edu            .init(system->maxMasters())
2706718Sgblack@eecs.umich.edu            .name(name() + "." + cstr + "_miss_latency")
2716718Sgblack@eecs.umich.edu            .desc("number of " + cstr + " miss cycles")
2727093Sgblack@eecs.umich.edu            .flags(total | nozero | nonan)
2737348SAli.Saidi@ARM.com            ;
2747348SAli.Saidi@ARM.com        for (int i = 0; i < system->maxMasters(); i++) {
2757093Sgblack@eecs.umich.edu            missLatency[access_idx].subname(i, system->getMasterName(i));
2767093Sgblack@eecs.umich.edu        }
2777093Sgblack@eecs.umich.edu    }
2787093Sgblack@eecs.umich.edu
2797093Sgblack@eecs.umich.edu    demandMissLatency
2807093Sgblack@eecs.umich.edu        .name(name() + ".demand_miss_latency")
2817093Sgblack@eecs.umich.edu        .desc("number of demand (read+write) miss cycles")
2826718Sgblack@eecs.umich.edu        .flags(total | nozero | nonan)
2837259Sgblack@eecs.umich.edu        ;
2847259Sgblack@eecs.umich.edu    demandMissLatency = SUM_DEMAND(missLatency);
2857259Sgblack@eecs.umich.edu    for (int i = 0; i < system->maxMasters(); i++) {
2867259Sgblack@eecs.umich.edu        demandMissLatency.subname(i, system->getMasterName(i));
2877259Sgblack@eecs.umich.edu    }
2887271Sgblack@eecs.umich.edu
2897271Sgblack@eecs.umich.edu    overallMissLatency
2907320Sgblack@eecs.umich.edu        .name(name() + ".overall_miss_latency")
2917320Sgblack@eecs.umich.edu        .desc("number of overall miss cycles")
2927320Sgblack@eecs.umich.edu        .flags(total | nozero | nonan)
2937320Sgblack@eecs.umich.edu        ;
2947320Sgblack@eecs.umich.edu    overallMissLatency = demandMissLatency + SUM_NON_DEMAND(missLatency);
2957320Sgblack@eecs.umich.edu    for (int i = 0; i < system->maxMasters(); i++) {
2967320Sgblack@eecs.umich.edu        overallMissLatency.subname(i, system->getMasterName(i));
2977320Sgblack@eecs.umich.edu    }
2987320Sgblack@eecs.umich.edu
2997271Sgblack@eecs.umich.edu    // access formulas
3007271Sgblack@eecs.umich.edu    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
3017287Sgblack@eecs.umich.edu        MemCmd cmd(access_idx);
3027287Sgblack@eecs.umich.edu        const string &cstr = cmd.toString();
3037287Sgblack@eecs.umich.edu
3047393Sgblack@eecs.umich.edu        accesses[access_idx]
3057393Sgblack@eecs.umich.edu            .name(name() + "." + cstr + "_accesses")
3067393Sgblack@eecs.umich.edu            .desc("number of " + cstr + " accesses(hits+misses)")
3077393Sgblack@eecs.umich.edu            .flags(total | nozero | nonan)
3087393Sgblack@eecs.umich.edu            ;
3097393Sgblack@eecs.umich.edu        accesses[access_idx] = hits[access_idx] + misses[access_idx];
3107393Sgblack@eecs.umich.edu
3117393Sgblack@eecs.umich.edu        for (int i = 0; i < system->maxMasters(); i++) {
3127393Sgblack@eecs.umich.edu            accesses[access_idx].subname(i, system->getMasterName(i));
3137393Sgblack@eecs.umich.edu        }
3147393Sgblack@eecs.umich.edu    }
3157393Sgblack@eecs.umich.edu
3167393Sgblack@eecs.umich.edu    demandAccesses
3177393Sgblack@eecs.umich.edu        .name(name() + ".demand_accesses")
3187393Sgblack@eecs.umich.edu        .desc("number of demand (read+write) accesses")
3197393Sgblack@eecs.umich.edu        .flags(total | nozero | nonan)
3207393Sgblack@eecs.umich.edu        ;
3217393Sgblack@eecs.umich.edu    demandAccesses = demandHits + demandMisses;
3227393Sgblack@eecs.umich.edu    for (int i = 0; i < system->maxMasters(); i++) {
3237393Sgblack@eecs.umich.edu        demandAccesses.subname(i, system->getMasterName(i));
3247393Sgblack@eecs.umich.edu    }
3257393Sgblack@eecs.umich.edu
3267393Sgblack@eecs.umich.edu    overallAccesses
3277393Sgblack@eecs.umich.edu        .name(name() + ".overall_accesses")
3287393Sgblack@eecs.umich.edu        .desc("number of overall (read+write) accesses")
3297393Sgblack@eecs.umich.edu        .flags(total | nozero | nonan)
3307393Sgblack@eecs.umich.edu        ;
3317393Sgblack@eecs.umich.edu    overallAccesses = overallHits + overallMisses;
3327393Sgblack@eecs.umich.edu    for (int i = 0; i < system->maxMasters(); i++) {
3337393Sgblack@eecs.umich.edu        overallAccesses.subname(i, system->getMasterName(i));
3347393Sgblack@eecs.umich.edu    }
3357393Sgblack@eecs.umich.edu
3367400SAli.Saidi@ARM.com    // miss rate formulas
3377400SAli.Saidi@ARM.com    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
3387400SAli.Saidi@ARM.com        MemCmd cmd(access_idx);
3397400SAli.Saidi@ARM.com        const string &cstr = cmd.toString();
3407400SAli.Saidi@ARM.com
3417400SAli.Saidi@ARM.com        missRate[access_idx]
3427400SAli.Saidi@ARM.com            .name(name() + "." + cstr + "_miss_rate")
3437400SAli.Saidi@ARM.com            .desc("miss rate for " + cstr + " accesses")
3447354Sgblack@eecs.umich.edu            .flags(total | nozero | nonan)
3457383Sgblack@eecs.umich.edu            ;
3467383Sgblack@eecs.umich.edu        missRate[access_idx] = misses[access_idx] / accesses[access_idx];
3477390Sgblack@eecs.umich.edu
3487393Sgblack@eecs.umich.edu        for (int i = 0; i < system->maxMasters(); i++) {
3497354Sgblack@eecs.umich.edu            missRate[access_idx].subname(i, system->getMasterName(i));
3507271Sgblack@eecs.umich.edu        }
3517400SAli.Saidi@ARM.com    }
3526333Sgblack@eecs.umich.edu
3536313Sgblack@eecs.umich.edu    demandMissRate
3546313Sgblack@eecs.umich.edu        .name(name() + ".demand_miss_rate")
3556313Sgblack@eecs.umich.edu        .desc("miss rate for demand accesses")
3566313Sgblack@eecs.umich.edu        .flags(total | nozero | nonan)
3576718Sgblack@eecs.umich.edu        ;
3586718Sgblack@eecs.umich.edu    demandMissRate = demandMisses / demandAccesses;
3596718Sgblack@eecs.umich.edu    for (int i = 0; i < system->maxMasters(); i++) {
3606726Sgblack@eecs.umich.edu        demandMissRate.subname(i, system->getMasterName(i));
3616726Sgblack@eecs.umich.edu    }
3626718Sgblack@eecs.umich.edu
3637310Sgblack@eecs.umich.edu    overallMissRate
3647310Sgblack@eecs.umich.edu        .name(name() + ".overall_miss_rate")
3657310Sgblack@eecs.umich.edu        .desc("miss rate for overall accesses")
3667310Sgblack@eecs.umich.edu        .flags(total | nozero | nonan)
3677310Sgblack@eecs.umich.edu        ;
3687310Sgblack@eecs.umich.edu    overallMissRate = overallMisses / overallAccesses;
3697310Sgblack@eecs.umich.edu    for (int i = 0; i < system->maxMasters(); i++) {
3707310Sgblack@eecs.umich.edu        overallMissRate.subname(i, system->getMasterName(i));
3717310Sgblack@eecs.umich.edu    }
3727310Sgblack@eecs.umich.edu
3737310Sgblack@eecs.umich.edu    // miss latency formulas
3747310Sgblack@eecs.umich.edu    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
3757310Sgblack@eecs.umich.edu        MemCmd cmd(access_idx);
3767310Sgblack@eecs.umich.edu        const string &cstr = cmd.toString();
3777310Sgblack@eecs.umich.edu
3787310Sgblack@eecs.umich.edu        avgMissLatency[access_idx]
3797310Sgblack@eecs.umich.edu            .name(name() + "." + cstr + "_avg_miss_latency")
3807310Sgblack@eecs.umich.edu            .desc("average " + cstr + " miss latency")
3817310Sgblack@eecs.umich.edu            .flags(total | nozero | nonan)
3827310Sgblack@eecs.umich.edu            ;
3837310Sgblack@eecs.umich.edu        avgMissLatency[access_idx] =
3846718Sgblack@eecs.umich.edu            missLatency[access_idx] / misses[access_idx];
3856313Sgblack@eecs.umich.edu
3866313Sgblack@eecs.umich.edu        for (int i = 0; i < system->maxMasters(); i++) {
3876313Sgblack@eecs.umich.edu            avgMissLatency[access_idx].subname(i, system->getMasterName(i));
3886313Sgblack@eecs.umich.edu        }
3896313Sgblack@eecs.umich.edu    }
3906313Sgblack@eecs.umich.edu
3916313Sgblack@eecs.umich.edu    demandAvgMissLatency
3926313Sgblack@eecs.umich.edu        .name(name() + ".demand_avg_miss_latency")
3936678Sgblack@eecs.umich.edu        .desc("average overall miss latency")
3946333Sgblack@eecs.umich.edu        .flags(total | nozero | nonan)
3956678Sgblack@eecs.umich.edu        ;
3966678Sgblack@eecs.umich.edu    demandAvgMissLatency = demandMissLatency / demandMisses;
3976333Sgblack@eecs.umich.edu    for (int i = 0; i < system->maxMasters(); i++) {
3986313Sgblack@eecs.umich.edu        demandAvgMissLatency.subname(i, system->getMasterName(i));
3996313Sgblack@eecs.umich.edu    }
4006313Sgblack@eecs.umich.edu
4017400SAli.Saidi@ARM.com    overallAvgMissLatency
4027400SAli.Saidi@ARM.com        .name(name() + ".overall_avg_miss_latency")
4037400SAli.Saidi@ARM.com        .desc("average overall miss latency")
4047400SAli.Saidi@ARM.com        .flags(total | nozero | nonan)
4056313Sgblack@eecs.umich.edu        ;
4066313Sgblack@eecs.umich.edu    overallAvgMissLatency = overallMissLatency / overallMisses;
4076313Sgblack@eecs.umich.edu    for (int i = 0; i < system->maxMasters(); i++) {
4086313Sgblack@eecs.umich.edu        overallAvgMissLatency.subname(i, system->getMasterName(i));
4096313Sgblack@eecs.umich.edu    }
4106313Sgblack@eecs.umich.edu
411    blocked_cycles.init(NUM_BLOCKED_CAUSES);
412    blocked_cycles
413        .name(name() + ".blocked_cycles")
414        .desc("number of cycles access was blocked")
415        .subname(Blocked_NoMSHRs, "no_mshrs")
416        .subname(Blocked_NoTargets, "no_targets")
417        ;
418
419
420    blocked_causes.init(NUM_BLOCKED_CAUSES);
421    blocked_causes
422        .name(name() + ".blocked")
423        .desc("number of cycles access was blocked")
424        .subname(Blocked_NoMSHRs, "no_mshrs")
425        .subname(Blocked_NoTargets, "no_targets")
426        ;
427
428    avg_blocked
429        .name(name() + ".avg_blocked_cycles")
430        .desc("average number of cycles each access was blocked")
431        .subname(Blocked_NoMSHRs, "no_mshrs")
432        .subname(Blocked_NoTargets, "no_targets")
433        ;
434
435    avg_blocked = blocked_cycles / blocked_causes;
436
437    unusedPrefetches
438        .name(name() + ".unused_prefetches")
439        .desc("number of HardPF blocks evicted w/o reference")
440        .flags(nozero)
441        ;
442
443    writebacks
444        .init(system->maxMasters())
445        .name(name() + ".writebacks")
446        .desc("number of writebacks")
447        .flags(total | nozero | nonan)
448        ;
449    for (int i = 0; i < system->maxMasters(); i++) {
450        writebacks.subname(i, system->getMasterName(i));
451    }
452
453    // MSHR statistics
454    // MSHR hit statistics
455    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
456        MemCmd cmd(access_idx);
457        const string &cstr = cmd.toString();
458
459        mshr_hits[access_idx]
460            .init(system->maxMasters())
461            .name(name() + "." + cstr + "_mshr_hits")
462            .desc("number of " + cstr + " MSHR hits")
463            .flags(total | nozero | nonan)
464            ;
465        for (int i = 0; i < system->maxMasters(); i++) {
466            mshr_hits[access_idx].subname(i, system->getMasterName(i));
467        }
468    }
469
470    demandMshrHits
471        .name(name() + ".demand_mshr_hits")
472        .desc("number of demand (read+write) MSHR hits")
473        .flags(total | nozero | nonan)
474        ;
475    demandMshrHits = SUM_DEMAND(mshr_hits);
476    for (int i = 0; i < system->maxMasters(); i++) {
477        demandMshrHits.subname(i, system->getMasterName(i));
478    }
479
480    overallMshrHits
481        .name(name() + ".overall_mshr_hits")
482        .desc("number of overall MSHR hits")
483        .flags(total | nozero | nonan)
484        ;
485    overallMshrHits = demandMshrHits + SUM_NON_DEMAND(mshr_hits);
486    for (int i = 0; i < system->maxMasters(); i++) {
487        overallMshrHits.subname(i, system->getMasterName(i));
488    }
489
490    // MSHR miss statistics
491    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
492        MemCmd cmd(access_idx);
493        const string &cstr = cmd.toString();
494
495        mshr_misses[access_idx]
496            .init(system->maxMasters())
497            .name(name() + "." + cstr + "_mshr_misses")
498            .desc("number of " + cstr + " MSHR misses")
499            .flags(total | nozero | nonan)
500            ;
501        for (int i = 0; i < system->maxMasters(); i++) {
502            mshr_misses[access_idx].subname(i, system->getMasterName(i));
503        }
504    }
505
506    demandMshrMisses
507        .name(name() + ".demand_mshr_misses")
508        .desc("number of demand (read+write) MSHR misses")
509        .flags(total | nozero | nonan)
510        ;
511    demandMshrMisses = SUM_DEMAND(mshr_misses);
512    for (int i = 0; i < system->maxMasters(); i++) {
513        demandMshrMisses.subname(i, system->getMasterName(i));
514    }
515
516    overallMshrMisses
517        .name(name() + ".overall_mshr_misses")
518        .desc("number of overall MSHR misses")
519        .flags(total | nozero | nonan)
520        ;
521    overallMshrMisses = demandMshrMisses + SUM_NON_DEMAND(mshr_misses);
522    for (int i = 0; i < system->maxMasters(); i++) {
523        overallMshrMisses.subname(i, system->getMasterName(i));
524    }
525
526    // MSHR miss latency statistics
527    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
528        MemCmd cmd(access_idx);
529        const string &cstr = cmd.toString();
530
531        mshr_miss_latency[access_idx]
532            .init(system->maxMasters())
533            .name(name() + "." + cstr + "_mshr_miss_latency")
534            .desc("number of " + cstr + " MSHR miss cycles")
535            .flags(total | nozero | nonan)
536            ;
537        for (int i = 0; i < system->maxMasters(); i++) {
538            mshr_miss_latency[access_idx].subname(i, system->getMasterName(i));
539        }
540    }
541
542    demandMshrMissLatency
543        .name(name() + ".demand_mshr_miss_latency")
544        .desc("number of demand (read+write) MSHR miss cycles")
545        .flags(total | nozero | nonan)
546        ;
547    demandMshrMissLatency = SUM_DEMAND(mshr_miss_latency);
548    for (int i = 0; i < system->maxMasters(); i++) {
549        demandMshrMissLatency.subname(i, system->getMasterName(i));
550    }
551
552    overallMshrMissLatency
553        .name(name() + ".overall_mshr_miss_latency")
554        .desc("number of overall MSHR miss cycles")
555        .flags(total | nozero | nonan)
556        ;
557    overallMshrMissLatency =
558        demandMshrMissLatency + SUM_NON_DEMAND(mshr_miss_latency);
559    for (int i = 0; i < system->maxMasters(); i++) {
560        overallMshrMissLatency.subname(i, system->getMasterName(i));
561    }
562
563    // MSHR uncacheable statistics
564    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
565        MemCmd cmd(access_idx);
566        const string &cstr = cmd.toString();
567
568        mshr_uncacheable[access_idx]
569            .init(system->maxMasters())
570            .name(name() + "." + cstr + "_mshr_uncacheable")
571            .desc("number of " + cstr + " MSHR uncacheable")
572            .flags(total | nozero | nonan)
573            ;
574        for (int i = 0; i < system->maxMasters(); i++) {
575            mshr_uncacheable[access_idx].subname(i, system->getMasterName(i));
576        }
577    }
578
579    overallMshrUncacheable
580        .name(name() + ".overall_mshr_uncacheable_misses")
581        .desc("number of overall MSHR uncacheable misses")
582        .flags(total | nozero | nonan)
583        ;
584    overallMshrUncacheable =
585        SUM_DEMAND(mshr_uncacheable) + SUM_NON_DEMAND(mshr_uncacheable);
586    for (int i = 0; i < system->maxMasters(); i++) {
587        overallMshrUncacheable.subname(i, system->getMasterName(i));
588    }
589
590    // MSHR miss latency statistics
591    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
592        MemCmd cmd(access_idx);
593        const string &cstr = cmd.toString();
594
595        mshr_uncacheable_lat[access_idx]
596            .init(system->maxMasters())
597            .name(name() + "." + cstr + "_mshr_uncacheable_latency")
598            .desc("number of " + cstr + " MSHR uncacheable cycles")
599            .flags(total | nozero | nonan)
600            ;
601        for (int i = 0; i < system->maxMasters(); i++) {
602            mshr_uncacheable_lat[access_idx].subname(
603                i, system->getMasterName(i));
604        }
605    }
606
607    overallMshrUncacheableLatency
608        .name(name() + ".overall_mshr_uncacheable_latency")
609        .desc("number of overall MSHR uncacheable cycles")
610        .flags(total | nozero | nonan)
611        ;
612    overallMshrUncacheableLatency =
613        SUM_DEMAND(mshr_uncacheable_lat) +
614        SUM_NON_DEMAND(mshr_uncacheable_lat);
615    for (int i = 0; i < system->maxMasters(); i++) {
616        overallMshrUncacheableLatency.subname(i, system->getMasterName(i));
617    }
618
619#if 0
620    // MSHR access formulas
621    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
622        MemCmd cmd(access_idx);
623        const string &cstr = cmd.toString();
624
625        mshrAccesses[access_idx]
626            .name(name() + "." + cstr + "_mshr_accesses")
627            .desc("number of " + cstr + " mshr accesses(hits+misses)")
628            .flags(total | nozero | nonan)
629            ;
630        mshrAccesses[access_idx] =
631            mshr_hits[access_idx] + mshr_misses[access_idx]
632            + mshr_uncacheable[access_idx];
633    }
634
635    demandMshrAccesses
636        .name(name() + ".demand_mshr_accesses")
637        .desc("number of demand (read+write) mshr accesses")
638        .flags(total | nozero | nonan)
639        ;
640    demandMshrAccesses = demandMshrHits + demandMshrMisses;
641
642    overallMshrAccesses
643        .name(name() + ".overall_mshr_accesses")
644        .desc("number of overall (read+write) mshr accesses")
645        .flags(total | nozero | nonan)
646        ;
647    overallMshrAccesses = overallMshrHits + overallMshrMisses
648        + overallMshrUncacheable;
649#endif
650
651    // MSHR miss rate formulas
652    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
653        MemCmd cmd(access_idx);
654        const string &cstr = cmd.toString();
655
656        mshrMissRate[access_idx]
657            .name(name() + "." + cstr + "_mshr_miss_rate")
658            .desc("mshr miss rate for " + cstr + " accesses")
659            .flags(total | nozero | nonan)
660            ;
661        mshrMissRate[access_idx] =
662            mshr_misses[access_idx] / accesses[access_idx];
663
664        for (int i = 0; i < system->maxMasters(); i++) {
665            mshrMissRate[access_idx].subname(i, system->getMasterName(i));
666        }
667    }
668
669    demandMshrMissRate
670        .name(name() + ".demand_mshr_miss_rate")
671        .desc("mshr miss rate for demand accesses")
672        .flags(total | nozero | nonan)
673        ;
674    demandMshrMissRate = demandMshrMisses / demandAccesses;
675    for (int i = 0; i < system->maxMasters(); i++) {
676        demandMshrMissRate.subname(i, system->getMasterName(i));
677    }
678
679    overallMshrMissRate
680        .name(name() + ".overall_mshr_miss_rate")
681        .desc("mshr miss rate for overall accesses")
682        .flags(total | nozero | nonan)
683        ;
684    overallMshrMissRate = overallMshrMisses / overallAccesses;
685    for (int i = 0; i < system->maxMasters(); i++) {
686        overallMshrMissRate.subname(i, system->getMasterName(i));
687    }
688
689    // mshrMiss latency formulas
690    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
691        MemCmd cmd(access_idx);
692        const string &cstr = cmd.toString();
693
694        avgMshrMissLatency[access_idx]
695            .name(name() + "." + cstr + "_avg_mshr_miss_latency")
696            .desc("average " + cstr + " mshr miss latency")
697            .flags(total | nozero | nonan)
698            ;
699        avgMshrMissLatency[access_idx] =
700            mshr_miss_latency[access_idx] / mshr_misses[access_idx];
701
702        for (int i = 0; i < system->maxMasters(); i++) {
703            avgMshrMissLatency[access_idx].subname(
704                i, system->getMasterName(i));
705        }
706    }
707
708    demandAvgMshrMissLatency
709        .name(name() + ".demand_avg_mshr_miss_latency")
710        .desc("average overall mshr miss latency")
711        .flags(total | nozero | nonan)
712        ;
713    demandAvgMshrMissLatency = demandMshrMissLatency / demandMshrMisses;
714    for (int i = 0; i < system->maxMasters(); i++) {
715        demandAvgMshrMissLatency.subname(i, system->getMasterName(i));
716    }
717
718    overallAvgMshrMissLatency
719        .name(name() + ".overall_avg_mshr_miss_latency")
720        .desc("average overall mshr miss latency")
721        .flags(total | nozero | nonan)
722        ;
723    overallAvgMshrMissLatency = overallMshrMissLatency / overallMshrMisses;
724    for (int i = 0; i < system->maxMasters(); i++) {
725        overallAvgMshrMissLatency.subname(i, system->getMasterName(i));
726    }
727
728    // mshrUncacheable latency formulas
729    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
730        MemCmd cmd(access_idx);
731        const string &cstr = cmd.toString();
732
733        avgMshrUncacheableLatency[access_idx]
734            .name(name() + "." + cstr + "_avg_mshr_uncacheable_latency")
735            .desc("average " + cstr + " mshr uncacheable latency")
736            .flags(total | nozero | nonan)
737            ;
738        avgMshrUncacheableLatency[access_idx] =
739            mshr_uncacheable_lat[access_idx] / mshr_uncacheable[access_idx];
740
741        for (int i = 0; i < system->maxMasters(); i++) {
742            avgMshrUncacheableLatency[access_idx].subname(
743                i, system->getMasterName(i));
744        }
745    }
746
747    overallAvgMshrUncacheableLatency
748        .name(name() + ".overall_avg_mshr_uncacheable_latency")
749        .desc("average overall mshr uncacheable latency")
750        .flags(total | nozero | nonan)
751        ;
752    overallAvgMshrUncacheableLatency =
753        overallMshrUncacheableLatency / overallMshrUncacheable;
754    for (int i = 0; i < system->maxMasters(); i++) {
755        overallAvgMshrUncacheableLatency.subname(i, system->getMasterName(i));
756    }
757
758}
759