gem5  [DEVELOP-FOR-23.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 gem5
58 {
59 
60 namespace statistics
61 {
62 
64 
65 void
67 {
68 }
69 
73 class StatEvent : public GlobalEvent
74 {
75  private:
76  bool dump;
77  bool reset;
79 
80  public:
81  StatEvent(Tick _when, bool _dump, bool _reset, Tick _repeat)
82  : GlobalEvent(_when, Stat_Event_Pri, 0),
83  dump(_dump), reset(_reset), repeat(_repeat)
84  {
85  }
86 
87  virtual void
89  {
90  if (dump)
92 
93  if (reset)
95 
96  if (repeat) {
98  repeat);
99  }
100  }
101 
102  const char *description() const { return "GlobalStatEvent"; }
103 };
104 
105 void
106 schedStatEvent(bool dump, bool reset, Tick when, Tick repeat)
107 {
108  // simQuantum is being added to the time when the stats would be
109  // dumped so as to ensure that this event happens only after the next
110  // sync amongst the event queues. Asingle event queue simulation
111  // should remain unaffected.
112  dumpEvent = new StatEvent(when + simQuantum, dump, reset, repeat);
113 }
114 
115 void
117 {
118  /*
119  * If the period is set to 0, then we do not want to dump periodically,
120  * thus we deschedule the event. Else, if the period is not 0, but the
121  * event has already been scheduled, we need to get rid of the old event
122  * before we create a new one, as the old event will no longer be moved
123  * forward in the event that we resume from a checkpoint.
124  */
125  if (dumpEvent != NULL && (period == 0 || dumpEvent->scheduled())) {
126  // Event should AutoDelete, so we do not need to free it.
128  }
129 
130  /*
131  * If the period is not 0, we schedule the event. If this is called with a
132  * period that is less than the current tick, then we shift the first dump
133  * by curTick. This ensures that we do not schedule the event is the past.
134  */
135  if (period != 0) {
136  // Schedule the event
137  if (period >= curTick()) {
138  schedStatEvent(true, true, (Tick)period, (Tick)period);
139  } else {
140  schedStatEvent(true, true, (Tick)period + curTick(), (Tick)period);
141  }
142  }
143 }
144 
145 void
147 {
148  /*
149  * If the dumpEvent has been scheduled, but is scheduled in the past, then
150  * we need to shift the event to be at a valid point in time. Therefore, we
151  * shift the event by curTick.
152  */
153  if (dumpEvent != NULL &&
154  (dumpEvent->scheduled() && dumpEvent->when() < curTick())) {
155  // shift by curTick() and reschedule
156  Tick _when = dumpEvent->when();
157  dumpEvent->reschedule(_when + curTick());
158  }
159 }
160 
161 } // namespace statistics
162 } // namespace gem5
gem5::curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46
gem5::statistics::StatEvent
Event to dump and/or reset the statistics.
Definition: stat_control.cc:73
time.hh
gem5::BaseGlobalEvent::reschedule
void reschedule(Tick when)
Definition: global_event.cc:100
gem5::statistics::updateEvents
void updateEvents()
Update the events after resuming from a checkpoint.
Definition: stat_control.cc:146
gem5::BaseGlobalEvent::scheduled
bool scheduled() const
Definition: global_event.hh:129
gem5::statistics::initSimStats
void initSimStats()
Definition: stat_control.cc:66
statistics.hh
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::statistics::StatEvent::repeat
Tick repeat
Definition: stat_control.cc:78
gem5::statistics::reset
void reset()
Definition: statistics.cc:309
gem5::statistics::dump
void dump()
Dump all statistics data to the registered outputs.
Definition: statistics.cc:300
gem5::simQuantum
Tick simQuantum
Simulation Quantum for multiple eventq simulation.
Definition: eventq.cc:48
gem5::BaseGlobalEvent::when
Tick when() const
Definition: global_event.hh:139
gem5::statistics::StatEvent::description
const char * description() const
Definition: stat_control.cc:102
gem5::GlobalEvent
The main global event class.
Definition: global_event.hh:178
gem5::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:222
gem5::BaseGlobalEvent::deschedule
void deschedule()
Definition: global_event.cc:87
stat_control.hh
gem5::statistics::periodicStatDump
void periodicStatDump(Tick period)
Schedule periodic statistics dumping.
Definition: stat_control.cc:116
gem5::statistics::StatEvent::process
virtual void process()
Definition: stat_control.cc:88
gem5::statistics::dumpEvent
GlobalEvent * dumpEvent
Definition: stat_control.cc:63
gem5::statistics::StatEvent::dump
bool dump
Definition: stat_control.cc:76
gem5::statistics::StatEvent::StatEvent
StatEvent(Tick _when, bool _dump, bool _reset, Tick _repeat)
Definition: stat_control.cc:81
gem5::statistics::StatEvent::reset
bool reset
Definition: stat_control.cc:77
global_event.hh
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::statistics::schedStatEvent
void schedStatEvent(bool dump, bool reset, Tick when, Tick repeat)
Schedule statistics dumping.
Definition: stat_control.cc:106
callback.hh

Generated on Sun Jul 30 2023 01:57:00 for gem5 by doxygen 1.8.17