1/* 2 * Copyright (c) 2018 Inria 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Daniel Carvalho 29 */ 30 31/** 32 * @file 33 * Declaration of a sector set associative tag store. 34 */ 35 36#ifndef __MEM_CACHE_TAGS_SECTOR_TAGS_HH__ 37#define __MEM_CACHE_TAGS_SECTOR_TAGS_HH__ 38 39#include <string> 40#include <vector> 41 42#include "mem/cache/sector_blk.hh" 43#include "mem/cache/tags/base.hh" 44#include "mem/packet.hh" 45#include "params/SectorTags.hh" 46 47class BaseReplacementPolicy;
| 1/* 2 * Copyright (c) 2018 Inria 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Daniel Carvalho 29 */ 30 31/** 32 * @file 33 * Declaration of a sector set associative tag store. 34 */ 35 36#ifndef __MEM_CACHE_TAGS_SECTOR_TAGS_HH__ 37#define __MEM_CACHE_TAGS_SECTOR_TAGS_HH__ 38 39#include <string> 40#include <vector> 41 42#include "mem/cache/sector_blk.hh" 43#include "mem/cache/tags/base.hh" 44#include "mem/packet.hh" 45#include "params/SectorTags.hh" 46 47class BaseReplacementPolicy;
|
48 49/** 50 * A SectorTags cache tag store. 51 * @sa \ref gem5MemorySystem "gem5 Memory System" 52 * 53 * The SectorTags placement policy divides the cache into s sectors of w 54 * consecutive sectors (ways). Each sector then consists of a number of 55 * sequential cache lines that may or may not be present. 56 */ 57class SectorTags : public BaseTags 58{ 59 protected: 60 /** Typedef the set type used in this tag store. */ 61 typedef std::vector<SectorBlk*> SetType; 62 63 /** The associativity of the cache. */ 64 const unsigned assoc; 65 /** The allocatable associativity of the cache (alloc mask). */ 66 unsigned allocAssoc; 67 68 /** Whether tags and data are accessed sequentially. */ 69 const bool sequentialAccess; 70 71 /** Replacement policy */ 72 BaseReplacementPolicy *replacementPolicy; 73 74 /** Number of data blocks per sector. */ 75 const unsigned numBlocksPerSector; 76 77 /** The number of sectors in the cache. */ 78 const unsigned numSectors; 79 /** The number of sets in the cache. */ 80 const unsigned numSets; 81 82 /** The cache blocks. */ 83 std::vector<SectorSubBlk> blks; 84 /** The cache sector blocks. */ 85 std::vector<SectorBlk> secBlks; 86 /** The cache sets. */ 87 std::vector<SetType> sets; 88 89 // Organization of an address: Tag | Set # | Sector Offset # | Offset # 90 /** The amount to shift the address to get the sector tag. */ 91 const int sectorShift; 92 /** The amount to shift the address to get the set. */ 93 const int setShift; 94 /** The amount to shift the address to get the tag. */ 95 const int tagShift; 96 97 /** Mask out all bits that aren't part of the sector tag. */ 98 const unsigned sectorMask; 99 /** Mask out all bits that aren't part of the set index. */ 100 const unsigned setMask; 101 102 public: 103 /** Convenience typedef. */ 104 typedef SectorTagsParams Params; 105 106 /** 107 * Construct and initialize this tag store. 108 */ 109 SectorTags(const Params *p); 110 111 /** 112 * Destructor. 113 */ 114 virtual ~SectorTags() {}; 115 116 /** 117 * This function updates the tags when a block is invalidated but does 118 * not invalidate the block itself. It also updates the replacement data. 119 * 120 * @param blk The block to invalidate. 121 */ 122 void invalidate(CacheBlk *blk) override; 123 124 /** 125 * Access block and update replacement data. May not succeed, in which 126 * case nullptr is returned. This has all the implications of a cache 127 * access and should only be used as such. Returns the access latency 128 * as a side effect. 129 * 130 * @param addr The address to find. 131 * @param is_secure True if the target memory space is secure. 132 * @param lat The access latency. 133 * @return Pointer to the cache block if found. 134 */ 135 CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat) override; 136 137 /** 138 * Find all possible block locations for insertion and replacement of 139 * an address. Should be called immediately before ReplacementPolicy's 140 * findVictim() not to break cache resizing. 141 * Returns sector blocks in all ways belonging to the set of the address. 142 * 143 * @param addr The addr to a find possible locations for. 144 * @return The possible locations. 145 */ 146 virtual const std::vector<SectorBlk*> getPossibleLocations(Addr addr) 147 const; 148 149 /** 150 * Insert the new block into the cache and update replacement data. 151 * 152 * @param pkt Packet holding the address to update 153 * @param blk The block to update. 154 */ 155 void insertBlock(const PacketPtr pkt, CacheBlk *blk) override; 156 157 /** 158 * Finds the given address in the cache, do not update replacement data. 159 * i.e. This is a no-side-effect find of a block. 160 * 161 * @param addr The address to find. 162 * @param is_secure True if the target memory space is secure. 163 * @return Pointer to the cache block if found. 164 */ 165 CacheBlk* findBlock(Addr addr, bool is_secure) const override; 166 167 /** 168 * Find a sector block given set and way. 169 * 170 * @param set The set of the block. 171 * @param way The way of the block. 172 * @return The block. 173 */ 174 ReplaceableEntry* findBlockBySetAndWay(int set, int way) const override; 175 176 /** 177 * Find replacement victim based on address. 178 * 179 * @param addr Address to find a victim for. 180 * @param is_secure True if the target memory space is secure. 181 * @param evict_blks Cache blocks to be evicted. 182 * @return Cache block to be replaced. 183 */ 184 CacheBlk* findVictim(Addr addr, const bool is_secure, 185 std::vector<CacheBlk*>& evict_blks) const override; 186 187 /** 188 * Generate the sector tag from the given address. 189 * 190 * @param addr The address to get the sector tag from. 191 * @return The sector tag of the address. 192 */ 193 Addr extractTag(Addr addr) const override; 194 195 /** 196 * Calculate the set index from the address. 197 * 198 * @param addr The address to get the set from. 199 * @return The set index of the address. 200 */ 201 int extractSet(Addr addr) const; 202 203 /** 204 * Calculate a block's offset in a sector from the address. 205 * 206 * @param addr The address to get the offset from. 207 * @return Offset of the corresponding block within its sector. 208 */ 209 int extractSectorOffset(Addr addr) const; 210 211 /** 212 * Regenerate the block address from the tag and set. 213 * 214 * @param block The block. 215 * @return the block address. 216 */ 217 Addr regenerateBlkAddr(const CacheBlk* blk) const override; 218 219 /** 220 * Visit each sub-block in the tags and apply a visitor. 221 * 222 * The visitor should be a std::function that takes a cache block. 223 * reference as its parameter. 224 * 225 * @param visitor Visitor to call on each block. 226 */ 227 void forEachBlk(std::function<void(CacheBlk &)> visitor) override; 228 229 /** 230 * Find if any of the sub-blocks satisfies a condition. 231 * 232 * The visitor should be a std::function that takes a cache block 233 * reference as its parameter. The visitor will terminate the 234 * traversal early if the condition is satisfied. 235 * 236 * @param visitor Visitor to call on each block. 237 */ 238 bool anyBlk(std::function<bool(CacheBlk &)> visitor) override; 239}; 240 241#endif //__MEM_CACHE_TAGS_SECTOR_TAGS_HH__
| 49 50/** 51 * A SectorTags cache tag store. 52 * @sa \ref gem5MemorySystem "gem5 Memory System" 53 * 54 * The SectorTags placement policy divides the cache into s sectors of w 55 * consecutive sectors (ways). Each sector then consists of a number of 56 * sequential cache lines that may or may not be present. 57 */ 58class SectorTags : public BaseTags 59{ 60 protected: 61 /** Typedef the set type used in this tag store. */ 62 typedef std::vector<SectorBlk*> SetType; 63 64 /** The associativity of the cache. */ 65 const unsigned assoc; 66 /** The allocatable associativity of the cache (alloc mask). */ 67 unsigned allocAssoc; 68 69 /** Whether tags and data are accessed sequentially. */ 70 const bool sequentialAccess; 71 72 /** Replacement policy */ 73 BaseReplacementPolicy *replacementPolicy; 74 75 /** Number of data blocks per sector. */ 76 const unsigned numBlocksPerSector; 77 78 /** The number of sectors in the cache. */ 79 const unsigned numSectors; 80 /** The number of sets in the cache. */ 81 const unsigned numSets; 82 83 /** The cache blocks. */ 84 std::vector<SectorSubBlk> blks; 85 /** The cache sector blocks. */ 86 std::vector<SectorBlk> secBlks; 87 /** The cache sets. */ 88 std::vector<SetType> sets; 89 90 // Organization of an address: Tag | Set # | Sector Offset # | Offset # 91 /** The amount to shift the address to get the sector tag. */ 92 const int sectorShift; 93 /** The amount to shift the address to get the set. */ 94 const int setShift; 95 /** The amount to shift the address to get the tag. */ 96 const int tagShift; 97 98 /** Mask out all bits that aren't part of the sector tag. */ 99 const unsigned sectorMask; 100 /** Mask out all bits that aren't part of the set index. */ 101 const unsigned setMask; 102 103 public: 104 /** Convenience typedef. */ 105 typedef SectorTagsParams Params; 106 107 /** 108 * Construct and initialize this tag store. 109 */ 110 SectorTags(const Params *p); 111 112 /** 113 * Destructor. 114 */ 115 virtual ~SectorTags() {}; 116 117 /** 118 * This function updates the tags when a block is invalidated but does 119 * not invalidate the block itself. It also updates the replacement data. 120 * 121 * @param blk The block to invalidate. 122 */ 123 void invalidate(CacheBlk *blk) override; 124 125 /** 126 * Access block and update replacement data. May not succeed, in which 127 * case nullptr is returned. This has all the implications of a cache 128 * access and should only be used as such. Returns the access latency 129 * as a side effect. 130 * 131 * @param addr The address to find. 132 * @param is_secure True if the target memory space is secure. 133 * @param lat The access latency. 134 * @return Pointer to the cache block if found. 135 */ 136 CacheBlk* accessBlock(Addr addr, bool is_secure, Cycles &lat) override; 137 138 /** 139 * Find all possible block locations for insertion and replacement of 140 * an address. Should be called immediately before ReplacementPolicy's 141 * findVictim() not to break cache resizing. 142 * Returns sector blocks in all ways belonging to the set of the address. 143 * 144 * @param addr The addr to a find possible locations for. 145 * @return The possible locations. 146 */ 147 virtual const std::vector<SectorBlk*> getPossibleLocations(Addr addr) 148 const; 149 150 /** 151 * Insert the new block into the cache and update replacement data. 152 * 153 * @param pkt Packet holding the address to update 154 * @param blk The block to update. 155 */ 156 void insertBlock(const PacketPtr pkt, CacheBlk *blk) override; 157 158 /** 159 * Finds the given address in the cache, do not update replacement data. 160 * i.e. This is a no-side-effect find of a block. 161 * 162 * @param addr The address to find. 163 * @param is_secure True if the target memory space is secure. 164 * @return Pointer to the cache block if found. 165 */ 166 CacheBlk* findBlock(Addr addr, bool is_secure) const override; 167 168 /** 169 * Find a sector block given set and way. 170 * 171 * @param set The set of the block. 172 * @param way The way of the block. 173 * @return The block. 174 */ 175 ReplaceableEntry* findBlockBySetAndWay(int set, int way) const override; 176 177 /** 178 * Find replacement victim based on address. 179 * 180 * @param addr Address to find a victim for. 181 * @param is_secure True if the target memory space is secure. 182 * @param evict_blks Cache blocks to be evicted. 183 * @return Cache block to be replaced. 184 */ 185 CacheBlk* findVictim(Addr addr, const bool is_secure, 186 std::vector<CacheBlk*>& evict_blks) const override; 187 188 /** 189 * Generate the sector tag from the given address. 190 * 191 * @param addr The address to get the sector tag from. 192 * @return The sector tag of the address. 193 */ 194 Addr extractTag(Addr addr) const override; 195 196 /** 197 * Calculate the set index from the address. 198 * 199 * @param addr The address to get the set from. 200 * @return The set index of the address. 201 */ 202 int extractSet(Addr addr) const; 203 204 /** 205 * Calculate a block's offset in a sector from the address. 206 * 207 * @param addr The address to get the offset from. 208 * @return Offset of the corresponding block within its sector. 209 */ 210 int extractSectorOffset(Addr addr) const; 211 212 /** 213 * Regenerate the block address from the tag and set. 214 * 215 * @param block The block. 216 * @return the block address. 217 */ 218 Addr regenerateBlkAddr(const CacheBlk* blk) const override; 219 220 /** 221 * Visit each sub-block in the tags and apply a visitor. 222 * 223 * The visitor should be a std::function that takes a cache block. 224 * reference as its parameter. 225 * 226 * @param visitor Visitor to call on each block. 227 */ 228 void forEachBlk(std::function<void(CacheBlk &)> visitor) override; 229 230 /** 231 * Find if any of the sub-blocks satisfies a condition. 232 * 233 * The visitor should be a std::function that takes a cache block 234 * reference as its parameter. The visitor will terminate the 235 * traversal early if the condition is satisfied. 236 * 237 * @param visitor Visitor to call on each block. 238 */ 239 bool anyBlk(std::function<bool(CacheBlk &)> visitor) override; 240}; 241 242#endif //__MEM_CACHE_TAGS_SECTOR_TAGS_HH__
|