113938Sodanrc@yahoo.com.br/* 213938Sodanrc@yahoo.com.br * Copyright (c) 2018 Inria 313938Sodanrc@yahoo.com.br * All rights reserved. 413938Sodanrc@yahoo.com.br * 513938Sodanrc@yahoo.com.br * Redistribution and use in source and binary forms, with or without 613938Sodanrc@yahoo.com.br * modification, are permitted provided that the following conditions are 713938Sodanrc@yahoo.com.br * met: redistributions of source code must retain the above copyright 813938Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer; 913938Sodanrc@yahoo.com.br * redistributions in binary form must reproduce the above copyright 1013938Sodanrc@yahoo.com.br * notice, this list of conditions and the following disclaimer in the 1113938Sodanrc@yahoo.com.br * documentation and/or other materials provided with the distribution; 1213938Sodanrc@yahoo.com.br * neither the name of the copyright holders nor the names of its 1313938Sodanrc@yahoo.com.br * contributors may be used to endorse or promote products derived from 1413938Sodanrc@yahoo.com.br * this software without specific prior written permission. 1513938Sodanrc@yahoo.com.br * 1613938Sodanrc@yahoo.com.br * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1713938Sodanrc@yahoo.com.br * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1813938Sodanrc@yahoo.com.br * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1913938Sodanrc@yahoo.com.br * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2013938Sodanrc@yahoo.com.br * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2113938Sodanrc@yahoo.com.br * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2213938Sodanrc@yahoo.com.br * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2313938Sodanrc@yahoo.com.br * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2413938Sodanrc@yahoo.com.br * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2513938Sodanrc@yahoo.com.br * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2613938Sodanrc@yahoo.com.br * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2713938Sodanrc@yahoo.com.br * 2813938Sodanrc@yahoo.com.br * Authors: Daniel Carvalho 2913938Sodanrc@yahoo.com.br */ 3013938Sodanrc@yahoo.com.br 3113938Sodanrc@yahoo.com.br/** 3213938Sodanrc@yahoo.com.br * @file 3313938Sodanrc@yahoo.com.br * Declaration of a compressed set associative tag store using superblocks. 3413938Sodanrc@yahoo.com.br */ 3513938Sodanrc@yahoo.com.br 3613938Sodanrc@yahoo.com.br#ifndef __MEM_CACHE_TAGS_COMPRESSED_TAGS_HH__ 3713938Sodanrc@yahoo.com.br#define __MEM_CACHE_TAGS_COMPRESSED_TAGS_HH__ 3813938Sodanrc@yahoo.com.br 3913938Sodanrc@yahoo.com.br#include <vector> 4013938Sodanrc@yahoo.com.br 4113938Sodanrc@yahoo.com.br#include "mem/cache/tags/sector_tags.hh" 4213938Sodanrc@yahoo.com.br#include "mem/cache/tags/super_blk.hh" 4313938Sodanrc@yahoo.com.br 4413938Sodanrc@yahoo.com.brclass BaseCache; 4513946Sodanrc@yahoo.com.brclass CacheBlk; 4613938Sodanrc@yahoo.com.brstruct CompressedTagsParams; 4713938Sodanrc@yahoo.com.br 4813938Sodanrc@yahoo.com.br/** 4913938Sodanrc@yahoo.com.br * A CompressedTags cache tag store. 5013938Sodanrc@yahoo.com.br * @sa \ref gem5MemorySystem "gem5 Memory System" 5113938Sodanrc@yahoo.com.br * 5213938Sodanrc@yahoo.com.br * The Compression Ratio (CR) of a superblock is defined by 5313938Sodanrc@yahoo.com.br * CR = uncompressed_size / compressed_size. 5413938Sodanrc@yahoo.com.br * 5513938Sodanrc@yahoo.com.br * The CompressedTags placement policy divides the cache into s sets of w 5613938Sodanrc@yahoo.com.br * superblocks (ways). Each superblock can then contain up to CR compressed 5713938Sodanrc@yahoo.com.br * blocks. 5813938Sodanrc@yahoo.com.br * 5913938Sodanrc@yahoo.com.br * For each tag entry there can be multiple data blocks. We have the same 6013938Sodanrc@yahoo.com.br * number of tags a conventional cache would have, but we instantiate the 6113938Sodanrc@yahoo.com.br * maximum number of data blocks (according to the compression ratio) per 6213938Sodanrc@yahoo.com.br * tag, to virtually implement compression without increasing the complexity 6313938Sodanrc@yahoo.com.br * of the simulator. 6413938Sodanrc@yahoo.com.br * 6513938Sodanrc@yahoo.com.br * This is a simple implementation of cache compression, where superblocks 6613938Sodanrc@yahoo.com.br * can only have at most numBlocksPerSector compressed blocks, each compressed 6713938Sodanrc@yahoo.com.br * to at least (100/numBlocksPerSector)% of its size. 6813938Sodanrc@yahoo.com.br * 6913938Sodanrc@yahoo.com.br * numBlocksPerSector holds the maximum number of blocks a superblock with 7013938Sodanrc@yahoo.com.br * the best possible compression factor would hold. It is equivalent to CR 7113938Sodanrc@yahoo.com.br * from the previous definition. 7213938Sodanrc@yahoo.com.br */ 7313938Sodanrc@yahoo.com.brclass CompressedTags : public SectorTags 7413938Sodanrc@yahoo.com.br{ 7513938Sodanrc@yahoo.com.br private: 7613938Sodanrc@yahoo.com.br /** The cache blocks. */ 7713938Sodanrc@yahoo.com.br std::vector<CompressionBlk> blks; 7813938Sodanrc@yahoo.com.br /** The cache superblocks. */ 7913938Sodanrc@yahoo.com.br std::vector<SuperBlk> superBlks; 8013938Sodanrc@yahoo.com.br 8113938Sodanrc@yahoo.com.br public: 8213938Sodanrc@yahoo.com.br /** Convenience typedef. */ 8313938Sodanrc@yahoo.com.br typedef CompressedTagsParams Params; 8413938Sodanrc@yahoo.com.br 8513938Sodanrc@yahoo.com.br /** 8613938Sodanrc@yahoo.com.br * Construct and initialize this tag store. 8713938Sodanrc@yahoo.com.br */ 8813938Sodanrc@yahoo.com.br CompressedTags(const Params *p); 8913938Sodanrc@yahoo.com.br 9013938Sodanrc@yahoo.com.br /** 9113938Sodanrc@yahoo.com.br * Destructor. 9213938Sodanrc@yahoo.com.br */ 9313938Sodanrc@yahoo.com.br virtual ~CompressedTags() {}; 9413938Sodanrc@yahoo.com.br 9513938Sodanrc@yahoo.com.br /** 9613938Sodanrc@yahoo.com.br * Initialize blocks as SuperBlk and CompressionBlk instances. 9713938Sodanrc@yahoo.com.br */ 9813938Sodanrc@yahoo.com.br void tagsInit() override; 9913938Sodanrc@yahoo.com.br 10013938Sodanrc@yahoo.com.br /** 10113946Sodanrc@yahoo.com.br * Find replacement victim based on address. Checks if data can be co- 10213946Sodanrc@yahoo.com.br * allocated before choosing blocks to be evicted. 10313946Sodanrc@yahoo.com.br * 10413946Sodanrc@yahoo.com.br * @param addr Address to find a victim for. 10513946Sodanrc@yahoo.com.br * @param is_secure True if the target memory space is secure. 10613946Sodanrc@yahoo.com.br * @param compressed_size Size, in bits, of new block to allocate. 10713946Sodanrc@yahoo.com.br * @param evict_blks Cache blocks to be evicted. 10813946Sodanrc@yahoo.com.br * @return Cache block to be replaced. 10913946Sodanrc@yahoo.com.br */ 11013946Sodanrc@yahoo.com.br CacheBlk* findVictim(Addr addr, const bool is_secure, 11113946Sodanrc@yahoo.com.br const std::size_t compressed_size, 11213946Sodanrc@yahoo.com.br std::vector<CacheBlk*>& evict_blks) const override; 11313946Sodanrc@yahoo.com.br 11413946Sodanrc@yahoo.com.br /** 11513945Sodanrc@yahoo.com.br * Insert the new block into the cache and update replacement data. 11613945Sodanrc@yahoo.com.br * 11713945Sodanrc@yahoo.com.br * @param pkt Packet holding the address to update 11813945Sodanrc@yahoo.com.br * @param blk The block to update. 11913945Sodanrc@yahoo.com.br */ 12013945Sodanrc@yahoo.com.br void insertBlock(const PacketPtr pkt, CacheBlk *blk) override; 12113945Sodanrc@yahoo.com.br 12213945Sodanrc@yahoo.com.br /** 12313938Sodanrc@yahoo.com.br * Visit each sub-block in the tags and apply a visitor. 12413938Sodanrc@yahoo.com.br * 12513938Sodanrc@yahoo.com.br * The visitor should be a std::function that takes a cache block. 12613938Sodanrc@yahoo.com.br * reference as its parameter. 12713938Sodanrc@yahoo.com.br * 12813938Sodanrc@yahoo.com.br * @param visitor Visitor to call on each block. 12913938Sodanrc@yahoo.com.br */ 13013938Sodanrc@yahoo.com.br void forEachBlk(std::function<void(CacheBlk &)> visitor) override; 13113938Sodanrc@yahoo.com.br 13213938Sodanrc@yahoo.com.br /** 13313938Sodanrc@yahoo.com.br * Find if any of the sub-blocks satisfies a condition. 13413938Sodanrc@yahoo.com.br * 13513938Sodanrc@yahoo.com.br * The visitor should be a std::function that takes a cache block 13613938Sodanrc@yahoo.com.br * reference as its parameter. The visitor will terminate the 13713938Sodanrc@yahoo.com.br * traversal early if the condition is satisfied. 13813938Sodanrc@yahoo.com.br * 13913938Sodanrc@yahoo.com.br * @param visitor Visitor to call on each block. 14013938Sodanrc@yahoo.com.br */ 14113938Sodanrc@yahoo.com.br bool anyBlk(std::function<bool(CacheBlk &)> visitor) override; 14213938Sodanrc@yahoo.com.br}; 14313938Sodanrc@yahoo.com.br 14413938Sodanrc@yahoo.com.br#endif //__MEM_CACHE_TAGS_COMPRESSED_TAGS_HH__ 145