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"])
59 agg_name
= "-".join(args
)
61 fullpath
= os
.path
.join("..", dirname
, "cpt." + agg_name
+ ".10000")
62 if not os
.path
.isdir(fullpath
):
63 os
.system("mkdir -p " + fullpath
)
64 elif os
.path
.isfile(fullpath
+ "/system.physmem.physmem"):
65 if os
.path
.isfile(fullpath
+ "/m5.cpt"):
66 print fullpath
, " already done"
69 myfile
= open(fullpath
+ "/system.physmem.physmem", "wb+")
70 merged_mem
= gzip
.GzipFile(fileobj
=myfile
, mode
="wb")
74 for (i
, arg
) in enumerate(args
):
77 config
.readfp(open(cpts
[i
] + "/m5.cpt"))
79 for sec
in config
.sections():
80 if re
.compile("cpu").search(sec
):
81 newsec
= re
.sub("cpu", "cpu" + str(i
), sec
)
82 merged
.add_section(newsec
)
83 if re
.compile("workload$").search(sec
):
84 merged
.set(newsec
, "M5_pid", i
)
86 items
= config
.items(sec
)
89 if config
.getint(sec
, "tag") != 0:
90 merged
.set(newsec
, item
[0], int(item
[1]) + page_ptr
)
92 elif item
[0] == "asn":
93 tmp
= re
.compile("(.*).Entry(\d+)").search(sec
).groups()
94 if config
.has_option(tmp
[0], "nlu"):
95 size
= config
.getint(tmp
[0], "nlu")
96 if int(tmp
[1]) < size
:
97 merged
.set(newsec
, item
[0], i
)
100 merged
.set(newsec
, item
[0], i
)
102 merged
.set(newsec
, item
[0], item
[1])
103 elif sec
== "system":
105 elif sec
== "Globals":
106 tick
= config
.getint(sec
, "curTick")
107 if tick
> max_curtick
:
109 when
= config
.getint("system.cpu.tickEvent", "_when")
112 merged
.add_section(sec
)
113 for item
in config
.items(sec
):
114 merged
.set(sec
, item
[0], item
[1])
115 if item
[0] == "curtick":
116 merged
.optionxform(str("curTick"))
117 elif item
[0] == "numevents":
118 merged
.optionxform(str("numEvents"))
120 page_ptr
= page_ptr
+ int(config
.get("system", "page_ptr"))
123 f
= open(cpts
[i
] + "/system.physmem.physmem", "rb")
124 gf
= gzip
.GzipFile(fileobj
=f
, mode
="rb")
125 pages
= int(config
.get("system", "page_ptr"))
126 print "pages to be read: ", pages
130 bytesRead
= gf
.read(1 << 13)
131 merged_mem
.write(bytesRead
)
137 merged
.add_section("system")
138 merged
.set("system", "page_ptr", page_ptr
)
140 print "Make sure the simulation using this checkpoint has at least "
141 if page_ptr
> (1<<20):
143 elif page_ptr
> (1<<19):
145 elif page_ptr
> (1<<18):
147 elif page_ptr
> (1<<17):
149 elif page_ptr
> (1<<16):
152 print "this is a small sim, you're probably fine",
155 merged
.add_section("Globals")
156 merged
.set("Globals", "curTick", max_curtick
)
158 for i
in xrange(len(args
)):
159 merged
.set("system.cpu" + str(i
) + ".tickEvent", "_when", when
)
161 merged
.write(file(fullpath
+ "/m5.cpt", "wb"))
165 if __name__
== "__main__":
167 parser
= optparse
.OptionParser()
168 parser
.add_option("--prefix", type="string", default
="agg")
170 (options
, args
) = parser
.parse_args()
172 aggregate(options
, args
)