Deleted Added
sdiff udiff text old ( 6154:6bb54dcb940e ) new ( 7048:2ab58c54de63 )
full compact
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;

--- 12 unchanged lines hidden (view full) ---

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/eventqueue/RubyEventQueue.hh"
30#include "mem/ruby/profiler/StoreTrace.hh"
31
32bool StoreTrace::s_init = false; // Total number of store lifetimes of
33 // all lines
34int64 StoreTrace::s_total_samples = 0; // Total number of store
35 // lifetimes of all lines
36Histogram* StoreTrace::s_store_count_ptr = NULL;
37Histogram* StoreTrace::s_store_first_to_stolen_ptr = NULL;
38Histogram* StoreTrace::s_store_last_to_stolen_ptr = NULL;
39Histogram* StoreTrace::s_store_first_to_last_ptr = NULL;
40
41StoreTrace::StoreTrace(const Address& addr)
42 : m_store_count(-1), m_store_first_to_stolen(-1),
43 m_store_last_to_stolen(-1), m_store_first_to_last(-1)
44{
45 StoreTrace::initSummary();
46 m_addr = addr;
47 m_total_samples = 0;
48
49 // Really -1 isn't valid, so this will trigger the initilization code
50 m_last_writer = -1;
51 m_stores_this_interval = 0;
52}
53
54StoreTrace::~StoreTrace()
55{
56}
57
58void
59StoreTrace::print(ostream& out) const
60{
61 out << m_addr
62 << " total_samples: " << m_total_samples << endl
63 << "store_count: " << m_store_count << endl
64 << "store_first_to_stolen: " << m_store_first_to_stolen << endl
65 << "store_last_to_stolen: " << m_store_last_to_stolen << endl
66 << "store_first_to_last: " << m_store_first_to_last << endl;
67}
68
69void
70StoreTrace::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
82void
83StoreTrace::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
92void
93StoreTrace::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
104StoreTrace::store(NodeID node)
105{
106 Time current = g_eventQueue_ptr->getTime();
107
108 assert((m_last_writer == -1) || (m_last_writer == node));
109
110 m_last_writer = node;
111 if (m_last_writer == -1) {
112 assert(m_stores_this_interval == 0);
113 }
114
115 if (m_stores_this_interval == 0) {
116 // A new proessor just wrote the line, so reset the stats
117 m_first_store = current;
118 }
119
120 m_last_store = current;
121 m_stores_this_interval++;
122}
123
124void
125StoreTrace::downgrade(NodeID node)
126{
127 if (node == m_last_writer) {
128 Time current = g_eventQueue_ptr->getTime();
129 assert(m_stores_this_interval != 0);
130 assert(m_last_store != 0);
131 assert(m_first_store != 0);
132 assert(m_last_writer != -1);
133
134 // Per line stats
135 m_store_first_to_stolen.add(current - m_first_store);
136 m_store_count.add(m_stores_this_interval);
137 m_store_last_to_stolen.add(current - m_last_store);
138 m_store_first_to_last.add(m_last_store - m_first_store);
139 m_total_samples++;
140
141 // Global stats
142 assert(s_store_first_to_stolen_ptr != NULL);
143 s_store_first_to_stolen_ptr->add(current - m_first_store);
144 s_store_count_ptr->add(m_stores_this_interval);
145 s_store_last_to_stolen_ptr->add(current - m_last_store);
146 s_store_first_to_last_ptr->add(m_last_store - m_first_store);
147 s_total_samples++;
148
149 // Initilize for next go round
150 m_stores_this_interval = 0;
151 m_last_store = 0;
152 m_first_store = 0;
153 m_last_writer = -1;
154 }
155}