base.cc revision 8922
12810SN/A/*
28856Sandreas.hansson@arm.com * Copyright (c) 2012 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
483348SN/A#include "cpu/base.hh"
493348SN/A#include "cpu/smt.hh"
508232Snate@binkert.org#include "debug/Cache.hh"
515338Sstever@gmail.com#include "mem/cache/base.hh"
525338Sstever@gmail.com#include "mem/cache/mshr.hh"
538786Sgblack@eecs.umich.edu#include "sim/full_system.hh"
542810SN/A
552810SN/Ausing namespace std;
562810SN/A
578856Sandreas.hansson@arm.comBaseCache::CacheSlavePort::CacheSlavePort(const std::string &_name,
588856Sandreas.hansson@arm.com                                          BaseCache *_cache,
598856Sandreas.hansson@arm.com                                          const std::string &_label)
608922Swilliam.wang@arm.com    : QueuedSlavePort(_name, _cache, queue), queue(*_cache, *this, _label),
618914Sandreas.hansson@arm.com      blocked(false), mustSendRetry(false), sendRetryEvent(this)
628856Sandreas.hansson@arm.com{
638856Sandreas.hansson@arm.com}
644475SN/A
655034SN/ABaseCache::BaseCache(const Params *p)
665034SN/A    : MemObject(p),
675314SN/A      mshrQueue("MSHRs", p->mshrs, 4, MSHRQueue_MSHRs),
685314SN/A      writeBuffer("write buffer", p->write_buffers, p->mshrs+1000,
694628SN/A                  MSHRQueue_WriteBuffer),
705034SN/A      blkSize(p->block_size),
715034SN/A      hitLatency(p->latency),
725034SN/A      numTarget(p->tgts_per_mshr),
736122SSteve.Reinhardt@amd.com      forwardSnoops(p->forward_snoops),
748134SAli.Saidi@ARM.com      isTopLevel(p->is_top_level),
754626SN/A      blocked(0),
764626SN/A      noTargetMSHR(NULL),
775034SN/A      missCount(p->max_miss_count),
786122SSteve.Reinhardt@amd.com      drainEvent(NULL),
798883SAli.Saidi@ARM.com      addrRanges(p->addr_ranges.begin(), p->addr_ranges.end()),
808833Sdam.sunwoo@arm.com      system(p->system)
814458SN/A{
822810SN/A}
832810SN/A
843013SN/Avoid
858856Sandreas.hansson@arm.comBaseCache::CacheSlavePort::setBlocked()
862810SN/A{
873013SN/A    assert(!blocked);
888856Sandreas.hansson@arm.com    DPRINTF(CachePort, "Cache port %s blocking new requests\n", name());
892810SN/A    blocked = true;
902810SN/A}
912810SN/A
922810SN/Avoid
938856Sandreas.hansson@arm.comBaseCache::CacheSlavePort::clearBlocked()
942810SN/A{
953013SN/A    assert(blocked);
968856Sandreas.hansson@arm.com    DPRINTF(CachePort, "Cache port %s accepting new requests\n", name());
973013SN/A    blocked = false;
988856Sandreas.hansson@arm.com    if (mustSendRetry) {
998856Sandreas.hansson@arm.com        DPRINTF(CachePort, "Cache port %s sending retry\n", name());
1002897SN/A        mustSendRetry = false;
1014666SN/A        // @TODO: need to find a better time (next bus cycle?)
1028922Swilliam.wang@arm.com        owner.schedule(sendRetryEvent, curTick() + 1);
1032897SN/A    }
1042810SN/A}
1052810SN/A
1062844SN/A
1072810SN/Avoid
1082858SN/ABaseCache::init()
1092858SN/A{
1108856Sandreas.hansson@arm.com    if (!cpuSidePort->isConnected() || !memSidePort->isConnected())
1118922Swilliam.wang@arm.com        fatal("Cache ports on %s are not connected\n", name());
1128711Sandreas.hansson@arm.com    cpuSidePort->sendRangeChange();
1132858SN/A}
1142858SN/A
1158922Swilliam.wang@arm.comMasterPort &
1168922Swilliam.wang@arm.comBaseCache::getMasterPort(const std::string &if_name, int idx)
1178922Swilliam.wang@arm.com{
1188922Swilliam.wang@arm.com    if (if_name == "mem_side") {
1198922Swilliam.wang@arm.com        return *memSidePort;
1208922Swilliam.wang@arm.com    }  else {
1218922Swilliam.wang@arm.com        return MemObject::getMasterPort(if_name, idx);
1228922Swilliam.wang@arm.com    }
1238922Swilliam.wang@arm.com}
1248922Swilliam.wang@arm.com
1258922Swilliam.wang@arm.comSlavePort &
1268922Swilliam.wang@arm.comBaseCache::getSlavePort(const std::string &if_name, int idx)
1278922Swilliam.wang@arm.com{
1288922Swilliam.wang@arm.com    if (if_name == "cpu_side") {
1298922Swilliam.wang@arm.com        return *cpuSidePort;
1308922Swilliam.wang@arm.com    } else {
1318922Swilliam.wang@arm.com        return MemObject::getSlavePort(if_name, idx);
1328922Swilliam.wang@arm.com    }
1338922Swilliam.wang@arm.com}
1344628SN/A
1352858SN/Avoid
1362810SN/ABaseCache::regStats()
1372810SN/A{
1382810SN/A    using namespace Stats;
1392810SN/A
1402810SN/A    // Hit statistics
1414022SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
1424022SN/A        MemCmd cmd(access_idx);
1434022SN/A        const string &cstr = cmd.toString();
1442810SN/A
1452810SN/A        hits[access_idx]
1468833Sdam.sunwoo@arm.com            .init(system->maxMasters())
1472810SN/A            .name(name() + "." + cstr + "_hits")
1482810SN/A            .desc("number of " + cstr + " hits")
1492810SN/A            .flags(total | nozero | nonan)
1502810SN/A            ;
1518833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
1528833Sdam.sunwoo@arm.com            hits[access_idx].subname(i, system->getMasterName(i));
1538833Sdam.sunwoo@arm.com        }
1542810SN/A    }
1552810SN/A
1564871SN/A// These macros make it easier to sum the right subset of commands and
1574871SN/A// to change the subset of commands that are considered "demand" vs
1584871SN/A// "non-demand"
1594871SN/A#define SUM_DEMAND(s) \
1604871SN/A    (s[MemCmd::ReadReq] + s[MemCmd::WriteReq] + s[MemCmd::ReadExReq])
1614871SN/A
1624871SN/A// should writebacks be included here?  prior code was inconsistent...
1634871SN/A#define SUM_NON_DEMAND(s) \
1644871SN/A    (s[MemCmd::SoftPFReq] + s[MemCmd::HardPFReq])
1654871SN/A
1662810SN/A    demandHits
1672810SN/A        .name(name() + ".demand_hits")
1682810SN/A        .desc("number of demand (read+write) hits")
1698833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
1702810SN/A        ;
1714871SN/A    demandHits = SUM_DEMAND(hits);
1728833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
1738833Sdam.sunwoo@arm.com        demandHits.subname(i, system->getMasterName(i));
1748833Sdam.sunwoo@arm.com    }
1752810SN/A
1762810SN/A    overallHits
1772810SN/A        .name(name() + ".overall_hits")
1782810SN/A        .desc("number of overall hits")
1798833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
1802810SN/A        ;
1814871SN/A    overallHits = demandHits + SUM_NON_DEMAND(hits);
1828833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
1838833Sdam.sunwoo@arm.com        overallHits.subname(i, system->getMasterName(i));
1848833Sdam.sunwoo@arm.com    }
1852810SN/A
1862810SN/A    // Miss statistics
1874022SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
1884022SN/A        MemCmd cmd(access_idx);
1894022SN/A        const string &cstr = cmd.toString();
1902810SN/A
1912810SN/A        misses[access_idx]
1928833Sdam.sunwoo@arm.com            .init(system->maxMasters())
1932810SN/A            .name(name() + "." + cstr + "_misses")
1942810SN/A            .desc("number of " + cstr + " misses")
1952810SN/A            .flags(total | nozero | nonan)
1962810SN/A            ;
1978833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
1988833Sdam.sunwoo@arm.com            misses[access_idx].subname(i, system->getMasterName(i));
1998833Sdam.sunwoo@arm.com        }
2002810SN/A    }
2012810SN/A
2022810SN/A    demandMisses
2032810SN/A        .name(name() + ".demand_misses")
2042810SN/A        .desc("number of demand (read+write) misses")
2058833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
2062810SN/A        ;
2074871SN/A    demandMisses = SUM_DEMAND(misses);
2088833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
2098833Sdam.sunwoo@arm.com        demandMisses.subname(i, system->getMasterName(i));
2108833Sdam.sunwoo@arm.com    }
2112810SN/A
2122810SN/A    overallMisses
2132810SN/A        .name(name() + ".overall_misses")
2142810SN/A        .desc("number of overall misses")
2158833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
2162810SN/A        ;
2174871SN/A    overallMisses = demandMisses + SUM_NON_DEMAND(misses);
2188833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
2198833Sdam.sunwoo@arm.com        overallMisses.subname(i, system->getMasterName(i));
2208833Sdam.sunwoo@arm.com    }
2212810SN/A
2222810SN/A    // Miss latency statistics
2234022SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
2244022SN/A        MemCmd cmd(access_idx);
2254022SN/A        const string &cstr = cmd.toString();
2262810SN/A
2272810SN/A        missLatency[access_idx]
2288833Sdam.sunwoo@arm.com            .init(system->maxMasters())
2292810SN/A            .name(name() + "." + cstr + "_miss_latency")
2302810SN/A            .desc("number of " + cstr + " miss cycles")
2312810SN/A            .flags(total | nozero | nonan)
2322810SN/A            ;
2338833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
2348833Sdam.sunwoo@arm.com            missLatency[access_idx].subname(i, system->getMasterName(i));
2358833Sdam.sunwoo@arm.com        }
2362810SN/A    }
2372810SN/A
2382810SN/A    demandMissLatency
2392810SN/A        .name(name() + ".demand_miss_latency")
2402810SN/A        .desc("number of demand (read+write) miss cycles")
2418833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
2422810SN/A        ;
2434871SN/A    demandMissLatency = SUM_DEMAND(missLatency);
2448833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
2458833Sdam.sunwoo@arm.com        demandMissLatency.subname(i, system->getMasterName(i));
2468833Sdam.sunwoo@arm.com    }
2472810SN/A
2482810SN/A    overallMissLatency
2492810SN/A        .name(name() + ".overall_miss_latency")
2502810SN/A        .desc("number of overall miss cycles")
2518833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
2522810SN/A        ;
2534871SN/A    overallMissLatency = demandMissLatency + SUM_NON_DEMAND(missLatency);
2548833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
2558833Sdam.sunwoo@arm.com        overallMissLatency.subname(i, system->getMasterName(i));
2568833Sdam.sunwoo@arm.com    }
2572810SN/A
2582810SN/A    // access formulas
2594022SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
2604022SN/A        MemCmd cmd(access_idx);
2614022SN/A        const string &cstr = cmd.toString();
2622810SN/A
2632810SN/A        accesses[access_idx]
2642810SN/A            .name(name() + "." + cstr + "_accesses")
2652810SN/A            .desc("number of " + cstr + " accesses(hits+misses)")
2662810SN/A            .flags(total | nozero | nonan)
2672810SN/A            ;
2688833Sdam.sunwoo@arm.com        accesses[access_idx] = hits[access_idx] + misses[access_idx];
2692810SN/A
2708833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
2718833Sdam.sunwoo@arm.com            accesses[access_idx].subname(i, system->getMasterName(i));
2728833Sdam.sunwoo@arm.com        }
2732810SN/A    }
2742810SN/A
2752810SN/A    demandAccesses
2762810SN/A        .name(name() + ".demand_accesses")
2772810SN/A        .desc("number of demand (read+write) accesses")
2788833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
2792810SN/A        ;
2802810SN/A    demandAccesses = demandHits + demandMisses;
2818833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
2828833Sdam.sunwoo@arm.com        demandAccesses.subname(i, system->getMasterName(i));
2838833Sdam.sunwoo@arm.com    }
2842810SN/A
2852810SN/A    overallAccesses
2862810SN/A        .name(name() + ".overall_accesses")
2872810SN/A        .desc("number of overall (read+write) accesses")
2888833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
2892810SN/A        ;
2902810SN/A    overallAccesses = overallHits + overallMisses;
2918833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
2928833Sdam.sunwoo@arm.com        overallAccesses.subname(i, system->getMasterName(i));
2938833Sdam.sunwoo@arm.com    }
2942810SN/A
2952810SN/A    // miss rate formulas
2964022SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
2974022SN/A        MemCmd cmd(access_idx);
2984022SN/A        const string &cstr = cmd.toString();
2992810SN/A
3002810SN/A        missRate[access_idx]
3012810SN/A            .name(name() + "." + cstr + "_miss_rate")
3022810SN/A            .desc("miss rate for " + cstr + " accesses")
3032810SN/A            .flags(total | nozero | nonan)
3042810SN/A            ;
3058833Sdam.sunwoo@arm.com        missRate[access_idx] = misses[access_idx] / accesses[access_idx];
3062810SN/A
3078833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
3088833Sdam.sunwoo@arm.com            missRate[access_idx].subname(i, system->getMasterName(i));
3098833Sdam.sunwoo@arm.com        }
3102810SN/A    }
3112810SN/A
3122810SN/A    demandMissRate
3132810SN/A        .name(name() + ".demand_miss_rate")
3142810SN/A        .desc("miss rate for demand accesses")
3158833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
3162810SN/A        ;
3172810SN/A    demandMissRate = demandMisses / demandAccesses;
3188833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
3198833Sdam.sunwoo@arm.com        demandMissRate.subname(i, system->getMasterName(i));
3208833Sdam.sunwoo@arm.com    }
3212810SN/A
3222810SN/A    overallMissRate
3232810SN/A        .name(name() + ".overall_miss_rate")
3242810SN/A        .desc("miss rate for overall accesses")
3258833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
3262810SN/A        ;
3272810SN/A    overallMissRate = overallMisses / overallAccesses;
3288833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
3298833Sdam.sunwoo@arm.com        overallMissRate.subname(i, system->getMasterName(i));
3308833Sdam.sunwoo@arm.com    }
3312810SN/A
3322810SN/A    // miss latency formulas
3334022SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
3344022SN/A        MemCmd cmd(access_idx);
3354022SN/A        const string &cstr = cmd.toString();
3362810SN/A
3372810SN/A        avgMissLatency[access_idx]
3382810SN/A            .name(name() + "." + cstr + "_avg_miss_latency")
3392810SN/A            .desc("average " + cstr + " miss latency")
3402810SN/A            .flags(total | nozero | nonan)
3412810SN/A            ;
3422810SN/A        avgMissLatency[access_idx] =
3432810SN/A            missLatency[access_idx] / misses[access_idx];
3448833Sdam.sunwoo@arm.com
3458833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
3468833Sdam.sunwoo@arm.com            avgMissLatency[access_idx].subname(i, system->getMasterName(i));
3478833Sdam.sunwoo@arm.com        }
3482810SN/A    }
3492810SN/A
3502810SN/A    demandAvgMissLatency
3512810SN/A        .name(name() + ".demand_avg_miss_latency")
3522810SN/A        .desc("average overall miss latency")
3538833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
3542810SN/A        ;
3552810SN/A    demandAvgMissLatency = demandMissLatency / demandMisses;
3568833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
3578833Sdam.sunwoo@arm.com        demandAvgMissLatency.subname(i, system->getMasterName(i));
3588833Sdam.sunwoo@arm.com    }
3592810SN/A
3602810SN/A    overallAvgMissLatency
3612810SN/A        .name(name() + ".overall_avg_miss_latency")
3622810SN/A        .desc("average overall miss latency")
3638833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
3642810SN/A        ;
3652810SN/A    overallAvgMissLatency = overallMissLatency / overallMisses;
3668833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
3678833Sdam.sunwoo@arm.com        overallAvgMissLatency.subname(i, system->getMasterName(i));
3688833Sdam.sunwoo@arm.com    }
3692810SN/A
3702810SN/A    blocked_cycles.init(NUM_BLOCKED_CAUSES);
3712810SN/A    blocked_cycles
3722810SN/A        .name(name() + ".blocked_cycles")
3732810SN/A        .desc("number of cycles access was blocked")
3742810SN/A        .subname(Blocked_NoMSHRs, "no_mshrs")
3752810SN/A        .subname(Blocked_NoTargets, "no_targets")
3762810SN/A        ;
3772810SN/A
3782810SN/A
3792810SN/A    blocked_causes.init(NUM_BLOCKED_CAUSES);
3802810SN/A    blocked_causes
3812810SN/A        .name(name() + ".blocked")
3822810SN/A        .desc("number of cycles access was blocked")
3832810SN/A        .subname(Blocked_NoMSHRs, "no_mshrs")
3842810SN/A        .subname(Blocked_NoTargets, "no_targets")
3852810SN/A        ;
3862810SN/A
3872810SN/A    avg_blocked
3882810SN/A        .name(name() + ".avg_blocked_cycles")
3892810SN/A        .desc("average number of cycles each access was blocked")
3902810SN/A        .subname(Blocked_NoMSHRs, "no_mshrs")
3912810SN/A        .subname(Blocked_NoTargets, "no_targets")
3922810SN/A        ;
3932810SN/A
3942810SN/A    avg_blocked = blocked_cycles / blocked_causes;
3952810SN/A
3962810SN/A    fastWrites
3972810SN/A        .name(name() + ".fast_writes")
3982810SN/A        .desc("number of fast writes performed")
3992810SN/A        ;
4002810SN/A
4012810SN/A    cacheCopies
4022810SN/A        .name(name() + ".cache_copies")
4032810SN/A        .desc("number of cache copies performed")
4042810SN/A        ;
4052826SN/A
4064626SN/A    writebacks
4078833Sdam.sunwoo@arm.com        .init(system->maxMasters())
4084626SN/A        .name(name() + ".writebacks")
4094626SN/A        .desc("number of writebacks")
4108833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
4114626SN/A        ;
4128833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
4138833Sdam.sunwoo@arm.com        writebacks.subname(i, system->getMasterName(i));
4148833Sdam.sunwoo@arm.com    }
4154626SN/A
4164626SN/A    // MSHR statistics
4174626SN/A    // MSHR hit statistics
4184626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
4194626SN/A        MemCmd cmd(access_idx);
4204626SN/A        const string &cstr = cmd.toString();
4214626SN/A
4224626SN/A        mshr_hits[access_idx]
4238833Sdam.sunwoo@arm.com            .init(system->maxMasters())
4244626SN/A            .name(name() + "." + cstr + "_mshr_hits")
4254626SN/A            .desc("number of " + cstr + " MSHR hits")
4264626SN/A            .flags(total | nozero | nonan)
4274626SN/A            ;
4288833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
4298833Sdam.sunwoo@arm.com            mshr_hits[access_idx].subname(i, system->getMasterName(i));
4308833Sdam.sunwoo@arm.com        }
4314626SN/A    }
4324626SN/A
4334626SN/A    demandMshrHits
4344626SN/A        .name(name() + ".demand_mshr_hits")
4354626SN/A        .desc("number of demand (read+write) MSHR hits")
4368833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
4374626SN/A        ;
4384871SN/A    demandMshrHits = SUM_DEMAND(mshr_hits);
4398833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
4408833Sdam.sunwoo@arm.com        demandMshrHits.subname(i, system->getMasterName(i));
4418833Sdam.sunwoo@arm.com    }
4424626SN/A
4434626SN/A    overallMshrHits
4444626SN/A        .name(name() + ".overall_mshr_hits")
4454626SN/A        .desc("number of overall MSHR hits")
4468833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
4474626SN/A        ;
4484871SN/A    overallMshrHits = demandMshrHits + SUM_NON_DEMAND(mshr_hits);
4498833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
4508833Sdam.sunwoo@arm.com        overallMshrHits.subname(i, system->getMasterName(i));
4518833Sdam.sunwoo@arm.com    }
4524626SN/A
4534626SN/A    // MSHR miss statistics
4544626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
4554626SN/A        MemCmd cmd(access_idx);
4564626SN/A        const string &cstr = cmd.toString();
4574626SN/A
4584626SN/A        mshr_misses[access_idx]
4598833Sdam.sunwoo@arm.com            .init(system->maxMasters())
4604626SN/A            .name(name() + "." + cstr + "_mshr_misses")
4614626SN/A            .desc("number of " + cstr + " MSHR misses")
4624626SN/A            .flags(total | nozero | nonan)
4634626SN/A            ;
4648833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
4658833Sdam.sunwoo@arm.com            mshr_misses[access_idx].subname(i, system->getMasterName(i));
4668833Sdam.sunwoo@arm.com        }
4674626SN/A    }
4684626SN/A
4694626SN/A    demandMshrMisses
4704626SN/A        .name(name() + ".demand_mshr_misses")
4714626SN/A        .desc("number of demand (read+write) MSHR misses")
4728833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
4734626SN/A        ;
4744871SN/A    demandMshrMisses = SUM_DEMAND(mshr_misses);
4758833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
4768833Sdam.sunwoo@arm.com        demandMshrMisses.subname(i, system->getMasterName(i));
4778833Sdam.sunwoo@arm.com    }
4784626SN/A
4794626SN/A    overallMshrMisses
4804626SN/A        .name(name() + ".overall_mshr_misses")
4814626SN/A        .desc("number of overall MSHR misses")
4828833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
4834626SN/A        ;
4844871SN/A    overallMshrMisses = demandMshrMisses + SUM_NON_DEMAND(mshr_misses);
4858833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
4868833Sdam.sunwoo@arm.com        overallMshrMisses.subname(i, system->getMasterName(i));
4878833Sdam.sunwoo@arm.com    }
4884626SN/A
4894626SN/A    // MSHR miss latency statistics
4904626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
4914626SN/A        MemCmd cmd(access_idx);
4924626SN/A        const string &cstr = cmd.toString();
4934626SN/A
4944626SN/A        mshr_miss_latency[access_idx]
4958833Sdam.sunwoo@arm.com            .init(system->maxMasters())
4964626SN/A            .name(name() + "." + cstr + "_mshr_miss_latency")
4974626SN/A            .desc("number of " + cstr + " MSHR miss cycles")
4984626SN/A            .flags(total | nozero | nonan)
4994626SN/A            ;
5008833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
5018833Sdam.sunwoo@arm.com            mshr_miss_latency[access_idx].subname(i, system->getMasterName(i));
5028833Sdam.sunwoo@arm.com        }
5034626SN/A    }
5044626SN/A
5054626SN/A    demandMshrMissLatency
5064626SN/A        .name(name() + ".demand_mshr_miss_latency")
5074626SN/A        .desc("number of demand (read+write) MSHR miss cycles")
5088833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
5094626SN/A        ;
5104871SN/A    demandMshrMissLatency = SUM_DEMAND(mshr_miss_latency);
5118833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
5128833Sdam.sunwoo@arm.com        demandMshrMissLatency.subname(i, system->getMasterName(i));
5138833Sdam.sunwoo@arm.com    }
5144626SN/A
5154626SN/A    overallMshrMissLatency
5164626SN/A        .name(name() + ".overall_mshr_miss_latency")
5174626SN/A        .desc("number of overall MSHR miss cycles")
5188833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
5194626SN/A        ;
5204871SN/A    overallMshrMissLatency =
5214871SN/A        demandMshrMissLatency + SUM_NON_DEMAND(mshr_miss_latency);
5228833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
5238833Sdam.sunwoo@arm.com        overallMshrMissLatency.subname(i, system->getMasterName(i));
5248833Sdam.sunwoo@arm.com    }
5254626SN/A
5264626SN/A    // MSHR uncacheable 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_uncacheable[access_idx]
5328833Sdam.sunwoo@arm.com            .init(system->maxMasters())
5334626SN/A            .name(name() + "." + cstr + "_mshr_uncacheable")
5344626SN/A            .desc("number of " + cstr + " MSHR uncacheable")
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_uncacheable[access_idx].subname(i, system->getMasterName(i));
5398833Sdam.sunwoo@arm.com        }
5404626SN/A    }
5414626SN/A
5424626SN/A    overallMshrUncacheable
5434626SN/A        .name(name() + ".overall_mshr_uncacheable_misses")
5444626SN/A        .desc("number of overall MSHR uncacheable misses")
5458833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
5464626SN/A        ;
5474871SN/A    overallMshrUncacheable =
5484871SN/A        SUM_DEMAND(mshr_uncacheable) + SUM_NON_DEMAND(mshr_uncacheable);
5498833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
5508833Sdam.sunwoo@arm.com        overallMshrUncacheable.subname(i, system->getMasterName(i));
5518833Sdam.sunwoo@arm.com    }
5524626SN/A
5534626SN/A    // MSHR miss latency statistics
5544626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
5554626SN/A        MemCmd cmd(access_idx);
5564626SN/A        const string &cstr = cmd.toString();
5574626SN/A
5584626SN/A        mshr_uncacheable_lat[access_idx]
5598833Sdam.sunwoo@arm.com            .init(system->maxMasters())
5604626SN/A            .name(name() + "." + cstr + "_mshr_uncacheable_latency")
5614626SN/A            .desc("number of " + cstr + " MSHR uncacheable cycles")
5624626SN/A            .flags(total | nozero | nonan)
5634626SN/A            ;
5648833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
5658833Sdam.sunwoo@arm.com            mshr_uncacheable_lat[access_idx].subname(i, system->getMasterName(i));
5668833Sdam.sunwoo@arm.com        }
5674626SN/A    }
5684626SN/A
5694626SN/A    overallMshrUncacheableLatency
5704626SN/A        .name(name() + ".overall_mshr_uncacheable_latency")
5714626SN/A        .desc("number of overall MSHR uncacheable cycles")
5728833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
5734626SN/A        ;
5744871SN/A    overallMshrUncacheableLatency =
5754871SN/A        SUM_DEMAND(mshr_uncacheable_lat) +
5764871SN/A        SUM_NON_DEMAND(mshr_uncacheable_lat);
5778833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
5788833Sdam.sunwoo@arm.com        overallMshrUncacheableLatency.subname(i, system->getMasterName(i));
5798833Sdam.sunwoo@arm.com    }
5804626SN/A
5814626SN/A#if 0
5824626SN/A    // MSHR access formulas
5834626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
5844626SN/A        MemCmd cmd(access_idx);
5854626SN/A        const string &cstr = cmd.toString();
5864626SN/A
5874626SN/A        mshrAccesses[access_idx]
5884626SN/A            .name(name() + "." + cstr + "_mshr_accesses")
5894626SN/A            .desc("number of " + cstr + " mshr accesses(hits+misses)")
5904626SN/A            .flags(total | nozero | nonan)
5914626SN/A            ;
5924626SN/A        mshrAccesses[access_idx] =
5934626SN/A            mshr_hits[access_idx] + mshr_misses[access_idx]
5944626SN/A            + mshr_uncacheable[access_idx];
5954626SN/A    }
5964626SN/A
5974626SN/A    demandMshrAccesses
5984626SN/A        .name(name() + ".demand_mshr_accesses")
5994626SN/A        .desc("number of demand (read+write) mshr accesses")
6004626SN/A        .flags(total | nozero | nonan)
6014626SN/A        ;
6024626SN/A    demandMshrAccesses = demandMshrHits + demandMshrMisses;
6034626SN/A
6044626SN/A    overallMshrAccesses
6054626SN/A        .name(name() + ".overall_mshr_accesses")
6064626SN/A        .desc("number of overall (read+write) mshr accesses")
6074626SN/A        .flags(total | nozero | nonan)
6084626SN/A        ;
6094626SN/A    overallMshrAccesses = overallMshrHits + overallMshrMisses
6104626SN/A        + overallMshrUncacheable;
6114626SN/A#endif
6124626SN/A
6134626SN/A    // MSHR miss rate formulas
6144626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
6154626SN/A        MemCmd cmd(access_idx);
6164626SN/A        const string &cstr = cmd.toString();
6174626SN/A
6184626SN/A        mshrMissRate[access_idx]
6194626SN/A            .name(name() + "." + cstr + "_mshr_miss_rate")
6204626SN/A            .desc("mshr miss rate for " + cstr + " accesses")
6214626SN/A            .flags(total | nozero | nonan)
6224626SN/A            ;
6234626SN/A        mshrMissRate[access_idx] =
6244626SN/A            mshr_misses[access_idx] / accesses[access_idx];
6258833Sdam.sunwoo@arm.com
6268833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
6278833Sdam.sunwoo@arm.com            mshrMissRate[access_idx].subname(i, system->getMasterName(i));
6288833Sdam.sunwoo@arm.com        }
6294626SN/A    }
6304626SN/A
6314626SN/A    demandMshrMissRate
6324626SN/A        .name(name() + ".demand_mshr_miss_rate")
6334626SN/A        .desc("mshr miss rate for demand accesses")
6348833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
6354626SN/A        ;
6364626SN/A    demandMshrMissRate = demandMshrMisses / demandAccesses;
6378833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
6388833Sdam.sunwoo@arm.com        demandMshrMissRate.subname(i, system->getMasterName(i));
6398833Sdam.sunwoo@arm.com    }
6404626SN/A
6414626SN/A    overallMshrMissRate
6424626SN/A        .name(name() + ".overall_mshr_miss_rate")
6434626SN/A        .desc("mshr miss rate for overall accesses")
6448833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
6454626SN/A        ;
6464626SN/A    overallMshrMissRate = overallMshrMisses / overallAccesses;
6478833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
6488833Sdam.sunwoo@arm.com        overallMshrMissRate.subname(i, system->getMasterName(i));
6498833Sdam.sunwoo@arm.com    }
6504626SN/A
6514626SN/A    // mshrMiss latency formulas
6524626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
6534626SN/A        MemCmd cmd(access_idx);
6544626SN/A        const string &cstr = cmd.toString();
6554626SN/A
6564626SN/A        avgMshrMissLatency[access_idx]
6574626SN/A            .name(name() + "." + cstr + "_avg_mshr_miss_latency")
6584626SN/A            .desc("average " + cstr + " mshr miss latency")
6594626SN/A            .flags(total | nozero | nonan)
6604626SN/A            ;
6614626SN/A        avgMshrMissLatency[access_idx] =
6624626SN/A            mshr_miss_latency[access_idx] / mshr_misses[access_idx];
6638833Sdam.sunwoo@arm.com
6648833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
6658833Sdam.sunwoo@arm.com            avgMshrMissLatency[access_idx].subname(i, system->getMasterName(i));
6668833Sdam.sunwoo@arm.com        }
6674626SN/A    }
6684626SN/A
6694626SN/A    demandAvgMshrMissLatency
6704626SN/A        .name(name() + ".demand_avg_mshr_miss_latency")
6714626SN/A        .desc("average overall mshr miss latency")
6728833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
6734626SN/A        ;
6744626SN/A    demandAvgMshrMissLatency = demandMshrMissLatency / demandMshrMisses;
6758833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
6768833Sdam.sunwoo@arm.com        demandAvgMshrMissLatency.subname(i, system->getMasterName(i));
6778833Sdam.sunwoo@arm.com    }
6784626SN/A
6794626SN/A    overallAvgMshrMissLatency
6804626SN/A        .name(name() + ".overall_avg_mshr_miss_latency")
6814626SN/A        .desc("average overall mshr miss latency")
6828833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
6834626SN/A        ;
6844626SN/A    overallAvgMshrMissLatency = overallMshrMissLatency / overallMshrMisses;
6858833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
6868833Sdam.sunwoo@arm.com        overallAvgMshrMissLatency.subname(i, system->getMasterName(i));
6878833Sdam.sunwoo@arm.com    }
6884626SN/A
6894626SN/A    // mshrUncacheable latency formulas
6904626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
6914626SN/A        MemCmd cmd(access_idx);
6924626SN/A        const string &cstr = cmd.toString();
6934626SN/A
6944626SN/A        avgMshrUncacheableLatency[access_idx]
6954626SN/A            .name(name() + "." + cstr + "_avg_mshr_uncacheable_latency")
6964626SN/A            .desc("average " + cstr + " mshr uncacheable latency")
6974626SN/A            .flags(total | nozero | nonan)
6984626SN/A            ;
6994626SN/A        avgMshrUncacheableLatency[access_idx] =
7004626SN/A            mshr_uncacheable_lat[access_idx] / mshr_uncacheable[access_idx];
7018833Sdam.sunwoo@arm.com
7028833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
7038833Sdam.sunwoo@arm.com            avgMshrUncacheableLatency[access_idx].subname(i, system->getMasterName(i));
7048833Sdam.sunwoo@arm.com        }
7054626SN/A    }
7064626SN/A
7074626SN/A    overallAvgMshrUncacheableLatency
7084626SN/A        .name(name() + ".overall_avg_mshr_uncacheable_latency")
7094626SN/A        .desc("average overall mshr uncacheable latency")
7108833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
7114626SN/A        ;
7124626SN/A    overallAvgMshrUncacheableLatency = overallMshrUncacheableLatency / overallMshrUncacheable;
7138833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
7148833Sdam.sunwoo@arm.com        overallAvgMshrUncacheableLatency.subname(i, system->getMasterName(i));
7158833Sdam.sunwoo@arm.com    }
7164626SN/A
7174626SN/A    mshr_cap_events
7188833Sdam.sunwoo@arm.com        .init(system->maxMasters())
7194626SN/A        .name(name() + ".mshr_cap_events")
7204626SN/A        .desc("number of times MSHR cap was activated")
7218833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
7224626SN/A        ;
7238833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
7248833Sdam.sunwoo@arm.com        mshr_cap_events.subname(i, system->getMasterName(i));
7258833Sdam.sunwoo@arm.com    }
7264626SN/A
7274626SN/A    //software prefetching stats
7284626SN/A    soft_prefetch_mshr_full
7298833Sdam.sunwoo@arm.com        .init(system->maxMasters())
7304626SN/A        .name(name() + ".soft_prefetch_mshr_full")
7314626SN/A        .desc("number of mshr full events for SW prefetching instrutions")
7328833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
7334626SN/A        ;
7348833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
7358833Sdam.sunwoo@arm.com        soft_prefetch_mshr_full.subname(i, system->getMasterName(i));
7368833Sdam.sunwoo@arm.com    }
7374626SN/A
7384626SN/A    mshr_no_allocate_misses
7394626SN/A        .name(name() +".no_allocate_misses")
7404626SN/A        .desc("Number of misses that were no-allocate")
7414626SN/A        ;
7424626SN/A
7432810SN/A}
7443503SN/A
7453503SN/Aunsigned int
7463503SN/ABaseCache::drain(Event *de)
7473503SN/A{
7484626SN/A    int count = memSidePort->drain(de) + cpuSidePort->drain(de);
7494626SN/A
7503503SN/A    // Set status
7514626SN/A    if (count != 0) {
7523503SN/A        drainEvent = de;
7533503SN/A
7543503SN/A        changeState(SimObject::Draining);
7554626SN/A        return count;
7563503SN/A    }
7573503SN/A
7583503SN/A    changeState(SimObject::Drained);
7593503SN/A    return 0;
7603503SN/A}
761