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