base.cc revision 12727
12810SN/A/* 210623Smitch.hayenga@arm.com * Copyright (c) 2013-2014 ARM Limited 39546Sandreas.hansson@arm.com * All rights reserved. 49546Sandreas.hansson@arm.com * 59546Sandreas.hansson@arm.com * The license below extends only to copyright in the software and shall 69546Sandreas.hansson@arm.com * not be construed as granting a license to any other intellectual 79546Sandreas.hansson@arm.com * property including but not limited to intellectual property relating 89546Sandreas.hansson@arm.com * to a hardware implementation of the functionality of the software 99546Sandreas.hansson@arm.com * licensed hereunder. You may use the software subject to the license 109546Sandreas.hansson@arm.com * terms below provided that you ensure that this notice is replicated 119546Sandreas.hansson@arm.com * unmodified and in its entirety in all distributions of the software, 129546Sandreas.hansson@arm.com * modified or unmodified, in source code or in binary form. 139546Sandreas.hansson@arm.com * 142810SN/A * Copyright (c) 2005 The Regents of The University of Michigan 152810SN/A * All rights reserved. 162810SN/A * 172810SN/A * Redistribution and use in source and binary forms, with or without 182810SN/A * modification, are permitted provided that the following conditions are 192810SN/A * met: redistributions of source code must retain the above copyright 202810SN/A * notice, this list of conditions and the following disclaimer; 212810SN/A * redistributions in binary form must reproduce the above copyright 222810SN/A * notice, this list of conditions and the following disclaimer in the 232810SN/A * documentation and/or other materials provided with the distribution; 242810SN/A * neither the name of the copyright holders nor the names of its 252810SN/A * contributors may be used to endorse or promote products derived from 262810SN/A * this software without specific prior written permission. 272810SN/A * 282810SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292810SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 302810SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 312810SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 322810SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 332810SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 342810SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 352810SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 362810SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 372810SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 382810SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392810SN/A * 402810SN/A * Authors: Ron Dreslinski 4110623Smitch.hayenga@arm.com * Mitch Hayenga 422810SN/A */ 432810SN/A 442810SN/A/** 452810SN/A * @file 462810SN/A * Hardware Prefetcher Definition. 472810SN/A */ 482810SN/A 4911793Sbrandon.potter@amd.com#include "mem/cache/prefetch/base.hh" 5011793Sbrandon.potter@amd.com 5112727Snikos.nikoleris@arm.com#include <cassert> 526658Snate@binkert.org 5311438SRekai.GonzalezAlberquilla@arm.com#include "base/intmath.hh" 545338Sstever@gmail.com#include "mem/cache/base.hh" 5512727Snikos.nikoleris@arm.com#include "params/BasePrefetcher.hh" 568832SAli.Saidi@ARM.com#include "sim/system.hh" 572810SN/A 5810623Smitch.hayenga@arm.comBasePrefetcher::BasePrefetcher(const BasePrefetcherParams *p) 5911438SRekai.GonzalezAlberquilla@arm.com : ClockedObject(p), cache(nullptr), blkSize(0), lBlkSize(0), 6011438SRekai.GonzalezAlberquilla@arm.com system(p->sys), onMiss(p->on_miss), onRead(p->on_read), 6110623Smitch.hayenga@arm.com onWrite(p->on_write), onData(p->on_data), onInst(p->on_inst), 6212680Sgiacomo.travaglini@arm.com masterId(system->getMasterId(this)), 6310466Sandreas.hansson@arm.com pageBytes(system->getPageBytes()) 642810SN/A{ 652810SN/A} 662810SN/A 672810SN/Avoid 682810SN/ABasePrefetcher::setCache(BaseCache *_cache) 692810SN/A{ 7010360Sandreas.hansson@arm.com assert(!cache); 712810SN/A cache = _cache; 722810SN/A blkSize = cache->getBlockSize(); 7311438SRekai.GonzalezAlberquilla@arm.com lBlkSize = floorLog2(blkSize); 742810SN/A} 752810SN/A 762810SN/Avoid 778831Smrinmoy.ghosh@arm.comBasePrefetcher::regStats() 782810SN/A{ 7911522Sstephan.diestelhorst@arm.com ClockedObject::regStats(); 8011522Sstephan.diestelhorst@arm.com 812810SN/A pfIssued 8210623Smitch.hayenga@arm.com .name(name() + ".num_hwpf_issued") 832810SN/A .desc("number of hwpf issued") 842810SN/A ; 8511438SRekai.GonzalezAlberquilla@arm.com 862810SN/A} 872810SN/A 8810623Smitch.hayenga@arm.combool 8910623Smitch.hayenga@arm.comBasePrefetcher::observeAccess(const PacketPtr &pkt) const 9010623Smitch.hayenga@arm.com{ 9110623Smitch.hayenga@arm.com Addr addr = pkt->getAddr(); 9210623Smitch.hayenga@arm.com bool fetch = pkt->req->isInstFetch(); 9310626SCurtis.Dunham@arm.com bool read = pkt->isRead(); 9410626SCurtis.Dunham@arm.com bool inv = pkt->isInvalidate(); 9510623Smitch.hayenga@arm.com bool is_secure = pkt->isSecure(); 9610623Smitch.hayenga@arm.com 9710623Smitch.hayenga@arm.com if (pkt->req->isUncacheable()) return false; 9810623Smitch.hayenga@arm.com if (fetch && !onInst) return false; 9910623Smitch.hayenga@arm.com if (!fetch && !onData) return false; 10010623Smitch.hayenga@arm.com if (!fetch && read && !onRead) return false; 10110623Smitch.hayenga@arm.com if (!fetch && !read && !onWrite) return false; 10210626SCurtis.Dunham@arm.com if (!fetch && !read && inv) return false; 10310883Sali.jafri@arm.com if (pkt->cmd == MemCmd::CleanEvict) return false; 10410623Smitch.hayenga@arm.com 10510623Smitch.hayenga@arm.com if (onMiss) { 10610623Smitch.hayenga@arm.com return !inCache(addr, is_secure) && 10710623Smitch.hayenga@arm.com !inMissQueue(addr, is_secure); 10810623Smitch.hayenga@arm.com } 10910623Smitch.hayenga@arm.com 11010623Smitch.hayenga@arm.com return true; 11110623Smitch.hayenga@arm.com} 11210623Smitch.hayenga@arm.com 11310623Smitch.hayenga@arm.combool 11410623Smitch.hayenga@arm.comBasePrefetcher::inCache(Addr addr, bool is_secure) const 1153861SN/A{ 11610028SGiacomo.Gabrielli@arm.com if (cache->inCache(addr, is_secure)) { 1173861SN/A return true; 1183861SN/A } 1193861SN/A return false; 1203861SN/A} 1213861SN/A 12210623Smitch.hayenga@arm.combool 12310623Smitch.hayenga@arm.comBasePrefetcher::inMissQueue(Addr addr, bool is_secure) const 1243861SN/A{ 12510028SGiacomo.Gabrielli@arm.com if (cache->inMissQueue(addr, is_secure)) { 1263861SN/A return true; 1273861SN/A } 1283861SN/A return false; 1293861SN/A} 1303861SN/A 1315875Ssteve.reinhardt@amd.combool 13210466Sandreas.hansson@arm.comBasePrefetcher::samePage(Addr a, Addr b) const 1335875Ssteve.reinhardt@amd.com{ 13410466Sandreas.hansson@arm.com return roundDown(a, pageBytes) == roundDown(b, pageBytes); 1355875Ssteve.reinhardt@amd.com} 1368831Smrinmoy.ghosh@arm.com 13711438SRekai.GonzalezAlberquilla@arm.comAddr 13811438SRekai.GonzalezAlberquilla@arm.comBasePrefetcher::blockAddress(Addr a) const 13911438SRekai.GonzalezAlberquilla@arm.com{ 14011438SRekai.GonzalezAlberquilla@arm.com return a & ~(blkSize-1); 14111438SRekai.GonzalezAlberquilla@arm.com} 1428831Smrinmoy.ghosh@arm.com 14311438SRekai.GonzalezAlberquilla@arm.comAddr 14411438SRekai.GonzalezAlberquilla@arm.comBasePrefetcher::blockIndex(Addr a) const 14511438SRekai.GonzalezAlberquilla@arm.com{ 14611438SRekai.GonzalezAlberquilla@arm.com return a >> lBlkSize; 14711438SRekai.GonzalezAlberquilla@arm.com} 14811438SRekai.GonzalezAlberquilla@arm.com 14911438SRekai.GonzalezAlberquilla@arm.comAddr 15011438SRekai.GonzalezAlberquilla@arm.comBasePrefetcher::pageAddress(Addr a) const 15111438SRekai.GonzalezAlberquilla@arm.com{ 15211438SRekai.GonzalezAlberquilla@arm.com return roundDown(a, pageBytes); 15311438SRekai.GonzalezAlberquilla@arm.com} 15411438SRekai.GonzalezAlberquilla@arm.com 15511438SRekai.GonzalezAlberquilla@arm.comAddr 15611438SRekai.GonzalezAlberquilla@arm.comBasePrefetcher::pageOffset(Addr a) const 15711438SRekai.GonzalezAlberquilla@arm.com{ 15811438SRekai.GonzalezAlberquilla@arm.com return a & (pageBytes - 1); 15911438SRekai.GonzalezAlberquilla@arm.com} 16011438SRekai.GonzalezAlberquilla@arm.com 16111438SRekai.GonzalezAlberquilla@arm.comAddr 16211438SRekai.GonzalezAlberquilla@arm.comBasePrefetcher::pageIthBlockAddress(Addr page, uint32_t blockIndex) const 16311438SRekai.GonzalezAlberquilla@arm.com{ 16411438SRekai.GonzalezAlberquilla@arm.com return page + (blockIndex << lBlkSize); 16511438SRekai.GonzalezAlberquilla@arm.com} 166