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

Generated on Wed Sep 30 2020 14:02:13 for gem5 by doxygen 1.8.17