AddressProfiler.cc revision 7455
12221SN/A/*
22221SN/A * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood
32221SN/A * All rights reserved.
42221SN/A *
52221SN/A * Redistribution and use in source and binary forms, with or without
62221SN/A * modification, are permitted provided that the following conditions are
72221SN/A * met: redistributions of source code must retain the above copyright
82221SN/A * notice, this list of conditions and the following disclaimer;
92221SN/A * redistributions in binary form must reproduce the above copyright
102221SN/A * notice, this list of conditions and the following disclaimer in the
112221SN/A * documentation and/or other materials provided with the distribution;
122221SN/A * neither the name of the copyright holders nor the names of its
132221SN/A * contributors may be used to endorse or promote products derived from
142221SN/A * this software without specific prior written permission.
152221SN/A *
162221SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172221SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182221SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192221SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202221SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212221SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222221SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232221SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242221SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252221SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262221SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu */
282665Ssaidi@eecs.umich.edu
292665Ssaidi@eecs.umich.edu#include <vector>
302221SN/A
312221SN/A#include "base/stl_helpers.hh"
323415Sgblack@eecs.umich.edu#include "mem/gems_common/PrioHeap.hh"
333415Sgblack@eecs.umich.edu#include "mem/protocol/CacheMsg.hh"
342223SN/A#include "mem/ruby/profiler/AddressProfiler.hh"
353415Sgblack@eecs.umich.edu#include "mem/ruby/profiler/Profiler.hh"
363578Sgblack@eecs.umich.edu#include "mem/ruby/system/System.hh"
373415Sgblack@eecs.umich.edu
383415Sgblack@eecs.umich.eduusing namespace std;
393523Sgblack@eecs.umich.edutypedef AddressProfiler::AddressMap AddressMap;
403415Sgblack@eecs.umich.edu
412680Sktlim@umich.eduusing m5::stl_helpers::operator<<;
422800Ssaidi@eecs.umich.edu
433523Sgblack@eecs.umich.edu// Helper functions
443415Sgblack@eecs.umich.eduAccessTraceForAddress&
452800Ssaidi@eecs.umich.edulookupTraceForAddress(const Address& addr, AddressMap& record_map)
462800Ssaidi@eecs.umich.edu{
472221SN/A    // we create a static default object here that is used to insert
483415Sgblack@eecs.umich.edu    // since the insertion will create a copy of the object in the
493415Sgblack@eecs.umich.edu    // process.  Perhaps this is optimizing early, but it doesn't seem
502223SN/A    // like it could hurt.
512221SN/A    static const AccessTraceForAddress dflt;
522221SN/A
533573Sgblack@eecs.umich.edu    pair<AddressMap::iterator, bool> r =
543576Sgblack@eecs.umich.edu        record_map.insert(make_pair(addr, dflt));
553576Sgblack@eecs.umich.edu    AddressMap::iterator i = r.first;
562221SN/A    AccessTraceForAddress &access_trace = i->second;
573573Sgblack@eecs.umich.edu    if (r.second) {
583576Sgblack@eecs.umich.edu        // there was nothing there and the insert succeed, so we need
593576Sgblack@eecs.umich.edu        // to actually set the address.
602221SN/A        access_trace.setAddress(addr);
613573Sgblack@eecs.umich.edu    }
623576Sgblack@eecs.umich.edu
633576Sgblack@eecs.umich.edu    return access_trace;
642221SN/A}
653573Sgblack@eecs.umich.edu
663576Sgblack@eecs.umich.eduvoid
673576Sgblack@eecs.umich.eduprintSorted(ostream& out, int num_of_sequencers, const AddressMap &record_map,
682221SN/A            string description)
693573Sgblack@eecs.umich.edu{
703576Sgblack@eecs.umich.edu    const int records_printed = 100;
713576Sgblack@eecs.umich.edu
722221SN/A    uint64 misses = 0;
733573Sgblack@eecs.umich.edu    PrioHeap<const AccessTraceForAddress*> heap;
743576Sgblack@eecs.umich.edu
753576Sgblack@eecs.umich.edu    AddressMap::const_iterator i = record_map.begin();
762221SN/A    AddressMap::const_iterator end = record_map.end();
773573Sgblack@eecs.umich.edu    for (; i != end; ++i) {
783576Sgblack@eecs.umich.edu        const AccessTraceForAddress* record = &i->second;
793576Sgblack@eecs.umich.edu        misses += record->getTotal();
803576Sgblack@eecs.umich.edu        heap.insert(record);
813576Sgblack@eecs.umich.edu    }
823576Sgblack@eecs.umich.edu
833576Sgblack@eecs.umich.edu    out << "Total_entries_" << description << ": " << record_map.size()
843576Sgblack@eecs.umich.edu        << endl;
852221SN/A    if (g_system_ptr->getProfiler()->getAllInstructions())
863573Sgblack@eecs.umich.edu        out << "Total_Instructions_" << description << ": " << misses << endl;
873576Sgblack@eecs.umich.edu    else
883576Sgblack@eecs.umich.edu        out << "Total_data_misses_" << description << ": " << misses << endl;
892221SN/A
903573Sgblack@eecs.umich.edu    out << "total | load store atomic | user supervisor | sharing | touched-by"
913576Sgblack@eecs.umich.edu        << endl;
923576Sgblack@eecs.umich.edu
932221SN/A    Histogram remaining_records(1, 100);
943573Sgblack@eecs.umich.edu    Histogram all_records(1, 100);
953576Sgblack@eecs.umich.edu    Histogram remaining_records_log(-1);
963576Sgblack@eecs.umich.edu    Histogram all_records_log(-1);
973576Sgblack@eecs.umich.edu
983576Sgblack@eecs.umich.edu    // Allows us to track how many lines where touched by n processors
993576Sgblack@eecs.umich.edu    std::vector<int64> m_touched_vec;
1003576Sgblack@eecs.umich.edu    std::vector<int64> m_touched_weighted_vec;
1013576Sgblack@eecs.umich.edu    m_touched_vec.resize(num_of_sequencers+1);
1023576Sgblack@eecs.umich.edu    m_touched_weighted_vec.resize(num_of_sequencers+1);
1033576Sgblack@eecs.umich.edu    for (int i = 0; i < m_touched_vec.size(); i++) {
1043576Sgblack@eecs.umich.edu        m_touched_vec[i] = 0;
1053576Sgblack@eecs.umich.edu        m_touched_weighted_vec[i] = 0;
1063576Sgblack@eecs.umich.edu    }
1072221SN/A
1083573Sgblack@eecs.umich.edu    int counter = 0;
1093576Sgblack@eecs.umich.edu    while (heap.size() > 0 && counter < records_printed) {
1103576Sgblack@eecs.umich.edu        const AccessTraceForAddress* record = heap.extractMin();
1112221SN/A        double percent = 100.0 * (record->getTotal() / double(misses));
1123573Sgblack@eecs.umich.edu        out << description << " | " << percent << " % " << *record << endl;
1133576Sgblack@eecs.umich.edu        all_records.add(record->getTotal());
1143576Sgblack@eecs.umich.edu        all_records_log.add(record->getTotal());
1152221SN/A        counter++;
1163573Sgblack@eecs.umich.edu        m_touched_vec[record->getTouchedBy()]++;
1173576Sgblack@eecs.umich.edu        m_touched_weighted_vec[record->getTouchedBy()] += record->getTotal();
1183576Sgblack@eecs.umich.edu    }
1192221SN/A
1203573Sgblack@eecs.umich.edu    while (heap.size() > 0) {
1213576Sgblack@eecs.umich.edu        const AccessTraceForAddress* record = heap.extractMin();
1223576Sgblack@eecs.umich.edu        all_records.add(record->getTotal());
1232221SN/A        remaining_records.add(record->getTotal());
1243573Sgblack@eecs.umich.edu        all_records_log.add(record->getTotal());
1253576Sgblack@eecs.umich.edu        remaining_records_log.add(record->getTotal());
1263576Sgblack@eecs.umich.edu        m_touched_vec[record->getTouchedBy()]++;
1272221SN/A        m_touched_weighted_vec[record->getTouchedBy()] += record->getTotal();
1283573Sgblack@eecs.umich.edu    }
1293576Sgblack@eecs.umich.edu    out << endl;
1303576Sgblack@eecs.umich.edu    out << "all_records_" << description << ": "
1312223SN/A        << all_records << endl
1323573Sgblack@eecs.umich.edu        << "all_records_log_" << description << ": "
1333576Sgblack@eecs.umich.edu        << all_records_log << endl
1343576Sgblack@eecs.umich.edu        << "remaining_records_" << description << ": "
1352223SN/A        << remaining_records << endl
1363573Sgblack@eecs.umich.edu        << "remaining_records_log_" << description << ": "
1373576Sgblack@eecs.umich.edu        << remaining_records_log << endl
1383576Sgblack@eecs.umich.edu        << "touched_by_" << description << ": "
1392223SN/A        << m_touched_vec << endl
1403573Sgblack@eecs.umich.edu        << "touched_by_weighted_" << description << ": "
1413576Sgblack@eecs.umich.edu        << m_touched_weighted_vec << endl
1423576Sgblack@eecs.umich.edu        << endl;
1432223SN/A}
1443573Sgblack@eecs.umich.edu
1453576Sgblack@eecs.umich.eduAddressProfiler::AddressProfiler(int num_of_sequencers)
1463576Sgblack@eecs.umich.edu{
1473576Sgblack@eecs.umich.edu    m_num_of_sequencers = num_of_sequencers;
1483576Sgblack@eecs.umich.edu    clearStats();
1493576Sgblack@eecs.umich.edu}
1503576Sgblack@eecs.umich.edu
1513576Sgblack@eecs.umich.eduAddressProfiler::~AddressProfiler()
1522223SN/A{
1533573Sgblack@eecs.umich.edu}
1543576Sgblack@eecs.umich.edu
1553576Sgblack@eecs.umich.eduvoid
1562223SN/AAddressProfiler::setHotLines(bool hot_lines)
1573573Sgblack@eecs.umich.edu{
1583576Sgblack@eecs.umich.edu    m_hot_lines = hot_lines;
1593576Sgblack@eecs.umich.edu}
1602223SN/A
1613573Sgblack@eecs.umich.eduvoid
1623576Sgblack@eecs.umich.eduAddressProfiler::setAllInstructions(bool all_instructions)
1633576Sgblack@eecs.umich.edu{
1642223SN/A    m_all_instructions = all_instructions;
1653573Sgblack@eecs.umich.edu}
1663576Sgblack@eecs.umich.edu
1673576Sgblack@eecs.umich.eduvoid
1682223SN/AAddressProfiler::printStats(ostream& out) const
1693573Sgblack@eecs.umich.edu{
1703576Sgblack@eecs.umich.edu    if (m_hot_lines) {
1713576Sgblack@eecs.umich.edu        out << endl;
1722223SN/A        out << "AddressProfiler Stats" << endl;
1733573Sgblack@eecs.umich.edu        out << "---------------------" << endl;
1743576Sgblack@eecs.umich.edu
1753576Sgblack@eecs.umich.edu        out << endl;
1762223SN/A        out << "sharing_misses: " << m_sharing_miss_counter << endl;
1773573Sgblack@eecs.umich.edu        out << "getx_sharing_histogram: " << m_getx_sharing_histogram << endl;
1783576Sgblack@eecs.umich.edu        out << "gets_sharing_histogram: " << m_gets_sharing_histogram << endl;
1793576Sgblack@eecs.umich.edu
1802223SN/A        out << endl;
1813573Sgblack@eecs.umich.edu        out << "Hot Data Blocks" << endl;
1823576Sgblack@eecs.umich.edu        out << "---------------" << endl;
1833576Sgblack@eecs.umich.edu        out << endl;
1842223SN/A        printSorted(out, m_num_of_sequencers, m_dataAccessTrace,
1853573Sgblack@eecs.umich.edu                    "block_address");
1863576Sgblack@eecs.umich.edu
1873576Sgblack@eecs.umich.edu        out << endl;
1882223SN/A        out << "Hot MacroData Blocks" << endl;
1893573Sgblack@eecs.umich.edu        out << "--------------------" << endl;
1903576Sgblack@eecs.umich.edu        out << endl;
1913576Sgblack@eecs.umich.edu        printSorted(out, m_num_of_sequencers, m_macroBlockAccessTrace,
1922223SN/A                    "macroblock_address");
1933576Sgblack@eecs.umich.edu
1943576Sgblack@eecs.umich.edu        out << "Hot Instructions" << endl;
1953576Sgblack@eecs.umich.edu        out << "----------------" << endl;
1963576Sgblack@eecs.umich.edu        out << endl;
1972527SN/A        printSorted(out, m_num_of_sequencers, m_programCounterAccessTrace,
1983573Sgblack@eecs.umich.edu                    "pc_address");
1993576Sgblack@eecs.umich.edu    }
2003890Ssaidi@eecs.umich.edu
2012223SN/A    if (m_all_instructions) {
2023573Sgblack@eecs.umich.edu        out << endl;
2033576Sgblack@eecs.umich.edu        out << "All Instructions Profile:" << endl;
2043576Sgblack@eecs.umich.edu        out << "-------------------------" << endl;
2052223SN/A        out << endl;
2063573Sgblack@eecs.umich.edu        printSorted(out, m_num_of_sequencers, m_programCounterAccessTrace,
2073576Sgblack@eecs.umich.edu                    "pc_address");
2083576Sgblack@eecs.umich.edu        out << endl;
2092223SN/A    }
2103573Sgblack@eecs.umich.edu
2114103Ssaidi@eecs.umich.edu    if (m_retryProfileHisto.size() > 0) {
2124103Ssaidi@eecs.umich.edu        out << "Retry Profile" << endl;
2134103Ssaidi@eecs.umich.edu        out << "-------------" << endl;
2144103Ssaidi@eecs.umich.edu        out << endl;
2153576Sgblack@eecs.umich.edu        out << "retry_histogram_absolute: " << m_retryProfileHisto << endl;
2163576Sgblack@eecs.umich.edu        out << "retry_histogram_write: " << m_retryProfileHistoWrite << endl;
2172223SN/A        out << "retry_histogram_read: " << m_retryProfileHistoRead << endl;
2183573Sgblack@eecs.umich.edu
2193576Sgblack@eecs.umich.edu        out << "retry_histogram_percent: ";
2203576Sgblack@eecs.umich.edu        m_retryProfileHisto.printPercent(out);
2212223SN/A        out << endl;
2223573Sgblack@eecs.umich.edu
2233576Sgblack@eecs.umich.edu        printSorted(out, m_num_of_sequencers, m_retryProfileMap,
2243576Sgblack@eecs.umich.edu                    "block_address");
2253576Sgblack@eecs.umich.edu        out << endl;
2263576Sgblack@eecs.umich.edu    }
2273576Sgblack@eecs.umich.edu}
2283576Sgblack@eecs.umich.edu
2293576Sgblack@eecs.umich.eduvoid
2303576Sgblack@eecs.umich.eduAddressProfiler::clearStats()
2313576Sgblack@eecs.umich.edu{
2323576Sgblack@eecs.umich.edu    // Clear the maps
2333576Sgblack@eecs.umich.edu    m_sharing_miss_counter = 0;
2343576Sgblack@eecs.umich.edu    m_dataAccessTrace.clear();
2353576Sgblack@eecs.umich.edu    m_macroBlockAccessTrace.clear();
2363576Sgblack@eecs.umich.edu    m_programCounterAccessTrace.clear();
2373576Sgblack@eecs.umich.edu    m_retryProfileMap.clear();
2383576Sgblack@eecs.umich.edu    m_retryProfileHisto.clear();
2393576Sgblack@eecs.umich.edu    m_retryProfileHistoRead.clear();
2403576Sgblack@eecs.umich.edu    m_retryProfileHistoWrite.clear();
2413576Sgblack@eecs.umich.edu    m_getx_sharing_histogram.clear();
2423576Sgblack@eecs.umich.edu    m_gets_sharing_histogram.clear();
2433576Sgblack@eecs.umich.edu}
2443576Sgblack@eecs.umich.edu
2453576Sgblack@eecs.umich.eduvoid
2463576Sgblack@eecs.umich.eduAddressProfiler::profileGetX(const Address& datablock, const Address& PC,
2473893Shsul@eecs.umich.edu                             const Set& owner, const Set& sharers,
2483576Sgblack@eecs.umich.edu                             NodeID requestor)
2493576Sgblack@eecs.umich.edu{
2503576Sgblack@eecs.umich.edu    Set indirection_set;
2513576Sgblack@eecs.umich.edu    indirection_set.addSet(sharers);
2523576Sgblack@eecs.umich.edu    indirection_set.addSet(owner);
2533576Sgblack@eecs.umich.edu    indirection_set.remove(requestor);
2543576Sgblack@eecs.umich.edu    int num_indirections = indirection_set.count();
2553576Sgblack@eecs.umich.edu
2563576Sgblack@eecs.umich.edu    m_getx_sharing_histogram.add(num_indirections);
2573576Sgblack@eecs.umich.edu    bool indirection_miss = (num_indirections > 0);
2583576Sgblack@eecs.umich.edu
2593576Sgblack@eecs.umich.edu    addTraceSample(datablock, PC, CacheRequestType_ST, AccessModeType(0),
2603576Sgblack@eecs.umich.edu                   requestor, indirection_miss);
2613576Sgblack@eecs.umich.edu}
2623576Sgblack@eecs.umich.edu
2633576Sgblack@eecs.umich.eduvoid
2643576Sgblack@eecs.umich.eduAddressProfiler::profileGetS(const Address& datablock, const Address& PC,
2653576Sgblack@eecs.umich.edu                             const Set& owner, const Set& sharers,
2663576Sgblack@eecs.umich.edu                             NodeID requestor)
2673576Sgblack@eecs.umich.edu{
2683576Sgblack@eecs.umich.edu    Set indirection_set;
2692223SN/A    indirection_set.addSet(owner);
2703415Sgblack@eecs.umich.edu    indirection_set.remove(requestor);
2713578Sgblack@eecs.umich.edu    int num_indirections = indirection_set.count();
2723578Sgblack@eecs.umich.edu
2733415Sgblack@eecs.umich.edu    m_gets_sharing_histogram.add(num_indirections);
2743415Sgblack@eecs.umich.edu    bool indirection_miss = (num_indirections > 0);
2753578Sgblack@eecs.umich.edu
2763415Sgblack@eecs.umich.edu    addTraceSample(datablock, PC, CacheRequestType_LD, AccessModeType(0),
2773578Sgblack@eecs.umich.edu                   requestor, indirection_miss);
2783578Sgblack@eecs.umich.edu}
2794172Ssaidi@eecs.umich.edu
2803578Sgblack@eecs.umich.eduvoid
2813578Sgblack@eecs.umich.eduAddressProfiler::addTraceSample(Address data_addr, Address pc_addr,
2823578Sgblack@eecs.umich.edu                                CacheRequestType type,
2833578Sgblack@eecs.umich.edu                                AccessModeType access_mode, NodeID id,
2844172Ssaidi@eecs.umich.edu                                bool sharing_miss)
2853746Sgblack@eecs.umich.edu{
2863746Sgblack@eecs.umich.edu    if (m_all_instructions) {
2874172Ssaidi@eecs.umich.edu        if (sharing_miss) {
2883746Sgblack@eecs.umich.edu            m_sharing_miss_counter++;
2894172Ssaidi@eecs.umich.edu        }
2903578Sgblack@eecs.umich.edu
2913578Sgblack@eecs.umich.edu        // record data address trace info
2923578Sgblack@eecs.umich.edu        data_addr.makeLineAddress();
2933578Sgblack@eecs.umich.edu        lookupTraceForAddress(data_addr, m_dataAccessTrace).
2943578Sgblack@eecs.umich.edu            update(type, access_mode, id, sharing_miss);
2953578Sgblack@eecs.umich.edu
2963578Sgblack@eecs.umich.edu        // record macro data address trace info
2973578Sgblack@eecs.umich.edu
2983578Sgblack@eecs.umich.edu        // 6 for datablock, 4 to make it 16x more coarse
2994172Ssaidi@eecs.umich.edu        Address macro_addr(data_addr.maskLowOrderBits(10));
3004172Ssaidi@eecs.umich.edu        lookupTraceForAddress(macro_addr, m_macroBlockAccessTrace).
3014172Ssaidi@eecs.umich.edu            update(type, access_mode, id, sharing_miss);
3024172Ssaidi@eecs.umich.edu
3034172Ssaidi@eecs.umich.edu        // record program counter address trace info
3043761Sgblack@eecs.umich.edu        lookupTraceForAddress(pc_addr, m_programCounterAccessTrace).
3054172Ssaidi@eecs.umich.edu            update(type, access_mode, id, sharing_miss);
3064172Ssaidi@eecs.umich.edu    }
3074172Ssaidi@eecs.umich.edu
3084172Ssaidi@eecs.umich.edu    if (m_all_instructions) {
3094172Ssaidi@eecs.umich.edu        // This code is used if the address profiler is an
3107720Sgblack@eecs.umich.edu        // all-instructions profiler record program counter address
3113578Sgblack@eecs.umich.edu        // trace info
3123578Sgblack@eecs.umich.edu        lookupTraceForAddress(pc_addr, m_programCounterAccessTrace).
3133578Sgblack@eecs.umich.edu            update(type, access_mode, id, sharing_miss);
3147720Sgblack@eecs.umich.edu    }
3153928Ssaidi@eecs.umich.edu}
3163578Sgblack@eecs.umich.edu
3173578Sgblack@eecs.umich.eduvoid
3183578Sgblack@eecs.umich.eduAddressProfiler::profileRetry(const Address& data_addr, AccessType type,
3193578Sgblack@eecs.umich.edu                              int count)
3203578Sgblack@eecs.umich.edu{
3213578Sgblack@eecs.umich.edu    m_retryProfileHisto.add(count);
3223578Sgblack@eecs.umich.edu    if (type == AccessType_Read) {
3233578Sgblack@eecs.umich.edu        m_retryProfileHistoRead.add(count);
3243578Sgblack@eecs.umich.edu    } else {
3253578Sgblack@eecs.umich.edu        m_retryProfileHistoWrite.add(count);
3263578Sgblack@eecs.umich.edu    }
3273578Sgblack@eecs.umich.edu    if (count > 1) {
3284172Ssaidi@eecs.umich.edu        lookupTraceForAddress(data_addr, m_retryProfileMap).addSample(count);
3293578Sgblack@eecs.umich.edu    }
3303578Sgblack@eecs.umich.edu}
3317720Sgblack@eecs.umich.edu