Profiler.cc revision 6285
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 296145Snate@binkert.org/* 306145Snate@binkert.org This file has been modified by Kevin Moore and Dan Nussbaum of the 316145Snate@binkert.org Scalable Systems Research Group at Sun Microsystems Laboratories 326145Snate@binkert.org (http://research.sun.com/scalable/) to support the Adaptive 336145Snate@binkert.org Transactional Memory Test Platform (ATMTP). 346145Snate@binkert.org 356145Snate@binkert.org Please send email to atmtp-interest@sun.com with feedback, questions, or 366145Snate@binkert.org to request future announcements about ATMTP. 376145Snate@binkert.org 386145Snate@binkert.org ---------------------------------------------------------------------- 396145Snate@binkert.org 406145Snate@binkert.org File modification date: 2008-02-23 416145Snate@binkert.org 426145Snate@binkert.org ---------------------------------------------------------------------- 436145Snate@binkert.org*/ 446145Snate@binkert.org 456145Snate@binkert.org/* 466284Snate@binkert.org * Profiler.cc 476145Snate@binkert.org * 486284Snate@binkert.org * Description: See Profiler.hh 496145Snate@binkert.org * 506145Snate@binkert.org * $Id$ 516145Snate@binkert.org * 526145Snate@binkert.org */ 536145Snate@binkert.org 546154Snate@binkert.org#include "mem/ruby/profiler/Profiler.hh" 556154Snate@binkert.org#include "mem/ruby/profiler/CacheProfiler.hh" 566154Snate@binkert.org#include "mem/ruby/profiler/AddressProfiler.hh" 576154Snate@binkert.org#include "mem/ruby/system/System.hh" 586154Snate@binkert.org#include "mem/ruby/network/Network.hh" 596154Snate@binkert.org#include "mem/gems_common/PrioHeap.hh" 606154Snate@binkert.org#include "mem/protocol/CacheMsg.hh" 616154Snate@binkert.org#include "mem/protocol/Protocol.hh" 626154Snate@binkert.org#include "mem/gems_common/util.hh" 636154Snate@binkert.org#include "mem/gems_common/Map.hh" 646154Snate@binkert.org#include "mem/ruby/common/Debug.hh" 656154Snate@binkert.org#include "mem/protocol/MachineType.hh" 666145Snate@binkert.org 676145Snate@binkert.org// Allows use of times() library call, which determines virtual runtime 686145Snate@binkert.org#include <sys/times.h> 696145Snate@binkert.org 706145Snate@binkert.orgextern std::ostream * debug_cout_ptr; 716145Snate@binkert.org 726145Snate@binkert.orgstatic double process_memory_total(); 736145Snate@binkert.orgstatic double process_memory_resident(); 746145Snate@binkert.org 756285Snate@binkert.orgProfiler::Profiler(const string & name) 766145Snate@binkert.org : m_conflicting_histogram(-1) 776145Snate@binkert.org{ 786285Snate@binkert.org m_name = name; 796145Snate@binkert.org m_requestProfileMap_ptr = new Map<string, int>; 806145Snate@binkert.org m_L1D_cache_profiler_ptr = new CacheProfiler("L1D_cache"); 816145Snate@binkert.org m_L1I_cache_profiler_ptr = new CacheProfiler("L1I_cache"); 826145Snate@binkert.org 836145Snate@binkert.org m_L2_cache_profiler_ptr = new CacheProfiler("L2_cache"); 846145Snate@binkert.org 856285Snate@binkert.org m_inst_profiler_ptr = NULL; 866285Snate@binkert.org m_address_profiler_ptr = NULL; 876285Snate@binkert.org 886285Snate@binkert.org/* 896145Snate@binkert.org m_address_profiler_ptr = new AddressProfiler; 906145Snate@binkert.org m_inst_profiler_ptr = NULL; 916285Snate@binkert.org if (m_all_instructions) { 926145Snate@binkert.org m_inst_profiler_ptr = new AddressProfiler; 936145Snate@binkert.org } 946285Snate@binkert.org*/ 956145Snate@binkert.org m_conflicting_map_ptr = new Map<Address, Time>; 966145Snate@binkert.org 976145Snate@binkert.org m_real_time_start_time = time(NULL); // Not reset in clearStats() 986145Snate@binkert.org m_stats_period = 1000000; // Default 996145Snate@binkert.org m_periodic_output_file_ptr = &cerr; 1006145Snate@binkert.org 1016285Snate@binkert.org//changed by SS 1026285Snate@binkert.org/* 1036145Snate@binkert.org // for MemoryControl: 1046145Snate@binkert.org m_memReq = 0; 1056145Snate@binkert.org m_memBankBusy = 0; 1066145Snate@binkert.org m_memBusBusy = 0; 1076145Snate@binkert.org m_memReadWriteBusy = 0; 1086145Snate@binkert.org m_memDataBusBusy = 0; 1096145Snate@binkert.org m_memTfawBusy = 0; 1106145Snate@binkert.org m_memRefresh = 0; 1116145Snate@binkert.org m_memRead = 0; 1126145Snate@binkert.org m_memWrite = 0; 1136145Snate@binkert.org m_memWaitCycles = 0; 1146145Snate@binkert.org m_memInputQ = 0; 1156145Snate@binkert.org m_memBankQ = 0; 1166145Snate@binkert.org m_memArbWait = 0; 1176145Snate@binkert.org m_memRandBusy = 0; 1186145Snate@binkert.org m_memNotOld = 0; 1196145Snate@binkert.org 1206145Snate@binkert.org 1216145Snate@binkert.org int totalBanks = RubyConfig::banksPerRank() 1226145Snate@binkert.org * RubyConfig::ranksPerDimm() 1236145Snate@binkert.org * RubyConfig::dimmsPerChannel(); 1246145Snate@binkert.org m_memBankCount.setSize(totalBanks); 1256285Snate@binkert.org*/ 1266145Snate@binkert.org} 1276145Snate@binkert.org 1286145Snate@binkert.orgProfiler::~Profiler() 1296145Snate@binkert.org{ 1306145Snate@binkert.org if (m_periodic_output_file_ptr != &cerr) { 1316145Snate@binkert.org delete m_periodic_output_file_ptr; 1326145Snate@binkert.org } 1336145Snate@binkert.org delete m_address_profiler_ptr; 1346145Snate@binkert.org delete m_L1D_cache_profiler_ptr; 1356145Snate@binkert.org delete m_L1I_cache_profiler_ptr; 1366145Snate@binkert.org delete m_L2_cache_profiler_ptr; 1376145Snate@binkert.org delete m_requestProfileMap_ptr; 1386145Snate@binkert.org delete m_conflicting_map_ptr; 1396145Snate@binkert.org} 1406145Snate@binkert.org 1416285Snate@binkert.orgvoid Profiler::init(const vector<string> & argv, vector<string> memory_control_names) 1426285Snate@binkert.org{ 1436285Snate@binkert.org // added by SS 1446285Snate@binkert.org vector<string>::iterator it; 1456285Snate@binkert.org memory_control_profiler* mcp; 1466285Snate@binkert.org m_memory_control_names = memory_control_names; 1476285Snate@binkert.org// printf ( "Here in Profiler::init \n"); 1486285Snate@binkert.org for ( it=memory_control_names.begin() ; it < memory_control_names.end(); it++ ){ 1496285Snate@binkert.org// printf ( "Here in Profiler::init memory control name %s \n", (*it).c_str()); 1506285Snate@binkert.org mcp = new memory_control_profiler; 1516285Snate@binkert.org mcp->m_memReq = 0; 1526285Snate@binkert.org mcp->m_memBankBusy = 0; 1536285Snate@binkert.org mcp->m_memBusBusy = 0; 1546285Snate@binkert.org mcp->m_memReadWriteBusy = 0; 1556285Snate@binkert.org mcp->m_memDataBusBusy = 0; 1566285Snate@binkert.org mcp->m_memTfawBusy = 0; 1576285Snate@binkert.org mcp->m_memRefresh = 0; 1586285Snate@binkert.org mcp->m_memRead = 0; 1596285Snate@binkert.org mcp->m_memWrite = 0; 1606285Snate@binkert.org mcp->m_memWaitCycles = 0; 1616285Snate@binkert.org mcp->m_memInputQ = 0; 1626285Snate@binkert.org mcp->m_memBankQ = 0; 1636285Snate@binkert.org mcp->m_memArbWait = 0; 1646285Snate@binkert.org mcp->m_memRandBusy = 0; 1656285Snate@binkert.org mcp->m_memNotOld = 0; 1666285Snate@binkert.org 1676285Snate@binkert.org mcp->m_banks_per_rank = RubySystem::getMemoryControl((*it).c_str())->getBanksPerRank(); 1686285Snate@binkert.org mcp->m_ranks_per_dimm = RubySystem::getMemoryControl((*it).c_str())->getRanksPerDimm(); 1696285Snate@binkert.org mcp->m_dimms_per_channel = RubySystem::getMemoryControl((*it).c_str())->getDimmsPerChannel(); 1706285Snate@binkert.org 1716285Snate@binkert.org int totalBanks = mcp->m_banks_per_rank 1726285Snate@binkert.org * mcp->m_ranks_per_dimm 1736285Snate@binkert.org * mcp->m_dimms_per_channel; 1746285Snate@binkert.org 1756285Snate@binkert.org mcp->m_memBankCount.setSize(totalBanks); 1766285Snate@binkert.org 1776285Snate@binkert.org m_memory_control_profilers [(*it).c_str()] = mcp; 1786285Snate@binkert.org } 1796285Snate@binkert.org 1806285Snate@binkert.org clearStats(); 1816285Snate@binkert.org m_hot_lines = false; 1826285Snate@binkert.org m_all_instructions = false; 1836285Snate@binkert.org 1846285Snate@binkert.org for (size_t i=0; i<argv.size(); i+=2) { 1856285Snate@binkert.org if ( argv[i] == "hot_lines") { 1866285Snate@binkert.org m_hot_lines = (argv[i+1]=="true"); 1876285Snate@binkert.org } else if ( argv[i] == "all_instructions") { 1886285Snate@binkert.org m_all_instructions = (argv[i+1]=="true"); 1896285Snate@binkert.org }else { 1906285Snate@binkert.org cerr << "WARNING: Profiler: Unkown configuration parameter: " << argv[i] << endl; 1916285Snate@binkert.org assert(false); 1926285Snate@binkert.org } 1936285Snate@binkert.org } 1946285Snate@binkert.org 1956285Snate@binkert.org m_address_profiler_ptr = new AddressProfiler; 1966285Snate@binkert.org m_address_profiler_ptr -> setHotLines(m_hot_lines); 1976285Snate@binkert.org m_address_profiler_ptr -> setAllInstructions(m_all_instructions); 1986285Snate@binkert.org 1996285Snate@binkert.org if (m_all_instructions) { 2006285Snate@binkert.org m_inst_profiler_ptr = new AddressProfiler; 2016285Snate@binkert.org m_inst_profiler_ptr -> setHotLines(m_hot_lines); 2026285Snate@binkert.org m_inst_profiler_ptr -> setAllInstructions(m_all_instructions); 2036285Snate@binkert.org } 2046285Snate@binkert.org} 2056285Snate@binkert.org 2066145Snate@binkert.orgvoid Profiler::wakeup() 2076145Snate@binkert.org{ 2086145Snate@binkert.org // FIXME - avoid the repeated code 2096145Snate@binkert.org 2106145Snate@binkert.org Vector<integer_t> perProcInstructionCount; 2116285Snate@binkert.org perProcInstructionCount.setSize(RubySystem::getNumberOfSequencers()); 2126145Snate@binkert.org 2136145Snate@binkert.org Vector<integer_t> perProcCycleCount; 2146285Snate@binkert.org perProcCycleCount.setSize(RubySystem::getNumberOfSequencers()); 2156145Snate@binkert.org 2166285Snate@binkert.org for(int i=0; i < RubySystem::getNumberOfSequencers(); i++) { 2176285Snate@binkert.org perProcInstructionCount[i] = g_system_ptr->getInstructionCount(i) - m_instructions_executed_at_start[i] + 1; 2186285Snate@binkert.org perProcCycleCount[i] = g_system_ptr->getCycleCount(i) - m_cycles_executed_at_start[i] + 1; 2196145Snate@binkert.org // The +1 allows us to avoid division by zero 2206145Snate@binkert.org } 2216145Snate@binkert.org 2226145Snate@binkert.org integer_t total_misses = m_perProcTotalMisses.sum(); 2236145Snate@binkert.org integer_t instruction_executed = perProcInstructionCount.sum(); 2246285Snate@binkert.org integer_t simics_cycles_executed = perProcCycleCount.sum(); 2256145Snate@binkert.org integer_t transactions_started = m_perProcStartTransaction.sum(); 2266145Snate@binkert.org integer_t transactions_ended = m_perProcEndTransaction.sum(); 2276145Snate@binkert.org 2286145Snate@binkert.org (*m_periodic_output_file_ptr) << "ruby_cycles: " << g_eventQueue_ptr->getTime()-m_ruby_start << endl; 2296145Snate@binkert.org (*m_periodic_output_file_ptr) << "total_misses: " << total_misses << " " << m_perProcTotalMisses << endl; 2306145Snate@binkert.org (*m_periodic_output_file_ptr) << "instruction_executed: " << instruction_executed << " " << perProcInstructionCount << endl; 2316285Snate@binkert.org (*m_periodic_output_file_ptr) << "simics_cycles_executed: " << simics_cycles_executed << " " << perProcCycleCount << endl; 2326145Snate@binkert.org (*m_periodic_output_file_ptr) << "transactions_started: " << transactions_started << " " << m_perProcStartTransaction << endl; 2336145Snate@binkert.org (*m_periodic_output_file_ptr) << "transactions_ended: " << transactions_ended << " " << m_perProcEndTransaction << endl; 2346145Snate@binkert.org (*m_periodic_output_file_ptr) << "L1TBE_usage: " << m_L1tbeProfile << endl; 2356145Snate@binkert.org (*m_periodic_output_file_ptr) << "L2TBE_usage: " << m_L2tbeProfile << endl; 2366145Snate@binkert.org (*m_periodic_output_file_ptr) << "mbytes_resident: " << process_memory_resident() << endl; 2376145Snate@binkert.org (*m_periodic_output_file_ptr) << "mbytes_total: " << process_memory_total() << endl; 2386145Snate@binkert.org if (process_memory_total() > 0) { 2396145Snate@binkert.org (*m_periodic_output_file_ptr) << "resident_ratio: " << process_memory_resident()/process_memory_total() << endl; 2406145Snate@binkert.org } 2416145Snate@binkert.org (*m_periodic_output_file_ptr) << "miss_latency: " << m_allMissLatencyHistogram << endl; 2426145Snate@binkert.org 2436145Snate@binkert.org *m_periodic_output_file_ptr << endl; 2446145Snate@binkert.org 2456285Snate@binkert.org if (m_all_instructions) { 2466145Snate@binkert.org m_inst_profiler_ptr->printStats(*m_periodic_output_file_ptr); 2476145Snate@binkert.org } 2486145Snate@binkert.org 2496145Snate@binkert.org //g_system_ptr->getNetwork()->printStats(*m_periodic_output_file_ptr); 2506145Snate@binkert.org g_eventQueue_ptr->scheduleEvent(this, m_stats_period); 2516145Snate@binkert.org} 2526145Snate@binkert.org 2536145Snate@binkert.orgvoid Profiler::setPeriodicStatsFile(const string& filename) 2546145Snate@binkert.org{ 2556145Snate@binkert.org cout << "Recording periodic statistics to file '" << filename << "' every " 2566145Snate@binkert.org << m_stats_period << " Ruby cycles" << endl; 2576145Snate@binkert.org 2586145Snate@binkert.org if (m_periodic_output_file_ptr != &cerr) { 2596145Snate@binkert.org delete m_periodic_output_file_ptr; 2606145Snate@binkert.org } 2616145Snate@binkert.org 2626145Snate@binkert.org m_periodic_output_file_ptr = new ofstream(filename.c_str()); 2636145Snate@binkert.org g_eventQueue_ptr->scheduleEvent(this, 1); 2646145Snate@binkert.org} 2656145Snate@binkert.org 2666145Snate@binkert.orgvoid Profiler::setPeriodicStatsInterval(integer_t period) 2676145Snate@binkert.org{ 2686145Snate@binkert.org cout << "Recording periodic statistics every " << m_stats_period << " Ruby cycles" << endl; 2696145Snate@binkert.org m_stats_period = period; 2706145Snate@binkert.org g_eventQueue_ptr->scheduleEvent(this, 1); 2716145Snate@binkert.org} 2726145Snate@binkert.org 2736145Snate@binkert.orgvoid Profiler::printConfig(ostream& out) const 2746145Snate@binkert.org{ 2756145Snate@binkert.org out << endl; 2766145Snate@binkert.org out << "Profiler Configuration" << endl; 2776145Snate@binkert.org out << "----------------------" << endl; 2786145Snate@binkert.org out << "periodic_stats_period: " << m_stats_period << endl; 2796145Snate@binkert.org} 2806145Snate@binkert.org 2816145Snate@binkert.orgvoid Profiler::print(ostream& out) const 2826145Snate@binkert.org{ 2836145Snate@binkert.org out << "[Profiler]"; 2846145Snate@binkert.org} 2856145Snate@binkert.org 2866145Snate@binkert.orgvoid Profiler::printStats(ostream& out, bool short_stats) 2876145Snate@binkert.org{ 2886145Snate@binkert.org out << endl; 2896145Snate@binkert.org if (short_stats) { 2906145Snate@binkert.org out << "SHORT "; 2916145Snate@binkert.org } 2926145Snate@binkert.org out << "Profiler Stats" << endl; 2936145Snate@binkert.org out << "--------------" << endl; 2946145Snate@binkert.org 2956145Snate@binkert.org time_t real_time_current = time(NULL); 2966145Snate@binkert.org double seconds = difftime(real_time_current, m_real_time_start_time); 2976145Snate@binkert.org double minutes = seconds/60.0; 2986145Snate@binkert.org double hours = minutes/60.0; 2996145Snate@binkert.org double days = hours/24.0; 3006145Snate@binkert.org Time ruby_cycles = g_eventQueue_ptr->getTime()-m_ruby_start; 3016145Snate@binkert.org 3026145Snate@binkert.org if (!short_stats) { 3036145Snate@binkert.org out << "Elapsed_time_in_seconds: " << seconds << endl; 3046145Snate@binkert.org out << "Elapsed_time_in_minutes: " << minutes << endl; 3056145Snate@binkert.org out << "Elapsed_time_in_hours: " << hours << endl; 3066145Snate@binkert.org out << "Elapsed_time_in_days: " << days << endl; 3076145Snate@binkert.org out << endl; 3086145Snate@binkert.org } 3096145Snate@binkert.org 3106145Snate@binkert.org // print the virtual runtimes as well 3116145Snate@binkert.org struct tms vtime; 3126145Snate@binkert.org times(&vtime); 3136145Snate@binkert.org seconds = (vtime.tms_utime + vtime.tms_stime) / 100.0; 3146145Snate@binkert.org minutes = seconds / 60.0; 3156145Snate@binkert.org hours = minutes / 60.0; 3166145Snate@binkert.org days = hours / 24.0; 3176145Snate@binkert.org out << "Virtual_time_in_seconds: " << seconds << endl; 3186145Snate@binkert.org out << "Virtual_time_in_minutes: " << minutes << endl; 3196145Snate@binkert.org out << "Virtual_time_in_hours: " << hours << endl; 3206145Snate@binkert.org out << "Virtual_time_in_days: " << hours << endl; 3216145Snate@binkert.org out << endl; 3226145Snate@binkert.org 3236145Snate@binkert.org out << "Ruby_current_time: " << g_eventQueue_ptr->getTime() << endl; 3246145Snate@binkert.org out << "Ruby_start_time: " << m_ruby_start << endl; 3256145Snate@binkert.org out << "Ruby_cycles: " << ruby_cycles << endl; 3266145Snate@binkert.org out << endl; 3276145Snate@binkert.org 3286145Snate@binkert.org if (!short_stats) { 3296145Snate@binkert.org out << "mbytes_resident: " << process_memory_resident() << endl; 3306145Snate@binkert.org out << "mbytes_total: " << process_memory_total() << endl; 3316145Snate@binkert.org if (process_memory_total() > 0) { 3326145Snate@binkert.org out << "resident_ratio: " << process_memory_resident()/process_memory_total() << endl; 3336145Snate@binkert.org } 3346145Snate@binkert.org out << endl; 3356145Snate@binkert.org 3366145Snate@binkert.org if(m_num_BA_broadcasts + m_num_BA_unicasts != 0){ 3376145Snate@binkert.org out << endl; 3386145Snate@binkert.org out << "Broadcast_percent: " << (float)m_num_BA_broadcasts/(m_num_BA_broadcasts+m_num_BA_unicasts) << endl; 3396145Snate@binkert.org } 3406145Snate@binkert.org } 3416145Snate@binkert.org 3426145Snate@binkert.org Vector<integer_t> perProcInstructionCount; 3436145Snate@binkert.org Vector<integer_t> perProcCycleCount; 3446145Snate@binkert.org Vector<double> perProcCPI; 3456145Snate@binkert.org Vector<double> perProcMissesPerInsn; 3466145Snate@binkert.org Vector<double> perProcInsnPerTrans; 3476145Snate@binkert.org Vector<double> perProcCyclesPerTrans; 3486145Snate@binkert.org Vector<double> perProcMissesPerTrans; 3496145Snate@binkert.org 3506285Snate@binkert.org perProcInstructionCount.setSize(RubySystem::getNumberOfSequencers()); 3516285Snate@binkert.org perProcCycleCount.setSize(RubySystem::getNumberOfSequencers()); 3526285Snate@binkert.org perProcCPI.setSize(RubySystem::getNumberOfSequencers()); 3536285Snate@binkert.org perProcMissesPerInsn.setSize(RubySystem::getNumberOfSequencers()); 3546145Snate@binkert.org 3556285Snate@binkert.org perProcInsnPerTrans.setSize(RubySystem::getNumberOfSequencers()); 3566285Snate@binkert.org perProcCyclesPerTrans.setSize(RubySystem::getNumberOfSequencers()); 3576285Snate@binkert.org perProcMissesPerTrans.setSize(RubySystem::getNumberOfSequencers()); 3586145Snate@binkert.org 3596285Snate@binkert.org for(int i=0; i < RubySystem::getNumberOfSequencers(); i++) { 3606285Snate@binkert.org perProcInstructionCount[i] = g_system_ptr->getInstructionCount(i) - m_instructions_executed_at_start[i] + 1; 3616285Snate@binkert.org perProcCycleCount[i] = g_system_ptr->getCycleCount(i) - m_cycles_executed_at_start[i] + 1; 3626145Snate@binkert.org // The +1 allows us to avoid division by zero 3636145Snate@binkert.org perProcCPI[i] = double(ruby_cycles)/perProcInstructionCount[i]; 3646145Snate@binkert.org perProcMissesPerInsn[i] = 1000.0 * (double(m_perProcTotalMisses[i]) / double(perProcInstructionCount[i])); 3656145Snate@binkert.org 3666145Snate@binkert.org int trans = m_perProcEndTransaction[i]; 3676145Snate@binkert.org if (trans == 0) { 3686145Snate@binkert.org perProcInsnPerTrans[i] = 0; 3696145Snate@binkert.org perProcCyclesPerTrans[i] = 0; 3706145Snate@binkert.org perProcMissesPerTrans[i] = 0; 3716145Snate@binkert.org } else { 3726145Snate@binkert.org perProcInsnPerTrans[i] = perProcInstructionCount[i] / double(trans); 3736145Snate@binkert.org perProcCyclesPerTrans[i] = ruby_cycles / double(trans); 3746145Snate@binkert.org perProcMissesPerTrans[i] = m_perProcTotalMisses[i] / double(trans); 3756145Snate@binkert.org } 3766145Snate@binkert.org } 3776145Snate@binkert.org 3786145Snate@binkert.org integer_t total_misses = m_perProcTotalMisses.sum(); 3796145Snate@binkert.org integer_t user_misses = m_perProcUserMisses.sum(); 3806145Snate@binkert.org integer_t supervisor_misses = m_perProcSupervisorMisses.sum(); 3816145Snate@binkert.org integer_t instruction_executed = perProcInstructionCount.sum(); 3826285Snate@binkert.org integer_t simics_cycles_executed = perProcCycleCount.sum(); 3836145Snate@binkert.org integer_t transactions_started = m_perProcStartTransaction.sum(); 3846145Snate@binkert.org integer_t transactions_ended = m_perProcEndTransaction.sum(); 3856145Snate@binkert.org 3866145Snate@binkert.org double instructions_per_transaction = (transactions_ended != 0) ? double(instruction_executed) / double(transactions_ended) : 0; 3876285Snate@binkert.org double cycles_per_transaction = (transactions_ended != 0) ? (RubySystem::getNumberOfSequencers() * double(ruby_cycles)) / double(transactions_ended) : 0; 3886145Snate@binkert.org double misses_per_transaction = (transactions_ended != 0) ? double(total_misses) / double(transactions_ended) : 0; 3896145Snate@binkert.org 3906145Snate@binkert.org out << "Total_misses: " << total_misses << endl; 3916145Snate@binkert.org out << "total_misses: " << total_misses << " " << m_perProcTotalMisses << endl; 3926145Snate@binkert.org out << "user_misses: " << user_misses << " " << m_perProcUserMisses << endl; 3936145Snate@binkert.org out << "supervisor_misses: " << supervisor_misses << " " << m_perProcSupervisorMisses << endl; 3946145Snate@binkert.org out << endl; 3956145Snate@binkert.org out << "instruction_executed: " << instruction_executed << " " << perProcInstructionCount << endl; 3966285Snate@binkert.org out << "ruby_cycles_executed: " << simics_cycles_executed << " " << perProcCycleCount << endl; 3976285Snate@binkert.org out << "cycles_per_instruction: " << (RubySystem::getNumberOfSequencers()*double(ruby_cycles))/double(instruction_executed) << " " << perProcCPI << endl; 3986145Snate@binkert.org out << "misses_per_thousand_instructions: " << 1000.0 * (double(total_misses) / double(instruction_executed)) << " " << perProcMissesPerInsn << endl; 3996145Snate@binkert.org out << endl; 4006145Snate@binkert.org out << "transactions_started: " << transactions_started << " " << m_perProcStartTransaction << endl; 4016145Snate@binkert.org out << "transactions_ended: " << transactions_ended << " " << m_perProcEndTransaction << endl; 4026145Snate@binkert.org out << "instructions_per_transaction: " << instructions_per_transaction << " " << perProcInsnPerTrans << endl; 4036145Snate@binkert.org out << "cycles_per_transaction: " << cycles_per_transaction << " " << perProcCyclesPerTrans << endl; 4046145Snate@binkert.org out << "misses_per_transaction: " << misses_per_transaction << " " << perProcMissesPerTrans << endl; 4056145Snate@binkert.org 4066145Snate@binkert.org out << endl; 4076145Snate@binkert.org 4086145Snate@binkert.org m_L1D_cache_profiler_ptr->printStats(out); 4096145Snate@binkert.org m_L1I_cache_profiler_ptr->printStats(out); 4106145Snate@binkert.org m_L2_cache_profiler_ptr->printStats(out); 4116145Snate@binkert.org 4126145Snate@binkert.org out << endl; 4136145Snate@binkert.org 4146285Snate@binkert.org vector<string>::iterator it; 4156285Snate@binkert.org 4166285Snate@binkert.org for ( it=m_memory_control_names.begin() ; it < m_memory_control_names.end(); it++ ){ 4176285Snate@binkert.org long long int m_memReq = m_memory_control_profilers[(*it).c_str()] -> m_memReq; 4186285Snate@binkert.org long long int m_memRefresh = m_memory_control_profilers[(*it).c_str()] -> m_memRefresh; 4196285Snate@binkert.org long long int m_memInputQ = m_memory_control_profilers[(*it).c_str()] -> m_memInputQ; 4206285Snate@binkert.org long long int m_memBankQ = m_memory_control_profilers[(*it).c_str()] -> m_memBankQ; 4216285Snate@binkert.org long long int m_memWaitCycles = m_memory_control_profilers[(*it).c_str()] -> m_memWaitCycles; 4226285Snate@binkert.org long long int m_memRead = m_memory_control_profilers[(*it).c_str()] -> m_memRead; 4236285Snate@binkert.org long long int m_memWrite = m_memory_control_profilers[(*it).c_str()] -> m_memWrite; 4246285Snate@binkert.org long long int m_memBankBusy = m_memory_control_profilers[(*it).c_str()] -> m_memBankBusy; 4256285Snate@binkert.org long long int m_memRandBusy = m_memory_control_profilers[(*it).c_str()] -> m_memRandBusy; 4266285Snate@binkert.org long long int m_memNotOld = m_memory_control_profilers[(*it).c_str()] -> m_memNotOld; 4276285Snate@binkert.org long long int m_memArbWait = m_memory_control_profilers[(*it).c_str()] -> m_memArbWait; 4286285Snate@binkert.org long long int m_memBusBusy = m_memory_control_profilers[(*it).c_str()] -> m_memBusBusy; 4296285Snate@binkert.org long long int m_memTfawBusy = m_memory_control_profilers[(*it).c_str()] -> m_memTfawBusy; 4306285Snate@binkert.org long long int m_memReadWriteBusy = m_memory_control_profilers[(*it).c_str()] -> m_memReadWriteBusy; 4316285Snate@binkert.org long long int m_memDataBusBusy = m_memory_control_profilers[(*it).c_str()] -> m_memDataBusBusy; 4326285Snate@binkert.org Vector<long long int> m_memBankCount = m_memory_control_profilers[(*it).c_str()] -> m_memBankCount; 4336285Snate@binkert.org 4346285Snate@binkert.org if (m_memReq || m_memRefresh) { // if there's a memory controller at all 4356285Snate@binkert.org long long int total_stalls = m_memInputQ + m_memBankQ + m_memWaitCycles; 4366285Snate@binkert.org double stallsPerReq = total_stalls * 1.0 / m_memReq; 4376285Snate@binkert.org out << "Memory control:" << endl; 4386285Snate@binkert.org out << " memory_total_requests: " << m_memReq << endl; // does not include refreshes 4396285Snate@binkert.org out << " memory_reads: " << m_memRead << endl; 4406285Snate@binkert.org out << " memory_writes: " << m_memWrite << endl; 4416285Snate@binkert.org out << " memory_refreshes: " << m_memRefresh << endl; 4426285Snate@binkert.org out << " memory_total_request_delays: " << total_stalls << endl; 4436285Snate@binkert.org out << " memory_delays_per_request: " << stallsPerReq << endl; 4446285Snate@binkert.org out << " memory_delays_in_input_queue: " << m_memInputQ << endl; 4456285Snate@binkert.org out << " memory_delays_behind_head_of_bank_queue: " << m_memBankQ << endl; 4466285Snate@binkert.org out << " memory_delays_stalled_at_head_of_bank_queue: " << m_memWaitCycles << endl; 4476285Snate@binkert.org // Note: The following "memory stalls" entries are a breakdown of the 4486285Snate@binkert.org // cycles which already showed up in m_memWaitCycles. The order is 4496285Snate@binkert.org // significant; it is the priority of attributing the cycles. 4506285Snate@binkert.org // For example, bank_busy is before arbitration because if the bank was 4516285Snate@binkert.org // busy, we didn't even check arbitration. 4526285Snate@binkert.org // Note: "not old enough" means that since we grouped waiting heads-of-queues 4536285Snate@binkert.org // into batches to avoid starvation, a request in a newer batch 4546285Snate@binkert.org // didn't try to arbitrate yet because there are older requests waiting. 4556285Snate@binkert.org out << " memory_stalls_for_bank_busy: " << m_memBankBusy << endl; 4566285Snate@binkert.org out << " memory_stalls_for_random_busy: " << m_memRandBusy << endl; 4576285Snate@binkert.org out << " memory_stalls_for_anti_starvation: " << m_memNotOld << endl; 4586285Snate@binkert.org out << " memory_stalls_for_arbitration: " << m_memArbWait << endl; 4596285Snate@binkert.org out << " memory_stalls_for_bus: " << m_memBusBusy << endl; 4606285Snate@binkert.org out << " memory_stalls_for_tfaw: " << m_memTfawBusy << endl; 4616285Snate@binkert.org out << " memory_stalls_for_read_write_turnaround: " << m_memReadWriteBusy << endl; 4626285Snate@binkert.org out << " memory_stalls_for_read_read_turnaround: " << m_memDataBusBusy << endl; 4636285Snate@binkert.org out << " accesses_per_bank: "; 4646285Snate@binkert.org for (int bank=0; bank < m_memBankCount.size(); bank++) { 4656285Snate@binkert.org out << m_memBankCount[bank] << " "; 4666285Snate@binkert.org //if ((bank % 8) == 7) out << " " << endl; 4676285Snate@binkert.org } 4686285Snate@binkert.org out << endl; 4696285Snate@binkert.org out << endl; 4706145Snate@binkert.org } 4716145Snate@binkert.org } 4726145Snate@binkert.org if (!short_stats) { 4736145Snate@binkert.org out << "Busy Controller Counts:" << endl; 4746145Snate@binkert.org for(int i=0; i < MachineType_NUM; i++) { 4756145Snate@binkert.org for(int j=0; j < MachineType_base_count((MachineType)i); j++) { 4766145Snate@binkert.org MachineID machID; 4776145Snate@binkert.org machID.type = (MachineType)i; 4786145Snate@binkert.org machID.num = j; 4796145Snate@binkert.org out << machID << ":" << m_busyControllerCount[i][j] << " "; 4806145Snate@binkert.org if ((j+1)%8 == 0) { 4816145Snate@binkert.org out << endl; 4826145Snate@binkert.org } 4836145Snate@binkert.org } 4846145Snate@binkert.org out << endl; 4856145Snate@binkert.org } 4866145Snate@binkert.org out << endl; 4876145Snate@binkert.org 4886145Snate@binkert.org out << "Busy Bank Count:" << m_busyBankCount << endl; 4896145Snate@binkert.org out << endl; 4906145Snate@binkert.org 4916145Snate@binkert.org out << "L1TBE_usage: " << m_L1tbeProfile << endl; 4926145Snate@binkert.org out << "L2TBE_usage: " << m_L2tbeProfile << endl; 4936145Snate@binkert.org out << "StopTable_usage: " << m_stopTableProfile << endl; 4946145Snate@binkert.org out << "sequencer_requests_outstanding: " << m_sequencer_requests << endl; 4956145Snate@binkert.org out << "store_buffer_size: " << m_store_buffer_size << endl; 4966145Snate@binkert.org out << "unique_blocks_in_store_buffer: " << m_store_buffer_blocks << endl; 4976145Snate@binkert.org out << endl; 4986145Snate@binkert.org } 4996145Snate@binkert.org 5006145Snate@binkert.org if (!short_stats) { 5016145Snate@binkert.org out << "All Non-Zero Cycle Demand Cache Accesses" << endl; 5026145Snate@binkert.org out << "----------------------------------------" << endl; 5036145Snate@binkert.org out << "miss_latency: " << m_allMissLatencyHistogram << endl; 5046145Snate@binkert.org for(int i=0; i<m_missLatencyHistograms.size(); i++) { 5056145Snate@binkert.org if (m_missLatencyHistograms[i].size() > 0) { 5066285Snate@binkert.org out << "miss_latency_" << RubyRequestType(i) << ": " << m_missLatencyHistograms[i] << endl; 5076145Snate@binkert.org } 5086145Snate@binkert.org } 5096145Snate@binkert.org for(int i=0; i<m_machLatencyHistograms.size(); i++) { 5106145Snate@binkert.org if (m_machLatencyHistograms[i].size() > 0) { 5116145Snate@binkert.org out << "miss_latency_" << GenericMachineType(i) << ": " << m_machLatencyHistograms[i] << endl; 5126145Snate@binkert.org } 5136145Snate@binkert.org } 5146145Snate@binkert.org out << "miss_latency_L2Miss: " << m_L2MissLatencyHistogram << endl; 5156145Snate@binkert.org 5166145Snate@binkert.org out << endl; 5176145Snate@binkert.org 5186145Snate@binkert.org out << "All Non-Zero Cycle SW Prefetch Requests" << endl; 5196145Snate@binkert.org out << "------------------------------------" << endl; 5206145Snate@binkert.org out << "prefetch_latency: " << m_allSWPrefetchLatencyHistogram << endl; 5216145Snate@binkert.org for(int i=0; i<m_SWPrefetchLatencyHistograms.size(); i++) { 5226145Snate@binkert.org if (m_SWPrefetchLatencyHistograms[i].size() > 0) { 5236145Snate@binkert.org out << "prefetch_latency_" << CacheRequestType(i) << ": " << m_SWPrefetchLatencyHistograms[i] << endl; 5246145Snate@binkert.org } 5256145Snate@binkert.org } 5266145Snate@binkert.org for(int i=0; i<m_SWPrefetchMachLatencyHistograms.size(); i++) { 5276145Snate@binkert.org if (m_SWPrefetchMachLatencyHistograms[i].size() > 0) { 5286145Snate@binkert.org out << "prefetch_latency_" << GenericMachineType(i) << ": " << m_SWPrefetchMachLatencyHistograms[i] << endl; 5296145Snate@binkert.org } 5306145Snate@binkert.org } 5316145Snate@binkert.org out << "prefetch_latency_L2Miss:" << m_SWPrefetchL2MissLatencyHistogram << endl; 5326145Snate@binkert.org 5336145Snate@binkert.org out << "multicast_retries: " << m_multicast_retry_histogram << endl; 5346145Snate@binkert.org out << "gets_mask_prediction_count: " << m_gets_mask_prediction << endl; 5356145Snate@binkert.org out << "getx_mask_prediction_count: " << m_getx_mask_prediction << endl; 5366145Snate@binkert.org out << "explicit_training_mask: " << m_explicit_training_mask << endl; 5376145Snate@binkert.org out << endl; 5386145Snate@binkert.org 5396145Snate@binkert.org if (m_all_sharing_histogram.size() > 0) { 5406145Snate@binkert.org out << "all_sharing: " << m_all_sharing_histogram << endl; 5416145Snate@binkert.org out << "read_sharing: " << m_read_sharing_histogram << endl; 5426145Snate@binkert.org out << "write_sharing: " << m_write_sharing_histogram << endl; 5436145Snate@binkert.org 5446145Snate@binkert.org out << "all_sharing_percent: "; m_all_sharing_histogram.printPercent(out); out << endl; 5456145Snate@binkert.org out << "read_sharing_percent: "; m_read_sharing_histogram.printPercent(out); out << endl; 5466145Snate@binkert.org out << "write_sharing_percent: "; m_write_sharing_histogram.printPercent(out); out << endl; 5476145Snate@binkert.org 5486145Snate@binkert.org int64 total_miss = m_cache_to_cache + m_memory_to_cache; 5496145Snate@binkert.org out << "all_misses: " << total_miss << endl; 5506145Snate@binkert.org out << "cache_to_cache_misses: " << m_cache_to_cache << endl; 5516145Snate@binkert.org out << "memory_to_cache_misses: " << m_memory_to_cache << endl; 5526145Snate@binkert.org out << "cache_to_cache_percent: " << 100.0 * (double(m_cache_to_cache) / double(total_miss)) << endl; 5536145Snate@binkert.org out << "memory_to_cache_percent: " << 100.0 * (double(m_memory_to_cache) / double(total_miss)) << endl; 5546145Snate@binkert.org out << endl; 5556145Snate@binkert.org } 5566145Snate@binkert.org 5576145Snate@binkert.org if (m_conflicting_histogram.size() > 0) { 5586145Snate@binkert.org out << "conflicting_histogram: " << m_conflicting_histogram << endl; 5596145Snate@binkert.org out << "conflicting_histogram_percent: "; m_conflicting_histogram.printPercent(out); out << endl; 5606145Snate@binkert.org out << endl; 5616145Snate@binkert.org } 5626145Snate@binkert.org 5636145Snate@binkert.org if (m_outstanding_requests.size() > 0) { 5646145Snate@binkert.org out << "outstanding_requests: "; m_outstanding_requests.printPercent(out); out << endl; 5656145Snate@binkert.org if (m_outstanding_persistent_requests.size() > 0) { 5666145Snate@binkert.org out << "outstanding_persistent_requests: "; m_outstanding_persistent_requests.printPercent(out); out << endl; 5676145Snate@binkert.org } 5686145Snate@binkert.org out << endl; 5696145Snate@binkert.org } 5706145Snate@binkert.org } 5716145Snate@binkert.org 5726145Snate@binkert.org if (!short_stats) { 5736148Ssanchezd@stanford.edu out << "Request vs. RubySystem State Profile" << endl; 5746145Snate@binkert.org out << "--------------------------------" << endl; 5756145Snate@binkert.org out << endl; 5766145Snate@binkert.org 5776145Snate@binkert.org Vector<string> requestProfileKeys = m_requestProfileMap_ptr->keys(); 5786145Snate@binkert.org requestProfileKeys.sortVector(); 5796145Snate@binkert.org 5806145Snate@binkert.org for(int i=0; i<requestProfileKeys.size(); i++) { 5816145Snate@binkert.org int temp_int = m_requestProfileMap_ptr->lookup(requestProfileKeys[i]); 5826145Snate@binkert.org double percent = (100.0*double(temp_int))/double(m_requests); 5836145Snate@binkert.org while (requestProfileKeys[i] != "") { 5846145Snate@binkert.org out << setw(10) << string_split(requestProfileKeys[i], ':'); 5856145Snate@binkert.org } 5866145Snate@binkert.org out << setw(11) << temp_int; 5876145Snate@binkert.org out << setw(14) << percent << endl; 5886145Snate@binkert.org } 5896145Snate@binkert.org out << endl; 5906145Snate@binkert.org 5916145Snate@binkert.org out << "filter_action: " << m_filter_action_histogram << endl; 5926145Snate@binkert.org 5936285Snate@binkert.org if (!m_all_instructions) { 5946145Snate@binkert.org m_address_profiler_ptr->printStats(out); 5956145Snate@binkert.org } 5966145Snate@binkert.org 5976285Snate@binkert.org if (m_all_instructions) { 5986145Snate@binkert.org m_inst_profiler_ptr->printStats(out); 5996145Snate@binkert.org } 6006145Snate@binkert.org 6016145Snate@binkert.org out << endl; 6026145Snate@binkert.org out << "Message Delayed Cycles" << endl; 6036145Snate@binkert.org out << "----------------------" << endl; 6046145Snate@binkert.org out << "Total_delay_cycles: " << m_delayedCyclesHistogram << endl; 6056145Snate@binkert.org out << "Total_nonPF_delay_cycles: " << m_delayedCyclesNonPFHistogram << endl; 6066145Snate@binkert.org for (int i = 0; i < m_delayedCyclesVCHistograms.size(); i++) { 6076145Snate@binkert.org out << " virtual_network_" << i << "_delay_cycles: " << m_delayedCyclesVCHistograms[i] << endl; 6086145Snate@binkert.org } 6096145Snate@binkert.org 6106145Snate@binkert.org printResourceUsage(out); 6116145Snate@binkert.org } 6126145Snate@binkert.org 6136145Snate@binkert.org} 6146145Snate@binkert.org 6156145Snate@binkert.orgvoid Profiler::printResourceUsage(ostream& out) const 6166145Snate@binkert.org{ 6176145Snate@binkert.org out << endl; 6186145Snate@binkert.org out << "Resource Usage" << endl; 6196145Snate@binkert.org out << "--------------" << endl; 6206145Snate@binkert.org 6216145Snate@binkert.org integer_t pagesize = getpagesize(); // page size in bytes 6226145Snate@binkert.org out << "page_size: " << pagesize << endl; 6236145Snate@binkert.org 6246145Snate@binkert.org rusage usage; 6256145Snate@binkert.org getrusage (RUSAGE_SELF, &usage); 6266145Snate@binkert.org 6276145Snate@binkert.org out << "user_time: " << usage.ru_utime.tv_sec << endl; 6286145Snate@binkert.org out << "system_time: " << usage.ru_stime.tv_sec << endl; 6296145Snate@binkert.org out << "page_reclaims: " << usage.ru_minflt << endl; 6306145Snate@binkert.org out << "page_faults: " << usage.ru_majflt << endl; 6316145Snate@binkert.org out << "swaps: " << usage.ru_nswap << endl; 6326145Snate@binkert.org out << "block_inputs: " << usage.ru_inblock << endl; 6336145Snate@binkert.org out << "block_outputs: " << usage.ru_oublock << endl; 6346145Snate@binkert.org} 6356145Snate@binkert.org 6366145Snate@binkert.orgvoid Profiler::clearStats() 6376145Snate@binkert.org{ 6386145Snate@binkert.org m_num_BA_unicasts = 0; 6396145Snate@binkert.org m_num_BA_broadcasts = 0; 6406145Snate@binkert.org 6416145Snate@binkert.org m_ruby_start = g_eventQueue_ptr->getTime(); 6426145Snate@binkert.org 6436285Snate@binkert.org m_instructions_executed_at_start.setSize(RubySystem::getNumberOfSequencers()); 6446285Snate@binkert.org m_cycles_executed_at_start.setSize(RubySystem::getNumberOfSequencers()); 6456285Snate@binkert.org for (int i=0; i < RubySystem::getNumberOfSequencers(); i++) { 6466145Snate@binkert.org if (g_system_ptr == NULL) { 6476145Snate@binkert.org m_instructions_executed_at_start[i] = 0; 6486145Snate@binkert.org m_cycles_executed_at_start[i] = 0; 6496145Snate@binkert.org } else { 6506285Snate@binkert.org m_instructions_executed_at_start[i] = g_system_ptr->getInstructionCount(i); 6516285Snate@binkert.org m_cycles_executed_at_start[i] = g_system_ptr->getCycleCount(i); 6526145Snate@binkert.org } 6536145Snate@binkert.org } 6546145Snate@binkert.org 6556285Snate@binkert.org m_perProcTotalMisses.setSize(RubySystem::getNumberOfSequencers()); 6566285Snate@binkert.org m_perProcUserMisses.setSize(RubySystem::getNumberOfSequencers()); 6576285Snate@binkert.org m_perProcSupervisorMisses.setSize(RubySystem::getNumberOfSequencers()); 6586285Snate@binkert.org m_perProcStartTransaction.setSize(RubySystem::getNumberOfSequencers()); 6596285Snate@binkert.org m_perProcEndTransaction.setSize(RubySystem::getNumberOfSequencers()); 6606145Snate@binkert.org 6616285Snate@binkert.org for(int i=0; i < RubySystem::getNumberOfSequencers(); i++) { 6626145Snate@binkert.org m_perProcTotalMisses[i] = 0; 6636145Snate@binkert.org m_perProcUserMisses[i] = 0; 6646145Snate@binkert.org m_perProcSupervisorMisses[i] = 0; 6656145Snate@binkert.org m_perProcStartTransaction[i] = 0; 6666145Snate@binkert.org m_perProcEndTransaction[i] = 0; 6676145Snate@binkert.org } 6686145Snate@binkert.org 6696145Snate@binkert.org m_busyControllerCount.setSize(MachineType_NUM); // all machines 6706145Snate@binkert.org for(int i=0; i < MachineType_NUM; i++) { 6716145Snate@binkert.org m_busyControllerCount[i].setSize(MachineType_base_count((MachineType)i)); 6726145Snate@binkert.org for(int j=0; j < MachineType_base_count((MachineType)i); j++) { 6736145Snate@binkert.org m_busyControllerCount[i][j] = 0; 6746145Snate@binkert.org } 6756145Snate@binkert.org } 6766145Snate@binkert.org m_busyBankCount = 0; 6776145Snate@binkert.org 6786145Snate@binkert.org m_delayedCyclesHistogram.clear(); 6796145Snate@binkert.org m_delayedCyclesNonPFHistogram.clear(); 6806285Snate@binkert.org m_delayedCyclesVCHistograms.setSize(RubySystem::getNetwork()->getNumberOfVirtualNetworks()); 6816285Snate@binkert.org for (int i = 0; i < RubySystem::getNetwork()->getNumberOfVirtualNetworks(); i++) { 6826145Snate@binkert.org m_delayedCyclesVCHistograms[i].clear(); 6836145Snate@binkert.org } 6846145Snate@binkert.org 6856145Snate@binkert.org m_gets_mask_prediction.clear(); 6866145Snate@binkert.org m_getx_mask_prediction.clear(); 6876145Snate@binkert.org m_explicit_training_mask.clear(); 6886145Snate@binkert.org 6896145Snate@binkert.org m_missLatencyHistograms.setSize(CacheRequestType_NUM); 6906145Snate@binkert.org for(int i=0; i<m_missLatencyHistograms.size(); i++) { 6916145Snate@binkert.org m_missLatencyHistograms[i].clear(200); 6926145Snate@binkert.org } 6936145Snate@binkert.org m_machLatencyHistograms.setSize(GenericMachineType_NUM+1); 6946145Snate@binkert.org for(int i=0; i<m_machLatencyHistograms.size(); i++) { 6956145Snate@binkert.org m_machLatencyHistograms[i].clear(200); 6966145Snate@binkert.org } 6976145Snate@binkert.org m_allMissLatencyHistogram.clear(200); 6986145Snate@binkert.org m_L2MissLatencyHistogram.clear(200); 6996145Snate@binkert.org 7006145Snate@binkert.org m_SWPrefetchLatencyHistograms.setSize(CacheRequestType_NUM); 7016145Snate@binkert.org for(int i=0; i<m_SWPrefetchLatencyHistograms.size(); i++) { 7026145Snate@binkert.org m_SWPrefetchLatencyHistograms[i].clear(200); 7036145Snate@binkert.org } 7046145Snate@binkert.org m_SWPrefetchMachLatencyHistograms.setSize(GenericMachineType_NUM+1); 7056145Snate@binkert.org for(int i=0; i<m_SWPrefetchMachLatencyHistograms.size(); i++) { 7066145Snate@binkert.org m_SWPrefetchMachLatencyHistograms[i].clear(200); 7076145Snate@binkert.org } 7086145Snate@binkert.org m_allSWPrefetchLatencyHistogram.clear(200); 7096145Snate@binkert.org m_SWPrefetchL2MissLatencyHistogram.clear(200); 7106145Snate@binkert.org 7116145Snate@binkert.org m_multicast_retry_histogram.clear(); 7126145Snate@binkert.org 7136145Snate@binkert.org m_L1tbeProfile.clear(); 7146145Snate@binkert.org m_L2tbeProfile.clear(); 7156145Snate@binkert.org m_stopTableProfile.clear(); 7166145Snate@binkert.org m_filter_action_histogram.clear(); 7176145Snate@binkert.org 7186145Snate@binkert.org m_sequencer_requests.clear(); 7196145Snate@binkert.org m_store_buffer_size.clear(); 7206145Snate@binkert.org m_store_buffer_blocks.clear(); 7216145Snate@binkert.org m_read_sharing_histogram.clear(); 7226145Snate@binkert.org m_write_sharing_histogram.clear(); 7236145Snate@binkert.org m_all_sharing_histogram.clear(); 7246145Snate@binkert.org m_cache_to_cache = 0; 7256145Snate@binkert.org m_memory_to_cache = 0; 7266145Snate@binkert.org 7276145Snate@binkert.org m_predictions = 0; 7286145Snate@binkert.org m_predictionOpportunities = 0; 7296145Snate@binkert.org m_goodPredictions = 0; 7306145Snate@binkert.org 7316145Snate@binkert.org // clear HashMaps 7326145Snate@binkert.org m_requestProfileMap_ptr->clear(); 7336145Snate@binkert.org 7346145Snate@binkert.org // count requests profiled 7356145Snate@binkert.org m_requests = 0; 7366145Snate@binkert.org 7376145Snate@binkert.org // Conflicting requests 7386145Snate@binkert.org m_conflicting_map_ptr->clear(); 7396145Snate@binkert.org m_conflicting_histogram.clear(); 7406145Snate@binkert.org 7416145Snate@binkert.org m_outstanding_requests.clear(); 7426145Snate@binkert.org m_outstanding_persistent_requests.clear(); 7436145Snate@binkert.org 7446145Snate@binkert.org m_L1D_cache_profiler_ptr->clearStats(); 7456145Snate@binkert.org m_L1I_cache_profiler_ptr->clearStats(); 7466145Snate@binkert.org m_L2_cache_profiler_ptr->clearStats(); 7476145Snate@binkert.org 7486145Snate@binkert.org // for MemoryControl: 7496285Snate@binkert.org/* 7506145Snate@binkert.org m_memReq = 0; 7516145Snate@binkert.org m_memBankBusy = 0; 7526145Snate@binkert.org m_memBusBusy = 0; 7536145Snate@binkert.org m_memTfawBusy = 0; 7546145Snate@binkert.org m_memReadWriteBusy = 0; 7556145Snate@binkert.org m_memDataBusBusy = 0; 7566145Snate@binkert.org m_memRefresh = 0; 7576145Snate@binkert.org m_memRead = 0; 7586145Snate@binkert.org m_memWrite = 0; 7596145Snate@binkert.org m_memWaitCycles = 0; 7606145Snate@binkert.org m_memInputQ = 0; 7616145Snate@binkert.org m_memBankQ = 0; 7626145Snate@binkert.org m_memArbWait = 0; 7636145Snate@binkert.org m_memRandBusy = 0; 7646145Snate@binkert.org m_memNotOld = 0; 7656145Snate@binkert.org 7666145Snate@binkert.org for (int bank=0; bank < m_memBankCount.size(); bank++) { 7676145Snate@binkert.org m_memBankCount[bank] = 0; 7686145Snate@binkert.org } 7696285Snate@binkert.org*/ 7706285Snate@binkert.org//added by SS 7716285Snate@binkert.org vector<string>::iterator it; 7726145Snate@binkert.org 7736285Snate@binkert.org for ( it=m_memory_control_names.begin() ; it < m_memory_control_names.end(); it++ ){ 7746285Snate@binkert.org m_memory_control_profilers[(*it).c_str()] -> m_memReq = 0; 7756285Snate@binkert.org m_memory_control_profilers[(*it).c_str()] -> m_memBankBusy = 0; 7766285Snate@binkert.org m_memory_control_profilers[(*it).c_str()] -> m_memBusBusy = 0; 7776285Snate@binkert.org m_memory_control_profilers[(*it).c_str()] -> m_memTfawBusy = 0; 7786285Snate@binkert.org m_memory_control_profilers[(*it).c_str()] -> m_memReadWriteBusy = 0; 7796285Snate@binkert.org m_memory_control_profilers[(*it).c_str()] -> m_memDataBusBusy = 0; 7806285Snate@binkert.org m_memory_control_profilers[(*it).c_str()] -> m_memRefresh = 0; 7816285Snate@binkert.org m_memory_control_profilers[(*it).c_str()] -> m_memRead = 0; 7826285Snate@binkert.org m_memory_control_profilers[(*it).c_str()] -> m_memWrite = 0; 7836285Snate@binkert.org m_memory_control_profilers[(*it).c_str()] -> m_memWaitCycles = 0; 7846285Snate@binkert.org m_memory_control_profilers[(*it).c_str()] -> m_memInputQ = 0; 7856285Snate@binkert.org m_memory_control_profilers[(*it).c_str()] -> m_memBankQ = 0; 7866285Snate@binkert.org m_memory_control_profilers[(*it).c_str()] -> m_memArbWait = 0; 7876285Snate@binkert.org m_memory_control_profilers[(*it).c_str()] -> m_memRandBusy = 0; 7886285Snate@binkert.org m_memory_control_profilers[(*it).c_str()] -> m_memNotOld = 0; 7896285Snate@binkert.org 7906285Snate@binkert.org for (int bank=0; bank < m_memory_control_profilers[(*it).c_str()] -> m_memBankCount.size(); bank++) { 7916285Snate@binkert.org m_memory_control_profilers[(*it).c_str()] -> m_memBankCount[bank] = 0; 7926285Snate@binkert.org } 7936285Snate@binkert.org } 7946145Snate@binkert.org // Flush the prefetches through the system - used so that there are no outstanding requests after stats are cleared 7956145Snate@binkert.org //g_eventQueue_ptr->triggerAllEvents(); 7966145Snate@binkert.org 7976145Snate@binkert.org // update the start time 7986145Snate@binkert.org m_ruby_start = g_eventQueue_ptr->getTime(); 7996145Snate@binkert.org} 8006145Snate@binkert.org 8016145Snate@binkert.orgvoid Profiler::addPrimaryStatSample(const CacheMsg& msg, NodeID id) 8026145Snate@binkert.org{ 8036145Snate@binkert.org if (Protocol::m_TwoLevelCache) { 8046145Snate@binkert.org if (msg.getType() == CacheRequestType_IFETCH) { 8056145Snate@binkert.org addL1IStatSample(msg, id); 8066145Snate@binkert.org } else { 8076145Snate@binkert.org addL1DStatSample(msg, id); 8086145Snate@binkert.org } 8096145Snate@binkert.org // profile the address after an L1 miss (outside of the processor for CMP) 8106145Snate@binkert.org if (Protocol::m_CMP) { 8116145Snate@binkert.org addAddressTraceSample(msg, id); 8126145Snate@binkert.org } 8136145Snate@binkert.org } else { 8146145Snate@binkert.org addL2StatSample(CacheRequestType_to_GenericRequestType(msg.getType()), 8156145Snate@binkert.org msg.getAccessMode(), msg.getSize(), msg.getPrefetch(), id); 8166145Snate@binkert.org addAddressTraceSample(msg, id); 8176145Snate@binkert.org } 8186145Snate@binkert.org} 8196145Snate@binkert.org 8206145Snate@binkert.orgvoid Profiler::profileConflictingRequests(const Address& addr) 8216145Snate@binkert.org{ 8226145Snate@binkert.org assert(addr == line_address(addr)); 8236145Snate@binkert.org Time last_time = m_ruby_start; 8246145Snate@binkert.org if (m_conflicting_map_ptr->exist(addr)) { 8256285Snate@binkert.org Time last_time = m_conflicting_map_ptr->lookup(addr); 8266145Snate@binkert.org } 8276145Snate@binkert.org Time current_time = g_eventQueue_ptr->getTime(); 8286145Snate@binkert.org assert (current_time - last_time > 0); 8296145Snate@binkert.org m_conflicting_histogram.add(current_time - last_time); 8306145Snate@binkert.org m_conflicting_map_ptr->add(addr, current_time); 8316145Snate@binkert.org} 8326145Snate@binkert.org 8336145Snate@binkert.orgvoid Profiler::addSecondaryStatSample(CacheRequestType requestType, AccessModeType type, int msgSize, PrefetchBit pfBit, NodeID id) 8346145Snate@binkert.org{ 8356145Snate@binkert.org addSecondaryStatSample(CacheRequestType_to_GenericRequestType(requestType), type, msgSize, pfBit, id); 8366145Snate@binkert.org} 8376145Snate@binkert.org 8386145Snate@binkert.orgvoid Profiler::addSecondaryStatSample(GenericRequestType requestType, AccessModeType type, int msgSize, PrefetchBit pfBit, NodeID id) 8396145Snate@binkert.org{ 8406145Snate@binkert.org addL2StatSample(requestType, type, msgSize, pfBit, id); 8416145Snate@binkert.org} 8426145Snate@binkert.org 8436145Snate@binkert.orgvoid Profiler::addL2StatSample(GenericRequestType requestType, AccessModeType type, int msgSize, PrefetchBit pfBit, NodeID id) 8446145Snate@binkert.org{ 8456145Snate@binkert.org m_perProcTotalMisses[id]++; 8466145Snate@binkert.org if (type == AccessModeType_SupervisorMode) { 8476145Snate@binkert.org m_perProcSupervisorMisses[id]++; 8486145Snate@binkert.org } else { 8496145Snate@binkert.org m_perProcUserMisses[id]++; 8506145Snate@binkert.org } 8516145Snate@binkert.org m_L2_cache_profiler_ptr->addStatSample(requestType, type, msgSize, pfBit); 8526145Snate@binkert.org} 8536145Snate@binkert.org 8546145Snate@binkert.orgvoid Profiler::addL1DStatSample(const CacheMsg& msg, NodeID id) 8556145Snate@binkert.org{ 8566145Snate@binkert.org m_L1D_cache_profiler_ptr->addStatSample(CacheRequestType_to_GenericRequestType(msg.getType()), 8576145Snate@binkert.org msg.getAccessMode(), msg.getSize(), msg.getPrefetch()); 8586145Snate@binkert.org} 8596145Snate@binkert.org 8606145Snate@binkert.orgvoid Profiler::addL1IStatSample(const CacheMsg& msg, NodeID id) 8616145Snate@binkert.org{ 8626145Snate@binkert.org m_L1I_cache_profiler_ptr->addStatSample(CacheRequestType_to_GenericRequestType(msg.getType()), 8636145Snate@binkert.org msg.getAccessMode(), msg.getSize(), msg.getPrefetch()); 8646145Snate@binkert.org} 8656145Snate@binkert.org 8666145Snate@binkert.orgvoid Profiler::addAddressTraceSample(const CacheMsg& msg, NodeID id) 8676145Snate@binkert.org{ 8686145Snate@binkert.org if (msg.getType() != CacheRequestType_IFETCH) { 8696145Snate@binkert.org 8706145Snate@binkert.org // Note: The following line should be commented out if you want to 8716145Snate@binkert.org // use the special profiling that is part of the GS320 protocol 8726145Snate@binkert.org 8736285Snate@binkert.org // NOTE: Unless PROFILE_HOT_LINES or RubyConfig::getProfileAllInstructions() are enabled, nothing will be profiled by the AddressProfiler 8746285Snate@binkert.org m_address_profiler_ptr->addTraceSample(msg.getLineAddress(), msg.getProgramCounter(), msg.getType(), msg.getAccessMode(), id, false); 8756145Snate@binkert.org } 8766145Snate@binkert.org} 8776145Snate@binkert.org 8786145Snate@binkert.orgvoid Profiler::profileSharing(const Address& addr, AccessType type, NodeID requestor, const Set& sharers, const Set& owner) 8796145Snate@binkert.org{ 8806145Snate@binkert.org Set set_contacted(owner); 8816145Snate@binkert.org if (type == AccessType_Write) { 8826145Snate@binkert.org set_contacted.addSet(sharers); 8836145Snate@binkert.org } 8846145Snate@binkert.org set_contacted.remove(requestor); 8856145Snate@binkert.org int number_contacted = set_contacted.count(); 8866145Snate@binkert.org 8876145Snate@binkert.org if (type == AccessType_Write) { 8886145Snate@binkert.org m_write_sharing_histogram.add(number_contacted); 8896145Snate@binkert.org } else { 8906145Snate@binkert.org m_read_sharing_histogram.add(number_contacted); 8916145Snate@binkert.org } 8926145Snate@binkert.org m_all_sharing_histogram.add(number_contacted); 8936145Snate@binkert.org 8946145Snate@binkert.org if (number_contacted == 0) { 8956145Snate@binkert.org m_memory_to_cache++; 8966145Snate@binkert.org } else { 8976145Snate@binkert.org m_cache_to_cache++; 8986145Snate@binkert.org } 8996145Snate@binkert.org 9006145Snate@binkert.org} 9016145Snate@binkert.org 9026145Snate@binkert.orgvoid Profiler::profileMsgDelay(int virtualNetwork, int delayCycles) { 9036145Snate@binkert.org assert(virtualNetwork < m_delayedCyclesVCHistograms.size()); 9046145Snate@binkert.org m_delayedCyclesHistogram.add(delayCycles); 9056145Snate@binkert.org m_delayedCyclesVCHistograms[virtualNetwork].add(delayCycles); 9066145Snate@binkert.org if (virtualNetwork != 0) { 9076145Snate@binkert.org m_delayedCyclesNonPFHistogram.add(delayCycles); 9086145Snate@binkert.org } 9096145Snate@binkert.org} 9106145Snate@binkert.org 9116145Snate@binkert.org// profiles original cache requests including PUTs 9126145Snate@binkert.orgvoid Profiler::profileRequest(const string& requestStr) 9136145Snate@binkert.org{ 9146145Snate@binkert.org m_requests++; 9156145Snate@binkert.org 9166145Snate@binkert.org if (m_requestProfileMap_ptr->exist(requestStr)) { 9176145Snate@binkert.org (m_requestProfileMap_ptr->lookup(requestStr))++; 9186145Snate@binkert.org } else { 9196145Snate@binkert.org m_requestProfileMap_ptr->add(requestStr, 1); 9206145Snate@binkert.org } 9216145Snate@binkert.org} 9226145Snate@binkert.org 9236145Snate@binkert.orgvoid Profiler::recordPrediction(bool wasGood, bool wasPredicted) 9246145Snate@binkert.org{ 9256145Snate@binkert.org m_predictionOpportunities++; 9266145Snate@binkert.org if(wasPredicted){ 9276145Snate@binkert.org m_predictions++; 9286145Snate@binkert.org if(wasGood){ 9296145Snate@binkert.org m_goodPredictions++; 9306145Snate@binkert.org } 9316145Snate@binkert.org } 9326145Snate@binkert.org} 9336145Snate@binkert.org 9346145Snate@binkert.orgvoid Profiler::profileFilterAction(int action) 9356145Snate@binkert.org{ 9366145Snate@binkert.org m_filter_action_histogram.add(action); 9376145Snate@binkert.org} 9386145Snate@binkert.org 9396145Snate@binkert.orgvoid Profiler::profileMulticastRetry(const Address& addr, int count) 9406145Snate@binkert.org{ 9416145Snate@binkert.org m_multicast_retry_histogram.add(count); 9426145Snate@binkert.org} 9436145Snate@binkert.org 9446145Snate@binkert.orgvoid Profiler::startTransaction(int cpu) 9456145Snate@binkert.org{ 9466145Snate@binkert.org m_perProcStartTransaction[cpu]++; 9476145Snate@binkert.org} 9486145Snate@binkert.org 9496145Snate@binkert.orgvoid Profiler::endTransaction(int cpu) 9506145Snate@binkert.org{ 9516145Snate@binkert.org m_perProcEndTransaction[cpu]++; 9526145Snate@binkert.org} 9536145Snate@binkert.org 9546145Snate@binkert.orgvoid Profiler::controllerBusy(MachineID machID) 9556145Snate@binkert.org{ 9566145Snate@binkert.org m_busyControllerCount[(int)machID.type][(int)machID.num]++; 9576145Snate@binkert.org} 9586145Snate@binkert.org 9596145Snate@binkert.orgvoid Profiler::profilePFWait(Time waitTime) 9606145Snate@binkert.org{ 9616145Snate@binkert.org m_prefetchWaitHistogram.add(waitTime); 9626145Snate@binkert.org} 9636145Snate@binkert.org 9646145Snate@binkert.orgvoid Profiler::bankBusy() 9656145Snate@binkert.org{ 9666145Snate@binkert.org m_busyBankCount++; 9676145Snate@binkert.org} 9686145Snate@binkert.org 9696145Snate@binkert.org// non-zero cycle demand request 9706285Snate@binkert.orgvoid Profiler::missLatency(Time t, RubyRequestType type) 9716145Snate@binkert.org{ 9726145Snate@binkert.org m_allMissLatencyHistogram.add(t); 9736145Snate@binkert.org m_missLatencyHistograms[type].add(t); 9746285Snate@binkert.org /* 9756145Snate@binkert.org m_machLatencyHistograms[respondingMach].add(t); 9766145Snate@binkert.org if(respondingMach == GenericMachineType_Directory || respondingMach == GenericMachineType_NUM) { 9776145Snate@binkert.org m_L2MissLatencyHistogram.add(t); 9786145Snate@binkert.org } 9796285Snate@binkert.org */ 9806145Snate@binkert.org} 9816145Snate@binkert.org 9826145Snate@binkert.org// non-zero cycle prefetch request 9836145Snate@binkert.orgvoid Profiler::swPrefetchLatency(Time t, CacheRequestType type, GenericMachineType respondingMach) 9846145Snate@binkert.org{ 9856145Snate@binkert.org m_allSWPrefetchLatencyHistogram.add(t); 9866145Snate@binkert.org m_SWPrefetchLatencyHistograms[type].add(t); 9876145Snate@binkert.org m_SWPrefetchMachLatencyHistograms[respondingMach].add(t); 9886145Snate@binkert.org if(respondingMach == GenericMachineType_Directory || respondingMach == GenericMachineType_NUM) { 9896145Snate@binkert.org m_SWPrefetchL2MissLatencyHistogram.add(t); 9906145Snate@binkert.org } 9916145Snate@binkert.org} 9926145Snate@binkert.org 9936285Snate@binkert.orgvoid Profiler::profileTransition(const string& component, NodeID version, Address addr, 9946145Snate@binkert.org const string& state, const string& event, 9956145Snate@binkert.org const string& next_state, const string& note) 9966145Snate@binkert.org{ 9976145Snate@binkert.org const int EVENT_SPACES = 20; 9986145Snate@binkert.org const int ID_SPACES = 3; 9996145Snate@binkert.org const int TIME_SPACES = 7; 10006145Snate@binkert.org const int COMP_SPACES = 10; 10016145Snate@binkert.org const int STATE_SPACES = 6; 10026145Snate@binkert.org 10036145Snate@binkert.org if ((g_debug_ptr->getDebugTime() > 0) && 10046145Snate@binkert.org (g_eventQueue_ptr->getTime() >= g_debug_ptr->getDebugTime())) { 10056145Snate@binkert.org (* debug_cout_ptr).flags(ios::right); 10066145Snate@binkert.org (* debug_cout_ptr) << setw(TIME_SPACES) << g_eventQueue_ptr->getTime() << " "; 10076145Snate@binkert.org (* debug_cout_ptr) << setw(ID_SPACES) << version << " "; 10086145Snate@binkert.org (* debug_cout_ptr) << setw(COMP_SPACES) << component; 10096145Snate@binkert.org (* debug_cout_ptr) << setw(EVENT_SPACES) << event << " "; 10106145Snate@binkert.org 10116285Snate@binkert.org (* debug_cout_ptr).flags(ios::right); 10126285Snate@binkert.org (* debug_cout_ptr) << setw(STATE_SPACES) << state; 10136285Snate@binkert.org (* debug_cout_ptr) << ">"; 10146285Snate@binkert.org (* debug_cout_ptr).flags(ios::left); 10156285Snate@binkert.org (* debug_cout_ptr) << setw(STATE_SPACES) << next_state; 10166285Snate@binkert.org 10176145Snate@binkert.org (* debug_cout_ptr) << " " << addr << " " << note; 10186145Snate@binkert.org 10196145Snate@binkert.org (* debug_cout_ptr) << endl; 10206145Snate@binkert.org } 10216145Snate@binkert.org} 10226145Snate@binkert.org 10236145Snate@binkert.org// Helper function 10246145Snate@binkert.orgstatic double process_memory_total() 10256145Snate@binkert.org{ 10266145Snate@binkert.org const double MULTIPLIER = 4096.0/(1024.0*1024.0); // 4kB page size, 1024*1024 bytes per MB, 10276145Snate@binkert.org ifstream proc_file; 10286145Snate@binkert.org proc_file.open("/proc/self/statm"); 10296145Snate@binkert.org int total_size_in_pages = 0; 10306145Snate@binkert.org int res_size_in_pages = 0; 10316145Snate@binkert.org proc_file >> total_size_in_pages; 10326145Snate@binkert.org proc_file >> res_size_in_pages; 10336145Snate@binkert.org return double(total_size_in_pages)*MULTIPLIER; // size in megabytes 10346145Snate@binkert.org} 10356145Snate@binkert.org 10366145Snate@binkert.orgstatic double process_memory_resident() 10376145Snate@binkert.org{ 10386145Snate@binkert.org const double MULTIPLIER = 4096.0/(1024.0*1024.0); // 4kB page size, 1024*1024 bytes per MB, 10396145Snate@binkert.org ifstream proc_file; 10406145Snate@binkert.org proc_file.open("/proc/self/statm"); 10416145Snate@binkert.org int total_size_in_pages = 0; 10426145Snate@binkert.org int res_size_in_pages = 0; 10436145Snate@binkert.org proc_file >> total_size_in_pages; 10446145Snate@binkert.org proc_file >> res_size_in_pages; 10456145Snate@binkert.org return double(res_size_in_pages)*MULTIPLIER; // size in megabytes 10466145Snate@binkert.org} 10476145Snate@binkert.org 10486145Snate@binkert.orgvoid Profiler::profileGetXMaskPrediction(const Set& pred_set) 10496145Snate@binkert.org{ 10506145Snate@binkert.org m_getx_mask_prediction.add(pred_set.count()); 10516145Snate@binkert.org} 10526145Snate@binkert.org 10536145Snate@binkert.orgvoid Profiler::profileGetSMaskPrediction(const Set& pred_set) 10546145Snate@binkert.org{ 10556145Snate@binkert.org m_gets_mask_prediction.add(pred_set.count()); 10566145Snate@binkert.org} 10576145Snate@binkert.org 10586145Snate@binkert.orgvoid Profiler::profileTrainingMask(const Set& pred_set) 10596145Snate@binkert.org{ 10606145Snate@binkert.org m_explicit_training_mask.add(pred_set.count()); 10616145Snate@binkert.org} 10626145Snate@binkert.org 10636145Snate@binkert.orgint64 Profiler::getTotalInstructionsExecuted() const 10646145Snate@binkert.org{ 10656145Snate@binkert.org int64 sum = 1; // Starting at 1 allows us to avoid division by zero 10666285Snate@binkert.org for(int i=0; i < RubySystem::getNumberOfSequencers(); i++) { 10676285Snate@binkert.org sum += (g_system_ptr->getInstructionCount(i) - m_instructions_executed_at_start[i]); 10686145Snate@binkert.org } 10696145Snate@binkert.org return sum; 10706145Snate@binkert.org} 10716145Snate@binkert.org 10726145Snate@binkert.orgint64 Profiler::getTotalTransactionsExecuted() const 10736145Snate@binkert.org{ 10746145Snate@binkert.org int64 sum = m_perProcEndTransaction.sum(); 10756145Snate@binkert.org if (sum > 0) { 10766145Snate@binkert.org return sum; 10776145Snate@binkert.org } else { 10786145Snate@binkert.org return 1; // Avoid division by zero errors 10796145Snate@binkert.org } 10806145Snate@binkert.org} 10816145Snate@binkert.org 10826145Snate@binkert.org 10836145Snate@binkert.org// The following case statement converts CacheRequestTypes to GenericRequestTypes 10846145Snate@binkert.org// allowing all profiling to be done with a single enum type instead of slow strings 10856145Snate@binkert.orgGenericRequestType Profiler::CacheRequestType_to_GenericRequestType(const CacheRequestType& type) { 10866145Snate@binkert.org switch (type) { 10876145Snate@binkert.org case CacheRequestType_LD: 10886145Snate@binkert.org return GenericRequestType_LD; 10896145Snate@binkert.org break; 10906145Snate@binkert.org case CacheRequestType_ST: 10916145Snate@binkert.org return GenericRequestType_ST; 10926145Snate@binkert.org break; 10936145Snate@binkert.org case CacheRequestType_ATOMIC: 10946145Snate@binkert.org return GenericRequestType_ATOMIC; 10956145Snate@binkert.org break; 10966145Snate@binkert.org case CacheRequestType_IFETCH: 10976145Snate@binkert.org return GenericRequestType_IFETCH; 10986145Snate@binkert.org break; 10996145Snate@binkert.org case CacheRequestType_NULL: 11006145Snate@binkert.org return GenericRequestType_NULL; 11016145Snate@binkert.org break; 11026145Snate@binkert.org default: 11036145Snate@binkert.org ERROR_MSG("Unexpected cache request type"); 11046145Snate@binkert.org } 11056145Snate@binkert.org} 11066145Snate@binkert.org 11076285Snate@binkert.orgvoid Profiler::rubyWatch(int id){ 11086285Snate@binkert.org int rn_g1 = 0;//SIMICS_get_register_number(id, "g1"); 11096285Snate@binkert.org uint64 tr = 0;//SIMICS_read_register(id, rn_g1); 11106285Snate@binkert.org Address watch_address = Address(tr); 11116285Snate@binkert.org const int ID_SPACES = 3; 11126285Snate@binkert.org const int TIME_SPACES = 7; 11136285Snate@binkert.org 11146285Snate@binkert.org (* debug_cout_ptr).flags(ios::right); 11156285Snate@binkert.org (* debug_cout_ptr) << setw(TIME_SPACES) << g_eventQueue_ptr->getTime() << " "; 11166285Snate@binkert.org (* debug_cout_ptr) << setw(ID_SPACES) << id << " " 11176285Snate@binkert.org << "RUBY WATCH " 11186285Snate@binkert.org << watch_address 11196285Snate@binkert.org << endl; 11206285Snate@binkert.org 11216285Snate@binkert.org if(!m_watch_address_list_ptr->exist(watch_address)){ 11226285Snate@binkert.org m_watch_address_list_ptr->add(watch_address, 1); 11236285Snate@binkert.org } 11246285Snate@binkert.org} 11256285Snate@binkert.org 11266285Snate@binkert.orgbool Profiler::watchAddress(Address addr){ 11276285Snate@binkert.org if (m_watch_address_list_ptr->exist(addr)) 11286285Snate@binkert.org return true; 11296285Snate@binkert.org else 11306285Snate@binkert.org return false; 11316285Snate@binkert.org} 11326285Snate@binkert.org 11336285Snate@binkert.org// For MemoryControl: 11346285Snate@binkert.orgvoid Profiler::profileMemReq(string name, int bank) { 11356285Snate@binkert.org// printf("name is %s", name.c_str()); 11366285Snate@binkert.org assert(m_memory_control_profilers.count(name) == 1); 11376285Snate@binkert.org m_memory_control_profilers[name] -> m_memReq++; 11386285Snate@binkert.org m_memory_control_profilers[name] -> m_memBankCount[bank]++; 11396285Snate@binkert.org} 11406285Snate@binkert.orgvoid Profiler::profileMemBankBusy(string name) { assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memBankBusy++; } 11416285Snate@binkert.orgvoid Profiler::profileMemBusBusy(string name) { assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memBusBusy++; } 11426285Snate@binkert.orgvoid Profiler::profileMemReadWriteBusy(string name) { assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memReadWriteBusy++; } 11436285Snate@binkert.orgvoid Profiler::profileMemDataBusBusy(string name) { assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memDataBusBusy++; } 11446285Snate@binkert.orgvoid Profiler::profileMemTfawBusy(string name) { assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memTfawBusy++; } 11456285Snate@binkert.orgvoid Profiler::profileMemRefresh(string name) { assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memRefresh++; } 11466285Snate@binkert.orgvoid Profiler::profileMemRead(string name) { assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memRead++; } 11476285Snate@binkert.orgvoid Profiler::profileMemWrite(string name) { assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memWrite++; } 11486285Snate@binkert.orgvoid Profiler::profileMemWaitCycles(string name, int cycles) { assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memWaitCycles += cycles; } 11496285Snate@binkert.orgvoid Profiler::profileMemInputQ(string name, int cycles) { assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memInputQ += cycles; } 11506285Snate@binkert.orgvoid Profiler::profileMemBankQ(string name, int cycles) { assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memBankQ += cycles; } 11516285Snate@binkert.orgvoid Profiler::profileMemArbWait(string name, int cycles) { assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memArbWait += cycles; } 11526285Snate@binkert.orgvoid Profiler::profileMemRandBusy(string name) { assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memRandBusy++; } 11536285Snate@binkert.orgvoid Profiler::profileMemNotOld(string name) { assert(m_memory_control_profilers.count(name) == 1); m_memory_control_profilers[name] -> m_memNotOld++; } 11546285Snate@binkert.org 1155