stride.cc (13427:72a3afac3e78) stride.cc (13551:f352df8e2863)
1/*
2 * Copyright (c) 2018 Inria
3 * Copyright (c) 2012-2013, 2015 ARM Limited
4 * All rights reserved
5 *
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating

--- 124 unchanged lines hidden (view full) ---

133 }
134}
135
136StridePrefetcher::PCTable::~PCTable()
137{
138}
139
140void
1/*
2 * Copyright (c) 2018 Inria
3 * Copyright (c) 2012-2013, 2015 ARM Limited
4 * All rights reserved
5 *
6 * The license below extends only to copyright in the software and shall
7 * not be construed as granting a license to any other intellectual
8 * property including but not limited to intellectual property relating

--- 124 unchanged lines hidden (view full) ---

133 }
134}
135
136StridePrefetcher::PCTable::~PCTable()
137{
138}
139
140void
141StridePrefetcher::calculatePrefetch(const PacketPtr &pkt,
141StridePrefetcher::calculatePrefetch(const PrefetchInfo &pfi,
142 std::vector<AddrPriority> &addresses)
143{
142 std::vector<AddrPriority> &addresses)
143{
144 if (!pkt->req->hasPC()) {
144 if (!pfi.hasPC()) {
145 DPRINTF(HWPrefetch, "Ignoring request with no PC.\n");
146 return;
147 }
148
149 // Get required packet info
145 DPRINTF(HWPrefetch, "Ignoring request with no PC.\n");
146 return;
147 }
148
149 // Get required packet info
150 Addr pkt_addr = pkt->getAddr();
151 Addr pc = pkt->req->getPC();
152 bool is_secure = pkt->isSecure();
153 MasterID master_id = useMasterId ? pkt->req->masterId() : 0;
150 Addr pf_addr = pfi.getAddr();
151 Addr pc = pfi.getPC();
152 bool is_secure = pfi.isSecure();
153 MasterID master_id = useMasterId ? pfi.getMasterId() : 0;
154
155 // Get corresponding pc table
156 PCTable* pcTable = findTable(master_id);
157
158 // Search for entry in the pc table
159 StrideEntry *entry = pcTable->findEntry(pc, is_secure);
160
161 if (entry != nullptr) {
162 // Hit in table
154
155 // Get corresponding pc table
156 PCTable* pcTable = findTable(master_id);
157
158 // Search for entry in the pc table
159 StrideEntry *entry = pcTable->findEntry(pc, is_secure);
160
161 if (entry != nullptr) {
162 // Hit in table
163 int new_stride = pkt_addr - entry->lastAddr;
163 int new_stride = pf_addr - entry->lastAddr;
164 bool stride_match = (new_stride == entry->stride);
165
166 // Adjust confidence for stride entry
167 if (stride_match && new_stride != 0) {
168 if (entry->confidence < maxConf)
169 entry->confidence++;
170 } else {
171 if (entry->confidence > minConf)
172 entry->confidence--;
173 // If confidence has dropped below the threshold, train new stride
174 if (entry->confidence < threshConf)
175 entry->stride = new_stride;
176 }
177
178 DPRINTF(HWPrefetch, "Hit: PC %x pkt_addr %x (%s) stride %d (%s), "
164 bool stride_match = (new_stride == entry->stride);
165
166 // Adjust confidence for stride entry
167 if (stride_match && new_stride != 0) {
168 if (entry->confidence < maxConf)
169 entry->confidence++;
170 } else {
171 if (entry->confidence > minConf)
172 entry->confidence--;
173 // If confidence has dropped below the threshold, train new stride
174 if (entry->confidence < threshConf)
175 entry->stride = new_stride;
176 }
177
178 DPRINTF(HWPrefetch, "Hit: PC %x pkt_addr %x (%s) stride %d (%s), "
179 "conf %d\n", pc, pkt_addr, is_secure ? "s" : "ns", new_stride,
180 stride_match ? "match" : "change",
179 "conf %d\n", pc, pf_addr, is_secure ? "s" : "ns",
180 new_stride, stride_match ? "match" : "change",
181 entry->confidence);
182
181 entry->confidence);
182
183 entry->lastAddr = pkt_addr;
183 entry->lastAddr = pf_addr;
184
185 // Abort prefetch generation if below confidence threshold
186 if (entry->confidence < threshConf)
187 return;
188
189 // Generate up to degree prefetches
190 for (int d = 1; d <= degree; d++) {
191 // Round strides up to atleast 1 cacheline
192 int prefetch_stride = new_stride;
193 if (abs(new_stride) < blkSize) {
194 prefetch_stride = (new_stride < 0) ? -blkSize : blkSize;
195 }
196
184
185 // Abort prefetch generation if below confidence threshold
186 if (entry->confidence < threshConf)
187 return;
188
189 // Generate up to degree prefetches
190 for (int d = 1; d <= degree; d++) {
191 // Round strides up to atleast 1 cacheline
192 int prefetch_stride = new_stride;
193 if (abs(new_stride) < blkSize) {
194 prefetch_stride = (new_stride < 0) ? -blkSize : blkSize;
195 }
196
197 Addr new_addr = pkt_addr + d * prefetch_stride;
198 if (samePage(pkt_addr, new_addr)) {
197 Addr new_addr = pf_addr + d * prefetch_stride;
198 if (samePage(pf_addr, new_addr)) {
199 DPRINTF(HWPrefetch, "Queuing prefetch to %#x.\n", new_addr);
200 addresses.push_back(AddrPriority(new_addr, 0));
201 } else {
202 // Record the number of page crossing prefetches generated
203 pfSpanPage += degree - d + 1;
204 DPRINTF(HWPrefetch, "Ignoring page crossing prefetch.\n");
205 return;
206 }
207 }
208 } else {
209 // Miss in table
199 DPRINTF(HWPrefetch, "Queuing prefetch to %#x.\n", new_addr);
200 addresses.push_back(AddrPriority(new_addr, 0));
201 } else {
202 // Record the number of page crossing prefetches generated
203 pfSpanPage += degree - d + 1;
204 DPRINTF(HWPrefetch, "Ignoring page crossing prefetch.\n");
205 return;
206 }
207 }
208 } else {
209 // Miss in table
210 DPRINTF(HWPrefetch, "Miss: PC %x pkt_addr %x (%s)\n", pc, pkt_addr,
210 DPRINTF(HWPrefetch, "Miss: PC %x pkt_addr %x (%s)\n", pc, pf_addr,
211 is_secure ? "s" : "ns");
212
213 StrideEntry* entry = pcTable->findVictim(pc);
214
215 // Invalidate victim
216 entry->invalidate();
217 replacementPolicy->invalidate(entry->replacementData);
218
219 // Insert new entry's data
220 entry->instAddr = pc;
211 is_secure ? "s" : "ns");
212
213 StrideEntry* entry = pcTable->findVictim(pc);
214
215 // Invalidate victim
216 entry->invalidate();
217 replacementPolicy->invalidate(entry->replacementData);
218
219 // Insert new entry's data
220 entry->instAddr = pc;
221 entry->lastAddr = pkt_addr;
221 entry->lastAddr = pf_addr;
222 entry->isSecure = is_secure;
223 entry->confidence = startConf;
224 replacementPolicy->reset(entry->replacementData);
225 }
226}
227
228inline Addr
229StridePrefetcher::PCTable::pcHash(Addr pc) const

--- 49 unchanged lines hidden ---
222 entry->isSecure = is_secure;
223 entry->confidence = startConf;
224 replacementPolicy->reset(entry->replacementData);
225 }
226}
227
228inline Addr
229StridePrefetcher::PCTable::pcHash(Addr pc) const

--- 49 unchanged lines hidden ---