1 # Copyright (c) 2006 The Regents of The University of Michigan
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
9 # notice, this list of conditions and the following disclaimer in the
10 # documentation and/or other materials provided with the distribution;
11 # neither the name of the copyright holders nor the names of its
12 # contributors may be used to endorse or promote products derived from
13 # this software without specific prior written permission.
15 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 from m5
.objects
import *
32 m5
.AddToPath('../common')
33 from Caches
import L1Cache
35 def run(options
, root
, testsys
):
37 maxtick
= options
.maxtick
39 simtime
= int(options
.maxtime
* root
.clock
.value
)
40 print "simulating for: ", simtime
45 if options
.checkpoint_dir
:
46 cptdir
= options
.checkpoint_dir
51 max_checkpoints
= options
.max_checkpoints
53 if options
.standard_switch
:
54 switch_cpus
= [TimingSimpleCPU(defer_registration
=True, cpu_id
=(np
+i
))
56 switch_cpus1
= [DerivO3CPU(defer_registration
=True, cpu_id
=(2*np
+i
))
59 switch_cpus
[i
].system
= testsys
60 switch_cpus1
[i
].system
= testsys
61 if not m5
.build_env
['FULL_SYSTEM']:
62 switch_cpus
[i
].workload
= testsys
.cpu
[i
].workload
63 switch_cpus1
[i
].workload
= testsys
.cpu
[i
].workload
64 switch_cpus
[i
].clock
= testsys
.cpu
[0].clock
65 switch_cpus1
[i
].clock
= testsys
.cpu
[0].clock
67 switch_cpus
[i
].addPrivateSplitL1Caches(L1Cache(size
= '32kB'),
68 L1Cache(size
= '64kB'))
70 switch_cpus
[i
].mem
= testsys
.physmem
71 switch_cpus1
[i
].mem
= testsys
.physmem
72 switch_cpus
[i
].connectMemPorts(testsys
.membus
)
73 root
.switch_cpus
= switch_cpus
74 root
.switch_cpus1
= switch_cpus1
75 switch_cpu_list
= [(testsys
.cpu
[i
], switch_cpus
[i
]) for i
in xrange(np
)]
76 switch_cpu_list1
= [(switch_cpus
[i
], switch_cpus1
[i
]) for i
in xrange(np
)]
80 if options
.checkpoint_restore
:
81 from os
.path
import isdir
82 from os
import listdir
86 m5
.panic("checkpoint dir %s does not exist!" % cptdir
)
88 dirs
= listdir(cptdir
)
89 expr
= re
.compile('cpt.([0-9]*)')
92 match
= expr
.match(dir)
94 cpts
.append(match
.group(1))
96 cpts
.sort(lambda a
,b
: cmp(long(a
), long(b
)))
98 cpt_num
= options
.checkpoint_restore
100 if cpt_num
> len(cpts
):
101 m5
.panic('Checkpoint %d not found' % cpt_num
)
103 m5
.restoreCheckpoint(root
,
104 "/".join([cptdir
, "cpt.%s" % cpts
[cpt_num
- 1]]))
106 if options
.standard_switch
:
107 exit_event
= m5
.simulate(10000)
109 ## when you change to Timing (or Atomic), you halt the system given
110 ## as argument. When you are finished with the system changes
111 ## (including switchCpus), you must resume the system manually.
112 ## You DON'T need to resume after just switching CPUs if you haven't
113 ## changed anything on the system level.
115 m5
.changeToTiming(testsys
)
116 m5
.switchCpus(switch_cpu_list
)
119 exit_event
= m5
.simulate(options
.warmup
)
120 m5
.switchCpus(switch_cpu_list1
)
125 ## Checkpoints being taken via the command line at <when> and at subsequent
126 ## periods of <period>. Checkpoint instructions received from the benchmark running
127 ## are ignored and skipped in favor of command line checkpoint instructions.
128 if options
.take_checkpoints
:
129 [when
, period
] = options
.take_checkpoints
.split(",", 1)
133 exit_event
= m5
.simulate(when
)
134 while exit_event
.getCause() == "checkpoint":
135 exit_event
= m5
.simulate(when
- m5
.curTick())
137 if exit_event
.getCause() == "simulate() limit reached":
138 m5
.checkpoint(root
, "/".join([cptdir
,"cpt.%d"]))
142 exit_cause
= "maximum %d checkpoints dropped" % max_checkpoints
143 while num_checkpoints
< max_checkpoints
:
144 if (sim_ticks
+ period
) > maxtick
and maxtick
!= -1:
145 exit_event
= m5
.simulate(maxtick
- sim_ticks
)
146 exit_cause
= exit_event
.getCause()
149 exit_event
= m5
.simulate(period
)
151 while exit_event
.getCause() == "checkpoint":
152 exit_event
= m5
.simulate(sim_ticks
- m5
.curTick())
153 if exit_event
.getCause() == "simulate() limit reached":
154 m5
.checkpoint(root
, "/".join([cptdir
,"cpt.%d"]))
157 else: #no checkpoints being taken via this script
158 exit_event
= m5
.simulate(maxtick
)
160 while exit_event
.getCause() == "checkpoint":
161 m5
.checkpoint(root
, "/".join([cptdir
,"cpt.%d"]))
163 if num_checkpoints
== max_checkpoints
:
164 exit_cause
= "maximum %d checkpoints dropped" % max_checkpoints
168 exit_event
= m5
.simulate(maxtick
)
170 exit_event
= m5
.simulate(maxtick
- m5
.curTick())
172 exit_cause
= exit_event
.getCause()
175 exit_cause
= exit_event
.getCause()
176 print 'Exiting @ cycle', m5
.curTick(), 'because ', exit_cause