gem5  v22.1.0.0
packet.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2019, 2021 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) 2006 The Regents of The University of Michigan
15  * Copyright (c) 2010,2015 Advanced Micro Devices, Inc.
16  * All rights reserved.
17  *
18  * Redistribution and use in source and binary forms, with or without
19  * modification, are permitted provided that the following conditions are
20  * met: redistributions of source code must retain the above copyright
21  * notice, this list of conditions and the following disclaimer;
22  * redistributions in binary form must reproduce the above copyright
23  * notice, this list of conditions and the following disclaimer in the
24  * documentation and/or other materials provided with the distribution;
25  * neither the name of the copyright holders nor the names of its
26  * contributors may be used to endorse or promote products derived from
27  * this software without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40  */
41 
47 #ifndef __MEM_PACKET_HH__
48 #define __MEM_PACKET_HH__
49 
50 #include <bitset>
51 #include <cassert>
52 #include <initializer_list>
53 #include <list>
54 
55 #include "base/addr_range.hh"
56 #include "base/cast.hh"
57 #include "base/compiler.hh"
58 #include "base/flags.hh"
59 #include "base/logging.hh"
60 #include "base/printable.hh"
61 #include "base/types.hh"
62 #include "mem/htm.hh"
63 #include "mem/request.hh"
64 #include "sim/byteswap.hh"
65 
66 namespace gem5
67 {
68 
69 class Packet;
70 typedef Packet *PacketPtr;
71 typedef uint8_t* PacketDataPtr;
73 typedef uint64_t PacketId;
74 
75 class MemCmd
76 {
77  friend class Packet;
78 
79  public:
83  enum Command
84  {
94  WriteClean, // writes dirty data below without evicting
103  SCUpgradeReq, // Special "weak" upgrade for StoreCond
105  SCUpgradeFailReq, // Failed SCUpgradeReq in MSHR (never sent)
106  UpgradeFailResp, // Valid for SCUpgradeReq only
113  StoreCondFailReq, // Failed StoreCondReq in MSHR (never sent)
121  // MessageReq and MessageResp are deprecated.
123  MemSyncReq, // memory synchronization request (e.g., cache invalidate)
124  MemSyncResp, // memory synchronization response
130  // Error responses
131  // @TODO these should be classified as responses rather than
132  // requests; coding them as requests initially for backwards
133  // compatibility
134  InvalidDestError, // packet dest field invalid
135  BadAddressError, // memory address invalid
136  ReadError, // packet dest unable to fulfill read command
137  WriteError, // packet dest unable to fulfill write command
138  FunctionalReadError, // unable to fulfill functional read
139  FunctionalWriteError, // unable to fulfill functional write
140  // Fake simulator-only commands
141  PrintReq, // Print state matching address
142  FlushReq, //request for a cache flush
143  InvalidateReq, // request for address to be invalidated
145  // hardware transactional memory
149  // Tlb shootdown
152  };
153 
154  private:
159  {
180  };
181 
182  static constexpr unsigned long long
183  buildAttributes(std::initializer_list<Attribute> attrs)
184  {
185  unsigned long long ret = 0;
186  for (const auto &attr: attrs)
187  ret |= (1ULL << attr);
188  return ret;
189  }
190 
195  struct CommandInfo
196  {
198  const std::bitset<NUM_COMMAND_ATTRIBUTES> attributes;
203  const std::string str;
204 
205  CommandInfo(std::initializer_list<Attribute> attrs,
206  Command _response, const std::string &_str) :
207  attributes(buildAttributes(attrs)), response(_response), str(_str)
208  {}
209  };
210 
212  static const CommandInfo commandInfo[];
213 
214  private:
215 
217 
218  bool
220  {
221  return commandInfo[cmd].attributes[attrib] != 0;
222  }
223 
224  public:
225 
226  bool isRead() const { return testCmdAttrib(IsRead); }
227  bool isWrite() const { return testCmdAttrib(IsWrite); }
228  bool isUpgrade() const { return testCmdAttrib(IsUpgrade); }
229  bool isRequest() const { return testCmdAttrib(IsRequest); }
230  bool isResponse() const { return testCmdAttrib(IsResponse); }
231  bool needsWritable() const { return testCmdAttrib(NeedsWritable); }
232  bool needsResponse() const { return testCmdAttrib(NeedsResponse); }
233  bool isInvalidate() const { return testCmdAttrib(IsInvalidate); }
234  bool isEviction() const { return testCmdAttrib(IsEviction); }
235  bool isClean() const { return testCmdAttrib(IsClean); }
236  bool fromCache() const { return testCmdAttrib(FromCache); }
237 
241  bool isWriteback() const { return testCmdAttrib(IsEviction) &&
243 
249  bool hasData() const { return testCmdAttrib(HasData); }
250  bool isLLSC() const { return testCmdAttrib(IsLlsc); }
251  bool isLockedRMW() const { return testCmdAttrib(IsLockedRMW); }
252  bool isSWPrefetch() const { return testCmdAttrib(IsSWPrefetch); }
253  bool isHWPrefetch() const { return testCmdAttrib(IsHWPrefetch); }
254  bool isPrefetch() const { return testCmdAttrib(IsSWPrefetch) ||
256  bool isError() const { return testCmdAttrib(IsError); }
257  bool isPrint() const { return testCmdAttrib(IsPrint); }
258  bool isFlush() const { return testCmdAttrib(IsFlush); }
259 
260  bool
261  isDemand() const
262  {
263  return (cmd == ReadReq || cmd == WriteReq ||
264  cmd == WriteLineReq || cmd == ReadExReq ||
265  cmd == ReadCleanReq || cmd == ReadSharedReq);
266  }
267 
268  Command
270  {
271  return commandInfo[cmd].response;
272  }
273 
275  const std::string &toString() const { return commandInfo[cmd].str; }
276  int toInt() const { return (int)cmd; }
277 
278  MemCmd(Command _cmd) : cmd(_cmd) { }
279  MemCmd(int _cmd) : cmd((Command)_cmd) { }
281 
282  bool operator==(MemCmd c2) const { return (cmd == c2.cmd); }
283  bool operator!=(MemCmd c2) const { return (cmd != c2.cmd); }
284 };
285 
293 class Packet : public Printable
294 {
295  public:
296  typedef uint32_t FlagsType;
298 
299  private:
300  enum : FlagsType
301  {
302  // Flags to transfer across when copying a packet
303  COPY_FLAGS = 0x000000FF,
304 
305  // Flags that are used to create reponse packets
306  RESPONDER_FLAGS = 0x00000009,
307 
308  // Does this packet have sharers (which means it should not be
309  // considered writable) or not. See setHasSharers below.
310  HAS_SHARERS = 0x00000001,
311 
312  // Special control flags
314  EXPRESS_SNOOP = 0x00000002,
315 
320 
321  // Snoop co-ordination flag to indicate that a cache is
322  // responding to a snoop. See setCacheResponding below.
323  CACHE_RESPONDING = 0x00000008,
324 
325  // The writeback/writeclean should be propagated further
326  // downstream by the receiver
327  WRITE_THROUGH = 0x00000010,
328 
329  // Response co-ordination flag for cache maintenance
330  // operations
331  SATISFIED = 0x00000020,
332 
333  // hardware transactional memory
334 
335  // Indicates that this packet/request has returned from the
336  // cache hierarchy in a failed transaction. The core is
337  // notified like this.
338  FAILS_TRANSACTION = 0x00000040,
339 
340  // Indicates that this packet/request originates in the CPU executing
341  // in transactional mode, i.e. in a transaction.
342  FROM_TRANSACTION = 0x00000080,
343 
345  VALID_ADDR = 0x00000100,
346  VALID_SIZE = 0x00000200,
347 
350  STATIC_DATA = 0x00001000,
354  DYNAMIC_DATA = 0x00002000,
355 
358  SUPPRESS_FUNC_ERROR = 0x00008000,
359 
360  // Signal block present to squash prefetch and cache evict packets
361  // through express snoop flag
362  BLOCK_CACHED = 0x00010000
363  };
364 
366 
367  public:
369 
372 
373  const PacketId id;
374 
377 
378  private:
387 
391 
393  bool _isSecure;
394 
396  unsigned size;
397 
402 
403  // Quality of Service priority value
404  uint8_t _qosValue;
405 
406  // hardware transactional memory
407 
414 
420 
421  public:
422 
430  uint32_t headerDelay;
431 
438  uint32_t snoopDelay;
439 
448  uint32_t payloadDelay;
449 
467  struct SenderState
468  {
471  virtual ~SenderState() {}
472  };
473 
478  class PrintReqState : public SenderState
479  {
480  private:
485  {
486  const std::string label;
487  std::string *prefix;
489  LabelStackEntry(const std::string &_label, std::string *_prefix);
490  };
491 
494 
495  std::string *curPrefixPtr;
496 
497  public:
498  std::ostream &os;
499  const int verbosity;
500 
501  PrintReqState(std::ostream &os, int verbosity = 0);
502  ~PrintReqState();
503 
507  const std::string &curPrefix() { return *curPrefixPtr; }
508 
514  void pushLabel(const std::string &lbl,
515  const std::string &prefix = " ");
516 
520  void popLabel();
521 
527  void printLabels();
528 
533  void printObj(Printable *obj);
534  };
535 
545 
554  void pushSenderState(SenderState *sender_state);
555 
565 
573  template <typename T>
575  {
576  T *t = NULL;
577  SenderState* sender_state = senderState;
578  while (t == NULL && sender_state != NULL) {
579  t = dynamic_cast<T*>(sender_state);
580  sender_state = sender_state->predecessor;
581  }
582  return t;
583  }
584 
587  const std::string &cmdString() const { return cmd.toString(); }
588 
590  inline int cmdToIndex() const { return cmd.toInt(); }
591 
592  bool isRead() const { return cmd.isRead(); }
593  bool isWrite() const { return cmd.isWrite(); }
594  bool isDemand() const { return cmd.isDemand(); }
595  bool isUpgrade() const { return cmd.isUpgrade(); }
596  bool isRequest() const { return cmd.isRequest(); }
597  bool isResponse() const { return cmd.isResponse(); }
598  bool needsWritable() const
599  {
600  // we should never check if a response needsWritable, the
601  // request has this flag, and for a response we should rather
602  // look at the hasSharers flag (if not set, the response is to
603  // be considered writable)
604  assert(isRequest());
605  return cmd.needsWritable();
606  }
607  bool needsResponse() const { return cmd.needsResponse(); }
608  bool isInvalidate() const { return cmd.isInvalidate(); }
609  bool isEviction() const { return cmd.isEviction(); }
610  bool isClean() const { return cmd.isClean(); }
611  bool fromCache() const { return cmd.fromCache(); }
612  bool isWriteback() const { return cmd.isWriteback(); }
613  bool hasData() const { return cmd.hasData(); }
614  bool hasRespData() const
615  {
616  MemCmd resp_cmd = cmd.responseCommand();
617  return resp_cmd.hasData();
618  }
619  bool isLLSC() const { return cmd.isLLSC(); }
620  bool isLockedRMW() const { return cmd.isLockedRMW(); }
621  bool isError() const { return cmd.isError(); }
622  bool isPrint() const { return cmd.isPrint(); }
623  bool isFlush() const { return cmd.isFlush(); }
624 
625  bool isWholeLineWrite(unsigned blk_size)
626  {
627  return (cmd == MemCmd::WriteReq || cmd == MemCmd::WriteLineReq) &&
628  getOffset(blk_size) == 0 && getSize() == blk_size;
629  }
630 
632 
652  {
653  assert(isRequest());
654  assert(!flags.isSet(CACHE_RESPONDING));
656  }
657  bool cacheResponding() const { return flags.isSet(CACHE_RESPONDING); }
684  bool hasSharers() const { return flags.isSet(HAS_SHARERS); }
686 
700  bool isExpressSnoop() const { return flags.isSet(EXPRESS_SNOOP); }
701 
712  {
713  assert(cacheResponding());
714  assert(!responderHadWritable());
716  }
717  bool responderHadWritable() const
718  { return flags.isSet(RESPONDER_HAD_WRITABLE); }
719 
727  void copyResponderFlags(const PacketPtr pkt);
728 
734  {
735  assert(cmd.isWrite() &&
738  }
740  bool writeThrough() const { return flags.isSet(WRITE_THROUGH); }
741 
748  {
749  assert(cmd.isClean());
750  assert(!flags.isSet(SATISFIED));
752  }
753  bool satisfied() const { return flags.isSet(SATISFIED); }
754 
758  bool isBlockCached() const { return flags.isSet(BLOCK_CACHED); }
760 
767  inline uint8_t qosValue() const { return _qosValue; }
768 
775  inline void qosValue(const uint8_t qos_value)
776  { _qosValue = qos_value; }
777 
778  inline RequestorID requestorId() const { return req->requestorId(); }
779 
780  // Network error conditions... encapsulate them as methods since
781  // their encoding keeps changing (from result field to command
782  // field, etc.)
783  void
785  {
786  assert(isResponse());
788  }
789 
790  // Command error conditions. The request is sent to target but the target
791  // cannot make it.
792  void
794  {
795  assert(isResponse());
796  if (isWrite()) {
798  } else {
800  }
801  }
802 
803  void copyError(Packet *pkt) { assert(pkt->isError()); cmd = pkt->cmd; }
804 
805  Addr getAddr() const { assert(flags.isSet(VALID_ADDR)); return addr; }
813  void setAddr(Addr _addr) { assert(flags.isSet(VALID_ADDR)); addr = _addr; }
814 
815  unsigned getSize() const { assert(flags.isSet(VALID_SIZE)); return size; }
816 
822  AddrRange getAddrRange() const;
823 
824  Addr getOffset(unsigned int blk_size) const
825  {
826  return getAddr() & Addr(blk_size - 1);
827  }
828 
829  Addr getBlockAddr(unsigned int blk_size) const
830  {
831  return getAddr() & ~(Addr(blk_size - 1));
832  }
833 
834  bool isSecure() const
835  {
836  assert(flags.isSet(VALID_ADDR));
837  return _isSecure;
838  }
839 
843  AtomicOpFunctor *getAtomicOp() const { return req->getAtomicOpFunctor(); }
844  bool isAtomicOp() const { return req->isAtomic(); }
845 
850  void
852  {
853  assert(isLLSC());
854  assert(isWrite());
856  }
857 
862  void
864  {
865  assert(isLLSC());
866  assert(isRead());
868  }
869 
875  Packet(const RequestPtr &_req, MemCmd _cmd)
876  : cmd(_cmd), id((PacketId)_req.get()), req(_req),
877  data(nullptr), addr(0), _isSecure(false), size(0),
878  _qosValue(0),
881  headerDelay(0), snoopDelay(0),
882  payloadDelay(0), senderState(NULL)
883  {
884  flags.clear();
885  if (req->hasPaddr()) {
886  addr = req->getPaddr();
888  _isSecure = req->isSecure();
889  }
890 
901  if (req->isHTMCmd()) {
903  assert(addr == 0x0);
904  }
905  if (req->hasSize()) {
906  size = req->getSize();
908  }
909  }
910 
916  Packet(const RequestPtr &_req, MemCmd _cmd, int _blkSize, PacketId _id = 0)
917  : cmd(_cmd), id(_id ? _id : (PacketId)_req.get()), req(_req),
918  data(nullptr), addr(0), _isSecure(false),
919  _qosValue(0),
922  headerDelay(0),
923  snoopDelay(0), payloadDelay(0), senderState(NULL)
924  {
925  flags.clear();
926  if (req->hasPaddr()) {
927  addr = req->getPaddr() & ~(_blkSize - 1);
929  _isSecure = req->isSecure();
930  }
931  size = _blkSize;
933  }
934 
942  Packet(const PacketPtr pkt, bool clear_flags, bool alloc_data)
943  : cmd(pkt->cmd), id(pkt->id), req(pkt->req),
944  data(nullptr),
945  addr(pkt->addr), _isSecure(pkt->_isSecure), size(pkt->size),
946  bytesValid(pkt->bytesValid),
947  _qosValue(pkt->qosValue()),
950  headerDelay(pkt->headerDelay),
951  snoopDelay(0),
954  {
955  if (!clear_flags)
956  flags.set(pkt->flags & COPY_FLAGS);
957 
958  flags.set(pkt->flags & (VALID_ADDR|VALID_SIZE));
959 
960  if (pkt->isHtmTransactional())
962 
963  if (pkt->htmTransactionFailedInCache()) {
966  );
967  }
968 
969  // should we allocate space for data, or not, the express
970  // snoops do not need to carry any data as they only serve to
971  // co-ordinate state changes
972  if (alloc_data) {
973  // even if asked to allocate data, if the original packet
974  // holds static data, then the sender will not be doing
975  // any memcpy on receiving the response, thus we simply
976  // carry the pointer forward
977  if (pkt->flags.isSet(STATIC_DATA)) {
978  data = pkt->data;
980  } else {
981  allocate();
982  }
983  }
984  }
985 
989  static MemCmd
991  {
992  if (req->isHTMCmd()) {
993  if (req->isHTMAbort())
994  return MemCmd::HTMAbort;
995  else
996  return MemCmd::HTMReq;
997  } else if (req->isLLSC())
998  return MemCmd::LoadLockedReq;
999  else if (req->isPrefetchEx())
1000  return MemCmd::SoftPFExReq;
1001  else if (req->isPrefetch())
1002  return MemCmd::SoftPFReq;
1003  else if (req->isLockedRMW())
1004  return MemCmd::LockedRMWReadReq;
1005  else
1006  return MemCmd::ReadReq;
1007  }
1008 
1012  static MemCmd
1014  {
1015  if (req->isLLSC())
1016  return MemCmd::StoreCondReq;
1017  else if (req->isSwap() || req->isAtomic())
1018  return MemCmd::SwapReq;
1019  else if (req->isCacheInvalidate()) {
1020  return req->isCacheClean() ? MemCmd::CleanInvalidReq :
1022  } else if (req->isCacheClean()) {
1023  return MemCmd::CleanSharedReq;
1024  } else if (req->isLockedRMW()) {
1026  } else
1027  return MemCmd::WriteReq;
1028  }
1029 
1034  static PacketPtr
1036  {
1037  return new Packet(req, makeReadCmd(req));
1038  }
1039 
1040  static PacketPtr
1042  {
1043  return new Packet(req, makeWriteCmd(req));
1044  }
1045 
1050  {
1051  deleteData();
1052  }
1053 
1058  void
1060  {
1061  assert(needsResponse());
1062  assert(isRequest());
1063  cmd = cmd.responseCommand();
1064 
1065  // responses are never express, even if the snoop that
1066  // triggered them was
1068  }
1069 
1070  void
1072  {
1073  makeResponse();
1074  }
1075 
1076  void
1078  {
1079  makeResponse();
1080  }
1081 
1082  void
1084  {
1085  if (!success) {
1086  if (isWrite()) {
1088  } else {
1090  }
1091  }
1092  }
1093 
1094  void
1095  setSize(unsigned size)
1096  {
1097  assert(!flags.isSet(VALID_SIZE));
1098 
1099  this->size = size;
1100  flags.set(VALID_SIZE);
1101  }
1102 
1112  bool matchBlockAddr(const Addr addr, const bool is_secure,
1113  const int blk_size) const;
1114 
1123  bool matchBlockAddr(const PacketPtr pkt, const int blk_size) const;
1124 
1132  bool matchAddr(const Addr addr, const bool is_secure) const;
1133 
1141  bool matchAddr(const PacketPtr pkt) const;
1142 
1143  public:
1160  template <typename T>
1161  void
1163  {
1165  data = (PacketDataPtr)p;
1167  }
1168 
1177  template <typename T>
1178  void
1179  dataStaticConst(const T *p)
1180  {
1182  data = const_cast<PacketDataPtr>(p);
1184  }
1185 
1198  template <typename T>
1199  void
1201  {
1203  data = (PacketDataPtr)p;
1205  }
1206 
1210  template <typename T>
1211  T*
1213  {
1215  assert(!isMaskedWrite());
1216  return (T*)data;
1217  }
1218 
1219  template <typename T>
1220  const T*
1221  getConstPtr() const
1222  {
1224  return (const T*)data;
1225  }
1226 
1231  template <typename T>
1232  T getBE() const;
1233 
1238  template <typename T>
1239  T getLE() const;
1240 
1245  template <typename T>
1246  T get(ByteOrder endian) const;
1247 
1249  template <typename T>
1250  void setBE(T v);
1251 
1253  template <typename T>
1254  void setLE(T v);
1255 
1260  template <typename T>
1261  void set(T v, ByteOrder endian);
1262 
1267  uint64_t getUintX(ByteOrder endian) const;
1268 
1274  void setUintX(uint64_t w, ByteOrder endian);
1275 
1279  void
1280  setData(const uint8_t *p)
1281  {
1282  // we should never be copying data onto itself, which means we
1283  // must idenfity packets with static data, as they carry the
1284  // same pointer from source to destination and back
1285  assert(p != getPtr<uint8_t>() || flags.isSet(STATIC_DATA));
1286 
1287  if (p != getPtr<uint8_t>()) {
1288  // for packet with allocated dynamic data, we copy data from
1289  // one to the other, e.g. a forwarded response to a response
1290  std::memcpy(getPtr<uint8_t>(), p, getSize());
1291  }
1292  }
1293 
1298  void
1299  setDataFromBlock(const uint8_t *blk_data, int blkSize)
1300  {
1301  setData(blk_data + getOffset(blkSize));
1302  }
1303 
1308  void
1309  writeData(uint8_t *p) const
1310  {
1311  if (!isMaskedWrite()) {
1312  std::memcpy(p, getConstPtr<uint8_t>(), getSize());
1313  } else {
1314  assert(req->getByteEnable().size() == getSize());
1315  // Write only the enabled bytes
1316  const uint8_t *base = getConstPtr<uint8_t>();
1317  for (unsigned int i = 0; i < getSize(); i++) {
1318  if (req->getByteEnable()[i]) {
1319  p[i] = *(base + i);
1320  }
1321  // Disabled bytes stay untouched
1322  }
1323  }
1324  }
1325 
1332  void
1333  writeDataToBlock(uint8_t *blk_data, int blkSize) const
1334  {
1335  writeData(blk_data + getOffset(blkSize));
1336  }
1337 
1342  void
1344  {
1345  if (flags.isSet(DYNAMIC_DATA))
1346  delete [] data;
1347 
1349  data = NULL;
1350  }
1351 
1353  void
1355  {
1356  // if either this command or the response command has a data
1357  // payload, actually allocate space
1358  if (hasData() || hasRespData()) {
1361  data = new uint8_t[getSize()];
1362  }
1363  }
1364 
1368  template <typename T>
1369  T getRaw() const;
1370 
1372  template <typename T>
1373  void setRaw(T v);
1374 
1375  public:
1385  bool
1387  {
1388  if (other->isMaskedWrite()) {
1389  // Do not forward data if overlapping with a masked write
1390  if (_isSecure == other->isSecure() &&
1391  getAddr() <= (other->getAddr() + other->getSize() - 1) &&
1392  other->getAddr() <= (getAddr() + getSize() - 1)) {
1393  warn("Trying to check against a masked write, skipping."
1394  " (addr: 0x%x, other addr: 0x%x)", getAddr(),
1395  other->getAddr());
1396  }
1397  return false;
1398  }
1399  // all packets that are carrying a payload should have a valid
1400  // data pointer
1401  return trySatisfyFunctional(other, other->getAddr(), other->isSecure(),
1402  other->getSize(),
1403  other->hasData() ?
1404  other->getPtr<uint8_t>() : NULL);
1405  }
1406 
1411  bool
1413  {
1414  return cmd == MemCmd::HardPFReq || isEviction();
1415  }
1416 
1421  bool
1423  {
1425  }
1426 
1427  bool
1429  {
1430  return (cmd == MemCmd::WriteReq && req->isMasked());
1431  }
1432 
1440  bool
1441  trySatisfyFunctional(Printable *obj, Addr base, bool is_secure, int size,
1442  uint8_t *_data);
1443 
1447  void
1448  pushLabel(const std::string &lbl)
1449  {
1450  if (isPrint())
1451  safe_cast<PrintReqState*>(senderState)->pushLabel(lbl);
1452  }
1453 
1457  void
1459  {
1460  if (isPrint())
1461  safe_cast<PrintReqState*>(senderState)->popLabel();
1462  }
1463 
1464  void print(std::ostream &o, int verbosity = 0,
1465  const std::string &prefix = "") const;
1466 
1473  std::string print() const;
1474 
1475  // hardware transactional memory
1476 
1485  void makeHtmTransactionalReqResponse(const HtmCacheFailure ret_code);
1486 
1491  void setHtmTransactional(uint64_t val);
1492 
1497  bool isHtmTransactional() const;
1498 
1505  uint64_t getHtmTransactionUid() const;
1506 
1512  void setHtmTransactionFailedInCache(const HtmCacheFailure ret_code);
1513 
1519  bool htmTransactionFailedInCache() const;
1520 
1526 };
1527 
1528 } // namespace gem5
1529 
1530 #endif //__MEM_PACKET_HH
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:82
bool isFlush() const
Definition: packet.hh:258
bool isSWPrefetch() const
Definition: packet.hh:252
bool isInvalidate() const
Definition: packet.hh:233
MemCmd(int _cmd)
Definition: packet.hh:279
const std::string & toString() const
Return the string to a cmd given by idx.
Definition: packet.hh:275
bool isRequest() const
Definition: packet.hh:229
static constexpr unsigned long long buildAttributes(std::initializer_list< Attribute > attrs)
Definition: packet.hh:183
bool isResponse() const
Definition: packet.hh:230
bool isRead() const
Definition: packet.hh:226
bool operator==(MemCmd c2) const
Definition: packet.hh:282
bool isWriteback() const
A writeback is an eviction that carries data.
Definition: packet.hh:241
static const CommandInfo commandInfo[]
Array to map Command enum to associated info.
Definition: packet.hh:212
bool isEviction() const
Definition: packet.hh:234
bool isHWPrefetch() const
Definition: packet.hh:253
Command cmd
Definition: packet.hh:216
Command
List of all commands associated with a packet.
Definition: packet.hh:84
@ LoadLockedReq
Definition: packet.hh:111
@ InvalidDestError
Definition: packet.hh:134
@ FunctionalReadError
Definition: packet.hh:138
@ ReadCleanReq
Definition: packet.hh:109
@ ReadRespWithInvalidate
Definition: packet.hh:88
@ CleanSharedReq
Definition: packet.hh:126
@ WritebackDirty
Definition: packet.hh:92
@ CleanInvalidResp
Definition: packet.hh:129
@ StoreCondFailReq
Definition: packet.hh:113
@ LockedRMWReadReq
Definition: packet.hh:115
@ StoreCondResp
Definition: packet.hh:114
@ InvalidateResp
Definition: packet.hh:144
@ CleanSharedResp
Definition: packet.hh:127
@ WriteClean
Definition: packet.hh:94
@ LockedRMWWriteReq
Definition: packet.hh:117
@ ReadSharedReq
Definition: packet.hh:110
@ BadAddressError
Definition: packet.hh:135
@ LockedRMWReadResp
Definition: packet.hh:116
@ MemFenceResp
Definition: packet.hh:125
@ SoftPFExReq
Definition: packet.hh:97
@ WritebackClean
Definition: packet.hh:93
@ SoftPFResp
Definition: packet.hh:99
@ LockedRMWWriteResp
Definition: packet.hh:118
@ WriteLineReq
Definition: packet.hh:101
@ SCUpgradeReq
Definition: packet.hh:103
@ NUM_MEM_CMDS
Definition: packet.hh:151
@ FunctionalWriteError
Definition: packet.hh:139
@ InvalidCmd
Definition: packet.hh:85
@ SCUpgradeFailReq
Definition: packet.hh:105
@ UpgradeFailResp
Definition: packet.hh:106
@ CleanInvalidReq
Definition: packet.hh:128
@ InvalidateReq
Definition: packet.hh:143
@ StoreCondReq
Definition: packet.hh:112
@ CleanEvict
Definition: packet.hh:95
@ WriteCompleteResp
Definition: packet.hh:91
MemCmd(Command _cmd)
Definition: packet.hh:278
bool isLockedRMW() const
Definition: packet.hh:251
bool isWrite() const
Definition: packet.hh:227
bool operator!=(MemCmd c2) const
Definition: packet.hh:283
bool needsResponse() const
Definition: packet.hh:232
bool testCmdAttrib(MemCmd::Attribute attrib) const
Definition: packet.hh:219
bool isLLSC() const
Definition: packet.hh:250
bool isPrint() const
Definition: packet.hh:257
Command responseCommand() const
Definition: packet.hh:269
bool isError() const
Definition: packet.hh:256
bool isDemand() const
Definition: packet.hh:261
bool hasData() const
Check if this particular packet type carries payload data.
Definition: packet.hh:249
bool needsWritable() const
Definition: packet.hh:231
bool isUpgrade() const
Definition: packet.hh:228
bool isClean() const
Definition: packet.hh:235
bool isPrefetch() const
Definition: packet.hh:254
int toInt() const
Definition: packet.hh:276
bool fromCache() const
Definition: packet.hh:236
Attribute
List of command attributes.
Definition: packet.hh:159
@ IsInvalidate
Definition: packet.hh:163
@ IsLockedRMW
x86 locked RMW access
Definition: packet.hh:173
@ NeedsResponse
Requester needs response from target.
Definition: packet.hh:168
@ IsRead
Data flows from responder to requester.
Definition: packet.hh:160
@ NeedsWritable
Requires writable copy to complete in-cache.
Definition: packet.hh:165
@ IsFlush
Flush the address from caches.
Definition: packet.hh:177
@ FromCache
Request originated from a caching agent.
Definition: packet.hh:178
@ IsSWPrefetch
Definition: packet.hh:170
@ IsError
Error response.
Definition: packet.hh:175
@ IsClean
Cleans any existing dirty blocks.
Definition: packet.hh:164
@ IsWrite
Data flows from requester to responder.
Definition: packet.hh:161
@ IsPrint
Print state matching address (for debugging)
Definition: packet.hh:176
@ IsHWPrefetch
Definition: packet.hh:171
@ HasData
There is an associated payload.
Definition: packet.hh:174
@ IsLlsc
Alpha/MIPS LL or SC access.
Definition: packet.hh:172
@ IsResponse
Issue by responder.
Definition: packet.hh:167
@ IsRequest
Issued by requester.
Definition: packet.hh:166
@ NUM_COMMAND_ATTRIBUTES
Definition: packet.hh:179
Object used to maintain state of a PrintReq.
Definition: packet.hh:479
void popLabel()
Pop a label off the label stack.
Definition: packet.cc:444
void printObj(Printable *obj)
Print a Printable object to os, because it matched the address on a PrintReq.
Definition: packet.cc:470
PrintReqState(std::ostream &os, int verbosity=0)
Definition: packet.cc:414
void pushLabel(const std::string &lbl, const std::string &prefix=" ")
Push a label onto the label stack, and prepend the given prefix string onto the current prefix.
Definition: packet.cc:435
std::list< LabelStackEntry > LabelStack
Definition: packet.hh:492
const std::string & curPrefix()
Returns the current line prefix.
Definition: packet.hh:507
std::string * curPrefixPtr
Definition: packet.hh:495
void printLabels()
Print all of the pending unprinted labels on the stack.
Definition: packet.cc:453
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
Definition: packet.hh:294
void setExpressSnoop()
The express snoop flag is used for two purposes.
Definition: packet.hh:699
bool responderHadWritable() const
Definition: packet.hh:717
bool isUpgrade() const
Definition: packet.hh:595
void setBadAddress()
Definition: packet.hh:784
bool isRead() const
Definition: packet.hh:592
bool isSecure() const
Definition: packet.hh:834
T * getPtr()
get a pointer to the data ptr.
Definition: packet.hh:1212
const PacketId id
Definition: packet.hh:373
Addr addr
The address of the request.
Definition: packet.hh:390
void writeDataToBlock(uint8_t *blk_data, int blkSize) const
Copy data from the packet to the provided block pointer, which is aligned to the given block size.
Definition: packet.hh:1333
Addr getAddr() const
Definition: packet.hh:805
AtomicOpFunctor * getAtomicOp() const
Accessor function to atomic op.
Definition: packet.hh:843
void pushLabel(const std::string &lbl)
Push label for PrintReq (safe to call unconditionally).
Definition: packet.hh:1448
bool isError() const
Definition: packet.hh:621
void setUintX(uint64_t w, ByteOrder endian)
Set the value in the word w after truncating it to the length of the packet and then byteswapping it ...
Definition: packet.cc:361
bool isLockedRMW() const
Definition: packet.hh:620
void deleteData()
delete the data pointed to in the data pointer.
Definition: packet.hh:1343
void setLE(T v)
Set the value in the data pointer to v as little endian.
std::vector< bool > bytesValid
Track the bytes found that satisfy a functional read.
Definition: packet.hh:401
Packet(const PacketPtr pkt, bool clear_flags, bool alloc_data)
Alternate constructor for copying a packet.
Definition: packet.hh:942
void setWriteThrough()
A writeback/writeclean cmd gets propagated further downstream by the receiver when the flag is set.
Definition: packet.hh:733
gem5::Flags< FlagsType > Flags
Definition: packet.hh:297
Packet(const RequestPtr &_req, MemCmd _cmd, int _blkSize, PacketId _id=0)
Alternate constructor if you are trying to create a packet with a request that is for a whole block,...
Definition: packet.hh:916
bool isAtomicOp() const
Definition: packet.hh:844
void setBE(T v)
Set the value in the data pointer to v as big endian.
bool isResponse() const
Definition: packet.hh:597
Flags flags
Definition: packet.hh:365
uint32_t snoopDelay
Keep track of the extra delay incurred by snooping upwards before sending a request down the memory s...
Definition: packet.hh:438
void setHtmTransactionFailedInCache(const HtmCacheFailure ret_code)
Stipulates that this packet/request has returned from the cache hierarchy in a failed transaction.
Definition: packet.cc:493
void makeTimingResponse()
Definition: packet.hh:1077
bool needsWritable() const
Definition: packet.hh:598
T getBE() const
Get the data in the packet byte swapped from big endian to host endian.
AddrRange getAddrRange() const
Get address range to which this packet belongs.
Definition: packet.cc:243
void copyError(Packet *pkt)
Definition: packet.hh:803
bool satisfied() const
Definition: packet.hh:753
bool isDemand() const
Definition: packet.hh:594
void setAddr(Addr _addr)
Update the address of this packet mid-transaction.
Definition: packet.hh:813
static PacketPtr createWrite(const RequestPtr &req)
Definition: packet.hh:1041
bool isCleanEviction() const
Is this packet a clean eviction, including both actual clean evict packets, but also clean writebacks...
Definition: packet.hh:1422
bool needsResponse() const
Definition: packet.hh:607
void dataStatic(T *p)
Set the data pointer to the following value that should not be freed.
Definition: packet.hh:1162
@ FAILS_TRANSACTION
Definition: packet.hh:338
@ VALID_ADDR
Are the 'addr' and 'size' fields valid?
Definition: packet.hh:345
@ SUPPRESS_FUNC_ERROR
suppress the error if this packet encounters a functional access failure.
Definition: packet.hh:358
@ WRITE_THROUGH
Definition: packet.hh:327
@ RESPONDER_FLAGS
Definition: packet.hh:306
@ DYNAMIC_DATA
The data pointer points to a value that should be freed when the packet is destroyed.
Definition: packet.hh:354
@ EXPRESS_SNOOP
Special timing-mode atomic snoop for multi-level coherence.
Definition: packet.hh:314
@ CACHE_RESPONDING
Definition: packet.hh:323
@ STATIC_DATA
Is the data pointer set to a value that shouldn't be freed when the packet is destroyed?
Definition: packet.hh:350
@ FROM_TRANSACTION
Definition: packet.hh:342
@ RESPONDER_HAD_WRITABLE
Allow a responding cache to inform the cache hierarchy that it had a writable copy before responding.
Definition: packet.hh:319
@ BLOCK_CACHED
Definition: packet.hh:362
SenderState * senderState
This packet's sender state.
Definition: packet.hh:544
uint32_t payloadDelay
The extra pipelining delay from seeing the packet until the end of payload is transmitted by the comp...
Definition: packet.hh:448
void makeResponse()
Take a request packet and modify it in place to be suitable for returning as a response to that reque...
Definition: packet.hh:1059
bool matchAddr(const Addr addr, const bool is_secure) const
Check if packet corresponds to a given address and address space.
Definition: packet.cc:403
RequestorID requestorId() const
Definition: packet.hh:778
static MemCmd makeWriteCmd(const RequestPtr &req)
Generate the appropriate write MemCmd based on the Request flags.
Definition: packet.hh:1013
uint32_t headerDelay
The extra delay from seeing the packet until the header is transmitted.
Definition: packet.hh:430
int cmdToIndex() const
Return the index of this command.
Definition: packet.hh:590
MemCmd::Command Command
Definition: packet.hh:368
uint8_t _qosValue
Definition: packet.hh:404
uint32_t FlagsType
Definition: packet.hh:296
void setResponderHadWritable()
On responding to a snoop request (which only happens for Modified or Owned lines),...
Definition: packet.hh:711
Addr getOffset(unsigned int blk_size) const
Definition: packet.hh:824
~Packet()
clean up packet variables
Definition: packet.hh:1049
T * findNextSenderState() const
Go through the sender state stack and return the first instance that is of type T (as determined by a...
Definition: packet.hh:574
void clearBlockCached()
Definition: packet.hh:759
bool mustCheckAbove() const
Does the request need to check for cached copies of the same block in the memory hierarchy above.
Definition: packet.hh:1412
void pushSenderState(SenderState *sender_state)
Push a new sender state to the packet and make the current sender state the predecessor of the new on...
Definition: packet.cc:334
void setRaw(T v)
Set the value in the data pointer to v without byte swapping.
bool hasData() const
Definition: packet.hh:613
uint8_t qosValue() const
QoS Value getter Returns 0 if QoS value was never set (constructor default).
Definition: packet.hh:767
void copyResponderFlags(const PacketPtr pkt)
Copy the reponse flags from an input packet to this packet.
Definition: packet.cc:324
SenderState * popSenderState()
Pop the top of the state stack and return a pointer to it.
Definition: packet.cc:342
bool hasRespData() const
Definition: packet.hh:614
bool writeThrough() const
Definition: packet.hh:740
HtmCacheFailure getHtmTransactionFailedInCacheRC() const
If a packet/request has returned from the cache hierarchy in a failed transaction,...
Definition: packet.cc:509
bool isHtmTransactional() const
Returns whether or not this packet/request originates in the CPU executing in transactional mode,...
Definition: packet.cc:523
std::string print() const
A no-args wrapper of print(std::ostream...) meant to be invoked from DPRINTFs avoiding string overhea...
Definition: packet.cc:382
bool fromCache() const
Definition: packet.hh:611
void setData(const uint8_t *p)
Copy data into the packet from the provided pointer.
Definition: packet.hh:1280
void convertScToWrite()
It has been determined that the SC packet should successfully update memory.
Definition: packet.hh:851
bool isWrite() const
Definition: packet.hh:593
void setDataFromBlock(const uint8_t *blk_data, int blkSize)
Copy data into the packet from the provided block pointer, which is aligned to the given block size.
Definition: packet.hh:1299
bool trySatisfyFunctional(PacketPtr other)
Check a functional request against a memory value stored in another packet (i.e.
Definition: packet.hh:1386
uint64_t getHtmTransactionUid() const
If a packet/request originates in a CPU executing in transactional mode, i.e.
Definition: packet.cc:529
Addr getBlockAddr(unsigned int blk_size) const
Definition: packet.hh:829
void setBadCommand()
Definition: packet.hh:793
void set(T v, ByteOrder endian)
Set the value in the data pointer to v using the specified endianness.
const std::string & cmdString() const
Return the string name of the cmd field (for debugging and tracing).
Definition: packet.hh:587
static PacketPtr createRead(const RequestPtr &req)
Constructor-like methods that return Packets based on Request objects.
Definition: packet.hh:1035
RequestPtr req
A pointer to the original request.
Definition: packet.hh:376
bool isPrint() const
Definition: packet.hh:622
unsigned getSize() const
Definition: packet.hh:815
unsigned size
The size of the request or transfer.
Definition: packet.hh:396
void setCacheResponding()
Snoop flags.
Definition: packet.hh:651
bool isClean() const
Definition: packet.hh:610
uint64_t getUintX(ByteOrder endian) const
Get the data in the packet byte swapped from the specified endianness and zero-extended to 64 bits.
Definition: packet.cc:352
void popLabel()
Pop label for PrintReq (safe to call unconditionally).
Definition: packet.hh:1458
bool isExpressSnoop() const
Definition: packet.hh:700
void setFunctionalResponseStatus(bool success)
Definition: packet.hh:1083
bool isWriteback() const
Definition: packet.hh:612
bool _isSecure
True if the request targets the secure memory space.
Definition: packet.hh:393
void convertLlToRead()
When ruby is in use, Ruby will monitor the cache line and the phys memory should treat LL ops as norm...
Definition: packet.hh:863
void dataStaticConst(const T *p)
Set the data pointer to the following value that should not be freed.
Definition: packet.hh:1179
void setHasSharers()
On fills, the hasSharers flag is used by the caches in combination with the cacheResponding flag,...
Definition: packet.hh:683
void clearWriteThrough()
Definition: packet.hh:739
Packet(const RequestPtr &_req, MemCmd _cmd)
Constructor.
Definition: packet.hh:875
bool matchBlockAddr(const Addr addr, const bool is_secure, const int blk_size) const
Check if packet corresponds to a given block-aligned address and address space.
Definition: packet.cc:389
HtmCacheFailure htmReturnReason
Holds the return status of the transaction.
Definition: packet.hh:413
void dataDynamic(T *p)
Set the data pointer to a value that should have delete [] called on it.
Definition: packet.hh:1200
void setHtmTransactional(uint64_t val)
Stipulates that this packet/request originates in the CPU executing in transactional mode,...
Definition: packet.cc:516
void makeHtmTransactionalReqResponse(const HtmCacheFailure ret_code)
Communicates to the core that a packet was processed by the memory subsystem while running in transac...
Definition: packet.cc:477
void setSize(unsigned size)
Definition: packet.hh:1095
const T * getConstPtr() const
Definition: packet.hh:1221
static MemCmd makeReadCmd(const RequestPtr &req)
Generate the appropriate read MemCmd based on the Request flags.
Definition: packet.hh:990
bool isLLSC() const
Definition: packet.hh:619
bool cacheResponding() const
Definition: packet.hh:657
T getRaw() const
Get the data in the packet without byte swapping.
void qosValue(const uint8_t qos_value)
QoS Value setter Interface for setting QoS priority value of the packet.
Definition: packet.hh:775
void makeAtomicResponse()
Definition: packet.hh:1071
void setSatisfied()
Set when a request hits in a cache and the cache is not going to respond.
Definition: packet.hh:747
MemCmd cmd
The command field of the packet.
Definition: packet.hh:371
bool suppressFuncError() const
Definition: packet.hh:756
bool isMaskedWrite() const
Definition: packet.hh:1428
T get(ByteOrder endian) const
Get the data in the packet byte swapped from the specified endianness.
bool isInvalidate() const
Definition: packet.hh:608
bool htmTransactionFailedInCache() const
Returns whether or not this packet/request has returned from the cache hierarchy in a failed transact...
Definition: packet.cc:503
T getLE() const
Get the data in the packet byte swapped from little endian to host endian.
bool isFlush() const
Definition: packet.hh:623
void setSuppressFuncError()
Definition: packet.hh:755
void writeData(uint8_t *p) const
Copy data from the packet to the memory at the provided pointer.
Definition: packet.hh:1309
bool isWholeLineWrite(unsigned blk_size)
Definition: packet.hh:625
uint64_t htmTransactionUid
A global unique identifier of the transaction.
Definition: packet.hh:419
bool hasSharers() const
Definition: packet.hh:684
bool isBlockCached() const
Definition: packet.hh:758
void setBlockCached()
Definition: packet.hh:757
PacketDataPtr data
A pointer to the data being transferred.
Definition: packet.hh:386
void allocate()
Allocate memory for the packet.
Definition: packet.hh:1354
bool isEviction() const
Definition: packet.hh:609
bool isRequest() const
Definition: packet.hh:596
Abstract base class for objects which support being printed to a stream for debugging.
Definition: printable.hh:48
STL list class.
Definition: stl.hh:51
void set(Type mask)
Set all flag's bits matching the given mask.
Definition: flags.hh:116
bool isSet(Type mask) const
Verifies whether any bit matching the given mask is set.
Definition: flags.hh:83
void clear()
Clear all flag's bits.
Definition: flags.hh:102
bool noneSet(Type mask) const
Verifies whether no bits matching the given mask are set.
Definition: flags.hh:99
#define warn(...)
Definition: logging.hh:246
Bitfield< 7 > i
Definition: misc_types.hh:67
constexpr RegId o(int index)
Definition: int.hh:147
Bitfield< 0 > v
Definition: pagetable.hh:65
Bitfield< 6 > w
Definition: pagetable.hh:59
Bitfield< 51 > t
Definition: pagetable.hh:56
Bitfield< 54 > p
Definition: pagetable.hh:70
Bitfield< 51, 12 > base
Definition: pagetable.hh:141
Bitfield< 63 > val
Definition: misc.hh:776
ProbePointArg< PacketInfo > Packet
Packet probe point.
Definition: mem.hh:109
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::shared_ptr< Request > RequestPtr
Definition: request.hh:92
Packet * PacketPtr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
uint64_t PacketId
Definition: packet.hh:73
uint8_t * PacketDataPtr
Definition: packet.hh:71
uint16_t RequestorID
Definition: request.hh:95
std::list< PacketPtr > PacketList
Definition: packet.hh:72
HtmCacheFailure
Definition: htm.hh:60
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
Structure that defines attributes and other data associated with a Command.
Definition: packet.hh:196
const Command response
Corresponding response for requests; InvalidCmd if no response is applicable.
Definition: packet.hh:201
const std::bitset< NUM_COMMAND_ATTRIBUTES > attributes
Set of attribute flags.
Definition: packet.hh:198
const std::string str
String representation (for printing)
Definition: packet.hh:203
CommandInfo(std::initializer_list< Attribute > attrs, Command _response, const std::string &_str)
Definition: packet.hh:205
An entry in the label stack.
Definition: packet.hh:485
LabelStackEntry(const std::string &_label, std::string *_prefix)
Definition: packet.cc:428
A virtual base opaque structure used to hold state associated with the packet (e.g....
Definition: packet.hh:468
SenderState * predecessor
Definition: packet.hh:469

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