45 #include "debug/HWPrefetch.hh"
46 #include "debug/HWPrefetchQueue.hh"
49 #include "params/QueuedPrefetcher.hh"
64 RequestPtr req = std::make_shared<Request>(paddr, blk_size,
83 assert(translationRequest !=
nullptr);
84 if (!ongoingTranslation) {
85 ongoingTranslation =
true;
95 assert(ongoingTranslation);
96 ongoingTranslation =
false;
97 bool failed = (fault !=
NoFault);
98 owner->translationComplete(
this, failed);
104 p.max_prefetch_requests_with_pending_translation),
124 std::string queue_name =
"";
125 if (&queue == &
pfq) {
129 queue_name =
"PFTransQ";
136 Addr paddr = it->pkt ? it->pkt->getAddr() : 0;
137 DPRINTF(HWPrefetchQueue,
"%s[%d]: Prefetch Req VA: %#x PA: %#x "
138 "prio: %3d\n", queue_name, pos,
vaddr, paddr, it->priority);
161 size_t max_pfs =
total;
164 size_t min_pfs = (
total - throttle_pfs) == 0 ?
165 1 : (
total - throttle_pfs);
166 max_pfs = min_pfs + (
total - min_pfs) *
180 auto itr =
pfq.begin();
181 while (itr !=
pfq.end()) {
182 if (itr->pfInfo.getAddr() == blk_addr &&
183 itr->pfInfo.isSecure() == is_secure) {
184 DPRINTF(HWPrefetch,
"Removing pf candidate addr: %#x "
185 "(cl: %#x), demand request going to the same addr\n",
186 itr->pfInfo.getAddr(),
189 itr =
pfq.erase(itr);
219 bool can_cross_page = (
tlb !=
nullptr);
223 DPRINTF(HWPrefetch,
"Found a pf candidate addr: %#x, "
224 "inserting into prefetch queue.\n", new_pfi.
getAddr());
226 insert(pkt, new_pfi, addr_prio.second);
228 if (num_pfs == max_pfs) {
232 DPRINTF(HWPrefetch,
"Ignoring page crossing prefetch.\n");
240 DPRINTF(HWPrefetch,
"Requesting a prefetch to issue.\n");
249 DPRINTF(HWPrefetch,
"No hardware prefetches available.\n");
258 assert(pkt !=
nullptr);
259 DPRINTF(HWPrefetch,
"Generating prefetch for %#x.\n", pkt->
getAddr());
266 : statistics::
Group(parent),
268 "number of prefetch candidates identified"),
270 "number of redundant prefetches already in prefetch queue"),
272 "number of redundant prefetches already in cache/mshr dropped"),
274 "number of prefetches dropped due to a demand for the same "
277 "number of prefetches dropped due to prefetch queue size"),
279 "number of prefetches that crossed the page"),
281 "number of prefetches that is useful and crossed the page")
296 dp.startTranslation(
tlb);
313 DPRINTF(HWPrefetch,
"%s Translation of vaddr %#x succeeded: "
315 it->translationRequest->getVaddr(),
316 it->translationRequest->getPaddr());
317 Addr target_paddr = it->translationRequest->getPaddr();
320 inMissQueue(target_paddr, it->pfInfo.isSecure()))) {
322 DPRINTF(HWPrefetch,
"Dropping redundant in "
323 "cache/MSHR prefetch addr:%#x\n", target_paddr);
331 DPRINTF(HWPrefetch,
"%s Translation of vaddr %#x failed, dropping "
332 "prefetch request %#x \n",
tlb->
name(),
333 it->translationRequest->getVaddr());
344 for (it = queue.begin(); it != queue.end() && !found; it++) {
345 found = it->pfInfo.sameAddr(pfi);
349 if (it != queue.end()) {
351 if (it->priority < priority) {
353 it->priority = priority;
355 while (prev != queue.begin()) {
359 std::swap(*it, *prev);
363 DPRINTF(HWPrefetch,
"Prefetch addr already in "
364 "prefetch queue, priority updated\n");
366 DPRINTF(HWPrefetch,
"Prefetch addr already in "
377 RequestPtr translation_req = std::make_shared<Request>(
379 pkt->
req->contextId());
381 return translation_req;
410 pkt->
req->getVaddr() : pkt->
req->getPaddr();
411 bool positive_stride = new_pfi.
getAddr() >= orig_addr;
413 (new_pfi.
getAddr() - orig_addr) : (orig_addr - new_pfi.
getAddr());
416 bool has_target_pa =
false;
423 target_paddr = positive_stride ? (pkt->
req->getPaddr() +
stride) :
426 target_paddr = new_pfi.
getAddr();
428 has_target_pa =
true;
433 if (!pkt->
req->hasContextId()) {
437 has_target_pa =
false;
440 }
else if (pkt->
req->hasVaddr()) {
441 has_target_pa =
false;
443 Addr target_vaddr = positive_stride ?
458 DPRINTF(HWPrefetch,
"Dropping redundant in "
459 "cache/MSHR prefetch addr:%#x\n", target_paddr);
469 DPRINTF(HWPrefetch,
"Prefetch queued. "
470 "addr:%#x priority: %3d tick:%lld.\n",
471 new_pfi.
getAddr(), priority, pf_time);
477 DPRINTF(HWPrefetch,
"Prefetch queued with no translation. "
478 "addr:%#x priority: %3d\n", new_pfi.
getAddr(), priority);
493 "Prefetch queue is both full and empty!");
497 "Prefetch queue is full with 1 element!");
501 while (cont && prev != queue.begin()) {
504 cont = prev->priority == it->priority;
509 DPRINTF(HWPrefetch,
"Prefetch queue full, removing lowest priority "
510 "oldest packet, addr: %#x\n",it->pfInfo.getAddr());
515 if ((queue.size() == 0) || (dpp <= queue.back())) {
516 queue.emplace_back(dpp);
521 }
while (it != queue.begin() && dpp > *it);
524 if (it == queue.begin() && dpp <= *it)
526 queue.insert(it, dpp);
529 if (debug::HWPrefetchQueue)
System * system
System we are currently operating in.
virtual void translateTiming(const RequestPtr &req, ThreadContext *tc, BaseMMU::Translation *translation, BaseMMU::Mode mode)=0
virtual std::string name() const
A Packet is used to encapsulate a transfer between two objects in the memory system (e....
RequestPtr req
A pointer to the original request.
void allocate()
Allocate memory for the packet.
@ SECURE
The request targets the secure memory space.
@ PREFETCH
The request is a prefetch.
ThreadContext is the external interface to all thread state for anything outside of the CPU.
Class containing the information needed by the prefetch to train and generate new prefetch requests.
Addr getPC() const
Returns the program counter that generated this request.
bool isSecure() const
Returns true if the address targets the secure memory space.
Addr getAddr() const
Obtains the address value of this Prefetcher address.
bool hasPC() const
Returns true if the associated program counter is valid.
const bool useVirtualAddresses
Use Virtual Addresses for prefetching.
unsigned blkSize
The block size of the parent cache.
uint64_t issuedPrefetches
Total prefetches issued.
bool inCache(Addr addr, bool is_secure) const
Determine if address is in cache.
const RequestorID requestorId
Request id for prefetches.
BaseTLB * tlb
Registered tlb for address translations.
bool inMissQueue(Addr addr, bool is_secure) const
Determine if address is in cache miss queue.
bool hasBeenPrefetched(Addr addr, bool is_secure) const
uint64_t usefulPrefetches
Total prefetches that has been useful.
gem5::prefetch::Base::StatGroup prefetchStats
BaseCache * cache
Pointr to the parent cache.
Addr blockAddress(Addr a) const
Determine the address of the block in which a lays.
bool samePage(Addr a, Addr b) const
Determine if addresses are on the same page.
const bool queueSquash
Squash queued prefetch if demand access observed.
void translationComplete(DeferredPacket *dp, bool failed)
Indicates that the translation of the address of the provided deferred packet has been successfully c...
gem5::prefetch::Queued::QueuedStats statsQueued
std::list< DeferredPacket >::iterator iterator
Queued(const QueuedPrefetcherParams &p)
void printQueue(const std::list< DeferredPacket > &queue) const
const unsigned queueSize
Maximum size of the prefetch queue.
std::list< DeferredPacket > pfqMissingTranslation
void processMissingTranslations(unsigned max)
Starts the translations of the queued prefetches with a missing translation.
RequestPtr createPrefetchRequest(Addr addr, PrefetchInfo const &pfi, PacketPtr pkt)
void notify(const PacketPtr &pkt, const PrefetchInfo &pfi) override
Notify prefetcher of cache access (may be any access or just misses, depending on cache parameters....
const bool queueFilter
Filter prefetches if already queued.
std::list< DeferredPacket >::const_iterator const_iterator
const bool tagPrefetch
Tag prefetch with PC of generating access?
const Cycles latency
Cycles after generation when a prefetch can first be issued.
const bool cacheSnoop
Snoop the cache before generating prefetch (cheating basically)
const unsigned int throttleControlPct
Percentage of requests that can be throttled.
void insert(const PacketPtr &pkt, PrefetchInfo &new_pfi, int32_t priority)
PacketPtr getPacket() override
void addToQueue(std::list< DeferredPacket > &queue, DeferredPacket &dpp)
Adds a DeferredPacket to the specified queue.
bool alreadyInQueue(std::list< DeferredPacket > &queue, const PrefetchInfo &pfi, int32_t priority)
Checks whether the specified prefetch request is already in the specified queue.
size_t getMaxPermittedPrefetches(size_t total) const
Returns the maxmimum number of prefetch requests that are allowed to be created from the number of pr...
virtual void calculatePrefetch(const PrefetchInfo &pfi, std::vector< AddrPriority > &addresses)=0
const unsigned missingTranslationQueueSize
Maximum size of the queue holding prefetch requests with missing address translations.
std::list< DeferredPacket > pfq
#define ADD_STAT(n,...)
Convenience macro to add a stat to a statistics group.
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
Declares a basic cache interface BaseCache.
Bitfield< 21, 20 > stride
ProbePointArg< PacketInfo > Packet
Packet probe point.
const FlagsType total
Print the total.
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
std::shared_ptr< FaultBase > Fault
std::shared_ptr< Request > RequestPtr
Tick curTick()
The universal simulation clock.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
uint64_t Tick
Tick count type.
constexpr decltype(nullptr) NoFault
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
Declaration of a request, the overall memory request consisting of the parts of the request that are ...
statistics::Scalar pfIssued
Tick tick
Time when this prefetch becomes ready.
void startTranslation(BaseTLB *tlb)
Issues the translation request to the provided TLB.
void setTranslationRequest(const RequestPtr &req)
Sets the translation request needed to obtain the physical address of this request.
void createPkt(Addr paddr, unsigned blk_size, RequestorID requestor_id, bool tag_prefetch, Tick t)
Create the associated memory packet.
void finish(const Fault &fault, const RequestPtr &req, ThreadContext *tc, BaseMMU::Mode mode) override
PacketPtr pkt
The memory packet generated by this prefetch.
PrefetchInfo pfInfo
Prefetch info corresponding to this packet.
statistics::Scalar pfUsefulSpanPage
statistics::Scalar pfBufferHit
statistics::Scalar pfIdentified
statistics::Scalar pfRemovedDemand
statistics::Scalar pfRemovedFull
statistics::Scalar pfSpanPage
statistics::Scalar pfInCache
QueuedStats(statistics::Group *parent)