gem5  v20.1.0.0
root.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2002-2005 The Regents of The University of Michigan
3  * Copyright (c) 2011 Advanced Micro Devices, Inc.
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
12  * documentation and/or other materials provided with the distribution;
13  * neither the name of the copyright holders nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
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 
30 #include "base/logging.hh"
31 #include "base/trace.hh"
32 #include "config/the_isa.hh"
33 #include "debug/TimeSync.hh"
34 #include "sim/eventq.hh"
35 #include "sim/full_system.hh"
36 #include "sim/root.hh"
37 
38 Root *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  */
46 void
48 {
49  Time cur_time, diff, period = timeSyncPeriod();
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.
59  // Refresh the current time.
60  cur_time.setTimer();
61  }
62  } while (diff < period);
63  lastTime = cur_time;
65 }
66 
67 void
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.
81  }
82 }
83 
85 void
87 {
88  bool en = timeSyncEnabled();
89  _period = newPeriod;
92 }
93 
95 void
97 {
98  bool en = timeSyncEnabled();
99  _spinThreshold = newThreshold;
101 }
102 
103 Root::Root(RootParams *p)
104  : SimObject(p), _enabled(false), _periodTick(p->time_sync_period),
105  syncEvent([this]{ timeSync(); }, name())
106 {
107  _period.setTick(p->time_sync_period);
108  _spinThreshold.setTick(p->time_sync_spin_threshold);
109 
110  assert(_root == NULL);
111  _root = this;
112  lastTime.setTimer();
113 
114  simQuantum = p->sim_quantum;
115 }
116 
117 void
119 {
120  timeSyncEnable(params()->time_sync_enable);
121 }
122 
123 void
125 {
127  std::string isa = THE_ISA_STR;
128  SERIALIZE_SCALAR(isa);
129 }
130 
131 
133 unsigned int FullSystemInt;
134 
135 Root *
136 RootParams::create()
137 {
138  static bool created = false;
139  if (created)
140  panic("only one root object allowed!");
141 
142  created = true;
143 
144  FullSystem = full_system;
145  FullSystemInt = full_system ? 1 : 0;
146 
147  return new Root(this);
148 }
Stats::_enabled
bool _enabled
Definition: statistics.cc:542
Root::_period
Time _period
Definition: root.hh:54
Root::timeSync
void timeSync()
Definition: root.cc:47
Root::timeSyncEnable
void timeSyncEnable(bool en)
Enable or disable time syncing.
Definition: root.cc:68
Tick
uint64_t Tick
Tick count type.
Definition: types.hh:63
EventManager::deschedule
void deschedule(Event &event)
Definition: eventq.hh:1014
Root::params
const Params * params() const
Definition: root.hh:97
sc_dt::remainder
return remainder
Definition: scfx_rep.cc:2201
Root::_periodTick
Tick _periodTick
Definition: root.hh:55
Root
Definition: root.hh:47
Root::Root
Root(Params *p)
Definition: root.cc:103
root.hh
Root::_root
static Root * _root
Definition: root.hh:50
Root::_spinThreshold
Time _spinThreshold
Definition: root.hh:56
cp
Definition: cprintf.cc:40
EventManager::schedule
void schedule(Event &event, Tick when)
Definition: eventq.hh:1005
Root::timeSyncEnabled
bool timeSyncEnabled() const
Check whether time syncing is enabled.
Definition: root.hh:82
Root::timeSyncPeriod
const Time timeSyncPeriod() const
Retrieve the period for the sync event.
Definition: root.hh:84
sleep
void sleep(const Time &time)
Definition: time.cc:141
DPRINTF
#define DPRINTF(x,...)
Definition: trace.hh:234
Root::startup
void startup() override
Schedule the timesync event at startup().
Definition: root.cc:118
Root::timeSyncSpinThreshold
const Time timeSyncSpinThreshold() const
Retrieve the threshold for time remaining to spin wait.
Definition: root.hh:86
ArmISA::en
Bitfield< 30 > en
Definition: miscregs_types.hh:455
FullSystemInt
unsigned int FullSystemInt
In addition to the boolean flag we make use of an unsigned int since the CPU instruction decoder make...
Definition: root.cc:133
name
const std::string & name()
Definition: trace.cc:50
SERIALIZE_SCALAR
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:790
Time::getTick
Tick getTick() const
Get the current time from a value measured in Ticks.
Definition: time.cc:65
FullSystem
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:132
full_system.hh
Root::syncEvent
EventFunctionWrapper syncEvent
Definition: root.hh:61
Time::setTimer
void setTimer()
Use this to set time for the purposes of time measurement (use a monotonic clock if it is available.
Definition: time.hh:90
Time
Definition: time.hh:45
Root::_enabled
bool _enabled
Definition: root.hh:53
Root::lastTime
Time lastTime
Definition: root.hh:58
logging.hh
simQuantum
Tick simQuantum
Simulation Quantum for multiple eventq simulation.
Definition: eventq.cc:47
CheckpointOut
std::ostream CheckpointOut
Definition: serialize.hh:63
trace.hh
MipsISA::p
Bitfield< 0 > p
Definition: pra_constants.hh:323
Root::serialize
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: root.cc:124
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:171
curTick
Tick curTick()
The current simulated tick.
Definition: core.hh:45
eventq.hh
SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:92

Generated on Wed Sep 30 2020 14:02:14 for gem5 by doxygen 1.8.17