gem5  v22.1.0.0
TBEStorage.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2021 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_TBESTORAGE_HH__
39 #define __MEM_RUBY_STRUCTURES_TBESTORAGE_HH__
40 
41 #include <cassert>
42 #include <stack>
43 #include <unordered_map>
44 
45 #include <base/statistics.hh>
46 
47 namespace gem5
48 {
49 
50 namespace ruby
51 {
52 
53 // The TBEStorage is used to track the resources consumed by the TBETable,
54 // i.e. the number of available TBE slots.
55 //
56 // TBEStorage resource tracking has two main differences from TBETable:
57 //
58 // 1) Allows slot reservation. This is useful to implement protocols that
59 // employ retry/credit messages instead of stall when the controller runs
60 // out of TBEs to accept new request.
61 //
62 // 2) Can also assign multiple entries to the same slot. This is useful to
63 // more easily model cases where multiple transactions share the same TBE
64 // resource (i.e. the slot).
65 // E.g: a request that triggers a replacement in a system without
66 // dedicated WB/Eviction buffer; both transactions can can have separate
67 // logical TBEs associated to the same slot.
68 //
69 // The motivation for having a separate structures for tracking TBEs
70 // availability are twofold:
71 //
72 // - Keeps TBETable simple and without the additional overhead for
73 // protocols that do not need these additional features.
74 //
75 // - Having two separate transactions sharing the same TBE resource using
76 // the current TBETable would be cumbersome since the TBETable is indexed
77 // by the transaction address.
78 
80 {
81  public:
82  TBEStorage(statistics::Group *parent, int number_of_TBEs);
83 
84  // Returns the current number of slots allocated
85  int size() const { return m_slots_used.size(); }
86 
87  // Returns the total capacity of this TBEStorage table
88  int capacity() const { return m_slots_used.size() + m_slots_avail.size(); }
89 
90  // Returns number of slots currently reserved
91  int reserved() const { return m_reserved; }
92 
93  // Returns the number of slots available
94  int slotsAvailable() const { return m_slots_avail.size() - m_reserved; }
95 
96  // Returns the TBEStorage utilization
97  float utilization() const { return size() / (float)capacity(); }
98 
99  // Returns true if slotsAvailable() >= n; current_time is always ignored
100  // This allows this class to be used with check_allocate in SLICC to
101  // trigger resource stalls when there are no slots available
102  bool areNSlotsAvailable(int n, Tick current_time = 0) const;
103 
104  // Increase/decrease the number of reserved slots. Having reserved slots
105  // reduces the number of slots available for allocation
106  void incrementReserved();
107  void decrementReserved();
108 
109  // Assign a TBETable entry to a free slot and returns the slot number.
110  // Notice we don't need any info from TBETable and just track the number
111  // of entries assigned to each slot.
112  // This funcion requires slotsAvailable() > 0
113  int addEntryToNewSlot();
114 
115  // Assign an entry to an existing non-empty slot
116  void addEntryToSlot(int slot);
117 
118  // Remove an entry from an existing non-empty slot. The slot becomes
119  // available again when the number of assigned entries == 0
120  void removeEntryFromSlot(int slot);
121 
122  private:
124  std::stack<int> m_slots_avail;
125  std::unordered_map<int, int> m_slots_used;
126 
128  {
130 
131  // Statistical variables
136 };
137 
138 inline bool
139 TBEStorage::areNSlotsAvailable(int n, Tick current_time) const
140 {
141  return slotsAvailable() >= n;
142 }
143 
144 inline void
146 {
147  ++m_reserved;
149 }
150 
151 inline void
153 {
154  assert(m_reserved > 0);
155  --m_reserved;
157 }
158 
159 inline int
161 {
162  assert(slotsAvailable() > 0);
163  assert(m_slots_avail.size() > 0);
164  int slot = m_slots_avail.top();
165  m_slots_used[slot] = 1;
166  m_slots_avail.pop();
167  m_stats.avg_size = size();
169  return slot;
170 }
171 
172 inline void
174 {
175  auto iter = m_slots_used.find(slot);
176  assert(iter != m_slots_used.end());
177  iter->second += 1;
178 }
179 
180 inline void
182 {
183  auto iter = m_slots_used.find(slot);
184  assert(iter != m_slots_used.end());
185  assert(iter->second > 0);
186  iter->second -= 1;
187  if (iter->second == 0) {
188  m_slots_used.erase(iter);
189  m_slots_avail.push(slot);
190  }
191  m_stats.avg_size = size();
193 }
194 
195 } // namespace ruby
196 } // namespace gem5
197 
198 #endif
bool areNSlotsAvailable(int n, Tick current_time=0) const
Definition: TBEStorage.hh:139
std::stack< int > m_slots_avail
Definition: TBEStorage.hh:124
void addEntryToSlot(int slot)
Definition: TBEStorage.hh:173
int slotsAvailable() const
Definition: TBEStorage.hh:94
int capacity() const
Definition: TBEStorage.hh:88
int reserved() const
Definition: TBEStorage.hh:91
TBEStorage(statistics::Group *parent, int number_of_TBEs)
Definition: TBEStorage.cc:46
void removeEntryFromSlot(int slot)
Definition: TBEStorage.hh:181
float utilization() const
Definition: TBEStorage.hh:97
std::unordered_map< int, int > m_slots_used
Definition: TBEStorage.hh:125
gem5::ruby::TBEStorage::TBEStorageStats m_stats
A stat that calculates the per tick average of a value.
Definition: statistics.hh:1959
Statistics container.
Definition: group.hh:94
Bitfield< 31 > n
Definition: misc_types.hh:462
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
uint64_t Tick
Tick count type.
Definition: types.hh:58
Declaration of Statistics objects.
TBEStorageStats(statistics::Group *parent)
Definition: TBEStorage.cc:53

Generated on Wed Dec 21 2022 10:22:38 for gem5 by doxygen 1.9.1