gem5 v24.0.0.0
Loading...
Searching...
No Matches
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
54namespace gem5
55{
56
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;
125
129 virtual ~Clocked() { }
130
136 void
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
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
234class 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__
The ClockDomain provides clock to group of clocked objects bundled under the same clock domain.
Tick clockPeriod() const
Get the clock period.
void registerWithClockDomain(Clocked *c)
Register a Clocked object with this ClockDomain.
double voltage() const
Get the current voltage this clock domain operates at.
The ClockedObject class extends the SimObject with a clock and accessor functions to relate ticks to ...
ClockedObject(const ClockedObjectParams &p)
void serialize(CheckpointOut &cp) const override
Serialize an object.
ClockedObjectParams Params
Parameters of ClockedObject.
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Helper class for objects that need to be clocked.
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...
void updateClockPeriod()
Update the tick to the current tick.
uint64_t frequency() const
Clocked & operator=(Clocked &)=delete
Tick nextCycle() const
Based on the clock of the object, determine the start tick of the first cycle that is at least one cy...
ClockDomain & clockDomain
The clock domain this clocked object belongs to.
Tick cyclesToTicks(Cycles c) const
Tick clockPeriod() const
virtual ~Clocked()
Virtual destructor due to inheritance.
void resetClock() const
Reset the object's clock using the current global tick value.
Clocked(ClockDomain &clk_domain)
Create a clocked object and set the clock domain based on the parameters.
void update() const
Align cycle and tick to the next clock edge if not already done.
Cycles ticksToCycles(Tick t) const
virtual void clockPeriodUpdated()
A hook subclasses can implement so they can do any extra work that's needed when the clock rate is ch...
Clocked(Clocked &)=delete
double voltage() const
Cycles is a wrapper class for representing cycle counts, i.e.
Definition types.hh:79
Helper class for objects that have power states.
Abstract superclass for simulation objects.
ClockDomain declarations.
static constexpr T divCeil(const T &a, const U &b)
Definition intmath.hh:110
Bitfield< 5 > t
Definition misc_types.hh:71
Bitfield< 29 > c
Definition misc_types.hh:53
Bitfield< 0 > p
Tick Frequency
The simulated frequency of curTick(). (In ticks per second)
Definition core.cc:47
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
Definition binary32.hh:36
Tick curTick()
The universal simulation clock.
Definition cur_tick.hh:46
std::ostream CheckpointOut
Definition serialize.hh:66
uint64_t Tick
Tick count type.
Definition types.hh:58
PowerState declaration and implementation.

Generated on Tue Jun 18 2024 16:24:06 for gem5 by doxygen 1.11.0