1 # Copyright (c) 2009 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.
29 from ConfigParser
import ConfigParser
32 import sys
, re
, optparse
, os
34 class myCP(ConfigParser
):
36 ConfigParser
.__init
__(self
)
38 def optionxform(self
, optionstr
):
41 def aggregate(options
, args
):
45 allfiles
= os
.listdir(os
.getcwd())
50 if re
.compile("cpt." + arg
+ ".\d+").search(f
):
55 print "missing checkpoint: ", arg
58 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
)
66 myfile
= open(fullpath
+ "/system.physmem.physmem", "wb+")
67 merged_mem
= gzip
.GzipFile(fileobj
=myfile
, mode
="wb")
71 for (i
, arg
) in enumerate(args
):
73 config
.readfp(open(cpts
[i
] + "/m5.cpt"))
75 for sec
in config
.sections():
76 if re
.compile("cpu").search(sec
):
77 newsec
= re
.sub("cpu", "cpu" + str(i
), sec
)
78 merged
.add_section(newsec
)
79 if re
.compile("workload$").search(sec
):
80 merged
.set(newsec
, "M5_pid", i
)
82 items
= config
.items(sec
)
85 if config
.getint(sec
, "tag") != 0:
86 merged
.set(newsec
, item
[0], int(item
[1]) + page_ptr
)
88 elif item
[0] == "asn":
89 tmp
= re
.compile("(.*).Entry(\d+)").search(sec
).groups()
90 if config
.has_option(tmp
[0], "nlu"):
91 size
= config
.getint(tmp
[0], "nlu")
92 if int(tmp
[1]) < size
:
93 merged
.set(newsec
, item
[0], i
)
96 merged
.set(newsec
, item
[0], i
)
98 merged
.set(newsec
, item
[0], item
[1])
101 elif sec
== "Globals":
102 tick
= config
.getint(sec
, "curTick")
103 if tick
> max_curtick
:
105 when
= config
.getint("system.cpu.tickEvent", "_when")
109 merged
.add_section(sec
)
110 for item
in config
.items(sec
):
111 merged
.set(sec
, item
[0], item
[1])
112 if item
[0] == "curtick":
113 merged
.optionxform(str("curTick"))
114 elif item
[0] == "numevents":
115 merged
.optionxform(str("numEvents"))
117 page_ptr
= page_ptr
+ int(config
.get("system", "page_ptr"))
120 f
= open(cpts
[i
] + "/system.physmem.physmem", "rb")
121 gf
= gzip
.GzipFile(fileobj
=f
, mode
="rb")
122 bytes
= int(config
.get("system", "page_ptr")) << 13
123 print "bytes to be read: ", bytes
125 bytesRead
= gf
.read(int(config
.get("system", "page_ptr")) << 13)
126 merged_mem
.write(bytesRead
)
131 merged
.add_section("system")
132 merged
.set("system", "page_ptr", page_ptr
)
134 print "Make sure the simulation using this checkpoint has at least "
135 if page_ptr
> (1<<20):
137 elif page_ptr
> (1<<19):
139 elif page_ptr
> (1<<18):
141 elif page_ptr
> (1<<17):
143 elif page_ptr
> (1<<16):
146 print "this is a small sim, you're probably fine",
149 merged
.add_section("Globals")
150 merged
.set("Globals", "curTick", max_curtick
)
152 for i
in xrange(len(args
)):
153 merged
.set("system.cpu" + str(i
) + ".tickEvent", "_when", when
)
155 merged
.write(file(fullpath
+ "/m5.cpt", "wb"))
159 if __name__
== "__main__":
161 parser
= optparse
.OptionParser()
162 parser
.add_option("--prefix", type="string", default
="agg")
164 (options
, args
) = parser
.parse_args()
166 aggregate(options
, args
)