stride.cc (13424:1744211c9a65) stride.cc (13425:00abf35b2f7e)
1/*
2 * Copyright (c) 2012-2013, 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

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

61 : QueuedPrefetcher(p),
62 maxConf(p->max_conf),
63 threshConf(p->thresh_conf),
64 minConf(p->min_conf),
65 startConf(p->start_conf),
66 pcTableAssoc(p->table_assoc),
67 pcTableSets(p->table_sets),
68 useMasterId(p->use_master_id),
1/*
2 * Copyright (c) 2012-2013, 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

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

61 : QueuedPrefetcher(p),
62 maxConf(p->max_conf),
63 threshConf(p->thresh_conf),
64 minConf(p->min_conf),
65 startConf(p->start_conf),
66 pcTableAssoc(p->table_assoc),
67 pcTableSets(p->table_sets),
68 useMasterId(p->use_master_id),
69 degree(p->degree),
70 pcTable(pcTableAssoc, pcTableSets, name())
69 degree(p->degree)
71{
72 assert(isPowerOf2(pcTableSets));
73}
74
70{
71 assert(isPowerOf2(pcTableSets));
72}
73
75std::vector<std::vector<StridePrefetcher::StrideEntry>>&
76StridePrefetcher::PCTable::allocateNewContext(int context)
74StridePrefetcher::PCTable*
75StridePrefetcher::findTable(int context)
77{
76{
78 auto res = entries.insert(std::make_pair(context,
79 std::vector<std::vector<StrideEntry>>(pcTableSets)));
80 auto it = res.first;
81 chatty_assert(res.second, "Allocating an already created context\n");
82 assert(it->first == context);
77 // Check if table for given context exists
78 auto it = pcTables.find(context);
79 if (it != pcTables.end())
80 return &it->second;
83
81
82 // If table does not exist yet, create one
83 return allocateNewContext(context);
84}
85
86StridePrefetcher::PCTable*
87StridePrefetcher::allocateNewContext(int context)
88{
89 // Create new table
90 auto insertion_result = pcTables.insert(std::make_pair(context,
91 PCTable(pcTableAssoc, pcTableSets, name())));
92
84 DPRINTF(HWPrefetch, "Adding context %i with stride entries\n", context);
85
93 DPRINTF(HWPrefetch, "Adding context %i with stride entries\n", context);
94
86 std::vector<std::vector<StrideEntry>>& table = it->second;
87 for (auto& set : table) {
95 // Get iterator to new pc table, and then return a pointer to the new table
96 return &(insertion_result.first->second);
97}
98
99StridePrefetcher::PCTable::PCTable(int assoc, int sets, const std::string name)
100 : pcTableAssoc(assoc), pcTableSets(sets), _name(name), entries(pcTableSets)
101{
102 for (auto& set : entries) {
88 set.resize(pcTableAssoc);
89 }
103 set.resize(pcTableAssoc);
104 }
90 return table;
91}
92
93StridePrefetcher::PCTable::~PCTable()
94{
95}
96
97void
98StridePrefetcher::calculatePrefetch(const PacketPtr &pkt,

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

104 }
105
106 // Get required packet info
107 Addr pkt_addr = pkt->getAddr();
108 Addr pc = pkt->req->getPC();
109 bool is_secure = pkt->isSecure();
110 MasterID master_id = useMasterId ? pkt->req->masterId() : 0;
111
105}
106
107StridePrefetcher::PCTable::~PCTable()
108{
109}
110
111void
112StridePrefetcher::calculatePrefetch(const PacketPtr &pkt,

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

118 }
119
120 // Get required packet info
121 Addr pkt_addr = pkt->getAddr();
122 Addr pc = pkt->req->getPC();
123 bool is_secure = pkt->isSecure();
124 MasterID master_id = useMasterId ? pkt->req->masterId() : 0;
125
126 // Get corresponding pc table
127 PCTable* pcTable = findTable(master_id);
128
112 // Search for entry in the pc table
129 // Search for entry in the pc table
113 StrideEntry *entry = findEntry(pc, is_secure, master_id);
130 StrideEntry *entry = pcTable->findEntry(pc, is_secure);
114
115 if (entry != nullptr) {
116 // Hit in table
117 int new_stride = pkt_addr - entry->lastAddr;
118 bool stride_match = (new_stride == entry->stride);
119
120 // Adjust confidence for stride entry
121 if (stride_match && new_stride != 0) {

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

159 return;
160 }
161 }
162 } else {
163 // Miss in table
164 DPRINTF(HWPrefetch, "Miss: PC %x pkt_addr %x (%s)\n", pc, pkt_addr,
165 is_secure ? "s" : "ns");
166
131
132 if (entry != nullptr) {
133 // Hit in table
134 int new_stride = pkt_addr - entry->lastAddr;
135 bool stride_match = (new_stride == entry->stride);
136
137 // Adjust confidence for stride entry
138 if (stride_match && new_stride != 0) {

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

176 return;
177 }
178 }
179 } else {
180 // Miss in table
181 DPRINTF(HWPrefetch, "Miss: PC %x pkt_addr %x (%s)\n", pc, pkt_addr,
182 is_secure ? "s" : "ns");
183
167 StrideEntry* entry = pcTableVictim(pc, master_id);
184 StrideEntry* entry = pcTable->findVictim(pc);
168 entry->instAddr = pc;
169 entry->lastAddr = pkt_addr;
170 entry->isSecure= is_secure;
171 entry->stride = 0;
172 entry->confidence = startConf;
173 }
174}
175
176inline Addr
185 entry->instAddr = pc;
186 entry->lastAddr = pkt_addr;
187 entry->isSecure= is_secure;
188 entry->stride = 0;
189 entry->confidence = startConf;
190 }
191}
192
193inline Addr
177StridePrefetcher::pcHash(Addr pc) const
194StridePrefetcher::PCTable::pcHash(Addr pc) const
178{
179 Addr hash1 = pc >> 1;
180 Addr hash2 = hash1 >> floorLog2(pcTableSets);
181 return (hash1 ^ hash2) & (Addr)(pcTableSets - 1);
182}
183
184inline StridePrefetcher::StrideEntry*
195{
196 Addr hash1 = pc >> 1;
197 Addr hash2 = hash1 >> floorLog2(pcTableSets);
198 return (hash1 ^ hash2) & (Addr)(pcTableSets - 1);
199}
200
201inline StridePrefetcher::StrideEntry*
185StridePrefetcher::pcTableVictim(Addr pc, int master_id)
202StridePrefetcher::PCTable::findVictim(Addr pc)
186{
187 // Rand replacement for now
188 int set = pcHash(pc);
189 int way = random_mt.random<int>(0, pcTableAssoc - 1);
190
191 DPRINTF(HWPrefetch, "Victimizing lookup table[%d][%d].\n", set, way);
203{
204 // Rand replacement for now
205 int set = pcHash(pc);
206 int way = random_mt.random<int>(0, pcTableAssoc - 1);
207
208 DPRINTF(HWPrefetch, "Victimizing lookup table[%d][%d].\n", set, way);
192 return &pcTable[master_id][set][way];
209 return &entries[set][way];
193}
194
195inline StridePrefetcher::StrideEntry*
210}
211
212inline StridePrefetcher::StrideEntry*
196StridePrefetcher::findEntry(Addr pc, bool is_secure, int master_id)
213StridePrefetcher::PCTable::findEntry(Addr pc, bool is_secure)
197{
198 int set = pcHash(pc);
214{
215 int set = pcHash(pc);
199 std::vector<StrideEntry>& set_entries = pcTable[master_id][set];
216 std::vector<StrideEntry>& set_entries = entries[set];
200 for (int way = 0; way < pcTableAssoc; way++) {
201 StrideEntry* entry = &set_entries[way];
202 // Search ways for match
203 if ((entry->instAddr == pc) && (entry->isSecure == is_secure)) {
204 DPRINTF(HWPrefetch, "Lookup hit table[%d][%d].\n", set, way);
205 return entry;
206 }
207 }
208 return nullptr;
209}
210
211StridePrefetcher*
212StridePrefetcherParams::create()
213{
214 return new StridePrefetcher(this);
215}
217 for (int way = 0; way < pcTableAssoc; way++) {
218 StrideEntry* entry = &set_entries[way];
219 // Search ways for match
220 if ((entry->instAddr == pc) && (entry->isSecure == is_secure)) {
221 DPRINTF(HWPrefetch, "Lookup hit table[%d][%d].\n", set, way);
222 return entry;
223 }
224 }
225 return nullptr;
226}
227
228StridePrefetcher*
229StridePrefetcherParams::create()
230{
231 return new StridePrefetcher(this);
232}