gem5  v21.1.0.2
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 
54 namespace gem5
55 {
56 
62 class Clocked
63 {
64 
65  private:
66  // the tick value of the next clock edge (>= curTick()) at the
67  // time of the last call to update()
68  mutable Tick tick;
69 
70  // The cycle counter value corresponding to the current value of
71  // 'tick'
72  mutable Cycles cycle;
73 
78  void
79  update() const
80  {
81  // both tick and cycle are up-to-date and we are done, note
82  // that the >= is important as it captures cases where tick
83  // has already passed curTick()
84  if (tick >= curTick())
85  return;
86 
87  // optimise for the common case and see if the tick should be
88  // advanced by a single clock period
89  tick += clockPeriod();
90  ++cycle;
91 
92  // see if we are done at this point
93  if (tick >= curTick())
94  return;
95 
96  // if not, we have to recalculate the cycle and tick, we
97  // perform the calculations in terms of relative cycles to
98  // allow changes to the clock period in the future
99  Cycles elapsedCycles(divCeil(curTick() - tick, clockPeriod()));
100  cycle += elapsedCycles;
101  tick += elapsedCycles * clockPeriod();
102  }
103 
108 
109  protected:
110 
115  Clocked(ClockDomain &clk_domain)
116  : tick(0), cycle(0), clockDomain(clk_domain)
117  {
118  // Register with the clock domain, so that if the clock domain
119  // frequency changes, we can update this object's tick.
121  }
122 
123  Clocked(Clocked &) = delete;
124  Clocked &operator=(Clocked &) = delete;
125 
129  virtual ~Clocked() { }
130 
136  void
137  resetClock() const
138  {
139  Cycles elapsedCycles(divCeil(curTick(), clockPeriod()));
140  cycle = elapsedCycles;
141  tick = elapsedCycles * clockPeriod();
142  }
143 
148  virtual void clockPeriodUpdated() {}
149 
150  public:
151 
155  void
157  {
158  update();
160  }
161 
176  Tick
177  clockEdge(Cycles cycles=Cycles(0)) const
178  {
179  // align tick to the next clock edge
180  update();
181 
182  // figure out when this future cycle is
183  return tick + clockPeriod() * cycles;
184  }
185 
194  Cycles
195  curCycle() const
196  {
197  // align cycle to the next clock edge.
198  update();
199 
200  return cycle;
201  }
202 
213  Tick nextCycle() const { return clockEdge(Cycles(1)); }
214 
215  uint64_t frequency() const { return sim_clock::Frequency / clockPeriod(); }
216 
217  Tick clockPeriod() const { return clockDomain.clockPeriod(); }
218 
219  double voltage() const { return clockDomain.voltage(); }
220 
221  Cycles
223  {
224  return Cycles(divCeil(t, clockPeriod()));
225  }
226 
227  Tick cyclesToTicks(Cycles c) const { return clockPeriod() * c; }
228 };
229 
234 class ClockedObject : public SimObject, public Clocked
235 {
236  public:
237  ClockedObject(const ClockedObjectParams &p);
238 
240  using Params = ClockedObjectParams;
241 
242  void serialize(CheckpointOut &cp) const override;
243  void unserialize(CheckpointIn &cp) override;
244 
246 };
247 
248 } // namespace gem5
249 
250 #endif //__SIM_CLOCKED_OBJECT_HH__
gem5::curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46
gem5::Clocked::cycle
Cycles cycle
Definition: clocked_object.hh:72
gem5::Clocked::operator=
Clocked & operator=(Clocked &)=delete
power_state.hh
gem5::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:148
gem5::Clocked::curCycle
Cycles curCycle() const
Determine the current cycle, corresponding to a tick aligned to a clock edge.
Definition: clocked_object.hh:195
gem5::CheckpointIn
Definition: serialize.hh:68
gem5::sim_clock::Frequency
Tick Frequency
The simulated frequency of curTick(). (In ticks per second)
Definition: core.cc:48
gem5::ClockDomain::registerWithClockDomain
void registerWithClockDomain(Clocked *c)
Register a Clocked object with this ClockDomain.
Definition: clock_domain.hh:115
gem5::ClockedObject::unserialize
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: clocked_object.cc:64
gem5::Clocked::update
void update() const
Align cycle and tick to the next clock edge if not already done.
Definition: clocked_object.hh:79
gem5::Clocked
Helper class for objects that need to be clocked.
Definition: clocked_object.hh:62
gem5::Cycles
Cycles is a wrapper class for representing cycle counts, i.e.
Definition: types.hh:78
gem5::Clocked::~Clocked
virtual ~Clocked()
Virtual destructor due to inheritance.
Definition: clocked_object.hh:129
gem5::Clocked::cyclesToTicks
Tick cyclesToTicks(Cycles c) const
Definition: clocked_object.hh:227
gem5::ClockDomain
The ClockDomain provides clock to group of clocked objects bundled under the same clock domain.
Definition: clock_domain.hh:71
sim_object.hh
gem5::ClockedObject::ClockedObject
ClockedObject(const ClockedObjectParams &p)
Definition: clocked_object.cc:46
gem5::MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:326
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::PowerState
Helper class for objects that have power states.
Definition: power_state.hh:64
gem5::Clocked::voltage
double voltage() const
Definition: clocked_object.hh:219
gem5::ClockedObject::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: clocked_object.cc:59
gem5::Clocked::updateClockPeriod
void updateClockPeriod()
Update the tick to the current tick.
Definition: clocked_object.hh:156
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
gem5::ArmISA::t
Bitfield< 5 > t
Definition: misc_types.hh:70
gem5::ArmISA::c
Bitfield< 29 > c
Definition: misc_types.hh:53
gem5::ClockDomain::voltage
double voltage() const
Get the current voltage this clock domain operates at.
Definition: clock_domain.cc:75
core.hh
gem5::Clocked::clockDomain
ClockDomain & clockDomain
The clock domain this clocked object belongs to.
Definition: clocked_object.hh:107
gem5::ClockedObject
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
Definition: clocked_object.hh:234
gem5::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:177
gem5::ClockedObject::powerState
PowerState * powerState
Definition: clocked_object.hh:245
gem5::divCeil
static constexpr T divCeil(const T &a, const U &b)
Definition: intmath.hh:110
clock_domain.hh
gem5::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:213
gem5::Clocked::Clocked
Clocked(ClockDomain &clk_domain)
Create a clocked object and set the clock domain based on the parameters.
Definition: clocked_object.hh:115
gem5::Clocked::tick
Tick tick
Definition: clocked_object.hh:68
gem5::Clocked::resetClock
void resetClock() const
Reset the object's clock using the current global tick value.
Definition: clocked_object.hh:137
gem5::CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:66
gem5::ClockedObject::Params
ClockedObjectParams Params
Parameters of ClockedObject.
Definition: clocked_object.hh:240
gem5::Clocked::ticksToCycles
Cycles ticksToCycles(Tick t) const
Definition: clocked_object.hh:222
gem5::Clocked::frequency
uint64_t frequency() const
Definition: clocked_object.hh:215
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: decoder.cc:40
gem5::ClockDomain::clockPeriod
Tick clockPeriod() const
Get the clock period.
Definition: clock_domain.hh:108
gem5::Clocked::clockPeriod
Tick clockPeriod() const
Definition: clocked_object.hh:217

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