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

Generated on Tue Sep 21 2021 12:25:48 for gem5 by doxygen 1.8.17