clocked_object.hh (9648:f10eb34e3e38) clocked_object.hh (9793:6e6cefc1db1f)
1/*
1/*
2 * Copyright (c) 2012 ARM Limited
2 * Copyright (c) 2012-2013 ARM Limited
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated

--- 33 unchanged lines hidden (view full) ---

44
45#ifndef __SIM_CLOCKED_OBJECT_HH__
46#define __SIM_CLOCKED_OBJECT_HH__
47
48#include "base/intmath.hh"
49#include "base/misc.hh"
50#include "params/ClockedObject.hh"
51#include "sim/core.hh"
3 * All rights reserved
4 *
5 * The license below extends only to copyright in the software and shall
6 * not be construed as granting a license to any other intellectual
7 * property including but not limited to intellectual property relating
8 * to a hardware implementation of the functionality of the software
9 * licensed hereunder. You may use the software subject to the license
10 * terms below provided that you ensure that this notice is replicated

--- 33 unchanged lines hidden (view full) ---

44
45#ifndef __SIM_CLOCKED_OBJECT_HH__
46#define __SIM_CLOCKED_OBJECT_HH__
47
48#include "base/intmath.hh"
49#include "base/misc.hh"
50#include "params/ClockedObject.hh"
51#include "sim/core.hh"
52#include "sim/clock_domain.hh"
52#include "sim/sim_object.hh"
53
54/**
55 * The ClockedObject class extends the SimObject with a clock and
56 * accessor functions to relate ticks to the cycles of the object.
57 */
58class ClockedObject : public SimObject
59{

--- 23 unchanged lines hidden (view full) ---

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
53#include "sim/sim_object.hh"
54
55/**
56 * The ClockedObject class extends the SimObject with a clock and
57 * accessor functions to relate ticks to the cycles of the object.
58 */
59class ClockedObject : public SimObject
60{

--- 23 unchanged lines hidden (view full) ---

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
91 tick += clock;
92 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
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
101 Cycles elapsedCycles(divCeil(curTick() - tick, clock));
102 Cycles elapsedCycles(divCeil(curTick() - tick, clockPeriod()));
102 cycle += elapsedCycles;
103 cycle += elapsedCycles;
103 tick += elapsedCycles * clock;
104 tick += elapsedCycles * clockPeriod();
104 }
105
105 }
106
106 // Clock period in ticks
107 Tick clock;
107 /**
108 * The clock domain this clocked object belongs to
109 */
110 ClockDomain &clockDomain;
108
109 protected:
110
111 /**
111
112 protected:
113
114 /**
112 * Create a clocked object and set the clock based on the
115 * Create a clocked object and set the clock domain based on the
113 * parameters.
114 */
115 ClockedObject(const ClockedObjectParams* p) :
116 * parameters.
117 */
118 ClockedObject(const ClockedObjectParams* p) :
116 SimObject(p), tick(0), cycle(0), clock(p->clock)
119 SimObject(p), tick(0), cycle(0), clockDomain(*p->clk_domain)
117 {
120 {
118 if (clock == 0) {
119 fatal("%s has a clock period of zero\n", name());
120 }
121 }
122
123 /**
124 * Virtual destructor due to inheritance.
125 */
126 virtual ~ClockedObject() { }
127
128 /**
129 * Reset the object's clock using the current global tick value. Likely
130 * to be used only when the global clock is reset. Currently, this done
131 * only when Ruby is done warming up the memory system.
132 */
133 void resetClock() const
134 {
121 }
122
123 /**
124 * Virtual destructor due to inheritance.
125 */
126 virtual ~ClockedObject() { }
127
128 /**
129 * Reset the object's clock using the current global tick value. Likely
130 * to be used only when the global clock is reset. Currently, this done
131 * only when Ruby is done warming up the memory system.
132 */
133 void resetClock() const
134 {
135 Cycles elapsedCycles(divCeil(curTick(), clock));
135 Cycles elapsedCycles(divCeil(curTick(), clockPeriod()));
136 cycle = elapsedCycles;
136 cycle = elapsedCycles;
137 tick = elapsedCycles * clock;
137 tick = elapsedCycles * clockPeriod();
138 }
139
140 public:
141
142 /**
143 * Determine the tick when a cycle begins, by default the current
144 * one, but the argument also enables the caller to determine a
145 * future cycle.
146 *
147 * @param cycles The number of cycles into the future
148 *
149 * @return The tick when the clock edge occurs
150 */
151 inline Tick clockEdge(Cycles cycles = Cycles(0)) const
152 {
153 // align tick to the next clock edge
154 update();
155
156 // figure out when this future cycle is
138 }
139
140 public:
141
142 /**
143 * Determine the tick when a cycle begins, by default the current
144 * one, but the argument also enables the caller to determine a
145 * future cycle.
146 *
147 * @param cycles The number of cycles into the future
148 *
149 * @return The tick when the clock edge occurs
150 */
151 inline Tick clockEdge(Cycles cycles = Cycles(0)) const
152 {
153 // align tick to the next clock edge
154 update();
155
156 // figure out when this future cycle is
157 return tick + clock * cycles;
157 return tick + clockPeriod() * cycles;
158 }
159
160 /**
161 * Determine the current cycle, corresponding to a tick aligned to
162 * a clock edge.
163 *
164 * @return The current cycle count
165 */

--- 10 unchanged lines hidden (view full) ---

176 * cycle begins, in other words, return the next clock edge.
177 * (This can never be the current tick.)
178 *
179 * @return The tick when the next cycle starts
180 */
181 Tick nextCycle() const
182 { return clockEdge(Cycles(1)); }
183
158 }
159
160 /**
161 * Determine the current cycle, corresponding to a tick aligned to
162 * a clock edge.
163 *
164 * @return The current cycle count
165 */

--- 10 unchanged lines hidden (view full) ---

176 * cycle begins, in other words, return the next clock edge.
177 * (This can never be the current tick.)
178 *
179 * @return The tick when the next cycle starts
180 */
181 Tick nextCycle() const
182 { return clockEdge(Cycles(1)); }
183
184 inline uint64_t frequency() const { return SimClock::Frequency / clock; }
184 inline uint64_t frequency() const
185 {
186 return SimClock::Frequency / clockPeriod();
187 }
185
188
186 inline Tick clockPeriod() const { return clock; }
189 inline Tick clockPeriod() const
190 {
191 return clockDomain.clockPeriod();
192 }
187
188 inline Cycles ticksToCycles(Tick t) const
193
194 inline Cycles ticksToCycles(Tick t) const
189 { return Cycles(t / clock); }
195 { return Cycles(t / clockPeriod()); }
190
191};
192
193#endif //__SIM_CLOCKED_OBJECT_HH__
196
197};
198
199#endif //__SIM_CLOCKED_OBJECT_HH__