ARM: Fix multiply operations.
[gem5.git] / util / checkpoint-aggregator.py
1 # Copyright (c) 2009 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
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.
14 #
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.
26 #
27 # Authors: Lisa Hsu
28
29 from ConfigParser import ConfigParser
30 import gzip
31
32 import sys, re, optparse, os
33
34 class myCP(ConfigParser):
35 def __init__(self):
36 ConfigParser.__init__(self)
37
38 def optionxform(self, optionstr):
39 return optionstr
40
41 def aggregate(options, args):
42 merged = myCP()
43 page_ptr = 0
44
45 allfiles = os.listdir(os.getcwd())
46 cpts = []
47 for arg in args:
48 found = False
49 for f in allfiles:
50 if re.compile("cpt." + arg + ".\d+").search(f):
51 found = True
52 cpts.append(f)
53 break
54 if not found:
55 print "missing checkpoint: ", arg
56 sys.exit(1)
57
58 dirname = "-".join([options.prefix, "cpt"])
59 print dirname
60 agg_name = "-".join(args)
61 print agg_name
62 fullpath = os.path.join("..", dirname, "cpt." + agg_name + ".10000")
63 if not os.path.isdir(fullpath):
64 os.system("mkdir -p " + fullpath)
65
66 myfile = open(fullpath + "/system.physmem.physmem", "wb+")
67 merged_mem = gzip.GzipFile(fileobj=myfile, mode="wb")
68
69 max_curtick = 0
70 when = 0
71 for (i, arg) in enumerate(args):
72 config = myCP()
73 config.readfp(open(cpts[i] + "/m5.cpt"))
74
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)
81
82 items = config.items(sec)
83 for item in items:
84 if item[0] == "ppn":
85 if config.getint(sec, "tag") != 0:
86 merged.set(newsec, item[0], int(item[1]) + page_ptr)
87 continue
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)
94 continue
95 else:
96 merged.set(newsec, item[0], i)
97 continue
98 merged.set(newsec, item[0], item[1])
99 elif sec == "system":
100 pass
101 elif sec == "Globals":
102 tick = config.getint(sec, "curTick")
103 if tick > max_curtick:
104 max_curtick = tick
105 when = config.getint("system.cpu.tickEvent", "_when")
106 else:
107 if i == 0:
108 print sec
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"))
116
117 page_ptr = page_ptr + int(config.get("system", "page_ptr"))
118
119 ### memory stuff
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
124
125 bytesRead = gf.read(int(config.get("system", "page_ptr")) << 13)
126 merged_mem.write(bytesRead)
127
128 gf.close()
129 f.close()
130
131 merged.add_section("system")
132 merged.set("system", "page_ptr", page_ptr)
133 print "WARNING: "
134 print "Make sure the simulation using this checkpoint has at least "
135 if page_ptr > (1<<20):
136 print "8G ",
137 elif page_ptr > (1<<19):
138 print "4G ",
139 elif page_ptr > (1<<18):
140 print "2G ",
141 elif page_ptr > (1<<17):
142 print "1G ",
143 elif page_ptr > (1<<16):
144 print "512KB ",
145 else:
146 print "this is a small sim, you're probably fine",
147 print "of memory."
148
149 merged.add_section("Globals")
150 merged.set("Globals", "curTick", max_curtick)
151
152 for i in xrange(len(args)):
153 merged.set("system.cpu" + str(i) + ".tickEvent", "_when", when)
154
155 merged.write(file(fullpath + "/m5.cpt", "wb"))
156 merged_mem.close()
157 myfile.close()
158
159 if __name__ == "__main__":
160
161 parser = optparse.OptionParser()
162 parser.add_option("--prefix", type="string", default="agg")
163
164 (options, args) = parser.parse_args()
165
166 aggregate(options, args)
167