base.cc revision 12727:56c23b54bcb1
11060SN/A/* 22702Sktlim@umich.edu * Copyright (c) 2013-2014 ARM Limited 36973Stjones1@inf.ed.ac.uk * All rights reserved. 41060SN/A * 51060SN/A * The license below extends only to copyright in the software and shall 61060SN/A * not be construed as granting a license to any other intellectual 71060SN/A * property including but not limited to intellectual property relating 81060SN/A * to a hardware implementation of the functionality of the software 91060SN/A * licensed hereunder. You may use the software subject to the license 101060SN/A * terms below provided that you ensure that this notice is replicated 111060SN/A * unmodified and in its entirety in all distributions of the software, 121060SN/A * modified or unmodified, in source code or in binary form. 131060SN/A * 141060SN/A * Copyright (c) 2005 The Regents of The University of Michigan 151060SN/A * All rights reserved. 161060SN/A * 171060SN/A * Redistribution and use in source and binary forms, with or without 181060SN/A * modification, are permitted provided that the following conditions are 191060SN/A * met: redistributions of source code must retain the above copyright 201060SN/A * notice, this list of conditions and the following disclaimer; 211060SN/A * redistributions in binary form must reproduce the above copyright 221060SN/A * notice, this list of conditions and the following disclaimer in the 231060SN/A * documentation and/or other materials provided with the distribution; 241060SN/A * neither the name of the copyright holders nor the names of its 251060SN/A * contributors may be used to endorse or promote products derived from 261060SN/A * this software without specific prior written permission. 271060SN/A * 282665Ssaidi@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 292665Ssaidi@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 306973Stjones1@inf.ed.ac.uk * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 311060SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 321060SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 331464SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 341464SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 351060SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 362731Sktlim@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 372292SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 381464SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 391060SN/A * 402669Sktlim@umich.edu * Authors: Ron Dreslinski 411060SN/A * Mitch Hayenga 421060SN/A */ 431858SN/A 446658Snate@binkert.org/** 453770Sgblack@eecs.umich.edu * @file 461464SN/A * Hardware Prefetcher Definition. 471464SN/A */ 482669Sktlim@umich.edu 491060SN/A#include "mem/cache/prefetch/base.hh" 506973Stjones1@inf.ed.ac.uk 512669Sktlim@umich.edu#include <cassert> 522292SN/A 536023Snate@binkert.org#include "base/intmath.hh" 541060SN/A#include "mem/cache/base.hh" 551060SN/A#include "params/BasePrefetcher.hh" 561060SN/A#include "sim/system.hh" 571060SN/A 581060SN/ABasePrefetcher::BasePrefetcher(const BasePrefetcherParams *p) 591060SN/A : ClockedObject(p), cache(nullptr), blkSize(0), lBlkSize(0), 601061SN/A system(p->sys), onMiss(p->on_miss), onRead(p->on_read), 611061SN/A onWrite(p->on_write), onData(p->on_data), onInst(p->on_inst), 621060SN/A masterId(system->getMasterId(this)), 631060SN/A pageBytes(system->getPageBytes()) 641061SN/A{ 651060SN/A} 661060SN/A 671060SN/Avoid 682733Sktlim@umich.eduBasePrefetcher::setCache(BaseCache *_cache) 692733Sktlim@umich.edu{ 701060SN/A assert(!cache); 712292SN/A cache = _cache; 722107SN/A blkSize = cache->getBlockSize(); 732690Sktlim@umich.edu lBlkSize = floorLog2(blkSize); 742107SN/A} 752690Sktlim@umich.edu 762690Sktlim@umich.eduvoid 771060SN/ABasePrefetcher::regStats() 782292SN/A{ 792292SN/A ClockedObject::regStats(); 802292SN/A 812292SN/A pfIssued 822292SN/A .name(name() + ".num_hwpf_issued") 832292SN/A .desc("number of hwpf issued") 841060SN/A ; 855543Ssaidi@eecs.umich.edu 865543Ssaidi@eecs.umich.edu} 871060SN/A 881060SN/Abool 892292SN/ABasePrefetcher::observeAccess(const PacketPtr &pkt) const 902107SN/A{ 911060SN/A Addr addr = pkt->getAddr(); 921060SN/A bool fetch = pkt->req->isInstFetch(); 931060SN/A bool read = pkt->isRead(); 941060SN/A bool inv = pkt->isInvalidate(); 951060SN/A bool is_secure = pkt->isSecure(); 961060SN/A 972292SN/A if (pkt->req->isUncacheable()) return false; 981060SN/A if (fetch && !onInst) return false; 991060SN/A if (!fetch && !onData) return false; 1005358Sgblack@eecs.umich.edu if (!fetch && read && !onRead) return false; 1015358Sgblack@eecs.umich.edu if (!fetch && !read && !onWrite) return false; 1025358Sgblack@eecs.umich.edu if (!fetch && !read && inv) return false; 1035358Sgblack@eecs.umich.edu if (pkt->cmd == MemCmd::CleanEvict) return false; 1045358Sgblack@eecs.umich.edu 1055358Sgblack@eecs.umich.edu if (onMiss) { 1065358Sgblack@eecs.umich.edu return !inCache(addr, is_secure) && 1075358Sgblack@eecs.umich.edu !inMissQueue(addr, is_secure); 1085358Sgblack@eecs.umich.edu } 1095358Sgblack@eecs.umich.edu 1105358Sgblack@eecs.umich.edu return true; 1115358Sgblack@eecs.umich.edu} 1125358Sgblack@eecs.umich.edu 1132292SN/Abool 1142292SN/ABasePrefetcher::inCache(Addr addr, bool is_secure) const 1152292SN/A{ 1162292SN/A if (cache->inCache(addr, is_secure)) { 1172292SN/A return true; 1182292SN/A } 1192292SN/A return false; 1201060SN/A} 1212132SN/A 1221060SN/Abool 1232292SN/ABasePrefetcher::inMissQueue(Addr addr, bool is_secure) const 1242292SN/A{ 1252292SN/A if (cache->inMissQueue(addr, is_secure)) { 1262292SN/A return true; 1272292SN/A } 1282292SN/A return false; 1292292SN/A} 1302292SN/A 1311060SN/Abool 1326973Stjones1@inf.ed.ac.ukBasePrefetcher::samePage(Addr a, Addr b) const 1336973Stjones1@inf.ed.ac.uk{ 1346973Stjones1@inf.ed.ac.uk return roundDown(a, pageBytes) == roundDown(b, pageBytes); 1356973Stjones1@inf.ed.ac.uk} 1366973Stjones1@inf.ed.ac.uk 1376973Stjones1@inf.ed.ac.ukAddr 1386973Stjones1@inf.ed.ac.ukBasePrefetcher::blockAddress(Addr a) const 1396973Stjones1@inf.ed.ac.uk{ 1401060SN/A return a & ~(blkSize-1); 1411060SN/A} 1421060SN/A 1432132SN/AAddr 1442132SN/ABasePrefetcher::blockIndex(Addr a) const 1451060SN/A{ 1461684SN/A return a >> lBlkSize; 1471060SN/A} 1481060SN/A 1491060SN/AAddr 1501060SN/ABasePrefetcher::pageAddress(Addr a) const 1512731Sktlim@umich.edu{ 1522731Sktlim@umich.edu return roundDown(a, pageBytes); 1532731Sktlim@umich.edu} 1542731Sktlim@umich.edu 1552731Sktlim@umich.eduAddr 1562731Sktlim@umich.eduBasePrefetcher::pageOffset(Addr a) const 1572731Sktlim@umich.edu{ 1582731Sktlim@umich.edu return a & (pageBytes - 1); 1592731Sktlim@umich.edu} 1602731Sktlim@umich.edu 1612731Sktlim@umich.eduAddr 1622731Sktlim@umich.eduBasePrefetcher::pageIthBlockAddress(Addr page, uint32_t blockIndex) const 1632731Sktlim@umich.edu{ 1642731Sktlim@umich.edu return page + (blockIndex << lBlkSize); 1652731Sktlim@umich.edu} 1662731Sktlim@umich.edu