gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
mshr.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) 2002-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  * Nikos Nikoleris
42  */
43 
49 #ifndef __MEM_CACHE_MSHR_HH__
50 #define __MEM_CACHE_MSHR_HH__
51 
52 #include <cassert>
53 #include <iosfwd>
54 #include <list>
55 #include <string>
56 #include <vector>
57 
58 #include "base/printable.hh"
59 #include "base/types.hh"
60 #include "mem/cache/queue_entry.hh"
61 #include "mem/packet.hh"
62 #include "mem/request.hh"
63 #include "sim/core.hh"
64 
65 class BaseCache;
66 
72 class MSHR : public QueueEntry, public Printable
73 {
74 
78  template<typename Entry>
79  friend class Queue;
80  friend class MSHRQueue;
81 
82  private:
83 
86 
112 
115 
118 
119  public:
120 
123 
125  bool isForward;
126 
127  class Target : public QueueEntry::Target {
128  public:
129 
130  enum Source {
134  };
135 
136  const Source source;
137 
154 
155  const bool allocOnFill;
156 
158  Target(PacketPtr _pkt, Tick _readyTime, Counter _order,
159  Source _source, bool _markedPending, bool alloc_on_fill)
160  : QueueEntry::Target(_pkt, _readyTime, _order), source(_source),
161  markedPending(_markedPending), allocOnFill(alloc_on_fill)
162  {}
163  };
164 
165  class TargetList : public std::list<Target> {
166 
167  public:
177 
178  TargetList();
179 
188  void updateFlags(PacketPtr pkt, Target::Source source,
189  bool alloc_on_fill);
190 
197  void init(Addr blk_addr, Addr blk_size) {
198  blkAddr = blk_addr;
199  blkSize = blk_size;
200  writesBitmap.resize(blk_size);
201 
202  resetFlags();
203  }
204 
205  void resetFlags() {
206  canMergeWrites = true;
207  std::fill(writesBitmap.begin(), writesBitmap.end(), false);
208 
209  needsWritable = false;
210  hasUpgrade = false;
211  allocOnFill = false;
212  hasFromCache = false;
213  }
214 
221  void populateFlags();
222 
230  void updateWriteFlags(PacketPtr pkt);
231 
238  bool isReset() const {
239  return !needsWritable && !hasUpgrade && !allocOnFill &&
240  !hasFromCache && canMergeWrites;
241  }
242 
255  void add(PacketPtr pkt, Tick readyTime, Counter order,
256  Target::Source source, bool markPending, bool alloc_on_fill);
257 
262  void replaceUpgrades();
263 
264  void clearDownstreamPending();
265  void clearDownstreamPending(iterator begin, iterator end);
267  void print(std::ostream &os, int verbosity,
268  const std::string &prefix) const;
269 
277  bool isWholeLineWrite() const
278  {
279  return std::all_of(writesBitmap.begin(), writesBitmap.end(),
280  [](bool i) { return i; });
281  }
282 
283  private:
286 
289 
292 
293  // NOTE: std::vector<bool> might not meet satisfy the
294  // ForwardIterator requirement and therefore cannot be used
295  // for writesBitmap.
301  };
302 
306  typedef List::iterator Iterator;
307 
314  bool needsWritable() const { return targets.needsWritable; }
315 
316  bool isCleaning() const {
317  PacketPtr pkt = targets.front().pkt;
318  return pkt->isClean();
319  }
320 
321  bool isPendingModified() const {
322  assert(inService); return pendingModified;
323  }
324 
325  bool hasPostInvalidate() const {
326  assert(inService); return postInvalidate;
327  }
328 
329  bool hasPostDowngrade() const {
330  assert(inService); return postDowngrade;
331  }
332 
333  bool sendPacket(BaseCache &cache) override;
334 
335  bool allocOnFill() const {
336  return targets.allocOnFill;
337  }
338 
344  bool hasFromCache() const {
345  return targets.hasFromCache;
346  }
347 
348  private:
358  void promoteIf(const std::function<bool (Target &)>& pred);
359 
364  Iterator readyIter;
365 
370  Iterator allocIter;
371 
374 
376 
377  public:
385  bool isWholeLineWrite() const {
386  return targets.isWholeLineWrite();
387  }
388 
398  void allocate(Addr blk_addr, unsigned blk_size, PacketPtr pkt,
399  Tick when_ready, Counter _order, bool alloc_on_fill);
400 
401  void markInService(bool pending_modified_resp);
402 
403  void clearDownstreamPending();
404 
408  void deallocate();
409 
414  void allocateTarget(PacketPtr target, Tick when, Counter order,
415  bool alloc_on_fill);
416  bool handleSnoop(PacketPtr target, Counter order);
417 
419  MSHR();
420 
425  int getNumTargets() const
426  { return targets.size() + deferredTargets.size(); }
427 
441 
446  bool hasTargets() const { return !targets.empty(); }
447 
453  {
454  assert(hasTargets());
455  return &targets.front();
456  }
457 
461  void popTarget()
462  {
463  targets.pop_front();
464  }
465 
466  bool promoteDeferredTargets();
467 
476  void promoteReadable();
477 
485  void promoteWritable();
486 
488 
493  void delay(Tick delay_ticks)
494  {
495  assert(readyTime <= curTick());
496  readyTime = curTick() + delay_ticks;
497  }
498 
502  void print(std::ostream &os,
503  int verbosity = 0,
504  const std::string &prefix = "") const override;
511  std::string print() const;
512 
513  bool matchBlockAddr(const Addr addr, const bool is_secure) const override;
514  bool matchBlockAddr(const PacketPtr pkt) const override;
515  bool conflictAddr(const QueueEntry* entry) const override;
516 };
517 
518 #endif // __MEM_CACHE_MSHR_HH__
Iterator readyIter
Pointer to this MSHR on the ready list.
Definition: mshr.hh:364
bool needsWritable() const
The pending* and post* flags are only valid if inService is true.
Definition: mshr.hh:314
bool hasPostInvalidate() const
Definition: mshr.hh:325
bool inService
True if the entry has been sent downstream.
Definition: queue_entry.hh:108
std::string print() const
A no-args wrapper of print(std::ostream...) meant to be invoked from DPRINTFs avoiding string overhea...
Definition: mshr.cc:732
A Class for maintaining a list of pending and allocated memory requests.
Definition: mshr_queue.hh:61
std::list< MSHR * > List
A list of MSHRs.
Definition: mshr.hh:304
Bitfield< 7 > i
void resetFlags()
Definition: mshr.hh:205
bool isWholeLineWrite() const
Check if this MSHR contains only compatible writes, and if they span the entire cache line...
Definition: mshr.hh:385
bool trySatisfyFunctional(PacketPtr pkt)
Definition: mshr.cc:685
const Source source
Request from cpu, memory, or prefetcher?
Definition: mshr.hh:136
int getNumTargets() const
Returns the current number of allocated targets.
Definition: mshr.hh:425
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
bool hasPostDowngrade() const
Definition: mshr.hh:329
ip6_addr_t addr
Definition: inet.hh:335
bool isClean() const
Definition: packet.hh:545
bool allocOnFill
Set when the response should allocate on fill.
Definition: mshr.hh:171
bool isPendingModified() const
Definition: mshr.hh:321
Addr blkSize
Size of the cache block.
Definition: mshr.hh:288
void promoteWritable()
Promotes deferred targets that do not require writable.
Definition: mshr.cc:658
TargetList deferredTargets
Definition: mshr.hh:375
bool allocOnFill() const
Definition: mshr.hh:335
A high-level queue interface, to be used by both the MSHR queue and the write buffer.
Definition: queue.hh:70
Bitfield< 17 > os
Definition: misc.hh:805
List::iterator Iterator
MSHR list iterator.
Definition: mshr.hh:306
bool postInvalidate
Did we snoop an invalidate while waiting for data?
Definition: mshr.hh:114
Target(PacketPtr _pkt, Tick _readyTime, Counter _order, Source _source, bool _markedPending, bool alloc_on_fill)
Definition: mshr.hh:158
const bool allocOnFill
Should the response servicing this target list allocate in the cache?
Definition: mshr.hh:155
void popTarget()
Pop first target.
Definition: mshr.hh:461
Tick curTick()
The current simulated tick.
Definition: core.hh:47
bool canMergeWrites
Indicates whether we can merge incoming write requests.
Definition: mshr.hh:291
bool isCleaning() const
Definition: mshr.hh:316
bool isReset() const
Tests if the flags of this TargetList have their default values.
Definition: mshr.hh:238
void allocateTarget(PacketPtr target, Tick when, Counter order, bool alloc_on_fill)
Add a request to the list of targets.
Definition: mshr.cc:372
void markInService(bool pending_modified_resp)
Definition: mshr.cc:339
void init(Addr blk_addr, Addr blk_size)
Reset state.
Definition: mshr.hh:197
bool needsWritable
Definition: mshr.hh:168
Generic queue entry.
uint64_t Tick
Tick count type.
Definition: types.hh:63
Miss Status and handling Register.
Definition: mshr.hh:72
QueueEntry::Target * getTarget() override
Returns a reference to the first target.
Definition: mshr.hh:452
A basic cache interface.
Definition: base.hh:93
bool isWholeLineWrite() const
Check if this list contains writes that cover an entire cache line.
Definition: mshr.hh:277
STL list class.
Definition: stl.hh:54
std::vector< char > writesBitmap
Track which bytes are written by requests in this target list.
Definition: mshr.hh:300
TargetList targets
List of all requests that match the address.
Definition: mshr.hh:373
bool conflictAddr(const QueueEntry *entry) const override
Check if given entry&#39;s packets conflict with this&#39; entries packets.
Definition: mshr.cc:754
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
bool markedPending
We use this flag to track whether we have cleared the downstreamPending flag for the MSHR of the cach...
Definition: mshr.hh:153
const Tick readyTime
Time when request is ready to be serviced.
Definition: queue_entry.hh:89
void promoteIf(const std::function< bool(Target &)> &pred)
Promotes deferred targets that satisfy a predicate.
Definition: mshr.cc:614
int64_t Counter
Statistics counter type.
Definition: types.hh:58
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:255
Abstract base class for objects which support being printed to a stream for debugging.
Definition: printable.hh:44
A queue entry is holding packets that will be serviced as soon as resources are available.
Definition: queue_entry.hh:86
A queue entry base class, to be used by both the MSHRs and write-queue entries.
Definition: queue_entry.hh:61
bool hasUpgrade
Definition: mshr.hh:169
bool wasWholeLineWrite
Track if we sent this as a whole line write or not.
Definition: mshr.hh:122
void clearDownstreamPending()
Definition: mshr.cc:329
Addr blkAddr
Block aligned address.
Definition: queue_entry.hh:114
Declaration of the Packet class.
Addr blkAddr
Address of the cache block for this list of targets.
Definition: mshr.hh:285
bool matchBlockAddr(const Addr addr, const bool is_secure) const override
Check if entry corresponds to the one being looked for.
Definition: mshr.cc:740
bool handleSnoop(PacketPtr target, Counter order)
Definition: mshr.cc:417
TargetList extractServiceableTargets(PacketPtr pkt)
Extracts the subset of the targets that can be serviced given a received response.
Definition: mshr.cc:541
bool isForward
True if the entry is just a simple forward from an upper level.
Definition: mshr.hh:125
void promoteReadable()
Promotes deferred targets that do not require writable.
Definition: mshr.cc:637
MSHR()
A simple constructor.
Definition: mshr.cc:64
bool promoteDeferredTargets()
Definition: mshr.cc:575
bool pendingModified
Here we use one flag to track both if:
Definition: mshr.hh:111
const PacketPtr pkt
Pending request packet.
Definition: queue_entry.hh:91
bool hasFromCache
Determine whether there was at least one non-snooping target coming from another cache.
Definition: mshr.hh:176
bool hasTargets() const
Returns true if there are targets left.
Definition: mshr.hh:446
const Counter order
Global order (for memory consistency mgmt)
Definition: queue_entry.hh:90
bool sendPacket(BaseCache &cache) override
Send this queue entry as a downstream packet, with the exact behaviour depending on the specific entr...
Definition: mshr.cc:700
void deallocate()
Mark this MSHR as free.
Definition: mshr.cc:360
Iterator allocIter
Pointer to this MSHR on the allocated list.
Definition: mshr.hh:370
void delay(Tick delay_ticks)
Adds a delay relative to the current tick to the current MSHR.
Definition: mshr.hh:493
void allocate(Addr blk_addr, unsigned blk_size, PacketPtr pkt, Tick when_ready, Counter _order, bool alloc_on_fill)
Allocate a miss to this MSHR.
Definition: mshr.cc:299
unsigned blkSize
Block size of the cache.
Definition: queue_entry.hh:117
bool downstreamPending
Flag set by downstream caches.
Definition: mshr.hh:85
bool hasFromCache() const
Determine if there are non-deferred requests from other caches.
Definition: mshr.hh:344
bool postDowngrade
Did we snoop a read while waiting for data?
Definition: mshr.hh:117

Generated on Fri Feb 28 2020 16:27:01 for gem5 by doxygen 1.8.13