gem5  v20.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/trace.hh"
54 #include "base/types.hh"
55 #include "debug/Drain.hh"
56 #include "mem/cache/queue_entry.hh"
57 #include "mem/packet.hh"
58 #include "sim/core.hh"
59 #include "sim/drain.hh"
60 
65 template<class Entry>
66 class Queue : public Drainable
67 {
68  static_assert(std::is_base_of<QueueEntry, Entry>::value,
69  "Entry must be derived from QueueEntry");
70 
71  protected:
73  const std::string label;
74 
81  const int numEntries;
82 
89  const int numReserve;
90 
94  typename Entry::List allocatedList;
96  typename Entry::List readyList;
98  typename Entry::List freeList;
99 
100  typename Entry::Iterator addToReadyList(Entry* entry)
101  {
102  if (readyList.empty() ||
103  readyList.back()->readyTime <= entry->readyTime) {
104  return readyList.insert(readyList.end(), entry);
105  }
106 
107  for (auto i = readyList.begin(); i != readyList.end(); ++i) {
108  if ((*i)->readyTime > entry->readyTime) {
109  return readyList.insert(i, entry);
110  }
111  }
112  panic("Failed to add to ready list.");
113  }
114 
117 
120 
121  public:
122 
129  Queue(const std::string &_label, int num_entries, int reserve) :
130  label(_label), numEntries(num_entries + reserve),
132  allocated(0)
133  {
134  for (int i = 0; i < numEntries; ++i) {
135  freeList.push_back(&entries[i]);
136  }
137  }
138 
139  bool isEmpty() const
140  {
141  return allocated == 0;
142  }
143 
144  bool isFull() const
145  {
146  return (allocated >= numEntries - numReserve);
147  }
148 
149  int numInService() const
150  {
151  return _numInService;
152  }
153 
162  Entry* findMatch(Addr blk_addr, bool is_secure,
163  bool ignore_uncacheable = true) const
164  {
165  for (const auto& entry : allocatedList) {
166  // we ignore any entries allocated for uncacheable
167  // accesses and simply ignore them when matching, in the
168  // cache we never check for matches when adding new
169  // uncacheable entries, and we do not want normal
170  // cacheable accesses being added to an WriteQueueEntry
171  // serving an uncacheable access
172  if (!(ignore_uncacheable && entry->isUncacheable()) &&
173  entry->matchBlockAddr(blk_addr, is_secure)) {
174  return entry;
175  }
176  }
177  return nullptr;
178  }
179 
181  {
182  pkt->pushLabel(label);
183  for (const auto& entry : allocatedList) {
184  if (entry->matchBlockAddr(pkt) &&
185  entry->trySatisfyFunctional(pkt)) {
186  pkt->popLabel();
187  return true;
188  }
189  }
190  pkt->popLabel();
191  return false;
192  }
193 
201  Entry* findPending(const QueueEntry* entry) const
202  {
203  for (const auto& ready_entry : readyList) {
204  if (ready_entry->conflictAddr(entry)) {
205  return ready_entry;
206  }
207  }
208  return nullptr;
209  }
210 
215  Entry* getNext() const
216  {
217  if (readyList.empty() || readyList.front()->readyTime > curTick()) {
218  return nullptr;
219  }
220  return readyList.front();
221  }
222 
224  {
225  return readyList.empty() ? MaxTick : readyList.front()->readyTime;
226  }
227 
234  void deallocate(Entry *entry)
235  {
236  allocatedList.erase(entry->allocIter);
237  freeList.push_front(entry);
238  allocated--;
239  if (entry->inService) {
240  _numInService--;
241  } else {
242  readyList.erase(entry->readyIter);
243  }
244  entry->deallocate();
245  if (drainState() == DrainState::Draining && allocated == 0) {
246  // Notify the drain manager that we have completed
247  // draining if there are no other outstanding requests in
248  // this queue.
249  DPRINTF(Drain, "Queue now empty, signalling drained\n");
250  signalDrainDone();
251  }
252  }
253 
254  DrainState drain() override
255  {
257  }
258 };
259 
260 #endif //__MEM_CACHE_QUEUE_HH__
Queue::allocated
int allocated
The number of currently allocated entries.
Definition: queue.hh:119
Queue::getNext
Entry * getNext() const
Returns the WriteQueueEntry at the head of the readyList.
Definition: queue.hh:215
Queue::readyList
Entry::List readyList
Holds pointers to entries that haven't been sent downstream.
Definition: queue.hh:96
queue_entry.hh
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
Queue::addToReadyList
Entry::Iterator addToReadyList(Entry *entry)
Definition: queue.hh:100
Queue::numInService
int numInService() const
Definition: queue.hh:149
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
Packet::pushLabel
void pushLabel(const std::string &lbl)
Push label for PrintReq (safe to call unconditionally).
Definition: packet.hh:1393
std::vector< Entry >
Queue::numReserve
const int numReserve
The number of entries to hold as a temporary overflow space.
Definition: queue.hh:89
packet.hh
DrainState::Drained
@ Drained
Buffers drained, ready for serialization/handover.
DrainState
DrainState
Object drain/handover states.
Definition: drain.hh:71
Drainable
Interface for objects that might require draining before checkpointing.
Definition: drain.hh:230
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
Queue::deallocate
void deallocate(Entry *entry)
Removes the given entry from the queue.
Definition: queue.hh:234
Drainable::signalDrainDone
void signalDrainDone() const
Signal that an object is drained.
Definition: drain.hh:301
Queue::numEntries
const int numEntries
The total number of entries in this queue.
Definition: queue.hh:81
Queue::findMatch
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:162
Queue::freeList
Entry::List freeList
Holds non allocated entries.
Definition: queue.hh:98
core.hh
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Queue::drain
DrainState drain() override
Draining is the process of clearing out the states of SimObjects.These are the SimObjects that are pa...
Definition: queue.hh:254
Drainable::drainState
DrainState drainState() const
Return the current drain state of an object.
Definition: drain.hh:320
Queue::findPending
Entry * findPending(const QueueEntry *entry) const
Find any pending requests that overlap the given request of a different queue.
Definition: queue.hh:201
types.hh
Packet
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:257
Queue
A high-level queue interface, to be used by both the MSHR queue and the write buffer.
Definition: queue.hh:66
Queue::isFull
bool isFull() const
Definition: queue.hh:144
logging.hh
Queue::nextReadyTime
Tick nextReadyTime() const
Definition: queue.hh:223
QueueEntry
A queue entry base class, to be used by both the MSHRs and write-queue entries.
Definition: queue_entry.hh:58
drain.hh
trace.hh
Queue::allocatedList
Entry::List allocatedList
Holds pointers to all allocated entries.
Definition: queue.hh:94
Queue::Queue
Queue(const std::string &_label, int num_entries, int reserve)
Create a queue with a given number of entries.
Definition: queue.hh:129
Queue::_numInService
int _numInService
The number of entries that are in service.
Definition: queue.hh:116
Queue::isEmpty
bool isEmpty() const
Definition: queue.hh:139
Queue::label
const std::string label
Local label (for functional print requests)
Definition: queue.hh:69
MaxTick
const Tick MaxTick
Definition: types.hh:65
Queue::trySatisfyFunctional
bool trySatisfyFunctional(PacketPtr pkt)
Definition: queue.hh:180
Packet::popLabel
void popLabel()
Pop label for PrintReq (safe to call unconditionally).
Definition: packet.hh:1403
DrainState::Draining
@ Draining
Draining buffers pending serialization/handover.
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
curTick
Tick curTick()
The current simulated tick.
Definition: core.hh:45
Queue::entries
std::vector< Entry > entries
Actual storage.
Definition: queue.hh:92

Generated on Wed Sep 30 2020 14:02:12 for gem5 by doxygen 1.8.17