queued.hh revision 11439
110623Smitch.hayenga@arm.com/* 211439SRekai.GonzalezAlberquilla@arm.com * Copyright (c) 2014-2015 ARM Limited 310623Smitch.hayenga@arm.com * All rights reserved 410623Smitch.hayenga@arm.com * 510623Smitch.hayenga@arm.com * The license below extends only to copyright in the software and shall 610623Smitch.hayenga@arm.com * not be construed as granting a license to any other intellectual 710623Smitch.hayenga@arm.com * property including but not limited to intellectual property relating 810623Smitch.hayenga@arm.com * to a hardware implementation of the functionality of the software 910623Smitch.hayenga@arm.com * licensed hereunder. You may use the software subject to the license 1010623Smitch.hayenga@arm.com * terms below provided that you ensure that this notice is replicated 1110623Smitch.hayenga@arm.com * unmodified and in its entirety in all distributions of the software, 1210623Smitch.hayenga@arm.com * modified or unmodified, in source code or in binary form. 1310623Smitch.hayenga@arm.com * 1410623Smitch.hayenga@arm.com * Redistribution and use in source and binary forms, with or without 1510623Smitch.hayenga@arm.com * modification, are permitted provided that the following conditions are 1610623Smitch.hayenga@arm.com * met: redistributions of source code must retain the above copyright 1710623Smitch.hayenga@arm.com * notice, this list of conditions and the following disclaimer; 1810623Smitch.hayenga@arm.com * redistributions in binary form must reproduce the above copyright 1910623Smitch.hayenga@arm.com * notice, this list of conditions and the following disclaimer in the 2010623Smitch.hayenga@arm.com * documentation and/or other materials provided with the distribution; 2110623Smitch.hayenga@arm.com * neither the name of the copyright holders nor the names of its 2210623Smitch.hayenga@arm.com * contributors may be used to endorse or promote products derived from 2310623Smitch.hayenga@arm.com * this software without specific prior written permission. 2410623Smitch.hayenga@arm.com * 2510623Smitch.hayenga@arm.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2610623Smitch.hayenga@arm.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 2710623Smitch.hayenga@arm.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 2810623Smitch.hayenga@arm.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2910623Smitch.hayenga@arm.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3010623Smitch.hayenga@arm.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3110623Smitch.hayenga@arm.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3210623Smitch.hayenga@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3310623Smitch.hayenga@arm.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3410623Smitch.hayenga@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3510623Smitch.hayenga@arm.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3610623Smitch.hayenga@arm.com * 3710623Smitch.hayenga@arm.com * Authors: Mitch Hayenga 3810623Smitch.hayenga@arm.com */ 3910623Smitch.hayenga@arm.com 4010623Smitch.hayenga@arm.com#ifndef __MEM_CACHE_PREFETCH_QUEUED_HH__ 4110623Smitch.hayenga@arm.com#define __MEM_CACHE_PREFETCH_QUEUED_HH__ 4210623Smitch.hayenga@arm.com 4310623Smitch.hayenga@arm.com#include <list> 4410623Smitch.hayenga@arm.com 4510623Smitch.hayenga@arm.com#include "mem/cache/prefetch/base.hh" 4610623Smitch.hayenga@arm.com#include "params/QueuedPrefetcher.hh" 4710623Smitch.hayenga@arm.com 4810623Smitch.hayenga@arm.comclass QueuedPrefetcher : public BasePrefetcher 4910623Smitch.hayenga@arm.com{ 5010623Smitch.hayenga@arm.com protected: 5110623Smitch.hayenga@arm.com struct DeferredPacket { 5210623Smitch.hayenga@arm.com Tick tick; 5310623Smitch.hayenga@arm.com PacketPtr pkt; 5411439SRekai.GonzalezAlberquilla@arm.com int32_t priority; 5511439SRekai.GonzalezAlberquilla@arm.com DeferredPacket(Tick t, PacketPtr p, int32_t pr) : tick(t), pkt(p), 5611439SRekai.GonzalezAlberquilla@arm.com priority(pr) {} 5711439SRekai.GonzalezAlberquilla@arm.com bool operator>(const DeferredPacket& that) const 5811439SRekai.GonzalezAlberquilla@arm.com { 5911439SRekai.GonzalezAlberquilla@arm.com return priority > that.priority; 6011439SRekai.GonzalezAlberquilla@arm.com } 6111439SRekai.GonzalezAlberquilla@arm.com bool operator<(const DeferredPacket& that) const 6211439SRekai.GonzalezAlberquilla@arm.com { 6311439SRekai.GonzalezAlberquilla@arm.com return priority < that.priority; 6411439SRekai.GonzalezAlberquilla@arm.com } 6511439SRekai.GonzalezAlberquilla@arm.com bool operator<=(const DeferredPacket& that) const 6611439SRekai.GonzalezAlberquilla@arm.com { 6711439SRekai.GonzalezAlberquilla@arm.com return !(*this > that); 6811439SRekai.GonzalezAlberquilla@arm.com } 6910623Smitch.hayenga@arm.com }; 7011439SRekai.GonzalezAlberquilla@arm.com using AddrPriority = std::pair<Addr, int32_t>; 7110623Smitch.hayenga@arm.com 7210623Smitch.hayenga@arm.com std::list<DeferredPacket> pfq; 7310623Smitch.hayenga@arm.com 7410623Smitch.hayenga@arm.com // PARAMETERS 7510623Smitch.hayenga@arm.com 7610623Smitch.hayenga@arm.com /** Maximum size of the prefetch queue */ 7710623Smitch.hayenga@arm.com const unsigned queueSize; 7810623Smitch.hayenga@arm.com 7910623Smitch.hayenga@arm.com /** Cycles after generation when a prefetch can first be issued */ 8010623Smitch.hayenga@arm.com const Cycles latency; 8110623Smitch.hayenga@arm.com 8210623Smitch.hayenga@arm.com /** Squash queued prefetch if demand access observed */ 8310623Smitch.hayenga@arm.com const bool queueSquash; 8410623Smitch.hayenga@arm.com 8510623Smitch.hayenga@arm.com /** Filter prefetches if already queued */ 8610623Smitch.hayenga@arm.com const bool queueFilter; 8710623Smitch.hayenga@arm.com 8810623Smitch.hayenga@arm.com /** Snoop the cache before generating prefetch (cheating basically) */ 8910623Smitch.hayenga@arm.com const bool cacheSnoop; 9010623Smitch.hayenga@arm.com 9110623Smitch.hayenga@arm.com /** Tag prefetch with PC of generating access? */ 9210623Smitch.hayenga@arm.com const bool tagPrefetch; 9310623Smitch.hayenga@arm.com 9411439SRekai.GonzalezAlberquilla@arm.com using const_iterator = std::list<DeferredPacket>::const_iterator; 9511439SRekai.GonzalezAlberquilla@arm.com std::list<DeferredPacket>::const_iterator inPrefetch(Addr address, 9611439SRekai.GonzalezAlberquilla@arm.com bool is_secure) const; 9711439SRekai.GonzalezAlberquilla@arm.com using iterator = std::list<DeferredPacket>::iterator; 9811439SRekai.GonzalezAlberquilla@arm.com std::list<DeferredPacket>::iterator inPrefetch(Addr address, 9911439SRekai.GonzalezAlberquilla@arm.com bool is_secure); 10010623Smitch.hayenga@arm.com 10110623Smitch.hayenga@arm.com // STATS 10210623Smitch.hayenga@arm.com Stats::Scalar pfIdentified; 10310623Smitch.hayenga@arm.com Stats::Scalar pfBufferHit; 10410623Smitch.hayenga@arm.com Stats::Scalar pfInCache; 10510623Smitch.hayenga@arm.com Stats::Scalar pfRemovedFull; 10610623Smitch.hayenga@arm.com Stats::Scalar pfSpanPage; 10710623Smitch.hayenga@arm.com 10810623Smitch.hayenga@arm.com public: 10910623Smitch.hayenga@arm.com QueuedPrefetcher(const QueuedPrefetcherParams *p); 11010623Smitch.hayenga@arm.com virtual ~QueuedPrefetcher(); 11110623Smitch.hayenga@arm.com 11210623Smitch.hayenga@arm.com Tick notify(const PacketPtr &pkt); 11311439SRekai.GonzalezAlberquilla@arm.com PacketPtr insert(AddrPriority& info, bool is_secure); 11410623Smitch.hayenga@arm.com 11510623Smitch.hayenga@arm.com // Note: This should really be pure virtual, but doesnt go well with params 11610623Smitch.hayenga@arm.com virtual void calculatePrefetch(const PacketPtr &pkt, 11711439SRekai.GonzalezAlberquilla@arm.com std::vector<AddrPriority> &addresses) = 0; 11810623Smitch.hayenga@arm.com PacketPtr getPacket(); 11910623Smitch.hayenga@arm.com 12010623Smitch.hayenga@arm.com Tick nextPrefetchReadyTime() const 12110623Smitch.hayenga@arm.com { 12210623Smitch.hayenga@arm.com return pfq.empty() ? MaxTick : pfq.front().tick; 12310623Smitch.hayenga@arm.com } 12410623Smitch.hayenga@arm.com 12510623Smitch.hayenga@arm.com void regStats(); 12610623Smitch.hayenga@arm.com}; 12710623Smitch.hayenga@arm.com 12810623Smitch.hayenga@arm.com#endif //__MEM_CACHE_PREFETCH_QUEUED_HH__ 12910623Smitch.hayenga@arm.com 130