9bb8b4f05cba5fcf886869915fa71e3a3b3e5518
2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
3 * Copyright (c) 2011 Advanced Micro Devices, Inc.
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.
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.
29 * Authors: Nathan Binkert
34 #include "base/misc.hh"
35 #include "base/trace.hh"
36 #include "config/the_isa.hh"
37 #include "debug/TimeSync.hh"
38 #include "sim/full_system.hh"
39 #include "sim/root.hh"
41 Root
*Root::_root
= NULL
;
44 * This function is called periodically by an event in M5 and ensures that
45 * at least as much real time has passed between invocations as simulated time.
46 * If not, the function either sleeps, or if the difference is small enough
52 Time cur_time
, diff
, period
= timeSyncPeriod();
56 diff
= cur_time
- lastTime
;
57 Time remainder
= period
- diff
;
58 if (diff
< period
&& remainder
> _spinThreshold
) {
59 DPRINTF(TimeSync
, "Sleeping to sync with real time.\n");
60 // Sleep until the end of the period, or until a signal.
62 // Refresh the current time.
65 } while (diff
< period
);
67 schedule(&syncEvent
, curTick() + _periodTick
);
71 Root::timeSyncEnable(bool en
)
78 Tick periods
= ((curTick() + _periodTick
- 1) / _periodTick
);
79 Tick nextPeriod
= periods
* _periodTick
;
80 schedule(&syncEvent
, nextPeriod
);
83 deschedule(&syncEvent
);
87 /// Configure the period for time sync events.
89 Root::timeSyncPeriod(Time newPeriod
)
91 bool en
= timeSyncEnabled();
93 _periodTick
= _period
.getTick();
97 /// Set the threshold for time remaining to spin wait.
99 Root::timeSyncSpinThreshold(Time newThreshold
)
101 bool en
= timeSyncEnabled();
102 _spinThreshold
= newThreshold
;
106 Root::Root(RootParams
*p
) : SimObject(p
), _enabled(false),
107 _periodTick(p
->time_sync_period
), syncEvent(this)
109 _period
.setTick(p
->time_sync_period
);
110 _spinThreshold
.setTick(p
->time_sync_spin_threshold
);
112 assert(_root
== NULL
);
116 simQuantum
= p
->sim_quantum
;
122 timeSyncEnable(params()->time_sync_enable
);
126 Root::loadState(Checkpoint
*cp
)
128 SimObject::loadState(cp
);
129 timeSyncEnable(params()->time_sync_enable
);
133 Root::serialize(std::ostream
&os
)
135 uint64_t cpt_ver
= gem5CheckpointVersion
;
136 SERIALIZE_SCALAR(cpt_ver
);
137 SERIALIZE_SCALAR(FullSystem
);
138 std::string isa
= THE_ISA_STR
;
139 SERIALIZE_SCALAR(isa
);
143 Root::unserialize(Checkpoint
*cp
, const std::string
§ion
)
145 uint64_t cpt_ver
= 0;
146 UNSERIALIZE_OPT_SCALAR(cpt_ver
);
147 if (cpt_ver
< gem5CheckpointVersion
) {
148 warn("**********************************************************\n");
149 warn("!!!! Checkpoint ver %#x is older than current ver %#x !!!!\n",
150 cpt_ver
, gem5CheckpointVersion
);
151 warn("You might experience some issues when restoring and should run "
152 "the checkpoint upgrader (util/cpt_upgrader.py) on your "
154 warn("**********************************************************\n");
155 } else if (cpt_ver
> gem5CheckpointVersion
) {
156 warn("**********************************************************\n");
157 warn("!!!! Checkpoint ver %#x is newer than current ver %#x !!!!\n",
158 cpt_ver
, gem5CheckpointVersion
);
159 warn("Running a new checkpoint with an older version of gem5 is not "
160 "supported. While it might work, you may experience incorrect "
161 "behavior or crashes.\n");
162 warn("**********************************************************\n");
168 unsigned int FullSystemInt
;
173 static bool created
= false;
175 panic("only one root object allowed!");
179 FullSystem
= full_system
;
180 FullSystemInt
= full_system
? 1 : 0;
182 return new Root(this);