__init__.py (3511:8cb26619b6ec) __init__.py (3624:aaba7e06ece4)
1# Copyright (c) 2005 The Regents of The University of Michigan
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

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

25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26#
27# Authors: Nathan Binkert
28# Steve Reinhardt
29
30import atexit, os, sys
31
32# import the SWIG-wrapped main C++ functions
1# Copyright (c) 2005 The Regents of The University of Michigan
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

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

25# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26#
27# Authors: Nathan Binkert
28# Steve Reinhardt
29
30import atexit, os, sys
31
32# import the SWIG-wrapped main C++ functions
33import cc_main
33import internal
34# import a few SWIG-wrapped items (those that are likely to be used
35# directly by user scripts) completely into this module for
36# convenience
34# import a few SWIG-wrapped items (those that are likely to be used
35# directly by user scripts) completely into this module for
36# convenience
37from cc_main import simulate, SimLoopExitEvent
37from internal.main import simulate, SimLoopExitEvent
38
39# import the m5 compile options
40import defines
41
42# define a MaxTick parameter
43MaxTick = 2**63 - 1
44
45# define this here so we can use it right away if necessary

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

80def instantiate(root):
81 params.ticks_per_sec = float(root.clock.frequency)
82 root.unproxy_all()
83 # ugly temporary hack to get output to config.ini
84 sys.stdout = file(os.path.join(options.outdir, 'config.ini'), 'w')
85 root.print_ini()
86 sys.stdout.close() # close config.ini
87 sys.stdout = sys.__stdout__ # restore to original
38
39# import the m5 compile options
40import defines
41
42# define a MaxTick parameter
43MaxTick = 2**63 - 1
44
45# define this here so we can use it right away if necessary

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

