gem5  v21.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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/statistics.hh"
54 #include "base/time.hh"
55 #include "sim/global_event.hh"
56 
57 namespace Stats {
58 
60 
61 void
63 {
64 }
65 
69 class StatEvent : public GlobalEvent
70 {
71  private:
72  bool dump;
73  bool reset;
75 
76  public:
77  StatEvent(Tick _when, bool _dump, bool _reset, Tick _repeat)
78  : GlobalEvent(_when, Stat_Event_Pri, 0),
79  dump(_dump), reset(_reset), repeat(_repeat)
80  {
81  }
82 
83  virtual void
85  {
86  if (dump)
87  Stats::dump();
88 
89  if (reset)
90  Stats::reset();
91 
92  if (repeat) {
94  }
95  }
96 
97  const char *description() const { return "GlobalStatEvent"; }
98 };
99 
100 void
101 schedStatEvent(bool dump, bool reset, Tick when, Tick repeat)
102 {
103  // simQuantum is being added to the time when the stats would be
104  // dumped so as to ensure that this event happens only after the next
105  // sync amongst the event queues. Asingle event queue simulation
106  // should remain unaffected.
107  dumpEvent = new StatEvent(when + simQuantum, dump, reset, repeat);
108 }
109 
110 void
112 {
113  /*
114  * If the period is set to 0, then we do not want to dump periodically,
115  * thus we deschedule the event. Else, if the period is not 0, but the event
116  * has already been scheduled, we need to get rid of the old event before we
117  * create a new one, as the old event will no longer be moved forward in the
118  * event that we resume from a checkpoint.
119  */
120  if (dumpEvent != NULL && (period == 0 || dumpEvent->scheduled())) {
121  // Event should AutoDelete, so we do not need to free it.
123  }
124 
125  /*
126  * If the period is not 0, we schedule the event. If this is called with a
127  * period that is less than the current tick, then we shift the first dump
128  * by curTick. This ensures that we do not schedule the event is the past.
129  */
130  if (period != 0) {
131  // Schedule the event
132  if (period >= curTick()) {
133  schedStatEvent(true, true, (Tick)period, (Tick)period);
134  } else {
135  schedStatEvent(true, true, (Tick)period + curTick(), (Tick)period);
136  }
137  }
138 }
139 
140 void
142 {
143  /*
144  * If the dumpEvent has been scheduled, but is scheduled in the past, then
145  * we need to shift the event to be at a valid point in time. Therefore, we
146  * shift the event by curTick.
147  */
148  if (dumpEvent != NULL &&
149  (dumpEvent->scheduled() && dumpEvent->when() < curTick())) {
150  // shift by curTick() and reschedule
151  Tick _when = dumpEvent->when();
152  dumpEvent->reschedule(_when + curTick());
153  }
154 }
155 
156 } // namespace Stats
EventBase::Stat_Event_Pri
static const Priority Stat_Event_Pri
Statistics events (dump, reset, etc.) come after everything else, but before exit.
Definition: eventq.hh:216
Stats::periodicStatDump
void periodicStatDump(Tick period)
Schedule periodic statistics dumping.
Definition: stat_control.cc:111
time.hh
Stats::StatEvent::repeat
Tick repeat
Definition: stat_control.cc:74
Stats::initSimStats
void initSimStats()
Definition: stat_control.cc:62
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:59
Stats::StatEvent::description
const char * description() const
Definition: stat_control.cc:97
Stats::reset
void reset()
Definition: statistics.cc:299
BaseGlobalEvent::deschedule
void deschedule()
Definition: global_event.cc:84
Stats::StatEvent::dump
bool dump
Definition: stat_control.cc:72
Stats::StatEvent::process
virtual void process()
Definition: stat_control.cc:84
BaseGlobalEvent::when
Tick when() const
Definition: global_event.hh:136
BaseGlobalEvent::reschedule
void reschedule(Tick when)
Definition: global_event.cc:97
statistics.hh
Stats::updateEvents
void updateEvents()
Update the events after resuming from a checkpoint.
Definition: stat_control.cc:141
Stats::StatEvent::StatEvent
StatEvent(Tick _when, bool _dump, bool _reset, Tick _repeat)
Definition: stat_control.cc:77
Stats::schedStatEvent
void schedStatEvent(bool dump, bool reset, Tick when, Tick repeat)
Schedule statistics dumping.
Definition: stat_control.cc:101
stat_control.hh
BaseGlobalEvent::scheduled
bool scheduled() const
Definition: global_event.hh:126
Stats::StatEvent::reset
bool reset
Definition: stat_control.cc:73
Stats::dump
void dump()
Dump all statistics data to the registered outputs.
Definition: statistics.cc:290
Stats::StatEvent
Event to dump and/or reset the statistics.
Definition: stat_control.cc:69
simQuantum
Tick simQuantum
Simulation Quantum for multiple eventq simulation.
Definition: eventq.cc:46
Stats
Definition: statistics.cc:53
curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:43
global_event.hh
GlobalEvent
The main global event class.
Definition: global_event.hh:173
Stats::dumpEvent
GlobalEvent * dumpEvent
Definition: stat_control.cc:59
callback.hh

Generated on Tue Mar 23 2021 19:41:28 for gem5 by doxygen 1.8.17