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

Generated on Tue Sep 21 2021 12:25:41 for gem5 by doxygen 1.8.17