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"
3011793Sbrandon.potter@amd.com
319171Snilay@cs.wisc.edu#include "sim/core.hh"
326145Snate@binkert.org
337055Snate@binkert.orgusing namespace std;
347055Snate@binkert.org
357048Snate@binkert.orgbool StoreTrace::s_init = false; // Total number of store lifetimes of
367048Snate@binkert.org                                 // all lines
3711061Snilay@cs.wisc.eduint64_t StoreTrace::s_total_samples = 0; // Total number of store
387048Snate@binkert.org                                       // lifetimes of all lines
396145Snate@binkert.orgHistogram* StoreTrace::s_store_count_ptr = NULL;
406145Snate@binkert.orgHistogram* StoreTrace::s_store_first_to_stolen_ptr = NULL;
416145Snate@binkert.orgHistogram* StoreTrace::s_store_last_to_stolen_ptr = NULL;
426145Snate@binkert.orgHistogram* StoreTrace::s_store_first_to_last_ptr = NULL;
436145Snate@binkert.org
4411025Snilay@cs.wisc.eduStoreTrace::StoreTrace(Addr addr)
457048Snate@binkert.org    : m_store_count(-1), m_store_first_to_stolen(-1),
467048Snate@binkert.org      m_store_last_to_stolen(-1), m_store_first_to_last(-1)
476145Snate@binkert.org{
487048Snate@binkert.org    StoreTrace::initSummary();
497048Snate@binkert.org    m_addr = addr;
507048Snate@binkert.org    m_total_samples = 0;
517048Snate@binkert.org
527048Snate@binkert.org    // Really -1 isn't valid, so this will trigger the initilization code
537048Snate@binkert.org    m_last_writer = -1;
547048Snate@binkert.org    m_stores_this_interval = 0;
556145Snate@binkert.org}
566145Snate@binkert.org
576145Snate@binkert.orgStoreTrace::~StoreTrace()
586145Snate@binkert.org{
596145Snate@binkert.org}
606145Snate@binkert.org
617048Snate@binkert.orgvoid
627048Snate@binkert.orgStoreTrace::print(ostream& out) const
636145Snate@binkert.org{
647048Snate@binkert.org    out << m_addr
657048Snate@binkert.org        << " total_samples: " << m_total_samples << endl
667048Snate@binkert.org        << "store_count: " << m_store_count << endl
677048Snate@binkert.org        << "store_first_to_stolen: " << m_store_first_to_stolen << endl
687048Snate@binkert.org        << "store_last_to_stolen: " << m_store_last_to_stolen << endl
697048Snate@binkert.org        << "store_first_to_last: " << m_store_first_to_last  << endl;
706145Snate@binkert.org}
716145Snate@binkert.org
727048Snate@binkert.orgvoid
737048Snate@binkert.orgStoreTrace::initSummary()
746145Snate@binkert.org{
757048Snate@binkert.org    if (!s_init) {
767048Snate@binkert.org        s_total_samples = 0;
777048Snate@binkert.org        s_store_count_ptr = new Histogram(-1);
787048Snate@binkert.org        s_store_first_to_stolen_ptr = new Histogram(-1);
797048Snate@binkert.org        s_store_last_to_stolen_ptr = new Histogram(-1);
807048Snate@binkert.org        s_store_first_to_last_ptr = new Histogram(-1);
817048Snate@binkert.org    }
827048Snate@binkert.org    s_init = true;
836145Snate@binkert.org}
846145Snate@binkert.org
857048Snate@binkert.orgvoid
867048Snate@binkert.orgStoreTrace::printSummary(ostream& out)
876145Snate@binkert.org{
887048Snate@binkert.org    out << "total_samples: " << s_total_samples << endl;
897048Snate@binkert.org    out << "store_count: " << (*s_store_count_ptr) << endl;
907048Snate@binkert.org    out << "store_first_to_stolen: " << (*s_store_first_to_stolen_ptr) << endl;
917048Snate@binkert.org    out << "store_last_to_stolen: " << (*s_store_last_to_stolen_ptr) << endl;
927048Snate@binkert.org    out << "store_first_to_last: " << (*s_store_first_to_last_ptr) << endl;
936145Snate@binkert.org}
946145Snate@binkert.org
957048Snate@binkert.orgvoid
967048Snate@binkert.orgStoreTrace::clearSummary()
976145Snate@binkert.org{
987048Snate@binkert.org    StoreTrace::initSummary();
997048Snate@binkert.org    s_total_samples = 0;
1007048Snate@binkert.org    s_store_count_ptr->clear();
1017048Snate@binkert.org    s_store_first_to_stolen_ptr->clear();
1027048Snate@binkert.org    s_store_last_to_stolen_ptr->clear();
1037048Snate@binkert.org    s_store_first_to_last_ptr->clear();
1046145Snate@binkert.org}
1056145Snate@binkert.org
1067048Snate@binkert.orgvoid
1077048Snate@binkert.orgStoreTrace::store(NodeID node)
1086145Snate@binkert.org{
1099171Snilay@cs.wisc.edu    Tick current = curTick();
1106145Snate@binkert.org
1117048Snate@binkert.org    assert((m_last_writer == -1) || (m_last_writer == node));
1126145Snate@binkert.org
1137048Snate@binkert.org    m_last_writer = node;
1147048Snate@binkert.org    if (m_last_writer == -1) {
1157048Snate@binkert.org        assert(m_stores_this_interval == 0);
1167048Snate@binkert.org    }
1176145Snate@binkert.org
1187048Snate@binkert.org    if (m_stores_this_interval == 0) {
1197048Snate@binkert.org        // A new proessor just wrote the line, so reset the stats
1207048Snate@binkert.org        m_first_store = current;
1217048Snate@binkert.org    }
1226145Snate@binkert.org
1237048Snate@binkert.org    m_last_store = current;
1247048Snate@binkert.org    m_stores_this_interval++;
1256145Snate@binkert.org}
1266145Snate@binkert.org
1277048Snate@binkert.orgvoid
1287048Snate@binkert.orgStoreTrace::downgrade(NodeID node)
1296145Snate@binkert.org{
1307048Snate@binkert.org    if (node == m_last_writer) {
13110302Snilay@cs.wisc.edu        Tick current = curTick();
1327048Snate@binkert.org        assert(m_stores_this_interval != 0);
1337048Snate@binkert.org        assert(m_last_store != 0);
1347048Snate@binkert.org        assert(m_first_store != 0);
1357048Snate@binkert.org        assert(m_last_writer != -1);
1366145Snate@binkert.org
1377048Snate@binkert.org        // Per line stats
1387048Snate@binkert.org        m_store_first_to_stolen.add(current - m_first_store);
1397048Snate@binkert.org        m_store_count.add(m_stores_this_interval);
1407048Snate@binkert.org        m_store_last_to_stolen.add(current - m_last_store);
1417048Snate@binkert.org        m_store_first_to_last.add(m_last_store - m_first_store);
1427048Snate@binkert.org        m_total_samples++;
1436145Snate@binkert.org
1447048Snate@binkert.org        // Global stats
1457048Snate@binkert.org        assert(s_store_first_to_stolen_ptr != NULL);
1467048Snate@binkert.org        s_store_first_to_stolen_ptr->add(current - m_first_store);
1477048Snate@binkert.org        s_store_count_ptr->add(m_stores_this_interval);
1487048Snate@binkert.org        s_store_last_to_stolen_ptr->add(current - m_last_store);
1497048Snate@binkert.org        s_store_first_to_last_ptr->add(m_last_store - m_first_store);
1507048Snate@binkert.org        s_total_samples++;
1516145Snate@binkert.org
1527048Snate@binkert.org        // Initilize for next go round
1537048Snate@binkert.org        m_stores_this_interval = 0;
1547048Snate@binkert.org        m_last_store = 0;
1557048Snate@binkert.org        m_first_store = 0;
1567048Snate@binkert.org        m_last_writer = -1;
1577048Snate@binkert.org    }
1586145Snate@binkert.org}
159