gem5 v24.1.0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MN_TBEStorage.hh
Go to the documentation of this file.
1/*
2 * Copyright (c) 2021-2022 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated
11 * unmodified and in its entirety in all distributions of the software,
12 * modified or unmodified, in source code or in binary form.
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions are
16 * met: redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer;
18 * redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution;
21 * neither the name of the copyright holders nor the names of its
22 * contributors may be used to endorse or promote products derived from
23 * this software without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 */
37
38#ifndef __MEM_RUBY_STRUCTURES_MN_TBESTORAGE_HH__
39#define __MEM_RUBY_STRUCTURES_MN_TBESTORAGE_HH__
40
41#include <cassert>
42#include <unordered_map>
43#include <vector>
44
45#include <base/statistics.hh>
46
49
50namespace gem5
51{
52
53namespace ruby
54{
55
56namespace CHI
57{
58
59// MN_TBEStorage is composed of multiple TBEStorage
60// partitions that could be used for specific types of TBEs.
61// Partition number 0 is the generic partition and will
62// store any kind of TBEs.
63// Space for specific TBEs will be looked first into the matching
64// partition, and when no space is available the generic one will
65// be used
66template <class RetryEntry>
68{
69 public:
71 std::initializer_list<TBEStorage *> _partitions)
72 : m_stats(parent),
73 partitions(_partitions)
74 {}
75
76 // Returns the current number of slots allocated
77 int
78 size() const
79 {
80 int total = 0;
81 for (auto part : partitions) {
82 total += part->size();
83 }
84 return total;
85 }
86
87 // Returns the total capacity of this TBEStorage table
88 int
89 capacity() const
90 {
91 int total = 0;
92 for (auto part : partitions) {
93 total += part->capacity();
94 }
95 return total;
96 }
97
98 // Returns number of slots currently reserved
99 int
100 reserved() const
101 {
102 int total = 0;
103 for (auto part : partitions) {
104 total += part->reserved();
105 }
106 return total;
107 }
108
109 // Returns the number of slots available for objects of a certain type;
110 int
111 slotsAvailable(int partition) const
112 {
113 auto generic_slots = partitions[0]->slotsAvailable();
114 if (partition) {
115 return partitions[partition]->slotsAvailable() +
116 generic_slots;
117 } else {
118 return generic_slots;
119 }
120 }
121
122 // Returns the TBEStorage utilization
123 float utilization() const { return size() / (float)capacity(); }
124
125 // Returns true if slotsAvailable(partition) >= n;
126 // current_time is always ignored
127 // This allows this class to be used with check_allocate in SLICC to
128 // trigger resource stalls when there are no slots available
129 bool
130 areNSlotsAvailable(int n, int partition,
131 Tick current_time = 0) const
132 {
133 return slotsAvailable(partition) >= n;
134 }
135
136 // Increase/decrease the number of reserved slots. Having reserved slots
137 // reduces the number of slots available for allocation
138 void
139 incrementReserved(int partition)
140 {
141 if (partition &&
142 partitions[partition]->areNSlotsAvailable(1)) {
143 partitions[partition]->incrementReserved();
144 } else {
145 partitions[0]->incrementReserved();
146 }
148 }
149
150 void
151 decrementReserved(int partition)
152 {
153 if (partition && (partitions[partition]->reserved() > 0)) {
154 partitions[partition]->decrementReserved();
155 } else {
156 partitions[0]->decrementReserved();
157 }
159 }
160
161 // Assign a TBETable entry to a free slot and returns the slot number.
162 // Notice we don't need any info from TBETable and just track the number
163 // of entries assigned to each slot.
164 // This funcion requires slotsAvailable() > 0
165 int
166 addEntryToNewSlot(int partition)
167 {
168 if (partition && partitions[partition]->areNSlotsAvailable(1)) {
169 int part_slot = partitions[partition]->addEntryToNewSlot();
170
173
174 return part_slot;
175 } else {
176 int generic_slot = partitions[0]->addEntryToNewSlot();
177
180
181 return partitions[partition]->capacity() + generic_slot;
182 }
183 }
184
185 // addEntryToSlot(int) is not supported.
186
187 // Remove an entry from an existing non-empty slot. The slot becomes
188 // available again when the number of assigned entries == 0
189 void
190 removeEntryFromSlot(int slot, int partition)
191 {
192 auto part_capacity = partitions[partition]->capacity();
193 if (slot < part_capacity) {
194 partitions[partition]->removeEntryFromSlot(slot);
195 } else {
196 partitions[0]->removeEntryFromSlot(
197 slot - part_capacity);
198 }
199
202 }
203
204 // Insert a "retry entry" into the queue
205 void
206 emplaceRetryEntry(RetryEntry entry)
207 {
208 m_retryEntries.push_back(entry);
209 }
210
211 // Check if a retry is possible
212 bool
214 {
215 auto retry_iter = getNextRetryEntryIter();
216 return retry_iter != m_retryEntries.end();
217 }
218
219 // Peek what the next thing to retry should be
220 // Should only be called if hasPossibleRetry() returns true
221 RetryEntry
223 {
224 auto retry_iter = getNextRetryEntryIter();
225 assert(retry_iter != m_retryEntries.end());
226
227 auto entry = *retry_iter;
228
229 m_retryEntries.erase(retry_iter);
230
231 return entry;
232 }
233
234 private:
236 {
238 : statistics::Group(parent),
239 ADD_STAT(avg_size, "Avg. number of slots allocated"),
240 ADD_STAT(avg_util, "Avg. utilization"),
241 ADD_STAT(avg_reserved, "Avg. number of slots reserved")
242 {}
243
244 // Statistical variables
249
251
253
256 {
257 auto begin_it = m_retryEntries.begin();
258 auto end_it = m_retryEntries.end();
259
260 for (auto it = begin_it; it != end_it; it++) {
261 if (areNSlotsAvailable(1, it->getisNonSync()))
262 return it;
263 }
264
265 return end_it;
266 }
267};
268
269} // namespace CHI
270
271} // namespace ruby
272
273} // namespace gem5
274
275#endif
void removeEntryFromSlot(int slot, int partition)
int addEntryToNewSlot(int partition)
bool areNSlotsAvailable(int n, int partition, Tick current_time=0) const
void emplaceRetryEntry(RetryEntry entry)
MN_TBEStorage(statistics::Group *parent, std::initializer_list< TBEStorage * > _partitions)
std::vector< TBEStorage * > partitions
std::list< RetryEntry > m_retryEntries
void decrementReserved(int partition)
std::list< RetryEntry >::iterator getNextRetryEntryIter()
gem5::ruby::CHI::MN_TBEStorage::MN_TBEStorageStats m_stats
void incrementReserved(int partition)
int slotsAvailable(int partition) const
A stat that calculates the per tick average of a value.
Statistics container.
Definition group.hh:93
STL list class.
Definition stl.hh:51
STL vector class.
Definition stl.hh:37
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
Definition group.hh:75
Bitfield< 31 > n
const FlagsType total
Print the total.
Definition info.hh:59
Copyright (c) 2024 Arm Limited All rights reserved.
Definition binary32.hh:36
uint64_t Tick
Tick count type.
Definition types.hh:58
Declaration of Statistics objects.

Generated on Mon Jan 13 2025 04:28:40 for gem5 by doxygen 1.9.8