gem5  v20.1.0.0
stat_control.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 ARM Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2004-2005 The Regents of The University of Michigan
15  * Copyright (c) 2013 Advanced Micro Devices, Inc.
16  * Copyright (c) 2013 Mark D. Hill and David A. Wood
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions are
21  * met: redistributions of source code must retain the above copyright
22  * notice, this list of conditions and the following disclaimer;
23  * redistributions in binary form must reproduce the above copyright
24  * notice, this list of conditions and the following disclaimer in the
25  * documentation and/or other materials provided with the distribution;
26  * neither the name of the copyright holders nor the names of its
27  * contributors may be used to endorse or promote products derived from
28  * this software without specific prior written permission.
29  *
30  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41  */
42 
43 // This file will contain default statistics for the simulator that
44 // don't really belong to a specific simulator object
45 
46 #include "sim/stat_control.hh"
47 
48 #include <fstream>
49 #include <iostream>
50 #include <list>
51 
52 #include "base/callback.hh"
53 #include "base/hostinfo.hh"
54 #include "base/statistics.hh"
55 #include "base/time.hh"
56 #include "cpu/base.hh"
57 #include "sim/global_event.hh"
58 
59 using namespace std;
60 
65 
66 namespace Stats {
67 
68 Time statTime(true);
70 
72 
73 double
75 {
76  Time now;
77  now.setTimer();
78 
79  Time elapsed = now - statTime;
80  return elapsed;
81 }
82 
83 Tick
85 {
86  return curTick() - startTick;
87 }
88 
89 Tick
91 {
92  return curTick();
93 }
94 
95 struct Global
96 {
102 
105 
106  Global();
107 };
108 
109 Global::Global()
110 {
111  simInsts
113  .name("sim_insts")
114  .desc("Number of instructions simulated")
115  .precision(0)
116  .prereq(simInsts)
117  ;
118 
119  simOps
120  .functor(BaseCPU::numSimulatedOps)
121  .name("sim_ops")
122  .desc("Number of ops (including micro ops) simulated")
123  .precision(0)
124  .prereq(simOps)
125  ;
126 
127  simSeconds
128  .name("sim_seconds")
129  .desc("Number of seconds simulated")
130  ;
131 
132  simFreq
134  .name("sim_freq")
135  .desc("Frequency of simulated ticks")
136  ;
137 
138  simTicks
140  .name("sim_ticks")
141  .desc("Number of ticks simulated")
142  ;
143 
144  finalTick
146  .name("final_tick")
147  .desc("Number of ticks from beginning of simulation "
148  "(restored from checkpoints and never reset)")
149  ;
150 
151  hostInstRate
152  .name("host_inst_rate")
153  .desc("Simulator instruction rate (inst/s)")
154  .precision(0)
155  .prereq(simInsts)
156  ;
157 
158  hostOpRate
159  .name("host_op_rate")
160  .desc("Simulator op (including micro ops) rate (op/s)")
161  .precision(0)
162  .prereq(simOps)
163  ;
164 
165  hostMemory
166  .functor(memUsage)
167  .name("host_mem_usage")
168  .desc("Number of bytes of host memory used")
169  .prereq(hostMemory)
170  ;
171 
172  hostSeconds
174  .name("host_seconds")
175  .desc("Real time elapsed on the host")
176  .precision(2)
177  ;
178 
179  hostTickRate
180  .name("host_tick_rate")
181  .desc("Simulator tick rate (ticks/s)")
182  .precision(0)
183  ;
184 
186  hostInstRate = simInsts / hostSeconds;
187  hostOpRate = simOps / hostSeconds;
188  hostTickRate = simTicks / hostSeconds;
189 
190  registerResetCallback([]() {
191  statTime.setTimer();
192  startTick = curTick();
193  });
194 }
195 
196 void
198 {
199  static Global global;
200 }
201 
205 class StatEvent : public GlobalEvent
206 {
207  private:
208  bool dump;
209  bool reset;
211 
212  public:
213  StatEvent(Tick _when, bool _dump, bool _reset, Tick _repeat)
214  : GlobalEvent(_when, Stat_Event_Pri, 0),
215  dump(_dump), reset(_reset), repeat(_repeat)
216  {
217  }
218 
219  virtual void
221  {
222  if (dump)
223  Stats::dump();
224 
225  if (reset)
226  Stats::reset();
227 
228  if (repeat) {
229  Stats::schedStatEvent(dump, reset, curTick() + repeat, repeat);
230  }
231  }
232 
233  const char *description() const { return "GlobalStatEvent"; }
234 };
235 
236 void
237 schedStatEvent(bool dump, bool reset, Tick when, Tick repeat)
238 {
239  // simQuantum is being added to the time when the stats would be
240  // dumped so as to ensure that this event happens only after the next
241  // sync amongst the event queues. Asingle event queue simulation
242  // should remain unaffected.
243  dumpEvent = new StatEvent(when + simQuantum, dump, reset, repeat);
244 }
245 
246 void
248 {
249  /*
250  * If the period is set to 0, then we do not want to dump periodically,
251  * thus we deschedule the event. Else, if the period is not 0, but the event
252  * has already been scheduled, we need to get rid of the old event before we
253  * create a new one, as the old event will no longer be moved forward in the
254  * event that we resume from a checkpoint.
255  */
256  if (dumpEvent != NULL && (period == 0 || dumpEvent->scheduled())) {
257  // Event should AutoDelete, so we do not need to free it.
259  }
260 
261  /*
262  * If the period is not 0, we schedule the event. If this is called with a
263  * period that is less than the current tick, then we shift the first dump
264  * by curTick. This ensures that we do not schedule the event is the past.
265  */
266  if (period != 0) {
267  // Schedule the event
268  if (period >= curTick()) {
269  schedStatEvent(true, true, (Tick)period, (Tick)period);
270  } else {
271  schedStatEvent(true, true, (Tick)period + curTick(), (Tick)period);
272  }
273  }
274 }
275 
276 void
278 {
279  /*
280  * If the dumpEvent has been scheduled, but is scheduled in the past, then
281  * we need to shift the event to be at a valid point in time. Therefore, we
282  * shift the event by curTick.
283  */
284  if (dumpEvent != NULL &&
285  (dumpEvent->scheduled() && dumpEvent->when() < curTick())) {
286  // shift by curTick() and reschedule
287  Tick _when = dumpEvent->when();
288  dumpEvent->reschedule(_when + curTick());
289  }
290 }
291 
292 } // namespace Stats
Stats::statElapsedTicks
Tick statElapsedTicks()
Definition: stat_control.cc:84
Stats::ValueBase::scalar
Derived & scalar(T &value)
Definition: statistics.hh:864
BaseCPU::numSimulatedInsts
static int numSimulatedInsts()
Definition: cpu_dummy.hh:46
Stats::Global::hostSeconds
Stats::Value hostSeconds
Definition: stat_control.cc:101
Stats::periodicStatDump
void periodicStatDump(Tick period)
Schedule periodic statistics dumping.
Definition: stat_control.cc:247
time.hh
Stats::StatEvent::repeat
Tick repeat
Definition: stat_control.cc:210
Stats::initSimStats
void initSimStats()
Definition: stat_control.cc:197
Stats::ValueBase::functor
Derived & functor(const T &func)
Definition: statistics.hh:873
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
Stats::Value
Definition: statistics.hh:2561
Stats::StatEvent::description
const char * description() const
Definition: stat_control.cc:233
Stats::reset
void reset()
Definition: statistics.cc:569
BaseGlobalEvent::deschedule
void deschedule()
Definition: global_event.cc:84
Stats::StatEvent::dump
bool dump
Definition: stat_control.cc:208
Stats::StatEvent::process
virtual void process()
Definition: stat_control.cc:220
SimClock::Frequency
Tick Frequency
The simulated frequency of curTick(). (In ticks per second)
Definition: core.cc:46
Stats::Global::simInsts
Stats::Value simInsts
Definition: stat_control.cc:103
simFreq
Stats::Value simFreq
Definition: stat_control.cc:64
BaseGlobalEvent::when
Tick when() const
Definition: global_event.hh:136
BaseGlobalEvent::reschedule
void reschedule(Tick when)
Definition: global_event.cc:97
Stats::Global::hostTickRate
Stats::Formula hostTickRate
Definition: stat_control.cc:99
Stats::DataWrap::prereq
Derived & prereq(const Stat &prereq)
Set the prerequisite stat and marks this stat to print at the end of simulation.
Definition: statistics.hh:345
simSeconds
Stats::Formula simSeconds
Definition: stat_control.cc:61
Stats::registerResetCallback
void registerResetCallback(const std::function< void()> &callback)
Register a callback that should be called whenever statistics are reset.
Definition: statistics.cc:537
statistics.hh
hostinfo.hh
Stats::statElapsedTime
double statElapsedTime()
Definition: stat_control.cc:74
Stats::Global::simOps
Stats::Value simOps
Definition: stat_control.cc:104
Stats::updateEvents
void updateEvents()
Update the events after resuming from a checkpoint.
Definition: stat_control.cc:277
Stats::StatEvent::StatEvent
StatEvent(Tick _when, bool _dump, bool _reset, Tick _repeat)
Definition: stat_control.cc:213
Stats::Global::hostInstRate
Stats::Formula hostInstRate
Definition: stat_control.cc:97
Stats::DataWrap::name
Derived & name(const std::string &name)
Set the name and marks this stat to print at the end of simulation.
Definition: statistics.hh:274
Stats::schedStatEvent
void schedStatEvent(bool dump, bool reset, Tick when, Tick repeat)
Schedule statistics dumping.
Definition: stat_control.cc:237
Stats::Global::hostMemory
Stats::Value hostMemory
Definition: stat_control.cc:100
finalTick
Stats::Value finalTick
Definition: stat_control.cc:63
stat_control.hh
Time::setTimer
void setTimer()
Use this to set time for the purposes of time measurement (use a monotonic clock if it is available.
Definition: time.hh:90
Stats::Global
Definition: stat_control.cc:95
Stats::statFinalTick
Tick statFinalTick()
Definition: stat_control.cc:90
Stats::startTick
Tick startTick
Definition: stat_control.cc:69
BaseGlobalEvent::scheduled
bool scheduled() const
Definition: global_event.hh:126
Stats::StatEvent::reset
bool reset
Definition: stat_control.cc:209
base.hh
std
Overload hash function for BasicBlockRange type.
Definition: vec_reg.hh:587
Stats::DataWrap::precision
Derived & precision(int _precision)
Set the precision and marks this stat to print at the end of simulation.
Definition: statistics.hh:319
Time
Definition: time.hh:45
Stats::dump
void dump()
Dump all statistics data to the registered outputs.
Definition: statistics.cc:560
Stats::Formula
A formula for statistics that is calculated when printed.
Definition: statistics.hh:3037
Stats::StatEvent
Event to dump and/or reset the statistics.
Definition: stat_control.cc:205
simQuantum
Tick simQuantum
Simulation Quantum for multiple eventq simulation.
Definition: eventq.cc:47
simTicks
Stats::Value simTicks
Definition: stat_control.cc:62
Stats
Definition: statistics.cc:61
BaseCPU::numSimulatedOps
static int numSimulatedOps()
Definition: cpu_dummy.hh:47
Stats::statTime
Time statTime(true)
memUsage
uint64_t memUsage()
Determine the simulator process' total virtual memory usage.
Definition: hostinfo.cc:99
global_event.hh
Stats::Global::hostOpRate
Stats::Formula hostOpRate
Definition: stat_control.cc:98
Stats::DataWrap::desc
Derived & desc(const std::string &_desc)
Set the description and marks this stat to print at the end of simulation.
Definition: statistics.hh:307
GlobalEvent
The main global event class.
Definition: global_event.hh:173
Stats::dumpEvent
GlobalEvent * dumpEvent
Definition: stat_control.cc:71
callback.hh
curTick
Tick curTick()
The current simulated tick.
Definition: core.hh:45

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17