2 * Copyright (c) 2018 Inria
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.
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.
31 * Declaration of a compressed set associative tag store using superblocks.
34 #ifndef __MEM_CACHE_TAGS_COMPRESSED_TAGS_HH__
35 #define __MEM_CACHE_TAGS_COMPRESSED_TAGS_HH__
39 #include "mem/cache/tags/sector_tags.hh"
40 #include "mem/cache/tags/super_blk.hh"
44 struct CompressedTagsParams;
47 * A CompressedTags cache tag store.
48 * @sa \ref gem5MemorySystem "gem5 Memory System"
50 * The Compression Ratio (CR) of a superblock is defined by
51 * CR = uncompressed_size / compressed_size.
53 * The CompressedTags placement policy divides the cache into s sets of w
54 * superblocks (ways). Each superblock can then contain up to CR compressed
57 * For each tag entry there can be multiple data blocks. We have the same
58 * number of tags a conventional cache would have, but we instantiate the
59 * maximum number of data blocks (according to the compression ratio) per
60 * tag, to virtually implement compression without increasing the complexity
63 * This is a simple implementation of cache compression, where superblocks
64 * can only have at most numBlocksPerSector compressed blocks, each compressed
65 * to at least (100/numBlocksPerSector)% of its size.
67 * numBlocksPerSector holds the maximum number of blocks a superblock with
68 * the best possible compression factor would hold. It is equivalent to CR
69 * from the previous definition.
71 class CompressedTags : public SectorTags
74 /** The cache blocks. */
75 std::vector<CompressionBlk> blks;
76 /** The cache superblocks. */
77 std::vector<SuperBlk> superBlks;
80 /** Convenience typedef. */
81 typedef CompressedTagsParams Params;
84 * Construct and initialize this tag store.
86 CompressedTags(const Params *p);
91 virtual ~CompressedTags() {};
94 * Initialize blocks as SuperBlk and CompressionBlk instances.
96 void tagsInit() override;
99 * Find replacement victim based on address. Checks if data can be co-
100 * allocated before choosing blocks to be evicted.
102 * @param addr Address to find a victim for.
103 * @param is_secure True if the target memory space is secure.
104 * @param compressed_size Size, in bits, of new block to allocate.
105 * @param evict_blks Cache blocks to be evicted.
106 * @return Cache block to be replaced.
108 CacheBlk* findVictim(Addr addr, const bool is_secure,
109 const std::size_t compressed_size,
110 std::vector<CacheBlk*>& evict_blks) override;
113 * Insert the new block into the cache and update replacement data.
115 * @param pkt Packet holding the address to update
116 * @param blk The block to update.
118 void insertBlock(const PacketPtr pkt, CacheBlk *blk) override;
121 * Visit each sub-block in the tags and apply a visitor.
123 * The visitor should be a std::function that takes a cache block.
124 * reference as its parameter.
126 * @param visitor Visitor to call on each block.
128 void forEachBlk(std::function<void(CacheBlk &)> visitor) override;
131 * Find if any of the sub-blocks satisfies a condition.
133 * The visitor should be a std::function that takes a cache block
134 * reference as its parameter. The visitor will terminate the
135 * traversal early if the condition is satisfied.
137 * @param visitor Visitor to call on each block.
139 bool anyBlk(std::function<bool(CacheBlk &)> visitor) override;
142 #endif //__MEM_CACHE_TAGS_COMPRESSED_TAGS_HH__