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