gem5  v20.1.0.0
clocked_object.hh
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012-2013, 2015-2017, 2019-2020 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 
44 #ifndef __SIM_CLOCKED_OBJECT_HH__
45 #define __SIM_CLOCKED_OBJECT_HH__
46 
47 
48 #include "params/ClockedObject.hh"
49 #include "sim/core.hh"
50 #include "sim/clock_domain.hh"
51 #include "sim/power_state.hh"
52 #include "sim/sim_object.hh"
53 
59 class Clocked
60 {
61 
62  private:
63  // the tick value of the next clock edge (>= curTick()) at the
64  // time of the last call to update()
65  mutable Tick tick;
66 
67  // The cycle counter value corresponding to the current value of
68  // 'tick'
69  mutable Cycles cycle;
70 
75  void
76  update() const
77  {
78  // both tick and cycle are up-to-date and we are done, note
79  // that the >= is important as it captures cases where tick
80  // has already passed curTick()
81  if (tick >= curTick())
82  return;
83 
84  // optimise for the common case and see if the tick should be
85  // advanced by a single clock period
86  tick += clockPeriod();
87  ++cycle;
88 
89  // see if we are done at this point
90  if (tick >= curTick())
91  return;
92 
93  // if not, we have to recalculate the cycle and tick, we
94  // perform the calculations in terms of relative cycles to
95  // allow changes to the clock period in the future
96  Cycles elapsedCycles(divCeil(curTick() - tick, clockPeriod()));
97  cycle += elapsedCycles;
98  tick += elapsedCycles * clockPeriod();
99  }
100 
105 
106  protected:
107 
112  Clocked(ClockDomain &clk_domain)
113  : tick(0), cycle(0), clockDomain(clk_domain)
114  {
115  // Register with the clock domain, so that if the clock domain
116  // frequency changes, we can update this object's tick.
118  }
119 
120  Clocked(Clocked &) = delete;
121  Clocked &operator=(Clocked &) = delete;
122 
126  virtual ~Clocked() { }
127 
133  void
134  resetClock() const
135  {
136  Cycles elapsedCycles(divCeil(curTick(), clockPeriod()));
137  cycle = elapsedCycles;
138  tick = elapsedCycles * clockPeriod();
139  }
140 
145  virtual void clockPeriodUpdated() {}
146 
147  public:
148 
152  void
154  {
155  update();
157  }
158 
173  Tick
174  clockEdge(Cycles cycles=Cycles(0)) const
175  {
176  // align tick to the next clock edge
177  update();
178 
179  // figure out when this future cycle is
180  return tick + clockPeriod() * cycles;
181  }
182 
191  Cycles
192  curCycle() const
193  {
194  // align cycle to the next clock edge.
195  update();
196 
197  return cycle;
198  }
199 
210  Tick nextCycle() const { return clockEdge(Cycles(1)); }
211 
212  uint64_t frequency() const { return SimClock::Frequency / clockPeriod(); }
213 
214  Tick clockPeriod() const { return clockDomain.clockPeriod(); }
215 
216  double voltage() const { return clockDomain.voltage(); }
217 
218  Cycles
220  {
221  return Cycles(divCeil(t, clockPeriod()));
222  }
223 
224  Tick cyclesToTicks(Cycles c) const { return clockPeriod() * c; }
225 };
226 
231 class ClockedObject : public SimObject, public Clocked
232 {
233  public:
234  ClockedObject(const ClockedObjectParams *p);
235 
237  typedef ClockedObjectParams Params;
238  const Params *
239  params() const
240  {
241  return reinterpret_cast<const Params*>(_params);
242  }
243 
244  void serialize(CheckpointOut &cp) const override;
245  void unserialize(CheckpointIn &cp) override;
246 
248 };
249 
250 #endif //__SIM_CLOCKED_OBJECT_HH__
power_state.hh
Clocked
Helper class for objects that need to be clocked.
Definition: clocked_object.hh:59
ClockedObject::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: clocked_object.cc:56
Clocked::clockDomain
ClockDomain & clockDomain
The clock domain this clocked object belongs to.
Definition: clocked_object.hh:104
Clocked::tick
Tick tick
Definition: clocked_object.hh:65
ClockDomain::voltage
double voltage() const
Get the current voltage this clock domain operates at.
Definition: clock_domain.cc:70
Clocked::voltage
double voltage() const
Definition: clocked_object.hh:216
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
Clocked::operator=
Clocked & operator=(Clocked &)=delete
ClockedObject::params
const Params * params() const
Definition: clocked_object.hh:239
ClockedObject::ClockedObject
ClockedObject(const ClockedObjectParams *p)
Definition: clocked_object.cc:43
ClockDomain
The ClockDomain provides clock to group of clocked objects bundled under the same clock domain.
Definition: clock_domain.hh:68
Clocked::Clocked
Clocked(ClockDomain &clk_domain)
Create a clocked object and set the clock domain based on the parameters.
Definition: clocked_object.hh:112
Clocked::clockPeriodUpdated
virtual void clockPeriodUpdated()
A hook subclasses can implement so they can do any extra work that's needed when the clock rate is ch...
Definition: clocked_object.hh:145
ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:231
SimClock::Frequency
Tick Frequency
The simulated frequency of curTick(). (In ticks per second)
Definition: core.cc:46
Clocked::update
void update() const
Align cycle and tick to the next clock edge if not already done.
Definition: clocked_object.hh:76
Clocked::updateClockPeriod
void updateClockPeriod()
Update the tick to the current tick.
Definition: clocked_object.hh:153
divCeil
T divCeil(const T &a, const U &b)
Definition: intmath.hh:114
cp
Definition: cprintf.cc:40
Clocked::cyclesToTicks
Tick cyclesToTicks(Cycles c) const
Definition: clocked_object.hh:224
sim_object.hh
PowerState
Helper class for objects that have power states.
Definition: power_state.hh:61
Clocked::curCycle
Cycles curCycle() const
Determine the current cycle, corresponding to a tick aligned to a clock edge.
Definition: clocked_object.hh:192
Clocked::clockEdge
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...
Definition: clocked_object.hh:174
Clocked::cycle
Cycles cycle
Definition: clocked_object.hh:69
core.hh
Clocked::clockPeriod
Tick clockPeriod() const
Definition: clocked_object.hh:214
Clocked::frequency
uint64_t frequency() const
Definition: clocked_object.hh:212
clock_domain.hh
ClockedObject::powerState
PowerState * powerState
Definition: clocked_object.hh:247
Clocked::resetClock
void resetClock() const
Reset the object's clock using the current global tick value.
Definition: clocked_object.hh:134
ArmISA::t
Bitfield< 5 > t
Definition: miscregs_types.hh:67
SimObject::_params
const SimObjectParams * _params
Cached copy of the object parameters.
Definition: sim_object.hh:110
Clocked::ticksToCycles
Cycles ticksToCycles(Tick t) const
Definition: clocked_object.hh:219
ClockedObject::Params
ClockedObjectParams Params
Parameters of ClockedObject.
Definition: clocked_object.hh:237
ClockedObject::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: clocked_object.cc:61
Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:83
Clocked::nextCycle
Tick nextCycle() const
Based on the clock of the object, determine the start tick of the first cycle that is at least one cy...
Definition: clocked_object.hh:210
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
ArmISA::c
Bitfield< 29 > c
Definition: miscregs_types.hh:50
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
Clocked::~Clocked
virtual ~Clocked()
Virtual destructor due to inheritance.
Definition: clocked_object.hh:126
ClockDomain::registerWithClockDomain
void registerWithClockDomain(Clocked *c)
Register a Clocked object with this ClockDomain.
Definition: clock_domain.hh:112
CheckpointIn
Definition: serialize.hh:67
ClockDomain::clockPeriod
Tick clockPeriod() const
Get the clock period.
Definition: clock_domain.hh:105
curTick
Tick curTick()
The current simulated tick.
Definition: core.hh:45
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:92

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17