gem5
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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  * Authors: Nathan Binkert
30  * Steve Reinhardt
31  * Gabe Black
32  */
33 
34 #include "base/misc.hh"
35 #include "base/trace.hh"
36 #include "config/the_isa.hh"
37 #include "debug/TimeSync.hh"
38 #include "sim/eventq_impl.hh"
39 #include "sim/full_system.hh"
40 #include "sim/root.hh"
41 
42 Root *Root::_root = NULL;
43 
44 /*
45  * This function is called periodically by an event in M5 and ensures that
46  * at least as much real time has passed between invocations as simulated time.
47  * If not, the function either sleeps, or if the difference is small enough
48  * spin waits.
49  */
50 void
52 {
53  Time cur_time, diff, period = timeSyncPeriod();
54 
55  do {
56  cur_time.setTimer();
57  diff = cur_time - lastTime;
58  Time remainder = period - diff;
59  if (diff < period && remainder > _spinThreshold) {
60  DPRINTF(TimeSync, "Sleeping to sync with real time.\n");
61  // Sleep until the end of the period, or until a signal.
62  sleep(remainder);
63  // Refresh the current time.
64  cur_time.setTimer();
65  }
66  } while (diff < period);
67  lastTime = cur_time;
69 }
70 
71 void
73 {
74  if (en == _enabled)
75  return;
76  _enabled = en;
77  if (_enabled) {
78  // Get event going.
79  Tick periods = ((curTick() + _periodTick - 1) / _periodTick);
80  Tick nextPeriod = periods * _periodTick;
81  schedule(&syncEvent, nextPeriod);
82  } else {
83  // Stop event.
85  }
86 }
87 
89 void
91 {
92  bool en = timeSyncEnabled();
93  _period = newPeriod;
95  timeSyncEnable(en);
96 }
97 
99 void
101 {
102  bool en = timeSyncEnabled();
103  _spinThreshold = newThreshold;
104  timeSyncEnable(en);
105 }
106 
107 Root::Root(RootParams *p) : SimObject(p), _enabled(false),
108  _periodTick(p->time_sync_period), syncEvent(this)
109 {
110  _period.setTick(p->time_sync_period);
111  _spinThreshold.setTick(p->time_sync_spin_threshold);
112 
113  assert(_root == NULL);
114  _root = this;
115  lastTime.setTimer();
116 
117  simQuantum = p->sim_quantum;
118 }
119 
120 void
122 {
123  timeSyncEnable(params()->time_sync_enable);
124 }
125 
126 void
128 {
130  timeSyncEnable(params()->time_sync_enable);
131 }
132 
133 void
135 {
137  std::string isa = THE_ISA_STR;
138  SERIALIZE_SCALAR(isa);
139 }
140 
141 void
143 {}
144 
145 
147 unsigned int FullSystemInt;
148 
149 Root *
150 RootParams::create()
151 {
152  static bool created = false;
153  if (created)
154  panic("only one root object allowed!");
155 
156  created = true;
157 
158  FullSystem = full_system;
159  FullSystemInt = full_system ? 1 : 0;
160 
161  return new Root(this);
162 }
#define DPRINTF(x,...)
Definition: trace.hh:212
const Time timeSyncSpinThreshold() const
Retrieve the threshold for time remaining to spin wait.
Definition: root.hh:89
#define panic(...)
Definition: misc.hh:153
static Root * _root
Definition: root.hh:52
void unserialize(CheckpointIn &cp) override
Unserialize an object.
Definition: root.cc:142
Time lastTime
Definition: root.hh:60
Definition: time.hh:48
void serialize(CheckpointOut &cp) const override
Serialize an object.
Definition: root.cc:134
EventWrapper< Root,&Root::timeSync > syncEvent
Definition: root.hh:63
bool _enabled
Definition: root.hh:55
bool _enabled
Definition: statistics.cc:499
Bitfield< 30 > en
Definition: miscregs.hh:1649
void deschedule(Event &event)
Definition: eventq.hh:734
bool FullSystem
The FullSystem variable can be used to determine the current mode of simulation.
Definition: root.cc:146
Tick curTick()
The current simulated tick.
Definition: core.hh:47
uint64_t Tick
Tick count type.
Definition: types.hh:63
Root(Params *p)
Definition: root.cc:107
const Params * params() const
Definition: root.hh:100
const Time timeSyncPeriod() const
Retrieve the period for the sync event.
Definition: root.hh:87
void loadState(CheckpointIn &cp) override
Schedule the timesync event at loadState() so that curTick is correct.
Definition: root.cc:127
Time _period
Definition: root.hh:56
bool timeSyncEnabled() const
Check whether time syncing is enabled.
Definition: root.hh:85
Tick _periodTick
Definition: root.hh:57
#define SERIALIZE_SCALAR(scalar)
Definition: serialize.hh:143
void timeSyncEnable(bool en)
Enable or disable time syncing.
Definition: root.cc:72
std::ostream CheckpointOut
Definition: serialize.hh:67
Definition: root.hh:49
void timeSync()
Definition: root.cc:51
void initState() override
Schedule the timesync event at initState() when not unserializing.
Definition: root.cc:121
void schedule(Event &event, Tick when)
Definition: eventq.hh:728
Tick getTick() const
Get the current time from a value measured in Ticks.
Definition: time.cc:65
void setTick(Tick ticks)
Set the current time from a value measured in Ticks.
Definition: time.cc:58
void setTimer()
Use this to set time for the purposes of time measurement (use a monotonic clock if it is available...
Definition: time.hh:93
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:147
Bitfield< 0 > p
Abstract superclass for simulation objects.
Definition: sim_object.hh:94
Time _spinThreshold
Definition: root.hh:58
void sleep(const Time &time)
Definition: time.cc:140
virtual void loadState(CheckpointIn &cp)
loadState() is called on each SimObject when restoring from a checkpoint.
Definition: sim_object.cc:79
Tick simQuantum
Simulation Quantum for multiple eventq simulation.
Definition: eventq.cc:50

Generated on Fri Jun 9 2017 13:03:51 for gem5 by doxygen 1.8.6