base.hh revision 10693
11689SN/A/* 22326SN/A * Copyright (c) 2012-2013 ARM Limited 31689SN/A * All rights reserved. 41689SN/A * 51689SN/A * The license below extends only to copyright in the software and shall 61689SN/A * not be construed as granting a license to any other intellectual 71689SN/A * property including but not limited to intellectual property relating 81689SN/A * to a hardware implementation of the functionality of the software 91689SN/A * licensed hereunder. You may use the software subject to the license 101689SN/A * terms below provided that you ensure that this notice is replicated 111689SN/A * unmodified and in its entirety in all distributions of the software, 121689SN/A * modified or unmodified, in source code or in binary form. 131689SN/A * 141689SN/A * Copyright (c) 2003-2005 The Regents of The University of Michigan 151689SN/A * All rights reserved. 161689SN/A * 171689SN/A * Redistribution and use in source and binary forms, with or without 181689SN/A * modification, are permitted provided that the following conditions are 191689SN/A * met: redistributions of source code must retain the above copyright 201689SN/A * notice, this list of conditions and the following disclaimer; 211689SN/A * redistributions in binary form must reproduce the above copyright 221689SN/A * notice, this list of conditions and the following disclaimer in the 231689SN/A * documentation and/or other materials provided with the distribution; 241689SN/A * neither the name of the copyright holders nor the names of its 251689SN/A * contributors may be used to endorse or promote products derived from 261689SN/A * this software without specific prior written permission. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 291689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 301689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 312292SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 322292SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 331060SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 341060SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 351060SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 361461SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 371060SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382292SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 391717SN/A * 402292SN/A * Authors: Erik Hallnor 412292SN/A * Ron Dreslinski 421060SN/A */ 432292SN/A 442292SN/A/** 452292SN/A * @file 462326SN/A * Declaration of a common base class for cache tagstore objects. 472326SN/A */ 482326SN/A 492326SN/A#ifndef __BASE_TAGS_HH__ 502326SN/A#define __BASE_TAGS_HH__ 512292SN/A 522326SN/A#include <string> 532326SN/A 542326SN/A#include "base/callback.hh" 552326SN/A#include "base/statistics.hh" 562326SN/A#include "params/BaseTags.hh" 572326SN/A#include "sim/clocked_object.hh" 582326SN/A 592326SN/Aclass BaseCache; 602326SN/A 612326SN/A/** 622326SN/A * A common base class of Cache tagstore objects. 632292SN/A */ 641681SN/Aclass BaseTags : public ClockedObject 652292SN/A{ 661060SN/A protected: 671060SN/A /** The block size of the cache. */ 681060SN/A const unsigned blkSize; 691061SN/A /** The size of the cache. */ 701061SN/A const unsigned size; 711060SN/A /** The access latency of the cache. */ 721060SN/A const Cycles accessLatency; 731060SN/A /** Pointer to the parent cache. */ 741681SN/A BaseCache *cache; 751061SN/A 762292SN/A /** 771060SN/A * The number of tags that need to be touched to meet the warmup 781061SN/A * percentage. 791061SN/A */ 801061SN/A int warmupBound; 811061SN/A /** Marked true when the cache is warmed up. */ 821060SN/A bool warmedUp; 831681SN/A 842292SN/A /** the number of blocks in the cache */ 852292SN/A unsigned numBlocks; 861060SN/A 872292SN/A // Statistics 882292SN/A /** 892292SN/A * @addtogroup CacheStatistics 901060SN/A * @{ 912292SN/A */ 922292SN/A 932292SN/A /** Number of replacements of valid blocks per thread. */ 942292SN/A Stats::Vector replacements; 952292SN/A /** Per cycle average of the number of tags that hold valid data. */ 962292SN/A Stats::Average tagsInUse; 971060SN/A 981060SN/A /** The total number of references to a block before it is replaced. */ 991060SN/A Stats::Scalar totalRefs; 1002292SN/A 1011060SN/A /** 1021060SN/A * The number of reference counts sampled. This is different from 1031060SN/A * replacements because we sample all the valid blocks when the simulator 1041060SN/A * exits. 1051060SN/A */ 1062292SN/A Stats::Scalar sampledRefs; 1071060SN/A 1082292SN/A /** 1092292SN/A * Average number of references to a block before is was replaced. 1102292SN/A * @todo This should change to an average stat once we have them. 1112292SN/A */ 1122292SN/A Stats::Formula avgRefs; 1132292SN/A 1141060SN/A /** The cycle that the warmup percentage was hit. */ 1151060SN/A Stats::Scalar warmupCycle; 1162292SN/A 1172292SN/A /** Average occupancy of each requestor using the cache */ 1181060SN/A Stats::AverageVector occupancies; 1192292SN/A 1202292SN/A /** Average occ % of each requestor using the cache */ 1211062SN/A Stats::Formula avgOccs; 1222292SN/A 1232632Sstever@eecs.umich.edu /** Occupancy of each context/cpu using the cache */ 1242632Sstever@eecs.umich.edu Stats::Vector occupanciesTaskId; 1252292SN/A 1262292SN/A /** Occupancy of each context/cpu using the cache */ 1272292SN/A Stats::Vector2d ageTaskId; 1282292SN/A 1292632Sstever@eecs.umich.edu /** Occ % of each context/cpu using the cache */ 1302632Sstever@eecs.umich.edu Stats::Formula percentOccsTaskId; 1312292SN/A 1322632Sstever@eecs.umich.edu /** Number of tags consulted over all accesses. */ 1332632Sstever@eecs.umich.edu Stats::Scalar tagAccesses; 1342292SN/A /** Number of data blocks consulted over all accesses. */ 1352632Sstever@eecs.umich.edu Stats::Scalar dataAccesses; 1362632Sstever@eecs.umich.edu 1372292SN/A /** 1382632Sstever@eecs.umich.edu * @} 1392632Sstever@eecs.umich.edu */ 1402292SN/A 1412292SN/A public: 1422632Sstever@eecs.umich.edu typedef BaseTagsParams Params; 1432292SN/A BaseTags(const Params *p); 1442292SN/A 1452632Sstever@eecs.umich.edu /** 1462348SN/A * Destructor. 1472307SN/A */ 1482632Sstever@eecs.umich.edu virtual ~BaseTags() {} 1492348SN/A 1502316SN/A /** 1512632Sstever@eecs.umich.edu * Set the parent cache back pointer. 1522348SN/A * @param _cache Pointer to parent cache. 1532307SN/A */ 1542632Sstever@eecs.umich.edu void setCache(BaseCache *_cache); 1552348SN/A 1562307SN/A /** 1572632Sstever@eecs.umich.edu * Register local statistics. 1582292SN/A */ 1592292SN/A void regStats(); 1602107SN/A 1612292SN/A /** 1622632Sstever@eecs.umich.edu * Average in the reference count for valid blocks when the simulation 1632632Sstever@eecs.umich.edu * exits. 1642292SN/A */ 1652292SN/A virtual void cleanupRefs() {} 1662292SN/A 1672292SN/A /** 1682292SN/A * Computes stats just prior to dump event 1692292SN/A */ 1702292SN/A virtual void computeStats() {} 1712292SN/A 1722292SN/A /** 1732632Sstever@eecs.umich.edu *iterated through all blocks and clear all locks 1742632Sstever@eecs.umich.edu *Needed to clear all lock tracking at once 1752292SN/A */ 1762292SN/A virtual void clearLocks() {} 1772292SN/A 1782292SN/A /** 1792292SN/A * Print all tags used 1802292SN/A */ 1812292SN/A virtual std::string print() const = 0; 1822292SN/A}; 1832292SN/A 1842292SN/Aclass BaseTagsCallback : public Callback 1852292SN/A{ 1862292SN/A BaseTags *tags; 1872292SN/A public: 1882292SN/A BaseTagsCallback(BaseTags *t) : tags(t) {} 1892292SN/A virtual void process() { tags->cleanupRefs(); }; 1902292SN/A}; 1912292SN/A 1922292SN/Aclass BaseTagsDumpCallback : public Callback 1932292SN/A{ 1942292SN/A BaseTags *tags; 1952292SN/A public: 1962292SN/A BaseTagsDumpCallback(BaseTags *t) : tags(t) {} 1972292SN/A virtual void process() { tags->computeStats(); }; 1982292SN/A}; 1992292SN/A 2002292SN/A#endif //__BASE_TAGS_HH__ 2012292SN/A