sector_tags.hh revision 12752
112752Sodanrc@yahoo.com.br/* 212752Sodanrc@yahoo.com.br * Copyright (c) 2018 Inria 312752Sodanrc@yahoo.com.br * All rights reserved. 412752Sodanrc@yahoo.com.br * 512752Sodanrc@yahoo.com.br * Redistribution and use in source and binary forms, with or without 612752Sodanrc@yahoo.com.br * modification, are permitted provided that the following conditions are 712752Sodanrc@yahoo.com.br * met: redistributions of source code must retain the above copyright 812752Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer; 912752Sodanrc@yahoo.com.br * redistributions in binary form must reproduce the above copyright 1012752Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer in the 1112752Sodanrc@yahoo.com.br * documentation and/or other materials provided with the distribution; 1212752Sodanrc@yahoo.com.br * neither the name of the copyright holders nor the names of its 1312752Sodanrc@yahoo.com.br * contributors may be used to endorse or promote products derived from 1412752Sodanrc@yahoo.com.br * this software without specific prior written permission. 1512752Sodanrc@yahoo.com.br * 1612752Sodanrc@yahoo.com.br * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1712752Sodanrc@yahoo.com.br * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1812752Sodanrc@yahoo.com.br * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1912752Sodanrc@yahoo.com.br * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2012752Sodanrc@yahoo.com.br * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2112752Sodanrc@yahoo.com.br * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2212752Sodanrc@yahoo.com.br * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2312752Sodanrc@yahoo.com.br * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2412752Sodanrc@yahoo.com.br * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2512752Sodanrc@yahoo.com.br * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2612752Sodanrc@yahoo.com.br * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2712752Sodanrc@yahoo.com.br * 2812752Sodanrc@yahoo.com.br * Authors: Daniel Carvalho 2912752Sodanrc@yahoo.com.br */ 3012752Sodanrc@yahoo.com.br 3112752Sodanrc@yahoo.com.br/** 3212752Sodanrc@yahoo.com.br * @file 3312752Sodanrc@yahoo.com.br * Declaration of a sector set associative tag store. 3412752Sodanrc@yahoo.com.br */ 3512752Sodanrc@yahoo.com.br 3612752Sodanrc@yahoo.com.br#ifndef __MEM_CACHE_TAGS_SECTOR_TAGS_HH__ 3712752Sodanrc@yahoo.com.br#define __MEM_CACHE_TAGS_SECTOR_TAGS_HH__ 3812752Sodanrc@yahoo.com.br 3912752Sodanrc@yahoo.com.br#include <string> 4012752Sodanrc@yahoo.com.br#include <vector> 4112752Sodanrc@yahoo.com.br 4212752Sodanrc@yahoo.com.br#include "mem/cache/sector_blk.hh" 4312752Sodanrc@yahoo.com.br#include "mem/cache/tags/base.hh" 4412752Sodanrc@yahoo.com.br#include "mem/packet.hh" 4512752Sodanrc@yahoo.com.br#include "params/SectorTags.hh" 4612752Sodanrc@yahoo.com.br 4712752Sodanrc@yahoo.com.brclass BaseReplacementPolicy; 4812752Sodanrc@yahoo.com.br 4912752Sodanrc@yahoo.com.br/** 5012752Sodanrc@yahoo.com.br * A SectorTags cache tag store. 5112752Sodanrc@yahoo.com.br * @sa \ref gem5MemorySystem "gem5 Memory System" 5212752Sodanrc@yahoo.com.br * 5312752Sodanrc@yahoo.com.br * The SectorTags placement policy divides the cache into s sectors of w 5412752Sodanrc@yahoo.com.br * consecutive sectors (ways). Each sector then consists of a number of 5512752Sodanrc@yahoo.com.br * sequential cache lines that may or may not be present. 5612752Sodanrc@yahoo.com.br */ 5712752Sodanrc@yahoo.com.brclass SectorTags : public BaseTags 5812752Sodanrc@yahoo.com.br{ 5912752Sodanrc@yahoo.com.br protected: 6012752Sodanrc@yahoo.com.br /** Typedef the set type used in this tag store. */ 6112752Sodanrc@yahoo.com.br typedef std::vector<SectorBlk*> SetType; 6212752Sodanrc@yahoo.com.br 6312752Sodanrc@yahoo.com.br /** The associativity of the cache. */ 6412752Sodanrc@yahoo.com.br const unsigned assoc; 6512752Sodanrc@yahoo.com.br /** The allocatable associativity of the cache (alloc mask). */ 6612752Sodanrc@yahoo.com.br unsigned allocAssoc; 6712752Sodanrc@yahoo.com.br 6812752Sodanrc@yahoo.com.br /** Whether tags and data are accessed sequentially. */ 6912752Sodanrc@yahoo.com.br const bool sequentialAccess; 7012752Sodanrc@yahoo.com.br 7112752Sodanrc@yahoo.com.br /** Replacement policy */ 7212752Sodanrc@yahoo.com.br BaseReplacementPolicy *replacementPolicy; 7312752Sodanrc@yahoo.com.br 7412752Sodanrc@yahoo.com.br /** Number of data blocks per sector. */ 7512752Sodanrc@yahoo.com.br const unsigned numBlocksPerSector; 7612752Sodanrc@yahoo.com.br 7712752Sodanrc@yahoo.com.br /** The number of sectors in the cache. */ 7812752Sodanrc@yahoo.com.br const unsigned numSectors; 7912752Sodanrc@yahoo.com.br /** The number of sets in the cache. */ 8012752Sodanrc@yahoo.com.br const unsigned numSets; 8112752Sodanrc@yahoo.com.br 8212752Sodanrc@yahoo.com.br /** The cache blocks. */ 8312752Sodanrc@yahoo.com.br std::vector<SectorSubBlk> blks; 8412752Sodanrc@yahoo.com.br /** The cache sector blocks. */ 8512752Sodanrc@yahoo.com.br std::vector<SectorBlk> secBlks; 8612752Sodanrc@yahoo.com.br /** The cache sets. */ 8712752Sodanrc@yahoo.com.br std::vector<SetType> sets; 8812752Sodanrc@yahoo.com.br 8912752Sodanrc@yahoo.com.br // Organization of an address: Tag | Set # | Sector Offset # | Offset # 9012752Sodanrc@yahoo.com.br /** The amount to shift the address to get the sector tag. */ 9112752Sodanrc@yahoo.com.br const int sectorShift; 9212752Sodanrc@yahoo.com.br /** The amount to shift the address to get the set. */ 9312752Sodanrc@yahoo.com.br const int setShift; 9412752Sodanrc@yahoo.com.br /** The amount to shift the address to get the tag. */ 9512752Sodanrc@yahoo.com.br const int tagShift; 9612752Sodanrc@yahoo.com.br 9712752Sodanrc@yahoo.com.br /** Mask out all bits that aren't part of the sector tag. */ 9812752Sodanrc@yahoo.com.br const unsigned sectorMask; 9912752Sodanrc@yahoo.com.br /** Mask out all bits that aren't part of the set index. */ 10012752Sodanrc@yahoo.com.br const unsigned setMask; 10112752Sodanrc@yahoo.com.br 10212752Sodanrc@yahoo.com.br public: 10312752Sodanrc@yahoo.com.br /** Convenience typedef. */ 10412752Sodanrc@yahoo.com.br typedef SectorTagsParams Params; 10512752Sodanrc@yahoo.com.br 10612752Sodanrc@yahoo.com.br /** 10712752Sodanrc@yahoo.com.br * Construct and initialize this tag store. 10812752Sodanrc@yahoo.com.br */ 10912752Sodanrc@yahoo.com.br SectorTags(const Params *p); 11012752Sodanrc@yahoo.com.br 11112752Sodanrc@yahoo.com.br /** 11212752Sodanrc@yahoo.com.br * Destructor. 11312752Sodanrc@yahoo.com.br */ 11412752Sodanrc@yahoo.com.br virtual ~SectorTags() {}; 11512752Sodanrc@yahoo.com.br 11612752Sodanrc@yahoo.com.br /** 11712752Sodanrc@yahoo.com.br * This function updates the tags when a block is invalidated but does 11812752Sodanrc@yahoo.com.br * not invalidate the block itself. It also updates the replacement data. 11912752Sodanrc@yahoo.com.br * 12012752Sodanrc@yahoo.com.br * @param blk The block to invalidate. 12112752Sodanrc@yahoo.com.br */ 12212752Sodanrc@yahoo.com.br void invalidate(CacheBlk *blk) override; 12312752Sodanrc@yahoo.com.br 12412752Sodanrc@yahoo.com.br /** 12512752Sodanrc@yahoo.com.br * Access block and update replacement data. May not succeed, in which 12612752Sodanrc@yahoo.com.br * case nullptr is returned. This has all the implications of a cache 12712752Sodanrc@yahoo.com.br * access and should only be used as such. Returns the access latency 12812752Sodanrc@yahoo.com.br * as a side effect. 12912752Sodanrc@yahoo.com.br * 13012752Sodanrc@yahoo.com.br * @param addr The address to find. 13112752Sodanrc@yahoo.com.br * @param is_secure True if the target memory space is secure. 13212752Sodanrc@yahoo.com.br * @param lat The access latency. 13312752Sodanrc@yahoo.com.br * @return Pointer to the cache block if found. 13412752Sodanrc@yahoo.com.br */ 13512752Sodanrc@yahoo.com.br CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat) override; 13612752Sodanrc@yahoo.com.br 13712752Sodanrc@yahoo.com.br /** 13812752Sodanrc@yahoo.com.br * Find all possible block locations for insertion and replacement of 13912752Sodanrc@yahoo.com.br * an address. Should be called immediately before ReplacementPolicy's 14012752Sodanrc@yahoo.com.br * findVictim() not to break cache resizing. 14112752Sodanrc@yahoo.com.br * Returns sector blocks in all ways belonging to the set of the address. 14212752Sodanrc@yahoo.com.br * 14312752Sodanrc@yahoo.com.br * @param addr The addr to a find possible locations for. 14412752Sodanrc@yahoo.com.br * @return The possible locations. 14512752Sodanrc@yahoo.com.br */ 14612752Sodanrc@yahoo.com.br virtual const std::vector<SectorBlk*> getPossibleLocations(Addr addr) 14712752Sodanrc@yahoo.com.br const; 14812752Sodanrc@yahoo.com.br 14912752Sodanrc@yahoo.com.br /** 15012752Sodanrc@yahoo.com.br * Insert the new block into the cache and update replacement data. 15112752Sodanrc@yahoo.com.br * 15212752Sodanrc@yahoo.com.br * @param pkt Packet holding the address to update 15312752Sodanrc@yahoo.com.br * @param blk The block to update. 15412752Sodanrc@yahoo.com.br */ 15512752Sodanrc@yahoo.com.br void insertBlock(PacketPtr pkt, CacheBlk *blk) override; 15612752Sodanrc@yahoo.com.br 15712752Sodanrc@yahoo.com.br /** 15812752Sodanrc@yahoo.com.br * Finds the given address in the cache, do not update replacement data. 15912752Sodanrc@yahoo.com.br * i.e. This is a no-side-effect find of a block. 16012752Sodanrc@yahoo.com.br * 16112752Sodanrc@yahoo.com.br * @param addr The address to find. 16212752Sodanrc@yahoo.com.br * @param is_secure True if the target memory space is secure. 16312752Sodanrc@yahoo.com.br * @return Pointer to the cache block if found. 16412752Sodanrc@yahoo.com.br */ 16512752Sodanrc@yahoo.com.br CacheBlk* findBlock(Addr addr, bool is_secure) const override; 16612752Sodanrc@yahoo.com.br 16712752Sodanrc@yahoo.com.br /** 16812752Sodanrc@yahoo.com.br * Find a sector block given set and way. 16912752Sodanrc@yahoo.com.br * 17012752Sodanrc@yahoo.com.br * @param set The set of the block. 17112752Sodanrc@yahoo.com.br * @param way The way of the block. 17212752Sodanrc@yahoo.com.br * @return The block. 17312752Sodanrc@yahoo.com.br */ 17412752Sodanrc@yahoo.com.br ReplaceableEntry* findBlockBySetAndWay(int set, int way) const override; 17512752Sodanrc@yahoo.com.br 17612752Sodanrc@yahoo.com.br /** 17712752Sodanrc@yahoo.com.br * Find replacement victim based on address. 17812752Sodanrc@yahoo.com.br * 17912752Sodanrc@yahoo.com.br * @param addr Address to find a victim for. 18012752Sodanrc@yahoo.com.br * @param is_secure True if the target memory space is secure. 18112752Sodanrc@yahoo.com.br * @param evict_blks Cache blocks to be evicted. 18212752Sodanrc@yahoo.com.br * @return Cache block to be replaced. 18312752Sodanrc@yahoo.com.br */ 18412752Sodanrc@yahoo.com.br CacheBlk* findVictim(Addr addr, const bool is_secure, 18512752Sodanrc@yahoo.com.br std::vector<CacheBlk*>& evict_blks) const override; 18612752Sodanrc@yahoo.com.br 18712752Sodanrc@yahoo.com.br /** 18812752Sodanrc@yahoo.com.br * Generate the sector tag from the given address. 18912752Sodanrc@yahoo.com.br * 19012752Sodanrc@yahoo.com.br * @param addr The address to get the sector tag from. 19112752Sodanrc@yahoo.com.br * @return The sector tag of the address. 19212752Sodanrc@yahoo.com.br */ 19312752Sodanrc@yahoo.com.br Addr extractTag(Addr addr) const override; 19412752Sodanrc@yahoo.com.br 19512752Sodanrc@yahoo.com.br /** 19612752Sodanrc@yahoo.com.br * Calculate the set index from the address. 19712752Sodanrc@yahoo.com.br * 19812752Sodanrc@yahoo.com.br * @param addr The address to get the set from. 19912752Sodanrc@yahoo.com.br * @return The set index of the address. 20012752Sodanrc@yahoo.com.br */ 20112752Sodanrc@yahoo.com.br int extractSet(Addr addr) const; 20212752Sodanrc@yahoo.com.br 20312752Sodanrc@yahoo.com.br /** 20412752Sodanrc@yahoo.com.br * Calculate a block's offset in a sector from the address. 20512752Sodanrc@yahoo.com.br * 20612752Sodanrc@yahoo.com.br * @param addr The address to get the offset from. 20712752Sodanrc@yahoo.com.br * @return Offset of the corresponding block within its sector. 20812752Sodanrc@yahoo.com.br */ 20912752Sodanrc@yahoo.com.br int extractSectorOffset(Addr addr) const; 21012752Sodanrc@yahoo.com.br 21112752Sodanrc@yahoo.com.br /** 21212752Sodanrc@yahoo.com.br * Regenerate the block address from the tag and set. 21312752Sodanrc@yahoo.com.br * 21412752Sodanrc@yahoo.com.br * @param block The block. 21512752Sodanrc@yahoo.com.br * @return the block address. 21612752Sodanrc@yahoo.com.br */ 21712752Sodanrc@yahoo.com.br Addr regenerateBlkAddr(const CacheBlk* blk) const override; 21812752Sodanrc@yahoo.com.br 21912752Sodanrc@yahoo.com.br /** 22012752Sodanrc@yahoo.com.br * Visit each sub-block in the tags and apply a visitor. 22112752Sodanrc@yahoo.com.br * 22212752Sodanrc@yahoo.com.br * The visitor should be a std::function that takes a cache block. 22312752Sodanrc@yahoo.com.br * reference as its parameter. 22412752Sodanrc@yahoo.com.br * 22512752Sodanrc@yahoo.com.br * @param visitor Visitor to call on each block. 22612752Sodanrc@yahoo.com.br */ 22712752Sodanrc@yahoo.com.br void forEachBlk(std::function<void(CacheBlk &)> visitor) override; 22812752Sodanrc@yahoo.com.br 22912752Sodanrc@yahoo.com.br /** 23012752Sodanrc@yahoo.com.br * Find if any of the sub-blocks satisfies a condition. 23112752Sodanrc@yahoo.com.br * 23212752Sodanrc@yahoo.com.br * The visitor should be a std::function that takes a cache block 23312752Sodanrc@yahoo.com.br * reference as its parameter. The visitor will terminate the 23412752Sodanrc@yahoo.com.br * traversal early if the condition is satisfied. 23512752Sodanrc@yahoo.com.br * 23612752Sodanrc@yahoo.com.br * @param visitor Visitor to call on each block. 23712752Sodanrc@yahoo.com.br */ 23812752Sodanrc@yahoo.com.br bool anyBlk(std::function<bool(CacheBlk &)> visitor) override; 23912752Sodanrc@yahoo.com.br}; 24012752Sodanrc@yahoo.com.br 24112752Sodanrc@yahoo.com.br#endif //__MEM_CACHE_TAGS_SECTOR_TAGS_HH__ 242