root.hh revision 7861
17861Sgblack@eecs.umich.edu/* 27861Sgblack@eecs.umich.edu * Copyright (c) 2011 Advanced Micro Devices 37861Sgblack@eecs.umich.edu * All rights reserved. 47861Sgblack@eecs.umich.edu * 57861Sgblack@eecs.umich.edu * Redistribution and use in source and binary forms, with or without 67861Sgblack@eecs.umich.edu * modification, are permitted provided that the following conditions are 77861Sgblack@eecs.umich.edu * met: redistributions of source code must retain the above copyright 87861Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer; 97861Sgblack@eecs.umich.edu * redistributions in binary form must reproduce the above copyright 107861Sgblack@eecs.umich.edu * notice, this list of conditions and the following disclaimer in the 117861Sgblack@eecs.umich.edu * documentation and/or other materials provided with the distribution; 127861Sgblack@eecs.umich.edu * neither the name of the copyright holders nor the names of its 137861Sgblack@eecs.umich.edu * contributors may be used to endorse or promote products derived from 147861Sgblack@eecs.umich.edu * this software without specific prior written permission. 157861Sgblack@eecs.umich.edu * 167861Sgblack@eecs.umich.edu * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 177861Sgblack@eecs.umich.edu * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 187861Sgblack@eecs.umich.edu * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 197861Sgblack@eecs.umich.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 207861Sgblack@eecs.umich.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 217861Sgblack@eecs.umich.edu * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 227861Sgblack@eecs.umich.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 237861Sgblack@eecs.umich.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 247861Sgblack@eecs.umich.edu * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 257861Sgblack@eecs.umich.edu * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 267861Sgblack@eecs.umich.edu * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 277861Sgblack@eecs.umich.edu * 287861Sgblack@eecs.umich.edu * Authors: Gabe Black 297861Sgblack@eecs.umich.edu */ 307861Sgblack@eecs.umich.edu 317861Sgblack@eecs.umich.edu/** 327861Sgblack@eecs.umich.edu * @file This file defines the Root simobject and the methods used to control 337861Sgblack@eecs.umich.edu * the time syncing mechanism provided through it. 347861Sgblack@eecs.umich.edu * 357861Sgblack@eecs.umich.edu * Time syncing prevents simulated time from passing faster than real time. It 367861Sgblack@eecs.umich.edu * works by scheduling a periodic event that checks to see if its simulated 377861Sgblack@eecs.umich.edu * period is shorter than its real period. If it is, it stalls the simulation 387861Sgblack@eecs.umich.edu * until they're equal. 397861Sgblack@eecs.umich.edu */ 407861Sgblack@eecs.umich.edu 417861Sgblack@eecs.umich.edu#ifndef __SIM_ROOT_HH__ 427861Sgblack@eecs.umich.edu#define __SIM_ROOT_HH__ 437861Sgblack@eecs.umich.edu 447861Sgblack@eecs.umich.edu#include "base/time.hh" 457861Sgblack@eecs.umich.edu#include "params/Root.hh" 467861Sgblack@eecs.umich.edu#include "sim/eventq.hh" 477861Sgblack@eecs.umich.edu#include "sim/sim_object.hh" 487861Sgblack@eecs.umich.edu 497861Sgblack@eecs.umich.educlass Root : public SimObject 507861Sgblack@eecs.umich.edu{ 517861Sgblack@eecs.umich.edu private: 527861Sgblack@eecs.umich.edu static Root *_root; 537861Sgblack@eecs.umich.edu 547861Sgblack@eecs.umich.edu protected: 557861Sgblack@eecs.umich.edu bool _enabled; 567861Sgblack@eecs.umich.edu Time _period; 577861Sgblack@eecs.umich.edu Tick _periodTick; 587861Sgblack@eecs.umich.edu Time _spinThreshold; 597861Sgblack@eecs.umich.edu 607861Sgblack@eecs.umich.edu Time lastTime; 617861Sgblack@eecs.umich.edu 627861Sgblack@eecs.umich.edu void timeSync(); 637861Sgblack@eecs.umich.edu EventWrapper<Root, &Root::timeSync> syncEvent; 647861Sgblack@eecs.umich.edu friend class EventWrapper<Root, &Root::timeSync>; 657861Sgblack@eecs.umich.edu 667861Sgblack@eecs.umich.edu public: 677861Sgblack@eecs.umich.edu /** 687861Sgblack@eecs.umich.edu * Use this function to get a pointer to the single Root object in the 697861Sgblack@eecs.umich.edu * simulation. This function asserts that such an object has actual been 707861Sgblack@eecs.umich.edu * constructed to avoid having to perform that check everywhere the root 717861Sgblack@eecs.umich.edu * is used. This is to allow calling the functions below. 727861Sgblack@eecs.umich.edu * 737861Sgblack@eecs.umich.edu * @return Pointer to the single root object. 747861Sgblack@eecs.umich.edu */ 757861Sgblack@eecs.umich.edu static Root * 767861Sgblack@eecs.umich.edu root() 777861Sgblack@eecs.umich.edu { 787861Sgblack@eecs.umich.edu assert(_root); 797861Sgblack@eecs.umich.edu return _root; 807861Sgblack@eecs.umich.edu } 817861Sgblack@eecs.umich.edu 827861Sgblack@eecs.umich.edu public: 837861Sgblack@eecs.umich.edu 847861Sgblack@eecs.umich.edu /// Check whether time syncing is enabled. 857861Sgblack@eecs.umich.edu bool timeSyncEnabled() const { return _enabled; } 867861Sgblack@eecs.umich.edu /// Retrieve the period for the sync event. 877861Sgblack@eecs.umich.edu const Time timeSyncPeriod() const { return _period; } 887861Sgblack@eecs.umich.edu /// Retrieve the threshold for time remaining to spin wait. 897861Sgblack@eecs.umich.edu const Time timeSyncSpinThreshold() const { return _spinThreshold; } 907861Sgblack@eecs.umich.edu 917861Sgblack@eecs.umich.edu /// Enable or disable time syncing. 927861Sgblack@eecs.umich.edu void timeSyncEnable(bool en); 937861Sgblack@eecs.umich.edu /// Configure the period for time sync events. 947861Sgblack@eecs.umich.edu void timeSyncPeriod(Time newPeriod); 957861Sgblack@eecs.umich.edu /// Set the threshold for time remaining to spin wait. 967861Sgblack@eecs.umich.edu void timeSyncSpinThreshold(Time newThreshold); 977861Sgblack@eecs.umich.edu 987861Sgblack@eecs.umich.edu Root(RootParams *p); 997861Sgblack@eecs.umich.edu}; 1007861Sgblack@eecs.umich.edu 1017861Sgblack@eecs.umich.edu#endif // __SIM_ROOT_HH__ 102