1/*
2 * Copyright (c) 2012-2013 ARM Limited
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

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

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
44/**
45 * @file
46 * ClockedObject declaration and implementation.
47 */
48
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 "base/misc.hh"
55#include "enums/PwrState.hh"
56#include "params/ClockedObject.hh"
57#include "sim/core.hh"
58#include "sim/clock_domain.hh"
59#include "sim/sim_object.hh"
60
61/**
62 * Helper class for objects that need to be clocked. Clocked objects
63 * typically inherit from this class. Objects that need SimObject

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

232 * The ClockedObject class extends the SimObject with a clock and
233 * accessor functions to relate ticks to the cycles of the object.
234 */
235class ClockedObject
236 : public SimObject, public Clocked
237{
238 public:
239 ClockedObject(const ClockedObjectParams *p)
236 : SimObject(p), Clocked(*p->clk_domain) { }
240 : SimObject(p), Clocked(*p->clk_domain),
241 _currPwrState(p->default_p_state),
242 prvEvalTick(0)
243 { }
244
245 /** Parameters of ClockedObject */
246 typedef ClockedObjectParams Params;
247 const Params* params() const
248 { return reinterpret_cast<const Params*>(_params); }
249
250 void serialize(CheckpointOut &cp) const override;
251 void unserialize(CheckpointIn &cp) override;
252
253 inline Enums::PwrState pwrState() const
254 { return _currPwrState; }
255
256 inline std::string pwrStateName() const
257 { return Enums::PwrStateStrings[_currPwrState]; }
258
259 /** Returns the percentage residency for each power state */
260 std::vector<double> pwrStateWeights() const;
261
262 /**
263 * Record stats values like state residency by computing the time
264 * difference from previous update. Also, updates the previous evaluation
265 * tick once all stats are recorded.
266 * Usually called on power state change and stats dump callback.
267 */
268 void computeStats();
269
270 void pwrState(Enums::PwrState);
271 void regStats();
272
273 protected:
274
275 /** To keep track of the current power state */
276 Enums::PwrState _currPwrState;
277
278 Tick prvEvalTick;
279
280 Stats::Scalar numPwrStateTransitions;
281 Stats::Distribution pwrStateClkGateDist;
282 Stats::Vector pwrStateResidencyTicks;
283
284};
285
286class ClockedObjectDumpCallback : public Callback
287{
288 ClockedObject *co;
289 public:
290 ClockedObjectDumpCallback(ClockedObject *co_t) : co(co_t) {}
291 virtual void process() { co->computeStats(); };
292};
293
294#endif //__SIM_CLOCKED_OBJECT_HH__