StoreTrace.cc revision 6149:ff34514cbf37
12137SN/A 25268Sksewell@umich.edu/* 35254Sksewell@umich.edu * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 45254Sksewell@umich.edu * All rights reserved. 52137SN/A * 65254Sksewell@umich.edu * Redistribution and use in source and binary forms, with or without 75254Sksewell@umich.edu * modification, are permitted provided that the following conditions are 85254Sksewell@umich.edu * met: redistributions of source code must retain the above copyright 95254Sksewell@umich.edu * notice, this list of conditions and the following disclaimer; 105254Sksewell@umich.edu * redistributions in binary form must reproduce the above copyright 115254Sksewell@umich.edu * notice, this list of conditions and the following disclaimer in the 125254Sksewell@umich.edu * documentation and/or other materials provided with the distribution; 135254Sksewell@umich.edu * neither the name of the copyright holders nor the names of its 145254Sksewell@umich.edu * contributors may be used to endorse or promote products derived from 155254Sksewell@umich.edu * this software without specific prior written permission. 162137SN/A * 175254Sksewell@umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 185254Sksewell@umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 195254Sksewell@umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 205254Sksewell@umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 215254Sksewell@umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 225254Sksewell@umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 235254Sksewell@umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 245254Sksewell@umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 255254Sksewell@umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 265254Sksewell@umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 275254Sksewell@umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 282665Ssaidi@eecs.umich.edu */ 295268Sksewell@umich.edu 305268Sksewell@umich.edu/* 312137SN/A * $Id$ 322137SN/A * 332597SN/A */ 342597SN/A 352137SN/A#include "StoreTrace.hh" 362137SN/A#include "RubyEventQueue.hh" 372137SN/A 382680Sktlim@umich.edubool StoreTrace::s_init = false; // Total number of store lifetimes of all lines 392137SN/Aint64 StoreTrace::s_total_samples = 0; // Total number of store lifetimes of all lines 402137SN/AHistogram* StoreTrace::s_store_count_ptr = NULL; 412137SN/AHistogram* StoreTrace::s_store_first_to_stolen_ptr = NULL; 424661Sksewell@umich.eduHistogram* StoreTrace::s_store_last_to_stolen_ptr = NULL; 432137SN/AHistogram* StoreTrace::s_store_first_to_last_ptr = NULL; 444661Sksewell@umich.edu 452137SN/AStoreTrace::StoreTrace(const Address& addr) : 462137SN/A m_store_count(-1), m_store_first_to_stolen(-1), m_store_last_to_stolen(-1), m_store_first_to_last(-1) 472137SN/A{ 482137SN/A StoreTrace::initSummary(); 492137SN/A m_addr = addr; 502137SN/A m_total_samples = 0; 513114Sgblack@eecs.umich.edu m_last_writer = -1; // Really -1 isn't valid, so this will trigger the initilization code 522680Sktlim@umich.edu m_stores_this_interval = 0; 532137SN/A} 542680Sktlim@umich.edu 552137SN/AStoreTrace::~StoreTrace() 562137SN/A{ 574661Sksewell@umich.edu} 582137SN/A 592137SN/Avoid StoreTrace::print(ostream& out) const 602137SN/A{ 612137SN/A out << m_addr; 622680Sktlim@umich.edu out << " total_samples: " << m_total_samples << endl; 632137SN/A out << "store_count: " << m_store_count << endl; 642137SN/A out << "store_first_to_stolen: " << m_store_first_to_stolen << endl; 652137SN/A out << "store_last_to_stolen: " << m_store_last_to_stolen << endl; 662484SN/A out << "store_first_to_last: " << m_store_first_to_last << endl; 672137SN/A} 682137SN/A 692137SN/A// Class method 703114Sgblack@eecs.umich.eduvoid StoreTrace::initSummary() 712680Sktlim@umich.edu{ 722137SN/A if (!s_init) { 732680Sktlim@umich.edu s_total_samples = 0; 742680Sktlim@umich.edu s_store_count_ptr = new Histogram(-1); 752137SN/A s_store_first_to_stolen_ptr = new Histogram(-1); 762137SN/A s_store_last_to_stolen_ptr = new Histogram(-1); 772137SN/A s_store_first_to_last_ptr = new Histogram(-1); 782137SN/A } 792680Sktlim@umich.edu s_init = true; 802137SN/A} 812137SN/A 822680Sktlim@umich.edu// Class method 832137SN/Avoid StoreTrace::printSummary(ostream& out) 842137SN/A{ 852137SN/A out << "total_samples: " << s_total_samples << endl; 862137SN/A out << "store_count: " << (*s_store_count_ptr) << endl; 872484SN/A out << "store_first_to_stolen: " << (*s_store_first_to_stolen_ptr) << endl; 882137SN/A out << "store_last_to_stolen: " << (*s_store_last_to_stolen_ptr) << endl; 892137SN/A out << "store_first_to_last: " << (*s_store_first_to_last_ptr) << endl; 902137SN/A} 912137SN/A 922137SN/A// Class method 932137SN/Avoid StoreTrace::clearSummary() 942137SN/A{ 952484SN/A StoreTrace::initSummary(); 962137SN/A s_total_samples = 0; 973114Sgblack@eecs.umich.edu s_store_count_ptr->clear(); 982680Sktlim@umich.edu s_store_first_to_stolen_ptr->clear(); 992137SN/A s_store_last_to_stolen_ptr->clear(); 1002680Sktlim@umich.edu s_store_first_to_last_ptr->clear(); 1012680Sktlim@umich.edu} 1022137SN/A 1032137SN/Avoid StoreTrace::store(NodeID node) 1042137SN/A{ 1052137SN/A Time current = g_eventQueue_ptr->getTime(); 1062680Sktlim@umich.edu 1072137SN/A assert((m_last_writer == -1) || (m_last_writer == node)); 1082680Sktlim@umich.edu 1092484SN/A m_last_writer = node; 1102137SN/A if (m_last_writer == -1) { 1112137SN/A assert(m_stores_this_interval == 0); 1122137SN/A } 1132137SN/A 1142137SN/A if (m_stores_this_interval == 0) { 1152484SN/A // A new proessor just wrote the line, so reset the stats 1162137SN/A m_first_store = current; 1172137SN/A } 1182137SN/A 1192137SN/A m_last_store = current; 1202137SN/A m_stores_this_interval++; 1212137SN/A} 1222137SN/A 1232137SN/Avoid StoreTrace::downgrade(NodeID node) 1242484SN/A{ 1252137SN/A if (node == m_last_writer) { 1262137SN/A Time current = g_eventQueue_ptr->getTime(); 1272137SN/A assert(m_stores_this_interval != 0); 1282137SN/A assert(m_last_store != 0); 1292553SN/A assert(m_first_store != 0); 1302137SN/A assert(m_last_writer != -1); 1312484SN/A 1322484SN/A // Per line stats 1332137SN/A m_store_first_to_stolen.add(current - m_first_store); 1342137SN/A m_store_count.add(m_stores_this_interval); 1352484SN/A m_store_last_to_stolen.add(current - m_last_store); 1362137SN/A m_store_first_to_last.add(m_last_store - m_first_store); 1372484SN/A m_total_samples++; 1382137SN/A 1392553SN/A // Global stats 1402484SN/A assert(s_store_first_to_stolen_ptr != NULL); 1412686Sksewell@umich.edu s_store_first_to_stolen_ptr->add(current - m_first_store); 1422484SN/A s_store_count_ptr->add(m_stores_this_interval); 1432137SN/A s_store_last_to_stolen_ptr->add(current - m_last_store); 1442484SN/A s_store_first_to_last_ptr->add(m_last_store - m_first_store); 1452484SN/A s_total_samples++; 1462137SN/A 1472137SN/A // Initilize for next go round 1482484SN/A m_stores_this_interval = 0; 1492484SN/A m_last_store = 0; 1502484SN/A m_first_store = 0; 1512484SN/A m_last_writer = -1; 1522484SN/A } 1532484SN/A} 1542484SN/A 1552484SN/Abool node_less_then_eq(const StoreTrace* n1, const StoreTrace* n2) 1562484SN/A{ 1572137SN/A return (n1->getTotal() > n2->getTotal()); 1582484SN/A} 1592484SN/A