stride.cc revision 10053:b0b69dbafc08
112697Santhony.gutierrez@amd.com/* 212697Santhony.gutierrez@amd.com * Copyright (c) 2012-2013 ARM Limited 311308Santhony.gutierrez@amd.com * All rights reserved 412697Santhony.gutierrez@amd.com * 511308Santhony.gutierrez@amd.com * The license below extends only to copyright in the software and shall 612697Santhony.gutierrez@amd.com * not be construed as granting a license to any other intellectual 712697Santhony.gutierrez@amd.com * property including but not limited to intellectual property relating 811308Santhony.gutierrez@amd.com * to a hardware implementation of the functionality of the software 912697Santhony.gutierrez@amd.com * licensed hereunder. You may use the software subject to the license 1012697Santhony.gutierrez@amd.com * terms below provided that you ensure that this notice is replicated 1111308Santhony.gutierrez@amd.com * unmodified and in its entirety in all distributions of the software, 1212697Santhony.gutierrez@amd.com * modified or unmodified, in source code or in binary form. 1312697Santhony.gutierrez@amd.com * 1412697Santhony.gutierrez@amd.com * Copyright (c) 2005 The Regents of The University of Michigan 1511308Santhony.gutierrez@amd.com * All rights reserved. 1612697Santhony.gutierrez@amd.com * 1712697Santhony.gutierrez@amd.com * Redistribution and use in source and binary forms, with or without 1812697Santhony.gutierrez@amd.com * modification, are permitted provided that the following conditions are 1911308Santhony.gutierrez@amd.com * met: redistributions of source code must retain the above copyright 2012697Santhony.gutierrez@amd.com * notice, this list of conditions and the following disclaimer; 2112697Santhony.gutierrez@amd.com * redistributions in binary form must reproduce the above copyright 2212697Santhony.gutierrez@amd.com * notice, this list of conditions and the following disclaimer in the 2312697Santhony.gutierrez@amd.com * documentation and/or other materials provided with the distribution; 2412697Santhony.gutierrez@amd.com * neither the name of the copyright holders nor the names of its 2512697Santhony.gutierrez@amd.com * contributors may be used to endorse or promote products derived from 2612697Santhony.gutierrez@amd.com * this software without specific prior written permission. 2712697Santhony.gutierrez@amd.com * 2812697Santhony.gutierrez@amd.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 2912697Santhony.gutierrez@amd.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3012697Santhony.gutierrez@amd.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 3111308Santhony.gutierrez@amd.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3211308Santhony.gutierrez@amd.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 3311308Santhony.gutierrez@amd.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 3411308Santhony.gutierrez@amd.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3511308Santhony.gutierrez@amd.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3611308Santhony.gutierrez@amd.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3713665Sandreas.sandberg@arm.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3811308Santhony.gutierrez@amd.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3911308Santhony.gutierrez@amd.com * 4011308Santhony.gutierrez@amd.com * Authors: Ron Dreslinski 4111308Santhony.gutierrez@amd.com * Steve Reinhardt 4211308Santhony.gutierrez@amd.com */ 4311308Santhony.gutierrez@amd.com 4411308Santhony.gutierrez@amd.com/** 4511308Santhony.gutierrez@amd.com * @file 46 * Stride Prefetcher template instantiations. 47 */ 48 49#include "base/trace.hh" 50#include "debug/HWPrefetch.hh" 51#include "mem/cache/prefetch/stride.hh" 52 53void 54StridePrefetcher::calculatePrefetch(PacketPtr &pkt, std::list<Addr> &addresses, 55 std::list<Cycles> &delays) 56{ 57 if (!pkt->req->hasPC()) { 58 DPRINTF(HWPrefetch, "ignoring request with no PC"); 59 return; 60 } 61 62 Addr data_addr = pkt->getAddr(); 63 bool is_secure = pkt->isSecure(); 64 MasterID master_id = useMasterId ? pkt->req->masterId() : 0; 65 Addr pc = pkt->req->getPC(); 66 assert(master_id < Max_Contexts); 67 std::list<StrideEntry*> &tab = table[master_id]; 68 69 // Revert to simple N-block ahead prefetch for instruction fetches 70 if (instTagged && pkt->req->isInstFetch()) { 71 for (int d = 1; d <= degree; d++) { 72 Addr new_addr = data_addr + d * blkSize; 73 if (pageStop && !samePage(data_addr, new_addr)) { 74 // Spanned the page, so now stop 75 pfSpanPage += degree - d + 1; 76 return; 77 } 78 DPRINTF(HWPrefetch, "queuing prefetch to %x @ %d\n", 79 new_addr, latency); 80 addresses.push_back(new_addr); 81 delays.push_back(latency); 82 } 83 return; 84 } 85 86 /* Scan Table for instAddr Match */ 87 std::list<StrideEntry*>::iterator iter; 88 for (iter = tab.begin(); iter != tab.end(); iter++) { 89 // Entries have to match on the security state as well 90 if ((*iter)->instAddr == pc && (*iter)->isSecure == is_secure) 91 break; 92 } 93 94 if (iter != tab.end()) { 95 // Hit in table 96 97 int new_stride = data_addr - (*iter)->missAddr; 98 bool stride_match = (new_stride == (*iter)->stride); 99 100 if (stride_match && new_stride != 0) { 101 if ((*iter)->confidence < Max_Conf) 102 (*iter)->confidence++; 103 } else { 104 (*iter)->stride = new_stride; 105 if ((*iter)->confidence > Min_Conf) 106 (*iter)->confidence = 0; 107 } 108 109 DPRINTF(HWPrefetch, "hit: PC %x data_addr %x (%s) stride %d (%s), " 110 "conf %d\n", pc, data_addr, is_secure ? "s" : "ns", new_stride, 111 stride_match ? "match" : "change", 112 (*iter)->confidence); 113 114 (*iter)->missAddr = data_addr; 115 (*iter)->isSecure = is_secure; 116 117 if ((*iter)->confidence <= 0) 118 return; 119 120 for (int d = 1; d <= degree; d++) { 121 Addr new_addr = data_addr + d * new_stride; 122 if (pageStop && !samePage(data_addr, new_addr)) { 123 // Spanned the page, so now stop 124 pfSpanPage += degree - d + 1; 125 return; 126 } else { 127 DPRINTF(HWPrefetch, " queuing prefetch to %x (%s) @ %d\n", 128 new_addr, is_secure ? "s" : "ns", latency); 129 addresses.push_back(new_addr); 130 delays.push_back(latency); 131 } 132 } 133 } else { 134 // Miss in table 135 // Find lowest confidence and replace 136 137 DPRINTF(HWPrefetch, "miss: PC %x data_addr %x (%s)\n", pc, data_addr, 138 is_secure ? "s" : "ns"); 139 140 if (tab.size() >= 256) { //set default table size is 256 141 std::list<StrideEntry*>::iterator min_pos = tab.begin(); 142 int min_conf = (*min_pos)->confidence; 143 for (iter = min_pos, ++iter; iter != tab.end(); ++iter) { 144 if ((*iter)->confidence < min_conf){ 145 min_pos = iter; 146 min_conf = (*iter)->confidence; 147 } 148 } 149 DPRINTF(HWPrefetch, " replacing PC %x (%s)\n", 150 (*min_pos)->instAddr, (*min_pos)->isSecure ? "s" : "ns"); 151 152 // free entry and delete it 153 delete *min_pos; 154 tab.erase(min_pos); 155 } 156 157 StrideEntry *new_entry = new StrideEntry; 158 new_entry->instAddr = pc; 159 new_entry->missAddr = data_addr; 160 new_entry->isSecure = is_secure; 161 new_entry->stride = 0; 162 new_entry->confidence = 0; 163 tab.push_back(new_entry); 164 } 165} 166 167 168StridePrefetcher* 169StridePrefetcherParams::create() 170{ 171 return new StridePrefetcher(this); 172} 173