StoreTrace.cc revision 11025:4872dbdea907
1/* 2 * Copyright (c) 1999-2008 Mark D. Hill and David A. Wood 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution; 12 * neither the name of the copyright holders nor the names of its 13 * contributors may be used to endorse or promote products derived from 14 * this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include "mem/ruby/profiler/StoreTrace.hh" 30#include "sim/core.hh" 31 32using namespace std; 33 34bool StoreTrace::s_init = false; // Total number of store lifetimes of 35 // all lines 36int64 StoreTrace::s_total_samples = 0; // Total number of store 37 // lifetimes of all lines 38Histogram* StoreTrace::s_store_count_ptr = NULL; 39Histogram* StoreTrace::s_store_first_to_stolen_ptr = NULL; 40Histogram* StoreTrace::s_store_last_to_stolen_ptr = NULL; 41Histogram* StoreTrace::s_store_first_to_last_ptr = NULL; 42 43StoreTrace::StoreTrace(Addr addr) 44 : m_store_count(-1), m_store_first_to_stolen(-1), 45 m_store_last_to_stolen(-1), m_store_first_to_last(-1) 46{ 47 StoreTrace::initSummary(); 48 m_addr = addr; 49 m_total_samples = 0; 50 51 // Really -1 isn't valid, so this will trigger the initilization code 52 m_last_writer = -1; 53 m_stores_this_interval = 0; 54} 55 56StoreTrace::~StoreTrace() 57{ 58} 59 60void 61StoreTrace::print(ostream& out) const 62{ 63 out << m_addr 64 << " total_samples: " << m_total_samples << endl 65 << "store_count: " << m_store_count << endl 66 << "store_first_to_stolen: " << m_store_first_to_stolen << endl 67 << "store_last_to_stolen: " << m_store_last_to_stolen << endl 68 << "store_first_to_last: " << m_store_first_to_last << endl; 69} 70 71void 72StoreTrace::initSummary() 73{ 74 if (!s_init) { 75 s_total_samples = 0; 76 s_store_count_ptr = new Histogram(-1); 77 s_store_first_to_stolen_ptr = new Histogram(-1); 78 s_store_last_to_stolen_ptr = new Histogram(-1); 79 s_store_first_to_last_ptr = new Histogram(-1); 80 } 81 s_init = true; 82} 83 84void 85StoreTrace::printSummary(ostream& out) 86{ 87 out << "total_samples: " << s_total_samples << endl; 88 out << "store_count: " << (*s_store_count_ptr) << endl; 89 out << "store_first_to_stolen: " << (*s_store_first_to_stolen_ptr) << endl; 90 out << "store_last_to_stolen: " << (*s_store_last_to_stolen_ptr) << endl; 91 out << "store_first_to_last: " << (*s_store_first_to_last_ptr) << endl; 92} 93 94void 95StoreTrace::clearSummary() 96{ 97 StoreTrace::initSummary(); 98 s_total_samples = 0; 99 s_store_count_ptr->clear(); 100 s_store_first_to_stolen_ptr->clear(); 101 s_store_last_to_stolen_ptr->clear(); 102 s_store_first_to_last_ptr->clear(); 103} 104 105void 106StoreTrace::store(NodeID node) 107{ 108 Tick current = curTick(); 109 110 assert((m_last_writer == -1) || (m_last_writer == node)); 111 112 m_last_writer = node; 113 if (m_last_writer == -1) { 114 assert(m_stores_this_interval == 0); 115 } 116 117 if (m_stores_this_interval == 0) { 118 // A new proessor just wrote the line, so reset the stats 119 m_first_store = current; 120 } 121 122 m_last_store = current; 123 m_stores_this_interval++; 124} 125 126void 127StoreTrace::downgrade(NodeID node) 128{ 129 if (node == m_last_writer) { 130 Tick current = curTick(); 131 assert(m_stores_this_interval != 0); 132 assert(m_last_store != 0); 133 assert(m_first_store != 0); 134 assert(m_last_writer != -1); 135 136 // Per line stats 137 m_store_first_to_stolen.add(current - m_first_store); 138 m_store_count.add(m_stores_this_interval); 139 m_store_last_to_stolen.add(current - m_last_store); 140 m_store_first_to_last.add(m_last_store - m_first_store); 141 m_total_samples++; 142 143 // Global stats 144 assert(s_store_first_to_stolen_ptr != NULL); 145 s_store_first_to_stolen_ptr->add(current - m_first_store); 146 s_store_count_ptr->add(m_stores_this_interval); 147 s_store_last_to_stolen_ptr->add(current - m_last_store); 148 s_store_first_to_last_ptr->add(m_last_store - m_first_store); 149 s_total_samples++; 150 151 // Initilize for next go round 152 m_stores_this_interval = 0; 153 m_last_store = 0; 154 m_first_store = 0; 155 m_last_writer = -1; 156 } 157} 158