stride.cc revision 10028
12810SN/A/* 210028SGiacomo.Gabrielli@arm.com * Copyright (c) 2012-2013 ARM Limited 310028SGiacomo.Gabrielli@arm.com * All rights reserved 410028SGiacomo.Gabrielli@arm.com * 510028SGiacomo.Gabrielli@arm.com * The license below extends only to copyright in the software and shall 610028SGiacomo.Gabrielli@arm.com * not be construed as granting a license to any other intellectual 710028SGiacomo.Gabrielli@arm.com * property including but not limited to intellectual property relating 810028SGiacomo.Gabrielli@arm.com * to a hardware implementation of the functionality of the software 910028SGiacomo.Gabrielli@arm.com * licensed hereunder. You may use the software subject to the license 1010028SGiacomo.Gabrielli@arm.com * terms below provided that you ensure that this notice is replicated 1110028SGiacomo.Gabrielli@arm.com * unmodified and in its entirety in all distributions of the software, 1210028SGiacomo.Gabrielli@arm.com * modified or unmodified, in source code or in binary form. 1310028SGiacomo.Gabrielli@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 412810SN/A * Steve Reinhardt 422810SN/A */ 432810SN/A 442810SN/A/** 452810SN/A * @file 462810SN/A * Stride Prefetcher template instantiations. 472810SN/A */ 482810SN/A 495875Ssteve.reinhardt@amd.com#include "base/trace.hh" 508232Snate@binkert.org#include "debug/HWPrefetch.hh" 515338Sstever@gmail.com#include "mem/cache/prefetch/stride.hh" 522810SN/A 533861SN/Avoid 543861SN/AStridePrefetcher::calculatePrefetch(PacketPtr &pkt, std::list<Addr> &addresses, 559288Sandreas.hansson@arm.com std::list<Cycles> &delays) 563861SN/A{ 575875Ssteve.reinhardt@amd.com if (!pkt->req->hasPC()) { 585875Ssteve.reinhardt@amd.com DPRINTF(HWPrefetch, "ignoring request with no PC"); 595875Ssteve.reinhardt@amd.com return; 605875Ssteve.reinhardt@amd.com } 612810SN/A 625875Ssteve.reinhardt@amd.com Addr blk_addr = pkt->getAddr() & ~(Addr)(blkSize-1); 6310028SGiacomo.Gabrielli@arm.com bool is_secure = pkt->isSecure(); 648832SAli.Saidi@ARM.com MasterID master_id = useMasterId ? pkt->req->masterId() : 0; 655875Ssteve.reinhardt@amd.com Addr pc = pkt->req->getPC(); 668832SAli.Saidi@ARM.com assert(master_id < Max_Contexts); 678832SAli.Saidi@ARM.com std::list<StrideEntry*> &tab = table[master_id]; 682810SN/A 695875Ssteve.reinhardt@amd.com /* Scan Table for instAddr Match */ 705875Ssteve.reinhardt@amd.com std::list<StrideEntry*>::iterator iter; 715875Ssteve.reinhardt@amd.com for (iter = tab.begin(); iter != tab.end(); iter++) { 7210028SGiacomo.Gabrielli@arm.com // Entries have to match on the security state as well 7310028SGiacomo.Gabrielli@arm.com if ((*iter)->instAddr == pc && (*iter)->isSecure == is_secure) 745875Ssteve.reinhardt@amd.com break; 755875Ssteve.reinhardt@amd.com } 763861SN/A 775875Ssteve.reinhardt@amd.com if (iter != tab.end()) { 785875Ssteve.reinhardt@amd.com // Hit in table 793861SN/A 805875Ssteve.reinhardt@amd.com int new_stride = blk_addr - (*iter)->missAddr; 815875Ssteve.reinhardt@amd.com bool stride_match = (new_stride == (*iter)->stride); 823861SN/A 835875Ssteve.reinhardt@amd.com if (stride_match && new_stride != 0) { 845875Ssteve.reinhardt@amd.com if ((*iter)->confidence < Max_Conf) 855875Ssteve.reinhardt@amd.com (*iter)->confidence++; 865875Ssteve.reinhardt@amd.com } else { 875875Ssteve.reinhardt@amd.com (*iter)->stride = new_stride; 885875Ssteve.reinhardt@amd.com if ((*iter)->confidence > Min_Conf) 895875Ssteve.reinhardt@amd.com (*iter)->confidence = 0; 905875Ssteve.reinhardt@amd.com } 913861SN/A 9210028SGiacomo.Gabrielli@arm.com DPRINTF(HWPrefetch, "hit: PC %x blk_addr %x (%s) stride %d (%s), " 9310028SGiacomo.Gabrielli@arm.com "conf %d\n", pc, blk_addr, is_secure ? "s" : "ns", new_stride, 9410028SGiacomo.Gabrielli@arm.com stride_match ? "match" : "change", 955875Ssteve.reinhardt@amd.com (*iter)->confidence); 965875Ssteve.reinhardt@amd.com 975875Ssteve.reinhardt@amd.com (*iter)->missAddr = blk_addr; 9810028SGiacomo.Gabrielli@arm.com (*iter)->isSecure = is_secure; 995875Ssteve.reinhardt@amd.com 1005875Ssteve.reinhardt@amd.com if ((*iter)->confidence <= 0) 1015875Ssteve.reinhardt@amd.com return; 1025875Ssteve.reinhardt@amd.com 1035875Ssteve.reinhardt@amd.com for (int d = 1; d <= degree; d++) { 1045875Ssteve.reinhardt@amd.com Addr new_addr = blk_addr + d * new_stride; 1055875Ssteve.reinhardt@amd.com if (pageStop && !samePage(blk_addr, new_addr)) { 1065875Ssteve.reinhardt@amd.com // Spanned the page, so now stop 1075875Ssteve.reinhardt@amd.com pfSpanPage += degree - d + 1; 1085875Ssteve.reinhardt@amd.com return; 1095875Ssteve.reinhardt@amd.com } else { 11010028SGiacomo.Gabrielli@arm.com DPRINTF(HWPrefetch, " queuing prefetch to %x (%s) @ %d\n", 11110028SGiacomo.Gabrielli@arm.com new_addr, is_secure ? "s" : "ns", latency); 1125875Ssteve.reinhardt@amd.com addresses.push_back(new_addr); 1135875Ssteve.reinhardt@amd.com delays.push_back(latency); 1145875Ssteve.reinhardt@amd.com } 1155875Ssteve.reinhardt@amd.com } 1165875Ssteve.reinhardt@amd.com } else { 1175875Ssteve.reinhardt@amd.com // Miss in table 1185875Ssteve.reinhardt@amd.com // Find lowest confidence and replace 1195875Ssteve.reinhardt@amd.com 12010028SGiacomo.Gabrielli@arm.com DPRINTF(HWPrefetch, "miss: PC %x blk_addr %x (%s)\n", pc, blk_addr, 12110028SGiacomo.Gabrielli@arm.com is_secure ? "s" : "ns"); 1225875Ssteve.reinhardt@amd.com 1235875Ssteve.reinhardt@amd.com if (tab.size() >= 256) { //set default table size is 256 1245875Ssteve.reinhardt@amd.com std::list<StrideEntry*>::iterator min_pos = tab.begin(); 1255875Ssteve.reinhardt@amd.com int min_conf = (*min_pos)->confidence; 1265875Ssteve.reinhardt@amd.com for (iter = min_pos, ++iter; iter != tab.end(); ++iter) { 1275875Ssteve.reinhardt@amd.com if ((*iter)->confidence < min_conf){ 1285875Ssteve.reinhardt@amd.com min_pos = iter; 1295875Ssteve.reinhardt@amd.com min_conf = (*iter)->confidence; 1305875Ssteve.reinhardt@amd.com } 1315875Ssteve.reinhardt@amd.com } 13210028SGiacomo.Gabrielli@arm.com DPRINTF(HWPrefetch, " replacing PC %x (%s)\n", 13310028SGiacomo.Gabrielli@arm.com (*min_pos)->instAddr, (*min_pos)->isSecure ? "s" : "ns"); 1348509SAli.Saidi@ARM.com 1358509SAli.Saidi@ARM.com // free entry and delete it 1368509SAli.Saidi@ARM.com delete *min_pos; 1375875Ssteve.reinhardt@amd.com tab.erase(min_pos); 1385875Ssteve.reinhardt@amd.com } 1395875Ssteve.reinhardt@amd.com 1405875Ssteve.reinhardt@amd.com StrideEntry *new_entry = new StrideEntry; 1415875Ssteve.reinhardt@amd.com new_entry->instAddr = pc; 1425875Ssteve.reinhardt@amd.com new_entry->missAddr = blk_addr; 14310028SGiacomo.Gabrielli@arm.com new_entry->isSecure = is_secure; 1445875Ssteve.reinhardt@amd.com new_entry->stride = 0; 1455875Ssteve.reinhardt@amd.com new_entry->confidence = 0; 1465875Ssteve.reinhardt@amd.com tab.push_back(new_entry); 1475875Ssteve.reinhardt@amd.com } 1483861SN/A} 1498831Smrinmoy.ghosh@arm.com 1508831Smrinmoy.ghosh@arm.com 1518831Smrinmoy.ghosh@arm.comStridePrefetcher* 1528831Smrinmoy.ghosh@arm.comStridePrefetcherParams::create() 1538831Smrinmoy.ghosh@arm.com{ 1548831Smrinmoy.ghosh@arm.com return new StridePrefetcher(this); 1558831Smrinmoy.ghosh@arm.com} 156