gem5  v22.1.0.0
queue.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2013, 2015-2016, 2018 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  * Copyright (c) 2003-2005 The Regents of The University of Michigan
15  * All rights reserved.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions are
19  * met: redistributions of source code must retain the above copyright
20  * notice, this list of conditions and the following disclaimer;
21  * redistributions in binary form must reproduce the above copyright
22  * notice, this list of conditions and the following disclaimer in the
23  * documentation and/or other materials provided with the distribution;
24  * neither the name of the copyright holders nor the names of its
25  * contributors may be used to endorse or promote products derived from
26  * this software without specific prior written permission.
27  *
28  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39  */
40 
45 #ifndef __MEM_CACHE_QUEUE_HH__
46 #define __MEM_CACHE_QUEUE_HH__
47 
48 #include <cassert>
49 #include <string>
50 #include <type_traits>
51 
52 #include "base/logging.hh"
53 #include "base/named.hh"
54 #include "base/trace.hh"
55 #include "base/types.hh"
56 #include "debug/Drain.hh"
57 #include "mem/cache/queue_entry.hh"
58 #include "mem/packet.hh"
59 #include "sim/cur_tick.hh"
60 #include "sim/drain.hh"
61 
62 namespace gem5
63 {
64 
69 template<class Entry>
70 class Queue : public Drainable, public Named
71 {
72  static_assert(std::is_base_of_v<QueueEntry, Entry>,
73  "Entry must be derived from QueueEntry");
74 
75  protected:
77  const std::string label;
78 
85  const int numEntries;
86 
93  const int numReserve;
94 
98  typename Entry::List allocatedList;
100  typename Entry::List readyList;
102  typename Entry::List freeList;
103 
104  typename Entry::Iterator addToReadyList(Entry* entry)
105  {
106  if (readyList.empty() ||
107  readyList.back()->readyTime <= entry->readyTime) {
108  return readyList.insert(readyList.end(), entry);
109  }
110 
111  for (auto i = readyList.begin(); i != readyList.end(); ++i) {
112  if ((*i)->readyTime > entry->readyTime) {
113  return readyList.insert(i, entry);
114  }
115  }
116  panic("Failed to add to ready list.");
117  }
118 
121 
124 
125  public:
126 
133  Queue(const std::string &_label, int num_entries, int reserve,
134  const std::string &name) :
135  Named(name),
136  label(_label), numEntries(num_entries + reserve),
137  numReserve(reserve), entries(numEntries, name + ".entry"),
138  _numInService(0), allocated(0)
139  {
140  for (int i = 0; i < numEntries; ++i) {
141  freeList.push_back(&entries[i]);
142  }
143  }
144 
145  bool isEmpty() const
146  {
147  return allocated == 0;
148  }
149 
150  bool isFull() const
151  {
152  return (allocated >= numEntries - numReserve);
153  }
154 
155  int numInService() const
156  {
157  return _numInService;
158  }
159 
168  Entry* findMatch(Addr blk_addr, bool is_secure,
169  bool ignore_uncacheable = true) const
170  {
171  for (const auto& entry : allocatedList) {
172  // we ignore any entries allocated for uncacheable
173  // accesses and simply ignore them when matching, in the
174  // cache we never check for matches when adding new
175  // uncacheable entries, and we do not want normal
176  // cacheable accesses being added to an WriteQueueEntry
177  // serving an uncacheable access
178  if (!(ignore_uncacheable && entry->isUncacheable()) &&
179  entry->matchBlockAddr(blk_addr, is_secure)) {
180  return entry;
181  }
182  }
183  return nullptr;
184  }
185 
187  {
188  pkt->pushLabel(label);
189  for (const auto& entry : allocatedList) {
190  if (entry->matchBlockAddr(pkt) &&
191  entry->trySatisfyFunctional(pkt)) {
192  pkt->popLabel();
193  return true;
194  }
195  }
196  pkt->popLabel();
197  return false;
198  }
199 
207  Entry* findPending(const QueueEntry* entry) const
208  {
209  for (const auto& ready_entry : readyList) {
210  if (ready_entry->conflictAddr(entry)) {
211  return ready_entry;
212  }
213  }
214  return nullptr;
215  }
216 
221  Entry* getNext() const
222  {
223  if (readyList.empty() || readyList.front()->readyTime > curTick()) {
224  return nullptr;
225  }
226  return readyList.front();
227  }
228 
230  {
231  return readyList.empty() ? MaxTick : readyList.front()->readyTime;
232  }
233 
240  virtual void
242  {
243  allocatedList.erase(entry->allocIter);
244  freeList.push_front(entry);
245  allocated--;
246  if (entry->inService) {
247  _numInService--;
248  } else {
249  readyList.erase(entry->readyIter);
250  }
251  entry->deallocate();
252  if (drainState() == DrainState::Draining && allocated == 0) {
253  // Notify the drain manager that we have completed
254  // draining if there are no other outstanding requests in
255  // this queue.
256  DPRINTF(Drain, "Queue now empty, signalling drained\n");
257  signalDrainDone();
258  }
259  }
260 
261  DrainState drain() override
262  {
264  }
265 };
266 
267 } // namespace gem5
268 
269 #endif //__MEM_CACHE_QUEUE_HH__
#define DPRINTF(x,...)
Definition: trace.hh:186
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
Interface for objects that might require draining before checkpointing.
Definition: drain.hh:235
Interface for things with names.
Definition: named.hh:39
virtual std::string name() const
Definition: named.hh:47
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
void pushLabel(const std::string &lbl)
Push label for PrintReq (safe to call unconditionally).
Definition: packet.hh:1448
void popLabel()
Pop label for PrintReq (safe to call unconditionally).
Definition: packet.hh:1458
A queue entry base class, to be used by both the MSHRs and write-queue entries.
Definition: queue_entry.hh:63
A high-level queue interface, to be used by both the MSHR queue and the write buffer.
Definition: queue.hh:71
DrainState drain() override
Draining is the process of clearing out the states of SimObjects.These are the SimObjects that are pa...
Definition: queue.hh:261
Queue(const std::string &_label, int num_entries, int reserve, const std::string &name)
Create a queue with a given number of entries.
Definition: queue.hh:133
Entry::List readyList
Holds pointers to entries that haven't been sent downstream.
Definition: queue.hh:100
virtual void deallocate(Entry *entry)
Removes the given entry from the queue.
Definition: queue.hh:241
bool isFull() const
Definition: queue.hh:150
Entry::List freeList
Holds non allocated entries.
Definition: queue.hh:102
Entry * findPending(const QueueEntry *entry) const
Find any pending requests that overlap the given request of a different queue.
Definition: queue.hh:207
bool isEmpty() const
Definition: queue.hh:145
std::vector< Entry > entries
Actual storage.
Definition: queue.hh:96
bool trySatisfyFunctional(PacketPtr pkt)
Definition: queue.hh:186
const std::string label
Local label (for functional print requests)
Definition: queue.hh:73
const int numReserve
The number of entries to hold as a temporary overflow space.
Definition: queue.hh:93
Tick nextReadyTime() const
Definition: queue.hh:229
Entry::List allocatedList
Holds pointers to all allocated entries.
Definition: queue.hh:98
Entry * getNext() const
Returns the WriteQueueEntry at the head of the readyList.
Definition: queue.hh:221
Entry::Iterator addToReadyList(Entry *entry)
Definition: queue.hh:104
int allocated
The number of currently allocated entries.
Definition: queue.hh:123
Entry * findMatch(Addr blk_addr, bool is_secure, bool ignore_uncacheable=true) const
Find the first entry that matches the provided address.
Definition: queue.hh:168
int _numInService
The number of entries that are in service.
Definition: queue.hh:120
int numInService() const
Definition: queue.hh:155
const int numEntries
The total number of entries in this queue.
Definition: queue.hh:85
void signalDrainDone() const
Signal that an object is drained.
Definition: drain.hh:305
DrainState drainState() const
Return the current drain state of an object.
Definition: drain.hh:324
DrainState
Object drain/handover states.
Definition: drain.hh:75
@ Draining
Draining buffers pending serialization/handover.
@ Drained
Buffers drained, ready for serialization/handover.
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
Bitfield< 7 > i
Definition: misc_types.hh:67
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
uint64_t Tick
Tick count type.
Definition: types.hh:58
const Tick MaxTick
Definition: types.hh:60
Declaration of the Packet class.
Generic queue entry.

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