super_blk.hh (13940:33cc30e2de52) super_blk.hh (13947:4cf8087cab09)
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/** @file
32 * Definition of a simple superblock class. Each superblock consists of a
33 * number of compressed cache blocks limited by the maximum compression
34 * factor that may or may not be present in the cache.
35 */
36
37#ifndef __MEM_CACHE_TAGS_SUPER_BLK_HH__
38#define __MEM_CACHE_TAGS_SUPER_BLK_HH__
39
40#include "mem/cache/tags/sector_blk.hh"
41
42class SuperBlk;
43
44/**
45 * A superblock is composed of sub-blocks, and each sub-block has information
46 * regarding its superblock and a pointer to its superblock tag. A superblock
47 * can be seen as a variation of a sector block, and therefore we use a sector
48 * nomenclature.
49 */
50class CompressionBlk : public SectorSubBlk
51{
52 private:
53 /**
54 * Set size, in bits, of this compressed block's data.
55 */
56 std::size_t _size;
57
58 /**
59 * Number of cycles needed to decompress this block. We store it to avoid
60 * doing decompressions.
61 */
62 Cycles _decompressionLatency;
63
64 public:
65 CompressionBlk();
66 CompressionBlk(const CompressionBlk&) = delete;
67 CompressionBlk& operator=(const CompressionBlk&) = delete;
68 ~CompressionBlk() {};
69
70 /**
71 * Check if this block holds compressed data.
72 *
73 * @return True if the block holds compressed data.
74 */
75 bool isCompressed() const;
76
77 /**
78 * Set compression bit.
79 */
80 void setCompressed();
81
82 /**
83 * Clear compression bit.
84 */
85 void setUncompressed();
86
87 /*
88 * Get size, in bits, of this compressed block's data.
89 *
90 * @return The compressed size.
91 */
92 std::size_t getSizeBits() const;
93
94 /**
95 * Set size, in bits, of this compressed block's data.
96 *
97 * @param The compressed size.
98 */
99 void setSizeBits(const std::size_t size);
100
101 /**
102 * Get number of cycles needed to decompress this block.
103 *
104 * @return Decompression latency.
105 */
106 Cycles getDecompressionLatency() const;
107
108 /**
109 * Set number of cycles needed to decompress this block.
110 *
111 * @param Decompression latency.
112 */
113 void setDecompressionLatency(const Cycles lat);
114
115 /**
116 * Pretty-print sector offset and other CacheBlk information.
117 *
118 * @return string with basic state information
119 */
120 std::string print() const override;
121};
122
123/**
124 * A basic compression superblock.
125 * Contains the tag and a list of blocks associated to this superblock.
126 */
127class SuperBlk : public SectorBlk
128{
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/** @file
32 * Definition of a simple superblock class. Each superblock consists of a
33 * number of compressed cache blocks limited by the maximum compression
34 * factor that may or may not be present in the cache.
35 */
36
37#ifndef __MEM_CACHE_TAGS_SUPER_BLK_HH__
38#define __MEM_CACHE_TAGS_SUPER_BLK_HH__
39
40#include "mem/cache/tags/sector_blk.hh"
41
42class SuperBlk;
43
44/**
45 * A superblock is composed of sub-blocks, and each sub-block has information
46 * regarding its superblock and a pointer to its superblock tag. A superblock
47 * can be seen as a variation of a sector block, and therefore we use a sector
48 * nomenclature.
49 */
50class CompressionBlk : public SectorSubBlk
51{
52 private:
53 /**
54 * Set size, in bits, of this compressed block's data.
55 */
56 std::size_t _size;
57
58 /**
59 * Number of cycles needed to decompress this block. We store it to avoid
60 * doing decompressions.
61 */
62 Cycles _decompressionLatency;
63
64 public:
65 CompressionBlk();
66 CompressionBlk(const CompressionBlk&) = delete;
67 CompressionBlk& operator=(const CompressionBlk&) = delete;
68 ~CompressionBlk() {};
69
70 /**
71 * Check if this block holds compressed data.
72 *
73 * @return True if the block holds compressed data.
74 */
75 bool isCompressed() const;
76
77 /**
78 * Set compression bit.
79 */
80 void setCompressed();
81
82 /**
83 * Clear compression bit.
84 */
85 void setUncompressed();
86
87 /*
88 * Get size, in bits, of this compressed block's data.
89 *
90 * @return The compressed size.
91 */
92 std::size_t getSizeBits() const;
93
94 /**
95 * Set size, in bits, of this compressed block's data.
96 *
97 * @param The compressed size.
98 */
99 void setSizeBits(const std::size_t size);
100
101 /**
102 * Get number of cycles needed to decompress this block.
103 *
104 * @return Decompression latency.
105 */
106 Cycles getDecompressionLatency() const;
107
108 /**
109 * Set number of cycles needed to decompress this block.
110 *
111 * @param Decompression latency.
112 */
113 void setDecompressionLatency(const Cycles lat);
114
115 /**
116 * Pretty-print sector offset and other CacheBlk information.
117 *
118 * @return string with basic state information
119 */
120 std::string print() const override;
121};
122
123/**
124 * A basic compression superblock.
125 * Contains the tag and a list of blocks associated to this superblock.
126 */
127class SuperBlk : public SectorBlk
128{
129 protected:
130 /** Block size, in bytes. */
131 std::size_t blkSize;
132
129 public:
133 public:
130 SuperBlk() : SectorBlk() {}
134 SuperBlk() : SectorBlk(), blkSize(0) {}
131 SuperBlk(const SuperBlk&) = delete;
132 SuperBlk& operator=(const SuperBlk&) = delete;
133 ~SuperBlk() {};
134
135 /**
136 * Returns whether the superblock contains compressed blocks or not. By
137 * default, if not blocks are valid, the superblock is compressible.
138 *
135 SuperBlk(const SuperBlk&) = delete;
136 SuperBlk& operator=(const SuperBlk&) = delete;
137 ~SuperBlk() {};
138
139 /**
140 * Returns whether the superblock contains compressed blocks or not. By
141 * default, if not blocks are valid, the superblock is compressible.
142 *
143 * @param ignored_blk If provided don't consider the given block.
139 * @return The compressibility state of the superblock.
140 */
144 * @return The compressibility state of the superblock.
145 */
141 bool isCompressed() const;
146 bool isCompressed(const CompressionBlk* ignored_blk = nullptr) const;
147
148 /**
149 * Checks whether a superblock can co-allocate given compressed data block.
150 *
151 * @param compressed_size Size, in bits, of new block to allocate.
152 * @return True if block can be co-allocated in superblock.
153 */
154 bool canCoAllocate(const std::size_t compressed_size) const;
155
156 /**
157 * Set block size. Should be called only once, when initializing blocks.
158 *
159 * @param blk_size The uncompressed block size.
160 */
161 void setBlkSize(const std::size_t blk_size);
142};
143
144#endif //__MEM_CACHE_TAGS_SUPER_BLK_HH__
162};
163
164#endif //__MEM_CACHE_TAGS_SUPER_BLK_HH__