root.hh revision 9048
12SN/A/* 21762SN/A * Copyright (c) 2011 Advanced Micro Devices, Inc. 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Gabe Black 292665Ssaidi@eecs.umich.edu */ 302SN/A 312SN/A/** 324183Sgblack@eecs.umich.edu * @file This file defines the Root simobject and the methods used to control 332439SN/A * the time syncing mechanism provided through it. 342680Sktlim@umich.edu * 352222SN/A * Time syncing prevents simulated time from passing faster than real time. It 364183Sgblack@eecs.umich.edu * works by scheduling a periodic event that checks to see if its simulated 374183Sgblack@eecs.umich.edu * period is shorter than its real period. If it is, it stalls the simulation 384183Sgblack@eecs.umich.edu * until they're equal. 392SN/A */ 402201SN/A 412680Sktlim@umich.edu#ifndef __SIM_ROOT_HH__ 422201SN/A#define __SIM_ROOT_HH__ 436815SLisa.Hsu@amd.com 442201SN/A#include "base/time.hh" 452222SN/A#include "params/Root.hh" 462680Sktlim@umich.edu#include "sim/eventq.hh" 472222SN/A#include "sim/sim_object.hh" 482680Sktlim@umich.edu 492680Sktlim@umich.educlass Root : public SimObject 502222SN/A{ 512680Sktlim@umich.edu private: 522222SN/A static Root *_root; 532201SN/A 542612SN/A protected: 552680Sktlim@umich.edu bool _enabled; 562612SN/A Time _period; 576815SLisa.Hsu@amd.com Tick _periodTick; 582612SN/A Time _spinThreshold; 595004Sgblack@eecs.umich.edu 604184Ssaidi@eecs.umich.edu Time lastTime; 615004Sgblack@eecs.umich.edu 624183Sgblack@eecs.umich.edu void timeSync(); 634183Sgblack@eecs.umich.edu EventWrapper<Root, &Root::timeSync> syncEvent; 644183Sgblack@eecs.umich.edu friend class EventWrapper<Root, &Root::timeSync>; 654434Ssaidi@eecs.umich.edu 664183Sgblack@eecs.umich.edu public: 674434Ssaidi@eecs.umich.edu /** 684183Sgblack@eecs.umich.edu * Use this function to get a pointer to the single Root object in the 695004Sgblack@eecs.umich.edu * simulation. This function asserts that such an object has actual been 705004Sgblack@eecs.umich.edu * constructed to avoid having to perform that check everywhere the root 715004Sgblack@eecs.umich.edu * is used. This is to allow calling the functions below. 725004Sgblack@eecs.umich.edu * 735004Sgblack@eecs.umich.edu * @return Pointer to the single root object. 744184Ssaidi@eecs.umich.edu */ 75 static Root * 76 root() 77 { 78 assert(_root); 79 return _root; 80 } 81 82 public: 83 84 /// Check whether time syncing is enabled. 85 bool timeSyncEnabled() const { return _enabled; } 86 /// Retrieve the period for the sync event. 87 const Time timeSyncPeriod() const { return _period; } 88 /// Retrieve the threshold for time remaining to spin wait. 89 const Time timeSyncSpinThreshold() const { return _spinThreshold; } 90 91 /// Enable or disable time syncing. 92 void timeSyncEnable(bool en); 93 /// Configure the period for time sync events. 94 void timeSyncPeriod(Time newPeriod); 95 /// Set the threshold for time remaining to spin wait. 96 void timeSyncSpinThreshold(Time newThreshold); 97 98 typedef RootParams Params; 99 const Params * 100 params() const 101 { 102 return dynamic_cast<const Params *>(_params); 103 } 104 105 Root(Params *p); 106 107 /** Schedule the timesync event at loadState() so that curTick is correct 108 */ 109 void loadState(Checkpoint *cp); 110 111 /** Schedule the timesync event at initState() when not unserializing 112 */ 113 void initState(); 114 115 virtual void serialize(std::ostream &os); 116 virtual void unserialize(Checkpoint *cp, const std::string §ion); 117 118}; 119 120#endif // __SIM_ROOT_HH__ 121