base.cc revision 12843
12810SN/A/* 22810SN/A * Copyright (c) 2013-2014 ARM Limited 32810SN/A * All rights reserved. 42810SN/A * 52810SN/A * The license below extends only to copyright in the software and shall 62810SN/A * not be construed as granting a license to any other intellectual 72810SN/A * property including but not limited to intellectual property relating 82810SN/A * to a hardware implementation of the functionality of the software 92810SN/A * licensed hereunder. You may use the software subject to the license 102810SN/A * terms below provided that you ensure that this notice is replicated 112810SN/A * unmodified and in its entirety in all distributions of the software, 122810SN/A * modified or unmodified, in source code or in binary form. 132810SN/A * 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 366658Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 376658Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 385875Ssteve.reinhardt@amd.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 392810SN/A * 406658Snate@binkert.org * Authors: Ron Dreslinski 418232Snate@binkert.org * Mitch Hayenga 428229Snate@binkert.org */ 435338Sstever@gmail.com 442814SN/A/** 458832SAli.Saidi@ARM.com * @file 462810SN/A * Hardware Prefetcher Definition. 478831Smrinmoy.ghosh@arm.com */ 488831Smrinmoy.ghosh@arm.com 498832SAli.Saidi@ARM.com#include "mem/cache/prefetch/base.hh" 508832SAli.Saidi@ARM.com 518832SAli.Saidi@ARM.com#include <cassert> 522810SN/A 532810SN/A#include "base/intmath.hh" 542810SN/A#include "mem/cache/base.hh" 552810SN/A#include "params/BasePrefetcher.hh" 562810SN/A#include "sim/system.hh" 572810SN/A 582810SN/ABasePrefetcher::BasePrefetcher(const BasePrefetcherParams *p) 592810SN/A : ClockedObject(p), cache(nullptr), blkSize(0), lBlkSize(0), 602810SN/A system(p->sys), onMiss(p->on_miss), onRead(p->on_read), 612810SN/A onWrite(p->on_write), onData(p->on_data), onInst(p->on_inst), 622810SN/A masterId(system->getMasterId(this)), 638831Smrinmoy.ghosh@arm.com pageBytes(system->getPageBytes()) 642810SN/A{ 652810SN/A} 668831Smrinmoy.ghosh@arm.com 672810SN/Avoid 682810SN/ABasePrefetcher::setCache(BaseCache *_cache) 692810SN/A{ 702810SN/A assert(!cache); 718831Smrinmoy.ghosh@arm.com cache = _cache; 722810SN/A blkSize = cache->getBlockSize(); 732810SN/A lBlkSize = floorLog2(blkSize); 742810SN/A} 752810SN/A 768831Smrinmoy.ghosh@arm.comvoid 772810SN/ABasePrefetcher::regStats() 782810SN/A{ 792810SN/A ClockedObject::regStats(); 802810SN/A 818831Smrinmoy.ghosh@arm.com pfIssued 822810SN/A .name(name() + ".num_hwpf_issued") 832810SN/A .desc("number of hwpf issued") 842810SN/A ; 852810SN/A 868831Smrinmoy.ghosh@arm.com} 872810SN/A 882810SN/Abool 892810SN/ABasePrefetcher::observeAccess(const PacketPtr &pkt) const 902810SN/A{ 918831Smrinmoy.ghosh@arm.com Addr addr = pkt->getAddr(); 922810SN/A bool fetch = pkt->req->isInstFetch(); 932810SN/A bool read = pkt->isRead(); 942810SN/A bool inv = pkt->isInvalidate(); 952810SN/A bool is_secure = pkt->isSecure(); 968831Smrinmoy.ghosh@arm.com 972810SN/A if (pkt->req->isUncacheable()) return false; 982810SN/A if (fetch && !onInst) return false; 992810SN/A if (!fetch && !onData) return false; 1002810SN/A if (!fetch && read && !onRead) return false; 1018831Smrinmoy.ghosh@arm.com if (!fetch && !read && !onWrite) return false; 1022810SN/A if (!fetch && !read && inv) return false; 1032810SN/A if (pkt->cmd == MemCmd::CleanEvict) return false; 1042810SN/A 1052810SN/A if (onMiss) { 1068831Smrinmoy.ghosh@arm.com return !inCache(addr, is_secure) && 1075875Ssteve.reinhardt@amd.com !inMissQueue(addr, is_secure); 1085875Ssteve.reinhardt@amd.com } 1092810SN/A 1102810SN/A return true; 1112810SN/A} 1123861SN/A 1133861SN/Abool 1143861SN/ABasePrefetcher::inCache(Addr addr, bool is_secure) const 1153861SN/A{ 1163861SN/A if (cache->inCache(addr, is_secure)) { 1173861SN/A return true; 1183861SN/A } 1193861SN/A return false; 1203861SN/A} 1213861SN/A 1223861SN/Abool 1233861SN/ABasePrefetcher::inMissQueue(Addr addr, bool is_secure) const 1243861SN/A{ 1253861SN/A if (cache->inMissQueue(addr, is_secure)) { 1263861SN/A return true; 1273861SN/A } 1283861SN/A return false; 1293861SN/A} 1303861SN/A 1313861SN/Abool 1323349SN/ABasePrefetcher::samePage(Addr a, Addr b) const 1332810SN/A{ 1342810SN/A return roundDown(a, pageBytes) == roundDown(b, pageBytes); 1355875Ssteve.reinhardt@amd.com} 1362810SN/A 1372810SN/AAddr 1385875Ssteve.reinhardt@amd.comBasePrefetcher::blockAddress(Addr a) const 1392810SN/A{ 1402810SN/A return a & ~(blkSize-1); 1412810SN/A} 1428533SLisa.Hsu@amd.com 1438509SAli.Saidi@ARM.comAddr 1442810SN/ABasePrefetcher::blockIndex(Addr a) const 1452810SN/A{ 1465875Ssteve.reinhardt@amd.com return a >> lBlkSize; 1478509SAli.Saidi@ARM.com} 1488509SAli.Saidi@ARM.com 1498509SAli.Saidi@ARM.comAddr 1508509SAli.Saidi@ARM.comBasePrefetcher::pageAddress(Addr a) const 1518509SAli.Saidi@ARM.com{ 1528509SAli.Saidi@ARM.com return roundDown(a, pageBytes); 1538509SAli.Saidi@ARM.com} 1548509SAli.Saidi@ARM.com 1558509SAli.Saidi@ARM.comAddr 1565875Ssteve.reinhardt@amd.comBasePrefetcher::pageOffset(Addr a) const 1572810SN/A{ 1584628SN/A return a & (pageBytes - 1); 1598509SAli.Saidi@ARM.com} 1602810SN/A 1618509SAli.Saidi@ARM.comAddr 1622810SN/ABasePrefetcher::pageIthBlockAddress(Addr page, uint32_t blockIndex) const 1632810SN/A{ 1645875Ssteve.reinhardt@amd.com return page + (blockIndex << lBlkSize); 1655875Ssteve.reinhardt@amd.com} 1662810SN/A