base.cc revision 8856
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::CacheMasterPort::CacheMasterPort(const std::string &_name,
588856Sandreas.hansson@arm.com                                            BaseCache *_cache,
598856Sandreas.hansson@arm.com                                            const std::string &_label)
608856Sandreas.hansson@arm.com    : SimpleTimingPort(_name, _cache, _label)
612810SN/A{
624475SN/A}
634475SN/A
648856Sandreas.hansson@arm.comBaseCache::CacheSlavePort::CacheSlavePort(const std::string &_name,
658856Sandreas.hansson@arm.com                                          BaseCache *_cache,
668856Sandreas.hansson@arm.com                                          const std::string &_label)
678856Sandreas.hansson@arm.com    : SimpleTimingPort(_name, _cache, _label), blocked(false),
688856Sandreas.hansson@arm.com      mustSendRetry(false), sendRetryEvent(this)
698856Sandreas.hansson@arm.com{
708856Sandreas.hansson@arm.com}
714475SN/A
725034SN/ABaseCache::BaseCache(const Params *p)
735034SN/A    : MemObject(p),
745314SN/A      mshrQueue("MSHRs", p->mshrs, 4, MSHRQueue_MSHRs),
755314SN/A      writeBuffer("write buffer", p->write_buffers, p->mshrs+1000,
764628SN/A                  MSHRQueue_WriteBuffer),
775034SN/A      blkSize(p->block_size),
785034SN/A      hitLatency(p->latency),
795034SN/A      numTarget(p->tgts_per_mshr),
806122SSteve.Reinhardt@amd.com      forwardSnoops(p->forward_snoops),
818134SAli.Saidi@ARM.com      isTopLevel(p->is_top_level),
824626SN/A      blocked(0),
834626SN/A      noTargetMSHR(NULL),
845034SN/A      missCount(p->max_miss_count),
856122SSteve.Reinhardt@amd.com      drainEvent(NULL),
866978SLisa.Hsu@amd.com      addrRange(p->addr_range),
878833Sdam.sunwoo@arm.com      system(p->system)
884458SN/A{
892810SN/A}
902810SN/A
913013SN/Avoid
928856Sandreas.hansson@arm.comBaseCache::CacheSlavePort::setBlocked()
932810SN/A{
943013SN/A    assert(!blocked);
958856Sandreas.hansson@arm.com    DPRINTF(CachePort, "Cache port %s blocking new requests\n", name());
962810SN/A    blocked = true;
972810SN/A}
982810SN/A
992810SN/Avoid
1008856Sandreas.hansson@arm.comBaseCache::CacheSlavePort::clearBlocked()
1012810SN/A{
1023013SN/A    assert(blocked);
1038856Sandreas.hansson@arm.com    DPRINTF(CachePort, "Cache port %s accepting new requests\n", name());
1043013SN/A    blocked = false;
1058856Sandreas.hansson@arm.com    if (mustSendRetry) {
1068856Sandreas.hansson@arm.com        DPRINTF(CachePort, "Cache port %s sending retry\n", name());
1072897SN/A        mustSendRetry = false;
1084666SN/A        // @TODO: need to find a better time (next bus cycle?)
1098856Sandreas.hansson@arm.com        owner->schedule(sendRetryEvent, curTick() + 1);
1102897SN/A    }
1112810SN/A}
1122810SN/A
1132844SN/A
1142810SN/Avoid
1152858SN/ABaseCache::init()
1162858SN/A{
1178856Sandreas.hansson@arm.com    if (!cpuSidePort->isConnected() || !memSidePort->isConnected())
1188856Sandreas.hansson@arm.com        panic("Cache %s not hooked up on both sides\n", name());
1198711Sandreas.hansson@arm.com    cpuSidePort->sendRangeChange();
1202858SN/A}
1212858SN/A
1224628SN/A
1232858SN/Avoid
1242810SN/ABaseCache::regStats()
1252810SN/A{
1262810SN/A    using namespace Stats;
1272810SN/A
1282810SN/A    // Hit statistics
1294022SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
1304022SN/A        MemCmd cmd(access_idx);
1314022SN/A        const string &cstr = cmd.toString();
1322810SN/A
1332810SN/A        hits[access_idx]
1348833Sdam.sunwoo@arm.com            .init(system->maxMasters())
1352810SN/A            .name(name() + "." + cstr + "_hits")
1362810SN/A            .desc("number of " + cstr + " hits")
1372810SN/A            .flags(total | nozero | nonan)
1382810SN/A            ;
1398833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
1408833Sdam.sunwoo@arm.com            hits[access_idx].subname(i, system->getMasterName(i));
1418833Sdam.sunwoo@arm.com        }
1422810SN/A    }
1432810SN/A
1444871SN/A// These macros make it easier to sum the right subset of commands and
1454871SN/A// to change the subset of commands that are considered "demand" vs
1464871SN/A// "non-demand"
1474871SN/A#define SUM_DEMAND(s) \
1484871SN/A    (s[MemCmd::ReadReq] + s[MemCmd::WriteReq] + s[MemCmd::ReadExReq])
1494871SN/A
1504871SN/A// should writebacks be included here?  prior code was inconsistent...
1514871SN/A#define SUM_NON_DEMAND(s) \
1524871SN/A    (s[MemCmd::SoftPFReq] + s[MemCmd::HardPFReq])
1534871SN/A
1542810SN/A    demandHits
1552810SN/A        .name(name() + ".demand_hits")
1562810SN/A        .desc("number of demand (read+write) hits")
1578833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
1582810SN/A        ;
1594871SN/A    demandHits = SUM_DEMAND(hits);
1608833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
1618833Sdam.sunwoo@arm.com        demandHits.subname(i, system->getMasterName(i));
1628833Sdam.sunwoo@arm.com    }
1632810SN/A
1642810SN/A    overallHits
1652810SN/A        .name(name() + ".overall_hits")
1662810SN/A        .desc("number of overall hits")
1678833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
1682810SN/A        ;
1694871SN/A    overallHits = demandHits + SUM_NON_DEMAND(hits);
1708833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
1718833Sdam.sunwoo@arm.com        overallHits.subname(i, system->getMasterName(i));
1728833Sdam.sunwoo@arm.com    }
1732810SN/A
1742810SN/A    // Miss statistics
1754022SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
1764022SN/A        MemCmd cmd(access_idx);
1774022SN/A        const string &cstr = cmd.toString();
1782810SN/A
1792810SN/A        misses[access_idx]
1808833Sdam.sunwoo@arm.com            .init(system->maxMasters())
1812810SN/A            .name(name() + "." + cstr + "_misses")
1822810SN/A            .desc("number of " + cstr + " misses")
1832810SN/A            .flags(total | nozero | nonan)
1842810SN/A            ;
1858833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
1868833Sdam.sunwoo@arm.com            misses[access_idx].subname(i, system->getMasterName(i));
1878833Sdam.sunwoo@arm.com        }
1882810SN/A    }
1892810SN/A
1902810SN/A    demandMisses
1912810SN/A        .name(name() + ".demand_misses")
1922810SN/A        .desc("number of demand (read+write) misses")
1938833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
1942810SN/A        ;
1954871SN/A    demandMisses = SUM_DEMAND(misses);
1968833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
1978833Sdam.sunwoo@arm.com        demandMisses.subname(i, system->getMasterName(i));
1988833Sdam.sunwoo@arm.com    }
1992810SN/A
2002810SN/A    overallMisses
2012810SN/A        .name(name() + ".overall_misses")
2022810SN/A        .desc("number of overall misses")
2038833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
2042810SN/A        ;
2054871SN/A    overallMisses = demandMisses + SUM_NON_DEMAND(misses);
2068833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
2078833Sdam.sunwoo@arm.com        overallMisses.subname(i, system->getMasterName(i));
2088833Sdam.sunwoo@arm.com    }
2092810SN/A
2102810SN/A    // Miss latency statistics
2114022SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
2124022SN/A        MemCmd cmd(access_idx);
2134022SN/A        const string &cstr = cmd.toString();
2142810SN/A
2152810SN/A        missLatency[access_idx]
2168833Sdam.sunwoo@arm.com            .init(system->maxMasters())
2172810SN/A            .name(name() + "." + cstr + "_miss_latency")
2182810SN/A            .desc("number of " + cstr + " miss cycles")
2192810SN/A            .flags(total | nozero | nonan)
2202810SN/A            ;
2218833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
2228833Sdam.sunwoo@arm.com            missLatency[access_idx].subname(i, system->getMasterName(i));
2238833Sdam.sunwoo@arm.com        }
2242810SN/A    }
2252810SN/A
2262810SN/A    demandMissLatency
2272810SN/A        .name(name() + ".demand_miss_latency")
2282810SN/A        .desc("number of demand (read+write) miss cycles")
2298833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
2302810SN/A        ;
2314871SN/A    demandMissLatency = SUM_DEMAND(missLatency);
2328833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
2338833Sdam.sunwoo@arm.com        demandMissLatency.subname(i, system->getMasterName(i));
2348833Sdam.sunwoo@arm.com    }
2352810SN/A
2362810SN/A    overallMissLatency
2372810SN/A        .name(name() + ".overall_miss_latency")
2382810SN/A        .desc("number of overall miss cycles")
2398833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
2402810SN/A        ;
2414871SN/A    overallMissLatency = demandMissLatency + SUM_NON_DEMAND(missLatency);
2428833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
2438833Sdam.sunwoo@arm.com        overallMissLatency.subname(i, system->getMasterName(i));
2448833Sdam.sunwoo@arm.com    }
2452810SN/A
2462810SN/A    // access formulas
2474022SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
2484022SN/A        MemCmd cmd(access_idx);
2494022SN/A        const string &cstr = cmd.toString();
2502810SN/A
2512810SN/A        accesses[access_idx]
2522810SN/A            .name(name() + "." + cstr + "_accesses")
2532810SN/A            .desc("number of " + cstr + " accesses(hits+misses)")
2542810SN/A            .flags(total | nozero | nonan)
2552810SN/A            ;
2568833Sdam.sunwoo@arm.com        accesses[access_idx] = hits[access_idx] + misses[access_idx];
2572810SN/A
2588833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
2598833Sdam.sunwoo@arm.com            accesses[access_idx].subname(i, system->getMasterName(i));
2608833Sdam.sunwoo@arm.com        }
2612810SN/A    }
2622810SN/A
2632810SN/A    demandAccesses
2642810SN/A        .name(name() + ".demand_accesses")
2652810SN/A        .desc("number of demand (read+write) accesses")
2668833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
2672810SN/A        ;
2682810SN/A    demandAccesses = demandHits + demandMisses;
2698833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
2708833Sdam.sunwoo@arm.com        demandAccesses.subname(i, system->getMasterName(i));
2718833Sdam.sunwoo@arm.com    }
2722810SN/A
2732810SN/A    overallAccesses
2742810SN/A        .name(name() + ".overall_accesses")
2752810SN/A        .desc("number of overall (read+write) accesses")
2768833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
2772810SN/A        ;
2782810SN/A    overallAccesses = overallHits + overallMisses;
2798833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
2808833Sdam.sunwoo@arm.com        overallAccesses.subname(i, system->getMasterName(i));
2818833Sdam.sunwoo@arm.com    }
2822810SN/A
2832810SN/A    // miss rate formulas
2844022SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
2854022SN/A        MemCmd cmd(access_idx);
2864022SN/A        const string &cstr = cmd.toString();
2872810SN/A
2882810SN/A        missRate[access_idx]
2892810SN/A            .name(name() + "." + cstr + "_miss_rate")
2902810SN/A            .desc("miss rate for " + cstr + " accesses")
2912810SN/A            .flags(total | nozero | nonan)
2922810SN/A            ;
2938833Sdam.sunwoo@arm.com        missRate[access_idx] = misses[access_idx] / accesses[access_idx];
2942810SN/A
2958833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
2968833Sdam.sunwoo@arm.com            missRate[access_idx].subname(i, system->getMasterName(i));
2978833Sdam.sunwoo@arm.com        }
2982810SN/A    }
2992810SN/A
3002810SN/A    demandMissRate
3012810SN/A        .name(name() + ".demand_miss_rate")
3022810SN/A        .desc("miss rate for demand accesses")
3038833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
3042810SN/A        ;
3052810SN/A    demandMissRate = demandMisses / demandAccesses;
3068833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
3078833Sdam.sunwoo@arm.com        demandMissRate.subname(i, system->getMasterName(i));
3088833Sdam.sunwoo@arm.com    }
3092810SN/A
3102810SN/A    overallMissRate
3112810SN/A        .name(name() + ".overall_miss_rate")
3122810SN/A        .desc("miss rate for overall accesses")
3138833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
3142810SN/A        ;
3152810SN/A    overallMissRate = overallMisses / overallAccesses;
3168833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
3178833Sdam.sunwoo@arm.com        overallMissRate.subname(i, system->getMasterName(i));
3188833Sdam.sunwoo@arm.com    }
3192810SN/A
3202810SN/A    // miss latency formulas
3214022SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
3224022SN/A        MemCmd cmd(access_idx);
3234022SN/A        const string &cstr = cmd.toString();
3242810SN/A
3252810SN/A        avgMissLatency[access_idx]
3262810SN/A            .name(name() + "." + cstr + "_avg_miss_latency")
3272810SN/A            .desc("average " + cstr + " miss latency")
3282810SN/A            .flags(total | nozero | nonan)
3292810SN/A            ;
3302810SN/A        avgMissLatency[access_idx] =
3312810SN/A            missLatency[access_idx] / misses[access_idx];
3328833Sdam.sunwoo@arm.com
3338833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
3348833Sdam.sunwoo@arm.com            avgMissLatency[access_idx].subname(i, system->getMasterName(i));
3358833Sdam.sunwoo@arm.com        }
3362810SN/A    }
3372810SN/A
3382810SN/A    demandAvgMissLatency
3392810SN/A        .name(name() + ".demand_avg_miss_latency")
3402810SN/A        .desc("average overall miss latency")
3418833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
3422810SN/A        ;
3432810SN/A    demandAvgMissLatency = demandMissLatency / demandMisses;
3448833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
3458833Sdam.sunwoo@arm.com        demandAvgMissLatency.subname(i, system->getMasterName(i));
3468833Sdam.sunwoo@arm.com    }
3472810SN/A
3482810SN/A    overallAvgMissLatency
3492810SN/A        .name(name() + ".overall_avg_miss_latency")
3502810SN/A        .desc("average overall miss latency")
3518833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
3522810SN/A        ;
3532810SN/A    overallAvgMissLatency = overallMissLatency / overallMisses;
3548833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
3558833Sdam.sunwoo@arm.com        overallAvgMissLatency.subname(i, system->getMasterName(i));
3568833Sdam.sunwoo@arm.com    }
3572810SN/A
3582810SN/A    blocked_cycles.init(NUM_BLOCKED_CAUSES);
3592810SN/A    blocked_cycles
3602810SN/A        .name(name() + ".blocked_cycles")
3612810SN/A        .desc("number of cycles access was blocked")
3622810SN/A        .subname(Blocked_NoMSHRs, "no_mshrs")
3632810SN/A        .subname(Blocked_NoTargets, "no_targets")
3642810SN/A        ;
3652810SN/A
3662810SN/A
3672810SN/A    blocked_causes.init(NUM_BLOCKED_CAUSES);
3682810SN/A    blocked_causes
3692810SN/A        .name(name() + ".blocked")
3702810SN/A        .desc("number of cycles access was blocked")
3712810SN/A        .subname(Blocked_NoMSHRs, "no_mshrs")
3722810SN/A        .subname(Blocked_NoTargets, "no_targets")
3732810SN/A        ;
3742810SN/A
3752810SN/A    avg_blocked
3762810SN/A        .name(name() + ".avg_blocked_cycles")
3772810SN/A        .desc("average number of cycles each access was blocked")
3782810SN/A        .subname(Blocked_NoMSHRs, "no_mshrs")
3792810SN/A        .subname(Blocked_NoTargets, "no_targets")
3802810SN/A        ;
3812810SN/A
3822810SN/A    avg_blocked = blocked_cycles / blocked_causes;
3832810SN/A
3842810SN/A    fastWrites
3852810SN/A        .name(name() + ".fast_writes")
3862810SN/A        .desc("number of fast writes performed")
3872810SN/A        ;
3882810SN/A
3892810SN/A    cacheCopies
3902810SN/A        .name(name() + ".cache_copies")
3912810SN/A        .desc("number of cache copies performed")
3922810SN/A        ;
3932826SN/A
3944626SN/A    writebacks
3958833Sdam.sunwoo@arm.com        .init(system->maxMasters())
3964626SN/A        .name(name() + ".writebacks")
3974626SN/A        .desc("number of writebacks")
3988833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
3994626SN/A        ;
4008833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
4018833Sdam.sunwoo@arm.com        writebacks.subname(i, system->getMasterName(i));
4028833Sdam.sunwoo@arm.com    }
4034626SN/A
4044626SN/A    // MSHR statistics
4054626SN/A    // MSHR hit statistics
4064626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
4074626SN/A        MemCmd cmd(access_idx);
4084626SN/A        const string &cstr = cmd.toString();
4094626SN/A
4104626SN/A        mshr_hits[access_idx]
4118833Sdam.sunwoo@arm.com            .init(system->maxMasters())
4124626SN/A            .name(name() + "." + cstr + "_mshr_hits")
4134626SN/A            .desc("number of " + cstr + " MSHR hits")
4144626SN/A            .flags(total | nozero | nonan)
4154626SN/A            ;
4168833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
4178833Sdam.sunwoo@arm.com            mshr_hits[access_idx].subname(i, system->getMasterName(i));
4188833Sdam.sunwoo@arm.com        }
4194626SN/A    }
4204626SN/A
4214626SN/A    demandMshrHits
4224626SN/A        .name(name() + ".demand_mshr_hits")
4234626SN/A        .desc("number of demand (read+write) MSHR hits")
4248833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
4254626SN/A        ;
4264871SN/A    demandMshrHits = SUM_DEMAND(mshr_hits);
4278833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
4288833Sdam.sunwoo@arm.com        demandMshrHits.subname(i, system->getMasterName(i));
4298833Sdam.sunwoo@arm.com    }
4304626SN/A
4314626SN/A    overallMshrHits
4324626SN/A        .name(name() + ".overall_mshr_hits")
4334626SN/A        .desc("number of overall MSHR hits")
4348833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
4354626SN/A        ;
4364871SN/A    overallMshrHits = demandMshrHits + SUM_NON_DEMAND(mshr_hits);
4378833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
4388833Sdam.sunwoo@arm.com        overallMshrHits.subname(i, system->getMasterName(i));
4398833Sdam.sunwoo@arm.com    }
4404626SN/A
4414626SN/A    // MSHR miss statistics
4424626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
4434626SN/A        MemCmd cmd(access_idx);
4444626SN/A        const string &cstr = cmd.toString();
4454626SN/A
4464626SN/A        mshr_misses[access_idx]
4478833Sdam.sunwoo@arm.com            .init(system->maxMasters())
4484626SN/A            .name(name() + "." + cstr + "_mshr_misses")
4494626SN/A            .desc("number of " + cstr + " MSHR misses")
4504626SN/A            .flags(total | nozero | nonan)
4514626SN/A            ;
4528833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
4538833Sdam.sunwoo@arm.com            mshr_misses[access_idx].subname(i, system->getMasterName(i));
4548833Sdam.sunwoo@arm.com        }
4554626SN/A    }
4564626SN/A
4574626SN/A    demandMshrMisses
4584626SN/A        .name(name() + ".demand_mshr_misses")
4594626SN/A        .desc("number of demand (read+write) MSHR misses")
4608833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
4614626SN/A        ;
4624871SN/A    demandMshrMisses = SUM_DEMAND(mshr_misses);
4638833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
4648833Sdam.sunwoo@arm.com        demandMshrMisses.subname(i, system->getMasterName(i));
4658833Sdam.sunwoo@arm.com    }
4664626SN/A
4674626SN/A    overallMshrMisses
4684626SN/A        .name(name() + ".overall_mshr_misses")
4694626SN/A        .desc("number of overall MSHR misses")
4708833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
4714626SN/A        ;
4724871SN/A    overallMshrMisses = demandMshrMisses + SUM_NON_DEMAND(mshr_misses);
4738833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
4748833Sdam.sunwoo@arm.com        overallMshrMisses.subname(i, system->getMasterName(i));
4758833Sdam.sunwoo@arm.com    }
4764626SN/A
4774626SN/A    // MSHR miss latency statistics
4784626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
4794626SN/A        MemCmd cmd(access_idx);
4804626SN/A        const string &cstr = cmd.toString();
4814626SN/A
4824626SN/A        mshr_miss_latency[access_idx]
4838833Sdam.sunwoo@arm.com            .init(system->maxMasters())
4844626SN/A            .name(name() + "." + cstr + "_mshr_miss_latency")
4854626SN/A            .desc("number of " + cstr + " MSHR miss cycles")
4864626SN/A            .flags(total | nozero | nonan)
4874626SN/A            ;
4888833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
4898833Sdam.sunwoo@arm.com            mshr_miss_latency[access_idx].subname(i, system->getMasterName(i));
4908833Sdam.sunwoo@arm.com        }
4914626SN/A    }
4924626SN/A
4934626SN/A    demandMshrMissLatency
4944626SN/A        .name(name() + ".demand_mshr_miss_latency")
4954626SN/A        .desc("number of demand (read+write) MSHR miss cycles")
4968833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
4974626SN/A        ;
4984871SN/A    demandMshrMissLatency = SUM_DEMAND(mshr_miss_latency);
4998833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
5008833Sdam.sunwoo@arm.com        demandMshrMissLatency.subname(i, system->getMasterName(i));
5018833Sdam.sunwoo@arm.com    }
5024626SN/A
5034626SN/A    overallMshrMissLatency
5044626SN/A        .name(name() + ".overall_mshr_miss_latency")
5054626SN/A        .desc("number of overall MSHR miss cycles")
5068833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
5074626SN/A        ;
5084871SN/A    overallMshrMissLatency =
5094871SN/A        demandMshrMissLatency + SUM_NON_DEMAND(mshr_miss_latency);
5108833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
5118833Sdam.sunwoo@arm.com        overallMshrMissLatency.subname(i, system->getMasterName(i));
5128833Sdam.sunwoo@arm.com    }
5134626SN/A
5144626SN/A    // MSHR uncacheable statistics
5154626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
5164626SN/A        MemCmd cmd(access_idx);
5174626SN/A        const string &cstr = cmd.toString();
5184626SN/A
5194626SN/A        mshr_uncacheable[access_idx]
5208833Sdam.sunwoo@arm.com            .init(system->maxMasters())
5214626SN/A            .name(name() + "." + cstr + "_mshr_uncacheable")
5224626SN/A            .desc("number of " + cstr + " MSHR uncacheable")
5234626SN/A            .flags(total | nozero | nonan)
5244626SN/A            ;
5258833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
5268833Sdam.sunwoo@arm.com            mshr_uncacheable[access_idx].subname(i, system->getMasterName(i));
5278833Sdam.sunwoo@arm.com        }
5284626SN/A    }
5294626SN/A
5304626SN/A    overallMshrUncacheable
5314626SN/A        .name(name() + ".overall_mshr_uncacheable_misses")
5324626SN/A        .desc("number of overall MSHR uncacheable misses")
5338833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
5344626SN/A        ;
5354871SN/A    overallMshrUncacheable =
5364871SN/A        SUM_DEMAND(mshr_uncacheable) + SUM_NON_DEMAND(mshr_uncacheable);
5378833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
5388833Sdam.sunwoo@arm.com        overallMshrUncacheable.subname(i, system->getMasterName(i));
5398833Sdam.sunwoo@arm.com    }
5404626SN/A
5414626SN/A    // MSHR miss latency statistics
5424626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
5434626SN/A        MemCmd cmd(access_idx);
5444626SN/A        const string &cstr = cmd.toString();
5454626SN/A
5464626SN/A        mshr_uncacheable_lat[access_idx]
5478833Sdam.sunwoo@arm.com            .init(system->maxMasters())
5484626SN/A            .name(name() + "." + cstr + "_mshr_uncacheable_latency")
5494626SN/A            .desc("number of " + cstr + " MSHR uncacheable cycles")
5504626SN/A            .flags(total | nozero | nonan)
5514626SN/A            ;
5528833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
5538833Sdam.sunwoo@arm.com            mshr_uncacheable_lat[access_idx].subname(i, system->getMasterName(i));
5548833Sdam.sunwoo@arm.com        }
5554626SN/A    }
5564626SN/A
5574626SN/A    overallMshrUncacheableLatency
5584626SN/A        .name(name() + ".overall_mshr_uncacheable_latency")
5594626SN/A        .desc("number of overall MSHR uncacheable cycles")
5608833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
5614626SN/A        ;
5624871SN/A    overallMshrUncacheableLatency =
5634871SN/A        SUM_DEMAND(mshr_uncacheable_lat) +
5644871SN/A        SUM_NON_DEMAND(mshr_uncacheable_lat);
5658833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
5668833Sdam.sunwoo@arm.com        overallMshrUncacheableLatency.subname(i, system->getMasterName(i));
5678833Sdam.sunwoo@arm.com    }
5684626SN/A
5694626SN/A#if 0
5704626SN/A    // MSHR access formulas
5714626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
5724626SN/A        MemCmd cmd(access_idx);
5734626SN/A        const string &cstr = cmd.toString();
5744626SN/A
5754626SN/A        mshrAccesses[access_idx]
5764626SN/A            .name(name() + "." + cstr + "_mshr_accesses")
5774626SN/A            .desc("number of " + cstr + " mshr accesses(hits+misses)")
5784626SN/A            .flags(total | nozero | nonan)
5794626SN/A            ;
5804626SN/A        mshrAccesses[access_idx] =
5814626SN/A            mshr_hits[access_idx] + mshr_misses[access_idx]
5824626SN/A            + mshr_uncacheable[access_idx];
5834626SN/A    }
5844626SN/A
5854626SN/A    demandMshrAccesses
5864626SN/A        .name(name() + ".demand_mshr_accesses")
5874626SN/A        .desc("number of demand (read+write) mshr accesses")
5884626SN/A        .flags(total | nozero | nonan)
5894626SN/A        ;
5904626SN/A    demandMshrAccesses = demandMshrHits + demandMshrMisses;
5914626SN/A
5924626SN/A    overallMshrAccesses
5934626SN/A        .name(name() + ".overall_mshr_accesses")
5944626SN/A        .desc("number of overall (read+write) mshr accesses")
5954626SN/A        .flags(total | nozero | nonan)
5964626SN/A        ;
5974626SN/A    overallMshrAccesses = overallMshrHits + overallMshrMisses
5984626SN/A        + overallMshrUncacheable;
5994626SN/A#endif
6004626SN/A
6014626SN/A    // MSHR miss rate formulas
6024626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
6034626SN/A        MemCmd cmd(access_idx);
6044626SN/A        const string &cstr = cmd.toString();
6054626SN/A
6064626SN/A        mshrMissRate[access_idx]
6074626SN/A            .name(name() + "." + cstr + "_mshr_miss_rate")
6084626SN/A            .desc("mshr miss rate for " + cstr + " accesses")
6094626SN/A            .flags(total | nozero | nonan)
6104626SN/A            ;
6114626SN/A        mshrMissRate[access_idx] =
6124626SN/A            mshr_misses[access_idx] / accesses[access_idx];
6138833Sdam.sunwoo@arm.com
6148833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
6158833Sdam.sunwoo@arm.com            mshrMissRate[access_idx].subname(i, system->getMasterName(i));
6168833Sdam.sunwoo@arm.com        }
6174626SN/A    }
6184626SN/A
6194626SN/A    demandMshrMissRate
6204626SN/A        .name(name() + ".demand_mshr_miss_rate")
6214626SN/A        .desc("mshr miss rate for demand accesses")
6228833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
6234626SN/A        ;
6244626SN/A    demandMshrMissRate = demandMshrMisses / demandAccesses;
6258833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
6268833Sdam.sunwoo@arm.com        demandMshrMissRate.subname(i, system->getMasterName(i));
6278833Sdam.sunwoo@arm.com    }
6284626SN/A
6294626SN/A    overallMshrMissRate
6304626SN/A        .name(name() + ".overall_mshr_miss_rate")
6314626SN/A        .desc("mshr miss rate for overall accesses")
6328833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
6334626SN/A        ;
6344626SN/A    overallMshrMissRate = overallMshrMisses / overallAccesses;
6358833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
6368833Sdam.sunwoo@arm.com        overallMshrMissRate.subname(i, system->getMasterName(i));
6378833Sdam.sunwoo@arm.com    }
6384626SN/A
6394626SN/A    // mshrMiss latency formulas
6404626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
6414626SN/A        MemCmd cmd(access_idx);
6424626SN/A        const string &cstr = cmd.toString();
6434626SN/A
6444626SN/A        avgMshrMissLatency[access_idx]
6454626SN/A            .name(name() + "." + cstr + "_avg_mshr_miss_latency")
6464626SN/A            .desc("average " + cstr + " mshr miss latency")
6474626SN/A            .flags(total | nozero | nonan)
6484626SN/A            ;
6494626SN/A        avgMshrMissLatency[access_idx] =
6504626SN/A            mshr_miss_latency[access_idx] / mshr_misses[access_idx];
6518833Sdam.sunwoo@arm.com
6528833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
6538833Sdam.sunwoo@arm.com            avgMshrMissLatency[access_idx].subname(i, system->getMasterName(i));
6548833Sdam.sunwoo@arm.com        }
6554626SN/A    }
6564626SN/A
6574626SN/A    demandAvgMshrMissLatency
6584626SN/A        .name(name() + ".demand_avg_mshr_miss_latency")
6594626SN/A        .desc("average overall mshr miss latency")
6608833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
6614626SN/A        ;
6624626SN/A    demandAvgMshrMissLatency = demandMshrMissLatency / demandMshrMisses;
6638833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
6648833Sdam.sunwoo@arm.com        demandAvgMshrMissLatency.subname(i, system->getMasterName(i));
6658833Sdam.sunwoo@arm.com    }
6664626SN/A
6674626SN/A    overallAvgMshrMissLatency
6684626SN/A        .name(name() + ".overall_avg_mshr_miss_latency")
6694626SN/A        .desc("average overall mshr miss latency")
6708833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
6714626SN/A        ;
6724626SN/A    overallAvgMshrMissLatency = overallMshrMissLatency / overallMshrMisses;
6738833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
6748833Sdam.sunwoo@arm.com        overallAvgMshrMissLatency.subname(i, system->getMasterName(i));
6758833Sdam.sunwoo@arm.com    }
6764626SN/A
6774626SN/A    // mshrUncacheable latency formulas
6784626SN/A    for (int access_idx = 0; access_idx < MemCmd::NUM_MEM_CMDS; ++access_idx) {
6794626SN/A        MemCmd cmd(access_idx);
6804626SN/A        const string &cstr = cmd.toString();
6814626SN/A
6824626SN/A        avgMshrUncacheableLatency[access_idx]
6834626SN/A            .name(name() + "." + cstr + "_avg_mshr_uncacheable_latency")
6844626SN/A            .desc("average " + cstr + " mshr uncacheable latency")
6854626SN/A            .flags(total | nozero | nonan)
6864626SN/A            ;
6874626SN/A        avgMshrUncacheableLatency[access_idx] =
6884626SN/A            mshr_uncacheable_lat[access_idx] / mshr_uncacheable[access_idx];
6898833Sdam.sunwoo@arm.com
6908833Sdam.sunwoo@arm.com        for (int i = 0; i < system->maxMasters(); i++) {
6918833Sdam.sunwoo@arm.com            avgMshrUncacheableLatency[access_idx].subname(i, system->getMasterName(i));
6928833Sdam.sunwoo@arm.com        }
6934626SN/A    }
6944626SN/A
6954626SN/A    overallAvgMshrUncacheableLatency
6964626SN/A        .name(name() + ".overall_avg_mshr_uncacheable_latency")
6974626SN/A        .desc("average overall mshr uncacheable latency")
6988833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
6994626SN/A        ;
7004626SN/A    overallAvgMshrUncacheableLatency = overallMshrUncacheableLatency / overallMshrUncacheable;
7018833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
7028833Sdam.sunwoo@arm.com        overallAvgMshrUncacheableLatency.subname(i, system->getMasterName(i));
7038833Sdam.sunwoo@arm.com    }
7044626SN/A
7054626SN/A    mshr_cap_events
7068833Sdam.sunwoo@arm.com        .init(system->maxMasters())
7074626SN/A        .name(name() + ".mshr_cap_events")
7084626SN/A        .desc("number of times MSHR cap was activated")
7098833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
7104626SN/A        ;
7118833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
7128833Sdam.sunwoo@arm.com        mshr_cap_events.subname(i, system->getMasterName(i));
7138833Sdam.sunwoo@arm.com    }
7144626SN/A
7154626SN/A    //software prefetching stats
7164626SN/A    soft_prefetch_mshr_full
7178833Sdam.sunwoo@arm.com        .init(system->maxMasters())
7184626SN/A        .name(name() + ".soft_prefetch_mshr_full")
7194626SN/A        .desc("number of mshr full events for SW prefetching instrutions")
7208833Sdam.sunwoo@arm.com        .flags(total | nozero | nonan)
7214626SN/A        ;
7228833Sdam.sunwoo@arm.com    for (int i = 0; i < system->maxMasters(); i++) {
7238833Sdam.sunwoo@arm.com        soft_prefetch_mshr_full.subname(i, system->getMasterName(i));
7248833Sdam.sunwoo@arm.com    }
7254626SN/A
7264626SN/A    mshr_no_allocate_misses
7274626SN/A        .name(name() +".no_allocate_misses")
7284626SN/A        .desc("Number of misses that were no-allocate")
7294626SN/A        ;
7304626SN/A
7312810SN/A}
7323503SN/A
7333503SN/Aunsigned int
7343503SN/ABaseCache::drain(Event *de)
7353503SN/A{
7364626SN/A    int count = memSidePort->drain(de) + cpuSidePort->drain(de);
7374626SN/A
7383503SN/A    // Set status
7394626SN/A    if (count != 0) {
7403503SN/A        drainEvent = de;
7413503SN/A
7423503SN/A        changeState(SimObject::Draining);
7434626SN/A        return count;
7443503SN/A    }
7453503SN/A
7463503SN/A    changeState(SimObject::Drained);
7473503SN/A    return 0;
7483503SN/A}
749