base.hh revision 9546:ac0c18d738ce
12SN/A/* 21762SN/A * Copyright (c) 2013 ARM Limited 32SN/A * All rights reserved. 42SN/A * 52SN/A * The license below extends only to copyright in the software and shall 62SN/A * not be construed as granting a license to any other intellectual 72SN/A * property including but not limited to intellectual property relating 82SN/A * to a hardware implementation of the functionality of the software 92SN/A * licensed hereunder. You may use the software subject to the license 102SN/A * terms below provided that you ensure that this notice is replicated 112SN/A * unmodified and in its entirety in all distributions of the software, 122SN/A * modified or unmodified, in source code or in binary form. 132SN/A * 142SN/A * Copyright (c) 2005 The Regents of The University of Michigan 152SN/A * All rights reserved. 162SN/A * 172SN/A * Redistribution and use in source and binary forms, with or without 182SN/A * modification, are permitted provided that the following conditions are 192SN/A * met: redistributions of source code must retain the above copyright 202SN/A * notice, this list of conditions and the following disclaimer; 212SN/A * redistributions in binary form must reproduce the above copyright 222SN/A * notice, this list of conditions and the following disclaimer in the 232SN/A * documentation and/or other materials provided with the distribution; 242SN/A * neither the name of the copyright holders nor the names of its 252SN/A * contributors may be used to endorse or promote products derived from 262SN/A * this software without specific prior written permission. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 302SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 311798SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 321798SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 332SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3456SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 352SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 362SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 372SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392667Sstever@eecs.umich.edu * 402SN/A * Authors: Ron Dreslinski 415606Snate@binkert.org */ 422SN/A 432SN/A/** 442SN/A * @file 453144Shsul@eecs.umich.edu * Miss and writeback queue declarations. 462SN/A */ 472SN/A 485606Snate@binkert.org#ifndef __MEM_CACHE_PREFETCH_BASE_PREFETCHER_HH__ 492SN/A#define __MEM_CACHE_PREFETCH_BASE_PREFETCHER_HH__ 502667Sstever@eecs.umich.edu 512667Sstever@eecs.umich.edu#include <list> 522SN/A 535543Ssaidi@eecs.umich.edu#include "base/statistics.hh" 542SN/A#include "mem/packet.hh" 555336Shines@cs.fsu.edu#include "params/BaseCache.hh" 562SN/A#include "sim/clocked_object.hh" 572SN/A 582839Sktlim@umich.educlass BaseCache; 592797Sktlim@umich.edu 602797Sktlim@umich.educlass BasePrefetcher : public ClockedObject 612839Sktlim@umich.edu{ 622797Sktlim@umich.edu protected: 635606Snate@binkert.org 642797Sktlim@umich.edu /** A deferred packet, buffered to transmit later. */ 655606Snate@binkert.org class DeferredPacket { 665606Snate@binkert.org public: 672797Sktlim@umich.edu Tick tick; ///< The tick when the packet is ready to transmit 682797Sktlim@umich.edu PacketPtr pkt; ///< Pointer to the packet to transmit 692797Sktlim@umich.edu DeferredPacket(Tick t, PacketPtr p) 702797Sktlim@umich.edu : tick(t), pkt(p) 712797Sktlim@umich.edu {} 722797Sktlim@umich.edu }; 732797Sktlim@umich.edu 742SN/A /** The Prefetch Queue. */ 752SN/A std::list<DeferredPacket> pf; 762SN/A 772SN/A // PARAMETERS 782SN/A 792SN/A /** The number of MSHRs in the Prefetch Queue. */ 802SN/A const unsigned size; 812SN/A 825543Ssaidi@eecs.umich.edu /** Pointr to the parent cache. */ 835543Ssaidi@eecs.umich.edu BaseCache* cache; 842SN/A 852SN/A /** The block size of the parent cache. */ 865606Snate@binkert.org int blkSize; 872SN/A 885543Ssaidi@eecs.umich.edu /** The latency before a prefetch is issued */ 892SN/A const Cycles latency; 905336Shines@cs.fsu.edu 912SN/A /** The number of prefetches to issue */ 922SN/A unsigned degree; 932SN/A 941798SN/A /** If patterns should be found per context id */ 952SN/A bool useMasterId; 962SN/A /** Do we prefetch across page boundaries. */ 972SN/A bool pageStop; 982SN/A 992SN/A /** Do we remove prefetches with later times than a new miss.*/ 1002SN/A bool serialSquash; 1012SN/A 1025606Snate@binkert.org /** Do we prefetch on only data reads, or on inst reads as well. */ 1035543Ssaidi@eecs.umich.edu bool onlyData; 1042SN/A 1055336Shines@cs.fsu.edu /** System we belong to */ 1062SN/A System* system; 1072SN/A 1081798SN/A /** Request id for prefetches */ 109 MasterID masterId; 110 111 public: 112 113 Stats::Scalar pfIdentified; 114 Stats::Scalar pfMSHRHit; 115 Stats::Scalar pfCacheHit; 116 Stats::Scalar pfBufferHit; 117 Stats::Scalar pfRemovedFull; 118 Stats::Scalar pfRemovedMSHR; 119 Stats::Scalar pfIssued; 120 Stats::Scalar pfSpanPage; 121 Stats::Scalar pfSquashed; 122 123 void regStats(); 124 125 public: 126 typedef BasePrefetcherParams Params; 127 BasePrefetcher(const Params *p); 128 129 virtual ~BasePrefetcher() {} 130 131 void setCache(BaseCache *_cache); 132 133 /** 134 * Notify prefetcher of cache access (may be any access or just 135 * misses, depending on cache parameters.) 136 * @retval Time of next prefetch availability, or 0 if none. 137 */ 138 Tick notify(PacketPtr &pkt, Tick tick); 139 140 bool inCache(Addr addr); 141 142 bool inMissQueue(Addr addr); 143 144 PacketPtr getPacket(); 145 146 bool havePending() 147 { 148 return !pf.empty(); 149 } 150 151 Tick nextPrefetchReadyTime() 152 { 153 return pf.empty() ? MaxTick : pf.front().tick; 154 } 155 156 virtual void calculatePrefetch(PacketPtr &pkt, 157 std::list<Addr> &addresses, 158 std::list<Cycles> &delays) = 0; 159 160 std::list<DeferredPacket>::iterator inPrefetch(Addr address); 161 162 /** 163 * Utility function: are addresses a and b on the same VM page? 164 */ 165 bool samePage(Addr a, Addr b); 166 public: 167 const Params* 168 params() const 169 { 170 return dynamic_cast<const Params *>(_params); 171 } 172 173}; 174#endif //__MEM_CACHE_PREFETCH_BASE_PREFETCHER_HH__ 175