1 # Copyright (c) 2009 The Regents of The University of Michigan
2 # Copyright (c) 2011 Advanced Micro Devices, Inc.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
7 # met: redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer;
9 # redistributions in binary form must reproduce the above copyright
10 # notice, this list of conditions and the following disclaimer in the
11 # documentation and/or other materials provided with the distribution;
12 # neither the name of the copyright holders nor the names of its
13 # contributors may be used to endorse or promote products derived from
14 # this software without specific prior written permission.
16 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 from ConfigParser
import ConfigParser
33 import sys
, re
, optparse
, os
35 class myCP(ConfigParser
):
37 ConfigParser
.__init
__(self
)
39 def optionxform(self
, optionstr
):
42 def aggregate(options
, args
):
46 allfiles
= os
.listdir(os
.getcwd())
51 if re
.compile("cpt." + arg
+ ".\d+").search(f
):
56 print "missing checkpoint: ", arg
59 dirname
= "-".join([options
.prefix
, "cpt"])
60 agg_name
= "-".join(args
)
62 fullpath
= os
.path
.join("..", dirname
, "cpt." + agg_name
+ ".10000")
63 if not os
.path
.isdir(fullpath
):
64 os
.system("mkdir -p " + fullpath
)
65 elif os
.path
.isfile(fullpath
+ "/system.physmem.physmem"):
66 if os
.path
.isfile(fullpath
+ "/m5.cpt"):
67 print fullpath
, " already done"
70 myfile
= open(fullpath
+ "/system.physmem.physmem", "wb+")
71 merged_mem
= gzip
.GzipFile(fileobj
=myfile
, mode
="wb")
75 for (i
, arg
) in enumerate(args
):
78 config
.readfp(open(cpts
[i
] + "/m5.cpt"))
80 for sec
in config
.sections():
81 if re
.compile("cpu").search(sec
):
82 newsec
= re
.sub("cpu", "cpu" + str(i
), sec
)
83 merged
.add_section(newsec
)
84 if re
.compile("workload$").search(sec
):
85 merged
.set(newsec
, "M5_pid", i
)
87 items
= config
.items(sec
)
91 if config
.getint(sec
, "tag") != 0:
92 merged
.set(newsec
, item
[0], int(item
[1]) + page_ptr
)
94 elif item
[0] == "asn":
95 tmp
= re
.compile("(.*).Entry(\d+)").search(sec
).groups()
96 if config
.has_option(tmp
[0], "nlu"):
97 size
= config
.getint(tmp
[0], "nlu")
98 if int(tmp
[1]) < size
:
99 merged
.set(newsec
, item
[0], i
)
102 merged
.set(newsec
, item
[0], i
)
104 merged
.set(newsec
, item
[0], item
[1])
107 if item
[0] == "paddr":
108 merged
.set(newsec
, item
[0], int(item
[1]) + (page_ptr
<< 12))
110 merged
.set(newsec
, item
[0], item
[1])
112 elif sec
== "system":
114 elif sec
== "Globals":
115 tick
= config
.getint(sec
, "curTick")
116 if tick
> max_curtick
:
118 when
= config
.getint("system.cpu.tickEvent", "_when")
121 merged
.add_section(sec
)
122 for item
in config
.items(sec
):
123 merged
.set(sec
, item
[0], item
[1])
124 if item
[0] == "curtick":
125 merged
.optionxform(str("curTick"))
126 elif item
[0] == "numevents":
127 merged
.optionxform(str("numEvents"))
129 page_ptr
= page_ptr
+ int(config
.get("system", "pagePtr"))
132 f
= open(cpts
[i
] + "/system.physmem.physmem", "rb")
133 gf
= gzip
.GzipFile(fileobj
=f
, mode
="rb")
134 pages
= int(config
.get("system", "pagePtr"))
135 print "pages to be read: ", pages
140 bytesRead
= gf
.read(1 << 13)
142 bytesRead
= gf
.read(1 << 12)
143 merged_mem
.write(bytesRead
)
149 merged
.add_section("system")
150 merged
.set("system", "pagePtr", page_ptr
)
151 merged
.set("system", "nextPID", len(args
))
154 print "Make sure the simulation using this checkpoint has at least ",
156 print page_ptr
, "x 8K of memory"
158 print page_ptr
, "x 4K of memory"
160 merged
.add_section("Globals")
161 merged
.set("Globals", "curTick", max_curtick
)
163 for i
in xrange(len(args
)):
164 merged
.set("system.cpu" + str(i
) + ".tickEvent", "_when", when
)
166 merged
.write(file(fullpath
+ "/m5.cpt", "wb"))
170 if __name__
== "__main__":
172 parser
= optparse
.OptionParser()
173 parser
.add_option("--prefix", type="string", default
="agg")
174 # If not alpha, then assume x86. Any other ISAs would need
175 # extra stuff in this script to appropriately parse their page tables
176 # and understand page sizes.
177 parser
.add_option("--alpha", action
="store_true")
179 (options
, args
) = parser
.parse_args()
181 aggregate(options
, args
)