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