simulate.py (11431:871eaaa0ab24) simulate.py (11802:be62996c95d1)
1# Copyright (c) 2012 ARM Limited
2# All rights reserved.
3#
4# The license below extends only to copyright in the software and shall
5# not be construed as granting a license to any other intellectual
6# property including but not limited to intellectual property relating
7# to a hardware implementation of the functionality of the software
8# licensed hereunder. You may use the software subject to the license

--- 31 unchanged lines hidden (view full) ---

40# Authors: Nathan Binkert
41# Steve Reinhardt
42
43import atexit
44import os
45import sys
46
47# import the SWIG-wrapped main C++ functions
1# Copyright (c) 2012 ARM Limited
2# All rights reserved.
3#
4# The license below extends only to copyright in the software and shall
5# not be construed as granting a license to any other intellectual
6# property including but not limited to intellectual property relating
7# to a hardware implementation of the functionality of the software
8# licensed hereunder. You may use the software subject to the license

--- 31 unchanged lines hidden (view full) ---

40# Authors: Nathan Binkert
41# Steve Reinhardt
42
43import atexit
44import os
45import sys
46
47# import the SWIG-wrapped main C++ functions
48import internal
49import core
48import _m5.drain
49import _m5.core
50from _m5.stats import updateEvents as updateStatEvents
51
50import stats
51import SimObject
52import ticks
53import objects
54from m5.util.dot_writer import do_dot, do_dvfs_dot
52import stats
53import SimObject
54import ticks
55import objects
56from m5.util.dot_writer import do_dot, do_dvfs_dot
55from m5.internal.stats import updateEvents as updateStatEvents
56
57from util import fatal
58from util import attrdict
59
60# define a MaxTick parameter, unsigned 64 bit
61MaxTick = 2**64 - 1
62
63_memory_modes = {
64 "atomic" : objects.params.atomic,
65 "timing" : objects.params.timing,
66 "atomic_noncaching" : objects.params.atomic_noncaching,
67 }
68
57
58from util import fatal
59from util import attrdict
60
61# define a MaxTick parameter, unsigned 64 bit
62MaxTick = 2**64 - 1
63
64_memory_modes = {
65 "atomic" : objects.params.atomic,
66 "timing" : objects.params.timing,
67 "atomic_noncaching" : objects.params.atomic_noncaching,
68 }
69
69_drain_manager = internal.drain.DrainManager.instance()
70_drain_manager = _m5.drain.DrainManager.instance()
70
71# The final hook to generate .ini files. Called from the user script
72# once the config is built.
73def instantiate(ckpt_dir=None):
74 from m5 import options
75
76 root = objects.Root.getInstance()
77

--- 55 unchanged lines hidden (view full) ---

133 do_dvfs_dot(root, options.outdir, options.dot_dvfs_config)
134
135 # We're done registering statistics. Enable the stats package now.
136 stats.enable()
137
138 # Restore checkpoint (if any)
139 if ckpt_dir:
140 _drain_manager.preCheckpointRestore()
71
72# The final hook to generate .ini files. Called from the user script
73# once the config is built.
74def instantiate(ckpt_dir=None):
75 from m5 import options
76
77 root = objects.Root.getInstance()
78

--- 55 unchanged lines hidden (view full) ---

134 do_dvfs_dot(root, options.outdir, options.dot_dvfs_config)
135
136 # We're done registering statistics. Enable the stats package now.
137 stats.enable()
138
139 # Restore checkpoint (if any)
140 if ckpt_dir:
141 _drain_manager.preCheckpointRestore()
141 ckpt = internal.core.getCheckpoint(ckpt_dir)
142 internal.core.unserializeGlobals(ckpt);
142 ckpt = _m5.core.getCheckpoint(ckpt_dir)
143 _m5.core.unserializeGlobals(ckpt);
143 for obj in root.descendants(): obj.loadState(ckpt)
144 else:
145 for obj in root.descendants(): obj.initState()
146
147 # Check to see if any of the stat events are in the past after resuming from
148 # a checkpoint, If so, this call will shift them to be at a valid time.
149 updateStatEvents()
150

--- 6 unchanged lines hidden (view full) ---

157 for obj in root.descendants(): obj.startup()
158 need_startup = False
159
160 # Python exit handlers happen in reverse order.
161 # We want to dump stats last.
162 atexit.register(stats.dump)
163
164 # register our C++ exit callback function with Python
144 for obj in root.descendants(): obj.loadState(ckpt)
145 else:
146 for obj in root.descendants(): obj.initState()
147
148 # Check to see if any of the stat events are in the past after resuming from
149 # a checkpoint, If so, this call will shift them to be at a valid time.
150 updateStatEvents()
151

--- 6 unchanged lines hidden (view full) ---

