AddressProfiler.cc revision 11061
16145Snate@binkert.org/* 26145Snate@binkert.org * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 36145Snate@binkert.org * All rights reserved. 46145Snate@binkert.org * 56145Snate@binkert.org * Redistribution and use in source and binary forms, with or without 66145Snate@binkert.org * modification, are permitted provided that the following conditions are 76145Snate@binkert.org * met: redistributions of source code must retain the above copyright 86145Snate@binkert.org * notice, this list of conditions and the following disclaimer; 96145Snate@binkert.org * redistributions in binary form must reproduce the above copyright 106145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the 116145Snate@binkert.org * documentation and/or other materials provided with the distribution; 126145Snate@binkert.org * neither the name of the copyright holders nor the names of its 136145Snate@binkert.org * contributors may be used to endorse or promote products derived from 146145Snate@binkert.org * this software without specific prior written permission. 156145Snate@binkert.org * 166145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196145Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206145Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226145Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236145Snate@binkert.org * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246145Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256145Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266145Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276145Snate@binkert.org */ 286145Snate@binkert.org 297454Snate@binkert.org#include <vector> 307454Snate@binkert.org 317454Snate@binkert.org#include "base/stl_helpers.hh" 328174Snilay@cs.wisc.edu#include "mem/protocol/RubyRequest.hh" 337048Snate@binkert.org#include "mem/ruby/profiler/AddressProfiler.hh" 347048Snate@binkert.org#include "mem/ruby/profiler/Profiler.hh" 357048Snate@binkert.org 367055Snate@binkert.orgusing namespace std; 377048Snate@binkert.orgtypedef AddressProfiler::AddressMap AddressMap; 386145Snate@binkert.org 397454Snate@binkert.orgusing m5::stl_helpers::operator<<; 407454Snate@binkert.org 416145Snate@binkert.org// Helper functions 427048Snate@binkert.orgAccessTraceForAddress& 4311025Snilay@cs.wisc.edulookupTraceForAddress(Addr addr, AddressMap& record_map) 447048Snate@binkert.org{ 457455Snate@binkert.org // we create a static default object here that is used to insert 467455Snate@binkert.org // since the insertion will create a copy of the object in the 477455Snate@binkert.org // process. Perhaps this is optimizing early, but it doesn't seem 487455Snate@binkert.org // like it could hurt. 497455Snate@binkert.org static const AccessTraceForAddress dflt; 507455Snate@binkert.org 517455Snate@binkert.org pair<AddressMap::iterator, bool> r = 527455Snate@binkert.org record_map.insert(make_pair(addr, dflt)); 537455Snate@binkert.org AddressMap::iterator i = r.first; 547455Snate@binkert.org AccessTraceForAddress &access_trace = i->second; 557455Snate@binkert.org if (r.second) { 567455Snate@binkert.org // there was nothing there and the insert succeed, so we need 577455Snate@binkert.org // to actually set the address. 587455Snate@binkert.org access_trace.setAddress(addr); 597048Snate@binkert.org } 607455Snate@binkert.org 617455Snate@binkert.org return access_trace; 627048Snate@binkert.org} 636145Snate@binkert.org 647048Snate@binkert.orgvoid 657455Snate@binkert.orgprintSorted(ostream& out, int num_of_sequencers, const AddressMap &record_map, 6610919Sbrandon.potter@amd.com string description, Profiler *profiler) 677048Snate@binkert.org{ 687048Snate@binkert.org const int records_printed = 100; 697048Snate@binkert.org 7011061Snilay@cs.wisc.edu uint64_t misses = 0; 717456Snate@binkert.org std::vector<const AccessTraceForAddress *> sorted; 727455Snate@binkert.org 737455Snate@binkert.org AddressMap::const_iterator i = record_map.begin(); 747455Snate@binkert.org AddressMap::const_iterator end = record_map.end(); 757455Snate@binkert.org for (; i != end; ++i) { 767455Snate@binkert.org const AccessTraceForAddress* record = &i->second; 777048Snate@binkert.org misses += record->getTotal(); 787456Snate@binkert.org sorted.push_back(record); 797048Snate@binkert.org } 807456Snate@binkert.org sort(sorted.begin(), sorted.end(), AccessTraceForAddress::less_equal); 817048Snate@binkert.org 827455Snate@binkert.org out << "Total_entries_" << description << ": " << record_map.size() 837455Snate@binkert.org << endl; 8410919Sbrandon.potter@amd.com if (profiler->getAllInstructions()) 857048Snate@binkert.org out << "Total_Instructions_" << description << ": " << misses << endl; 867048Snate@binkert.org else 877048Snate@binkert.org out << "Total_data_misses_" << description << ": " << misses << endl; 887048Snate@binkert.org 897048Snate@binkert.org out << "total | load store atomic | user supervisor | sharing | touched-by" 907048Snate@binkert.org << endl; 917048Snate@binkert.org 927048Snate@binkert.org Histogram remaining_records(1, 100); 937048Snate@binkert.org Histogram all_records(1, 100); 947048Snate@binkert.org Histogram remaining_records_log(-1); 957048Snate@binkert.org Histogram all_records_log(-1); 967048Snate@binkert.org 977048Snate@binkert.org // Allows us to track how many lines where touched by n processors 9811061Snilay@cs.wisc.edu std::vector<int64_t> m_touched_vec; 9911061Snilay@cs.wisc.edu std::vector<int64_t> m_touched_weighted_vec; 1007454Snate@binkert.org m_touched_vec.resize(num_of_sequencers+1); 1017454Snate@binkert.org m_touched_weighted_vec.resize(num_of_sequencers+1); 1029550Sandreas.hansson@arm.com for (int j = 0; j < m_touched_vec.size(); j++) { 1039550Sandreas.hansson@arm.com m_touched_vec[j] = 0; 1049550Sandreas.hansson@arm.com m_touched_weighted_vec[j] = 0; 1057048Snate@binkert.org } 1067048Snate@binkert.org 1077048Snate@binkert.org int counter = 0; 1087456Snate@binkert.org int max = sorted.size(); 1097456Snate@binkert.org while (counter < max && counter < records_printed) { 1107456Snate@binkert.org const AccessTraceForAddress* record = sorted[counter]; 1117048Snate@binkert.org double percent = 100.0 * (record->getTotal() / double(misses)); 1127048Snate@binkert.org out << description << " | " << percent << " % " << *record << endl; 1137048Snate@binkert.org all_records.add(record->getTotal()); 1147048Snate@binkert.org all_records_log.add(record->getTotal()); 1157048Snate@binkert.org counter++; 1167048Snate@binkert.org m_touched_vec[record->getTouchedBy()]++; 1177048Snate@binkert.org m_touched_weighted_vec[record->getTouchedBy()] += record->getTotal(); 1187048Snate@binkert.org } 1197048Snate@binkert.org 1207456Snate@binkert.org while (counter < max) { 1217456Snate@binkert.org const AccessTraceForAddress* record = sorted[counter]; 1227048Snate@binkert.org all_records.add(record->getTotal()); 1237048Snate@binkert.org remaining_records.add(record->getTotal()); 1247048Snate@binkert.org all_records_log.add(record->getTotal()); 1257048Snate@binkert.org remaining_records_log.add(record->getTotal()); 1267048Snate@binkert.org m_touched_vec[record->getTouchedBy()]++; 1277048Snate@binkert.org m_touched_weighted_vec[record->getTouchedBy()] += record->getTotal(); 1287048Snate@binkert.org } 1297048Snate@binkert.org out << endl; 1307048Snate@binkert.org out << "all_records_" << description << ": " 1317048Snate@binkert.org << all_records << endl 1327048Snate@binkert.org << "all_records_log_" << description << ": " 1337048Snate@binkert.org << all_records_log << endl 1347048Snate@binkert.org << "remaining_records_" << description << ": " 1357048Snate@binkert.org << remaining_records << endl 1367048Snate@binkert.org << "remaining_records_log_" << description << ": " 1377048Snate@binkert.org << remaining_records_log << endl 1387048Snate@binkert.org << "touched_by_" << description << ": " 1397048Snate@binkert.org << m_touched_vec << endl 1407048Snate@binkert.org << "touched_by_weighted_" << description << ": " 1417048Snate@binkert.org << m_touched_weighted_vec << endl 1427048Snate@binkert.org << endl; 1437048Snate@binkert.org} 1446896SBrad.Beckmann@amd.com 14510919Sbrandon.potter@amd.comAddressProfiler::AddressProfiler(int num_of_sequencers, Profiler *profiler) 14610919Sbrandon.potter@amd.com : m_profiler(profiler) 1476145Snate@binkert.org{ 1487048Snate@binkert.org m_num_of_sequencers = num_of_sequencers; 1497048Snate@binkert.org clearStats(); 1506145Snate@binkert.org} 1516145Snate@binkert.org 1526145Snate@binkert.orgAddressProfiler::~AddressProfiler() 1536145Snate@binkert.org{ 1546145Snate@binkert.org} 1556145Snate@binkert.org 1567048Snate@binkert.orgvoid 1577048Snate@binkert.orgAddressProfiler::setHotLines(bool hot_lines) 1587048Snate@binkert.org{ 1597048Snate@binkert.org m_hot_lines = hot_lines; 1606285Snate@binkert.org} 1616285Snate@binkert.org 1627048Snate@binkert.orgvoid 1637048Snate@binkert.orgAddressProfiler::setAllInstructions(bool all_instructions) 1646145Snate@binkert.org{ 1657048Snate@binkert.org m_all_instructions = all_instructions; 1666145Snate@binkert.org} 1676145Snate@binkert.org 1687048Snate@binkert.orgvoid 1697048Snate@binkert.orgAddressProfiler::printStats(ostream& out) const 1706145Snate@binkert.org{ 1717048Snate@binkert.org if (m_hot_lines) { 1727048Snate@binkert.org out << endl; 1737048Snate@binkert.org out << "AddressProfiler Stats" << endl; 1747048Snate@binkert.org out << "---------------------" << endl; 1757048Snate@binkert.org 1767048Snate@binkert.org out << endl; 1777048Snate@binkert.org out << "sharing_misses: " << m_sharing_miss_counter << endl; 1787048Snate@binkert.org out << "getx_sharing_histogram: " << m_getx_sharing_histogram << endl; 1797048Snate@binkert.org out << "gets_sharing_histogram: " << m_gets_sharing_histogram << endl; 1807048Snate@binkert.org 1817048Snate@binkert.org out << endl; 1827048Snate@binkert.org out << "Hot Data Blocks" << endl; 1837048Snate@binkert.org out << "---------------" << endl; 1847048Snate@binkert.org out << endl; 1857048Snate@binkert.org printSorted(out, m_num_of_sequencers, m_dataAccessTrace, 18610919Sbrandon.potter@amd.com "block_address", m_profiler); 1877048Snate@binkert.org 1887048Snate@binkert.org out << endl; 1897048Snate@binkert.org out << "Hot MacroData Blocks" << endl; 1907048Snate@binkert.org out << "--------------------" << endl; 1917048Snate@binkert.org out << endl; 1927048Snate@binkert.org printSorted(out, m_num_of_sequencers, m_macroBlockAccessTrace, 19310919Sbrandon.potter@amd.com "macroblock_address", m_profiler); 1947048Snate@binkert.org 1957048Snate@binkert.org out << "Hot Instructions" << endl; 1967048Snate@binkert.org out << "----------------" << endl; 1977048Snate@binkert.org out << endl; 1987048Snate@binkert.org printSorted(out, m_num_of_sequencers, m_programCounterAccessTrace, 19910919Sbrandon.potter@amd.com "pc_address", m_profiler); 2007048Snate@binkert.org } 2017048Snate@binkert.org 2027048Snate@binkert.org if (m_all_instructions) { 2037048Snate@binkert.org out << endl; 2047048Snate@binkert.org out << "All Instructions Profile:" << endl; 2057048Snate@binkert.org out << "-------------------------" << endl; 2067048Snate@binkert.org out << endl; 2077048Snate@binkert.org printSorted(out, m_num_of_sequencers, m_programCounterAccessTrace, 20810919Sbrandon.potter@amd.com "pc_address", m_profiler); 2097048Snate@binkert.org out << endl; 2107048Snate@binkert.org } 2117048Snate@binkert.org 2127048Snate@binkert.org if (m_retryProfileHisto.size() > 0) { 2137048Snate@binkert.org out << "Retry Profile" << endl; 2147048Snate@binkert.org out << "-------------" << endl; 2157048Snate@binkert.org out << endl; 2167048Snate@binkert.org out << "retry_histogram_absolute: " << m_retryProfileHisto << endl; 2177048Snate@binkert.org out << "retry_histogram_write: " << m_retryProfileHistoWrite << endl; 2187048Snate@binkert.org out << "retry_histogram_read: " << m_retryProfileHistoRead << endl; 2197048Snate@binkert.org 2207048Snate@binkert.org out << "retry_histogram_percent: "; 2217048Snate@binkert.org m_retryProfileHisto.printPercent(out); 2227048Snate@binkert.org out << endl; 2237048Snate@binkert.org 2247048Snate@binkert.org printSorted(out, m_num_of_sequencers, m_retryProfileMap, 22510919Sbrandon.potter@amd.com "block_address", m_profiler); 2267048Snate@binkert.org out << endl; 2277048Snate@binkert.org } 2286145Snate@binkert.org} 2296145Snate@binkert.org 2307048Snate@binkert.orgvoid 2317048Snate@binkert.orgAddressProfiler::clearStats() 2326145Snate@binkert.org{ 2337048Snate@binkert.org // Clear the maps 2347048Snate@binkert.org m_sharing_miss_counter = 0; 2357455Snate@binkert.org m_dataAccessTrace.clear(); 2367455Snate@binkert.org m_macroBlockAccessTrace.clear(); 2377455Snate@binkert.org m_programCounterAccessTrace.clear(); 2387455Snate@binkert.org m_retryProfileMap.clear(); 2397048Snate@binkert.org m_retryProfileHisto.clear(); 2407048Snate@binkert.org m_retryProfileHistoRead.clear(); 2417048Snate@binkert.org m_retryProfileHistoWrite.clear(); 2427048Snate@binkert.org m_getx_sharing_histogram.clear(); 2437048Snate@binkert.org m_gets_sharing_histogram.clear(); 2446145Snate@binkert.org} 2456145Snate@binkert.org 2467048Snate@binkert.orgvoid 24711025Snilay@cs.wisc.eduAddressProfiler::profileGetX(Addr datablock, Addr PC, 2487048Snate@binkert.org const Set& owner, const Set& sharers, 2497048Snate@binkert.org NodeID requestor) 2506145Snate@binkert.org{ 2517048Snate@binkert.org Set indirection_set; 2527048Snate@binkert.org indirection_set.addSet(sharers); 2537048Snate@binkert.org indirection_set.addSet(owner); 2547048Snate@binkert.org indirection_set.remove(requestor); 2557048Snate@binkert.org int num_indirections = indirection_set.count(); 2566145Snate@binkert.org 2577048Snate@binkert.org m_getx_sharing_histogram.add(num_indirections); 2587048Snate@binkert.org bool indirection_miss = (num_indirections > 0); 2596145Snate@binkert.org 2608165Snilay@cs.wisc.edu addTraceSample(datablock, PC, RubyRequestType_ST, RubyAccessMode(0), 2617048Snate@binkert.org requestor, indirection_miss); 2626145Snate@binkert.org} 2636145Snate@binkert.org 2647048Snate@binkert.orgvoid 26511025Snilay@cs.wisc.eduAddressProfiler::profileGetS(Addr datablock, Addr PC, 2667048Snate@binkert.org const Set& owner, const Set& sharers, 2677048Snate@binkert.org NodeID requestor) 2686145Snate@binkert.org{ 2697048Snate@binkert.org Set indirection_set; 2707048Snate@binkert.org indirection_set.addSet(owner); 2717048Snate@binkert.org indirection_set.remove(requestor); 2727048Snate@binkert.org int num_indirections = indirection_set.count(); 2737048Snate@binkert.org 2747048Snate@binkert.org m_gets_sharing_histogram.add(num_indirections); 2757048Snate@binkert.org bool indirection_miss = (num_indirections > 0); 2767048Snate@binkert.org 2778165Snilay@cs.wisc.edu addTraceSample(datablock, PC, RubyRequestType_LD, RubyAccessMode(0), 2787048Snate@binkert.org requestor, indirection_miss); 2797048Snate@binkert.org} 2807048Snate@binkert.org 2817048Snate@binkert.orgvoid 28211025Snilay@cs.wisc.eduAddressProfiler::addTraceSample(Addr data_addr, Addr pc_addr, 2838165Snilay@cs.wisc.edu RubyRequestType type, 2848164Snilay@cs.wisc.edu RubyAccessMode access_mode, NodeID id, 2857048Snate@binkert.org bool sharing_miss) 2867048Snate@binkert.org{ 2877048Snate@binkert.org if (m_all_instructions) { 2887048Snate@binkert.org if (sharing_miss) { 2897048Snate@binkert.org m_sharing_miss_counter++; 2907048Snate@binkert.org } 2917048Snate@binkert.org 2927048Snate@binkert.org // record data address trace info 29311025Snilay@cs.wisc.edu data_addr = makeLineAddress(data_addr); 2947048Snate@binkert.org lookupTraceForAddress(data_addr, m_dataAccessTrace). 2957048Snate@binkert.org update(type, access_mode, id, sharing_miss); 2967048Snate@binkert.org 2977048Snate@binkert.org // record macro data address trace info 2987048Snate@binkert.org 2997048Snate@binkert.org // 6 for datablock, 4 to make it 16x more coarse 30011025Snilay@cs.wisc.edu Addr macro_addr = maskLowOrderBits(data_addr, 10); 3017048Snate@binkert.org lookupTraceForAddress(macro_addr, m_macroBlockAccessTrace). 3027048Snate@binkert.org update(type, access_mode, id, sharing_miss); 3037048Snate@binkert.org 3047048Snate@binkert.org // record program counter address trace info 3057048Snate@binkert.org lookupTraceForAddress(pc_addr, m_programCounterAccessTrace). 3067048Snate@binkert.org update(type, access_mode, id, sharing_miss); 3076145Snate@binkert.org } 3086145Snate@binkert.org 3097048Snate@binkert.org if (m_all_instructions) { 3107048Snate@binkert.org // This code is used if the address profiler is an 3117048Snate@binkert.org // all-instructions profiler record program counter address 3127048Snate@binkert.org // trace info 3137048Snate@binkert.org lookupTraceForAddress(pc_addr, m_programCounterAccessTrace). 3147048Snate@binkert.org update(type, access_mode, id, sharing_miss); 3157048Snate@binkert.org } 3166145Snate@binkert.org} 3176145Snate@binkert.org 3187048Snate@binkert.orgvoid 31911025Snilay@cs.wisc.eduAddressProfiler::profileRetry(Addr data_addr, AccessType type, int count) 3206145Snate@binkert.org{ 3217048Snate@binkert.org m_retryProfileHisto.add(count); 3227048Snate@binkert.org if (type == AccessType_Read) { 3237048Snate@binkert.org m_retryProfileHistoRead.add(count); 3247048Snate@binkert.org } else { 3257048Snate@binkert.org m_retryProfileHistoWrite.add(count); 3267048Snate@binkert.org } 3277048Snate@binkert.org if (count > 1) { 3287048Snate@binkert.org lookupTraceForAddress(data_addr, m_retryProfileMap).addSample(count); 3297048Snate@binkert.org } 3306145Snate@binkert.org} 331