AddressProfiler.cc (7454:3a3e8e8cce1b) AddressProfiler.cc (7455:586f99bf0dc4)
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
29#include <vector>
30
31#include "base/stl_helpers.hh"
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
29#include <vector>
30
31#include "base/stl_helpers.hh"
32#include "mem/gems_common/Map.hh"
33#include "mem/gems_common/PrioHeap.hh"
34#include "mem/protocol/CacheMsg.hh"
32#include "mem/gems_common/PrioHeap.hh"
33#include "mem/protocol/CacheMsg.hh"
35#include "mem/ruby/profiler/AccessTraceForAddress.hh"
36#include "mem/ruby/profiler/AddressProfiler.hh"
37#include "mem/ruby/profiler/Profiler.hh"
38#include "mem/ruby/system/System.hh"
39
40using namespace std;
41typedef AddressProfiler::AddressMap AddressMap;
42
43using m5::stl_helpers::operator<<;
44
45// Helper functions
46AccessTraceForAddress&
34#include "mem/ruby/profiler/AddressProfiler.hh"
35#include "mem/ruby/profiler/Profiler.hh"
36#include "mem/ruby/system/System.hh"
37
38using namespace std;
39typedef AddressProfiler::AddressMap AddressMap;
40
41using m5::stl_helpers::operator<<;
42
43// Helper functions
44AccessTraceForAddress&
47lookupTraceForAddress(const Address& addr, AddressMap* record_map)
45lookupTraceForAddress(const Address& addr, AddressMap& record_map)
48{
46{
49 if (!record_map->exist(addr)) {
50 record_map->add(addr, AccessTraceForAddress(addr));
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
53 pair<AddressMap::iterator, bool> r =
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);
51 }
61 }
52 return record_map->lookup(addr);
62
63 return access_trace;
53}
54
55void
64}
65
66void
56printSorted(ostream& out, int num_of_sequencers, const AddressMap* record_map,
67printSorted(ostream& out, int num_of_sequencers, const AddressMap &record_map,
57 string description)
58{
59 const int records_printed = 100;
60
61 uint64 misses = 0;
68 string description)
69{
70 const int records_printed = 100;
71
72 uint64 misses = 0;
62 PrioHeap heap;
63 std::vector<Address> keys = record_map->keys();
64 for (int i = 0; i < keys.size(); i++) {
65 AccessTraceForAddress* record = &(record_map->lookup(keys[i]));
73 PrioHeap<const AccessTraceForAddress*> heap;
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;
66 misses += record->getTotal();
67 heap.insert(record);
68 }
69
79 misses += record->getTotal();
80 heap.insert(record);
81 }
82
70 out << "Total_entries_" << description << ": " << keys.size() << endl;
83 out << "Total_entries_" << description << ": " << record_map.size()
84 << endl;
71 if (g_system_ptr->getProfiler()->getAllInstructions())
72 out << "Total_Instructions_" << description << ": " << misses << endl;
73 else
74 out << "Total_data_misses_" << description << ": " << misses << endl;
75
76 out << "total | load store atomic | user supervisor | sharing | touched-by"
77 << endl;
78
79 Histogram remaining_records(1, 100);
80 Histogram all_records(1, 100);
81 Histogram remaining_records_log(-1);
82 Histogram all_records_log(-1);
83
84 // Allows us to track how many lines where touched by n processors
85 std::vector<int64> m_touched_vec;
86 std::vector<int64> m_touched_weighted_vec;
87 m_touched_vec.resize(num_of_sequencers+1);
88 m_touched_weighted_vec.resize(num_of_sequencers+1);
89 for (int i = 0; i < m_touched_vec.size(); i++) {
90 m_touched_vec[i] = 0;
91 m_touched_weighted_vec[i] = 0;
92 }
93
94 int counter = 0;
95 while (heap.size() > 0 && counter < records_printed) {
85 if (g_system_ptr->getProfiler()->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> m_touched_vec;
100 std::vector<int64> 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 i = 0; i < m_touched_vec.size(); i++) {
104 m_touched_vec[i] = 0;
105 m_touched_weighted_vec[i] = 0;
106 }
107
108 int counter = 0;
109 while (heap.size() > 0 && counter < records_printed) {
96 AccessTraceForAddress* record = heap.extractMin();
110 const AccessTraceForAddress* record = heap.extractMin();
97 double percent = 100.0 * (record->getTotal() / double(misses));
98 out << description << " | " << percent << " % " << *record << endl;
99 all_records.add(record->getTotal());
100 all_records_log.add(record->getTotal());
101 counter++;
102 m_touched_vec[record->getTouchedBy()]++;
103 m_touched_weighted_vec[record->getTouchedBy()] += record->getTotal();
104 }
105
106 while (heap.size() > 0) {
111 double percent = 100.0 * (record->getTotal() / double(misses));
112 out << description << " | " << percent << " % " << *record << endl;
113 all_records.add(record->getTotal());
114 all_records_log.add(record->getTotal());
115 counter++;
116 m_touched_vec[record->getTouchedBy()]++;
117 m_touched_weighted_vec[record->getTouchedBy()] += record->getTotal();
118 }
119
120 while (heap.size() > 0) {
107 AccessTraceForAddress* record = heap.extractMin();
121 const AccessTraceForAddress* record = heap.extractMin();
108 all_records.add(record->getTotal());
109 remaining_records.add(record->getTotal());
110 all_records_log.add(record->getTotal());
111 remaining_records_log.add(record->getTotal());
112 m_touched_vec[record->getTouchedBy()]++;
113 m_touched_weighted_vec[record->getTouchedBy()] += record->getTotal();
114 }
115 out << endl;
116 out << "all_records_" << description << ": "
117 << all_records << endl
118 << "all_records_log_" << description << ": "
119 << all_records_log << endl
120 << "remaining_records_" << description << ": "
121 << remaining_records << endl
122 << "remaining_records_log_" << description << ": "
123 << remaining_records_log << endl
124 << "touched_by_" << description << ": "
125 << m_touched_vec << endl
126 << "touched_by_weighted_" << description << ": "
127 << m_touched_weighted_vec << endl
128 << endl;
129}
130
131AddressProfiler::AddressProfiler(int num_of_sequencers)
132{
122 all_records.add(record->getTotal());
123 remaining_records.add(record->getTotal());
124 all_records_log.add(record->getTotal());
125 remaining_records_log.add(record->getTotal());
126 m_touched_vec[record->getTouchedBy()]++;
127 m_touched_weighted_vec[record->getTouchedBy()] += record->getTotal();
128 }
129 out << endl;
130 out << "all_records_" << description << ": "
131 << all_records << endl
132 << "all_records_log_" << description << ": "
133 << all_records_log << endl
134 << "remaining_records_" << description << ": "
135 << remaining_records << endl
136 << "remaining_records_log_" << description << ": "
137 << remaining_records_log << endl
138 << "touched_by_" << description << ": "
139 << m_touched_vec << endl
140 << "touched_by_weighted_" << description << ": "
141 << m_touched_weighted_vec << endl
142 << endl;
143}
144
145AddressProfiler::AddressProfiler(int num_of_sequencers)
146{
133 m_dataAccessTrace = new AddressMap;
134 m_macroBlockAccessTrace = new AddressMap;
135 m_programCounterAccessTrace = new AddressMap;
136 m_retryProfileMap = new AddressMap;
137 m_num_of_sequencers = num_of_sequencers;
138 clearStats();
139}
140
141AddressProfiler::~AddressProfiler()
142{
147 m_num_of_sequencers = num_of_sequencers;
148 clearStats();
149}
150
151AddressProfiler::~AddressProfiler()
152{
143 delete m_dataAccessTrace;
144 delete m_macroBlockAccessTrace;
145 delete m_programCounterAccessTrace;
146 delete m_retryProfileMap;
147}
148
149void
150AddressProfiler::setHotLines(bool hot_lines)
151{
152 m_hot_lines = hot_lines;
153}
154
155void
156AddressProfiler::setAllInstructions(bool all_instructions)
157{
158 m_all_instructions = all_instructions;
159}
160
161void
162AddressProfiler::printStats(ostream& out) const
163{
164 if (m_hot_lines) {
165 out << endl;
166 out << "AddressProfiler Stats" << endl;
167 out << "---------------------" << endl;
168
169 out << endl;
170 out << "sharing_misses: " << m_sharing_miss_counter << endl;
171 out << "getx_sharing_histogram: " << m_getx_sharing_histogram << endl;
172 out << "gets_sharing_histogram: " << m_gets_sharing_histogram << endl;
173
174 out << endl;
175 out << "Hot Data Blocks" << endl;
176 out << "---------------" << endl;
177 out << endl;
178 printSorted(out, m_num_of_sequencers, m_dataAccessTrace,
179 "block_address");
180
181 out << endl;
182 out << "Hot MacroData Blocks" << endl;
183 out << "--------------------" << endl;
184 out << endl;
185 printSorted(out, m_num_of_sequencers, m_macroBlockAccessTrace,
186 "macroblock_address");
187
188 out << "Hot Instructions" << endl;
189 out << "----------------" << endl;
190 out << endl;
191 printSorted(out, m_num_of_sequencers, m_programCounterAccessTrace,
192 "pc_address");
193 }
194
195 if (m_all_instructions) {
196 out << endl;
197 out << "All Instructions Profile:" << endl;
198 out << "-------------------------" << endl;
199 out << endl;
200 printSorted(out, m_num_of_sequencers, m_programCounterAccessTrace,
201 "pc_address");
202 out << endl;
203 }
204
205 if (m_retryProfileHisto.size() > 0) {
206 out << "Retry Profile" << endl;
207 out << "-------------" << endl;
208 out << endl;
209 out << "retry_histogram_absolute: " << m_retryProfileHisto << endl;
210 out << "retry_histogram_write: " << m_retryProfileHistoWrite << endl;
211 out << "retry_histogram_read: " << m_retryProfileHistoRead << endl;
212
213 out << "retry_histogram_percent: ";
214 m_retryProfileHisto.printPercent(out);
215 out << endl;
216
217 printSorted(out, m_num_of_sequencers, m_retryProfileMap,
218 "block_address");
219 out << endl;
220 }
221}
222
223void
224AddressProfiler::clearStats()
225{
226 // Clear the maps
227 m_sharing_miss_counter = 0;
153}
154
155void
156AddressProfiler::setHotLines(bool hot_lines)
157{
158 m_hot_lines = hot_lines;
159}
160
161void
162AddressProfiler::setAllInstructions(bool all_instructions)
163{
164 m_all_instructions = all_instructions;
165}
166
167void
168AddressProfiler::printStats(ostream& out) const
169{
170 if (m_hot_lines) {
171 out << endl;
172 out << "AddressProfiler Stats" << endl;
173 out << "---------------------" << endl;
174
175 out << endl;
176 out << "sharing_misses: " << m_sharing_miss_counter << endl;
177 out << "getx_sharing_histogram: " << m_getx_sharing_histogram << endl;
178 out << "gets_sharing_histogram: " << m_gets_sharing_histogram << endl;
179
180 out << endl;
181 out << "Hot Data Blocks" << endl;
182 out << "---------------" << endl;
183 out << endl;
184 printSorted(out, m_num_of_sequencers, m_dataAccessTrace,
185 "block_address");
186
187 out << endl;
188 out << "Hot MacroData Blocks" << endl;
189 out << "--------------------" << endl;
190 out << endl;
191 printSorted(out, m_num_of_sequencers, m_macroBlockAccessTrace,
192 "macroblock_address");
193
194 out << "Hot Instructions" << endl;
195 out << "----------------" << endl;
196 out << endl;
197 printSorted(out, m_num_of_sequencers, m_programCounterAccessTrace,
198 "pc_address");
199 }
200
201 if (m_all_instructions) {
202 out << endl;
203 out << "All Instructions Profile:" << endl;
204 out << "-------------------------" << endl;
205 out << endl;
206 printSorted(out, m_num_of_sequencers, m_programCounterAccessTrace,
207 "pc_address");
208 out << endl;
209 }
210
211 if (m_retryProfileHisto.size() > 0) {
212 out << "Retry Profile" << endl;
213 out << "-------------" << endl;
214 out << endl;
215 out << "retry_histogram_absolute: " << m_retryProfileHisto << endl;
216 out << "retry_histogram_write: " << m_retryProfileHistoWrite << endl;
217 out << "retry_histogram_read: " << m_retryProfileHistoRead << endl;
218
219 out << "retry_histogram_percent: ";
220 m_retryProfileHisto.printPercent(out);
221 out << endl;
222
223 printSorted(out, m_num_of_sequencers, m_retryProfileMap,
224 "block_address");
225 out << endl;
226 }
227}
228
229void
230AddressProfiler::clearStats()
231{
232 // Clear the maps
233 m_sharing_miss_counter = 0;
228 m_dataAccessTrace->clear();
229 m_macroBlockAccessTrace->clear();
230 m_programCounterAccessTrace->clear();
231 m_retryProfileMap->clear();
234 m_dataAccessTrace.clear();
235 m_macroBlockAccessTrace.clear();
236 m_programCounterAccessTrace.clear();
237 m_retryProfileMap.clear();
232 m_retryProfileHisto.clear();
233 m_retryProfileHistoRead.clear();
234 m_retryProfileHistoWrite.clear();
235 m_getx_sharing_histogram.clear();
236 m_gets_sharing_histogram.clear();
237}
238
239void
240AddressProfiler::profileGetX(const Address& datablock, const Address& PC,
241 const Set& owner, const Set& sharers,
242 NodeID requestor)
243{
244 Set indirection_set;
245 indirection_set.addSet(sharers);
246 indirection_set.addSet(owner);
247 indirection_set.remove(requestor);
248 int num_indirections = indirection_set.count();
249
250 m_getx_sharing_histogram.add(num_indirections);
251 bool indirection_miss = (num_indirections > 0);
252
253 addTraceSample(datablock, PC, CacheRequestType_ST, AccessModeType(0),
254 requestor, indirection_miss);
255}
256
257void
258AddressProfiler::profileGetS(const Address& datablock, const Address& PC,
259 const Set& owner, const Set& sharers,
260 NodeID requestor)
261{
262 Set indirection_set;
263 indirection_set.addSet(owner);
264 indirection_set.remove(requestor);
265 int num_indirections = indirection_set.count();
266
267 m_gets_sharing_histogram.add(num_indirections);
268 bool indirection_miss = (num_indirections > 0);
269
270 addTraceSample(datablock, PC, CacheRequestType_LD, AccessModeType(0),
271 requestor, indirection_miss);
272}
273
274void
275AddressProfiler::addTraceSample(Address data_addr, Address pc_addr,
276 CacheRequestType type,
277 AccessModeType access_mode, NodeID id,
278 bool sharing_miss)
279{
280 if (m_all_instructions) {
281 if (sharing_miss) {
282 m_sharing_miss_counter++;
283 }
284
285 // record data address trace info
286 data_addr.makeLineAddress();
287 lookupTraceForAddress(data_addr, m_dataAccessTrace).
288 update(type, access_mode, id, sharing_miss);
289
290 // record macro data address trace info
291
292 // 6 for datablock, 4 to make it 16x more coarse
293 Address macro_addr(data_addr.maskLowOrderBits(10));
294 lookupTraceForAddress(macro_addr, m_macroBlockAccessTrace).
295 update(type, access_mode, id, sharing_miss);
296
297 // record program counter address trace info
298 lookupTraceForAddress(pc_addr, m_programCounterAccessTrace).
299 update(type, access_mode, id, sharing_miss);
300 }
301
302 if (m_all_instructions) {
303 // This code is used if the address profiler is an
304 // all-instructions profiler record program counter address
305 // trace info
306 lookupTraceForAddress(pc_addr, m_programCounterAccessTrace).
307 update(type, access_mode, id, sharing_miss);
308 }
309}
310
311void
312AddressProfiler::profileRetry(const Address& data_addr, AccessType type,
313 int count)
314{
315 m_retryProfileHisto.add(count);
316 if (type == AccessType_Read) {
317 m_retryProfileHistoRead.add(count);
318 } else {
319 m_retryProfileHistoWrite.add(count);
320 }
321 if (count > 1) {
322 lookupTraceForAddress(data_addr, m_retryProfileMap).addSample(count);
323 }
324}
238 m_retryProfileHisto.clear();
239 m_retryProfileHistoRead.clear();
240 m_retryProfileHistoWrite.clear();
241 m_getx_sharing_histogram.clear();
242 m_gets_sharing_histogram.clear();
243}
244
245void
246AddressProfiler::profileGetX(const Address& datablock, const Address& PC,
247 const Set& owner, const Set& sharers,
248 NodeID requestor)
249{
250 Set indirection_set;
251 indirection_set.addSet(sharers);
252 indirection_set.addSet(owner);
253 indirection_set.remove(requestor);
254 int num_indirections = indirection_set.count();
255
256 m_getx_sharing_histogram.add(num_indirections);
257 bool indirection_miss = (num_indirections > 0);
258
259 addTraceSample(datablock, PC, CacheRequestType_ST, AccessModeType(0),
260 requestor, indirection_miss);
261}
262
263void
264AddressProfiler::profileGetS(const Address& datablock, const Address& PC,
265 const Set& owner, const Set& sharers,
266 NodeID requestor)
267{
268 Set indirection_set;
269 indirection_set.addSet(owner);
270 indirection_set.remove(requestor);
271 int num_indirections = indirection_set.count();
272
273 m_gets_sharing_histogram.add(num_indirections);
274 bool indirection_miss = (num_indirections > 0);
275
276 addTraceSample(datablock, PC, CacheRequestType_LD, AccessModeType(0),
277 requestor, indirection_miss);
278}
279
280void
281AddressProfiler::addTraceSample(Address data_addr, Address pc_addr,
282 CacheRequestType type,
283 AccessModeType access_mode, NodeID id,
284 bool sharing_miss)
285{
286 if (m_all_instructions) {
287 if (sharing_miss) {
288 m_sharing_miss_counter++;
289 }
290
291 // record data address trace info
292 data_addr.makeLineAddress();
293 lookupTraceForAddress(data_addr, m_dataAccessTrace).
294 update(type, access_mode, id, sharing_miss);
295
296 // record macro data address trace info
297
298 // 6 for datablock, 4 to make it 16x more coarse
299 Address macro_addr(data_addr.maskLowOrderBits(10));
300 lookupTraceForAddress(macro_addr, m_macroBlockAccessTrace).
301 update(type, access_mode, id, sharing_miss);
302
303 // record program counter address trace info
304 lookupTraceForAddress(pc_addr, m_programCounterAccessTrace).
305 update(type, access_mode, id, sharing_miss);
306 }
307
308 if (m_all_instructions) {
309 // This code is used if the address profiler is an
310 // all-instructions profiler record program counter address
311 // trace info
312 lookupTraceForAddress(pc_addr, m_programCounterAccessTrace).
313 update(type, access_mode, id, sharing_miss);
314 }
315}
316
317void
318AddressProfiler::profileRetry(const Address& data_addr, AccessType type,
319 int count)
320{
321 m_retryProfileHisto.add(count);
322 if (type == AccessType_Read) {
323 m_retryProfileHistoRead.add(count);
324 } else {
325 m_retryProfileHistoWrite.add(count);
326 }
327 if (count > 1) {
328 lookupTraceForAddress(data_addr, m_retryProfileMap).addSample(count);
329 }
330}