StoreTrace.cc revision 7048
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 297048Snate@binkert.org#include "mem/ruby/eventqueue/RubyEventQueue.hh" 307048Snate@binkert.org#include "mem/ruby/profiler/StoreTrace.hh" 316145Snate@binkert.org 327048Snate@binkert.orgbool StoreTrace::s_init = false; // Total number of store lifetimes of 337048Snate@binkert.org // all lines 347048Snate@binkert.orgint64 StoreTrace::s_total_samples = 0; // Total number of store 357048Snate@binkert.org // lifetimes of all lines 366145Snate@binkert.orgHistogram* StoreTrace::s_store_count_ptr = NULL; 376145Snate@binkert.orgHistogram* StoreTrace::s_store_first_to_stolen_ptr = NULL; 386145Snate@binkert.orgHistogram* StoreTrace::s_store_last_to_stolen_ptr = NULL; 396145Snate@binkert.orgHistogram* StoreTrace::s_store_first_to_last_ptr = NULL; 406145Snate@binkert.org 417048Snate@binkert.orgStoreTrace::StoreTrace(const Address& addr) 427048Snate@binkert.org : m_store_count(-1), m_store_first_to_stolen(-1), 437048Snate@binkert.org m_store_last_to_stolen(-1), m_store_first_to_last(-1) 446145Snate@binkert.org{ 457048Snate@binkert.org StoreTrace::initSummary(); 467048Snate@binkert.org m_addr = addr; 477048Snate@binkert.org m_total_samples = 0; 487048Snate@binkert.org 497048Snate@binkert.org // Really -1 isn't valid, so this will trigger the initilization code 507048Snate@binkert.org m_last_writer = -1; 517048Snate@binkert.org m_stores_this_interval = 0; 526145Snate@binkert.org} 536145Snate@binkert.org 546145Snate@binkert.orgStoreTrace::~StoreTrace() 556145Snate@binkert.org{ 566145Snate@binkert.org} 576145Snate@binkert.org 587048Snate@binkert.orgvoid 597048Snate@binkert.orgStoreTrace::print(ostream& out) const 606145Snate@binkert.org{ 617048Snate@binkert.org out << m_addr 627048Snate@binkert.org << " total_samples: " << m_total_samples << endl 637048Snate@binkert.org << "store_count: " << m_store_count << endl 647048Snate@binkert.org << "store_first_to_stolen: " << m_store_first_to_stolen << endl 657048Snate@binkert.org << "store_last_to_stolen: " << m_store_last_to_stolen << endl 667048Snate@binkert.org << "store_first_to_last: " << m_store_first_to_last << endl; 676145Snate@binkert.org} 686145Snate@binkert.org 697048Snate@binkert.orgvoid 707048Snate@binkert.orgStoreTrace::initSummary() 716145Snate@binkert.org{ 727048Snate@binkert.org if (!s_init) { 737048Snate@binkert.org s_total_samples = 0; 747048Snate@binkert.org s_store_count_ptr = new Histogram(-1); 757048Snate@binkert.org s_store_first_to_stolen_ptr = new Histogram(-1); 767048Snate@binkert.org s_store_last_to_stolen_ptr = new Histogram(-1); 777048Snate@binkert.org s_store_first_to_last_ptr = new Histogram(-1); 787048Snate@binkert.org } 797048Snate@binkert.org s_init = true; 806145Snate@binkert.org} 816145Snate@binkert.org 827048Snate@binkert.orgvoid 837048Snate@binkert.orgStoreTrace::printSummary(ostream& out) 846145Snate@binkert.org{ 857048Snate@binkert.org out << "total_samples: " << s_total_samples << endl; 867048Snate@binkert.org out << "store_count: " << (*s_store_count_ptr) << endl; 877048Snate@binkert.org out << "store_first_to_stolen: " << (*s_store_first_to_stolen_ptr) << endl; 887048Snate@binkert.org out << "store_last_to_stolen: " << (*s_store_last_to_stolen_ptr) << endl; 897048Snate@binkert.org out << "store_first_to_last: " << (*s_store_first_to_last_ptr) << endl; 906145Snate@binkert.org} 916145Snate@binkert.org 927048Snate@binkert.orgvoid 937048Snate@binkert.orgStoreTrace::clearSummary() 946145Snate@binkert.org{ 957048Snate@binkert.org StoreTrace::initSummary(); 967048Snate@binkert.org s_total_samples = 0; 977048Snate@binkert.org s_store_count_ptr->clear(); 987048Snate@binkert.org s_store_first_to_stolen_ptr->clear(); 997048Snate@binkert.org s_store_last_to_stolen_ptr->clear(); 1007048Snate@binkert.org s_store_first_to_last_ptr->clear(); 1016145Snate@binkert.org} 1026145Snate@binkert.org 1037048Snate@binkert.orgvoid 1047048Snate@binkert.orgStoreTrace::store(NodeID node) 1056145Snate@binkert.org{ 1067048Snate@binkert.org Time current = g_eventQueue_ptr->getTime(); 1076145Snate@binkert.org 1087048Snate@binkert.org assert((m_last_writer == -1) || (m_last_writer == node)); 1096145Snate@binkert.org 1107048Snate@binkert.org m_last_writer = node; 1117048Snate@binkert.org if (m_last_writer == -1) { 1127048Snate@binkert.org assert(m_stores_this_interval == 0); 1137048Snate@binkert.org } 1146145Snate@binkert.org 1157048Snate@binkert.org if (m_stores_this_interval == 0) { 1167048Snate@binkert.org // A new proessor just wrote the line, so reset the stats 1177048Snate@binkert.org m_first_store = current; 1187048Snate@binkert.org } 1196145Snate@binkert.org 1207048Snate@binkert.org m_last_store = current; 1217048Snate@binkert.org m_stores_this_interval++; 1226145Snate@binkert.org} 1236145Snate@binkert.org 1247048Snate@binkert.orgvoid 1257048Snate@binkert.orgStoreTrace::downgrade(NodeID node) 1266145Snate@binkert.org{ 1277048Snate@binkert.org if (node == m_last_writer) { 1287048Snate@binkert.org Time current = g_eventQueue_ptr->getTime(); 1297048Snate@binkert.org assert(m_stores_this_interval != 0); 1307048Snate@binkert.org assert(m_last_store != 0); 1317048Snate@binkert.org assert(m_first_store != 0); 1327048Snate@binkert.org assert(m_last_writer != -1); 1336145Snate@binkert.org 1347048Snate@binkert.org // Per line stats 1357048Snate@binkert.org m_store_first_to_stolen.add(current - m_first_store); 1367048Snate@binkert.org m_store_count.add(m_stores_this_interval); 1377048Snate@binkert.org m_store_last_to_stolen.add(current - m_last_store); 1387048Snate@binkert.org m_store_first_to_last.add(m_last_store - m_first_store); 1397048Snate@binkert.org m_total_samples++; 1406145Snate@binkert.org 1417048Snate@binkert.org // Global stats 1427048Snate@binkert.org assert(s_store_first_to_stolen_ptr != NULL); 1437048Snate@binkert.org s_store_first_to_stolen_ptr->add(current - m_first_store); 1447048Snate@binkert.org s_store_count_ptr->add(m_stores_this_interval); 1457048Snate@binkert.org s_store_last_to_stolen_ptr->add(current - m_last_store); 1467048Snate@binkert.org s_store_first_to_last_ptr->add(m_last_store - m_first_store); 1477048Snate@binkert.org s_total_samples++; 1486145Snate@binkert.org 1497048Snate@binkert.org // Initilize for next go round 1507048Snate@binkert.org m_stores_this_interval = 0; 1517048Snate@binkert.org m_last_store = 0; 1527048Snate@binkert.org m_first_store = 0; 1537048Snate@binkert.org m_last_writer = -1; 1547048Snate@binkert.org } 1556145Snate@binkert.org} 156