gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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/stl_helpers.hh"
34 #include "mem/protocol/RubyRequest.hh"
36 
37 using namespace std;
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(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(ostream& out, int num_of_sequencers, const AddressMap &record_map,
67  string description, Profiler *profiler)
68 {
69  const int records_printed = 100;
70 
71  uint64_t misses = 0;
73 
74  AddressMap::const_iterator i = record_map.begin();
75  AddressMap::const_iterator end = record_map.end();
76  for (; i != end; ++i) {
77  const AccessTraceForAddress* record = &i->second;
78  misses += record->getTotal();
79  sorted.push_back(record);
80  }
81  sort(sorted.begin(), sorted.end(), AccessTraceForAddress::less_equal);
82 
83  out << "Total_entries_" << description << ": " << record_map.size()
84  << endl;
85  if (profiler->getAllInstructions())
86  out << "Total_Instructions_" << description << ": " << misses << endl;
87  else
88  out << "Total_data_misses_" << description << ": " << misses << endl;
89 
90  out << "total | load store atomic | user supervisor | sharing | touched-by"
91  << endl;
92 
93  Histogram remaining_records(1, 100);
94  Histogram all_records(1, 100);
95  Histogram remaining_records_log(-1);
96  Histogram all_records_log(-1);
97 
98  // Allows us to track how many lines where touched by n processors
99  std::vector<int64_t> m_touched_vec;
100  std::vector<int64_t> m_touched_weighted_vec;
101  m_touched_vec.resize(num_of_sequencers+1);
102  m_touched_weighted_vec.resize(num_of_sequencers+1);
103  for (int j = 0; j < m_touched_vec.size(); j++) {
104  m_touched_vec[j] = 0;
105  m_touched_weighted_vec[j] = 0;
106  }
107 
108  int counter = 0;
109  int max = sorted.size();
110  while (counter < max && counter < records_printed) {
111  const AccessTraceForAddress* record = sorted[counter];
112  double percent = 100.0 * (record->getTotal() / double(misses));
113  out << description << " | " << percent << " % " << *record << endl;
114  all_records.add(record->getTotal());
115  all_records_log.add(record->getTotal());
116  counter++;
117  m_touched_vec[record->getTouchedBy()]++;
118  m_touched_weighted_vec[record->getTouchedBy()] += record->getTotal();
119  }
120 
121  while (counter < max) {
122  const AccessTraceForAddress* record = sorted[counter];
123  all_records.add(record->getTotal());
124  remaining_records.add(record->getTotal());
125  all_records_log.add(record->getTotal());
126  remaining_records_log.add(record->getTotal());
127  m_touched_vec[record->getTouchedBy()]++;
128  m_touched_weighted_vec[record->getTouchedBy()] += record->getTotal();
129  }
130  out << endl;
131  out << "all_records_" << description << ": "
132  << all_records << endl
133  << "all_records_log_" << description << ": "
134  << all_records_log << endl
135  << "remaining_records_" << description << ": "
136  << remaining_records << endl
137  << "remaining_records_log_" << description << ": "
138  << remaining_records_log << endl
139  << "touched_by_" << description << ": "
140  << m_touched_vec << endl
141  << "touched_by_weighted_" << description << ": "
142  << m_touched_weighted_vec << endl
143  << endl;
144 }
145 
146 AddressProfiler::AddressProfiler(int num_of_sequencers, Profiler *profiler)
147  : m_profiler(profiler)
148 {
149  m_num_of_sequencers = num_of_sequencers;
150  clearStats();
151 }
152 
154 {
155 }
156 
157 void
159 {
160  m_hot_lines = hot_lines;
161 }
162 
163 void
165 {
166  m_all_instructions = all_instructions;
167 }
168 
169 void
170 AddressProfiler::printStats(ostream& out) const
171 {
172  if (m_hot_lines) {
173  out << endl;
174  out << "AddressProfiler Stats" << endl;
175  out << "---------------------" << endl;
176 
177  out << endl;
178  out << "sharing_misses: " << m_sharing_miss_counter << endl;
179  out << "getx_sharing_histogram: " << m_getx_sharing_histogram << endl;
180  out << "gets_sharing_histogram: " << m_gets_sharing_histogram << endl;
181 
182  out << endl;
183  out << "Hot Data Blocks" << endl;
184  out << "---------------" << endl;
185  out << endl;
187  "block_address", m_profiler);
188 
189  out << endl;
190  out << "Hot MacroData Blocks" << endl;
191  out << "--------------------" << endl;
192  out << endl;
194  "macroblock_address", m_profiler);
195 
196  out << "Hot Instructions" << endl;
197  out << "----------------" << endl;
198  out << endl;
200  "pc_address", m_profiler);
201  }
202 
203  if (m_all_instructions) {
204  out << endl;
205  out << "All Instructions Profile:" << endl;
206  out << "-------------------------" << endl;
207  out << endl;
209  "pc_address", m_profiler);
210  out << endl;
211  }
212 
213  if (m_retryProfileHisto.size() > 0) {
214  out << "Retry Profile" << endl;
215  out << "-------------" << endl;
216  out << endl;
217  out << "retry_histogram_absolute: " << m_retryProfileHisto << endl;
218  out << "retry_histogram_write: " << m_retryProfileHistoWrite << endl;
219  out << "retry_histogram_read: " << m_retryProfileHistoRead << endl;
220 
221  out << "retry_histogram_percent: ";
223  out << endl;
224 
226  "block_address", m_profiler);
227  out << endl;
228  }
229 }
230 
231 void
233 {
234  // Clear the maps
236  m_dataAccessTrace.clear();
237  m_macroBlockAccessTrace.clear();
239  m_retryProfileMap.clear();
245 }
246 
247 void
249  const Set& owner, const Set& sharers,
250  NodeID requestor)
251 {
252  Set indirection_set;
253  indirection_set.addSet(sharers);
254  indirection_set.addSet(owner);
255  indirection_set.remove(requestor);
256  int num_indirections = indirection_set.count();
257 
258  m_getx_sharing_histogram.add(num_indirections);
259  bool indirection_miss = (num_indirections > 0);
260 
261  addTraceSample(datablock, PC, RubyRequestType_ST, RubyAccessMode(0),
262  requestor, indirection_miss);
263 }
264 
265 void
267  const Set& owner, const Set& sharers,
268  NodeID requestor)
269 {
270  Set indirection_set;
271  indirection_set.addSet(owner);
272  indirection_set.remove(requestor);
273  int num_indirections = indirection_set.count();
274 
275  m_gets_sharing_histogram.add(num_indirections);
276  bool indirection_miss = (num_indirections > 0);
277 
278  addTraceSample(datablock, PC, RubyRequestType_LD, RubyAccessMode(0),
279  requestor, indirection_miss);
280 }
281 
282 void
284  RubyRequestType type,
285  RubyAccessMode access_mode, NodeID id,
286  bool sharing_miss)
287 {
288  if (m_all_instructions) {
289  if (sharing_miss) {
291  }
292 
293  // record data address trace info
294  data_addr = makeLineAddress(data_addr);
296  update(type, access_mode, id, sharing_miss);
297 
298  // record macro data address trace info
299 
300  // 6 for datablock, 4 to make it 16x more coarse
301  Addr macro_addr = maskLowOrderBits(data_addr, 10);
303  update(type, access_mode, id, sharing_miss);
304 
305  // record program counter address trace info
307  update(type, access_mode, id, sharing_miss);
308  }
309 
310  if (m_all_instructions) {
311  // This code is used if the address profiler is an
312  // all-instructions profiler record program counter address
313  // trace info
315  update(type, access_mode, id, sharing_miss);
316  }
317 }
318 
319 void
320 AddressProfiler::profileRetry(Addr data_addr, AccessType type, int count)
321 {
322  m_retryProfileHisto.add(count);
323  if (type == AccessType_Read) {
325  } else {
327  }
328  if (count > 1) {
330  }
331 }
count
Definition: misc.hh:704
int count() const
Definition: Set.hh:125
Bitfield< 7 > i
Definition: miscregs.hh:1378
STL pair class.
Definition: stl.hh:61
ip6_addr_t addr
Definition: inet.hh:335
Histogram m_gets_sharing_histogram
std::unordered_map< Addr, AccessTraceForAddress > AddressMap
AddressMap m_dataAccessTrace
Histogram m_retryProfileHisto
void remove(NodeID index)
Definition: Set.hh:94
void setHotLines(bool hot_lines)
Histogram m_retryProfileHistoWrite
AddressProfiler(int num_of_sequencers, Profiler *profiler)
STL vector class.
Definition: stl.hh:40
unsigned int NodeID
Definition: TypeDefines.hh:34
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
void printStats(std::ostream &out) const
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:142
Addr makeLineAddress(Addr addr)
Definition: Address.cc:112
AddressProfiler::AddressMap AddressMap
void addSet(const Set &obj)
Definition: Set.hh:84
Histogram m_getx_sharing_histogram
Bitfield< 24 > j
Definition: miscregs.hh:1369
void setAllInstructions(bool all_instructions)
void profileRetry(Addr data_addr, AccessType type, int count)
type
Definition: misc.hh:728
AddressMap m_programCounterAccessTrace
void printSorted(ostream &out, int num_of_sequencers, const AddressMap &record_map, string description, Profiler *profiler)
void printPercent(std::ostream &out) const
Definition: Histogram.cc:194
void profileGetS(Addr datablock, Addr PC, const Set &owner, const Set &sharers, NodeID requestor)
void clear()
Definition: Histogram.hh:47
Histogram m_retryProfileHistoRead
Profiler * m_profiler
AddressMap m_macroBlockAccessTrace
static bool less_equal(const AccessTraceForAddress *n1, const AccessTraceForAddress *n2)
Addr maskLowOrderBits(Addr addr, unsigned int number)
Definition: Address.cc:74
AddressMap m_retryProfileMap
Definition: Set.hh:45
bool getAllInstructions() const
Definition: Profiler.hh:83
uint64_t size() const
Definition: Histogram.hh:51

Generated on Fri Jun 9 2017 13:03:50 for gem5 by doxygen 1.8.6