base.cc revision 11722
16145Snate@binkert.org/*
26239Snate@binkert.org * Copyright (c) 2013 ARM Limited
36239Snate@binkert.org * All rights reserved.
46145Snate@binkert.org *
56239Snate@binkert.org * The license below extends only to copyright in the software and shall
66239Snate@binkert.org * not be construed as granting a license to any other intellectual
76239Snate@binkert.org * property including but not limited to intellectual property relating
86239Snate@binkert.org * to a hardware implementation of the functionality of the software
96239Snate@binkert.org * licensed hereunder.  You may use the software subject to the license
106239Snate@binkert.org * terms below provided that you ensure that this notice is replicated
116239Snate@binkert.org * unmodified and in its entirety in all distributions of the software,
126239Snate@binkert.org * modified or unmodified, in source code or in binary form.
136239Snate@binkert.org *
146239Snate@binkert.org * Copyright (c) 2003-2005 The Regents of The University of Michigan
156145Snate@binkert.org * All rights reserved.
166239Snate@binkert.org *
176239Snate@binkert.org * Redistribution and use in source and binary forms, with or without
186239Snate@binkert.org * modification, are permitted provided that the following conditions are
196239Snate@binkert.org * met: redistributions of source code must retain the above copyright
206239Snate@binkert.org * notice, this list of conditions and the following disclaimer;
216239Snate@binkert.org * redistributions in binary form must reproduce the above copyright
226239Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
236239Snate@binkert.org * documentation and/or other materials provided with the distribution;
246239Snate@binkert.org * neither the name of the copyright holders nor the names of its
256239Snate@binkert.org * contributors may be used to endorse or promote products derived from
266239Snate@binkert.org * this software without specific prior written permission.
276145Snate@binkert.org *
286145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
297039Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
307039Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
316145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
328091Snilay@cs.wisc.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
336145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
347002Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
357002Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
368608Snilay@cs.wisc.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
376145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
386145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
396145Snate@binkert.org *
406145Snate@binkert.org * Authors: Erik Hallnor
416145Snate@binkert.org *          Ron Dreslinski
426145Snate@binkert.org */
436145Snate@binkert.org
447039Snate@binkert.org/**
457039Snate@binkert.org * @file
467039Snate@binkert.org * Definitions of BaseTags.
477039Snate@binkert.org */
487039Snate@binkert.org
497039Snate@binkert.org#include "mem/cache/tags/base.hh"
506145Snate@binkert.org
517039Snate@binkert.org#include "cpu/smt.hh" //maxThreadsPerCPU
527039Snate@binkert.org#include "mem/cache/base.hh"
537039Snate@binkert.org#include "sim/sim_exit.hh"
547039Snate@binkert.org
556145Snate@binkert.orgusing namespace std;
567039Snate@binkert.org
577039Snate@binkert.orgBaseTags::BaseTags(const Params *p)
586145Snate@binkert.org    : ClockedObject(p), blkSize(p->block_size), size(p->size),
597039Snate@binkert.org      lookupLatency(p->tag_latency),
607039Snate@binkert.org      accessLatency(p->sequential_access ?
617039Snate@binkert.org                    p->tag_latency + p->data_latency :
627039Snate@binkert.org                    std::max(p->tag_latency, p->data_latency)),
637039Snate@binkert.org      cache(nullptr), warmupBound(0),
647039Snate@binkert.org      warmedUp(false), numBlocks(0)
657039Snate@binkert.org{
667039Snate@binkert.org}
676145Snate@binkert.org
688091Snilay@cs.wisc.eduvoid
698091Snilay@cs.wisc.eduBaseTags::setCache(BaseCache *_cache)
708091Snilay@cs.wisc.edu{
718091Snilay@cs.wisc.edu    assert(!cache);
726145Snate@binkert.org    cache = _cache;
737039Snate@binkert.org}
747039Snate@binkert.org
756145Snate@binkert.orgvoid
767039Snate@binkert.orgBaseTags::regStats()
776145Snate@binkert.org{
787055Snate@binkert.org    ClockedObject::regStats();
797055Snate@binkert.org
807055Snate@binkert.org    using namespace Stats;
816145Snate@binkert.org
827039Snate@binkert.org    replacements
837039Snate@binkert.org        .init(maxThreadsPerCPU)
847039Snate@binkert.org        .name(name() + ".replacements")
857039Snate@binkert.org        .desc("number of replacements")
867039Snate@binkert.org        .flags(total)
877039Snate@binkert.org        ;
887039Snate@binkert.org
897039Snate@binkert.org    tagsInUse
907039Snate@binkert.org        .name(name() + ".tagsinuse")
917039Snate@binkert.org        .desc("Cycle average of tags in use")
926145Snate@binkert.org        ;
936145Snate@binkert.org
947039Snate@binkert.org    totalRefs
957039Snate@binkert.org        .name(name() + ".total_refs")
966145Snate@binkert.org        .desc("Total number of references to valid blocks.")
977039Snate@binkert.org        ;
987039Snate@binkert.org
997039Snate@binkert.org    sampledRefs
1006145Snate@binkert.org        .name(name() + ".sampled_refs")
1016145Snate@binkert.org        .desc("Sample count of references to valid blocks.")
1027039Snate@binkert.org        ;
1037039Snate@binkert.org
1046145Snate@binkert.org    avgRefs
1057039Snate@binkert.org        .name(name() + ".avg_refs")
1066145Snate@binkert.org        .desc("Average number of references to valid blocks.")
1076145Snate@binkert.org        ;
1087055Snate@binkert.org
1097055Snate@binkert.org    avgRefs = totalRefs/sampledRefs;
1106145Snate@binkert.org
1117039Snate@binkert.org    warmupCycle
1127055Snate@binkert.org        .name(name() + ".warmup_cycle")
1137039Snate@binkert.org        .desc("Cycle when the warmup percentage was hit.")
1146145Snate@binkert.org        ;
1156145Snate@binkert.org
1167039Snate@binkert.org    occupancies
1177039Snate@binkert.org        .init(cache->system->maxMasters())
1186145Snate@binkert.org        .name(name() + ".occ_blocks")
1197039Snate@binkert.org        .desc("Average occupied blocks per requestor")
1206145Snate@binkert.org        .flags(nozero | nonan)
1216145Snate@binkert.org        ;
1227039Snate@binkert.org    for (int i = 0; i < cache->system->maxMasters(); i++) {
1237039Snate@binkert.org        occupancies.subname(i, cache->system->getMasterName(i));
1246145Snate@binkert.org    }
1257039Snate@binkert.org
1267039Snate@binkert.org    avgOccs
1276145Snate@binkert.org        .name(name() + ".occ_percent")
1287039Snate@binkert.org        .desc("Average percentage of cache occupancy")
1297039Snate@binkert.org        .flags(nozero | total)
1307039Snate@binkert.org        ;
1317039Snate@binkert.org    for (int i = 0; i < cache->system->maxMasters(); i++) {
1327039Snate@binkert.org        avgOccs.subname(i, cache->system->getMasterName(i));
1337039Snate@binkert.org    }
1347039Snate@binkert.org
1357039Snate@binkert.org    avgOccs = occupancies / Stats::constant(numBlocks);
1367039Snate@binkert.org
1377039Snate@binkert.org    occupanciesTaskId
1387039Snate@binkert.org        .init(ContextSwitchTaskId::NumTaskId)
1397039Snate@binkert.org        .name(name() + ".occ_task_id_blocks")
1407039Snate@binkert.org        .desc("Occupied blocks per task id")
1417039Snate@binkert.org        .flags(nozero | nonan)
1427039Snate@binkert.org        ;
1436145Snate@binkert.org
1446145Snate@binkert.org    ageTaskId
1457027SBrad.Beckmann@amd.com        .init(ContextSwitchTaskId::NumTaskId, 5)
1467039Snate@binkert.org        .name(name() + ".age_task_id_blocks")
1477039Snate@binkert.org        .desc("Occupied blocks per task id")
1487027SBrad.Beckmann@amd.com        .flags(nozero | nonan)
1497027SBrad.Beckmann@amd.com        ;
1507027SBrad.Beckmann@amd.com
1517054Snate@binkert.org    percentOccsTaskId
1527027SBrad.Beckmann@amd.com        .name(name() + ".occ_task_id_percent")
1537027SBrad.Beckmann@amd.com        .desc("Percentage of cache occupancy per task id")
1547027SBrad.Beckmann@amd.com        .flags(nozero)
1557027SBrad.Beckmann@amd.com        ;
1567027SBrad.Beckmann@amd.com
1577027SBrad.Beckmann@amd.com    percentOccsTaskId = occupanciesTaskId / Stats::constant(numBlocks);
1587027SBrad.Beckmann@amd.com
1597027SBrad.Beckmann@amd.com    tagAccesses
1607027SBrad.Beckmann@amd.com        .name(name() + ".tag_accesses")
1617027SBrad.Beckmann@amd.com        .desc("Number of tag accesses")
1627027SBrad.Beckmann@amd.com        ;
1637027SBrad.Beckmann@amd.com
1647027SBrad.Beckmann@amd.com    dataAccesses
1657027SBrad.Beckmann@amd.com        .name(name() + ".data_accesses")
1667027SBrad.Beckmann@amd.com        .desc("Number of data accesses")
1677563SBrad.Beckmann@amd.com        ;
1687027SBrad.Beckmann@amd.com
1697027SBrad.Beckmann@amd.com    registerDumpCallback(new BaseTagsDumpCallback(this));
1707027SBrad.Beckmann@amd.com    registerExitCallback(new BaseTagsCallback(this));
1717027SBrad.Beckmann@amd.com}
1727039Snate@binkert.org