queued.hh revision 13416:d90887d0c889
110448Snilay@cs.wisc.edu/* 210448Snilay@cs.wisc.edu * Copyright (c) 2014-2015 ARM Limited 310448Snilay@cs.wisc.edu * All rights reserved 410448Snilay@cs.wisc.edu * 510448Snilay@cs.wisc.edu * The license below extends only to copyright in the software and shall 610448Snilay@cs.wisc.edu * not be construed as granting a license to any other intellectual 710448Snilay@cs.wisc.edu * property including but not limited to intellectual property relating 810448Snilay@cs.wisc.edu * to a hardware implementation of the functionality of the software 910448Snilay@cs.wisc.edu * licensed hereunder. You may use the software subject to the license 1010448Snilay@cs.wisc.edu * terms below provided that you ensure that this notice is replicated 1110448Snilay@cs.wisc.edu * unmodified and in its entirety in all distributions of the software, 1210448Snilay@cs.wisc.edu * modified or unmodified, in source code or in binary form. 1310448Snilay@cs.wisc.edu * 1410448Snilay@cs.wisc.edu * Redistribution and use in source and binary forms, with or without 1510448Snilay@cs.wisc.edu * modification, are permitted provided that the following conditions are 1610448Snilay@cs.wisc.edu * met: redistributions of source code must retain the above copyright 1710448Snilay@cs.wisc.edu * notice, this list of conditions and the following disclaimer; 1810448Snilay@cs.wisc.edu * redistributions in binary form must reproduce the above copyright 1910448Snilay@cs.wisc.edu * notice, this list of conditions and the following disclaimer in the 2010448Snilay@cs.wisc.edu * documentation and/or other materials provided with the distribution; 2110448Snilay@cs.wisc.edu * neither the name of the copyright holders nor the names of its 2210447Snilay@cs.wisc.edu * contributors may be used to endorse or promote products derived from 2310447Snilay@cs.wisc.edu * this software without specific prior written permission. 2410447Snilay@cs.wisc.edu * 2510447Snilay@cs.wisc.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2610447Snilay@cs.wisc.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2710447Snilay@cs.wisc.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2810447Snilay@cs.wisc.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2910447Snilay@cs.wisc.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3010447Snilay@cs.wisc.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3110447Snilay@cs.wisc.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3210447Snilay@cs.wisc.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3310447Snilay@cs.wisc.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3410447Snilay@cs.wisc.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3510447Snilay@cs.wisc.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3610447Snilay@cs.wisc.edu * 3710447Snilay@cs.wisc.edu * Authors: Mitch Hayenga 3810447Snilay@cs.wisc.edu */ 3910447Snilay@cs.wisc.edu 4010447Snilay@cs.wisc.edu#ifndef __MEM_CACHE_PREFETCH_QUEUED_HH__ 4110447Snilay@cs.wisc.edu#define __MEM_CACHE_PREFETCH_QUEUED_HH__ 4210447Snilay@cs.wisc.edu 4310447Snilay@cs.wisc.edu#include <cstdint> 4410447Snilay@cs.wisc.edu#include <list> 4510447Snilay@cs.wisc.edu#include <utility> 4610447Snilay@cs.wisc.edu 4710447Snilay@cs.wisc.edu#include "base/statistics.hh" 4810447Snilay@cs.wisc.edu#include "base/types.hh" 4910447Snilay@cs.wisc.edu#include "mem/cache/prefetch/base.hh" 5010447Snilay@cs.wisc.edu#include "mem/packet.hh" 5110447Snilay@cs.wisc.edu 5210447Snilay@cs.wisc.edustruct QueuedPrefetcherParams; 5310447Snilay@cs.wisc.edu 5410447Snilay@cs.wisc.educlass QueuedPrefetcher : public BasePrefetcher 5510447Snilay@cs.wisc.edu{ 5610447Snilay@cs.wisc.edu protected: 5710447Snilay@cs.wisc.edu struct DeferredPacket { 5810447Snilay@cs.wisc.edu Tick tick; 5910447Snilay@cs.wisc.edu PacketPtr pkt; 6010447Snilay@cs.wisc.edu int32_t priority; 6110447Snilay@cs.wisc.edu DeferredPacket(Tick t, PacketPtr p, int32_t pr) : tick(t), pkt(p), 6210447Snilay@cs.wisc.edu priority(pr) {} 6310447Snilay@cs.wisc.edu bool operator>(const DeferredPacket& that) const 6410447Snilay@cs.wisc.edu { 6510447Snilay@cs.wisc.edu return priority > that.priority; 6610447Snilay@cs.wisc.edu } 6710447Snilay@cs.wisc.edu bool operator<(const DeferredPacket& that) const 6810447Snilay@cs.wisc.edu { 6910447Snilay@cs.wisc.edu return priority < that.priority; 7010447Snilay@cs.wisc.edu } 7110447Snilay@cs.wisc.edu bool operator<=(const DeferredPacket& that) const 7210447Snilay@cs.wisc.edu { 7310447Snilay@cs.wisc.edu return !(*this > that); 7410447Snilay@cs.wisc.edu } 7510447Snilay@cs.wisc.edu }; 7610447Snilay@cs.wisc.edu using AddrPriority = std::pair<Addr, int32_t>; 7710447Snilay@cs.wisc.edu 7810447Snilay@cs.wisc.edu std::list<DeferredPacket> pfq; 7910447Snilay@cs.wisc.edu 8010447Snilay@cs.wisc.edu // PARAMETERS 8110447Snilay@cs.wisc.edu 8210447Snilay@cs.wisc.edu /** Maximum size of the prefetch queue */ 8310447Snilay@cs.wisc.edu const unsigned queueSize; 8410447Snilay@cs.wisc.edu 8510447Snilay@cs.wisc.edu /** Cycles after generation when a prefetch can first be issued */ 8610447Snilay@cs.wisc.edu const Cycles latency; 8710447Snilay@cs.wisc.edu 8810447Snilay@cs.wisc.edu /** Squash queued prefetch if demand access observed */ 8910447Snilay@cs.wisc.edu const bool queueSquash; 9010447Snilay@cs.wisc.edu 9110447Snilay@cs.wisc.edu /** Filter prefetches if already queued */ 9210447Snilay@cs.wisc.edu const bool queueFilter; 9310447Snilay@cs.wisc.edu 9410447Snilay@cs.wisc.edu /** Snoop the cache before generating prefetch (cheating basically) */ 95 const bool cacheSnoop; 96 97 /** Tag prefetch with PC of generating access? */ 98 const bool tagPrefetch; 99 100 using const_iterator = std::list<DeferredPacket>::const_iterator; 101 std::list<DeferredPacket>::const_iterator inPrefetch(Addr address, 102 bool is_secure) const; 103 using iterator = std::list<DeferredPacket>::iterator; 104 std::list<DeferredPacket>::iterator inPrefetch(Addr address, 105 bool is_secure); 106 107 // STATS 108 Stats::Scalar pfIdentified; 109 Stats::Scalar pfBufferHit; 110 Stats::Scalar pfInCache; 111 Stats::Scalar pfRemovedFull; 112 Stats::Scalar pfSpanPage; 113 114 public: 115 QueuedPrefetcher(const QueuedPrefetcherParams *p); 116 virtual ~QueuedPrefetcher(); 117 118 void notify(const PacketPtr &pkt) override; 119 PacketPtr insert(AddrPriority& info, bool is_secure); 120 121 // Note: This should really be pure virtual, but doesnt go well with params 122 virtual void calculatePrefetch(const PacketPtr &pkt, 123 std::vector<AddrPriority> &addresses) = 0; 124 PacketPtr getPacket(); 125 126 Tick nextPrefetchReadyTime() const 127 { 128 return pfq.empty() ? MaxTick : pfq.front().tick; 129 } 130 131 void regStats(); 132}; 133 134#endif //__MEM_CACHE_PREFETCH_QUEUED_HH__ 135 136