simulate.py (7525:722f2ad014a7) | simulate.py (7527:fe90827a663f) |
---|---|
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 --- 41 unchanged lines hidden (view full) --- 50 root = objects.Root.getInstance() 51 52 if not root: 53 fatal("Need to instantiate Root() before calling instantiate()") 54 55 # we need to fix the global frequency 56 ticks.fixGlobalFrequency() 57 | 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 --- 41 unchanged lines hidden (view full) --- 50 root = objects.Root.getInstance() 51 52 if not root: 53 fatal("Need to instantiate Root() before calling instantiate()") 54 55 # we need to fix the global frequency 56 ticks.fixGlobalFrequency() 57 |
58 root.unproxy_all() | 58 # Unproxy in sorted order for determinism 59 for obj in root.descendants(): obj.unproxyParams() |
59 60 if options.dump_config: 61 ini_file = file(os.path.join(options.outdir, options.dump_config), 'w') | 60 61 if options.dump_config: 62 ini_file = file(os.path.join(options.outdir, options.dump_config), 'w') |
62 root.print_ini(ini_file) | 63 # Print ini sections in sorted order for easier diffing 64 for obj in sorted(root.descendants(), key=lambda o: o.path()): 65 obj.print_ini(ini_file) |
63 ini_file.close() 64 65 # Initialize the global statistics 66 stats.initSimStats() 67 68 # Create the C++ sim objects and connect ports | 66 ini_file.close() 67 68 # Initialize the global statistics 69 stats.initSimStats() 70 71 # Create the C++ sim objects and connect ports |
69 root.createCCObject() 70 root.connectPorts() | 72 for obj in root.descendants(): obj.createCCObject() 73 for obj in root.descendants(): obj.connectPorts() |
71 72 # Do a second pass to finish initializing the sim objects | 74 75 # Do a second pass to finish initializing the sim objects |
73 core.initAll() | 76 for obj in root.descendants(): obj.init() |
74 75 # Do a third pass to initialize statistics | 77 78 # Do a third pass to initialize statistics |
76 core.regAllStats() | 79 for obj in root.descendants(): obj.regStats() 80 for obj in root.descendants(): obj.regFormulas() |
77 78 # We're done registering statistics. Enable the stats package now. 79 stats.enable() 80 81 # Reset to put the stats in a consistent state. 82 stats.reset() 83 84def doDot(root): --- 7 unchanged lines hidden (view full) --- 92 dot.write_ps("config.ps") 93 94need_resume = [] 95need_startup = True 96def simulate(*args, **kwargs): 97 global need_resume, need_startup 98 99 if need_startup: | 81 82 # We're done registering statistics. Enable the stats package now. 83 stats.enable() 84 85 # Reset to put the stats in a consistent state. 86 stats.reset() 87 88def doDot(root): --- 7 unchanged lines hidden (view full) --- 96 dot.write_ps("config.ps") 97 98need_resume = [] 99need_startup = True 100def simulate(*args, **kwargs): 101 global need_resume, need_startup 102 103 if need_startup: |
100 internal.core.startupAll() | 104 root = objects.Root.getInstance() 105 for obj in root.descendants(): obj.startup() |
101 need_startup = False 102 103 for root in need_resume: 104 resume(root) 105 need_resume = [] 106 107 return internal.event.simulate(*args, **kwargs) 108 --- 15 unchanged lines hidden (view full) --- 124 125# Tries to drain all objects. Draining might not be completed unless 126# all objects return that they are drained on the first call. This is 127# because as objects drain they may cause other objects to no longer 128# be drained. 129def drain(root): 130 all_drained = False 131 drain_event = internal.event.createCountedDrain() | 106 need_startup = False 107 108 for root in need_resume: 109 resume(root) 110 need_resume = [] 111 112 return internal.event.simulate(*args, **kwargs) 113 --- 15 unchanged lines hidden (view full) --- 129 130# Tries to drain all objects. Draining might not be completed unless 131# all objects return that they are drained on the first call. This is 132# because as objects drain they may cause other objects to no longer 133# be drained. 134def drain(root): 135 all_drained = False 136 drain_event = internal.event.createCountedDrain() |
132 unready_objects = root.startDrain(drain_event, True) | 137 unready_objs = sum(obj.drain(drain_event) for obj in root.descendants()) |
133 # If we've got some objects that can't drain immediately, then simulate | 138 # If we've got some objects that can't drain immediately, then simulate |
134 if unready_objects > 0: 135 drain_event.setCount(unready_objects) | 139 if unready_objs > 0: 140 drain_event.setCount(unready_objs) |
136 simulate() 137 else: 138 all_drained = True 139 internal.event.cleanupCountedDrain(drain_event) 140 return all_drained 141 142def resume(root): | 141 simulate() 142 else: 143 all_drained = True 144 internal.event.cleanupCountedDrain(drain_event) 145 return all_drained 146 147def resume(root): |
143 root.resume() | 148 for obj in root.descendants(): obj.resume() |
144 145def checkpoint(dir): 146 root = objects.Root.getInstance() 147 if not isinstance(root, objects.Root): 148 raise TypeError, "Checkpoint must be called on a root object." 149 doDrain(root) 150 print "Writing checkpoint" 151 internal.core.serializeAll(dir) --- 8 unchanged lines hidden (view full) --- 160 161def changeToAtomic(system): 162 if not isinstance(system, (objects.Root, objects.System)): 163 raise TypeError, "Parameter of type '%s'. Must be type %s or %s." % \ 164 (type(system), objects.Root, objects.System) 165 if system.getMemoryMode() != objects.params.atomic: 166 doDrain(system) 167 print "Changing memory mode to atomic" | 149 150def checkpoint(dir): 151 root = objects.Root.getInstance() 152 if not isinstance(root, objects.Root): 153 raise TypeError, "Checkpoint must be called on a root object." 154 doDrain(root) 155 print "Writing checkpoint" 156 internal.core.serializeAll(dir) --- 8 unchanged lines hidden (view full) --- 165 166def changeToAtomic(system): 167 if not isinstance(system, (objects.Root, objects.System)): 168 raise TypeError, "Parameter of type '%s'. Must be type %s or %s." % \ 169 (type(system), objects.Root, objects.System) 170 if system.getMemoryMode() != objects.params.atomic: 171 doDrain(system) 172 print "Changing memory mode to atomic" |
168 system.changeTiming(objects.params.atomic) | 173 for obj in system.descendants(): 174 obj.changeTiming(objects.params.atomic) |
169 170def changeToTiming(system): 171 if not isinstance(system, (objects.Root, objects.System)): 172 raise TypeError, "Parameter of type '%s'. Must be type %s or %s." % \ 173 (type(system), objects.Root, objects.System) 174 175 if system.getMemoryMode() != objects.params.timing: 176 doDrain(system) 177 print "Changing memory mode to timing" | 175 176def changeToTiming(system): 177 if not isinstance(system, (objects.Root, objects.System)): 178 raise TypeError, "Parameter of type '%s'. Must be type %s or %s." % \ 179 (type(system), objects.Root, objects.System) 180 181 if system.getMemoryMode() != objects.params.timing: 182 doDrain(system) 183 print "Changing memory mode to timing" |
178 system.changeTiming(objects.params.timing) | 184 for obj in system.descendants(): 185 obj.changeTiming(objects.params.timing) |
179 180def switchCpus(cpuList): 181 print "switching cpus" 182 if not isinstance(cpuList, list): 183 raise RuntimeError, "Must pass a list to this function" 184 for item in cpuList: 185 if not isinstance(item, tuple) or len(item) != 2: 186 raise RuntimeError, "List must have tuples of (oldCPU,newCPU)" --- 15 unchanged lines hidden --- | 186 187def switchCpus(cpuList): 188 print "switching cpus" 189 if not isinstance(cpuList, list): 190 raise RuntimeError, "Must pass a list to this function" 191 for item in cpuList: 192 if not isinstance(item, tuple) or len(item) != 2: 193 raise RuntimeError, "List must have tuples of (oldCPU,newCPU)" --- 15 unchanged lines hidden --- |