gem5  v21.0.1.0
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"
37 
39 
40 using m5::stl_helpers::operator<<;
41 
42 // Helper functions
45 {
46  // we create a static default object here that is used to insert
47  // since the insertion will create a copy of the object in the
48  // process. Perhaps this is optimizing early, but it doesn't seem
49  // like it could hurt.
50  static const AccessTraceForAddress dflt;
51 
53  record_map.insert(std::make_pair(addr, dflt));
54  AddressMap::iterator i = r.first;
55  AccessTraceForAddress &access_trace = i->second;
56  if (r.second) {
57  // there was nothing there and the insert succeed, so we need
58  // to actually set the address.
59  access_trace.setAddress(addr);
60  }
61 
62  return access_trace;
63 }
64 
65 void
66 printSorted(std::ostream& out, int num_of_sequencers,
67  const AddressMap &record_map, std::string description,
68  Profiler *profiler)
69 {
70  const int records_printed = 100;
71 
72  uint64_t misses = 0;
74 
75  AddressMap::const_iterator i = record_map.begin();
76  AddressMap::const_iterator end = record_map.end();
77  for (; i != end; ++i) {
78  const AccessTraceForAddress* record = &i->second;
79  misses += record->getTotal();
80  sorted.push_back(record);
81  }
82  sort(sorted.begin(), sorted.end(), AccessTraceForAddress::less_equal);
83 
84  out << "Total_entries_" << description << ": " << record_map.size()
85  << std::endl;
86  if (profiler->getAllInstructions()) {
87  out << "Total_Instructions_" << description << ": " << misses
88  << std::endl;
89  } else {
90  out << "Total_data_misses_" << description << ": " << misses
91  << std::endl;
92  }
93 
94  out << "total | load store atomic | user supervisor | sharing | touched-by"
95  << std::endl;
96 
97  Histogram remaining_records(1, 100);
98  Histogram all_records(1, 100);
99  Histogram remaining_records_log(-1);
100  Histogram all_records_log(-1);
101 
102  // Allows us to track how many lines where touched by n processors
103  std::vector<int64_t> m_touched_vec;
104  std::vector<int64_t> m_touched_weighted_vec;
105  m_touched_vec.resize(num_of_sequencers+1);
106  m_touched_weighted_vec.resize(num_of_sequencers+1);
107  for (int j = 0; j < m_touched_vec.size(); j++) {
108  m_touched_vec[j] = 0;
109  m_touched_weighted_vec[j] = 0;
110  }
111 
112  int counter = 0;
113  int max = sorted.size();
114  while (counter < max && counter < records_printed) {
115  const AccessTraceForAddress* record = sorted[counter];
116  double percent = 100.0 * (record->getTotal() / double(misses));
117  out << description << " | " << percent << " % " << *record
118  << std::endl;
119  all_records.add(record->getTotal());
120  all_records_log.add(record->getTotal());
121  counter++;
122  m_touched_vec[record->getTouchedBy()]++;
123  m_touched_weighted_vec[record->getTouchedBy()] += record->getTotal();
124  }
125 
126  while (counter < max) {
127  const AccessTraceForAddress* record = sorted[counter];
128  all_records.add(record->getTotal());
129  remaining_records.add(record->getTotal());
130  all_records_log.add(record->getTotal());
131  remaining_records_log.add(record->getTotal());
132  m_touched_vec[record->getTouchedBy()]++;
133  m_touched_weighted_vec[record->getTouchedBy()] += record->getTotal();
134  }
135  out << std::endl;
136  out << "all_records_" << description << ": "
137  << all_records << std::endl
138  << "all_records_log_" << description << ": "
139  << all_records_log << std::endl
140  << "remaining_records_" << description << ": "
141  << remaining_records << std::endl
142  << "remaining_records_log_" << description << ": "
143  << remaining_records_log << std::endl
144  << "touched_by_" << description << ": "
145  << m_touched_vec << std::endl
146  << "touched_by_weighted_" << description << ": "
147  << m_touched_weighted_vec << std::endl
148  << std::endl;
149 }
150 
151 AddressProfiler::AddressProfiler(int num_of_sequencers, Profiler *profiler)
152  : m_profiler(profiler)
153 {
154  m_num_of_sequencers = num_of_sequencers;
155  clearStats();
156 }
157 
159 {
160 }
161 
162 void
164 {
165  m_hot_lines = hot_lines;
166 }
167 
168 void
170 {
171  m_all_instructions = all_instructions;
172 }
173 
174 void
175 AddressProfiler::printStats(std::ostream& out) const
176 {
177  if (m_hot_lines) {
178  out << std::endl;
179  out << "AddressProfiler Stats" << std::endl;
180  out << "---------------------" << std::endl;
181 
182  out << std::endl;
183  out << "sharing_misses: " << m_sharing_miss_counter << std::endl;
184  out << "getx_sharing_histogram: " << m_getx_sharing_histogram
185  << std::endl;
186  out << "gets_sharing_histogram: " << m_gets_sharing_histogram
187  << std::endl;
188 
189  out << std::endl;
190  out << "Hot Data Blocks" << std::endl;
191  out << "---------------" << std::endl;
192  out << std::endl;
194  "block_address", m_profiler);
195 
196  out << std::endl;
197  out << "Hot MacroData Blocks" << std::endl;
198  out << "--------------------" << std::endl;
199  out << std::endl;
201  "macroblock_address", m_profiler);
202 
203  out << "Hot Instructions" << std::endl;
204  out << "----------------" << std::endl;
205  out << std::endl;
207  "pc_address", m_profiler);
208  }
209 
210  if (m_all_instructions) {
211  out << std::endl;
212  out << "All Instructions Profile:" << std::endl;
213  out << "-------------------------" << std::endl;
214  out << std::endl;
216  "pc_address", m_profiler);
217  out << std::endl;
218  }
219 
220  if (m_retryProfileHisto.size() > 0) {
221  out << "Retry Profile" << std::endl;
222  out << "-------------" << std::endl;
223  out << std::endl;
224  out << "retry_histogram_absolute: " << m_retryProfileHisto
225  << std::endl;
226  out << "retry_histogram_write: " << m_retryProfileHistoWrite
227  << std::endl;
228  out << "retry_histogram_read: " << m_retryProfileHistoRead
229  << std::endl;
230 
231  out << "retry_histogram_percent: ";
233  out << std::endl;
234 
236  "block_address", m_profiler);
237  out << std::endl;
238  }
239 }
240 
241 void
243 {
244  // Clear the maps
246  m_dataAccessTrace.clear();
247  m_macroBlockAccessTrace.clear();
249  m_retryProfileMap.clear();
255 }
256 
257 void
259  const Set& owner, const Set& sharers,
260  NodeID requestor)
261 {
262  Set indirection_set;
263  indirection_set.addSet(sharers);
264  indirection_set.addSet(owner);
265  indirection_set.remove(requestor);
266  int num_indirections = indirection_set.count();
267 
268  m_getx_sharing_histogram.add(num_indirections);
269  bool indirection_miss = (num_indirections > 0);
270 
271  addTraceSample(datablock, PC, RubyRequestType_ST, RubyAccessMode(0),
272  requestor, indirection_miss);
273 }
274 
275 void
277  const Set& owner, const Set& sharers,
278  NodeID requestor)
279 {
280  Set indirection_set;
281  indirection_set.addSet(owner);
282  indirection_set.remove(requestor);
283  int num_indirections = indirection_set.count();
284 
285  m_gets_sharing_histogram.add(num_indirections);
286  bool indirection_miss = (num_indirections > 0);
287 
288  addTraceSample(datablock, PC, RubyRequestType_LD, RubyAccessMode(0),
289  requestor, indirection_miss);
290 }
291 
292 void
294  RubyRequestType type,
295  RubyAccessMode access_mode, NodeID id,
296  bool sharing_miss)
297 {
298  if (m_all_instructions) {
299  if (sharing_miss) {
301  }
302 
303  // record data address trace info
304  data_addr = makeLineAddress(data_addr);
306  update(type, access_mode, id, sharing_miss);
307 
308  // record macro data address trace info
309 
310  // 6 for datablock, 4 to make it 16x more coarse
311  Addr macro_addr = mbits<Addr>(data_addr, 63, 10);
313  update(type, access_mode, id, sharing_miss);
314 
315  // record program counter address trace info
317  update(type, access_mode, id, sharing_miss);
318  }
319 
320  if (m_all_instructions) {
321  // This code is used if the address profiler is an
322  // all-instructions profiler record program counter address
323  // trace info
325  update(type, access_mode, id, sharing_miss);
326  }
327 }
328 
329 void
330 AddressProfiler::profileRetry(Addr data_addr, AccessType type, int count)
331 {
333  if (type == AccessType_Read) {
335  } else {
337  }
338  if (count > 1) {
340  }
341 }
Set
Definition: Set.hh:42
AddressProfiler::m_all_instructions
bool m_all_instructions
Definition: AddressProfiler.hh:94
Profiler.hh
AddressProfiler::setHotLines
void setHotLines(bool hot_lines)
Definition: AddressProfiler.cc:163
makeLineAddress
Addr makeLineAddress(Addr addr)
Definition: Address.cc:54
AddressProfiler::profileGetS
void profileGetS(Addr datablock, Addr PC, const Set &owner, const Set &sharers, NodeID requestor)
Definition: AddressProfiler.cc:276
ArmISA::i
Bitfield< 7 > i
Definition: miscregs_types.hh:63
AddressProfiler::addTraceSample
void addTraceSample(Addr data_addr, Addr pc_addr, RubyRequestType type, RubyAccessMode access_mode, NodeID id, bool sharing_miss)
Definition: AddressProfiler.cc:293
AccessTraceForAddress::addSample
void addSample(int value)
Definition: AccessTraceForAddress.cc:98
AddressProfiler::AddressProfiler
AddressProfiler(int num_of_sequencers, Profiler *profiler)
Definition: AddressProfiler.cc:151
AccessTraceForAddress::getTouchedBy
int getTouchedBy() const
Definition: AccessTraceForAddress.hh:55
std::vector
STL vector class.
Definition: stl.hh:37
Histogram::printPercent
void printPercent(std::ostream &out) const
Definition: Histogram.cc:192
X86ISA::count
count
Definition: misc.hh:703
Set::addSet
void addSet(const Set &obj)
Definition: Set.hh:82
AddressProfiler::m_retryProfileMap
AddressMap m_retryProfileMap
Definition: AddressProfiler.hh:83
Set::count
int count() const
Definition: Set.hh:123
AddressProfiler::m_retryProfileHistoWrite
Histogram m_retryProfileHistoWrite
Definition: AddressProfiler.hh:85
ArmISA::j
Bitfield< 24 > j
Definition: miscregs_types.hh:54
AddressProfiler::printStats
void printStats(std::ostream &out) const
Definition: AddressProfiler.cc:175
Histogram::clear
void clear()
Definition: Histogram.hh:47
bitfield.hh
lookupTraceForAddress
AccessTraceForAddress & lookupTraceForAddress(Addr addr, AddressMap &record_map)
Definition: AddressProfiler.cc:44
AddressProfiler::profileRetry
void profileRetry(Addr data_addr, AccessType type, int count)
Definition: AddressProfiler.cc:330
Profiler
Definition: Profiler.hh:65
MipsISA::r
r
Definition: pra_constants.hh:95
AccessTraceForAddress::less_equal
static bool less_equal(const AccessTraceForAddress *n1, const AccessTraceForAddress *n2)
Definition: AccessTraceForAddress.hh:62
Histogram::size
uint64_t size() const
Definition: Histogram.hh:51
AccessTraceForAddress
Definition: AccessTraceForAddress.hh:41
AddressProfiler::setAllInstructions
void setAllInstructions(bool all_instructions)
Definition: AddressProfiler.cc:169
AddressProfiler::profileGetX
void profileGetX(Addr datablock, Addr PC, const Set &owner, const Set &sharers, NodeID requestor)
Definition: AddressProfiler.cc:258
Profiler::getAllInstructions
bool getAllInstructions() const
Definition: Profiler.hh:84
std::pair
STL pair class.
Definition: stl.hh:58
Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:148
AddressProfiler::m_programCounterAccessTrace
AddressMap m_programCounterAccessTrace
Definition: AddressProfiler.hh:82
AccessTraceForAddress::getTotal
int getTotal() const
Definition: AccessTraceForAddress.cc:88
AddressProfiler::~AddressProfiler
~AddressProfiler()
Definition: AddressProfiler.cc:158
X86ISA::addr
Bitfield< 3 > addr
Definition: types.hh:80
AccessTraceForAddress::setAddress
void setAddress(Addr addr)
Definition: AccessTraceForAddress.hh:50
AddressProfiler::m_hot_lines
bool m_hot_lines
Definition: AddressProfiler.hh:93
AddressProfiler::AddressMap
std::unordered_map< Addr, AccessTraceForAddress > AddressMap
Definition: AddressProfiler.hh:47
AddressProfiler::m_dataAccessTrace
AddressMap m_dataAccessTrace
Definition: AddressProfiler.hh:80
AddressProfiler::clearStats
void clearStats()
Definition: AddressProfiler.cc:242
AddressProfiler::m_macroBlockAccessTrace
AddressMap m_macroBlockAccessTrace
Definition: AddressProfiler.hh:81
AddressProfiler::m_getx_sharing_histogram
Histogram m_getx_sharing_histogram
Definition: AddressProfiler.hh:87
AddressProfiler::m_retryProfileHisto
Histogram m_retryProfileHisto
Definition: AddressProfiler.hh:84
AddressMap
AddressProfiler::AddressMap AddressMap
Definition: AddressProfiler.cc:38
Histogram
Definition: Histogram.hh:37
printSorted
void printSorted(std::ostream &out, int num_of_sequencers, const AddressMap &record_map, std::string description, Profiler *profiler)
Definition: AddressProfiler.cc:66
AddressProfiler::m_profiler
Profiler * m_profiler
Definition: AddressProfiler.hh:90
NodeID
unsigned int NodeID
Definition: TypeDefines.hh:34
X86ISA::type
type
Definition: misc.hh:727
AddressProfiler::m_sharing_miss_counter
int64_t m_sharing_miss_counter
Definition: AddressProfiler.hh:78
AddressProfiler.hh
AddressProfiler::m_num_of_sequencers
int m_num_of_sequencers
Definition: AddressProfiler.hh:96
Set::remove
void remove(NodeID index)
Definition: Set.hh:92
stl_helpers.hh
AddressProfiler::m_gets_sharing_histogram
Histogram m_gets_sharing_histogram
Definition: AddressProfiler.hh:88
AddressProfiler::m_retryProfileHistoRead
Histogram m_retryProfileHistoRead
Definition: AddressProfiler.hh:86
Histogram::add
void add(int64_t value)
Definition: Histogram.cc:86

Generated on Tue Jun 22 2021 15:28:30 for gem5 by doxygen 1.8.17