/* * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer; * redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution; * neither the name of the copyright holders nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /* * AddressProfiler.cc * * Description: See AddressProfiler.hh * * $Id$ * */ #include "mem/ruby/profiler/AddressProfiler.hh" #include "mem/protocol/CacheMsg.hh" #include "mem/ruby/profiler/AccessTraceForAddress.hh" #include "mem/gems_common/PrioHeap.hh" #include "mem/gems_common/Map.hh" #include "mem/ruby/system/System.hh" #include "mem/ruby/profiler/Profiler.hh" // Helper functions static AccessTraceForAddress& lookupTraceForAddress(const Address& addr, Map
* record_map); static void printSorted(ostream& out, const Map* record_map, string description); AddressProfiler::AddressProfiler() { m_dataAccessTrace = new Map; m_macroBlockAccessTrace = new Map; m_programCounterAccessTrace = new Map; m_retryProfileMap = new Map; clearStats(); } AddressProfiler::~AddressProfiler() { delete m_dataAccessTrace; delete m_macroBlockAccessTrace; delete m_programCounterAccessTrace; delete m_retryProfileMap; } void AddressProfiler::setHotLines(bool hot_lines){ m_hot_lines = hot_lines; } void AddressProfiler::setAllInstructions(bool all_instructions){ m_all_instructions = all_instructions; } void AddressProfiler::printStats(ostream& out) const { if (m_hot_lines) { out << endl; out << "AddressProfiler Stats" << endl; out << "---------------------" << endl; out << endl; out << "sharing_misses: " << m_sharing_miss_counter << endl; out << "getx_sharing_histogram: " << m_getx_sharing_histogram << endl; out << "gets_sharing_histogram: " << m_gets_sharing_histogram << endl; out << endl; out << "Hot Data Blocks" << endl; out << "---------------" << endl; out << endl; printSorted(out, m_dataAccessTrace, "block_address"); out << endl; out << "Hot MacroData Blocks" << endl; out << "--------------------" << endl; out << endl; printSorted(out, m_macroBlockAccessTrace, "macroblock_address"); out << "Hot Instructions" << endl; out << "----------------" << endl; out << endl; printSorted(out, m_programCounterAccessTrace, "pc_address"); } if (m_all_instructions){ out << endl; out << "All Instructions Profile:" << endl; out << "-------------------------" << endl; out << endl; printSorted(out, m_programCounterAccessTrace, "pc_address"); out << endl; } if (m_retryProfileHisto.size() > 0) { out << "Retry Profile" << endl; out << "-------------" << endl; out << endl; out << "retry_histogram_absolute: " << m_retryProfileHisto << endl; out << "retry_histogram_write: " << m_retryProfileHistoWrite << endl; out << "retry_histogram_read: " << m_retryProfileHistoRead << endl; out << "retry_histogram_percent: "; m_retryProfileHisto.printPercent(out); out << endl; printSorted(out, m_retryProfileMap, "block_address"); out << endl; } } void AddressProfiler::clearStats() { // Clear the maps m_sharing_miss_counter = 0; m_dataAccessTrace->clear(); m_macroBlockAccessTrace->clear(); m_programCounterAccessTrace->clear(); m_retryProfileMap->clear(); m_retryProfileHisto.clear(); m_retryProfileHistoRead.clear(); m_retryProfileHistoWrite.clear(); m_getx_sharing_histogram.clear(); m_gets_sharing_histogram.clear(); } void AddressProfiler::profileGetX(const Address& datablock, const Address& PC, const Set& owner, const Set& sharers, NodeID requestor) { Set indirection_set; indirection_set.addSet(sharers); indirection_set.addSet(owner); indirection_set.remove(requestor); int num_indirections = indirection_set.count(); m_getx_sharing_histogram.add(num_indirections); bool indirection_miss = (num_indirections > 0); addTraceSample(datablock, PC, CacheRequestType_ST, AccessModeType(0), requestor, indirection_miss); } void AddressProfiler::profileGetS(const Address& datablock, const Address& PC, const Set& owner, const Set& sharers, NodeID requestor) { Set indirection_set; indirection_set.addSet(owner); indirection_set.remove(requestor); int num_indirections = indirection_set.count(); m_gets_sharing_histogram.add(num_indirections); bool indirection_miss = (num_indirections > 0); addTraceSample(datablock, PC, CacheRequestType_LD, AccessModeType(0), requestor, indirection_miss); } void AddressProfiler::addTraceSample(Address data_addr, Address pc_addr, CacheRequestType type, AccessModeType access_mode, NodeID id, bool sharing_miss) { if (m_all_instructions) { if (sharing_miss) { m_sharing_miss_counter++; } // record data address trace info data_addr.makeLineAddress(); lookupTraceForAddress(data_addr, m_dataAccessTrace).update(type, access_mode, id, sharing_miss); // record macro data address trace info Address macro_addr(data_addr.maskLowOrderBits(10)); // 6 for datablock, 4 to make it 16x more coarse lookupTraceForAddress(macro_addr, m_macroBlockAccessTrace).update(type, access_mode, id, sharing_miss); // record program counter address trace info lookupTraceForAddress(pc_addr, m_programCounterAccessTrace).update(type, access_mode, id, sharing_miss); } if (m_all_instructions) { // This code is used if the address profiler is an all-instructions profiler // record program counter address trace info lookupTraceForAddress(pc_addr, m_programCounterAccessTrace).update(type, access_mode, id, sharing_miss); } } void AddressProfiler::profileRetry(const Address& data_addr, AccessType type, int count) { m_retryProfileHisto.add(count); if (type == AccessType_Read) { m_retryProfileHistoRead.add(count); } else { m_retryProfileHistoWrite.add(count); } if (count > 1) { lookupTraceForAddress(data_addr, m_retryProfileMap).addSample(count); } } // ***** Normal Functions ****** static void printSorted(ostream& out, const Map* record_map, string description) { const int records_printed = 100; uint64 misses = 0; PrioHeap