158 for obj in root.descendants(): obj.startup()
159 need_startup = False
160
161 # Python exit handlers happen in reverse order.
162 # We want to dump stats last.
163 atexit.register(stats.dump)
164
165 # register our C++ exit callback function with Python
165 atexit.register(internal.core.doExitCleanup)
166 atexit.register(_m5.core.doExitCleanup)
166
167 # Reset to put the stats in a consistent state.
168 stats.reset()
169
170 if _drain_manager.isDrained():
171 _drain_manager.resume()
172
167
168 # Reset to put the stats in a consistent state.
169 stats.reset()
170
171 if _drain_manager.isDrained():
172 _drain_manager.resume()
173
173 return internal.event.simulate(*args, **kwargs)
174 return _m5.event.simulate(*args, **kwargs)
174
175
175# Export curTick to user script.
176def curTick():
177 return internal.core.curTick()
178
179def drain():
180 """Drain the simulator in preparation of a checkpoint or memory mode
181 switch.
182
183 This operation is a no-op if the simulator is already in the
184 Drained state.
185
186 """

--- 6 unchanged lines hidden (view full) ---

193 # Try to drain the system. The drain is successful if all
194 # objects are done without simulation. We need to simulate
195 # more if not.
196 if _drain_manager.tryDrain():
197 return True
198
199 # WARNING: if a valid exit event occurs while draining, it
200 # will not get returned to the user script
176def drain():
177 """Drain the simulator in preparation of a checkpoint or memory mode
178 switch.
179
180 This operation is a no-op if the simulator is already in the
181 Drained state.
182
183 """

--- 6 unchanged lines hidden (view full) ---

190 # Try to drain the system. The drain is successful if all
191 # objects are done without simulation. We need to simulate
192 # more if not.
193 if _drain_manager.tryDrain():
194 return True
195
196 # WARNING: if a valid exit event occurs while draining, it
197 # will not get returned to the user script
201 exit_event = internal.event.simulate()
198 exit_event = _m5.event.simulate()
202 while exit_event.getCause() != 'Finished drain':
203 exit_event = simulate()
204
205 return False
206
207 # Don't try to drain a system that is already drained
208 is_drained = _drain_manager.isDrained()
209 while not is_drained:

--- 12 unchanged lines hidden (view full) ---

222def checkpoint(dir):
223 root = objects.Root.getInstance()
224 if not isinstance(root, objects.Root):
225 raise TypeError, "Checkpoint must be called on a root object."
226
227 drain()
228 memWriteback(root)
229 print "Writing checkpoint"
199 while exit_event.getCause() != 'Finished drain':
200 exit_event = simulate()
201
202 return False
203
204 # Don't try to drain a system that is already drained
205 is_drained = _drain_manager.isDrained()
206 while not is_drained:

--- 12 unchanged lines hidden (view full) ---

219def checkpoint(dir):
220 root = objects.Root.getInstance()
221 if not isinstance(root, objects.Root):
222 raise TypeError, "Checkpoint must be called on a root object."
223
224 drain()
225 memWriteback(root)
226 print "Writing checkpoint"
230 internal.core.serializeAll(dir)
227 _m5.core.serializeAll(dir)
231
232def _changeMemoryMode(system, mode):
233 if not isinstance(system, (objects.Root, objects.System)):
234 raise TypeError, "Parameter of type '%s'. Must be type %s or %s." % \
235 (type(system), objects.Root, objects.System)
236 if system.getMemoryMode() != mode:
237 system.setMemoryMode(mode)
238 else:

--- 99 unchanged lines hidden (view full) ---

338 simout -- New simulation output directory.
339
340 Return Value:
341 pid of the child process or 0 if running in the child.
342 """
343 from m5 import options
344 global fork_count
345
228
229def _changeMemoryMode(system, mode):
230 if not isinstance(system, (objects.Root, objects.System)):
231 raise TypeError, "Parameter of type '%s'. Must be type %s or %s." % \
232 (type(system), objects.Root, objects.System)
233 if system.getMemoryMode() != mode:
234 system.setMemoryMode(mode)
235 else:

--- 99 unchanged lines hidden (view full) ---

335 simout -- New simulation output directory.
336
337 Return Value:
338 pid of the child process or 0 if running in the child.
339 """
340 from m5 import options
341 global fork_count
342
346 if not internal.core.listenersDisabled():
343 if not _m5.core.listenersDisabled():
347 raise RuntimeError, "Can not fork a simulator with listeners enabled"
348
349 drain()
350
351 try:
352 pid = os.fork()
353 except OSError, e:
354 raise e

--- 4 unchanged lines hidden (view full) ---

359 notifyFork(root)
360 # Setup a new output directory
361 parent = options.outdir
362 options.outdir = simout % {
363 "parent" : parent,
364 "fork_seq" : fork_count,
365 "pid" : os.getpid(),
366 }
344 raise RuntimeError, "Can not fork a simulator with listeners enabled"
345
346 drain()
347
348 try:
349 pid = os.fork()
350 except OSError, e:
351 raise e

--- 4 unchanged lines hidden (view full) ---

356 notifyFork(root)
357 # Setup a new output directory
358 parent = options.outdir
359 options.outdir = simout % {
360 "parent" : parent,
361 "fork_seq" : fork_count,
362 "pid" : os.getpid(),
363 }
367 core.setOutputDir(options.outdir)
364 _m5.core.setOutputDir(options.outdir)
368 else:
369 fork_count += 1
370
371 return pid
372
365 else:
366 fork_count += 1
367
368 return pid
369
373from internal.core import disableAllListeners
374from internal.core import listenersDisabled
370from _m5.core import disableAllListeners, listenersDisabled
371from _m5.core import curTick