request.hh revision 10882:3e84b8b49c77
1/* 2 * Copyright (c) 2012-2013 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: Ron Dreslinski 41 * Steve Reinhardt 42 * Ali Saidi 43 */ 44 45/** 46 * @file 47 * Declaration of a request, the overall memory request consisting of 48 the parts of the request that are persistent throughout the transaction. 49 */ 50 51#ifndef __MEM_REQUEST_HH__ 52#define __MEM_REQUEST_HH__ 53 54#include <cassert> 55#include <climits> 56 57#include "base/flags.hh" 58#include "base/misc.hh" 59#include "base/types.hh" 60#include "sim/core.hh" 61 62/** 63 * Special TaskIds that are used for per-context-switch stats dumps 64 * and Cache Occupancy. Having too many tasks seems to be a problem 65 * with vector stats. 1024 seems to be a reasonable number that 66 * doesn't cause a problem with stats and is large enough to realistic 67 * benchmarks (Linux/Android boot, BBench, etc.) 68 */ 69 70namespace ContextSwitchTaskId { 71 enum TaskId { 72 MaxNormalTaskId = 1021, /* Maximum number of normal tasks */ 73 Prefetcher = 1022, /* For cache lines brought in by prefetcher */ 74 DMA = 1023, /* Mostly Table Walker */ 75 Unknown = 1024, 76 NumTaskId 77 }; 78} 79 80class Request; 81 82typedef Request* RequestPtr; 83typedef uint16_t MasterID; 84 85class Request 86{ 87 public: 88 typedef uint32_t FlagsType; 89 typedef uint8_t ArchFlagsType; 90 typedef ::Flags<FlagsType> Flags; 91 92 enum : FlagsType { 93 /** 94 * Architecture specific flags. 95 * 96 * These bits int the flag field are reserved for 97 * architecture-specific code. For example, SPARC uses them to 98 * represent ASIs. 99 */ 100 ARCH_BITS = 0x000000FF, 101 /** The request was an instruction fetch. */ 102 INST_FETCH = 0x00000100, 103 /** The virtual address is also the physical address. */ 104 PHYSICAL = 0x00000200, 105 /** 106 * The request is to an uncacheable address. 107 * 108 * @note Uncacheable accesses may be reordered by CPU models. The 109 * STRICT_ORDER flag should be set if such reordering is 110 * undesirable. 111 */ 112 UNCACHEABLE = 0x00000400, 113 /** 114 * The request is required to be strictly ordered by <i>CPU 115 * models</i> and is non-speculative. 116 * 117 * A strictly ordered request is guaranteed to never be 118 * re-ordered or executed speculatively by a CPU model. The 119 * memory system may still reorder requests in caches unless 120 * the UNCACHEABLE flag is set as well. 121 */ 122 STRICT_ORDER = 0x00000800, 123 /** This request is to a memory mapped register. */ 124 MMAPPED_IPR = 0x00002000, 125 /** This request is a clear exclusive. */ 126 CLEAR_LL = 0x00004000, 127 /** This request is made in privileged mode. */ 128 PRIVILEGED = 0x00008000, 129 130 /** 131 * This is a write that is targeted and zeroing an entire 132 * cache block. There is no need for a read/modify/write 133 */ 134 CACHE_BLOCK_ZERO = 0x00010000, 135 136 /** The request should not cause a memory access. */ 137 NO_ACCESS = 0x00080000, 138 /** 139 * This request will lock or unlock the accessed memory. When 140 * used with a load, the access locks the particular chunk of 141 * memory. When used with a store, it unlocks. The rule is 142 * that locked accesses have to be made up of a locked load, 143 * some operation on the data, and then a locked store. 144 */ 145 LOCKED_RMW = 0x00100000, 146 /** The request is a Load locked/store conditional. */ 147 LLSC = 0x00200000, 148 /** This request is for a memory swap. */ 149 MEM_SWAP = 0x00400000, 150 MEM_SWAP_COND = 0x00800000, 151 152 /** The request is a prefetch. */ 153 PREFETCH = 0x01000000, 154 /** The request should be prefetched into the exclusive state. */ 155 PF_EXCLUSIVE = 0x02000000, 156 /** The request should be marked as LRU. */ 157 EVICT_NEXT = 0x04000000, 158 159 /** 160 * The request should be handled by the generic IPR code (only 161 * valid together with MMAPPED_IPR) 162 */ 163 GENERIC_IPR = 0x08000000, 164 165 /** The request targets the secure memory space. */ 166 SECURE = 0x10000000, 167 /** The request is a page table walk */ 168 PT_WALK = 0x20000000, 169 170 /** 171 * These flags are *not* cleared when a Request object is 172 * reused (assigned a new address). 173 */ 174 STICKY_FLAGS = INST_FETCH 175 }; 176 177 /** Master Ids that are statically allocated 178 * @{*/ 179 enum : MasterID { 180 /** This master id is used for writeback requests by the caches */ 181 wbMasterId = 0, 182 /** 183 * This master id is used for functional requests that 184 * don't come from a particular device 185 */ 186 funcMasterId = 1, 187 /** This master id is used for message signaled interrupts */ 188 intMasterId = 2, 189 /** 190 * Invalid master id for assertion checking only. It is 191 * invalid behavior to ever send this id as part of a request. 192 */ 193 invldMasterId = std::numeric_limits<MasterID>::max() 194 }; 195 /** @} */ 196 197 /** Invalid or unknown Pid. Possible when operating system is not present 198 * or has not assigned a pid yet */ 199 static const uint32_t invldPid = std::numeric_limits<uint32_t>::max(); 200 201 private: 202 typedef uint8_t PrivateFlagsType; 203 typedef ::Flags<PrivateFlagsType> PrivateFlags; 204 205 enum : PrivateFlagsType { 206 /** Whether or not the size is valid. */ 207 VALID_SIZE = 0x00000001, 208 /** Whether or not paddr is valid (has been written yet). */ 209 VALID_PADDR = 0x00000002, 210 /** Whether or not the vaddr & asid are valid. */ 211 VALID_VADDR = 0x00000004, 212 /** Whether or not the pc is valid. */ 213 VALID_PC = 0x00000010, 214 /** Whether or not the context ID is valid. */ 215 VALID_CONTEXT_ID = 0x00000020, 216 VALID_THREAD_ID = 0x00000040, 217 /** Whether or not the sc result is valid. */ 218 VALID_EXTRA_DATA = 0x00000080, 219 220 /** 221 * These flags are *not* cleared when a Request object is reused 222 * (assigned a new address). 223 */ 224 STICKY_PRIVATE_FLAGS = VALID_CONTEXT_ID | VALID_THREAD_ID 225 }; 226 227 private: 228 229 /** 230 * Set up a physical (e.g. device) request in a previously 231 * allocated Request object. 232 */ 233 void 234 setPhys(Addr paddr, unsigned size, Flags flags, MasterID mid, Tick time) 235 { 236 assert(size >= 0); 237 _paddr = paddr; 238 _size = size; 239 _time = time; 240 _masterId = mid; 241 _flags.clear(~STICKY_FLAGS); 242 _flags.set(flags); 243 privateFlags.clear(~STICKY_PRIVATE_FLAGS); 244 privateFlags.set(VALID_PADDR|VALID_SIZE); 245 depth = 0; 246 accessDelta = 0; 247 //translateDelta = 0; 248 } 249 250 /** 251 * The physical address of the request. Valid only if validPaddr 252 * is set. 253 */ 254 Addr _paddr; 255 256 /** 257 * The size of the request. This field must be set when vaddr or 258 * paddr is written via setVirt() or setPhys(), so it is always 259 * valid as long as one of the address fields is valid. 260 */ 261 unsigned _size; 262 263 /** The requestor ID which is unique in the system for all ports 264 * that are capable of issuing a transaction 265 */ 266 MasterID _masterId; 267 268 /** Flag structure for the request. */ 269 Flags _flags; 270 271 /** Private flags for field validity checking. */ 272 PrivateFlags privateFlags; 273 274 /** 275 * The time this request was started. Used to calculate 276 * latencies. This field is set to curTick() any time paddr or vaddr 277 * is written. 278 */ 279 Tick _time; 280 281 /** 282 * The task id associated with this request 283 */ 284 uint32_t _taskId; 285 286 /** The address space ID. */ 287 int _asid; 288 289 /** The virtual address of the request. */ 290 Addr _vaddr; 291 292 /** 293 * Extra data for the request, such as the return value of 294 * store conditional or the compare value for a CAS. */ 295 uint64_t _extraData; 296 297 /** The context ID (for statistics, typically). */ 298 int _contextId; 299 /** The thread ID (id within this CPU) */ 300 ThreadID _threadId; 301 302 /** program counter of initiating access; for tracing/debugging */ 303 Addr _pc; 304 305 public: 306 307 /** 308 * Minimal constructor. No fields are initialized. (Note that 309 * _flags and privateFlags are cleared by Flags default 310 * constructor.) 311 */ 312 Request() 313 : _paddr(0), _size(0), _masterId(invldMasterId), _time(0), 314 _taskId(ContextSwitchTaskId::Unknown), _asid(0), _vaddr(0), 315 _extraData(0), _contextId(0), _threadId(0), _pc(0), 316 translateDelta(0), accessDelta(0), depth(0) 317 {} 318 319 /** 320 * Constructor for physical (e.g. device) requests. Initializes 321 * just physical address, size, flags, and timestamp (to curTick()). 322 * These fields are adequate to perform a request. 323 */ 324 Request(Addr paddr, unsigned size, Flags flags, MasterID mid) 325 : _paddr(0), _size(0), _masterId(invldMasterId), _time(0), 326 _taskId(ContextSwitchTaskId::Unknown), _asid(0), _vaddr(0), 327 _extraData(0), _contextId(0), _threadId(0), _pc(0), 328 translateDelta(0), accessDelta(0), depth(0) 329 { 330 setPhys(paddr, size, flags, mid, curTick()); 331 } 332 333 Request(Addr paddr, unsigned size, Flags flags, MasterID mid, Tick time) 334 : _paddr(0), _size(0), _masterId(invldMasterId), _time(0), 335 _taskId(ContextSwitchTaskId::Unknown), _asid(0), _vaddr(0), 336 _extraData(0), _contextId(0), _threadId(0), _pc(0), 337 translateDelta(0), accessDelta(0), depth(0) 338 { 339 setPhys(paddr, size, flags, mid, time); 340 } 341 342 Request(Addr paddr, unsigned size, Flags flags, MasterID mid, Tick time, 343 Addr pc) 344 : _paddr(0), _size(0), _masterId(invldMasterId), _time(0), 345 _taskId(ContextSwitchTaskId::Unknown), _asid(0), _vaddr(0), 346 _extraData(0), _contextId(0), _threadId(0), _pc(0), 347 translateDelta(0), accessDelta(0), depth(0) 348 { 349 setPhys(paddr, size, flags, mid, time); 350 privateFlags.set(VALID_PC); 351 _pc = pc; 352 } 353 354 Request(int asid, Addr vaddr, unsigned size, Flags flags, MasterID mid, 355 Addr pc, int cid, ThreadID tid) 356 : _paddr(0), _size(0), _masterId(invldMasterId), _time(0), 357 _taskId(ContextSwitchTaskId::Unknown), _asid(0), _vaddr(0), 358 _extraData(0), _contextId(0), _threadId(0), _pc(0), 359 translateDelta(0), accessDelta(0), depth(0) 360 { 361 setVirt(asid, vaddr, size, flags, mid, pc); 362 setThreadContext(cid, tid); 363 } 364 365 ~Request() {} 366 367 /** 368 * Set up CPU and thread numbers. 369 */ 370 void 371 setThreadContext(int context_id, ThreadID tid) 372 { 373 _contextId = context_id; 374 _threadId = tid; 375 privateFlags.set(VALID_CONTEXT_ID|VALID_THREAD_ID); 376 } 377 378 /** 379 * Set up a virtual (e.g., CPU) request in a previously 380 * allocated Request object. 381 */ 382 void 383 setVirt(int asid, Addr vaddr, unsigned size, Flags flags, MasterID mid, 384 Addr pc) 385 { 386 _asid = asid; 387 _vaddr = vaddr; 388 _size = size; 389 _masterId = mid; 390 _pc = pc; 391 _time = curTick(); 392 393 _flags.clear(~STICKY_FLAGS); 394 _flags.set(flags); 395 privateFlags.clear(~STICKY_PRIVATE_FLAGS); 396 privateFlags.set(VALID_VADDR|VALID_SIZE|VALID_PC); 397 depth = 0; 398 accessDelta = 0; 399 translateDelta = 0; 400 } 401 402 /** 403 * Set just the physical address. This usually used to record the 404 * result of a translation. However, when using virtualized CPUs 405 * setPhys() is sometimes called to finalize a physical address 406 * without a virtual address, so we can't check if the virtual 407 * address is valid. 408 */ 409 void 410 setPaddr(Addr paddr) 411 { 412 _paddr = paddr; 413 privateFlags.set(VALID_PADDR); 414 } 415 416 /** 417 * Generate two requests as if this request had been split into two 418 * pieces. The original request can't have been translated already. 419 */ 420 void splitOnVaddr(Addr split_addr, RequestPtr &req1, RequestPtr &req2) 421 { 422 assert(privateFlags.isSet(VALID_VADDR)); 423 assert(privateFlags.noneSet(VALID_PADDR)); 424 assert(split_addr > _vaddr && split_addr < _vaddr + _size); 425 req1 = new Request(*this); 426 req2 = new Request(*this); 427 req1->_size = split_addr - _vaddr; 428 req2->_vaddr = split_addr; 429 req2->_size = _size - req1->_size; 430 } 431 432 /** 433 * Accessor for paddr. 434 */ 435 bool 436 hasPaddr() const 437 { 438 return privateFlags.isSet(VALID_PADDR); 439 } 440 441 Addr 442 getPaddr() const 443 { 444 assert(privateFlags.isSet(VALID_PADDR)); 445 return _paddr; 446 } 447 448 /** 449 * Time for the TLB/table walker to successfully translate this request. 450 */ 451 Tick translateDelta; 452 453 /** 454 * Access latency to complete this memory transaction not including 455 * translation time. 456 */ 457 Tick accessDelta; 458 459 /** 460 * Level of the cache hierachy where this request was responded to 461 * (e.g. 0 = L1; 1 = L2). 462 */ 463 mutable int depth; 464 465 /** 466 * Accessor for size. 467 */ 468 bool 469 hasSize() const 470 { 471 return privateFlags.isSet(VALID_SIZE); 472 } 473 474 unsigned 475 getSize() const 476 { 477 assert(privateFlags.isSet(VALID_SIZE)); 478 return _size; 479 } 480 481 /** Accessor for time. */ 482 Tick 483 time() const 484 { 485 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR)); 486 return _time; 487 } 488 489 /** Accessor for flags. */ 490 Flags 491 getFlags() 492 { 493 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR)); 494 return _flags; 495 } 496 497 /** Note that unlike other accessors, this function sets *specific 498 flags* (ORs them in); it does not assign its argument to the 499 _flags field. Thus this method should rightly be called 500 setFlags() and not just flags(). */ 501 void 502 setFlags(Flags flags) 503 { 504 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR)); 505 _flags.set(flags); 506 } 507 508 /** Accessor function for vaddr.*/ 509 bool 510 hasVaddr() const 511 { 512 return privateFlags.isSet(VALID_VADDR); 513 } 514 515 Addr 516 getVaddr() const 517 { 518 assert(privateFlags.isSet(VALID_VADDR)); 519 return _vaddr; 520 } 521 522 /** Accesssor for the requestor id. */ 523 MasterID 524 masterId() const 525 { 526 return _masterId; 527 } 528 529 uint32_t 530 taskId() const 531 { 532 return _taskId; 533 } 534 535 void 536 taskId(uint32_t id) { 537 _taskId = id; 538 } 539 540 /** Accessor function for asid.*/ 541 int 542 getAsid() const 543 { 544 assert(privateFlags.isSet(VALID_VADDR)); 545 return _asid; 546 } 547 548 /** Accessor function for asid.*/ 549 void 550 setAsid(int asid) 551 { 552 _asid = asid; 553 } 554 555 /** Accessor function for architecture-specific flags.*/ 556 ArchFlagsType 557 getArchFlags() const 558 { 559 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR)); 560 return _flags & ARCH_BITS; 561 } 562 563 /** Accessor function to check if sc result is valid. */ 564 bool 565 extraDataValid() const 566 { 567 return privateFlags.isSet(VALID_EXTRA_DATA); 568 } 569 570 /** Accessor function for store conditional return value.*/ 571 uint64_t 572 getExtraData() const 573 { 574 assert(privateFlags.isSet(VALID_EXTRA_DATA)); 575 return _extraData; 576 } 577 578 /** Accessor function for store conditional return value.*/ 579 void 580 setExtraData(uint64_t extraData) 581 { 582 _extraData = extraData; 583 privateFlags.set(VALID_EXTRA_DATA); 584 } 585 586 bool 587 hasContextId() const 588 { 589 return privateFlags.isSet(VALID_CONTEXT_ID); 590 } 591 592 /** Accessor function for context ID.*/ 593 int 594 contextId() const 595 { 596 assert(privateFlags.isSet(VALID_CONTEXT_ID)); 597 return _contextId; 598 } 599 600 /** Accessor function for thread ID. */ 601 ThreadID 602 threadId() const 603 { 604 assert(privateFlags.isSet(VALID_THREAD_ID)); 605 return _threadId; 606 } 607 608 void 609 setPC(Addr pc) 610 { 611 privateFlags.set(VALID_PC); 612 _pc = pc; 613 } 614 615 bool 616 hasPC() const 617 { 618 return privateFlags.isSet(VALID_PC); 619 } 620 621 /** Accessor function for pc.*/ 622 Addr 623 getPC() const 624 { 625 assert(privateFlags.isSet(VALID_PC)); 626 return _pc; 627 } 628 629 /** 630 * Increment/Get the depth at which this request is responded to. 631 * This currently happens when the request misses in any cache level. 632 */ 633 void incAccessDepth() const { depth++; } 634 int getAccessDepth() const { return depth; } 635 636 /** 637 * Set/Get the time taken for this request to be successfully translated. 638 */ 639 void setTranslateLatency() { translateDelta = curTick() - _time; } 640 Tick getTranslateLatency() const { return translateDelta; } 641 642 /** 643 * Set/Get the time taken to complete this request's access, not including 644 * the time to successfully translate the request. 645 */ 646 void setAccessLatency() { accessDelta = curTick() - _time - translateDelta; } 647 Tick getAccessLatency() const { return accessDelta; } 648 649 /** Accessor functions for flags. Note that these are for testing 650 only; setting flags should be done via setFlags(). */ 651 bool isUncacheable() const { return _flags.isSet(UNCACHEABLE); } 652 bool isStrictlyOrdered() const { return _flags.isSet(STRICT_ORDER); } 653 bool isInstFetch() const { return _flags.isSet(INST_FETCH); } 654 bool isPrefetch() const { return _flags.isSet(PREFETCH); } 655 bool isLLSC() const { return _flags.isSet(LLSC); } 656 bool isPriv() const { return _flags.isSet(PRIVILEGED); } 657 bool isLockedRMW() const { return _flags.isSet(LOCKED_RMW); } 658 bool isSwap() const { return _flags.isSet(MEM_SWAP|MEM_SWAP_COND); } 659 bool isCondSwap() const { return _flags.isSet(MEM_SWAP_COND); } 660 bool isMmappedIpr() const { return _flags.isSet(MMAPPED_IPR); } 661 bool isClearLL() const { return _flags.isSet(CLEAR_LL); } 662 bool isSecure() const { return _flags.isSet(SECURE); } 663 bool isPTWalk() const { return _flags.isSet(PT_WALK); } 664}; 665 666#endif // __MEM_REQUEST_HH__ 667