AddressProfiler.cc revision 7048
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 "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" 33#include "mem/ruby/profiler/AddressProfiler.hh" 34#include "mem/ruby/profiler/Profiler.hh" 35#include "mem/ruby/system/System.hh" 36 37typedef AddressProfiler::AddressMap AddressMap; 38 39// Helper functions 40AccessTraceForAddress& 41lookupTraceForAddress(const Address& addr, AddressMap* record_map) 42{ 43 if (!record_map->exist(addr)) { 44 record_map->add(addr, AccessTraceForAddress(addr)); 45 } 46 return record_map->lookup(addr); 47} 48 49void 50printSorted(ostream& out, int num_of_sequencers, const AddressMap* record_map, 51 string description) 52{ 53 const int records_printed = 100; 54 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 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 70 out << "total | load store atomic | user supervisor | sharing | touched-by" 71 << endl; 72 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 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 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 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; 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 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 135AddressProfiler::~AddressProfiler() 136{ 137 delete m_dataAccessTrace; 138 delete m_macroBlockAccessTrace; 139 delete m_programCounterAccessTrace; 140 delete m_retryProfileMap; 141} 142 143void 144AddressProfiler::setHotLines(bool hot_lines) 145{ 146 m_hot_lines = hot_lines; 147} 148 149void 150AddressProfiler::setAllInstructions(bool all_instructions) 151{ 152 m_all_instructions = all_instructions; 153} 154 155void 156AddressProfiler::printStats(ostream& out) const 157{ 158 if (m_hot_lines) { 159 out << endl; 160 out << "AddressProfiler Stats" << endl; 161 out << "---------------------" << endl; 162 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 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 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 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 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 207 out << "retry_histogram_percent: "; 208 m_retryProfileHisto.printPercent(out); 209 out << endl; 210 211 printSorted(out, m_num_of_sequencers, m_retryProfileMap, 212 "block_address"); 213 out << endl; 214 } 215} 216 217void 218AddressProfiler::clearStats() 219{ 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 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 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{ 256 Set indirection_set; 257 indirection_set.addSet(owner); 258 indirection_set.remove(requestor); 259 int num_indirections = indirection_set.count(); 260 261 m_gets_sharing_histogram.add(num_indirections); 262 bool indirection_miss = (num_indirections > 0); 263 264 addTraceSample(datablock, PC, CacheRequestType_LD, AccessModeType(0), 265 requestor, indirection_miss); 266} 267 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 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 284 // record macro data address trace info 285 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 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 305void 306AddressProfiler::profileRetry(const Address& data_addr, AccessType type, 307 int count) 308{ 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} 319