LSQ Unit: After deleting part of a split request, set it to NULL so that it
[gem5.git] / src / sim / stat_control.cc
1 /*
2 * Copyright (c) 2004-2005 The Regents of The University of Michigan
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 * Authors: Nathan Binkert
29 */
30
31 // This file will contain default statistics for the simulator that
32 // don't really belong to a specific simulator object
33
34 #include <fstream>
35 #include <iostream>
36 #include <list>
37
38 #include "base/callback.hh"
39 #include "base/hostinfo.hh"
40 #include "base/statistics.hh"
41 #include "base/time.hh"
42 #include "cpu/base.hh"
43 #include "sim/eventq.hh"
44
45 using namespace std;
46
47 Stats::Formula simSeconds;
48 Stats::Value simTicks;
49 Stats::Value simFreq;
50
51 namespace Stats {
52
53 Time statTime(true);
54 Tick startTick;
55
56 struct SimTicksReset : public Callback
57 {
58 void process()
59 {
60 statTime.set();
61 startTick = curTick;
62 }
63 };
64
65 double
66 statElapsedTime()
67 {
68 Time now(true);
69 Time elapsed = now - statTime;
70 return elapsed();
71 }
72
73 Tick
74 statElapsedTicks()
75 {
76 return curTick - startTick;
77 }
78
79 SimTicksReset simTicksReset;
80
81 struct Global
82 {
83 Stats::Formula hostInstRate;
84 Stats::Formula hostTickRate;
85 Stats::Value hostMemory;
86 Stats::Value hostSeconds;
87
88 Stats::Value simInsts;
89
90 Global();
91 };
92
93 Global::Global()
94 {
95 simInsts
96 .functor(BaseCPU::numSimulatedInstructions)
97 .name("sim_insts")
98 .desc("Number of instructions simulated")
99 .precision(0)
100 .prereq(simInsts)
101 ;
102
103 simSeconds
104 .name("sim_seconds")
105 .desc("Number of seconds simulated")
106 ;
107
108 simFreq
109 .scalar(SimClock::Frequency)
110 .name("sim_freq")
111 .desc("Frequency of simulated ticks")
112 ;
113
114 simTicks
115 .functor(statElapsedTicks)
116 .name("sim_ticks")
117 .desc("Number of ticks simulated")
118 ;
119
120 hostInstRate
121 .name("host_inst_rate")
122 .desc("Simulator instruction rate (inst/s)")
123 .precision(0)
124 .prereq(simInsts)
125 ;
126
127 hostMemory
128 .functor(memUsage)
129 .name("host_mem_usage")
130 .desc("Number of bytes of host memory used")
131 .prereq(hostMemory)
132 ;
133
134 hostSeconds
135 .functor(statElapsedTime)
136 .name("host_seconds")
137 .desc("Real time elapsed on the host")
138 .precision(2)
139 ;
140
141 hostTickRate
142 .name("host_tick_rate")
143 .desc("Simulator tick rate (ticks/s)")
144 .precision(0)
145 ;
146
147 simSeconds = simTicks / simFreq;
148 hostInstRate = simInsts / hostSeconds;
149 hostTickRate = simTicks / hostSeconds;
150
151 registerResetCallback(&simTicksReset);
152 }
153
154 void
155 initSimStats()
156 {
157 static Global global;
158 }
159
160 class _StatEvent : public Event
161 {
162 private:
163 bool dump;
164 bool reset;
165 Tick repeat;
166
167 public:
168 _StatEvent(bool _dump, bool _reset, Tick _repeat)
169 : Event(Stat_Event_Pri), dump(_dump), reset(_reset), repeat(_repeat)
170 {
171 setFlags(AutoDelete);
172 }
173
174 virtual void
175 process()
176 {
177 if (dump)
178 Stats::dump();
179
180 if (reset)
181 Stats::reset();
182
183 if (repeat) {
184 Event *event = new _StatEvent(dump, reset, repeat);
185 mainEventQueue.schedule(event, curTick + repeat);
186 }
187 }
188 };
189
190 void
191 StatEvent(bool dump, bool reset, Tick when, Tick repeat)
192 {
193 Event *event = new _StatEvent(dump, reset, repeat);
194 mainEventQueue.schedule(event, when);
195 }
196
197 /* namespace Stats */ }