/*
+ * Copyright (c) 2012-2013 ARM Limited
+ * All rights reserved
+ *
+ * The license below extends only to copyright in the software and shall
+ * not be construed as granting a license to any other intellectual
+ * property including but not limited to intellectual property relating
+ * to a hardware implementation of the functionality of the software
+ * licensed hereunder. You may use the software subject to the license
+ * terms below provided that you ensure that this notice is replicated
+ * unmodified and in its entirety in all distributions of the software,
+ * modified or unmodified, in source code or in binary form.
+ *
* Copyright (c) 2002-2005 The Regents of The University of Michigan
+ * Copyright (c) 2010,2015 Advanced Micro Devices, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
#ifndef __MEM_REQUEST_HH__
#define __MEM_REQUEST_HH__
-#include "sim/host.hh"
-#include "sim/root.hh"
-
#include <cassert>
+#include <climits>
-class Request;
+#include "base/flags.hh"
+#include "base/misc.hh"
+#include "base/types.hh"
+#include "sim/core.hh"
-typedef Request* RequestPtr;
+/**
+ * Special TaskIds that are used for per-context-switch stats dumps
+ * and Cache Occupancy. Having too many tasks seems to be a problem
+ * with vector stats. 1024 seems to be a reasonable number that
+ * doesn't cause a problem with stats and is large enough to realistic
+ * benchmarks (Linux/Android boot, BBench, etc.)
+ */
+namespace ContextSwitchTaskId {
+ enum TaskId {
+ MaxNormalTaskId = 1021, /* Maximum number of normal tasks */
+ Prefetcher = 1022, /* For cache lines brought in by prefetcher */
+ DMA = 1023, /* Mostly Table Walker */
+ Unknown = 1024,
+ NumTaskId
+ };
+}
-/** The request is a Load locked/store conditional. */
-const unsigned LOCKED = 0x001;
-/** The virtual address is also the physical address. */
-const unsigned PHYSICAL = 0x002;
-/** The request is an ALPHA VPTE pal access (hw_ld). */
-const unsigned VPTE = 0x004;
-/** Use the alternate mode bits in ALPHA. */
-const unsigned ALTMODE = 0x008;
-/** The request is to an uncacheable address. */
-const unsigned UNCACHEABLE = 0x010;
-/** The request should not cause a page fault. */
-const unsigned NO_FAULT = 0x020;
-/** The request should be prefetched into the exclusive state. */
-const unsigned PF_EXCLUSIVE = 0x100;
-/** The request should be marked as LRU. */
-const unsigned EVICT_NEXT = 0x200;
-/** The request should ignore unaligned access faults */
-const unsigned NO_ALIGN_FAULT = 0x400;
-/** The request was an instruction read. */
-const unsigned INST_READ = 0x800;
+class Request;
+
+typedef Request* RequestPtr;
+typedef uint16_t MasterID;
class Request
{
+ public:
+ typedef uint32_t FlagsType;
+ typedef uint8_t ArchFlagsType;
+ typedef ::Flags<FlagsType> Flags;
+
+ enum : FlagsType {
+ /**
+ * Architecture specific flags.
+ *
+ * These bits int the flag field are reserved for
+ * architecture-specific code. For example, SPARC uses them to
+ * represent ASIs.
+ */
+ ARCH_BITS = 0x000000FF,
+ /** The request was an instruction fetch. */
+ INST_FETCH = 0x00000100,
+ /** The virtual address is also the physical address. */
+ PHYSICAL = 0x00000200,
+ /**
+ * The request is to an uncacheable address.
+ *
+ * @note Uncacheable accesses may be reordered by CPU models. The
+ * STRICT_ORDER flag should be set if such reordering is
+ * undesirable.
+ */
+ UNCACHEABLE = 0x00000400,
+ /**
+ * The request is required to be strictly ordered by <i>CPU
+ * models</i> and is non-speculative.
+ *
+ * A strictly ordered request is guaranteed to never be
+ * re-ordered or executed speculatively by a CPU model. The
+ * memory system may still reorder requests in caches unless
+ * the UNCACHEABLE flag is set as well.
+ */
+ STRICT_ORDER = 0x00000800,
+ /** This request is to a memory mapped register. */
+ MMAPPED_IPR = 0x00002000,
+ /** This request is made in privileged mode. */
+ PRIVILEGED = 0x00008000,
+
+ /**
+ * This is a write that is targeted and zeroing an entire
+ * cache block. There is no need for a read/modify/write
+ */
+ CACHE_BLOCK_ZERO = 0x00010000,
+
+ /** The request should not cause a memory access. */
+ NO_ACCESS = 0x00080000,
+ /**
+ * This request will lock or unlock the accessed memory. When
+ * used with a load, the access locks the particular chunk of
+ * memory. When used with a store, it unlocks. The rule is
+ * that locked accesses have to be made up of a locked load,
+ * some operation on the data, and then a locked store.
+ */
+ LOCKED_RMW = 0x00100000,
+ /** The request is a Load locked/store conditional. */
+ LLSC = 0x00200000,
+ /** This request is for a memory swap. */
+ MEM_SWAP = 0x00400000,
+ MEM_SWAP_COND = 0x00800000,
+
+ /** The request is a prefetch. */
+ PREFETCH = 0x01000000,
+ /** The request should be prefetched into the exclusive state. */
+ PF_EXCLUSIVE = 0x02000000,
+ /** The request should be marked as LRU. */
+ EVICT_NEXT = 0x04000000,
+
+ /**
+ * The request should be handled by the generic IPR code (only
+ * valid together with MMAPPED_IPR)
+ */
+ GENERIC_IPR = 0x08000000,
+
+ /** The request targets the secure memory space. */
+ SECURE = 0x10000000,
+ /** The request is a page table walk */
+ PT_WALK = 0x20000000,
+
+ /**
+ * These flags are *not* cleared when a Request object is
+ * reused (assigned a new address).
+ */
+ STICKY_FLAGS = INST_FETCH
+ };
+
+ /** Master Ids that are statically allocated
+ * @{*/
+ enum : MasterID {
+ /** This master id is used for writeback requests by the caches */
+ wbMasterId = 0,
+ /**
+ * This master id is used for functional requests that
+ * don't come from a particular device
+ */
+ funcMasterId = 1,
+ /** This master id is used for message signaled interrupts */
+ intMasterId = 2,
+ /**
+ * Invalid master id for assertion checking only. It is
+ * invalid behavior to ever send this id as part of a request.
+ */
+ invldMasterId = std::numeric_limits<MasterID>::max()
+ };
+ /** @} */
+
+ private:
+ typedef uint8_t PrivateFlagsType;
+ typedef ::Flags<PrivateFlagsType> PrivateFlags;
+
+ enum : PrivateFlagsType {
+ /** Whether or not the size is valid. */
+ VALID_SIZE = 0x00000001,
+ /** Whether or not paddr is valid (has been written yet). */
+ VALID_PADDR = 0x00000002,
+ /** Whether or not the vaddr & asid are valid. */
+ VALID_VADDR = 0x00000004,
+ /** Whether or not the pc is valid. */
+ VALID_PC = 0x00000010,
+ /** Whether or not the context ID is valid. */
+ VALID_CONTEXT_ID = 0x00000020,
+ VALID_THREAD_ID = 0x00000040,
+ /** Whether or not the sc result is valid. */
+ VALID_EXTRA_DATA = 0x00000080,
+
+ /**
+ * These flags are *not* cleared when a Request object is reused
+ * (assigned a new address).
+ */
+ STICKY_PRIVATE_FLAGS = VALID_CONTEXT_ID | VALID_THREAD_ID
+ };
+
private:
+
+ /**
+ * Set up a physical (e.g. device) request in a previously
+ * allocated Request object.
+ */
+ void
+ setPhys(Addr paddr, unsigned size, Flags flags, MasterID mid, Tick time)
+ {
+ assert(size >= 0);
+ _paddr = paddr;
+ _size = size;
+ _time = time;
+ _masterId = mid;
+ _flags.clear(~STICKY_FLAGS);
+ _flags.set(flags);
+ privateFlags.clear(~STICKY_PRIVATE_FLAGS);
+ privateFlags.set(VALID_PADDR|VALID_SIZE);
+ depth = 0;
+ accessDelta = 0;
+ //translateDelta = 0;
+ }
+
/**
* The physical address of the request. Valid only if validPaddr
- * is set. */
- Addr paddr;
+ * is set.
+ */
+ Addr _paddr;
/**
* The size of the request. This field must be set when vaddr or
* paddr is written via setVirt() or setPhys(), so it is always
- * valid as long as one of the address fields is valid. */
- int size;
+ * valid as long as one of the address fields is valid.
+ */
+ unsigned _size;
+
+ /** The requestor ID which is unique in the system for all ports
+ * that are capable of issuing a transaction
+ */
+ MasterID _masterId;
/** Flag structure for the request. */
- uint32_t flags;
+ Flags _flags;
+
+ /** Private flags for field validity checking. */
+ PrivateFlags privateFlags;
/**
* The time this request was started. Used to calculate
- * latencies. This field is set to curTick any time paddr or vaddr
- * is written. */
- Tick time;
+ * latencies. This field is set to curTick() any time paddr or vaddr
+ * is written.
+ */
+ Tick _time;
+
+ /**
+ * The task id associated with this request
+ */
+ uint32_t _taskId;
/** The address space ID. */
- int asid;
+ int _asid;
+
/** The virtual address of the request. */
- Addr vaddr;
+ Addr _vaddr;
- /** The return value of store conditional. */
- uint64_t scResult;
+ /**
+ * Extra data for the request, such as the return value of
+ * store conditional or the compare value for a CAS. */
+ uint64_t _extraData;
- /** The cpu number (for statistics, typically). */
- int cpuNum;
- /** The requesting thread id (for statistics, typically). */
- int threadNum;
+ /** The context ID (for statistics, typically). */
+ ContextID _contextId;
+ /** The thread ID (id within this CPU) */
+ ThreadID _threadId;
/** program counter of initiating access; for tracing/debugging */
- Addr pc;
-
- /** Whether or not paddr is valid (has been written yet). */
- bool validPaddr;
- /** Whether or not the asid & vaddr are valid. */
- bool validAsidVaddr;
- /** Whether or not the sc result is valid. */
- bool validScResult;
- /** Whether or not the cpu number & thread ID are valid. */
- bool validCpuAndThreadNums;
- /** Whether or not the pc is valid. */
- bool validPC;
+ Addr _pc;
public:
- /** Minimal constructor. No fields are initialized. */
+
+ /**
+ * Minimal constructor. No fields are initialized. (Note that
+ * _flags and privateFlags are cleared by Flags default
+ * constructor.)
+ */
Request()
- : validPaddr(false), validAsidVaddr(false),
- validScResult(false), validCpuAndThreadNums(false), validPC(false)
+ : _paddr(0), _size(0), _masterId(invldMasterId), _time(0),
+ _taskId(ContextSwitchTaskId::Unknown), _asid(0), _vaddr(0),
+ _extraData(0), _contextId(0), _threadId(0), _pc(0),
+ translateDelta(0), accessDelta(0), depth(0)
{}
/**
* Constructor for physical (e.g. device) requests. Initializes
- * just physical address, size, flags, and timestamp (to curTick).
- * These fields are adequate to perform a request. */
- Request(Addr _paddr, int _size, int _flags)
- : validCpuAndThreadNums(false)
- { setPhys(_paddr, _size, _flags); }
+ * just physical address, size, flags, and timestamp (to curTick()).
+ * These fields are adequate to perform a request.
+ */
+ Request(Addr paddr, unsigned size, Flags flags, MasterID mid)
+ : _paddr(0), _size(0), _masterId(invldMasterId), _time(0),
+ _taskId(ContextSwitchTaskId::Unknown), _asid(0), _vaddr(0),
+ _extraData(0), _contextId(0), _threadId(0), _pc(0),
+ translateDelta(0), accessDelta(0), depth(0)
+ {
+ setPhys(paddr, size, flags, mid, curTick());
+ }
- Request(int _asid, Addr _vaddr, int _size, int _flags, Addr _pc,
- int _cpuNum, int _threadNum)
+ Request(Addr paddr, unsigned size, Flags flags, MasterID mid, Tick time)
+ : _paddr(0), _size(0), _masterId(invldMasterId), _time(0),
+ _taskId(ContextSwitchTaskId::Unknown), _asid(0), _vaddr(0),
+ _extraData(0), _contextId(0), _threadId(0), _pc(0),
+ translateDelta(0), accessDelta(0), depth(0)
{
- setThreadContext(_cpuNum, _threadNum);
- setVirt(_asid, _vaddr, _size, _flags, _pc);
+ setPhys(paddr, size, flags, mid, time);
}
- /**
- * Set up CPU and thread numbers. */
- void setThreadContext(int _cpuNum, int _threadNum)
+ Request(Addr paddr, unsigned size, Flags flags, MasterID mid, Tick time,
+ Addr pc)
+ : _paddr(0), _size(0), _masterId(invldMasterId), _time(0),
+ _taskId(ContextSwitchTaskId::Unknown), _asid(0), _vaddr(0),
+ _extraData(0), _contextId(0), _threadId(0), _pc(0),
+ translateDelta(0), accessDelta(0), depth(0)
{
- cpuNum = _cpuNum;
- threadNum = _threadNum;
- validCpuAndThreadNums = true;
+ setPhys(paddr, size, flags, mid, time);
+ privateFlags.set(VALID_PC);
+ _pc = pc;
}
+ Request(int asid, Addr vaddr, unsigned size, Flags flags, MasterID mid,
+ Addr pc, ContextID cid, ThreadID tid)
+ : _paddr(0), _size(0), _masterId(invldMasterId), _time(0),
+ _taskId(ContextSwitchTaskId::Unknown), _asid(0), _vaddr(0),
+ _extraData(0), _contextId(0), _threadId(0), _pc(0),
+ translateDelta(0), accessDelta(0), depth(0)
+ {
+ setVirt(asid, vaddr, size, flags, mid, pc);
+ setThreadContext(cid, tid);
+ }
+
+ ~Request() {}
+
/**
- * Set up a physical (e.g. device) request in a previously
- * allocated Request object. */
- void setPhys(Addr _paddr, int _size, int _flags)
+ * Set up CPU and thread numbers.
+ */
+ void
+ setThreadContext(ContextID context_id, ThreadID tid)
{
- paddr = _paddr;
- size = _size;
- flags = _flags;
- time = curTick;
- validPaddr = true;
- validAsidVaddr = false;
- validPC = false;
- validScResult = false;
+ _contextId = context_id;
+ _threadId = tid;
+ privateFlags.set(VALID_CONTEXT_ID|VALID_THREAD_ID);
}
/**
* Set up a virtual (e.g., CPU) request in a previously
- * allocated Request object. */
- void setVirt(int _asid, Addr _vaddr, int _size, int _flags, Addr _pc)
+ * allocated Request object.
+ */
+ void
+ setVirt(int asid, Addr vaddr, unsigned size, Flags flags, MasterID mid,
+ Addr pc)
+ {
+ _asid = asid;
+ _vaddr = vaddr;
+ _size = size;
+ _masterId = mid;
+ _pc = pc;
+ _time = curTick();
+
+ _flags.clear(~STICKY_FLAGS);
+ _flags.set(flags);
+ privateFlags.clear(~STICKY_PRIVATE_FLAGS);
+ privateFlags.set(VALID_VADDR|VALID_SIZE|VALID_PC);
+ depth = 0;
+ accessDelta = 0;
+ translateDelta = 0;
+ }
+
+ /**
+ * Set just the physical address. This usually used to record the
+ * result of a translation. However, when using virtualized CPUs
+ * setPhys() is sometimes called to finalize a physical address
+ * without a virtual address, so we can't check if the virtual
+ * address is valid.
+ */
+ void
+ setPaddr(Addr paddr)
{
- asid = _asid;
- vaddr = _vaddr;
- size = _size;
- flags = _flags;
- pc = _pc;
- time = curTick;
- validPaddr = false;
- validAsidVaddr = true;
- validPC = true;
- validScResult = false;
+ _paddr = paddr;
+ privateFlags.set(VALID_PADDR);
}
- /** Set just the physical address. This should only be used to
- * record the result of a translation, and thus the vaddr must be
- * valid before this method is called. Otherwise, use setPhys()
- * to guarantee that the size and flags are also set.
+ /**
+ * Generate two requests as if this request had been split into two
+ * pieces. The original request can't have been translated already.
*/
- void setPaddr(Addr _paddr)
+ void splitOnVaddr(Addr split_addr, RequestPtr &req1, RequestPtr &req2)
+ {
+ assert(privateFlags.isSet(VALID_VADDR));
+ assert(privateFlags.noneSet(VALID_PADDR));
+ assert(split_addr > _vaddr && split_addr < _vaddr + _size);
+ req1 = new Request(*this);
+ req2 = new Request(*this);
+ req1->_size = split_addr - _vaddr;
+ req2->_vaddr = split_addr;
+ req2->_size = _size - req1->_size;
+ }
+
+ /**
+ * Accessor for paddr.
+ */
+ bool
+ hasPaddr() const
+ {
+ return privateFlags.isSet(VALID_PADDR);
+ }
+
+ Addr
+ getPaddr() const
{
- assert(validAsidVaddr);
- paddr = _paddr;
- validPaddr = true;
+ assert(privateFlags.isSet(VALID_PADDR));
+ return _paddr;
}
- /** Accessor for paddr. */
- Addr getPaddr() { assert(validPaddr); return paddr; }
+ /**
+ * Time for the TLB/table walker to successfully translate this request.
+ */
+ Tick translateDelta;
+
+ /**
+ * Access latency to complete this memory transaction not including
+ * translation time.
+ */
+ Tick accessDelta;
+
+ /**
+ * Level of the cache hierachy where this request was responded to
+ * (e.g. 0 = L1; 1 = L2).
+ */
+ mutable int depth;
+
+ /**
+ * Accessor for size.
+ */
+ bool
+ hasSize() const
+ {
+ return privateFlags.isSet(VALID_SIZE);
+ }
+
+ unsigned
+ getSize() const
+ {
+ assert(privateFlags.isSet(VALID_SIZE));
+ return _size;
+ }
- /** Accessor for size. */
- int getSize() { assert(validPaddr || validAsidVaddr); return size; }
/** Accessor for time. */
- Tick getTime() { assert(validPaddr || validAsidVaddr); return time; }
+ Tick
+ time() const
+ {
+ assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
+ return _time;
+ }
/** Accessor for flags. */
- uint32_t getFlags() { assert(validPaddr || validAsidVaddr); return flags; }
- /** Accessor for paddr. */
- void setFlags(uint32_t _flags)
- { assert(validPaddr || validAsidVaddr); flags = _flags; }
+ Flags
+ getFlags()
+ {
+ assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
+ return _flags;
+ }
+
+ /** Note that unlike other accessors, this function sets *specific
+ flags* (ORs them in); it does not assign its argument to the
+ _flags field. Thus this method should rightly be called
+ setFlags() and not just flags(). */
+ void
+ setFlags(Flags flags)
+ {
+ assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
+ _flags.set(flags);
+ }
/** Accessor function for vaddr.*/
- Addr getVaddr() { assert(validAsidVaddr); return vaddr; }
+ bool
+ hasVaddr() const
+ {
+ return privateFlags.isSet(VALID_VADDR);
+ }
+
+ Addr
+ getVaddr() const
+ {
+ assert(privateFlags.isSet(VALID_VADDR));
+ return _vaddr;
+ }
+
+ /** Accesssor for the requestor id. */
+ MasterID
+ masterId() const
+ {
+ return _masterId;
+ }
+
+ uint32_t
+ taskId() const
+ {
+ return _taskId;
+ }
+
+ void
+ taskId(uint32_t id) {
+ _taskId = id;
+ }
+
+ /** Accessor function for asid.*/
+ int
+ getAsid() const
+ {
+ assert(privateFlags.isSet(VALID_VADDR));
+ return _asid;
+ }
/** Accessor function for asid.*/
- int getAsid() { assert(validAsidVaddr); return asid; }
+ void
+ setAsid(int asid)
+ {
+ _asid = asid;
+ }
+
+ /** Accessor function for architecture-specific flags.*/
+ ArchFlagsType
+ getArchFlags() const
+ {
+ assert(privateFlags.isSet(VALID_PADDR|VALID_VADDR));
+ return _flags & ARCH_BITS;
+ }
/** Accessor function to check if sc result is valid. */
- bool scResultValid() { return validScResult; }
+ bool
+ extraDataValid() const
+ {
+ return privateFlags.isSet(VALID_EXTRA_DATA);
+ }
+
/** Accessor function for store conditional return value.*/
- uint64_t getScResult() { assert(validScResult); return scResult; }
+ uint64_t
+ getExtraData() const
+ {
+ assert(privateFlags.isSet(VALID_EXTRA_DATA));
+ return _extraData;
+ }
+
/** Accessor function for store conditional return value.*/
- void setScResult(uint64_t _scResult)
- { scResult = _scResult; validScResult = true; }
+ void
+ setExtraData(uint64_t extraData)
+ {
+ _extraData = extraData;
+ privateFlags.set(VALID_EXTRA_DATA);
+ }
+
+ bool
+ hasContextId() const
+ {
+ return privateFlags.isSet(VALID_CONTEXT_ID);
+ }
- /** Accessor function for cpu number.*/
- int getCpuNum() { assert(validCpuAndThreadNums); return cpuNum; }
- /** Accessor function for thread number.*/
- int getThreadNum() { assert(validCpuAndThreadNums); return threadNum; }
+ /** Accessor function for context ID.*/
+ ContextID
+ contextId() const
+ {
+ assert(privateFlags.isSet(VALID_CONTEXT_ID));
+ return _contextId;
+ }
+
+ /** Accessor function for thread ID. */
+ ThreadID
+ threadId() const
+ {
+ assert(privateFlags.isSet(VALID_THREAD_ID));
+ return _threadId;
+ }
+
+ void
+ setPC(Addr pc)
+ {
+ privateFlags.set(VALID_PC);
+ _pc = pc;
+ }
+
+ bool
+ hasPC() const
+ {
+ return privateFlags.isSet(VALID_PC);
+ }
/** Accessor function for pc.*/
- Addr getPC() { assert(validPC); return pc; }
+ Addr
+ getPC() const
+ {
+ assert(privateFlags.isSet(VALID_PC));
+ return _pc;
+ }
- /** Accessor Function to Check Cacheability. */
- bool isUncacheable() { return getFlags() & UNCACHEABLE; }
+ /**
+ * Increment/Get the depth at which this request is responded to.
+ * This currently happens when the request misses in any cache level.
+ */
+ void incAccessDepth() const { depth++; }
+ int getAccessDepth() const { return depth; }
- bool isInstRead() { return getFlags() & INST_READ; }
+ /**
+ * Set/Get the time taken for this request to be successfully translated.
+ */
+ void setTranslateLatency() { translateDelta = curTick() - _time; }
+ Tick getTranslateLatency() const { return translateDelta; }
- friend class Packet;
+ /**
+ * Set/Get the time taken to complete this request's access, not including
+ * the time to successfully translate the request.
+ */
+ void setAccessLatency() { accessDelta = curTick() - _time - translateDelta; }
+ Tick getAccessLatency() const { return accessDelta; }
+
+ /** Accessor functions for flags. Note that these are for testing
+ only; setting flags should be done via setFlags(). */
+ bool isUncacheable() const { return _flags.isSet(UNCACHEABLE); }
+ bool isStrictlyOrdered() const { return _flags.isSet(STRICT_ORDER); }
+ bool isInstFetch() const { return _flags.isSet(INST_FETCH); }
+ bool isPrefetch() const { return _flags.isSet(PREFETCH); }
+ bool isLLSC() const { return _flags.isSet(LLSC); }
+ bool isPriv() const { return _flags.isSet(PRIVILEGED); }
+ bool isLockedRMW() const { return _flags.isSet(LOCKED_RMW); }
+ bool isSwap() const { return _flags.isSet(MEM_SWAP|MEM_SWAP_COND); }
+ bool isCondSwap() const { return _flags.isSet(MEM_SWAP_COND); }
+ bool isMmappedIpr() const { return _flags.isSet(MMAPPED_IPR); }
+ bool isSecure() const { return _flags.isSet(SECURE); }
+ bool isPTWalk() const { return _flags.isSet(PT_WALK); }
};
#endif // __MEM_REQUEST_HH__