simulate.py (9343:e63c6f279906) | simulate.py (9344:7f966113afd1) |
---|---|
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 --- 143 unchanged lines hidden (view full) --- 152 return internal.core.curTick() 153 154# Python exit handlers happen in reverse order. We want to dump stats last. 155atexit.register(stats.dump) 156 157# register our C++ exit callback function with Python 158atexit.register(internal.core.doExitCleanup) 159 | 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 --- 143 unchanged lines hidden (view full) --- 152 return internal.core.curTick() 153 154# Python exit handlers happen in reverse order. We want to dump stats last. 155atexit.register(stats.dump) 156 157# register our C++ exit callback function with Python 158atexit.register(internal.core.doExitCleanup) 159 |
160# This loops until all objects have been fully drained. 161def doDrain(root): 162 all_drained = drain(root) 163 while (not all_drained): 164 all_drained = drain(root) 165 166# Tries to drain all objects. Draining might not be completed unless 167# all objects return that they are drained on the first call. This is 168# because as objects drain they may cause other objects to no longer 169# be drained. | 160# Drain the system in preparation of a checkpoint or memory mode 161# switch. |
170def drain(root): | 162def drain(root): |
171 all_drained = False 172 dm = internal.drain.createDrainManager() 173 unready_objs = sum(obj.drain(dm) for obj in root.descendants()) 174 # If we've got some objects that can't drain immediately, then simulate 175 if unready_objs > 0: 176 dm.setCount(unready_objs) 177 simulate() 178 else: 179 all_drained = True 180 internal.drain.cleanupDrainManager(dm) 181 return all_drained | 163 # Try to drain all objects. Draining might not be completed unless 164 # all objects return that they are drained on the first call. This 165 # is because as objects drain they may cause other objects to no 166 # longer be drained. 167 def _drain(): 168 all_drained = False 169 dm = internal.drain.createDrainManager() 170 unready_objs = sum(obj.drain(dm) for obj in root.descendants()) 171 # If we've got some objects that can't drain immediately, then simulate 172 if unready_objs > 0: 173 dm.setCount(unready_objs) 174 simulate() 175 else: 176 all_drained = True 177 internal.drain.cleanupDrainManager(dm) 178 return all_drained |
182 | 179 |
180 all_drained = _drain() 181 while (not all_drained): 182 all_drained = _drain() 183 |
|
183def resume(root): 184 for obj in root.descendants(): obj.drainResume() 185 186def checkpoint(dir): 187 root = objects.Root.getInstance() 188 if not isinstance(root, objects.Root): 189 raise TypeError, "Checkpoint must be called on a root object." | 184def resume(root): 185 for obj in root.descendants(): obj.drainResume() 186 187def checkpoint(dir): 188 root = objects.Root.getInstance() 189 if not isinstance(root, objects.Root): 190 raise TypeError, "Checkpoint must be called on a root object." |
190 doDrain(root) | 191 drain(root) |
191 print "Writing checkpoint" 192 internal.core.serializeAll(dir) 193 resume(root) 194 195def changeMemoryMode(system, mode): 196 if not isinstance(system, (objects.Root, objects.System)): 197 raise TypeError, "Parameter of type '%s'. Must be type %s or %s." % \ 198 (type(system), objects.Root, objects.System) 199 if system.getMemoryMode() != mode: | 192 print "Writing checkpoint" 193 internal.core.serializeAll(dir) 194 resume(root) 195 196def changeMemoryMode(system, mode): 197 if not isinstance(system, (objects.Root, objects.System)): 198 raise TypeError, "Parameter of type '%s'. Must be type %s or %s." % \ 199 (type(system), objects.Root, objects.System) 200 if system.getMemoryMode() != mode: |
200 doDrain(system) | 201 drain(system) |
201 system.setMemoryMode(mode) 202 else: 203 print "System already in target mode. Memory mode unchanged." 204 205def changeToAtomic(system, **kwargs): 206 print "Changing memory mode to atomic" 207 changeMemoryMode(system, objects.params.atomic, **kwargs) 208 --- 26 unchanged lines hidden --- | 202 system.setMemoryMode(mode) 203 else: 204 print "System already in target mode. Memory mode unchanged." 205 206def changeToAtomic(system, **kwargs): 207 print "Changing memory mode to atomic" 208 changeMemoryMode(system, objects.params.atomic, **kwargs) 209 --- 26 unchanged lines hidden --- |