gem5 v24.1.0.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
AddressProfiler.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
30
31#include <vector>
32
33#include "base/bitfield.hh"
34#include "base/stl_helpers.hh"
36#include "mem/ruby/protocol/RubyRequest.hh"
38
39namespace gem5
40{
41
42namespace ruby
43{
44
46
47using gem5::stl_helpers::operator<<;
48
49// Helper functions
52{
53 // we create a static default object here that is used to insert
54 // since the insertion will create a copy of the object in the
55 // process. Perhaps this is optimizing early, but it doesn't seem
56 // like it could hurt.
57 static const AccessTraceForAddress dflt;
58
60 record_map.insert(std::make_pair(addr, dflt));
61 AddressMap::iterator i = r.first;
62 AccessTraceForAddress &access_trace = i->second;
63 if (r.second) {
64 // there was nothing there and the insert succeed, so we need
65 // to actually set the address.
66 access_trace.setAddress(addr);
67 }
68
69 return access_trace;
70}
71
72void
73printSorted(std::ostream& out, int num_of_sequencers,
74 const AddressMap &record_map, std::string description,
75 Profiler *profiler)
76{
77 const int records_printed = 100;
78
79 uint64_t misses = 0;
81
82 AddressMap::const_iterator i = record_map.begin();
83 AddressMap::const_iterator end = record_map.end();
84 for (; i != end; ++i) {
85 const AccessTraceForAddress* record = &i->second;
86 misses += record->getTotal();
87 sorted.push_back(record);
88 }
89 sort(sorted.begin(), sorted.end(), AccessTraceForAddress::less_equal);
90
91 out << "Total_entries_" << description << ": " << record_map.size()
92 << std::endl;
93 if (profiler->getAllInstructions()) {
94 out << "Total_Instructions_" << description << ": " << misses
95 << std::endl;
96 } else {
97 out << "Total_data_misses_" << description << ": " << misses
98 << std::endl;
99 }
100
101 out << "total | load store atomic | user supervisor | sharing | touched-by"
102 << std::endl;
103
104 Histogram remaining_records(1, 100);
105 Histogram all_records(1, 100);
106 Histogram remaining_records_log(-1);
107 Histogram all_records_log(-1);
108
109 // Allows us to track how many lines where touched by n processors
110 std::vector<int64_t> m_touched_vec;
111 std::vector<int64_t> m_touched_weighted_vec;
112 m_touched_vec.resize(num_of_sequencers+1);
113 m_touched_weighted_vec.resize(num_of_sequencers+1);
114 for (int j = 0; j < m_touched_vec.size(); j++) {
115 m_touched_vec[j] = 0;
116 m_touched_weighted_vec[j] = 0;
117 }
118
119 int counter = 0;
120 int max = sorted.size();
121 while (counter < max && counter < records_printed) {
122 const AccessTraceForAddress* record = sorted[counter];
123 double percent = 100.0 * (record->getTotal() / double(misses));
124 out << description << " | " << percent << " % " << *record
125 << std::endl;
126 all_records.add(record->getTotal());
127 all_records_log.add(record->getTotal());
128 counter++;
129 m_touched_vec[record->getTouchedBy()]++;
130 m_touched_weighted_vec[record->getTouchedBy()] += record->getTotal();
131 }
132
133 while (counter < max) {
134 const AccessTraceForAddress* record = sorted[counter];
135 all_records.add(record->getTotal());
136 remaining_records.add(record->getTotal());
137 all_records_log.add(record->getTotal());
138 remaining_records_log.add(record->getTotal());
139 m_touched_vec[record->getTouchedBy()]++;
140 m_touched_weighted_vec[record->getTouchedBy()] += record->getTotal();
141 }
142 out << std::endl;
143 out << "all_records_" << description << ": "
144 << all_records << std::endl
145 << "all_records_log_" << description << ": "
146 << all_records_log << std::endl
147 << "remaining_records_" << description << ": "
148 << remaining_records << std::endl
149 << "remaining_records_log_" << description << ": "
150 << remaining_records_log << std::endl
151 << "touched_by_" << description << ": "
152 << m_touched_vec << std::endl
153 << "touched_by_weighted_" << description << ": "
154 << m_touched_weighted_vec << std::endl
155 << std::endl;
156}
157
158AddressProfiler::AddressProfiler(int num_of_sequencers, Profiler *profiler)
159 : m_profiler(profiler)
160{
161 m_num_of_sequencers = num_of_sequencers;
162 clearStats();
163}
164
168
169void
171{
172 m_hot_lines = hot_lines;
173}
174
175void
177{
178 m_all_instructions = all_instructions;
179}
180
181void
182AddressProfiler::printStats(std::ostream& out) const
183{
184 if (m_hot_lines) {
185 out << std::endl;
186 out << "AddressProfiler Stats" << std::endl;
187 out << "---------------------" << std::endl;
188
189 out << std::endl;
190 out << "sharing_misses: " << m_sharing_miss_counter << std::endl;
191 out << "getx_sharing_histogram: " << m_getx_sharing_histogram
192 << std::endl;
193 out << "gets_sharing_histogram: " << m_gets_sharing_histogram
194 << std::endl;
195
196 out << std::endl;
197 out << "Hot Data Blocks" << std::endl;
198 out << "---------------" << std::endl;
199 out << std::endl;
201 "block_address", m_profiler);
202
203 out << std::endl;
204 out << "Hot MacroData Blocks" << std::endl;
205 out << "--------------------" << std::endl;
206 out << std::endl;
208 "macroblock_address", m_profiler);
209
210 out << "Hot Instructions" << std::endl;
211 out << "----------------" << std::endl;
212 out << std::endl;
214 "pc_address", m_profiler);
215 }
216
217 if (m_all_instructions) {
218 out << std::endl;
219 out << "All Instructions Profile:" << std::endl;
220 out << "-------------------------" << std::endl;
221 out << std::endl;
223 "pc_address", m_profiler);
224 out << std::endl;
225 }
226
227 if (m_retryProfileHisto.size() > 0) {
228 out << "Retry Profile" << std::endl;
229 out << "-------------" << std::endl;
230 out << std::endl;
231 out << "retry_histogram_absolute: " << m_retryProfileHisto
232 << std::endl;
233 out << "retry_histogram_write: " << m_retryProfileHistoWrite
234 << std::endl;
235 out << "retry_histogram_read: " << m_retryProfileHistoRead
236 << std::endl;
237
238 out << "retry_histogram_percent: ";
240 out << std::endl;
241
243 "block_address", m_profiler);
244 out << std::endl;
245 }
246}
247
248void
263
264void
266 const Set& owner, const Set& sharers,
267 NodeID requestor)
268{
269 Set indirection_set;
270 indirection_set.addSet(sharers);
271 indirection_set.addSet(owner);
272 indirection_set.remove(requestor);
273 int num_indirections = indirection_set.count();
274
275 m_getx_sharing_histogram.add(num_indirections);
276 bool indirection_miss = (num_indirections > 0);
277
278 addTraceSample(datablock, PC, RubyRequestType_ST, RubyAccessMode(0),
279 requestor, indirection_miss);
280}
281
282void
284 const Set& owner, const Set& sharers,
285 NodeID requestor)
286{
287 Set indirection_set;
288 indirection_set.addSet(owner);
289 indirection_set.remove(requestor);
290 int num_indirections = indirection_set.count();
291
292 m_gets_sharing_histogram.add(num_indirections);
293 bool indirection_miss = (num_indirections > 0);
294
295 addTraceSample(datablock, PC, RubyRequestType_LD, RubyAccessMode(0),
296 requestor, indirection_miss);
297}
298
299void
301 RubyRequestType type,
302 RubyAccessMode access_mode, NodeID id,
303 bool sharing_miss)
304{
305 if (m_all_instructions) {
306 if (sharing_miss) {
308 }
309
310 // record data address trace info
311 int block_size_bits = m_profiler->m_ruby_system->getBlockSizeBits();
312 data_addr = makeLineAddress(data_addr, block_size_bits);
314 update(type, access_mode, id, sharing_miss);
315
316 // record macro data address trace info
317
318 // 6 for datablock, 4 to make it 16x more coarse
319 Addr macro_addr = mbits<Addr>(data_addr, 63, 10);
321 update(type, access_mode, id, sharing_miss);
322
323 // record program counter address trace info
325 update(type, access_mode, id, sharing_miss);
326 }
327
328 if (m_all_instructions) {
329 // This code is used if the address profiler is an
330 // all-instructions profiler record program counter address
331 // trace info
333 update(type, access_mode, id, sharing_miss);
334 }
335}
336
337void
338AddressProfiler::profileRetry(Addr data_addr, AccessType type, int count)
339{
341 if (type == AccessType_Read) {
343 } else {
345 }
346 if (count > 1) {
348 }
349}
350
351} // namespace ruby
352} // namespace gem5
static bool less_equal(const AccessTraceForAddress *n1, const AccessTraceForAddress *n2)
void profileGetX(Addr datablock, Addr PC, const Set &owner, const Set &sharers, NodeID requestor)
void setHotLines(bool hot_lines)
AddressProfiler(int num_of_sequencers, Profiler *profiler)
void profileRetry(Addr data_addr, AccessType type, int count)
std::unordered_map< Addr, AccessTraceForAddress > AddressMap
void addTraceSample(Addr data_addr, Addr pc_addr, RubyRequestType type, RubyAccessMode access_mode, NodeID id, bool sharing_miss)
void setAllInstructions(bool all_instructions)
void profileGetS(Addr datablock, Addr PC, const Set &owner, const Set &sharers, NodeID requestor)
void printStats(std::ostream &out) const
uint64_t size() const
Definition Histogram.hh:58
void add(int64_t value)
Definition Histogram.cc:93
void printPercent(std::ostream &out) const
Definition Histogram.cc:199
RubySystem * m_ruby_system
Definition Profiler.hh:77
bool getAllInstructions() const
Definition Profiler.hh:90
uint32_t getBlockSizeBits()
Definition RubySystem.hh:74
void remove(NodeID index)
Definition Set.hh:98
void addSet(const Set &obj)
Definition Set.hh:88
int count() const
Definition Set.hh:129
STL pair class.
Definition stl.hh:58
STL vector class.
Definition stl.hh:37
Bitfield< 7 > i
Definition misc_types.hh:67
Bitfield< 3 > addr
Definition types.hh:84
Addr makeLineAddress(Addr addr, int cacheLineBits)
Definition Address.cc:61
void printSorted(std::ostream &out, int num_of_sequencers, const AddressMap &record_map, std::string description, Profiler *profiler)
AccessTraceForAddress & lookupTraceForAddress(Addr addr, AddressMap &record_map)
AddressProfiler::AddressMap AddressMap
unsigned int NodeID
Copyright (c) 2024 Arm Limited 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

Generated on Mon Jan 13 2025 04:28:40 for gem5 by doxygen 1.9.8