gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
queue.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2013, 2015-2016 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  * Authors: Erik Hallnor
41  * Andreas Sandberg
42  * Andreas Hansson
43  */
44 
49 #ifndef __MEM_CACHE_QUEUE_HH__
50 #define __MEM_CACHE_QUEUE_HH__
51 
52 #include <cassert>
53 
54 #include "base/trace.hh"
55 #include "debug/Drain.hh"
56 #include "mem/cache/queue_entry.hh"
57 #include "sim/drain.hh"
58 
63 template<class Entry>
64 class Queue : public Drainable
65 {
66  protected:
68  const std::string label;
69 
76  const int numEntries;
77 
84  const int numReserve;
85 
89  typename Entry::List allocatedList;
91  typename Entry::List readyList;
93  typename Entry::List freeList;
94 
95  typename Entry::Iterator addToReadyList(Entry* entry)
96  {
97  if (readyList.empty() ||
98  readyList.back()->readyTime <= entry->readyTime) {
99  return readyList.insert(readyList.end(), entry);
100  }
101 
102  for (auto i = readyList.begin(); i != readyList.end(); ++i) {
103  if ((*i)->readyTime > entry->readyTime) {
104  return readyList.insert(i, entry);
105  }
106  }
107  assert(false);
108  return readyList.end(); // keep stupid compilers happy
109  }
110 
113 
116 
117  public:
118 
125  Queue(const std::string &_label, int num_entries, int reserve) :
126  label(_label), numEntries(num_entries + reserve),
128  allocated(0)
129  {
130  for (int i = 0; i < numEntries; ++i) {
131  freeList.push_back(&entries[i]);
132  }
133  }
134 
135  bool isEmpty() const
136  {
137  return allocated == 0;
138  }
139 
140  bool isFull() const
141  {
142  return (allocated >= numEntries - numReserve);
143  }
144 
145  int numInService() const
146  {
147  return _numInService;
148  }
149 
156  Entry* findMatch(Addr blk_addr, bool is_secure) const
157  {
158  for (const auto& entry : allocatedList) {
159  // we ignore any entries allocated for uncacheable
160  // accesses and simply ignore them when matching, in the
161  // cache we never check for matches when adding new
162  // uncacheable entries, and we do not want normal
163  // cacheable accesses being added to an WriteQueueEntry
164  // serving an uncacheable access
165  if (!entry->isUncacheable() && entry->blkAddr == blk_addr &&
166  entry->isSecure == is_secure) {
167  return entry;
168  }
169  }
170  return nullptr;
171  }
172 
173  bool checkFunctional(PacketPtr pkt, Addr blk_addr)
174  {
175  pkt->pushLabel(label);
176  for (const auto& entry : allocatedList) {
177  if (entry->blkAddr == blk_addr && entry->checkFunctional(pkt)) {
178  pkt->popLabel();
179  return true;
180  }
181  }
182  pkt->popLabel();
183  return false;
184  }
185 
192  Entry* findPending(Addr blk_addr, bool is_secure) const
193  {
194  for (const auto& entry : readyList) {
195  if (entry->blkAddr == blk_addr && entry->isSecure == is_secure) {
196  return entry;
197  }
198  }
199  return nullptr;
200  }
201 
206  Entry* getNext() const
207  {
208  if (readyList.empty() || readyList.front()->readyTime > curTick()) {
209  return nullptr;
210  }
211  return readyList.front();
212  }
213 
215  {
216  return readyList.empty() ? MaxTick : readyList.front()->readyTime;
217  }
218 
225  void deallocate(Entry *entry)
226  {
227  allocatedList.erase(entry->allocIter);
228  freeList.push_front(entry);
229  allocated--;
230  if (entry->inService) {
231  _numInService--;
232  } else {
233  readyList.erase(entry->readyIter);
234  }
235  entry->deallocate();
236  if (drainState() == DrainState::Draining && allocated == 0) {
237  // Notify the drain manager that we have completed
238  // draining if there are no other outstanding requests in
239  // this queue.
240  DPRINTF(Drain, "Queue now empty, signalling drained\n");
241  signalDrainDone();
242  }
243  }
244 
245  DrainState drain() override
246  {
248  }
249 };
250 
251 #endif //__MEM_CACHE_QUEUE_HH__
Entry * findMatch(Addr blk_addr, bool is_secure) const
Find the first WriteQueueEntry that matches the provided address.
Definition: queue.hh:156
#define DPRINTF(x,...)
Definition: trace.hh:212
Entry * findPending(Addr blk_addr, bool is_secure) const
Find any pending requests that overlap the given request.
Definition: queue.hh:192
Entry::List readyList
Holds pointers to entries that haven't been sent downstream.
Definition: queue.hh:91
Bitfield< 7 > i
Definition: miscregs.hh:1378
DrainState
Object drain/handover states.
Definition: drain.hh:71
Running normally.
bool isFull() const
Definition: queue.hh:140
Entry::Iterator addToReadyList(Entry *entry)
Definition: queue.hh:95
const int numReserve
The number of entries to hold as a temporary overflow space.
Definition: queue.hh:84
void pushLabel(const std::string &lbl)
Push label for PrintReq (safe to call unconditionally).
Definition: packet.hh:1160
A high-level queue interface, to be used by both the MSHR queue and the write buffer.
Definition: queue.hh:64
bool checkFunctional(PacketPtr pkt, Addr blk_addr)
Definition: queue.hh:173
void deallocate(Entry *entry)
Removes the given entry from the queue.
Definition: queue.hh:225
Interface for objects that might require draining before checkpointing.
Definition: drain.hh:223
const Tick MaxTick
Definition: types.hh:65
Tick curTick()
The current simulated tick.
Definition: core.hh:47
Generic queue entry.
uint64_t Tick
Tick count type.
Definition: types.hh:63
DrainState drain() override
Notify an object that it needs to drain its state.
Definition: queue.hh:245
void popLabel()
Pop label for PrintReq (safe to call unconditionally).
Definition: packet.hh:1170
const int numEntries
The total number of entries in this queue.
Definition: queue.hh:76
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
Draining buffers pending serialization/handover.
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
Entry::List freeList
Holds non allocated entries.
Definition: queue.hh:93
Tick nextReadyTime() const
Definition: queue.hh:214
int numInService() const
Definition: queue.hh:145
const std::string label
Local label (for functional print requests)
Definition: queue.hh:68
void signalDrainDone() const
Signal that an object is drained.
Definition: drain.hh:267
Entry * getNext() const
Returns the WriteQueueEntry at the head of the readyList.
Definition: queue.hh:206
Entry::List allocatedList
Holds pointers to all allocated entries.
Definition: queue.hh:89
DrainState drainState() const
Return the current drain state of an object.
Definition: drain.hh:282
bool isEmpty() const
Definition: queue.hh:135
Queue(const std::string &_label, int num_entries, int reserve)
Create a queue with a given number of entries.
Definition: queue.hh:125
int _numInService
The number of entries that are in service.
Definition: queue.hh:112
std::vector< Entry > entries
Actual storage.
Definition: queue.hh:87
int allocated
The number of currently allocated entries.
Definition: queue.hh:115

Generated on Fri Jun 9 2017 13:03:48 for gem5 by doxygen 1.8.6