gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
clocked_object.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2013, 2015-2016 ARM Limited
3  * Copyright (c) 2013 Cornell University
4  * All rights reserved
5  *
6  * The license below extends only to copyright in the software and shall
7  * not be construed as granting a license to any other intellectual
8  * property including but not limited to intellectual property relating
9  * to a hardware implementation of the functionality of the software
10  * licensed hereunder. You may use the software subject to the license
11  * terms below provided that you ensure that this notice is replicated
12  * unmodified and in its entirety in all distributions of the software,
13  * modified or unmodified, in source code or in binary form.
14  *
15  * Redistribution and use in source and binary forms, with or without
16  * modification, are permitted provided that the following conditions are
17  * met: redistributions of source code must retain the above copyright
18  * notice, this list of conditions and the following disclaimer;
19  * redistributions in binary form must reproduce the above copyright
20  * notice, this list of conditions and the following disclaimer in the
21  * documentation and/or other materials provided with the distribution;
22  * neither the name of the copyright holders nor the names of its
23  * contributors may be used to endorse or promote products derived from
24  * this software without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37  *
38  * Authors: Andreas Hansson
39  * Christopher Torng
40  * Akash Bagdia
41  * David Guillen Fandos
42  */
43 
49 #ifndef __SIM_CLOCKED_OBJECT_HH__
50 #define __SIM_CLOCKED_OBJECT_HH__
51 
52 #include "base/callback.hh"
53 #include "base/intmath.hh"
54 #include "enums/PwrState.hh"
55 #include "params/ClockedObject.hh"
56 #include "sim/core.hh"
57 #include "sim/clock_domain.hh"
58 #include "sim/sim_object.hh"
59 
65 class Clocked
66 {
67 
68  private:
69  // the tick value of the next clock edge (>= curTick()) at the
70  // time of the last call to update()
71  mutable Tick tick;
72 
73  // The cycle counter value corresponding to the current value of
74  // 'tick'
75  mutable Cycles cycle;
76 
81  void update() const
82  {
83  // both tick and cycle are up-to-date and we are done, note
84  // that the >= is important as it captures cases where tick
85  // has already passed curTick()
86  if (tick >= curTick())
87  return;
88 
89  // optimise for the common case and see if the tick should be
90  // advanced by a single clock period
91  tick += clockPeriod();
92  ++cycle;
93 
94  // see if we are done at this point
95  if (tick >= curTick())
96  return;
97 
98  // if not, we have to recalculate the cycle and tick, we
99  // perform the calculations in terms of relative cycles to
100  // allow changes to the clock period in the future
101  Cycles elapsedCycles(divCeil(curTick() - tick, clockPeriod()));
102  cycle += elapsedCycles;
103  tick += elapsedCycles * clockPeriod();
104  }
105 
110 
111  protected:
112 
117  Clocked(ClockDomain &clk_domain)
118  : tick(0), cycle(0), clockDomain(clk_domain)
119  {
120  // Register with the clock domain, so that if the clock domain
121  // frequency changes, we can update this object's tick.
123  }
124 
125  Clocked(Clocked &) = delete;
126  Clocked &operator=(Clocked &) = delete;
127 
131  virtual ~Clocked() { }
132 
138  void resetClock() const
139  {
140  Cycles elapsedCycles(divCeil(curTick(), clockPeriod()));
141  cycle = elapsedCycles;
142  tick = elapsedCycles * clockPeriod();
143  }
144 
145  public:
146 
151  inline void updateClockPeriod() const
152  {
153  update();
154  }
155 
170  inline Tick clockEdge(Cycles cycles = Cycles(0)) const
171  {
172  // align tick to the next clock edge
173  update();
174 
175  // figure out when this future cycle is
176  return tick + clockPeriod() * cycles;
177  }
178 
187  inline Cycles curCycle() const
188  {
189  // align cycle to the next clock edge.
190  update();
191 
192  return cycle;
193  }
194 
205  Tick nextCycle() const
206  { return clockEdge(Cycles(1)); }
207 
208  inline uint64_t frequency() const
209  {
210  return SimClock::Frequency / clockPeriod();
211  }
212 
213  inline Tick clockPeriod() const
214  {
215  return clockDomain.clockPeriod();
216  }
217 
218  inline double voltage() const
219  {
220  return clockDomain.voltage();
221  }
222 
223  inline Cycles ticksToCycles(Tick t) const
224  { return Cycles(divCeil(t, clockPeriod())); }
225 
226  inline Tick cyclesToTicks(Cycles c) const
227  { return clockPeriod() * c; }
228 };
229 
235  : public SimObject, public Clocked
236 {
237  public:
238  ClockedObject(const ClockedObjectParams *p);
239 
241  typedef ClockedObjectParams Params;
242  const Params* params() const
243  { return reinterpret_cast<const Params*>(_params); }
244 
245  void serialize(CheckpointOut &cp) const override;
246  void unserialize(CheckpointIn &cp) override;
247 
248  inline Enums::PwrState pwrState() const
249  { return _currPwrState; }
250 
251  inline std::string pwrStateName() const
252  { return Enums::PwrStateStrings[_currPwrState]; }
253 
256 
263  void computeStats();
264 
265  void pwrState(Enums::PwrState);
266  void regStats() override;
267 
268  protected:
269 
271  Enums::PwrState _currPwrState;
272 
274 
278 
279 };
280 
282 {
284  public:
286  virtual void process() { co->computeStats(); };
287 };
288 
289 #endif //__SIM_CLOCKED_OBJECT_HH__
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
Generic callback class.
Definition: callback.hh:41
void computeStats()
Record stats values like state residency by computing the time difference from previous update...
ClockedObjectParams Params
Parameters of ClockedObject.
const Params * params() const
Cycles ticksToCycles(Tick t) const
Tick cyclesToTicks(Cycles c) const
virtual ~Clocked()
Virtual destructor due to inheritance.
double voltage() const
Get the current voltage this clock domain operates at.
Definition: clock_domain.cc:75
uint64_t frequency() const
A vector of scalar stats.
Definition: statistics.hh:2499
ClockedObjectDumpCallback(ClockedObject *co_t)
void resetClock() const
Reset the object's clock using the current global tick value.
Tick Frequency
The simulated frequency of curTick(). (In ticks per second)
Definition: core.cc:47
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2475
Clocked(ClockDomain &clk_domain)
Create a clocked object and set the clock domain based on the parameters.
Stats::Distribution pwrStateClkGateDist
void updateClockPeriod() const
Update the tick to the current tick.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Cycles curCycle() const
Determine the current cycle, corresponding to a tick aligned to a clock edge.
Tick clockEdge(Cycles cycles=Cycles(0)) const
Determine the tick when a cycle begins, by default the current one, but the argument also enables the...
Tick curTick()
The current simulated tick.
Definition: core.hh:47
Enums::PwrState pwrState() const
std::string pwrStateName() const
double voltage() const
uint64_t Tick
Tick count type.
Definition: types.hh:63
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
A simple distribution stat.
Definition: statistics.hh:2523
void serialize(CheckpointOut &cp) const override
Serialize an object.
Stats::Vector pwrStateResidencyTicks
ClockDomain declarations.
void update() const
Align cycle and tick to the next clock edge if not already done.
Helper class for objects that need to be clocked.
virtual void process()
virtual process function that is invoked when the callback queue is executed.
Tick clockPeriod() const
Bitfield< 29 > c
Definition: miscregs.hh:1365
ClockDomain & clockDomain
The clock domain this clocked object belongs to.
The ClockDomain provides clock to group of clocked objects bundled under the same clock domain...
Definition: clock_domain.hh:73
std::ostream CheckpointOut
Definition: serialize.hh:67
Cycles cycle
std::vector< double > pwrStateWeights() const
Returns the percentage residency for each power state.
const SimObjectParams * _params
Cached copy of the object parameters.
Definition: sim_object.hh:107
T divCeil(const T &a, const U &b)
Definition: intmath.hh:198
void registerWithClockDomain(Clocked *c)
Register a Clocked object with this ClockDomain.
Tick nextCycle() const
Based on the clock of the object, determine the start tick of the first cycle that is at least one cy...
Clocked & operator=(Clocked &)=delete
Stats::Scalar numPwrStateTransitions
Bitfield< 5 > t
Definition: miscregs.hh:1382
Bitfield< 0 > p
Enums::PwrState _currPwrState
To keep track of the current power state.
void regStats() override
Register statistics for this object.
Abstract superclass for simulation objects.
Definition: sim_object.hh:94
ClockedObject(const ClockedObjectParams *p)
Tick clockPeriod() const
Get the clock period.

Generated on Fri Jun 9 2017 13:03:51 for gem5 by doxygen 1.8.6