gem5  v22.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/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
void reschedule(Tick when)
bool scheduled() const
The main global event class.
Event to dump and/or reset the statistics.
Definition: stat_control.cc:75
StatEvent(Tick _when, bool _dump, bool _reset, Tick _repeat)
Definition: stat_control.cc:82
const char * description() const
Global events and related declarations.
static const Priority Stat_Event_Pri
Statistics events (dump, reset, etc.) come after everything else, but before exit.
Definition: eventq.hh:219
GlobalEvent * dumpEvent
Definition: stat_control.cc:64
void schedStatEvent(bool dump, bool reset, Tick when, Tick repeat)
Schedule statistics dumping.
void periodicStatDump(Tick period)
Schedule periodic statistics dumping.
void updateEvents()
Update the events after resuming from a checkpoint.
void dump()
Dump all statistics data to the registered outputs.
Definition: statistics.cc:301
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Tick simQuantum
Simulation Quantum for multiple eventq simulation.
Definition: eventq.cc:48
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46
uint64_t Tick
Tick count type.
Definition: types.hh:58
GEM5_DEPRECATED_NAMESPACE(GuestABI, guest_abi)
Declaration of Statistics objects.

Generated on Wed Dec 21 2022 10:22:40 for gem5 by doxygen 1.9.1