packet.hh (3940:b87f85bb4275) | packet.hh (4022:c422464ca16e) |
---|---|
1/* 2 * Copyright (c) 2006 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 26 unchanged lines hidden (view full) --- 35 * Declaration of the Packet class. 36 */ 37 38#ifndef __MEM_PACKET_HH__ 39#define __MEM_PACKET_HH__ 40 41#include <cassert> 42#include <list> | 1/* 2 * Copyright (c) 2006 The Regents of The University of Michigan 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; --- 26 unchanged lines hidden (view full) --- 35 * Declaration of the Packet class. 36 */ 37 38#ifndef __MEM_PACKET_HH__ 39#define __MEM_PACKET_HH__ 40 41#include <cassert> 42#include <list> |
43#include <bitset> |
|
43 44#include "base/misc.hh" 45#include "mem/request.hh" 46#include "sim/host.hh" 47#include "sim/root.hh" 48 49 50struct Packet; --- 5 unchanged lines hidden (view full) --- 56#define NACKED_LINE (1 << 0) 57#define SATISFIED (1 << 1) 58#define SHARED_LINE (1 << 2) 59#define CACHE_LINE_FILL (1 << 3) 60#define COMPRESSED (1 << 4) 61#define NO_ALLOCATE (1 << 5) 62#define SNOOP_COMMIT (1 << 6) 63 | 44 45#include "base/misc.hh" 46#include "mem/request.hh" 47#include "sim/host.hh" 48#include "sim/root.hh" 49 50 51struct Packet; --- 5 unchanged lines hidden (view full) --- 57#define NACKED_LINE (1 << 0) 58#define SATISFIED (1 << 1) 59#define SHARED_LINE (1 << 2) 60#define CACHE_LINE_FILL (1 << 3) 61#define COMPRESSED (1 << 4) 62#define NO_ALLOCATE (1 << 5) 63#define SNOOP_COMMIT (1 << 6) 64 |
64//for now. @todo fix later 65#define NUM_MEM_CMDS (1 << 11) | 65 66class MemCmd 67{ 68 public: 69 70 /** List of all commands associated with a packet. */ 71 enum Command 72 { 73 InvalidCmd, 74 ReadReq, 75 WriteReq, 76 WriteReqNoAck, 77 ReadResp, 78 WriteResp, 79 Writeback, 80 SoftPFReq, 81 HardPFReq, 82 SoftPFResp, 83 HardPFResp, 84 InvalidateReq, 85 WriteInvalidateReq, 86 WriteInvalidateResp, 87 UpgradeReq, 88 ReadExReq, 89 ReadExResp, 90 NUM_MEM_CMDS 91 }; 92 93 private: 94 /** List of command attributes. */ 95 enum Attribute 96 { 97 IsRead, 98 IsWrite, 99 IsPrefetch, 100 IsInvalidate, 101 IsRequest, 102 IsResponse, 103 NeedsResponse, 104 IsSWPrefetch, 105 IsHWPrefetch, 106 IsUpgrade, 107 HasData, 108 NUM_COMMAND_ATTRIBUTES 109 }; 110 111 /** Structure that defines attributes and other data associated 112 * with a Command. */ 113 struct CommandInfo { 114 /** Set of attribute flags. */ 115 const std::bitset<NUM_COMMAND_ATTRIBUTES> attributes; 116 /** Corresponding response for requests; InvalidCmd if no 117 * response is applicable. */ 118 const Command response; 119 /** String representation (for printing) */ 120 const std::string str; 121 }; 122 123 /** Array to map Command enum to associated info. */ 124 static const CommandInfo commandInfo[]; 125 126 private: 127 128 Command cmd; 129 130 bool testCmdAttrib(MemCmd::Attribute attrib) const { 131 return commandInfo[cmd].attributes[attrib] != 0; 132 } 133 134 public: 135 136 bool isRead() const { return testCmdAttrib(IsRead); } 137 bool isWrite() const { return testCmdAttrib(IsWrite); } 138 bool isRequest() const { return testCmdAttrib(IsRequest); } 139 bool isResponse() const { return testCmdAttrib(IsResponse); } 140 bool needsResponse() const { return testCmdAttrib(NeedsResponse); } 141 bool isInvalidate() const { return testCmdAttrib(IsInvalidate); } 142 bool hasData() const { return testCmdAttrib(HasData); } 143 144 const Command responseCommand() const { 145 return commandInfo[cmd].response; 146 } 147 148 /** Return the string to a cmd given by idx. */ 149 const std::string &toString() const { 150 return commandInfo[cmd].str; 151 } 152 153 int toInt() const { return (int)cmd; } 154 155 MemCmd(Command _cmd) 156 : cmd(_cmd) 157 { } 158 159 MemCmd(int _cmd) 160 : cmd((Command)_cmd) 161 { } 162 163 MemCmd() 164 : cmd(InvalidCmd) 165 { } 166 167 bool operator==(MemCmd c2) { return (cmd == c2.cmd); } 168 bool operator!=(MemCmd c2) { return (cmd != c2.cmd); } 169 170 friend class Packet; 171}; 172 |
66/** 67 * A Packet is used to encapsulate a transfer between two objects in 68 * the memory system (e.g., the L1 and L2 cache). (In contrast, a 69 * single Request travels all the way from the requester to the 70 * ultimate destination and back, possibly being conveyed by several 71 * different Packets along the way.) 72 */ 73class Packet 74{ 75 public: | 173/** 174 * A Packet is used to encapsulate a transfer between two objects in 175 * the memory system (e.g., the L1 and L2 cache). (In contrast, a 176 * single Request travels all the way from the requester to the 177 * ultimate destination and back, possibly being conveyed by several 178 * different Packets along the way.) 179 */ 180class Packet 181{ 182 public: |
183 184 typedef MemCmd::Command Command; 185 |
|
76 /** Temporary FLAGS field until cache gets working, this should be in coherence/sender state. */ 77 uint64_t flags; 78 79 private: 80 /** A pointer to the data being transfered. It can be differnt 81 * sizes at each level of the heirarchy so it belongs in the 82 * packet, not request. This may or may not be populated when a 83 * responder recieves the packet. If not populated it memory --- 79 unchanged lines hidden (view full) --- 163 public: 164 virtual ~SenderState() {} 165 }; 166 167 /** This packet's sender state. Devices should use dynamic_cast<> 168 * to cast to the state appropriate to the sender. */ 169 SenderState *senderState; 170 | 186 /** Temporary FLAGS field until cache gets working, this should be in coherence/sender state. */ 187 uint64_t flags; 188 189 private: 190 /** A pointer to the data being transfered. It can be differnt 191 * sizes at each level of the heirarchy so it belongs in the 192 * packet, not request. This may or may not be populated when a 193 * responder recieves the packet. If not populated it memory --- 79 unchanged lines hidden (view full) --- 273 public: 274 virtual ~SenderState() {} 275 }; 276 277 /** This packet's sender state. Devices should use dynamic_cast<> 278 * to cast to the state appropriate to the sender. */ 279 SenderState *senderState; 280 |
171 private: 172 /** List of command attributes. */ 173 // If you add a new CommandAttribute, make sure to increase NUM_MEM_CMDS 174 // as well. 175 enum CommandAttribute 176 { 177 IsRead = 1 << 0, 178 IsWrite = 1 << 1, 179 IsPrefetch = 1 << 2, 180 IsInvalidate = 1 << 3, 181 IsRequest = 1 << 4, 182 IsResponse = 1 << 5, 183 NeedsResponse = 1 << 6, 184 IsSWPrefetch = 1 << 7, 185 IsHWPrefetch = 1 << 8, 186 IsUpgrade = 1 << 9, 187 HasData = 1 << 10 188 }; 189 | |
190 public: | 281 public: |
191 /** List of all commands associated with a packet. */ 192 enum Command 193 { 194 InvalidCmd = 0, 195 ReadReq = IsRead | IsRequest | NeedsResponse, 196 WriteReq = IsWrite | IsRequest | NeedsResponse | HasData, 197 WriteReqNoAck = IsWrite | IsRequest | HasData, 198 ReadResp = IsRead | IsResponse | NeedsResponse | HasData, 199 WriteResp = IsWrite | IsResponse | NeedsResponse, 200 Writeback = IsWrite | IsRequest | HasData, 201 SoftPFReq = IsRead | IsRequest | IsSWPrefetch | NeedsResponse, 202 HardPFReq = IsRead | IsRequest | IsHWPrefetch | NeedsResponse, 203 SoftPFResp = IsRead | IsResponse | IsSWPrefetch 204 | NeedsResponse | HasData, 205 HardPFResp = IsRead | IsResponse | IsHWPrefetch 206 | NeedsResponse | HasData, 207 InvalidateReq = IsInvalidate | IsRequest, 208 WriteInvalidateReq = IsWrite | IsInvalidate | IsRequest 209 | HasData | NeedsResponse, 210 WriteInvalidateResp = IsWrite | IsInvalidate | IsRequest 211 | NeedsResponse | IsResponse, 212 UpgradeReq = IsInvalidate | IsRequest | IsUpgrade, 213 ReadExReq = IsRead | IsInvalidate | IsRequest | NeedsResponse, 214 ReadExResp = IsRead | IsInvalidate | IsResponse 215 | NeedsResponse | HasData 216 }; | |
217 | 282 |
283 /** The command field of the packet. */ 284 MemCmd cmd; 285 |
|
218 /** Return the string name of the cmd field (for debugging and 219 * tracing). */ | 286 /** Return the string name of the cmd field (for debugging and 287 * tracing). */ |
220 const std::string &cmdString() const; | 288 const std::string &cmdString() const { return cmd.toString(); } |
221 | 289 |
222 /** Reutrn the string to a cmd given by idx. */ 223 const std::string &cmdIdxToString(Command idx); 224 | |
225 /** Return the index of this command. */ | 290 /** Return the index of this command. */ |
226 inline int cmdToIndex() const { return (int) cmd; } | 291 inline int cmdToIndex() const { return cmd.toInt(); } |
227 | 292 |
228 /** The command field of the packet. */ 229 Command cmd; | 293 public: |
230 | 294 |
231 bool isRead() const { return (cmd & IsRead) != 0; } 232 bool isWrite() const { return (cmd & IsWrite) != 0; } 233 bool isRequest() const { return (cmd & IsRequest) != 0; } 234 bool isResponse() const { return (cmd & IsResponse) != 0; } 235 bool needsResponse() const { return (cmd & NeedsResponse) != 0; } 236 bool isInvalidate() const { return (cmd & IsInvalidate) != 0; } 237 bool hasData() const { return (cmd & HasData) != 0; } | 295 bool isRead() const { return cmd.isRead(); } 296 bool isWrite() const { return cmd.isWrite(); } 297 bool isRequest() const { return cmd.isRequest(); } 298 bool isResponse() const { return cmd.isResponse(); } 299 bool needsResponse() const { return cmd.needsResponse(); } 300 bool isInvalidate() const { return cmd.isInvalidate(); } 301 bool hasData() const { return cmd.hasData(); } |
238 239 bool isCacheFill() const { return (flags & CACHE_LINE_FILL) != 0; } 240 bool isNoAllocate() const { return (flags & NO_ALLOCATE) != 0; } 241 bool isCompressed() const { return (flags & COMPRESSED) != 0; } 242 243 bool nic_pkt() { panic("Unimplemented"); M5_DUMMY_RETURN } 244 245 /** Possible results of a packet's request. */ --- 17 unchanged lines hidden (view full) --- 263 short getDest() const { return dest; } 264 void setDest(short _dest) { dest = _dest; } 265 266 Addr getAddr() const { assert(addrSizeValid); return addr; } 267 int getSize() const { assert(addrSizeValid); return size; } 268 Addr getOffset(int blkSize) const { return addr & (Addr)(blkSize - 1); } 269 270 void addrOverride(Addr newAddr) { assert(addrSizeValid); addr = newAddr; } | 302 303 bool isCacheFill() const { return (flags & CACHE_LINE_FILL) != 0; } 304 bool isNoAllocate() const { return (flags & NO_ALLOCATE) != 0; } 305 bool isCompressed() const { return (flags & COMPRESSED) != 0; } 306 307 bool nic_pkt() { panic("Unimplemented"); M5_DUMMY_RETURN } 308 309 /** Possible results of a packet's request. */ --- 17 unchanged lines hidden (view full) --- 327 short getDest() const { return dest; } 328 void setDest(short _dest) { dest = _dest; } 329 330 Addr getAddr() const { assert(addrSizeValid); return addr; } 331 int getSize() const { assert(addrSizeValid); return size; } 332 Addr getOffset(int blkSize) const { return addr & (Addr)(blkSize - 1); } 333 334 void addrOverride(Addr newAddr) { assert(addrSizeValid); addr = newAddr; } |
271 void cmdOverride(Command newCmd) { cmd = newCmd; } | 335 void cmdOverride(MemCmd newCmd) { cmd = newCmd; } |
272 273 /** Constructor. Note that a Request object must be constructed 274 * first, but the Requests's physical address and size fields 275 * need not be valid. The command and destination addresses 276 * must be supplied. */ | 336 337 /** Constructor. Note that a Request object must be constructed 338 * first, but the Requests's physical address and size fields 339 * need not be valid. The command and destination addresses 340 * must be supplied. */ |
277 Packet(Request *_req, Command _cmd, short _dest) | 341 Packet(Request *_req, MemCmd _cmd, short _dest) |
278 : data(NULL), staticData(false), dynamicData(false), arrayData(false), 279 addr(_req->paddr), size(_req->size), dest(_dest), 280 addrSizeValid(_req->validPaddr), 281 srcValid(false), 282 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd), 283 result(Unknown) 284 { 285 flags = 0; 286 time = curTick; 287 } 288 289 /** Alternate constructor if you are trying to create a packet with 290 * a request that is for a whole block, not the address from the req. 291 * this allows for overriding the size/addr of the req.*/ | 342 : data(NULL), staticData(false), dynamicData(false), arrayData(false), 343 addr(_req->paddr), size(_req->size), dest(_dest), 344 addrSizeValid(_req->validPaddr), 345 srcValid(false), 346 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd), 347 result(Unknown) 348 { 349 flags = 0; 350 time = curTick; 351 } 352 353 /** Alternate constructor if you are trying to create a packet with 354 * a request that is for a whole block, not the address from the req. 355 * this allows for overriding the size/addr of the req.*/ |
292 Packet(Request *_req, Command _cmd, short _dest, int _blkSize) | 356 Packet(Request *_req, MemCmd _cmd, short _dest, int _blkSize) |
293 : data(NULL), staticData(false), dynamicData(false), arrayData(false), 294 addr(_req->paddr & ~(_blkSize - 1)), size(_blkSize), 295 dest(_dest), 296 addrSizeValid(_req->validPaddr), srcValid(false), 297 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd), 298 result(Unknown) 299 { 300 flags = 0; --- 28 unchanged lines hidden (view full) --- 329 * for returning as a response to that request. Used for timing 330 * accesses only. For atomic and functional accesses, the 331 * request packet is always implicitly passed back *without* 332 * modifying the destination fields, so this function 333 * should not be called. */ 334 void makeTimingResponse() { 335 assert(needsResponse()); 336 assert(isRequest()); | 357 : data(NULL), staticData(false), dynamicData(false), arrayData(false), 358 addr(_req->paddr & ~(_blkSize - 1)), size(_blkSize), 359 dest(_dest), 360 addrSizeValid(_req->validPaddr), srcValid(false), 361 req(_req), coherence(NULL), senderState(NULL), cmd(_cmd), 362 result(Unknown) 363 { 364 flags = 0; --- 28 unchanged lines hidden (view full) --- 393 * for returning as a response to that request. Used for timing 394 * accesses only. For atomic and functional accesses, the 395 * request packet is always implicitly passed back *without* 396 * modifying the destination fields, so this function 397 * should not be called. */ 398 void makeTimingResponse() { 399 assert(needsResponse()); 400 assert(isRequest()); |
337 int icmd = (int)cmd; 338 icmd &= ~(IsRequest); 339 icmd |= IsResponse; 340 if (isRead()) 341 icmd |= HasData; 342 if (isWrite()) 343 icmd &= ~HasData; 344 cmd = (Command)icmd; | 401 cmd = cmd.responseCommand(); |
345 dest = src; 346 srcValid = false; 347 } 348 | 402 dest = src; 403 srcValid = false; 404 } 405 |
349 350 void toggleData() { 351 int icmd = (int)cmd; 352 icmd ^= HasData; 353 cmd = (Command)icmd; 354 } 355 | |
356 /** 357 * Take a request packet and modify it in place to be suitable for 358 * returning as a response to that request. 359 */ 360 void makeAtomicResponse() 361 { 362 assert(needsResponse()); 363 assert(isRequest()); | 406 /** 407 * Take a request packet and modify it in place to be suitable for 408 * returning as a response to that request. 409 */ 410 void makeAtomicResponse() 411 { 412 assert(needsResponse()); 413 assert(isRequest()); |
364 int icmd = (int)cmd; 365 icmd &= ~(IsRequest); 366 icmd |= IsResponse; 367 if (isRead()) 368 icmd |= HasData; 369 if (isWrite()) 370 icmd &= ~HasData; 371 cmd = (Command)icmd; | 414 cmd = cmd.responseCommand(); |
372 } 373 374 /** 375 * Take a request packet that has been returned as NACKED and 376 * modify it so that it can be sent out again. Only packets that 377 * need a response can be NACKED, so verify that that is true. 378 */ 379 void --- 96 unchanged lines hidden --- | 415 } 416 417 /** 418 * Take a request packet that has been returned as NACKED and 419 * modify it so that it can be sent out again. Only packets that 420 * need a response can be NACKED, so verify that that is true. 421 */ 422 void --- 96 unchanged lines hidden --- |