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 3313219Sodanrc@yahoo.com.br * Declaration of a sector 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 3913941Sodanrc@yahoo.com.br#include <cstdint> 4012752Sodanrc@yahoo.com.br#include <string> 4112752Sodanrc@yahoo.com.br#include <vector> 4212752Sodanrc@yahoo.com.br 4312752Sodanrc@yahoo.com.br#include "mem/cache/tags/base.hh" 4413224Sodanrc@yahoo.com.br#include "mem/cache/tags/sector_blk.hh" 4513752Sodanrc@yahoo.com.br#include "mem/packet.hh" 4612752Sodanrc@yahoo.com.br#include "params/SectorTags.hh" 4712752Sodanrc@yahoo.com.br 4812752Sodanrc@yahoo.com.brclass BaseReplacementPolicy; 4912773Sodanrc@yahoo.com.brclass ReplaceableEntry; 5012752Sodanrc@yahoo.com.br 5112752Sodanrc@yahoo.com.br/** 5212752Sodanrc@yahoo.com.br * A SectorTags cache tag store. 5312752Sodanrc@yahoo.com.br * @sa \ref gem5MemorySystem "gem5 Memory System" 5412752Sodanrc@yahoo.com.br * 5512752Sodanrc@yahoo.com.br * The SectorTags placement policy divides the cache into s sectors of w 5612752Sodanrc@yahoo.com.br * consecutive sectors (ways). Each sector then consists of a number of 5712752Sodanrc@yahoo.com.br * sequential cache lines that may or may not be present. 5812752Sodanrc@yahoo.com.br */ 5912752Sodanrc@yahoo.com.brclass SectorTags : public BaseTags 6012752Sodanrc@yahoo.com.br{ 6113938Sodanrc@yahoo.com.br private: 6213938Sodanrc@yahoo.com.br /** The cache blocks. */ 6313938Sodanrc@yahoo.com.br std::vector<SectorSubBlk> blks; 6413938Sodanrc@yahoo.com.br /** The cache sector blocks. */ 6513938Sodanrc@yahoo.com.br std::vector<SectorBlk> secBlks; 6613938Sodanrc@yahoo.com.br 6712752Sodanrc@yahoo.com.br protected: 6812752Sodanrc@yahoo.com.br /** The allocatable associativity of the cache (alloc mask). */ 6912752Sodanrc@yahoo.com.br unsigned allocAssoc; 7012752Sodanrc@yahoo.com.br 7112752Sodanrc@yahoo.com.br /** Whether tags and data are accessed sequentially. */ 7212752Sodanrc@yahoo.com.br const bool sequentialAccess; 7312752Sodanrc@yahoo.com.br 7412752Sodanrc@yahoo.com.br /** Replacement policy */ 7512752Sodanrc@yahoo.com.br BaseReplacementPolicy *replacementPolicy; 7612752Sodanrc@yahoo.com.br 7712752Sodanrc@yahoo.com.br /** Number of data blocks per sector. */ 7812752Sodanrc@yahoo.com.br const unsigned numBlocksPerSector; 7912752Sodanrc@yahoo.com.br 8012752Sodanrc@yahoo.com.br /** The number of sectors in the cache. */ 8112752Sodanrc@yahoo.com.br const unsigned numSectors; 8212752Sodanrc@yahoo.com.br 8313219Sodanrc@yahoo.com.br // Organization of an address: 8413219Sodanrc@yahoo.com.br // Tag | Placement Location | Sector Offset # | Offset # 8512752Sodanrc@yahoo.com.br /** The amount to shift the address to get the sector tag. */ 8612752Sodanrc@yahoo.com.br const int sectorShift; 8712752Sodanrc@yahoo.com.br 8812752Sodanrc@yahoo.com.br /** Mask out all bits that aren't part of the sector tag. */ 8912752Sodanrc@yahoo.com.br const unsigned sectorMask; 9013217Sodanrc@yahoo.com.br 9112752Sodanrc@yahoo.com.br public: 9212752Sodanrc@yahoo.com.br /** Convenience typedef. */ 9312752Sodanrc@yahoo.com.br typedef SectorTagsParams Params; 9412752Sodanrc@yahoo.com.br 9512752Sodanrc@yahoo.com.br /** 9612752Sodanrc@yahoo.com.br * Construct and initialize this tag store. 9712752Sodanrc@yahoo.com.br */ 9812752Sodanrc@yahoo.com.br SectorTags(const Params *p); 9912752Sodanrc@yahoo.com.br 10012752Sodanrc@yahoo.com.br /** 10112752Sodanrc@yahoo.com.br * Destructor. 10212752Sodanrc@yahoo.com.br */ 10312752Sodanrc@yahoo.com.br virtual ~SectorTags() {}; 10412752Sodanrc@yahoo.com.br 10512752Sodanrc@yahoo.com.br /** 10613419Sodanrc@yahoo.com.br * Initialize blocks as SectorBlk and SectorSubBlk instances. 10713216Sodanrc@yahoo.com.br */ 10813419Sodanrc@yahoo.com.br void tagsInit() override; 10913216Sodanrc@yahoo.com.br 11013216Sodanrc@yahoo.com.br /** 11112752Sodanrc@yahoo.com.br * This function updates the tags when a block is invalidated but does 11212752Sodanrc@yahoo.com.br * not invalidate the block itself. It also updates the replacement data. 11312752Sodanrc@yahoo.com.br * 11412752Sodanrc@yahoo.com.br * @param blk The block to invalidate. 11512752Sodanrc@yahoo.com.br */ 11612752Sodanrc@yahoo.com.br void invalidate(CacheBlk *blk) override; 11712752Sodanrc@yahoo.com.br 11812752Sodanrc@yahoo.com.br /** 11912752Sodanrc@yahoo.com.br * Access block and update replacement data. May not succeed, in which 12012752Sodanrc@yahoo.com.br * case nullptr is returned. This has all the implications of a cache 12113418Sodanrc@yahoo.com.br * access and should only be used as such. Returns the tag lookup latency 12212752Sodanrc@yahoo.com.br * as a side effect. 12312752Sodanrc@yahoo.com.br * 12412752Sodanrc@yahoo.com.br * @param addr The address to find. 12512752Sodanrc@yahoo.com.br * @param is_secure True if the target memory space is secure. 12613418Sodanrc@yahoo.com.br * @param lat The latency of the tag lookup. 12712752Sodanrc@yahoo.com.br * @return Pointer to the cache block if found. 12812752Sodanrc@yahoo.com.br */ 12912752Sodanrc@yahoo.com.br CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat) override; 13012752Sodanrc@yahoo.com.br 13112752Sodanrc@yahoo.com.br /** 13212752Sodanrc@yahoo.com.br * Insert the new block into the cache and update replacement data. 13312752Sodanrc@yahoo.com.br * 13413752Sodanrc@yahoo.com.br * @param pkt Packet holding the address to update 13512752Sodanrc@yahoo.com.br * @param blk The block to update. 13612752Sodanrc@yahoo.com.br */ 13713752Sodanrc@yahoo.com.br void insertBlock(const PacketPtr pkt, CacheBlk *blk) override; 13812752Sodanrc@yahoo.com.br 13912752Sodanrc@yahoo.com.br /** 14012752Sodanrc@yahoo.com.br * Finds the given address in the cache, do not update replacement data. 14112752Sodanrc@yahoo.com.br * i.e. This is a no-side-effect find of a block. 14212752Sodanrc@yahoo.com.br * 14312752Sodanrc@yahoo.com.br * @param addr The address to find. 14412752Sodanrc@yahoo.com.br * @param is_secure True if the target memory space is secure. 14512752Sodanrc@yahoo.com.br * @return Pointer to the cache block if found. 14612752Sodanrc@yahoo.com.br */ 14712752Sodanrc@yahoo.com.br CacheBlk* findBlock(Addr addr, bool is_secure) const override; 14812752Sodanrc@yahoo.com.br 14912752Sodanrc@yahoo.com.br /** 15012752Sodanrc@yahoo.com.br * Find replacement victim based on address. 15112752Sodanrc@yahoo.com.br * 15212752Sodanrc@yahoo.com.br * @param addr Address to find a victim for. 15312752Sodanrc@yahoo.com.br * @param is_secure True if the target memory space is secure. 15413941Sodanrc@yahoo.com.br * @param size Size, in bits, of new block to allocate. 15512752Sodanrc@yahoo.com.br * @param evict_blks Cache blocks to be evicted. 15612752Sodanrc@yahoo.com.br * @return Cache block to be replaced. 15712752Sodanrc@yahoo.com.br */ 15812752Sodanrc@yahoo.com.br CacheBlk* findVictim(Addr addr, const bool is_secure, 15913941Sodanrc@yahoo.com.br const std::size_t size, 16012752Sodanrc@yahoo.com.br std::vector<CacheBlk*>& evict_blks) const override; 16112752Sodanrc@yahoo.com.br 16212752Sodanrc@yahoo.com.br /** 16312752Sodanrc@yahoo.com.br * Calculate a block's offset in a sector from the address. 16412752Sodanrc@yahoo.com.br * 16512752Sodanrc@yahoo.com.br * @param addr The address to get the offset from. 16612752Sodanrc@yahoo.com.br * @return Offset of the corresponding block within its sector. 16712752Sodanrc@yahoo.com.br */ 16812752Sodanrc@yahoo.com.br int extractSectorOffset(Addr addr) const; 16912752Sodanrc@yahoo.com.br 17012752Sodanrc@yahoo.com.br /** 17113219Sodanrc@yahoo.com.br * Regenerate the block address from the tag and location. 17212752Sodanrc@yahoo.com.br * 17312752Sodanrc@yahoo.com.br * @param block The block. 17412752Sodanrc@yahoo.com.br * @return the block address. 17512752Sodanrc@yahoo.com.br */ 17612752Sodanrc@yahoo.com.br Addr regenerateBlkAddr(const CacheBlk* blk) const override; 17712752Sodanrc@yahoo.com.br 17812752Sodanrc@yahoo.com.br /** 17912752Sodanrc@yahoo.com.br * Visit each sub-block in the tags and apply a visitor. 18012752Sodanrc@yahoo.com.br * 18112752Sodanrc@yahoo.com.br * The visitor should be a std::function that takes a cache block. 18212752Sodanrc@yahoo.com.br * reference as its parameter. 18312752Sodanrc@yahoo.com.br * 18412752Sodanrc@yahoo.com.br * @param visitor Visitor to call on each block. 18512752Sodanrc@yahoo.com.br */ 18612752Sodanrc@yahoo.com.br void forEachBlk(std::function<void(CacheBlk &)> visitor) override; 18712752Sodanrc@yahoo.com.br 18812752Sodanrc@yahoo.com.br /** 18912752Sodanrc@yahoo.com.br * Find if any of the sub-blocks satisfies a condition. 19012752Sodanrc@yahoo.com.br * 19112752Sodanrc@yahoo.com.br * The visitor should be a std::function that takes a cache block 19212752Sodanrc@yahoo.com.br * reference as its parameter. The visitor will terminate the 19312752Sodanrc@yahoo.com.br * traversal early if the condition is satisfied. 19412752Sodanrc@yahoo.com.br * 19512752Sodanrc@yahoo.com.br * @param visitor Visitor to call on each block. 19612752Sodanrc@yahoo.com.br */ 19712752Sodanrc@yahoo.com.br bool anyBlk(std::function<bool(CacheBlk &)> visitor) override; 19812752Sodanrc@yahoo.com.br}; 19912752Sodanrc@yahoo.com.br 20012752Sodanrc@yahoo.com.br#endif //__MEM_CACHE_TAGS_SECTOR_TAGS_HH__ 201