gem5  v20.0.0.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 
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 {
323  m_retryProfileHisto.add(count);
324  if (type == AccessType_Read) {
326  } else {
328  }
329  if (count > 1) {
331  }
332 }
count
Definition: misc.hh:703
void printStats(std::ostream &out) const
Bitfield< 7 > i
STL pair class.
Definition: stl.hh:58
uint64_t size() const
Definition: Histogram.hh:51
ip6_addr_t addr
Definition: inet.hh:330
Histogram m_gets_sharing_histogram
std::unordered_map< Addr, AccessTraceForAddress > AddressMap
AddressMap m_dataAccessTrace
int count() const
Definition: Set.hh:123
Histogram m_retryProfileHisto
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
void remove(NodeID index)
Definition: Set.hh:92
void setHotLines(bool hot_lines)
void printPercent(std::ostream &out) const
Definition: Histogram.cc:194
Histogram m_retryProfileHistoWrite
AddressProfiler(int num_of_sequencers, Profiler *profiler)
STL vector class.
Definition: stl.hh:37
unsigned int NodeID
Definition: TypeDefines.hh:34
uint8_t type
Definition: inet.hh:328
void add(int64_t value)
Definition: Histogram.cc:88
void profileGetX(Addr datablock, Addr PC, const Set &owner, const Set &sharers, NodeID requestor)
void addTraceSample(Addr data_addr, Addr pc_addr, RubyRequestType type, RubyAccessMode access_mode, NodeID id, bool sharing_miss)
int64_t m_sharing_miss_counter
AccessTraceForAddress & lookupTraceForAddress(Addr addr, AddressMap &record_map)
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:140
Addr makeLineAddress(Addr addr)
Definition: Address.cc:54
AddressProfiler::AddressMap AddressMap
void addSet(const Set &obj)
Definition: Set.hh:82
Histogram m_getx_sharing_histogram
Bitfield< 24 > j
void setAllInstructions(bool all_instructions)
void profileRetry(Addr data_addr, AccessType type, int count)
AddressMap m_programCounterAccessTrace
void printSorted(ostream &out, int num_of_sequencers, const AddressMap &record_map, string description, Profiler *profiler)
void profileGetS(Addr datablock, Addr PC, const Set &owner, const Set &sharers, NodeID requestor)
void clear()
Definition: Histogram.hh:47
Histogram m_retryProfileHistoRead
bool getAllInstructions() const
Definition: Profiler.hh:83
Profiler * m_profiler
AddressMap m_macroBlockAccessTrace
static bool less_equal(const AccessTraceForAddress *n1, const AccessTraceForAddress *n2)
AddressMap m_retryProfileMap
Definition: Set.hh:42

Generated on Thu May 28 2020 16:21:34 for gem5 by doxygen 1.8.13