base.cc revision 11455
12810SN/A/*
29614Srene.dejong@arm.com * Copyright (c) 2012-2013 ARM Limited
38856Sandreas.hansson@arm.com * All rights reserved.
48856Sandreas.hansson@arm.com *
58856Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall
68856Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual
78856Sandreas.hansson@arm.com * property including but not limited to intellectual property relating
88856Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software
98856Sandreas.hansson@arm.com * licensed hereunder.  You may use the software subject to the license
108856Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated
118856Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software,
128856Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form.
138856Sandreas.hansson@arm.com *
142810SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan
152810SN/A * All rights reserved.
162810SN/A *
172810SN/A * Redistribution and use in source and binary forms, with or without
182810SN/A * modification, are permitted provided that the following conditions are
192810SN/A * met: redistributions of source code must retain the above copyright
202810SN/A * notice, this list of conditions and the following disclaimer;
212810SN/A * redistributions in binary form must reproduce the above copyright
222810SN/A * notice, this list of conditions and the following disclaimer in the
232810SN/A * documentation and/or other materials provided with the distribution;
242810SN/A * neither the name of the copyright holders nor the names of its
252810SN/A * contributors may be used to endorse or promote products derived from
262810SN/A * this software without specific prior written permission.
272810SN/A *
282810SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
292810SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
302810SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
312810SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
322810SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
332810SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
342810SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
352810SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
362810SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
372810SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
382810SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
392810SN/A *
402810SN/A * Authors: Erik Hallnor
412810SN/A */
422810SN/A
432810SN/A/**
442810SN/A * @file
452810SN/A * Definition of BaseCache functions.
462810SN/A */
472810SN/A
488232Snate@binkert.org#include "debug/Cache.hh"
499152Satgutier@umich.edu#include "debug/Drain.hh"
509795Sandreas.hansson@arm.com#include "mem/cache/tags/fa_lru.hh"
519795Sandreas.hansson@arm.com#include "mem/cache/tags/lru.hh"
5210263Satgutier@umich.edu#include "mem/cache/tags/random_repl.hh"
535338Sstever@gmail.com#include "mem/cache/base.hh"
549795Sandreas.hansson@arm.com#include "mem/cache/cache.hh"
555338Sstever@gmail.com#include "mem/cache/mshr.hh"
568786Sgblack@eecs.umich.edu#include "sim/full_system.hh"
572810SN/A
582810SN/Ausing namespace std;
592810SN/A
608856Sandreas.hansson@arm.comBaseCache::CacheSlavePort::CacheSlavePort(const std::string &_name,
618856Sandreas.hansson@arm.com                                          BaseCache *_cache,
628856Sandreas.hansson@arm.com                                          const std::string &_label)
638922Swilliam.wang@arm.com    : QueuedSlavePort(_name, _cache, queue), queue(*_cache, *this, _label),
648914Sandreas.hansson@arm.com      blocked(false), mustSendRetry(false), sendRetryEvent(this)
658856Sandreas.hansson@arm.com{
668856Sandreas.hansson@arm.com}
674475SN/A
6811053Sandreas.hansson@arm.comBaseCache::BaseCache(const BaseCacheParams *p, unsigned blk_size)
695034SN/A    : MemObject(p),
7010360Sandreas.hansson@arm.com      cpuSidePort(nullptr), memSidePort(nullptr),
7111377Sandreas.hansson@arm.com      mshrQueue("MSHRs", p->mshrs, 0, p->demand_mshr_reserve), // see below
7211377Sandreas.hansson@arm.com      writeBuffer("write buffer", p->write_buffers, p->mshrs), // see below
7311053Sandreas.hansson@arm.com      blkSize(blk_size),
7410693SMarco.Balboni@ARM.com      lookupLatency(p->hit_latency),
7510693SMarco.Balboni@ARM.com      forwardLatency(p->hit_latency),
7610693SMarco.Balboni@ARM.com      fillLatency(p->response_latency),
779263Smrinmoy.ghosh@arm.com      responseLatency(p->response_latency),
785034SN/A      numTarget(p->tgts_per_mshr),
7911331Sandreas.hansson@arm.com      forwardSnoops(true),
8010884Sandreas.hansson@arm.com      isReadOnly(p->is_read_only),
814626SN/A      blocked(0),
8210360Sandreas.hansson@arm.com      order(0),
834626SN/A      noTargetMSHR(NULL),
845034SN/A      missCount(p->max_miss_count),
858883SAli.Saidi@ARM.com      addrRanges(p->addr_ranges.begin(), p->addr_ranges.end()),
868833Sdam.sunwoo@arm.com      system(p->system)
874458SN/A{
8811377Sandreas.hansson@arm.com    // the MSHR queue has no reserve entries as we check the MSHR
8911377Sandreas.hansson@arm.com    // queue on every single allocation, whereas the write queue has
9011377Sandreas.hansson@arm.com    // as many reserve entries as we have MSHRs, since every MSHR may
9111377Sandreas.hansson@arm.com    // eventually require a writeback, and we do not check the write
9211377Sandreas.hansson@arm.com    // buffer before committing to an MSHR
9311377Sandreas.hansson@arm.com
9411331Sandreas.hansson@arm.com    // forward snoops is overridden in init() once we can query
9511331Sandreas.hansson@arm.com    // whether the connected master is actually snooping or not
962810SN/A}
972810SN/A
983013SN/Avoid
998856Sandreas.hansson@arm.comBaseCache::CacheSlavePort::setBlocked()
1002810SN/A{
1013013SN/A    assert(!blocked);
10210714Sandreas.hansson@arm.com    DPRINTF(CachePort, "Port is blocking new requests\n");
1032810SN/A    blocked = true;
1049614Srene.dejong@arm.com    // if we already scheduled a retry in this cycle, but it has not yet
1059614Srene.dejong@arm.com    // happened, cancel it
1069614Srene.dejong@arm.com    if (sendRetryEvent.scheduled()) {
10710345SCurtis.Dunham@arm.com        owner.deschedule(sendRetryEvent);
10810714Sandreas.hansson@arm.com        DPRINTF(CachePort, "Port descheduled retry\n");
10910345SCurtis.Dunham@arm.com        mustSendRetry = true;
1109614Srene.dejong@arm.com    }
1112810SN/A}
1122810SN/A
1132810SN/Avoid
1148856Sandreas.hansson@arm.comBaseCache::CacheSlavePort::clearBlocked()
1152810SN/A{
1163013SN/A    assert(blocked);
11710714Sandreas.hansson@arm.com    DPRINTF(CachePort, "Port is accepting new requests\n");
1183013SN/A    blocked = false;
1198856Sandreas.hansson@arm.com    if (mustSendRetry) {
12010714Sandreas.hansson@arm.com        // @TODO: need to find a better time (next cycle?)
1218922Swilliam.wang@arm.com        owner.schedule(sendRetryEvent, curTick() + 1);
1222897SN/A    }
1232810SN/A}
1242810SN/A
12510344Sandreas.hansson@arm.comvoid
12610344Sandreas.hansson@arm.comBaseCache::CacheSlavePort::processSendRetry()
12710344Sandreas.hansson@arm.com{
12810714Sandreas.hansson@arm.com    DPRINTF(CachePort, "Port is sending retry\n");
12910344Sandreas.hansson@arm.com
13010344Sandreas.hansson@arm.com    // reset the flag and call retry
13110344Sandreas.hansson@arm.com    mustSendRetry = false;
13210713Sandreas.hansson@arm.com    sendRetryReq();
13310344Sandreas.hansson@arm.com}
1342844SN/A
1352810SN/Avoid
1362858SN/ABaseCache::init()
1372858SN/A{
1388856Sandreas.hansson@arm.com    if (!cpuSidePort->isConnected() || !memSidePort->isConnected())
1398922Swilliam.wang@arm.com        fatal("Cache ports on %s are not connected\n", name());
1408711Sandreas.hansson@arm.com    cpuSidePort->sendRangeChange();
14111331Sandreas.hansson@arm.com    forwardSnoops = cpuSidePort->isSnooping();
1422858SN/A}
1432858SN/A
1449294Sandreas.hansson@arm.comBaseMasterPort &
1459294Sandreas.hansson@arm.comBaseCache::getMasterPort(const std::string &if_name, PortID idx)
1468922Swilliam.wang@arm.com{
1478922Swilliam.wang@arm.com    if (if_name == "mem_side") {
1488922Swilliam.wang@arm.com        return *memSidePort;
1498922Swilliam.wang@arm.com    }  else {
1508922Swilliam.wang@arm.com        return MemObject::getMasterPort(if_name, idx);
1518922Swilliam.wang@arm.com    }
1528922Swilliam.wang@arm.com}
1538922Swilliam.wang@arm.com
1549294Sandreas.hansson@arm.comBaseSlavePort &
1559294Sandreas.hansson@arm.comBaseCache::getSlavePort(const std::string &if_name, PortID idx)
1568922Swilliam.wang@arm.com{
1578922Swilliam.wang@arm.com    if (if_name == "cpu_side") {
1588922Swilliam.wang@arm.com        return *cpuSidePort;
1598922Swilliam.wang@arm.com    } else {
1608922Swilliam.wang@arm.com        return MemObject::getSlavePort(if_name, idx);
1618922Swilliam.wang@arm.com    }
1628922Swilliam.wang@arm.com}
1634628SN/A
16410821Sandreas.hansson@arm.combool
16510821Sandreas.hansson@arm.comBaseCache::inRange(Addr addr) const
16610821Sandreas.hansson@arm.com{
16710821Sandreas.hansson@arm.com    for (const auto& r : addrRanges) {
16810821Sandreas.hansson@arm.com        if (r.contains(addr)) {
16910821Sandreas.hansson@arm.com            return true;
17010821Sandreas.hansson@arm.com       }
17110821Sandreas.hansson@arm.com    }
17210821Sandreas.hansson@arm.com    return false;
17310821Sandreas.hansson@arm.com}
17410821Sandreas.hansson@arm.com
1752858SN/Avoid
1762810SN/ABaseCache::regStats()
1772810SN/A{
1782810SN/A    using namespace Stats;
1792810SN/A
1802810SN/A    // Hit statistics
1814022SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
1824022SN/A        MemCmd cmd(access_idx);
1834022SN/A        const string &cstr = cmd.toString();
1842810SN/A
1852810SN/A        hits[access_idx]
1868833Sdam.sunwoo@arm.com            .init(system->maxMasters())
1872810SN/A            .name(name() + "." + cstr + "_hits")
1882810SN/A            .desc("number of " + cstr + " hits")
1892810SN/A            .flags(total | nozero | nonan)
1902810SN/A            ;
1918833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
1928833Sdam.sunwoo@arm.com            hits[access_idx].subname(i, system->getMasterName(i));
1938833Sdam.sunwoo@arm.com        }
1942810SN/A    }
1952810SN/A
1964871SN/A// These macros make it easier to sum the right subset of commands and
1974871SN/A// to change the subset of commands that are considered "demand" vs
1984871SN/A// "non-demand"
1994871SN/A#define SUM_DEMAND(s) \
20011455Sandreas.hansson@arm.com    (s[MemCmd::ReadReq] + s[MemCmd::WriteReq] + s[MemCmd::WriteLineReq] + \
20110885Sandreas.hansson@arm.com     s[MemCmd::ReadExReq] + s[MemCmd::ReadCleanReq] + s[MemCmd::ReadSharedReq])
2024871SN/A
2034871SN/A// should writebacks be included here?  prior code was inconsistent...
2044871SN/A#define SUM_NON_DEMAND(s) \
2054871SN/A    (s[MemCmd::SoftPFReq] + s[MemCmd::HardPFReq])
2064871SN/A
2072810SN/A    demandHits
2082810SN/A        .name(name() + ".demand_hits")
2092810SN/A        .desc("number of demand (read+write) hits")
2108833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
2112810SN/A        ;
2124871SN/A    demandHits = SUM_DEMAND(hits);
2138833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
2148833Sdam.sunwoo@arm.com        demandHits.subname(i, system->getMasterName(i));
2158833Sdam.sunwoo@arm.com    }
2162810SN/A
2172810SN/A    overallHits
2182810SN/A        .name(name() + ".overall_hits")
2192810SN/A        .desc("number of overall hits")
2208833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
2212810SN/A        ;
2224871SN/A    overallHits = demandHits + SUM_NON_DEMAND(hits);
2238833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
2248833Sdam.sunwoo@arm.com        overallHits.subname(i, system->getMasterName(i));
2258833Sdam.sunwoo@arm.com    }
2262810SN/A
2272810SN/A    // Miss statistics
2284022SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
2294022SN/A        MemCmd cmd(access_idx);
2304022SN/A        const string &cstr = cmd.toString();
2312810SN/A
2322810SN/A        misses[access_idx]
2338833Sdam.sunwoo@arm.com            .init(system->maxMasters())
2342810SN/A            .name(name() + "." + cstr + "_misses")
2352810SN/A            .desc("number of " + cstr + " misses")
2362810SN/A            .flags(total | nozero | nonan)
2372810SN/A            ;
2388833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
2398833Sdam.sunwoo@arm.com            misses[access_idx].subname(i, system->getMasterName(i));
2408833Sdam.sunwoo@arm.com        }
2412810SN/A    }
2422810SN/A
2432810SN/A    demandMisses
2442810SN/A        .name(name() + ".demand_misses")
2452810SN/A        .desc("number of demand (read+write) misses")
2468833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
2472810SN/A        ;
2484871SN/A    demandMisses = SUM_DEMAND(misses);
2498833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
2508833Sdam.sunwoo@arm.com        demandMisses.subname(i, system->getMasterName(i));
2518833Sdam.sunwoo@arm.com    }
2522810SN/A
2532810SN/A    overallMisses
2542810SN/A        .name(name() + ".overall_misses")
2552810SN/A        .desc("number of overall misses")
2568833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
2572810SN/A        ;
2584871SN/A    overallMisses = demandMisses + SUM_NON_DEMAND(misses);
2598833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
2608833Sdam.sunwoo@arm.com        overallMisses.subname(i, system->getMasterName(i));
2618833Sdam.sunwoo@arm.com    }
2622810SN/A
2632810SN/A    // Miss latency statistics
2644022SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
2654022SN/A        MemCmd cmd(access_idx);
2664022SN/A        const string &cstr = cmd.toString();
2672810SN/A
2682810SN/A        missLatency[access_idx]
2698833Sdam.sunwoo@arm.com            .init(system->maxMasters())
2702810SN/A            .name(name() + "." + cstr + "_miss_latency")
2712810SN/A            .desc("number of " + cstr + " miss cycles")
2722810SN/A            .flags(total | nozero | nonan)
2732810SN/A            ;
2748833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
2758833Sdam.sunwoo@arm.com            missLatency[access_idx].subname(i, system->getMasterName(i));
2768833Sdam.sunwoo@arm.com        }
2772810SN/A    }
2782810SN/A
2792810SN/A    demandMissLatency
2802810SN/A        .name(name() + ".demand_miss_latency")
2812810SN/A        .desc("number of demand (read+write) miss cycles")
2828833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
2832810SN/A        ;
2844871SN/A    demandMissLatency = SUM_DEMAND(missLatency);
2858833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
2868833Sdam.sunwoo@arm.com        demandMissLatency.subname(i, system->getMasterName(i));
2878833Sdam.sunwoo@arm.com    }
2882810SN/A
2892810SN/A    overallMissLatency
2902810SN/A        .name(name() + ".overall_miss_latency")
2912810SN/A        .desc("number of overall miss cycles")
2928833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
2932810SN/A        ;
2944871SN/A    overallMissLatency = demandMissLatency + SUM_NON_DEMAND(missLatency);
2958833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
2968833Sdam.sunwoo@arm.com        overallMissLatency.subname(i, system->getMasterName(i));
2978833Sdam.sunwoo@arm.com    }
2982810SN/A
2992810SN/A    // access formulas
3004022SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
3014022SN/A        MemCmd cmd(access_idx);
3024022SN/A        const string &cstr = cmd.toString();
3032810SN/A
3042810SN/A        accesses[access_idx]
3052810SN/A            .name(name() + "." + cstr + "_accesses")
3062810SN/A            .desc("number of " + cstr + " accesses(hits+misses)")
3072810SN/A            .flags(total | nozero | nonan)
3082810SN/A            ;
3098833Sdam.sunwoo@arm.com        accesses[access_idx] = hits[access_idx] + misses[access_idx];
3102810SN/A
3118833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
3128833Sdam.sunwoo@arm.com            accesses[access_idx].subname(i, system->getMasterName(i));
3138833Sdam.sunwoo@arm.com        }
3142810SN/A    }
3152810SN/A
3162810SN/A    demandAccesses
3172810SN/A        .name(name() + ".demand_accesses")
3182810SN/A        .desc("number of demand (read+write) accesses")
3198833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
3202810SN/A        ;
3212810SN/A    demandAccesses = demandHits + demandMisses;
3228833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
3238833Sdam.sunwoo@arm.com        demandAccesses.subname(i, system->getMasterName(i));
3248833Sdam.sunwoo@arm.com    }
3252810SN/A
3262810SN/A    overallAccesses
3272810SN/A        .name(name() + ".overall_accesses")
3282810SN/A        .desc("number of overall (read+write) accesses")
3298833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
3302810SN/A        ;
3312810SN/A    overallAccesses = overallHits + overallMisses;
3328833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
3338833Sdam.sunwoo@arm.com        overallAccesses.subname(i, system->getMasterName(i));
3348833Sdam.sunwoo@arm.com    }
3352810SN/A
3362810SN/A    // miss rate formulas
3374022SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
3384022SN/A        MemCmd cmd(access_idx);
3394022SN/A        const string &cstr = cmd.toString();
3402810SN/A
3412810SN/A        missRate[access_idx]
3422810SN/A            .name(name() + "." + cstr + "_miss_rate")
3432810SN/A            .desc("miss rate for " + cstr + " accesses")
3442810SN/A            .flags(total | nozero | nonan)
3452810SN/A            ;
3468833Sdam.sunwoo@arm.com        missRate[access_idx] = misses[access_idx] / accesses[access_idx];
3472810SN/A
3488833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
3498833Sdam.sunwoo@arm.com            missRate[access_idx].subname(i, system->getMasterName(i));
3508833Sdam.sunwoo@arm.com        }
3512810SN/A    }
3522810SN/A
3532810SN/A    demandMissRate
3542810SN/A        .name(name() + ".demand_miss_rate")
3552810SN/A        .desc("miss rate for demand accesses")
3568833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
3572810SN/A        ;
3582810SN/A    demandMissRate = demandMisses / demandAccesses;
3598833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
3608833Sdam.sunwoo@arm.com        demandMissRate.subname(i, system->getMasterName(i));
3618833Sdam.sunwoo@arm.com    }
3622810SN/A
3632810SN/A    overallMissRate
3642810SN/A        .name(name() + ".overall_miss_rate")
3652810SN/A        .desc("miss rate for overall accesses")
3668833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
3672810SN/A        ;
3682810SN/A    overallMissRate = overallMisses / overallAccesses;
3698833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
3708833Sdam.sunwoo@arm.com        overallMissRate.subname(i, system->getMasterName(i));
3718833Sdam.sunwoo@arm.com    }
3722810SN/A
3732810SN/A    // miss latency formulas
3744022SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
3754022SN/A        MemCmd cmd(access_idx);
3764022SN/A        const string &cstr = cmd.toString();
3772810SN/A
3782810SN/A        avgMissLatency[access_idx]
3792810SN/A            .name(name() + "." + cstr + "_avg_miss_latency")
3802810SN/A            .desc("average " + cstr + " miss latency")
3812810SN/A            .flags(total | nozero | nonan)
3822810SN/A            ;
3832810SN/A        avgMissLatency[access_idx] =
3842810SN/A            missLatency[access_idx] / misses[access_idx];
3858833Sdam.sunwoo@arm.com
3868833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
3878833Sdam.sunwoo@arm.com            avgMissLatency[access_idx].subname(i, system->getMasterName(i));
3888833Sdam.sunwoo@arm.com        }
3892810SN/A    }
3902810SN/A
3912810SN/A    demandAvgMissLatency
3922810SN/A        .name(name() + ".demand_avg_miss_latency")
3932810SN/A        .desc("average overall miss latency")
3948833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
3952810SN/A        ;
3962810SN/A    demandAvgMissLatency = demandMissLatency / demandMisses;
3978833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
3988833Sdam.sunwoo@arm.com        demandAvgMissLatency.subname(i, system->getMasterName(i));
3998833Sdam.sunwoo@arm.com    }
4002810SN/A
4012810SN/A    overallAvgMissLatency
4022810SN/A        .name(name() + ".overall_avg_miss_latency")
4032810SN/A        .desc("average overall miss latency")
4048833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
4052810SN/A        ;
4062810SN/A    overallAvgMissLatency = overallMissLatency / overallMisses;
4078833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
4088833Sdam.sunwoo@arm.com        overallAvgMissLatency.subname(i, system->getMasterName(i));
4098833Sdam.sunwoo@arm.com    }
4102810SN/A
4112810SN/A    blocked_cycles.init(NUM_BLOCKED_CAUSES);
4122810SN/A    blocked_cycles
4132810SN/A        .name(name() + ".blocked_cycles")
4142810SN/A        .desc("number of cycles access was blocked")
4152810SN/A        .subname(Blocked_NoMSHRs, "no_mshrs")
4162810SN/A        .subname(Blocked_NoTargets, "no_targets")
4172810SN/A        ;
4182810SN/A
4192810SN/A
4202810SN/A    blocked_causes.init(NUM_BLOCKED_CAUSES);
4212810SN/A    blocked_causes
4222810SN/A        .name(name() + ".blocked")
4232810SN/A        .desc("number of cycles access was blocked")
4242810SN/A        .subname(Blocked_NoMSHRs, "no_mshrs")
4252810SN/A        .subname(Blocked_NoTargets, "no_targets")
4262810SN/A        ;
4272810SN/A
4282810SN/A    avg_blocked
4292810SN/A        .name(name() + ".avg_blocked_cycles")
4302810SN/A        .desc("average number of cycles each access was blocked")
4312810SN/A        .subname(Blocked_NoMSHRs, "no_mshrs")
4322810SN/A        .subname(Blocked_NoTargets, "no_targets")
4332810SN/A        ;
4342810SN/A
4352810SN/A    avg_blocked = blocked_cycles / blocked_causes;
4362810SN/A
43711436SRekai.GonzalezAlberquilla@arm.com    unusedPrefetches
43811436SRekai.GonzalezAlberquilla@arm.com        .name(name() + ".unused_prefetches")
43911436SRekai.GonzalezAlberquilla@arm.com        .desc("number of HardPF blocks evicted w/o reference")
44011436SRekai.GonzalezAlberquilla@arm.com        .flags(nozero)
44111436SRekai.GonzalezAlberquilla@arm.com        ;
44211436SRekai.GonzalezAlberquilla@arm.com
4434626SN/A    writebacks
4448833Sdam.sunwoo@arm.com        .init(system->maxMasters())
4454626SN/A        .name(name() + ".writebacks")
4464626SN/A        .desc("number of writebacks")
4478833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
4484626SN/A        ;
4498833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
4508833Sdam.sunwoo@arm.com        writebacks.subname(i, system->getMasterName(i));
4518833Sdam.sunwoo@arm.com    }
4524626SN/A
4534626SN/A    // MSHR statistics
4544626SN/A    // MSHR hit statistics
4554626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
4564626SN/A        MemCmd cmd(access_idx);
4574626SN/A        const string &cstr = cmd.toString();
4584626SN/A
4594626SN/A        mshr_hits[access_idx]
4608833Sdam.sunwoo@arm.com            .init(system->maxMasters())
4614626SN/A            .name(name() + "." + cstr + "_mshr_hits")
4624626SN/A            .desc("number of " + cstr + " MSHR hits")
4634626SN/A            .flags(total | nozero | nonan)
4644626SN/A            ;
4658833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
4668833Sdam.sunwoo@arm.com            mshr_hits[access_idx].subname(i, system->getMasterName(i));
4678833Sdam.sunwoo@arm.com        }
4684626SN/A    }
4694626SN/A
4704626SN/A    demandMshrHits
4714626SN/A        .name(name() + ".demand_mshr_hits")
4724626SN/A        .desc("number of demand (read+write) MSHR hits")
4738833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
4744626SN/A        ;
4754871SN/A    demandMshrHits = SUM_DEMAND(mshr_hits);
4768833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
4778833Sdam.sunwoo@arm.com        demandMshrHits.subname(i, system->getMasterName(i));
4788833Sdam.sunwoo@arm.com    }
4794626SN/A
4804626SN/A    overallMshrHits
4814626SN/A        .name(name() + ".overall_mshr_hits")
4824626SN/A        .desc("number of overall MSHR hits")
4838833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
4844626SN/A        ;
4854871SN/A    overallMshrHits = demandMshrHits + SUM_NON_DEMAND(mshr_hits);
4868833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
4878833Sdam.sunwoo@arm.com        overallMshrHits.subname(i, system->getMasterName(i));
4888833Sdam.sunwoo@arm.com    }
4894626SN/A
4904626SN/A    // MSHR miss statistics
4914626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
4924626SN/A        MemCmd cmd(access_idx);
4934626SN/A        const string &cstr = cmd.toString();
4944626SN/A
4954626SN/A        mshr_misses[access_idx]
4968833Sdam.sunwoo@arm.com            .init(system->maxMasters())
4974626SN/A            .name(name() + "." + cstr + "_mshr_misses")
4984626SN/A            .desc("number of " + cstr + " MSHR misses")
4994626SN/A            .flags(total | nozero | nonan)
5004626SN/A            ;
5018833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
5028833Sdam.sunwoo@arm.com            mshr_misses[access_idx].subname(i, system->getMasterName(i));
5038833Sdam.sunwoo@arm.com        }
5044626SN/A    }
5054626SN/A
5064626SN/A    demandMshrMisses
5074626SN/A        .name(name() + ".demand_mshr_misses")
5084626SN/A        .desc("number of demand (read+write) MSHR misses")
5098833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
5104626SN/A        ;
5114871SN/A    demandMshrMisses = SUM_DEMAND(mshr_misses);
5128833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
5138833Sdam.sunwoo@arm.com        demandMshrMisses.subname(i, system->getMasterName(i));
5148833Sdam.sunwoo@arm.com    }
5154626SN/A
5164626SN/A    overallMshrMisses
5174626SN/A        .name(name() + ".overall_mshr_misses")
5184626SN/A        .desc("number of overall MSHR misses")
5198833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
5204626SN/A        ;
5214871SN/A    overallMshrMisses = demandMshrMisses + SUM_NON_DEMAND(mshr_misses);
5228833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
5238833Sdam.sunwoo@arm.com        overallMshrMisses.subname(i, system->getMasterName(i));
5248833Sdam.sunwoo@arm.com    }
5254626SN/A
5264626SN/A    // MSHR miss latency statistics
5274626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
5284626SN/A        MemCmd cmd(access_idx);
5294626SN/A        const string &cstr = cmd.toString();
5304626SN/A
5314626SN/A        mshr_miss_latency[access_idx]
5328833Sdam.sunwoo@arm.com            .init(system->maxMasters())
5334626SN/A            .name(name() + "." + cstr + "_mshr_miss_latency")
5344626SN/A            .desc("number of " + cstr + " MSHR miss cycles")
5354626SN/A            .flags(total | nozero | nonan)
5364626SN/A            ;
5378833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
5388833Sdam.sunwoo@arm.com            mshr_miss_latency[access_idx].subname(i, system->getMasterName(i));
5398833Sdam.sunwoo@arm.com        }
5404626SN/A    }
5414626SN/A
5424626SN/A    demandMshrMissLatency
5434626SN/A        .name(name() + ".demand_mshr_miss_latency")
5444626SN/A        .desc("number of demand (read+write) MSHR miss cycles")
5458833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
5464626SN/A        ;
5474871SN/A    demandMshrMissLatency = SUM_DEMAND(mshr_miss_latency);
5488833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
5498833Sdam.sunwoo@arm.com        demandMshrMissLatency.subname(i, system->getMasterName(i));
5508833Sdam.sunwoo@arm.com    }
5514626SN/A
5524626SN/A    overallMshrMissLatency
5534626SN/A        .name(name() + ".overall_mshr_miss_latency")
5544626SN/A        .desc("number of overall MSHR miss cycles")
5558833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
5564626SN/A        ;
5574871SN/A    overallMshrMissLatency =
5584871SN/A        demandMshrMissLatency + SUM_NON_DEMAND(mshr_miss_latency);
5598833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
5608833Sdam.sunwoo@arm.com        overallMshrMissLatency.subname(i, system->getMasterName(i));
5618833Sdam.sunwoo@arm.com    }
5624626SN/A
5634626SN/A    // MSHR uncacheable statistics
5644626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
5654626SN/A        MemCmd cmd(access_idx);
5664626SN/A        const string &cstr = cmd.toString();
5674626SN/A
5684626SN/A        mshr_uncacheable[access_idx]
5698833Sdam.sunwoo@arm.com            .init(system->maxMasters())
5704626SN/A            .name(name() + "." + cstr + "_mshr_uncacheable")
5714626SN/A            .desc("number of " + cstr + " MSHR uncacheable")
5724626SN/A            .flags(total | nozero | nonan)
5734626SN/A            ;
5748833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
5758833Sdam.sunwoo@arm.com            mshr_uncacheable[access_idx].subname(i, system->getMasterName(i));
5768833Sdam.sunwoo@arm.com        }
5774626SN/A    }
5784626SN/A
5794626SN/A    overallMshrUncacheable
5804626SN/A        .name(name() + ".overall_mshr_uncacheable_misses")
5814626SN/A        .desc("number of overall MSHR uncacheable misses")
5828833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
5834626SN/A        ;
5844871SN/A    overallMshrUncacheable =
5854871SN/A        SUM_DEMAND(mshr_uncacheable) + SUM_NON_DEMAND(mshr_uncacheable);
5868833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
5878833Sdam.sunwoo@arm.com        overallMshrUncacheable.subname(i, system->getMasterName(i));
5888833Sdam.sunwoo@arm.com    }
5894626SN/A
5904626SN/A    // MSHR miss latency statistics
5914626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
5924626SN/A        MemCmd cmd(access_idx);
5934626SN/A        const string &cstr = cmd.toString();
5944626SN/A
5954626SN/A        mshr_uncacheable_lat[access_idx]
5968833Sdam.sunwoo@arm.com            .init(system->maxMasters())
5974626SN/A            .name(name() + "." + cstr + "_mshr_uncacheable_latency")
5984626SN/A            .desc("number of " + cstr + " MSHR uncacheable cycles")
5994626SN/A            .flags(total | nozero | nonan)
6004626SN/A            ;
6018833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
6028833Sdam.sunwoo@arm.com            mshr_uncacheable_lat[access_idx].subname(i, system->getMasterName(i));
6038833Sdam.sunwoo@arm.com        }
6044626SN/A    }
6054626SN/A
6064626SN/A    overallMshrUncacheableLatency
6074626SN/A        .name(name() + ".overall_mshr_uncacheable_latency")
6084626SN/A        .desc("number of overall MSHR uncacheable cycles")
6098833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
6104626SN/A        ;
6114871SN/A    overallMshrUncacheableLatency =
6124871SN/A        SUM_DEMAND(mshr_uncacheable_lat) +
6134871SN/A        SUM_NON_DEMAND(mshr_uncacheable_lat);
6148833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
6158833Sdam.sunwoo@arm.com        overallMshrUncacheableLatency.subname(i, system->getMasterName(i));
6168833Sdam.sunwoo@arm.com    }
6174626SN/A
6184626SN/A#if 0
6194626SN/A    // MSHR access formulas
6204626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
6214626SN/A        MemCmd cmd(access_idx);
6224626SN/A        const string &cstr = cmd.toString();
6234626SN/A
6244626SN/A        mshrAccesses[access_idx]
6254626SN/A            .name(name() + "." + cstr + "_mshr_accesses")
6264626SN/A            .desc("number of " + cstr + " mshr accesses(hits+misses)")
6274626SN/A            .flags(total | nozero | nonan)
6284626SN/A            ;
6294626SN/A        mshrAccesses[access_idx] =
6304626SN/A            mshr_hits[access_idx] + mshr_misses[access_idx]
6314626SN/A            + mshr_uncacheable[access_idx];
6324626SN/A    }
6334626SN/A
6344626SN/A    demandMshrAccesses
6354626SN/A        .name(name() + ".demand_mshr_accesses")
6364626SN/A        .desc("number of demand (read+write) mshr accesses")
6374626SN/A        .flags(total | nozero | nonan)
6384626SN/A        ;
6394626SN/A    demandMshrAccesses = demandMshrHits + demandMshrMisses;
6404626SN/A
6414626SN/A    overallMshrAccesses
6424626SN/A        .name(name() + ".overall_mshr_accesses")
6434626SN/A        .desc("number of overall (read+write) mshr accesses")
6444626SN/A        .flags(total | nozero | nonan)
6454626SN/A        ;
6464626SN/A    overallMshrAccesses = overallMshrHits + overallMshrMisses
6474626SN/A        + overallMshrUncacheable;
6484626SN/A#endif
6494626SN/A
6504626SN/A    // MSHR miss rate formulas
6514626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
6524626SN/A        MemCmd cmd(access_idx);
6534626SN/A        const string &cstr = cmd.toString();
6544626SN/A
6554626SN/A        mshrMissRate[access_idx]
6564626SN/A            .name(name() + "." + cstr + "_mshr_miss_rate")
6574626SN/A            .desc("mshr miss rate for " + cstr + " accesses")
6584626SN/A            .flags(total | nozero | nonan)
6594626SN/A            ;
6604626SN/A        mshrMissRate[access_idx] =
6614626SN/A            mshr_misses[access_idx] / accesses[access_idx];
6628833Sdam.sunwoo@arm.com
6638833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
6648833Sdam.sunwoo@arm.com            mshrMissRate[access_idx].subname(i, system->getMasterName(i));
6658833Sdam.sunwoo@arm.com        }
6664626SN/A    }
6674626SN/A
6684626SN/A    demandMshrMissRate
6694626SN/A        .name(name() + ".demand_mshr_miss_rate")
6704626SN/A        .desc("mshr miss rate for demand accesses")
6718833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
6724626SN/A        ;
6734626SN/A    demandMshrMissRate = demandMshrMisses / demandAccesses;
6748833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
6758833Sdam.sunwoo@arm.com        demandMshrMissRate.subname(i, system->getMasterName(i));
6768833Sdam.sunwoo@arm.com    }
6774626SN/A
6784626SN/A    overallMshrMissRate
6794626SN/A        .name(name() + ".overall_mshr_miss_rate")
6804626SN/A        .desc("mshr miss rate for overall accesses")
6818833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
6824626SN/A        ;
6834626SN/A    overallMshrMissRate = overallMshrMisses / overallAccesses;
6848833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
6858833Sdam.sunwoo@arm.com        overallMshrMissRate.subname(i, system->getMasterName(i));
6868833Sdam.sunwoo@arm.com    }
6874626SN/A
6884626SN/A    // mshrMiss latency formulas
6894626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
6904626SN/A        MemCmd cmd(access_idx);
6914626SN/A        const string &cstr = cmd.toString();
6924626SN/A
6934626SN/A        avgMshrMissLatency[access_idx]
6944626SN/A            .name(name() + "." + cstr + "_avg_mshr_miss_latency")
6954626SN/A            .desc("average " + cstr + " mshr miss latency")
6964626SN/A            .flags(total | nozero | nonan)
6974626SN/A            ;
6984626SN/A        avgMshrMissLatency[access_idx] =
6994626SN/A            mshr_miss_latency[access_idx] / mshr_misses[access_idx];
7008833Sdam.sunwoo@arm.com
7018833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
7028833Sdam.sunwoo@arm.com            avgMshrMissLatency[access_idx].subname(i, system->getMasterName(i));
7038833Sdam.sunwoo@arm.com        }
7044626SN/A    }
7054626SN/A
7064626SN/A    demandAvgMshrMissLatency
7074626SN/A        .name(name() + ".demand_avg_mshr_miss_latency")
7084626SN/A        .desc("average overall mshr miss latency")
7098833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
7104626SN/A        ;
7114626SN/A    demandAvgMshrMissLatency = demandMshrMissLatency / demandMshrMisses;
7128833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
7138833Sdam.sunwoo@arm.com        demandAvgMshrMissLatency.subname(i, system->getMasterName(i));
7148833Sdam.sunwoo@arm.com    }
7154626SN/A
7164626SN/A    overallAvgMshrMissLatency
7174626SN/A        .name(name() + ".overall_avg_mshr_miss_latency")
7184626SN/A        .desc("average overall mshr miss latency")
7198833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
7204626SN/A        ;
7214626SN/A    overallAvgMshrMissLatency = overallMshrMissLatency / overallMshrMisses;
7228833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
7238833Sdam.sunwoo@arm.com        overallAvgMshrMissLatency.subname(i, system->getMasterName(i));
7248833Sdam.sunwoo@arm.com    }
7254626SN/A
7264626SN/A    // mshrUncacheable latency formulas
7274626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
7284626SN/A        MemCmd cmd(access_idx);
7294626SN/A        const string &cstr = cmd.toString();
7304626SN/A
7314626SN/A        avgMshrUncacheableLatency[access_idx]
7324626SN/A            .name(name() + "." + cstr + "_avg_mshr_uncacheable_latency")
7334626SN/A            .desc("average " + cstr + " mshr uncacheable latency")
7344626SN/A            .flags(total | nozero | nonan)
7354626SN/A            ;
7364626SN/A        avgMshrUncacheableLatency[access_idx] =
7374626SN/A            mshr_uncacheable_lat[access_idx] / mshr_uncacheable[access_idx];
7388833Sdam.sunwoo@arm.com
7398833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
7408833Sdam.sunwoo@arm.com            avgMshrUncacheableLatency[access_idx].subname(i, system->getMasterName(i));
7418833Sdam.sunwoo@arm.com        }
7424626SN/A    }
7434626SN/A
7444626SN/A    overallAvgMshrUncacheableLatency
7454626SN/A        .name(name() + ".overall_avg_mshr_uncacheable_latency")
7464626SN/A        .desc("average overall mshr uncacheable latency")
7478833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
7484626SN/A        ;
7494626SN/A    overallAvgMshrUncacheableLatency = overallMshrUncacheableLatency / overallMshrUncacheable;
7508833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
7518833Sdam.sunwoo@arm.com        overallAvgMshrUncacheableLatency.subname(i, system->getMasterName(i));
7528833Sdam.sunwoo@arm.com    }
7534626SN/A
7542810SN/A}
755