gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules 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
82  update() const
83  {
84  // both tick and cycle are up-to-date and we are done, note
85  // that the >= is important as it captures cases where tick
86  // has already passed curTick()
87  if (tick >= curTick())
88  return;
89 
90  // optimise for the common case and see if the tick should be
91  // advanced by a single clock period
92  tick += clockPeriod();
93  ++cycle;
94 
95  // see if we are done at this point
96  if (tick >= curTick())
97  return;
98 
99  // if not, we have to recalculate the cycle and tick, we
100  // perform the calculations in terms of relative cycles to
101  // allow changes to the clock period in the future
102  Cycles elapsedCycles(divCeil(curTick() - tick, clockPeriod()));
103  cycle += elapsedCycles;
104  tick += elapsedCycles * clockPeriod();
105  }
106 
111 
112  protected:
113 
118  Clocked(ClockDomain &clk_domain)
119  : tick(0), cycle(0), clockDomain(clk_domain)
120  {
121  // Register with the clock domain, so that if the clock domain
122  // frequency changes, we can update this object's tick.
123  clockDomain.registerWithClockDomain(this);
124  }
125 
126  Clocked(Clocked &) = delete;
127  Clocked &operator=(Clocked &) = delete;
128 
132  virtual ~Clocked() { }
133 
139  void
140  resetClock() const
141  {
142  Cycles elapsedCycles(divCeil(curTick(), clockPeriod()));
143  cycle = elapsedCycles;
144  tick = elapsedCycles * clockPeriod();
145  }
146 
151  virtual void clockPeriodUpdated() {}
152 
153  public:
154 
158  void
160  {
161  update();
163  }
164 
179  Tick
180  clockEdge(Cycles cycles=Cycles(0)) const
181  {
182  // align tick to the next clock edge
183  update();
184 
185  // figure out when this future cycle is
186  return tick + clockPeriod() * cycles;
187  }
188 
197  Cycles
198  curCycle() const
199  {
200  // align cycle to the next clock edge.
201  update();
202 
203  return cycle;
204  }
205 
216  Tick nextCycle() const { return clockEdge(Cycles(1)); }
217 
218  uint64_t frequency() const { return SimClock::Frequency / clockPeriod(); }
219 
220  Tick clockPeriod() const { return clockDomain.clockPeriod(); }
221 
222  double voltage() const { return clockDomain.voltage(); }
223 
224  Cycles
226  {
227  return Cycles(divCeil(t, clockPeriod()));
228  }
229 
230  Tick cyclesToTicks(Cycles c) const { return clockPeriod() * c; }
231 };
232 
237 class ClockedObject : public SimObject, public Clocked
238 {
239  public:
240  ClockedObject(const ClockedObjectParams *p);
241 
243  typedef ClockedObjectParams Params;
244  const Params *
245  params() const
246  {
247  return reinterpret_cast<const Params*>(_params);
248  }
249 
250  void serialize(CheckpointOut &cp) const override;
251  void unserialize(CheckpointIn &cp) override;
252 
253  Enums::PwrState pwrState() const { return _currPwrState; }
254 
255  std::string
256  pwrStateName() const
257  {
258  return Enums::PwrStateStrings[_currPwrState];
259  }
260 
262  std::vector<double> pwrStateWeights() const;
263 
270  void computeStats();
271 
272  void pwrState(Enums::PwrState);
273 
274  protected:
275 
277  Enums::PwrState _currPwrState;
278 
280 
282  {
284 
285  void regStats() override;
286  void preDumpStats() override;
287 
292  } stats;
293 };
294 
295 #endif //__SIM_CLOCKED_OBJECT_HH__
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
ClockedObjectParams Params
Parameters of ClockedObject.
virtual ~Clocked()
Virtual destructor due to inheritance.
A vector of scalar stats.
Definition: statistics.hh:2550
Definition: cprintf.cc:42
Tick clockPeriod() const
double voltage() const
Tick Frequency
The simulated frequency of curTick(). (In ticks per second)
Definition: core.cc:49
std::string pwrStateName() const
const Params * params() const
This is a simple scalar statistic, like a counter.
Definition: statistics.hh:2508
Clocked(ClockDomain &clk_domain)
Create a clocked object and set the clock domain based on the parameters.
Tick cyclesToTicks(Cycles c) const
void resetClock() const
Reset the object&#39;s clock using the current global tick value.
Tick curTick()
The current simulated tick.
Definition: core.hh:47
Stats::Distribution pwrStateClkGateDist
uint64_t frequency() 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:2592
void serialize(const ThreadContext &tc, CheckpointOut &cp)
Thread context serialization helpers.
Cycles curCycle() const
Determine the current cycle, corresponding to a tick aligned to a clock edge.
ClockDomain declarations.
Tick nextCycle() const
Based on the clock of the object, determine the start tick of the first cycle that is at least one cy...
Helper class for objects that need to be clocked.
Statistics container.
Definition: group.hh:85
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...
Enums::PwrState pwrState() const
Bitfield< 29 > c
ClockDomain & clockDomain
The clock domain this clocked object belongs to.
virtual void clockPeriodUpdated()
A hook subclasses can implement so they can do any extra work that&#39;s needed when the clock rate is ch...
The ClockDomain provides clock to group of clocked objects bundled under the same clock domain...
Definition: clock_domain.hh:73
Cycles ticksToCycles(Tick t) const
std::ostream CheckpointOut
Definition: serialize.hh:68
Cycles cycle
void updateClockPeriod()
Update the tick to the current tick.
T divCeil(const T &a, const U &b)
Definition: intmath.hh:153
void registerWithClockDomain(Clocked *c)
Register a Clocked object with this ClockDomain.
void unserialize(ThreadContext &tc, CheckpointIn &cp)
Clocked & operator=(Clocked &)=delete
Bitfield< 5 > t
Bitfield< 0 > p
void update() const
Align cycle and tick to the next clock edge if not already done.
Enums::PwrState _currPwrState
To keep track of the current power state.
double voltage() const
Get the current voltage this clock domain operates at.
Definition: clock_domain.cc:76
Abstract superclass for simulation objects.
Definition: sim_object.hh:96
Tick clockPeriod() const
Get the clock period.

Generated on Fri Feb 28 2020 16:27:02 for gem5 by doxygen 1.8.13