compressed_tags.hh revision 13945
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; 4513938Sodanrc@yahoo.com.brstruct CompressedTagsParams; 4613938Sodanrc@yahoo.com.br 4713938Sodanrc@yahoo.com.br/** 4813938Sodanrc@yahoo.com.br * A CompressedTags cache tag store. 4913938Sodanrc@yahoo.com.br * @sa \ref gem5MemorySystem "gem5 Memory System" 5013938Sodanrc@yahoo.com.br * 5113938Sodanrc@yahoo.com.br * The Compression Ratio (CR) of a superblock is defined by 5213938Sodanrc@yahoo.com.br * CR = uncompressed_size / compressed_size. 5313938Sodanrc@yahoo.com.br * 5413938Sodanrc@yahoo.com.br * The CompressedTags placement policy divides the cache into s sets of w 5513938Sodanrc@yahoo.com.br * superblocks (ways). Each superblock can then contain up to CR compressed 5613938Sodanrc@yahoo.com.br * blocks. 5713938Sodanrc@yahoo.com.br * 5813938Sodanrc@yahoo.com.br * For each tag entry there can be multiple data blocks. We have the same 5913938Sodanrc@yahoo.com.br * number of tags a conventional cache would have, but we instantiate the 6013938Sodanrc@yahoo.com.br * maximum number of data blocks (according to the compression ratio) per 6113938Sodanrc@yahoo.com.br * tag, to virtually implement compression without increasing the complexity 6213938Sodanrc@yahoo.com.br * of the simulator. 6313938Sodanrc@yahoo.com.br * 6413938Sodanrc@yahoo.com.br * This is a simple implementation of cache compression, where superblocks 6513938Sodanrc@yahoo.com.br * can only have at most numBlocksPerSector compressed blocks, each compressed 6613938Sodanrc@yahoo.com.br * to at least (100/numBlocksPerSector)% of its size. 6713938Sodanrc@yahoo.com.br * 6813938Sodanrc@yahoo.com.br * numBlocksPerSector holds the maximum number of blocks a superblock with 6913938Sodanrc@yahoo.com.br * the best possible compression factor would hold. It is equivalent to CR 7013938Sodanrc@yahoo.com.br * from the previous definition. 7113938Sodanrc@yahoo.com.br */ 7213938Sodanrc@yahoo.com.brclass CompressedTags : public SectorTags 7313938Sodanrc@yahoo.com.br{ 7413938Sodanrc@yahoo.com.br private: 7513938Sodanrc@yahoo.com.br /** The cache blocks. */ 7613938Sodanrc@yahoo.com.br std::vector<CompressionBlk> blks; 7713938Sodanrc@yahoo.com.br /** The cache superblocks. */ 7813938Sodanrc@yahoo.com.br std::vector<SuperBlk> superBlks; 7913938Sodanrc@yahoo.com.br 8013938Sodanrc@yahoo.com.br public: 8113938Sodanrc@yahoo.com.br /** Convenience typedef. */ 8213938Sodanrc@yahoo.com.br typedef CompressedTagsParams Params; 8313938Sodanrc@yahoo.com.br 8413938Sodanrc@yahoo.com.br /** 8513938Sodanrc@yahoo.com.br * Construct and initialize this tag store. 8613938Sodanrc@yahoo.com.br */ 8713938Sodanrc@yahoo.com.br CompressedTags(const Params *p); 8813938Sodanrc@yahoo.com.br 8913938Sodanrc@yahoo.com.br /** 9013938Sodanrc@yahoo.com.br * Destructor. 9113938Sodanrc@yahoo.com.br */ 9213938Sodanrc@yahoo.com.br virtual ~CompressedTags() {}; 9313938Sodanrc@yahoo.com.br 9413938Sodanrc@yahoo.com.br /** 9513938Sodanrc@yahoo.com.br * Initialize blocks as SuperBlk and CompressionBlk instances. 9613938Sodanrc@yahoo.com.br */ 9713938Sodanrc@yahoo.com.br void tagsInit() override; 9813938Sodanrc@yahoo.com.br 9913938Sodanrc@yahoo.com.br /** 10013945Sodanrc@yahoo.com.br * Insert the new block into the cache and update replacement data. 10113945Sodanrc@yahoo.com.br * 10213945Sodanrc@yahoo.com.br * @param pkt Packet holding the address to update 10313945Sodanrc@yahoo.com.br * @param blk The block to update. 10413945Sodanrc@yahoo.com.br */ 10513945Sodanrc@yahoo.com.br void insertBlock(const PacketPtr pkt, CacheBlk *blk) override; 10613945Sodanrc@yahoo.com.br 10713945Sodanrc@yahoo.com.br /** 10813938Sodanrc@yahoo.com.br * Visit each sub-block in the tags and apply a visitor. 10913938Sodanrc@yahoo.com.br * 11013938Sodanrc@yahoo.com.br * The visitor should be a std::function that takes a cache block. 11113938Sodanrc@yahoo.com.br * reference as its parameter. 11213938Sodanrc@yahoo.com.br * 11313938Sodanrc@yahoo.com.br * @param visitor Visitor to call on each block. 11413938Sodanrc@yahoo.com.br */ 11513938Sodanrc@yahoo.com.br void forEachBlk(std::function<void(CacheBlk &)> visitor) override; 11613938Sodanrc@yahoo.com.br 11713938Sodanrc@yahoo.com.br /** 11813938Sodanrc@yahoo.com.br * Find if any of the sub-blocks satisfies a condition. 11913938Sodanrc@yahoo.com.br * 12013938Sodanrc@yahoo.com.br * The visitor should be a std::function that takes a cache block 12113938Sodanrc@yahoo.com.br * reference as its parameter. The visitor will terminate the 12213938Sodanrc@yahoo.com.br * traversal early if the condition is satisfied. 12313938Sodanrc@yahoo.com.br * 12413938Sodanrc@yahoo.com.br * @param visitor Visitor to call on each block. 12513938Sodanrc@yahoo.com.br */ 12613938Sodanrc@yahoo.com.br bool anyBlk(std::function<bool(CacheBlk &)> visitor) override; 12713938Sodanrc@yahoo.com.br}; 12813938Sodanrc@yahoo.com.br 12913938Sodanrc@yahoo.com.br#endif //__MEM_CACHE_TAGS_COMPRESSED_TAGS_HH__ 130