gem5 v24.0.0.0
Loading...
Searching...
No Matches
stride.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2018 Inria
3 * Copyright (c) 2012-2013, 2015, 2022-2023 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
9 * to a hardware implementation of the functionality of the software
10 * licensed hereunder. You may use the software subject to the license
11 * terms below provided that you ensure that this notice is replicated
12 * unmodified and in its entirety in all distributions of the software,
13 * modified or unmodified, in source code or in binary form.
14 *
15 * Copyright (c) 2005 The Regents of The University of Michigan
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 */
41
48
49#include <cassert>
50
51#include "base/intmath.hh"
52#include "base/logging.hh"
53#include "base/random.hh"
54#include "base/trace.hh"
55#include "debug/HWPrefetch.hh"
58#include "params/StridePrefetcher.hh"
59
60namespace gem5
61{
62
63namespace prefetch
64{
65
67 : TaggedEntry(), confidence(init_confidence)
68{
69 invalidate();
70}
71
72void
74{
76 lastAddr = 0;
77 stride = 0;
78 confidence.reset();
79}
80
81Stride::Stride(const StridePrefetcherParams &p)
82 : Queued(p),
83 initConfidence(p.confidence_counter_bits, p.initial_confidence),
84 threshConf(p.confidence_threshold/100.0),
85 useRequestorId(p.use_requestor_id),
88 pcTableInfo(p.table_assoc, p.table_entries, p.table_indexing_policy,
89 p.table_replacement_policy)
90{
91}
92
95{
96 // Check if table for given context exists
97 auto it = pcTables.find(context);
98 if (it != pcTables.end())
99 return &it->second;
100
101 // If table does not exist yet, create one
102 return allocateNewContext(context);
103}
104
107{
108 std::string table_name = name() + ".PCTable" + std::to_string(context);
109 // Create new table
110 auto ins_result = pcTables.emplace(std::piecewise_construct,
111 std::forward_as_tuple(context),
112 std::forward_as_tuple(table_name.c_str(),
118
119 DPRINTF(HWPrefetch, "Adding context %i with stride entries\n", context);
120
121 // Get iterator to new pc table, and then return a pointer to the new table
122 return &(ins_result.first->second);
123}
124
125void
127 std::vector<AddrPriority> &addresses,
128 const CacheAccessor &cache)
129{
130 if (!pfi.hasPC()) {
131 DPRINTF(HWPrefetch, "Ignoring request with no PC.\n");
132 return;
133 }
134
135 // Get required packet info
136 Addr pf_addr = pfi.getAddr();
137 Addr pc = pfi.getPC();
138 bool is_secure = pfi.isSecure();
139 RequestorID requestor_id = useRequestorId ? pfi.getRequestorId() : 0;
140
141 // Get corresponding pc table
142 PCTable* pcTable = findTable(requestor_id);
143
144 // Search for entry in the pc table
145 StrideEntry *entry = pcTable->findEntry(pc, is_secure);
146
147 if (entry != nullptr) {
148 pcTable->accessEntry(entry);
149
150 // Hit in table
151 int new_stride = pf_addr - entry->lastAddr;
152 bool stride_match = (new_stride == entry->stride);
153
154 // Adjust confidence for stride entry
155 if (stride_match && new_stride != 0) {
156 entry->confidence++;
157 } else {
158 entry->confidence--;
159 // If confidence has dropped below the threshold, train new stride
160 if (entry->confidence.calcSaturation() < threshConf) {
161 entry->stride = new_stride;
162 }
163 }
164
165 DPRINTF(HWPrefetch, "Hit: PC %x pkt_addr %x (%s) stride %d (%s), "
166 "conf %d\n", pc, pf_addr, is_secure ? "s" : "ns",
167 new_stride, stride_match ? "match" : "change",
168 (int)entry->confidence);
169
170 entry->lastAddr = pf_addr;
171
172 // Abort prefetch generation if below confidence threshold
173 if (entry->confidence.calcSaturation() < threshConf) {
174 return;
175 }
176
177 // Round strides up to atleast 1 cacheline
178 int prefetch_stride = new_stride;
179 if (abs(new_stride) < blkSize) {
180 prefetch_stride = (new_stride < 0) ? -blkSize : blkSize;
181 }
182
183 Addr new_addr = pf_addr + distance * prefetch_stride;
184 // Generate up to degree prefetches
185 for (int d = 1; d <= degree; d++) {
186 new_addr += prefetch_stride;
187 addresses.push_back(AddrPriority(new_addr, 0));
188 }
189 } else {
190 // Miss in table
191 DPRINTF(HWPrefetch, "Miss: PC %x pkt_addr %x (%s)\n", pc, pf_addr,
192 is_secure ? "s" : "ns");
193
194 StrideEntry* entry = pcTable->findVictim(pc);
195
196 // Insert new entry's data
197 entry->lastAddr = pf_addr;
198 pcTable->insertEntry(pc, is_secure, entry);
199 }
200}
201
202uint32_t
204{
205 const Addr hash1 = pc >> 1;
206 const Addr hash2 = hash1 >> tagShift;
207 return (hash1 ^ hash2) & setMask;
208}
209
210Addr
215
216} // namespace prefetch
217} // namespace gem5
#define DPRINTF(x,...)
Definition trace.hh:210
virtual Entry * findVictim(const Addr addr)
Find a victim to be replaced.
virtual void accessEntry(Entry *entry)
Update the replacement information for an entry.
Associative container based on the previosuly defined Entry type Each element is indexed by a key of ...
void insertEntry(Addr addr, bool is_secure, Entry *entry)
Indicate that an entry has just been inserted.
Entry * findEntry(Addr addr, bool is_secure) const
Find an entry within the set.
const unsigned setMask
Mask out all bits that aren't part of the set index.
Definition base.hh:87
const int tagShift
The amount to shift the address to get the tag.
Definition base.hh:97
virtual std::string name() const
Definition named.hh:47
A tagged entry is an entry containing a tag.
void invalidate() override
Invalidate the block.
Class containing the information needed by the prefetch to train and generate new prefetch requests.
Definition base.hh:111
Addr getPC() const
Returns the program counter that generated this request.
Definition base.hh:156
bool isSecure() const
Returns true if the address targets the secure memory space.
Definition base.hh:147
Addr getAddr() const
Obtains the address value of this Prefetcher address.
Definition base.hh:138
bool hasPC() const
Returns true if the associated program counter is valid.
Definition base.hh:166
RequestorID getRequestorId() const
Gets the requestor ID that generated this address.
Definition base.hh:175
unsigned blkSize
The block size of the parent cache.
Definition base.hh:286
std::pair< Addr, int32_t > AddrPriority
Definition queued.hh:192
Addr extractTag(const Addr addr) const override
Generate the tag from the given address.
Definition stride.cc:211
uint32_t extractSet(const Addr addr) const override
Apply a hash function to calculate address set.
Definition stride.cc:203
const SatCounter8 initConfidence
Initial confidence counter value for the pc tables.
Definition stride.hh:99
const double threshConf
Confidence threshold for prefetch generation.
Definition stride.hh:102
PCTable * allocateNewContext(int context)
Create a PC table for the given context.
Definition stride.cc:106
void calculatePrefetch(const PrefetchInfo &pfi, std::vector< AddrPriority > &addresses, const CacheAccessor &cache) override
Definition stride.cc:126
const int distance
How far ahead of the demand stream to start prefetching.
Definition stride.hh:114
Stride(const StridePrefetcherParams &p)
Definition stride.cc:81
std::unordered_map< int, PCTable > pcTables
Definition stride.hh:148
const bool useRequestorId
Definition stride.hh:104
const struct gem5::prefetch::Stride::PCTableInfo pcTableInfo
PCTable * findTable(int context)
Try to find a table of entries for the given context.
Definition stride.cc:94
STL vector class.
Definition stl.hh:37
double calcSaturation() const
Calculate saturation percentile of the current counter's value with regard to its maximum possible va...
Bitfield< 21, 20 > stride
Bitfield< 9 > d
Definition misc_types.hh:64
Bitfield< 4 > pc
Bitfield< 0 > p
Bitfield< 3 > addr
Definition types.hh:84
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
uint16_t RequestorID
Definition request.hh:95
Describes a strided prefetcher.
Provides generic cache lookup functions.
replacement_policy::Base *const replacementPolicy
Definition stride.hh:125
BaseIndexingPolicy *const indexingPolicy
Definition stride.hh:124
Tagged by hashed PCs.
Definition stride.hh:138
StrideEntry(const SatCounter8 &init_confidence)
Definition stride.cc:66
void invalidate() override
Invalidate the block.
Definition stride.cc:73

Generated on Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0