+ if (en == _enabled)
+ return;
+ _enabled = en;
+ if (_enabled) {
+ // Get event going.
+ Tick periods = ((curTick() + _periodTick - 1) / _periodTick);
+ Tick nextPeriod = periods * _periodTick;
+ schedule(&syncEvent, nextPeriod);
+ } else {
+ // Stop event.
+ deschedule(&syncEvent);
+ }
+}
+
+/// Configure the period for time sync events.
+void
+Root::timeSyncPeriod(Time newPeriod)
+{
+ bool en = timeSyncEnabled();
+ _period = newPeriod;
+ _periodTick = _period.nsec() * SimClock::Int::ns +
+ _period.sec() * SimClock::Int::s;
+ timeSyncEnable(en);
+}
+
+/// Set the threshold for time remaining to spin wait.
+void
+Root::timeSyncSpinThreshold(Time newThreshold)
+{
+ bool en = timeSyncEnabled();
+ _spinThreshold = newThreshold;
+ timeSyncEnable(en);
+}
+
+Root::Root(RootParams *p) : SimObject(p), _enabled(false),
+ _periodTick(p->time_sync_period), syncEvent(this)
+{
+ uint64_t nsecs = p->time_sync_period / SimClock::Int::ns;
+ _period.set(nsecs / Time::NSEC_PER_SEC, nsecs % Time::NSEC_PER_SEC);
+ nsecs = p->time_sync_spin_threshold / SimClock::Int::ns;
+ _spinThreshold.set(nsecs / Time::NSEC_PER_SEC,
+ nsecs % Time::NSEC_PER_SEC);
+
+ assert(_root == NULL);
+ _root = this;
+ lastTime.setTimer();
+ timeSyncEnable(p->time_sync_enable);
+}