gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
blk.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-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  */
43 
48 #ifndef __MEM_CACHE_BLK_HH__
49 #define __MEM_CACHE_BLK_HH__
50 
51 #include <list>
52 
53 #include "base/printable.hh"
54 #include "mem/packet.hh"
55 #include "mem/request.hh"
56 
60 enum CacheBlkStatusBits : unsigned {
62  BlkValid = 0x01,
64  BlkWritable = 0x02,
66  BlkReadable = 0x04,
68  BlkDirty = 0x08,
72  BlkSecure = 0x40,
73 };
74 
79 class CacheBlk
80 {
81  public:
83  uint32_t task_id;
84 
94  uint8_t *data;
95 
97  typedef unsigned State;
98 
101 
104 
109  int set, way;
110 
112  bool isTouched;
113 
115  unsigned refCount;
116 
119 
121 
122  protected:
127  class Lock {
128  public:
129  ContextID contextId; // locking context
130  Addr lowAddr; // low address of lock range
131  Addr highAddr; // high address of lock range
132 
133  // check for matching execution context, and an address that
134  // is within the lock
135  bool matches(const RequestPtr req) const
136  {
137  Addr req_low = req->getPaddr();
138  Addr req_high = req_low + req->getSize() -1;
139  return (contextId == req->contextId()) &&
140  (req_low >= lowAddr) && (req_high <= highAddr);
141  }
142 
143  // check if a request is intersecting and thus invalidating the lock
144  bool intersects(const RequestPtr req) const
145  {
146  Addr req_low = req->getPaddr();
147  Addr req_high = req_low + req->getSize() - 1;
148 
149  return (req_low <= highAddr) && (req_high >= lowAddr);
150  }
151 
152  Lock(const RequestPtr req)
153  : contextId(req->contextId()),
154  lowAddr(req->getPaddr()),
155  highAddr(lowAddr + req->getSize() - 1)
156  {
157  }
158  };
159 
163 
164  public:
165 
167  : task_id(ContextSwitchTaskId::Unknown),
168  tag(0), data(0), status(0), whenReady(0),
169  set(-1), way(-1), isTouched(false), refCount(0),
170  srcMasterId(Request::invldMasterId),
171  tickInserted(0)
172  {}
173 
174  CacheBlk(const CacheBlk&) = delete;
175  CacheBlk& operator=(const CacheBlk&) = delete;
176 
181  bool isWritable() const
182  {
183  const State needed_bits = BlkWritable | BlkValid;
184  return (status & needed_bits) == needed_bits;
185  }
186 
193  bool isReadable() const
194  {
195  const State needed_bits = BlkReadable | BlkValid;
196  return (status & needed_bits) == needed_bits;
197  }
198 
203  bool isValid() const
204  {
205  return (status & BlkValid) != 0;
206  }
207 
211  void invalidate()
212  {
213  status = 0;
214  isTouched = false;
215  lockList.clear();
216  }
217 
222  bool isDirty() const
223  {
224  return (status & BlkDirty) != 0;
225  }
226 
232  bool wasPrefetched() const
233  {
234  return (status & BlkHWPrefetched) != 0;
235  }
236 
241  bool isSecure() const
242  {
243  return (status & BlkSecure) != 0;
244  }
245 
251  {
252  assert(pkt->isLLSC());
253  auto l = lockList.begin();
254  while (l != lockList.end()) {
255  if (l->intersects(pkt->req))
256  l = lockList.erase(l);
257  else
258  ++l;
259  }
260 
261  lockList.emplace_front(pkt->req);
262  }
263 
269  {
270  auto l = lockList.begin();
271  while (l != lockList.end()) {
272  if (l->intersects(req) && l->contextId != req->contextId()) {
273  l = lockList.erase(l);
274  } else {
275  ++l;
276  }
277  }
278  }
279 
286  std::string print() const
287  {
312  unsigned state = isWritable() << 2 | isDirty() << 1 | isValid();
313  char s = '?';
314  switch (state) {
315  case 0b111: s = 'M'; break;
316  case 0b011: s = 'O'; break;
317  case 0b101: s = 'E'; break;
318  case 0b001: s = 'S'; break;
319  case 0b000: s = 'I'; break;
320  default: s = 'T'; break; // @TODO add other types
321  }
322  return csprintf("state: %x (%c) valid: %d writable: %d readable: %d "
323  "dirty: %d tag: %x", status, s, isValid(),
324  isWritable(), isReadable(), isDirty(), tag);
325  }
326 
333  {
334  assert(pkt->isWrite());
335 
336  // common case
337  if (!pkt->isLLSC() && lockList.empty())
338  return true;
339 
340  RequestPtr req = pkt->req;
341 
342  if (pkt->isLLSC()) {
343  // it's a store conditional... have to check for matching
344  // load locked.
345  bool success = false;
346 
347  auto l = lockList.begin();
348  while (!success && l != lockList.end()) {
349  if (l->matches(pkt->req)) {
350  // it's a store conditional, and as far as the
351  // memory system can tell, the requesting
352  // context's lock is still valid.
353  success = true;
354  lockList.erase(l);
355  } else {
356  ++l;
357  }
358  }
359 
360  req->setExtraData(success ? 1 : 0);
361  // clear any intersected locks from other contexts (our LL
362  // should already have cleared them)
363  clearLoadLocks(req);
364  return success;
365  } else {
366  // a normal write, if there is any lock not from this
367  // context we clear the list, thus for a private cache we
368  // never clear locks on normal writes
369  clearLoadLocks(req);
370  return true;
371  }
372  }
373 };
374 
382 {
384  public:
387  void print(std::ostream &o, int verbosity = 0,
388  const std::string &prefix = "") const;
389 };
390 
398 {
399  public:
400 
402  virtual ~CacheBlkVisitor() {}
403 
404  virtual bool operator()(CacheBlk &blk) = 0;
405 };
406 
407 #endif //__MEM_CACHE_BLK_HH__
bool isDirty() const
Check to see if a block has been written.
Definition: blk.hh:222
bool isLLSC() const
Definition: packet.hh:527
virtual bool operator()(CacheBlk &blk)=0
State status
The current status of this block.
Definition: blk.hh:100
Tick whenReady
Which curTick() will this block be accessable.
Definition: blk.hh:103
ContextID contextId() const
Accessor function for context ID.
Definition: request.hh:694
Addr tag
Data block tag value.
Definition: blk.hh:86
valid, readable
Definition: blk.hh:62
void setExtraData(uint64_t extraData)
Accessor function for store conditional return value.
Definition: request.hh:680
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
void clearLoadLocks(RequestPtr req)
Clear the any load lock that intersect the request, and is from a different context.
Definition: blk.hh:268
bool isWrite() const
Definition: packet.hh:503
Simple class to provide virtual print() method on cache blocks without allocating a vtable pointer fo...
Definition: blk.hh:381
CacheBlk()
Definition: blk.hh:166
unsigned refCount
Number of references to this block since it was brought in.
Definition: blk.hh:115
bool isWritable() const
Checks the write permissions of this block.
Definition: blk.hh:181
ContextID contextId
Definition: blk.hh:129
CacheBlkPrintWrapper(CacheBlk *_blk)
Definition: blk.hh:385
Tick tickInserted
Definition: blk.hh:120
bool matches(const RequestPtr req) const
Definition: blk.hh:135
int way
Definition: blk.hh:109
CacheBlk * blk
Definition: blk.hh:383
A Basic Cache block.
Definition: blk.hh:79
std::string csprintf(const char *format, const Args &...args)
Definition: cprintf.hh:161
bool checkWrite(PacketPtr pkt)
Handle interaction of load-locked operations and stores.
Definition: blk.hh:332
void trackLoadLocked(PacketPtr pkt)
Track the fact that a local locked was issued to the block.
Definition: blk.hh:250
Bitfield< 4 > s
Definition: miscregs.hh:1738
block holds data from the secure memory space
Definition: blk.hh:72
uint64_t Tick
Tick count type.
Definition: types.hh:63
unsigned State
block state: OR of CacheBlkStatusBit
Definition: blk.hh:97
write permission
Definition: blk.hh:64
CacheBlkVisitor()
Definition: blk.hh:401
Addr getPaddr() const
Definition: request.hh:519
const RequestPtr req
A pointer to the original request.
Definition: packet.hh:304
virtual ~CacheBlkVisitor()
Definition: blk.hh:402
STL list class.
Definition: stl.hh:54
void invalidate()
Invalidate the block and clear all state.
Definition: blk.hh:211
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:142
A Packet is used to encapsulate a transfer between two objects in the memory system (e...
Definition: packet.hh:245
Abstract base class for objects which support being printed to a stream for debugging.
Definition: printable.hh:44
Represents that the indicated thread context has a "lock" on the block, in the LL/SC sense...
Definition: blk.hh:127
bool isTouched
whether this block has been touched
Definition: blk.hh:112
CacheBlk & operator=(const CacheBlk &)=delete
read permission (yes, block can be valid but not readable)
Definition: blk.hh:66
std::string print() const
Pretty-print a tag, and interpret state bits to readable form including mapping to a MOESI state...
Definition: blk.hh:286
Declaration of the Packet class.
dirty (modified)
Definition: blk.hh:68
int srcMasterId
holds the source requestor ID for this block.
Definition: blk.hh:118
std::list< Lock > lockList
List of thread contexts that have performed a load-locked (LL) on the block since the last store...
Definition: blk.hh:162
Addr highAddr
Definition: blk.hh:131
uint32_t task_id
Task Id associated with this block.
Definition: blk.hh:83
void print(std::ostream &o, int verbosity=0, const std::string &prefix="") const
Definition: blk.cc:46
int set
The set and way this block belongs to.
Definition: blk.hh:109
bool isReadable() const
Checks the read permissions of this block.
Definition: blk.hh:193
bool isValid() const
Checks that a block is valid.
Definition: blk.hh:203
unsigned getSize() const
Definition: request.hh:552
bool intersects(const RequestPtr req) const
Definition: blk.hh:144
Base class for cache block visitor, operating on the cache block base class (later subclassed for the...
Definition: blk.hh:397
Bitfield< 5 > l
bool wasPrefetched() const
Check if this block was the result of a hardware prefetch, yet to be touched.
Definition: blk.hh:232
uint8_t * data
Contains a copy of the data in this block for easy access.
Definition: blk.hh:94
block was a hardware prefetch yet unaccessed
Definition: blk.hh:70
Addr lowAddr
Definition: blk.hh:130
int ContextID
Globally unique thread context ID.
Definition: types.hh:175
virtual ~CacheBlkPrintWrapper()
Definition: blk.hh:386
CacheBlkStatusBits
Cache block status bit assignments.
Definition: blk.hh:60
Lock(const RequestPtr req)
Definition: blk.hh:152
bool isSecure() const
Check if this block holds data from the secure memory space.
Definition: blk.hh:241

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