root.cc (7826:c06505ff551e) | root.cc (7861:4ebff121cc0e) |
---|---|
1/* 2 * Copyright (c) 2002-2005 The Regents of The University of Michigan | 1/* 2 * Copyright (c) 2002-2005 The Regents of The University of Michigan |
3 * Copyright (c) 2011 Advanced Micro Devices |
|
3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer; 9 * redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the --- 11 unchanged lines hidden (view full) --- 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 * Authors: Nathan Binkert 29 * Steve Reinhardt | 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer; 10 * redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the --- 11 unchanged lines hidden (view full) --- 23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * 29 * Authors: Nathan Binkert 30 * Steve Reinhardt |
31 * Gabe Black |
|
30 */ 31 32#include "base/misc.hh" | 32 */ 33 34#include "base/misc.hh" |
33#include "params/Root.hh" 34#include "sim/sim_object.hh" | 35#include "sim/core.hh" 36#include "sim/root.hh" |
35 | 37 |
36// Dummy Object 37struct Root : public SimObject | 38Root *Root::_root = NULL; 39 40/* 41 * This function is called periodically by an event in M5 and ensures that 42 * at least as much real time has passed between invocations as simulated time. 43 * If not, the function either sleeps, or if the difference is small enough 44 * spin waits. 45 */ 46void 47Root::timeSync() |
38{ | 48{ |
39 Root(RootParams *params) : SimObject(params) {} 40}; | 49 Time cur_time, diff, period = timeSyncPeriod(); |
41 | 50 |
51 do { 52 cur_time.setTimer(); 53 diff = cur_time - lastTime; 54 Time remainder = period - diff; 55 if (diff < period && remainder > _spinThreshold) { 56 DPRINTF(TimeSync, "Sleeping to sync with real time.\n"); 57 // Sleep until the end of the period, or until a signal. 58 sleep(remainder); 59 // Refresh the current time. 60 cur_time.setTimer(); 61 } 62 } while (diff < period); 63 lastTime = cur_time; 64 schedule(&syncEvent, curTick() + _periodTick); 65} 66 67void 68Root::timeSyncEnable(bool en) 69{ 70 if (en == _enabled) 71 return; 72 _enabled = en; 73 if (_enabled) { 74 // Get event going. 75 Tick periods = ((curTick() + _periodTick - 1) / _periodTick); 76 Tick nextPeriod = periods * _periodTick; 77 schedule(&syncEvent, nextPeriod); 78 } else { 79 // Stop event. 80 deschedule(&syncEvent); 81 } 82} 83 84/// Configure the period for time sync events. 85void 86Root::timeSyncPeriod(Time newPeriod) 87{ 88 bool en = timeSyncEnabled(); 89 _period = newPeriod; 90 _periodTick = _period.nsec() * SimClock::Int::ns + 91 _period.sec() * SimClock::Int::s; 92 timeSyncEnable(en); 93} 94 95/// Set the threshold for time remaining to spin wait. 96void 97Root::timeSyncSpinThreshold(Time newThreshold) 98{ 99 bool en = timeSyncEnabled(); 100 _spinThreshold = newThreshold; 101 timeSyncEnable(en); 102} 103 104Root::Root(RootParams *p) : SimObject(p), _enabled(false), 105 _periodTick(p->time_sync_period), syncEvent(this) 106{ 107 uint64_t nsecs = p->time_sync_period / SimClock::Int::ns; 108 _period.set(nsecs / Time::NSEC_PER_SEC, nsecs % Time::NSEC_PER_SEC); 109 nsecs = p->time_sync_spin_threshold / SimClock::Int::ns; 110 _spinThreshold.set(nsecs / Time::NSEC_PER_SEC, 111 nsecs % Time::NSEC_PER_SEC); 112 113 assert(_root == NULL); 114 _root = this; 115 lastTime.setTimer(); 116 timeSyncEnable(p->time_sync_enable); 117} 118 |
|
42Root * 43RootParams::create() 44{ 45 static bool created = false; 46 if (created) 47 panic("only one root object allowed!"); 48 49 created = true; 50 51 return new Root(this); 52} | 119Root * 120RootParams::create() 121{ 122 static bool created = false; 123 if (created) 124 panic("only one root object allowed!"); 125 126 created = true; 127 128 return new Root(this); 129} |