2 * Copyright (c) 2012-2013 ARM Limited
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.
14 * Copyright (c) 2002-2005 The Regents of The University of Michigan
15 * Copyright (c) 2010,2015 Advanced Micro Devices, Inc.
16 * All rights reserved.
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.
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.
41 * Authors: Ron Dreslinski
48 * Declaration of a request, the overall memory request consisting of
49 the parts of the request that are persistent throughout the transaction.
52 #ifndef __MEM_REQUEST_HH__
53 #define __MEM_REQUEST_HH__
58 #include "base/flags.hh"
59 #include "base/misc.hh"
60 #include "base/types.hh"
61 #include "cpu/inst_seq.hh"
62 #include "sim/core.hh"
65 * Special TaskIds that are used for per-context-switch stats dumps
66 * and Cache Occupancy. Having too many tasks seems to be a problem
67 * with vector stats. 1024 seems to be a reasonable number that
68 * doesn't cause a problem with stats and is large enough to realistic
69 * benchmarks (Linux/Android boot, BBench, etc.)
72 namespace ContextSwitchTaskId {
74 MaxNormalTaskId = 1021, /* Maximum number of normal tasks */
75 Prefetcher = 1022, /* For cache lines brought in by prefetcher */
76 DMA = 1023, /* Mostly Table Walker */
84 typedef Request* RequestPtr;
85 typedef uint16_t MasterID;
90 typedef uint32_t FlagsType;
91 typedef uint8_t ArchFlagsType;
92 typedef ::Flags<FlagsType> Flags;
96 * Architecture specific flags.
98 * These bits int the flag field are reserved for
99 * architecture-specific code. For example, SPARC uses them to
102 ARCH_BITS = 0x000000FF,
103 /** The request was an instruction fetch. */
104 INST_FETCH = 0x00000100,
105 /** The virtual address is also the physical address. */
106 PHYSICAL = 0x00000200,
108 * The request is to an uncacheable address.
110 * @note Uncacheable accesses may be reordered by CPU models. The
111 * STRICT_ORDER flag should be set if such reordering is
114 UNCACHEABLE = 0x00000400,
116 * The request is required to be strictly ordered by <i>CPU
117 * models</i> and is non-speculative.
119 * A strictly ordered request is guaranteed to never be
120 * re-ordered or executed speculatively by a CPU model. The
121 * memory system may still reorder requests in caches unless
122 * the UNCACHEABLE flag is set as well.
124 STRICT_ORDER = 0x00000800,
125 /** This request is to a memory mapped register. */
126 MMAPPED_IPR = 0x00002000,
127 /** This request is made in privileged mode. */
128 PRIVILEGED = 0x00008000,
131 * This is a write that is targeted and zeroing an entire
132 * cache block. There is no need for a read/modify/write
134 CACHE_BLOCK_ZERO = 0x00010000,
136 /** The request should not cause a memory access. */
137 NO_ACCESS = 0x00080000,
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.
145 LOCKED_RMW = 0x00100000,
146 /** The request is a Load locked/store conditional. */
148 /** This request is for a memory swap. */
149 MEM_SWAP = 0x00400000,
150 MEM_SWAP_COND = 0x00800000,
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 /** The request should be marked with ACQUIRE. */
159 ACQUIRE = 0x00020000,
160 /** The request should be marked with RELEASE. */
161 RELEASE = 0x00040000,
163 /** The request is an atomic that returns data. */
164 ATOMIC_RETURN_OP = 0x40000000,
165 /** The request is an atomic that does not return data. */
166 ATOMIC_NO_RETURN_OP = 0x80000000,
168 /** The request should be marked with KERNEL.
169 * Used to indicate the synchronization associated with a GPU kernel
170 * launch or completion.
175 * The request should be handled by the generic IPR code (only
176 * valid together with MMAPPED_IPR)
178 GENERIC_IPR = 0x08000000,
180 /** The request targets the secure memory space. */
182 /** The request is a page table walk */
183 PT_WALK = 0x20000000,
186 * These flags are *not* cleared when a Request object is
187 * reused (assigned a new address).
189 STICKY_FLAGS = INST_FETCH
192 /** Master Ids that are statically allocated
195 /** This master id is used for writeback requests by the caches */
198 * This master id is used for functional requests that
199 * don't come from a particular device
202 /** This master id is used for message signaled interrupts */
205 * Invalid master id for assertion checking only. It is
206 * invalid behavior to ever send this id as part of a request.
208 invldMasterId = std::numeric_limits<MasterID>::max()
212 typedef uint32_t MemSpaceConfigFlagsType;
213 typedef ::Flags<MemSpaceConfigFlagsType> MemSpaceConfigFlags;
215 enum : MemSpaceConfigFlagsType {
216 /** Has a synchronization scope been set? */
217 SCOPE_VALID = 0x00000001,
218 /** Access has Wavefront scope visibility */
219 WAVEFRONT_SCOPE = 0x00000002,
220 /** Access has Workgroup scope visibility */
221 WORKGROUP_SCOPE = 0x00000004,
222 /** Access has Device (e.g., GPU) scope visibility */
223 DEVICE_SCOPE = 0x00000008,
224 /** Access has System (e.g., CPU + GPU) scope visibility */
225 SYSTEM_SCOPE = 0x00000010,
227 /** Global Segment */
228 GLOBAL_SEGMENT = 0x00000020,
230 GROUP_SEGMENT = 0x00000040,
231 /** Private Segment */
232 PRIVATE_SEGMENT = 0x00000080,
233 /** Kergarg Segment */
234 KERNARG_SEGMENT = 0x00000100,
235 /** Readonly Segment */
236 READONLY_SEGMENT = 0x00000200,
238 SPILL_SEGMENT = 0x00000400,
240 ARG_SEGMENT = 0x00000800,
244 typedef uint8_t PrivateFlagsType;
245 typedef ::Flags<PrivateFlagsType> PrivateFlags;
247 enum : PrivateFlagsType {
248 /** Whether or not the size is valid. */
249 VALID_SIZE = 0x00000001,
250 /** Whether or not paddr is valid (has been written yet). */
251 VALID_PADDR = 0x00000002,
252 /** Whether or not the vaddr & asid are valid. */
253 VALID_VADDR = 0x00000004,
254 /** Whether or not the instruction sequence number is valid. */
255 VALID_INST_SEQ_NUM = 0x00000008,
256 /** Whether or not the pc is valid. */
257 VALID_PC = 0x00000010,
258 /** Whether or not the context ID is valid. */
259 VALID_CONTEXT_ID = 0x00000020,
260 /** Whether or not the sc result is valid. */
261 VALID_EXTRA_DATA = 0x00000080,
263 * These flags are *not* cleared when a Request object is reused
264 * (assigned a new address).
266 STICKY_PRIVATE_FLAGS = VALID_CONTEXT_ID
272 * Set up a physical (e.g. device) request in a previously
273 * allocated Request object.
276 setPhys(Addr paddr, unsigned size, Flags flags, MasterID mid, Tick time)
282 _flags.clear(~STICKY_FLAGS);
284 privateFlags.clear(~STICKY_PRIVATE_FLAGS);
285 privateFlags.set(VALID_PADDR|VALID_SIZE);
288 //translateDelta = 0;
292 * The physical address of the request. Valid only if validPaddr
298 * The size of the request. This field must be set when vaddr or
299 * paddr is written via setVirt() or setPhys(), so it is always
300 * valid as long as one of the address fields is valid.
304 /** The requestor ID which is unique in the system for all ports
305 * that are capable of issuing a transaction
309 /** Flag structure for the request. */
312 /** Memory space configuraiton flag structure for the request. */
313 MemSpaceConfigFlags _memSpaceConfigFlags;
315 /** Private flags for field validity checking. */
316 PrivateFlags privateFlags;
319 * The time this request was started. Used to calculate
320 * latencies. This field is set to curTick() any time paddr or vaddr
326 * The task id associated with this request
330 /** The address space ID. */
333 /** The virtual address of the request. */
337 * Extra data for the request, such as the return value of
338 * store conditional or the compare value for a CAS. */
341 /** The context ID (for statistics, locks, and wakeups). */
342 ContextID _contextId;
344 /** program counter of initiating access; for tracing/debugging */
347 /** Sequence number of the instruction that creates the request */
348 InstSeqNum _reqInstSeqNum;
350 /** A pointer to an atomic operation */
351 AtomicOpFunctor *atomicOpFunctor;
356 * Minimal constructor. No fields are initialized. (Note that
357 * _flags and privateFlags are cleared by Flags default
361 : _paddr(0), _size(0), _masterId(invldMasterId), _time(0),
362 _taskId(ContextSwitchTaskId::Unknown), _asid(0), _vaddr(0),
363 _extraData(0), _contextId(0), _pc(0),
364 _reqInstSeqNum(0), atomicOpFunctor(nullptr), translateDelta(0),
365 accessDelta(0), depth(0)
368 Request(Addr paddr, unsigned size, Flags flags, MasterID mid,
369 InstSeqNum seq_num, ContextID cid)
370 : _paddr(0), _size(0), _masterId(invldMasterId), _time(0),
371 _taskId(ContextSwitchTaskId::Unknown), _asid(0), _vaddr(0),
372 _extraData(0), _contextId(0), _pc(0),
373 _reqInstSeqNum(seq_num), atomicOpFunctor(nullptr), translateDelta(0),
374 accessDelta(0), depth(0)
376 setPhys(paddr, size, flags, mid, curTick());
378 privateFlags.set(VALID_INST_SEQ_NUM);
382 * Constructor for physical (e.g. device) requests. Initializes
383 * just physical address, size, flags, and timestamp (to curTick()).
384 * These fields are adequate to perform a request.
386 Request(Addr paddr, unsigned size, Flags flags, MasterID mid)
387 : _paddr(0), _size(0), _masterId(invldMasterId), _time(0),
388 _taskId(ContextSwitchTaskId::Unknown), _asid(0), _vaddr(0),
389 _extraData(0), _contextId(0), _pc(0),
390 _reqInstSeqNum(0), atomicOpFunctor(nullptr), translateDelta(0),
391 accessDelta(0), depth(0)
393 setPhys(paddr, size, flags, mid, curTick());
396 Request(Addr paddr, unsigned size, Flags flags, MasterID mid, Tick time)
397 : _paddr(0), _size(0), _masterId(invldMasterId), _time(0),
398 _taskId(ContextSwitchTaskId::Unknown), _asid(0), _vaddr(0),
399 _extraData(0), _contextId(0), _pc(0),
400 _reqInstSeqNum(0), atomicOpFunctor(nullptr), translateDelta(0),
401 accessDelta(0), depth(0)
403 setPhys(paddr, size, flags, mid, time);
406 Request(Addr paddr, unsigned size, Flags flags, MasterID mid, Tick time,
408 : _paddr(0), _size(0), _masterId(invldMasterId), _time(0),
409 _taskId(ContextSwitchTaskId::Unknown), _asid(0), _vaddr(0),
410 _extraData(0), _contextId(0), _pc(pc),
411 _reqInstSeqNum(0), atomicOpFunctor(nullptr), translateDelta(0),
412 accessDelta(0), depth(0)
414 setPhys(paddr, size, flags, mid, time);
415 privateFlags.set(VALID_PC);
418 Request(int asid, Addr vaddr, unsigned size, Flags flags, MasterID mid,
419 Addr pc, ContextID cid)
420 : _paddr(0), _size(0), _masterId(invldMasterId), _time(0),
421 _taskId(ContextSwitchTaskId::Unknown), _asid(0), _vaddr(0),
422 _extraData(0), _contextId(0), _pc(0),
423 _reqInstSeqNum(0), atomicOpFunctor(nullptr), translateDelta(0),
424 accessDelta(0), depth(0)
426 setVirt(asid, vaddr, size, flags, mid, pc);
430 Request(int asid, Addr vaddr, unsigned size, Flags flags, MasterID mid,
431 Addr pc, ContextID cid, AtomicOpFunctor *atomic_op)
432 : atomicOpFunctor(atomic_op)
434 setVirt(asid, vaddr, size, flags, mid, pc);
440 if (hasAtomicOpFunctor()) {
441 delete atomicOpFunctor;
446 * Set up Context numbers.
449 setContext(ContextID context_id)
451 _contextId = context_id;
452 privateFlags.set(VALID_CONTEXT_ID);
456 * Set up a virtual (e.g., CPU) request in a previously
457 * allocated Request object.
460 setVirt(int asid, Addr vaddr, unsigned size, Flags flags, MasterID mid,
470 _flags.clear(~STICKY_FLAGS);
472 privateFlags.clear(~STICKY_PRIVATE_FLAGS);
473 privateFlags.set(VALID_VADDR|VALID_SIZE|VALID_PC);
480 * Set just the physical address. This usually used to record the
481 * result of a translation. However, when using virtualized CPUs
482 * setPhys() is sometimes called to finalize a physical address
483 * without a virtual address, so we can't check if the virtual
490 privateFlags.set(VALID_PADDR);
494 * Generate two requests as if this request had been split into two
495 * pieces. The original request can't have been translated already.
497 void splitOnVaddr(Addr split_addr, RequestPtr &req1, RequestPtr &req2)
499 assert(privateFlags.isSet(VALID_VADDR));
500 assert(privateFlags.noneSet(VALID_PADDR));
501 assert(split_addr > _vaddr && split_addr < _vaddr + _size);
502 req1 = new Request(*this);
503 req2 = new Request(*this);
504 req1->_size = split_addr - _vaddr;
505 req2->_vaddr = split_addr;
506 req2->_size = _size - req1->_size;
510 * Accessor for paddr.
515 return privateFlags.isSet(VALID_PADDR);
521 assert(privateFlags.isSet(VALID_PADDR));
526 * Time for the TLB/table walker to successfully translate this request.
531 * Access latency to complete this memory transaction not including
537 * Level of the cache hierachy where this request was responded to
538 * (e.g. 0 = L1; 1 = L2).
548 return privateFlags.isSet(VALID_SIZE);
554 assert(privateFlags.isSet(VALID_SIZE));
558 /** Accessor for time. */
562 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
567 * Accessor for atomic-op functor.
572 return atomicOpFunctor != NULL;
578 assert(atomicOpFunctor != NULL);
579 return atomicOpFunctor;
582 /** Accessor for flags. */
586 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
590 /** Note that unlike other accessors, this function sets *specific
591 flags* (ORs them in); it does not assign its argument to the
592 _flags field. Thus this method should rightly be called
593 setFlags() and not just flags(). */
595 setFlags(Flags flags)
597 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
602 setMemSpaceConfigFlags(MemSpaceConfigFlags extraFlags)
604 assert(privateFlags.isSet(VALID_PADDR | VALID_VADDR));
605 _memSpaceConfigFlags.set(extraFlags);
608 /** Accessor function for vaddr.*/
612 return privateFlags.isSet(VALID_VADDR);
618 assert(privateFlags.isSet(VALID_VADDR));
622 /** Accesssor for the requestor id. */
636 taskId(uint32_t id) {
640 /** Accessor function for asid.*/
644 assert(privateFlags.isSet(VALID_VADDR));
648 /** Accessor function for asid.*/
655 /** Accessor function for architecture-specific flags.*/
659 assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
660 return _flags & ARCH_BITS;
663 /** Accessor function to check if sc result is valid. */
665 extraDataValid() const
667 return privateFlags.isSet(VALID_EXTRA_DATA);
670 /** Accessor function for store conditional return value.*/
674 assert(privateFlags.isSet(VALID_EXTRA_DATA));
678 /** Accessor function for store conditional return value.*/
680 setExtraData(uint64_t extraData)
682 _extraData = extraData;
683 privateFlags.set(VALID_EXTRA_DATA);
689 return privateFlags.isSet(VALID_CONTEXT_ID);
692 /** Accessor function for context ID.*/
696 assert(privateFlags.isSet(VALID_CONTEXT_ID));
703 privateFlags.set(VALID_PC);
710 return privateFlags.isSet(VALID_PC);
713 /** Accessor function for pc.*/
717 assert(privateFlags.isSet(VALID_PC));
722 * Increment/Get the depth at which this request is responded to.
723 * This currently happens when the request misses in any cache level.
725 void incAccessDepth() const { depth++; }
726 int getAccessDepth() const { return depth; }
729 * Set/Get the time taken for this request to be successfully translated.
731 void setTranslateLatency() { translateDelta = curTick() - _time; }
732 Tick getTranslateLatency() const { return translateDelta; }
735 * Set/Get the time taken to complete this request's access, not including
736 * the time to successfully translate the request.
738 void setAccessLatency() { accessDelta = curTick() - _time - translateDelta; }
739 Tick getAccessLatency() const { return accessDelta; }
742 * Accessor for the sequence number of instruction that creates the
746 hasInstSeqNum() const
748 return privateFlags.isSet(VALID_INST_SEQ_NUM);
752 getReqInstSeqNum() const
754 assert(privateFlags.isSet(VALID_INST_SEQ_NUM));
755 return _reqInstSeqNum;
759 setReqInstSeqNum(const InstSeqNum seq_num)
761 privateFlags.set(VALID_INST_SEQ_NUM);
762 _reqInstSeqNum = seq_num;
765 /** Accessor functions for flags. Note that these are for testing
766 only; setting flags should be done via setFlags(). */
767 bool isUncacheable() const { return _flags.isSet(UNCACHEABLE); }
768 bool isStrictlyOrdered() const { return _flags.isSet(STRICT_ORDER); }
769 bool isInstFetch() const { return _flags.isSet(INST_FETCH); }
770 bool isPrefetch() const { return _flags.isSet(PREFETCH); }
771 bool isLLSC() const { return _flags.isSet(LLSC); }
772 bool isPriv() const { return _flags.isSet(PRIVILEGED); }
773 bool isLockedRMW() const { return _flags.isSet(LOCKED_RMW); }
774 bool isSwap() const { return _flags.isSet(MEM_SWAP|MEM_SWAP_COND); }
775 bool isCondSwap() const { return _flags.isSet(MEM_SWAP_COND); }
776 bool isMmappedIpr() const { return _flags.isSet(MMAPPED_IPR); }
777 bool isSecure() const { return _flags.isSet(SECURE); }
778 bool isPTWalk() const { return _flags.isSet(PT_WALK); }
779 bool isAcquire() const { return _flags.isSet(ACQUIRE); }
780 bool isRelease() const { return _flags.isSet(RELEASE); }
781 bool isKernel() const { return _flags.isSet(KERNEL); }
782 bool isAtomicReturn() const { return _flags.isSet(ATOMIC_RETURN_OP); }
783 bool isAtomicNoReturn() const { return _flags.isSet(ATOMIC_NO_RETURN_OP); }
788 return _flags.isSet(ATOMIC_RETURN_OP) ||
789 _flags.isSet(ATOMIC_NO_RETURN_OP);
793 * Accessor functions for the memory space configuration flags and used by
794 * GPU ISAs such as the Heterogeneous System Architecture (HSA). Note that
795 * these are for testing only; setting extraFlags should be done via
796 * setMemSpaceConfigFlags().
798 bool isScoped() const { return _memSpaceConfigFlags.isSet(SCOPE_VALID); }
801 isWavefrontScope() const
804 return _memSpaceConfigFlags.isSet(WAVEFRONT_SCOPE);
808 isWorkgroupScope() const
811 return _memSpaceConfigFlags.isSet(WORKGROUP_SCOPE);
815 isDeviceScope() const
818 return _memSpaceConfigFlags.isSet(DEVICE_SCOPE);
822 isSystemScope() const
825 return _memSpaceConfigFlags.isSet(SYSTEM_SCOPE);
829 isGlobalSegment() const
831 return _memSpaceConfigFlags.isSet(GLOBAL_SEGMENT) ||
832 (!isGroupSegment() && !isPrivateSegment() &&
833 !isKernargSegment() && !isReadonlySegment() &&
834 !isSpillSegment() && !isArgSegment());
838 isGroupSegment() const
840 return _memSpaceConfigFlags.isSet(GROUP_SEGMENT);
844 isPrivateSegment() const
846 return _memSpaceConfigFlags.isSet(PRIVATE_SEGMENT);
850 isKernargSegment() const
852 return _memSpaceConfigFlags.isSet(KERNARG_SEGMENT);
856 isReadonlySegment() const
858 return _memSpaceConfigFlags.isSet(READONLY_SEGMENT);
862 isSpillSegment() const
864 return _memSpaceConfigFlags.isSet(SPILL_SEGMENT);
870 return _memSpaceConfigFlags.isSet(ARG_SEGMENT);
874 #endif // __MEM_REQUEST_HH__