80def instantiate(root):
81 params.ticks_per_sec = float(root.clock.frequency)
82 root.unproxy_all()
83 # ugly temporary hack to get output to config.ini
84 sys.stdout = file(os.path.join(options.outdir, 'config.ini'), 'w')
85 root.print_ini()
86 sys.stdout.close() # close config.ini
87 sys.stdout = sys.__stdout__ # restore to original
88 cc_main.loadIniFile(resolveSimObject) # load config.ini into C++
88 internal.main.loadIniFile(resolveSimObject) # load config.ini into C++
89 root.createCCObject()
90 root.connectPorts()
89 root.createCCObject()
90 root.connectPorts()
91 cc_main.finalInit()
91 internal.main.finalInit()
92 noDot = True # temporary until we fix dot
93 if not noDot:
94 dot = pydot.Dot()
95 instance.outputDot(dot)
96 dot.orientation = "portrait"
97 dot.size = "8.5,11"
98 dot.ranksep="equally"
99 dot.rank="samerank"
100 dot.write("config.dot")
101 dot.write_ps("config.ps")
102
103# Export curTick to user script.
104def curTick():
92 noDot = True # temporary until we fix dot
93 if not noDot:
94 dot = pydot.Dot()
95 instance.outputDot(dot)
96 dot.orientation = "portrait"
97 dot.size = "8.5,11"
98 dot.ranksep="equally"
99 dot.rank="samerank"
100 dot.write("config.dot")
101 dot.write_ps("config.ps")
102
103# Export curTick to user script.
104def curTick():
105 return cc_main.cvar.curTick
105 return internal.main.cvar.curTick
106
107# register our C++ exit callback function with Python
106
107# register our C++ exit callback function with Python
108atexit.register(cc_main.doExitCleanup)
108atexit.register(internal.main.doExitCleanup)
109
110# This loops until all objects have been fully drained.
111def doDrain(root):
112 all_drained = drain(root)
113 while (not all_drained):
114 all_drained = drain(root)
115
116# Tries to drain all objects. Draining might not be completed unless
117# all objects return that they are drained on the first call. This is
118# because as objects drain they may cause other objects to no longer
119# be drained.
120def drain(root):
121 all_drained = False
109
110# This loops until all objects have been fully drained.
111def doDrain(root):
112 all_drained = drain(root)
113 while (not all_drained):
114 all_drained = drain(root)
115
116# Tries to drain all objects. Draining might not be completed unless
117# all objects return that they are drained on the first call. This is
118# because as objects drain they may cause other objects to no longer
119# be drained.
120def drain(root):
121 all_drained = False
122 drain_event = cc_main.createCountedDrain()
122 drain_event = internal.main.createCountedDrain()
123 unready_objects = root.startDrain(drain_event, True)
124 # If we've got some objects that can't drain immediately, then simulate
125 if unready_objects > 0:
126 drain_event.setCount(unready_objects)
127 simulate()
128 else:
129 all_drained = True
123 unready_objects = root.startDrain(drain_event, True)
124 # If we've got some objects that can't drain immediately, then simulate
125 if unready_objects > 0:
126 drain_event.setCount(unready_objects)
127 simulate()
128 else:
129 all_drained = True
130 cc_main.cleanupCountedDrain(drain_event)
130 internal.main.cleanupCountedDrain(drain_event)
131 return all_drained
132
133def resume(root):
134 root.resume()
135
136def checkpoint(root, dir):
137 if not isinstance(root, objects.Root):
138 raise TypeError, "Object is not a root object. Checkpoint must be called on a root object."
139 doDrain(root)
140 print "Writing checkpoint"
131 return all_drained
132
133def resume(root):
134 root.resume()
135
136def checkpoint(root, dir):
137 if not isinstance(root, objects.Root):
138 raise TypeError, "Object is not a root object. Checkpoint must be called on a root object."
139 doDrain(root)
140 print "Writing checkpoint"
141 cc_main.serializeAll(dir)
141 internal.main.serializeAll(dir)
142 resume(root)
143
144def restoreCheckpoint(root, dir):
145 print "Restoring from checkpoint"
142 resume(root)
143
144def restoreCheckpoint(root, dir):
145 print "Restoring from checkpoint"
146 cc_main.unserializeAll(dir)
146 internal.main.unserializeAll(dir)
147 resume(root)
148
149def changeToAtomic(system):
150 if not isinstance(system, objects.Root) and not isinstance(system, objects.System):
151 raise TypeError, "Object is not a root or system object. Checkpoint must be "
152 "called on a root object."
153 doDrain(system)
154 print "Changing memory mode to atomic"
147 resume(root)
148
149def changeToAtomic(system):
150 if not isinstance(system, objects.Root) and not isinstance(system, objects.System):
151 raise TypeError, "Object is not a root or system object. Checkpoint must be "
152 "called on a root object."
153 doDrain(system)
154 print "Changing memory mode to atomic"
155 system.changeTiming(cc_main.SimObject.Atomic)
155 system.changeTiming(internal.main.SimObject.Atomic)
156
157def changeToTiming(system):
158 if not isinstance(system, objects.Root) and not isinstance(system, objects.System):
159 raise TypeError, "Object is not a root or system object. Checkpoint must be "
160 "called on a root object."
161 doDrain(system)
162 print "Changing memory mode to timing"
156
157def changeToTiming(system):
158 if not isinstance(system, objects.Root) and not isinstance(system, objects.System):
159 raise TypeError, "Object is not a root or system object. Checkpoint must be "
160 "called on a root object."
161 doDrain(system)
162 print "Changing memory mode to timing"
163 system.changeTiming(cc_main.SimObject.Timing)
163 system.changeTiming(internal.main.SimObject.Timing)
164
165def switchCpus(cpuList):
166 print "switching cpus"
167 if not isinstance(cpuList, list):
168 raise RuntimeError, "Must pass a list to this function"
169 for i in cpuList:
170 if not isinstance(i, tuple):
171 raise RuntimeError, "List must have tuples of (oldCPU,newCPU)"
172
173 [old_cpus, new_cpus] = zip(*cpuList)
174
175 for cpu in old_cpus:
176 if not isinstance(cpu, objects.BaseCPU):
177 raise TypeError, "%s is not of type BaseCPU" % cpu
178 for cpu in new_cpus:
179 if not isinstance(cpu, objects.BaseCPU):
180 raise TypeError, "%s is not of type BaseCPU" % cpu
181
182 # Drain all of the individual CPUs
164
165def switchCpus(cpuList):
166 print "switching cpus"
167 if not isinstance(cpuList, list):
168 raise RuntimeError, "Must pass a list to this function"
169 for i in cpuList:
170 if not isinstance(i, tuple):
171 raise RuntimeError, "List must have tuples of (oldCPU,newCPU)"
172
173 [old_cpus, new_cpus] = zip(*cpuList)
174
175 for cpu in old_cpus:
176 if not isinstance(cpu, objects.BaseCPU):
177 raise TypeError, "%s is not of type BaseCPU" % cpu
178 for cpu in new_cpus:
179 if not isinstance(cpu, objects.BaseCPU):
180 raise TypeError, "%s is not of type BaseCPU" % cpu
181
182 # Drain all of the individual CPUs
183 drain_event = cc_main.createCountedDrain()
183 drain_event = internal.main.createCountedDrain()
184 unready_cpus = 0
185 for old_cpu in old_cpus:
186 unready_cpus += old_cpu.startDrain(drain_event, False)
187 # If we've got some objects that can't drain immediately, then simulate
188 if unready_cpus > 0:
189 drain_event.setCount(unready_cpus)
190 simulate()
184 unready_cpus = 0
185 for old_cpu in old_cpus:
186 unready_cpus += old_cpu.startDrain(drain_event, False)
187 # If we've got some objects that can't drain immediately, then simulate
188 if unready_cpus > 0:
189 drain_event.setCount(unready_cpus)
190 simulate()
191 cc_main.cleanupCountedDrain(drain_event)
191 internal.main.cleanupCountedDrain(drain_event)
192 # Now all of the CPUs are ready to be switched out
193 for old_cpu in old_cpus:
194 old_cpu._ccObject.switchOut()
195 index = 0
196 for new_cpu in new_cpus:
197 new_cpu.takeOverFrom(old_cpus[index])
198 new_cpu._ccObject.resume()
199 index += 1

--- 14 unchanged lines hidden ---
192 # Now all of the CPUs are ready to be switched out
193 for old_cpu in old_cpus:
194 old_cpu._ccObject.switchOut()
195 index = 0
196 for new_cpu in new_cpus:
197 new_cpu.takeOverFrom(old_cpus[index])
198 new_cpu._ccObject.resume()
199 index += 1

--- 14 unchanged lines hidden ---