1/* 2 * Copyright (c) 2014-2015 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated 11 * unmodified and in its entirety in all distributions of the software, 12 * modified or unmodified, in source code or in binary form. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions are 16 * met: redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer; 18 * redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution; 21 * neither the name of the copyright holders nor the names of its 22 * contributors may be used to endorse or promote products derived from 23 * this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 * 37 * Authors: Mitch Hayenga 38 */ 39 40#include "mem/cache/prefetch/queued.hh" 41 42#include <cassert> 43 44#include "base/logging.hh" 45#include "base/trace.hh" 46#include "debug/HWPrefetch.hh" 47#include "mem/request.hh" 48#include "params/QueuedPrefetcher.hh" 49 50QueuedPrefetcher::QueuedPrefetcher(const QueuedPrefetcherParams *p) 51 : BasePrefetcher(p), queueSize(p->queue_size), latency(p->latency), 52 queueSquash(p->queue_squash), queueFilter(p->queue_filter), 53 cacheSnoop(p->cache_snoop), tagPrefetch(p->tag_prefetch) 54{ 55 56} 57 58QueuedPrefetcher::~QueuedPrefetcher() 59{ 60 // Delete the queued prefetch packets 61 for (DeferredPacket &p : pfq) {
| 1/* 2 * Copyright (c) 2014-2015 ARM Limited 3 * All rights reserved 4 * 5 * The license below extends only to copyright in the software and shall 6 * not be construed as granting a license to any other intellectual 7 * property including but not limited to intellectual property relating 8 * to a hardware implementation of the functionality of the software 9 * licensed hereunder. You may use the software subject to the license 10 * terms below provided that you ensure that this notice is replicated 11 * unmodified and in its entirety in all distributions of the software, 12 * modified or unmodified, in source code or in binary form. 13 * 14 * Redistribution and use in source and binary forms, with or without 15 * modification, are permitted provided that the following conditions are 16 * met: redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer; 18 * redistributions in binary form must reproduce the above copyright 19 * notice, this list of conditions and the following disclaimer in the 20 * documentation and/or other materials provided with the distribution; 21 * neither the name of the copyright holders nor the names of its 22 * contributors may be used to endorse or promote products derived from 23 * this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 26 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 27 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 28 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 29 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 30 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 31 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 32 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 33 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 34 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 35 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 36 * 37 * Authors: Mitch Hayenga 38 */ 39 40#include "mem/cache/prefetch/queued.hh" 41 42#include <cassert> 43 44#include "base/logging.hh" 45#include "base/trace.hh" 46#include "debug/HWPrefetch.hh" 47#include "mem/request.hh" 48#include "params/QueuedPrefetcher.hh" 49 50QueuedPrefetcher::QueuedPrefetcher(const QueuedPrefetcherParams *p) 51 : BasePrefetcher(p), queueSize(p->queue_size), latency(p->latency), 52 queueSquash(p->queue_squash), queueFilter(p->queue_filter), 53 cacheSnoop(p->cache_snoop), tagPrefetch(p->tag_prefetch) 54{ 55 56} 57 58QueuedPrefetcher::~QueuedPrefetcher() 59{ 60 // Delete the queued prefetch packets 61 for (DeferredPacket &p : pfq) {
|
62 delete p.pkt->req;
| |
63 delete p.pkt; 64 } 65} 66 67Tick 68QueuedPrefetcher::notify(const PacketPtr &pkt) 69{ 70 // Verify this access type is observed by prefetcher 71 if (observeAccess(pkt)) { 72 Addr blk_addr = pkt->getBlockAddr(blkSize); 73 bool is_secure = pkt->isSecure(); 74 75 // Squash queued prefetches if demand miss to same line 76 if (queueSquash) { 77 auto itr = pfq.begin(); 78 while (itr != pfq.end()) { 79 if (itr->pkt->getAddr() == blk_addr && 80 itr->pkt->isSecure() == is_secure) {
| 62 delete p.pkt; 63 } 64} 65 66Tick 67QueuedPrefetcher::notify(const PacketPtr &pkt) 68{ 69 // Verify this access type is observed by prefetcher 70 if (observeAccess(pkt)) { 71 Addr blk_addr = pkt->getBlockAddr(blkSize); 72 bool is_secure = pkt->isSecure(); 73 74 // Squash queued prefetches if demand miss to same line 75 if (queueSquash) { 76 auto itr = pfq.begin(); 77 while (itr != pfq.end()) { 78 if (itr->pkt->getAddr() == blk_addr && 79 itr->pkt->isSecure() == is_secure) {
|
81 delete itr->pkt->req;
| |
82 delete itr->pkt; 83 itr = pfq.erase(itr); 84 } else { 85 ++itr; 86 } 87 } 88 } 89 90 // Calculate prefetches given this access 91 std::vector<AddrPriority> addresses; 92 calculatePrefetch(pkt, addresses); 93 94 // Queue up generated prefetches 95 for (AddrPriority& pf_info : addresses) { 96 97 // Block align prefetch address 98 pf_info.first &= ~(Addr)(blkSize - 1); 99 100 pfIdentified++; 101 DPRINTF(HWPrefetch, "Found a pf candidate addr: %#x, " 102 "inserting into prefetch queue.\n", pf_info.first); 103 104 // Create and insert the request 105 PacketPtr pf_pkt = insert(pf_info, is_secure); 106 107 if (pf_pkt != nullptr) { 108 if (tagPrefetch && pkt->req->hasPC()) { 109 // Tag prefetch packet with accessing pc 110 pf_pkt->req->setPC(pkt->req->getPC()); 111 } 112 } 113 } 114 } 115 116 return pfq.empty() ? MaxTick : pfq.front().tick; 117} 118 119PacketPtr 120QueuedPrefetcher::getPacket() 121{ 122 DPRINTF(HWPrefetch, "Requesting a prefetch to issue.\n"); 123 124 if (pfq.empty()) { 125 DPRINTF(HWPrefetch, "No hardware prefetches available.\n"); 126 return nullptr; 127 } 128 129 PacketPtr pkt = pfq.begin()->pkt; 130 pfq.pop_front(); 131 132 pfIssued++; 133 assert(pkt != nullptr); 134 DPRINTF(HWPrefetch, "Generating prefetch for %#x.\n", pkt->getAddr()); 135 return pkt; 136} 137 138std::list<QueuedPrefetcher::DeferredPacket>::const_iterator 139QueuedPrefetcher::inPrefetch(Addr address, bool is_secure) const 140{ 141 for (const_iterator dp = pfq.begin(); dp != pfq.end(); dp++) { 142 if ((*dp).pkt->getAddr() == address && 143 (*dp).pkt->isSecure() == is_secure) return dp; 144 } 145 146 return pfq.end(); 147} 148 149QueuedPrefetcher::iterator 150QueuedPrefetcher::inPrefetch(Addr address, bool is_secure) 151{ 152 for (iterator dp = pfq.begin(); dp != pfq.end(); dp++) { 153 if (dp->pkt->getAddr() == address && 154 dp->pkt->isSecure() == is_secure) return dp; 155 } 156 157 return pfq.end(); 158} 159 160void 161QueuedPrefetcher::regStats() 162{ 163 BasePrefetcher::regStats(); 164 165 pfIdentified 166 .name(name() + ".pfIdentified") 167 .desc("number of prefetch candidates identified"); 168 169 pfBufferHit 170 .name(name() + ".pfBufferHit") 171 .desc("number of redundant prefetches already in prefetch queue"); 172 173 pfInCache 174 .name(name() + ".pfInCache") 175 .desc("number of redundant prefetches already in cache/mshr dropped"); 176 177 pfRemovedFull 178 .name(name() + ".pfRemovedFull") 179 .desc("number of prefetches dropped due to prefetch queue size"); 180 181 pfSpanPage 182 .name(name() + ".pfSpanPage") 183 .desc("number of prefetches not generated due to page crossing"); 184} 185 186PacketPtr 187QueuedPrefetcher::insert(AddrPriority &pf_info, bool is_secure) 188{ 189 if (queueFilter) { 190 iterator it = inPrefetch(pf_info.first, is_secure); 191 /* If the address is already in the queue, update priority and leave */ 192 if (it != pfq.end()) { 193 pfBufferHit++; 194 if (it->priority < pf_info.second) { 195 /* Update priority value and position in the queue */ 196 it->priority = pf_info.second; 197 iterator prev = it; 198 bool cont = true; 199 while (cont && prev != pfq.begin()) { 200 prev--; 201 /* If the packet has higher priority, swap */ 202 if (*it > *prev) { 203 std::swap(*it, *prev); 204 it = prev; 205 } 206 } 207 DPRINTF(HWPrefetch, "Prefetch addr already in " 208 "prefetch queue, priority updated\n"); 209 } else { 210 DPRINTF(HWPrefetch, "Prefetch addr already in " 211 "prefetch queue\n"); 212 } 213 return nullptr; 214 } 215 } 216 217 if (cacheSnoop && (inCache(pf_info.first, is_secure) || 218 inMissQueue(pf_info.first, is_secure))) { 219 pfInCache++; 220 DPRINTF(HWPrefetch, "Dropping redundant in " 221 "cache/MSHR prefetch addr:%#x\n", pf_info.first); 222 return nullptr; 223 } 224 225 /* Create a prefetch memory request */ 226 RequestPtr pf_req =
| 80 delete itr->pkt; 81 itr = pfq.erase(itr); 82 } else { 83 ++itr; 84 } 85 } 86 } 87 88 // Calculate prefetches given this access 89 std::vector<AddrPriority> addresses; 90 calculatePrefetch(pkt, addresses); 91 92 // Queue up generated prefetches 93 for (AddrPriority& pf_info : addresses) { 94 95 // Block align prefetch address 96 pf_info.first &= ~(Addr)(blkSize - 1); 97 98 pfIdentified++; 99 DPRINTF(HWPrefetch, "Found a pf candidate addr: %#x, " 100 "inserting into prefetch queue.\n", pf_info.first); 101 102 // Create and insert the request 103 PacketPtr pf_pkt = insert(pf_info, is_secure); 104 105 if (pf_pkt != nullptr) { 106 if (tagPrefetch && pkt->req->hasPC()) { 107 // Tag prefetch packet with accessing pc 108 pf_pkt->req->setPC(pkt->req->getPC()); 109 } 110 } 111 } 112 } 113 114 return pfq.empty() ? MaxTick : pfq.front().tick; 115} 116 117PacketPtr 118QueuedPrefetcher::getPacket() 119{ 120 DPRINTF(HWPrefetch, "Requesting a prefetch to issue.\n"); 121 122 if (pfq.empty()) { 123 DPRINTF(HWPrefetch, "No hardware prefetches available.\n"); 124 return nullptr; 125 } 126 127 PacketPtr pkt = pfq.begin()->pkt; 128 pfq.pop_front(); 129 130 pfIssued++; 131 assert(pkt != nullptr); 132 DPRINTF(HWPrefetch, "Generating prefetch for %#x.\n", pkt->getAddr()); 133 return pkt; 134} 135 136std::list<QueuedPrefetcher::DeferredPacket>::const_iterator 137QueuedPrefetcher::inPrefetch(Addr address, bool is_secure) const 138{ 139 for (const_iterator dp = pfq.begin(); dp != pfq.end(); dp++) { 140 if ((*dp).pkt->getAddr() == address && 141 (*dp).pkt->isSecure() == is_secure) return dp; 142 } 143 144 return pfq.end(); 145} 146 147QueuedPrefetcher::iterator 148QueuedPrefetcher::inPrefetch(Addr address, bool is_secure) 149{ 150 for (iterator dp = pfq.begin(); dp != pfq.end(); dp++) { 151 if (dp->pkt->getAddr() == address && 152 dp->pkt->isSecure() == is_secure) return dp; 153 } 154 155 return pfq.end(); 156} 157 158void 159QueuedPrefetcher::regStats() 160{ 161 BasePrefetcher::regStats(); 162 163 pfIdentified 164 .name(name() + ".pfIdentified") 165 .desc("number of prefetch candidates identified"); 166 167 pfBufferHit 168 .name(name() + ".pfBufferHit") 169 .desc("number of redundant prefetches already in prefetch queue"); 170 171 pfInCache 172 .name(name() + ".pfInCache") 173 .desc("number of redundant prefetches already in cache/mshr dropped"); 174 175 pfRemovedFull 176 .name(name() + ".pfRemovedFull") 177 .desc("number of prefetches dropped due to prefetch queue size"); 178 179 pfSpanPage 180 .name(name() + ".pfSpanPage") 181 .desc("number of prefetches not generated due to page crossing"); 182} 183 184PacketPtr 185QueuedPrefetcher::insert(AddrPriority &pf_info, bool is_secure) 186{ 187 if (queueFilter) { 188 iterator it = inPrefetch(pf_info.first, is_secure); 189 /* If the address is already in the queue, update priority and leave */ 190 if (it != pfq.end()) { 191 pfBufferHit++; 192 if (it->priority < pf_info.second) { 193 /* Update priority value and position in the queue */ 194 it->priority = pf_info.second; 195 iterator prev = it; 196 bool cont = true; 197 while (cont && prev != pfq.begin()) { 198 prev--; 199 /* If the packet has higher priority, swap */ 200 if (*it > *prev) { 201 std::swap(*it, *prev); 202 it = prev; 203 } 204 } 205 DPRINTF(HWPrefetch, "Prefetch addr already in " 206 "prefetch queue, priority updated\n"); 207 } else { 208 DPRINTF(HWPrefetch, "Prefetch addr already in " 209 "prefetch queue\n"); 210 } 211 return nullptr; 212 } 213 } 214 215 if (cacheSnoop && (inCache(pf_info.first, is_secure) || 216 inMissQueue(pf_info.first, is_secure))) { 217 pfInCache++; 218 DPRINTF(HWPrefetch, "Dropping redundant in " 219 "cache/MSHR prefetch addr:%#x\n", pf_info.first); 220 return nullptr; 221 } 222 223 /* Create a prefetch memory request */ 224 RequestPtr pf_req =
|
227 new Request(pf_info.first, blkSize, 0, masterId);
| 225 std::make_shared<Request>(pf_info.first, blkSize, 0, masterId);
|
228 229 if (is_secure) { 230 pf_req->setFlags(Request::SECURE); 231 } 232 pf_req->taskId(ContextSwitchTaskId::Prefetcher); 233 PacketPtr pf_pkt = new Packet(pf_req, MemCmd::HardPFReq); 234 pf_pkt->allocate(); 235 236 /* Verify prefetch buffer space for request */ 237 if (pfq.size() == queueSize) { 238 pfRemovedFull++; 239 /* Lowest priority packet */ 240 iterator it = pfq.end(); 241 panic_if (it == pfq.begin(), "Prefetch queue is both full and empty!"); 242 --it; 243 /* Look for oldest in that level of priority */ 244 panic_if (it == pfq.begin(), "Prefetch queue is full with 1 element!"); 245 iterator prev = it; 246 bool cont = true; 247 /* While not at the head of the queue */ 248 while (cont && prev != pfq.begin()) { 249 prev--; 250 /* While at the same level of priority */ 251 cont = (*prev).priority == (*it).priority; 252 if (cont) 253 /* update pointer */ 254 it = prev; 255 } 256 DPRINTF(HWPrefetch, "Prefetch queue full, removing lowest priority " 257 "oldest packet, addr: %#x", it->pkt->getAddr());
| 226 227 if (is_secure) { 228 pf_req->setFlags(Request::SECURE); 229 } 230 pf_req->taskId(ContextSwitchTaskId::Prefetcher); 231 PacketPtr pf_pkt = new Packet(pf_req, MemCmd::HardPFReq); 232 pf_pkt->allocate(); 233 234 /* Verify prefetch buffer space for request */ 235 if (pfq.size() == queueSize) { 236 pfRemovedFull++; 237 /* Lowest priority packet */ 238 iterator it = pfq.end(); 239 panic_if (it == pfq.begin(), "Prefetch queue is both full and empty!"); 240 --it; 241 /* Look for oldest in that level of priority */ 242 panic_if (it == pfq.begin(), "Prefetch queue is full with 1 element!"); 243 iterator prev = it; 244 bool cont = true; 245 /* While not at the head of the queue */ 246 while (cont && prev != pfq.begin()) { 247 prev--; 248 /* While at the same level of priority */ 249 cont = (*prev).priority == (*it).priority; 250 if (cont) 251 /* update pointer */ 252 it = prev; 253 } 254 DPRINTF(HWPrefetch, "Prefetch queue full, removing lowest priority " 255 "oldest packet, addr: %#x", it->pkt->getAddr());
|
258 delete it->pkt->req;
| |
259 delete it->pkt; 260 pfq.erase(it); 261 } 262 263 Tick pf_time = curTick() + clockPeriod() * latency; 264 DPRINTF(HWPrefetch, "Prefetch queued. " 265 "addr:%#x priority: %3d tick:%lld.\n", 266 pf_info.first, pf_info.second, pf_time); 267 268 /* Create the packet and find the spot to insert it */ 269 DeferredPacket dpp(pf_time, pf_pkt, pf_info.second); 270 if (pfq.size() == 0) { 271 pfq.emplace_back(dpp); 272 } else { 273 iterator it = pfq.end(); 274 while (it != pfq.begin() && dpp > *it) 275 --it; 276 /* If we reach the head, we have to see if the new element is new head 277 * or not */ 278 if (it == pfq.begin() && dpp <= *it) 279 it++; 280 pfq.insert(it, dpp); 281 } 282 283 return pf_pkt; 284}
| 256 delete it->pkt; 257 pfq.erase(it); 258 } 259 260 Tick pf_time = curTick() + clockPeriod() * latency; 261 DPRINTF(HWPrefetch, "Prefetch queued. " 262 "addr:%#x priority: %3d tick:%lld.\n", 263 pf_info.first, pf_info.second, pf_time); 264 265 /* Create the packet and find the spot to insert it */ 266 DeferredPacket dpp(pf_time, pf_pkt, pf_info.second); 267 if (pfq.size() == 0) { 268 pfq.emplace_back(dpp); 269 } else { 270 iterator it = pfq.end(); 271 while (it != pfq.begin() && dpp > *it) 272 --it; 273 /* If we reach the head, we have to see if the new element is new head 274 * or not */ 275 if (it == pfq.begin() && dpp <= *it) 276 it++; 277 pfq.insert(it, dpp); 278 } 279 280 return pf_pkt; 281}
|