iic.hh
来自「linux下基于c++的处理器仿真平台。具有处理器流水线」· HH 代码 · 共 576 行 · 第 1/2 页
HH
576 行
/* * Copyright (c) 2002, 2003, 2004, 2005 * The Regents of The University of Michigan * All Rights Reserved * * This code is part of the M5 simulator, developed by Nathan Binkert, * Erik Hallnor, Steve Raasch, and Steve Reinhardt, with contributions * from Ron Dreslinski, Dave Greene, Lisa Hsu, Kevin Lim, Ali Saidi, * and Andrew Schultz. * * Permission is granted to use, copy, create derivative works and * redistribute this software and such derivative works for any * purpose, so long as the copyright notice above, this grant of * permission, and the disclaimer below appear in all copies made; and * so long as the name of The University of Michigan is not used in * any advertising or publicity pertaining to the use or distribution * of this software without specific, written prior authorization. * * THIS SOFTWARE IS PROVIDED AS IS, WITHOUT REPRESENTATION FROM THE * UNIVERSITY OF MICHIGAN AS TO ITS FITNESS FOR ANY PURPOSE, AND * WITHOUT WARRANTY BY THE UNIVERSITY OF MICHIGAN OF ANY KIND, EITHER * EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE. THE REGENTS OF THE UNIVERSITY OF MICHIGAN SHALL NOT BE * LIABLE FOR ANY DAMAGES, INCLUDING DIRECT, SPECIAL, INDIRECT, * INCIDENTAL, OR CONSEQUENTIAL DAMAGES, WITH RESPECT TO ANY CLAIM * ARISING OUT OF OR IN CONNECTION WITH THE USE OF THE SOFTWARE, EVEN * IF IT HAS BEEN OR IS HEREAFTER ADVISED OF THE POSSIBILITY OF SUCH * DAMAGES. *//** * @file * Declaration of the Indirect Index Cache (IIC) tags store. */#ifndef __IIC_HH__#define __IIC_HH__#include <list>#include <vector>#include "mem/cache/cache_blk.hh"#include "mem/cache/tags/repl/repl.hh"#include "mem/mem_req.hh"#include "base/statistics.hh"#include "mem/cache/tags/base_tags.hh"class BaseCache; // Forward declaration/** * IIC cache blk. */class IICTag : public CacheBlk{ public: /** * Copy the contents of the given IICTag into this one. * @param rhs The tag to copy. * @return const reference to this tag. */ const IICTag& operator=(const IICTag& rhs) { CacheBlk::operator=(rhs); chain_ptr = rhs.chain_ptr; re = rhs.re; set = rhs.set; trivialData = rhs.trivialData; numData = rhs.numData; data_ptr.clear(); for (int i = 0; i < rhs.numData; ++i) { data_ptr.push_back(rhs.data_ptr[i]); } return *this; } /** Hash chain pointer into secondary store. */ unsigned long chain_ptr; /** Data array pointers for each subblock. */ std::vector<unsigned long> data_ptr; /** Replacement Entry pointer. */ void *re; /** * An array to store small compressed data. Conceputally the same size * as the unsused data array pointers. */ uint8_t *trivialData; /** * The number of allocated subblocks. */ int numData;};/** * A hash set for the IIC primary lookup table. */class IICSet{public: /** The associativity of the primary table. */ int assoc; /** The number of hash chains followed when finding the last block. */ int depth; /** The current number of blocks on the chain. */ int size; /** Tag pointer into the secondary tag storage. */ unsigned long chain_ptr; /** The LRU list of the primary table. MRU is at 0 index. */ IICTag ** tags; /** * Find the addr in this set, return the chain pointer to the secondary if * it isn't found. * @param asid The address space ID. * @param tag The address to find. * @param chain_ptr The chain pointer to start the search of the secondary * @return Pointer to the tag, NULL if not found. */ IICTag* findTag(int asid, Addr tag, unsigned long &chain_ptr) { depth = 1; for (int i = 0; i < assoc; ++i) { if (tags[i]->tag == tag && tags[i]->isValid()) { return tags[i]; } } chain_ptr = this->chain_ptr; return 0; } /** * Find an usused tag in this set. * @return Pointer to the unused tag, NULL if none are free. */ IICTag* findFree() { for (int i = 0; i < assoc; ++i) { if (!tags[i]->isValid()) { return tags[i]; } } return 0; } /** * Move a tag to the head of the LRU list * @param tag The tag to move. */ void moveToHead(IICTag *tag); /** * Move a tag to the tail (LRU) of the LRU list * @param tag The tag to move. */ void moveToTail(IICTag *tag);};/** * The IIC tag store. This is a hardware-realizable, fully-associative tag * store that uses software replacement, e.g. Gen. */class IIC : public BaseTags{ public: /** Typedef of the block type used in this class. */ typedef IICTag BlkType; /** Typedef for list of pointers to the local block type. */ typedef std::list<IICTag*> BlkList; protected: /** The number of set in the primary table. */ const int hashSets; /** The block size in bytes. */ const int blkSize; /** The associativity of the primary table. */ const int assoc; /** The base hit latency. */ const int hitLatency; /** The subblock size, used for compression. */ const int subSize; /** The number of subblocks */ const int numSub; /** The number of bytes used by data pointers */ const int trivialSize; /** The amount to shift address to get the tag. */ const int tagShift; /** The mask to get block offset bits. */ const unsigned blkMask; /** The amount to shift to get the subblock number. */ const int subShift; /** The mask to get the correct subblock number. */ const unsigned subMask; /** The latency of a hash lookup. */ const int hashDelay; /** The number of data blocks. */ const int numBlocks; /** The total number of tags in primary and secondary. */ const int numTags; /** The number of tags in the secondary tag store. */ const int numSecondary; /** The Null tag pointer. */ const int tagNull; /** The last tag in the primary table. */ const int primaryBound; /** All of the tags */ IICTag *tagStore; /** * Pointer to the head of the secondary freelist (maintained with chain * pointers. */ unsigned long freelist; /** * The data block freelist. */ std::list<unsigned long> blkFreelist; /** The primary table. */ IICSet *sets; /** The replacement policy. */ Repl *repl; /** An array of data reference counters. */ int *dataReferenceCount; /** The data blocks. */ uint8_t *dataStore; /** Storage for the fast access data of each cache block. */ uint8_t **dataBlks; /** * Count of the current number of free secondary tags. * Used for debugging. */ int freeSecond; // IIC Statistics /** * @addtogroup IICStatistics IIC Statistics * @{ */ /** Hash hit depth of cache hits. */ Stats::Distribution<> hitHashDepth; /** Hash depth for cache misses. */ Stats::Distribution<> missHashDepth; /** Count of accesses to each hash set. */ Stats::Distribution<> setAccess; /** The total hash depth for every miss. */ Stats::Scalar<> missDepthTotal; /** The total hash depth for all hits. */ Stats::Scalar<> hitDepthTotal; /** The number of hash misses. */ Stats::Scalar<> hashMiss; /** The number of hash hits. */ Stats::Scalar<> hashHit; /** @} */ public: /** * Collection of parameters for the IIC. */ class Params { public: /** The size in bytes of the cache. */ int size; /** The number of sets in the primary table. */ int numSets; /** The block size in bytes. */ int blkSize; /** The associativity of the primary table. */ int assoc; /** The number of cycles for each hash lookup. */ int hashDelay; /** The number of cycles to read the data. */ int hitLatency; /** The replacement policy. */ Repl *rp; /** The subblock size in bytes. */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?