StoreTrace.cc revision 10302
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/profiler/StoreTrace.hh"
309171Snilay@cs.wisc.edu#include "sim/core.hh"
316145Snate@binkert.org
327055Snate@binkert.orgusing namespace std;
337055Snate@binkert.org
347048Snate@binkert.orgbool StoreTrace::s_init = false; // Total number of store lifetimes of
357048Snate@binkert.org                                 // all lines
367048Snate@binkert.orgint64 StoreTrace::s_total_samples = 0; // Total number of store
377048Snate@binkert.org                                       // lifetimes of all lines
386145Snate@binkert.orgHistogram* StoreTrace::s_store_count_ptr = NULL;
396145Snate@binkert.orgHistogram* StoreTrace::s_store_first_to_stolen_ptr = NULL;
406145Snate@binkert.orgHistogram* StoreTrace::s_store_last_to_stolen_ptr = NULL;
416145Snate@binkert.orgHistogram* StoreTrace::s_store_first_to_last_ptr = NULL;
426145Snate@binkert.org
437048Snate@binkert.orgStoreTrace::StoreTrace(const Address& addr)
447048Snate@binkert.org    : m_store_count(-1), m_store_first_to_stolen(-1),
457048Snate@binkert.org      m_store_last_to_stolen(-1), m_store_first_to_last(-1)
466145Snate@binkert.org{
477048Snate@binkert.org    StoreTrace::initSummary();
487048Snate@binkert.org    m_addr = addr;
497048Snate@binkert.org    m_total_samples = 0;
507048Snate@binkert.org
517048Snate@binkert.org    // Really -1 isn't valid, so this will trigger the initilization code
527048Snate@binkert.org    m_last_writer = -1;
537048Snate@binkert.org    m_stores_this_interval = 0;
546145Snate@binkert.org}
556145Snate@binkert.org
566145Snate@binkert.orgStoreTrace::~StoreTrace()
576145Snate@binkert.org{
586145Snate@binkert.org}
596145Snate@binkert.org
607048Snate@binkert.orgvoid
617048Snate@binkert.orgStoreTrace::print(ostream& out) const
626145Snate@binkert.org{
637048Snate@binkert.org    out << m_addr
647048Snate@binkert.org        << " total_samples: " << m_total_samples << endl
657048Snate@binkert.org        << "store_count: " << m_store_count << endl
667048Snate@binkert.org        << "store_first_to_stolen: " << m_store_first_to_stolen << endl
677048Snate@binkert.org        << "store_last_to_stolen: " << m_store_last_to_stolen << endl
687048Snate@binkert.org        << "store_first_to_last: " << m_store_first_to_last  << endl;
696145Snate@binkert.org}
706145Snate@binkert.org
717048Snate@binkert.orgvoid
727048Snate@binkert.orgStoreTrace::initSummary()
736145Snate@binkert.org{
747048Snate@binkert.org    if (!s_init) {
757048Snate@binkert.org        s_total_samples = 0;
767048Snate@binkert.org        s_store_count_ptr = new Histogram(-1);
777048Snate@binkert.org        s_store_first_to_stolen_ptr = new Histogram(-1);
787048Snate@binkert.org        s_store_last_to_stolen_ptr = new Histogram(-1);
797048Snate@binkert.org        s_store_first_to_last_ptr = new Histogram(-1);
807048Snate@binkert.org    }
817048Snate@binkert.org    s_init = true;
826145Snate@binkert.org}
836145Snate@binkert.org
847048Snate@binkert.orgvoid
857048Snate@binkert.orgStoreTrace::printSummary(ostream& out)
866145Snate@binkert.org{
877048Snate@binkert.org    out << "total_samples: " << s_total_samples << endl;
887048Snate@binkert.org    out << "store_count: " << (*s_store_count_ptr) << endl;
897048Snate@binkert.org    out << "store_first_to_stolen: " << (*s_store_first_to_stolen_ptr) << endl;
907048Snate@binkert.org    out << "store_last_to_stolen: " << (*s_store_last_to_stolen_ptr) << endl;
917048Snate@binkert.org    out << "store_first_to_last: " << (*s_store_first_to_last_ptr) << endl;
926145Snate@binkert.org}
936145Snate@binkert.org
947048Snate@binkert.orgvoid
957048Snate@binkert.orgStoreTrace::clearSummary()
966145Snate@binkert.org{
977048Snate@binkert.org    StoreTrace::initSummary();
987048Snate@binkert.org    s_total_samples = 0;
997048Snate@binkert.org    s_store_count_ptr->clear();
1007048Snate@binkert.org    s_store_first_to_stolen_ptr->clear();
1017048Snate@binkert.org    s_store_last_to_stolen_ptr->clear();
1027048Snate@binkert.org    s_store_first_to_last_ptr->clear();
1036145Snate@binkert.org}
1046145Snate@binkert.org
1057048Snate@binkert.orgvoid
1067048Snate@binkert.orgStoreTrace::store(NodeID node)
1076145Snate@binkert.org{
1089171Snilay@cs.wisc.edu    Tick current = curTick();
1096145Snate@binkert.org
1107048Snate@binkert.org    assert((m_last_writer == -1) || (m_last_writer == node));
1116145Snate@binkert.org
1127048Snate@binkert.org    m_last_writer = node;
1137048Snate@binkert.org    if (m_last_writer == -1) {
1147048Snate@binkert.org        assert(m_stores_this_interval == 0);
1157048Snate@binkert.org    }
1166145Snate@binkert.org
1177048Snate@binkert.org    if (m_stores_this_interval == 0) {
1187048Snate@binkert.org        // A new proessor just wrote the line, so reset the stats
1197048Snate@binkert.org        m_first_store = current;
1207048Snate@binkert.org    }
1216145Snate@binkert.org
1227048Snate@binkert.org    m_last_store = current;
1237048Snate@binkert.org    m_stores_this_interval++;
1246145Snate@binkert.org}
1256145Snate@binkert.org
1267048Snate@binkert.orgvoid
1277048Snate@binkert.orgStoreTrace::downgrade(NodeID node)
1286145Snate@binkert.org{
1297048Snate@binkert.org    if (node == m_last_writer) {
13010302Snilay@cs.wisc.edu        Tick current = curTick();
1317048Snate@binkert.org        assert(m_stores_this_interval != 0);
1327048Snate@binkert.org        assert(m_last_store != 0);
1337048Snate@binkert.org        assert(m_first_store != 0);
1347048Snate@binkert.org        assert(m_last_writer != -1);
1356145Snate@binkert.org
1367048Snate@binkert.org        // Per line stats
1377048Snate@binkert.org        m_store_first_to_stolen.add(current - m_first_store);
1387048Snate@binkert.org        m_store_count.add(m_stores_this_interval);
1397048Snate@binkert.org        m_store_last_to_stolen.add(current - m_last_store);
1407048Snate@binkert.org        m_store_first_to_last.add(m_last_store - m_first_store);
1417048Snate@binkert.org        m_total_samples++;
1426145Snate@binkert.org
1437048Snate@binkert.org        // Global stats
1447048Snate@binkert.org        assert(s_store_first_to_stolen_ptr != NULL);
1457048Snate@binkert.org        s_store_first_to_stolen_ptr->add(current - m_first_store);
1467048Snate@binkert.org        s_store_count_ptr->add(m_stores_this_interval);
1477048Snate@binkert.org        s_store_last_to_stolen_ptr->add(current - m_last_store);
1487048Snate@binkert.org        s_store_first_to_last_ptr->add(m_last_store - m_first_store);
1497048Snate@binkert.org        s_total_samples++;
1506145Snate@binkert.org
1517048Snate@binkert.org        // Initilize for next go round
1527048Snate@binkert.org        m_stores_this_interval = 0;
1537048Snate@binkert.org        m_last_store = 0;
1547048Snate@binkert.org        m_first_store = 0;
1557048Snate@binkert.org        m_last_writer = -1;
1567048Snate@binkert.org    }
1576145Snate@binkert.org}
158