PageRenderTime 49ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/util/checkpoint_aggregator.py

https://bitbucket.org/musleh123/ece565
Python | 182 lines | 124 code | 26 blank | 32 comment | 37 complexity | e9f7b4589c897ba8c9d21ea89bf5babc MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, WTFPL
  1. # Copyright (c) 2009 The Regents of The University of Michigan
  2. # Copyright (c) 2011 Advanced Micro Devices, Inc.
  3. # All rights reserved.
  4. #
  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.
  15. #
  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.
  27. #
  28. # Authors: Lisa Hsu
  29. from ConfigParser import ConfigParser
  30. import gzip
  31. import sys, re, optparse, os
  32. class myCP(ConfigParser):
  33. def __init__(self):
  34. ConfigParser.__init__(self)
  35. def optionxform(self, optionstr):
  36. return optionstr
  37. def aggregate(options, args):
  38. merged = myCP()
  39. page_ptr = 0
  40. allfiles = os.listdir(os.getcwd())
  41. cpts = []
  42. for arg in args:
  43. found = False
  44. for f in allfiles:
  45. if re.compile("cpt." + arg + ".\d+").search(f):
  46. found = True
  47. cpts.append(f)
  48. break
  49. if not found:
  50. print "missing checkpoint: ", arg
  51. sys.exit(1)
  52. dirname = "-".join([options.prefix, "cpt"])
  53. agg_name = "-".join(args)
  54. print agg_name
  55. fullpath = os.path.join("..", dirname, "cpt." + agg_name + ".10000")
  56. if not os.path.isdir(fullpath):
  57. os.system("mkdir -p " + fullpath)
  58. elif os.path.isfile(fullpath + "/system.physmem.physmem"):
  59. if os.path.isfile(fullpath + "/m5.cpt"):
  60. print fullpath, " already done"
  61. return
  62. myfile = open(fullpath + "/system.physmem.physmem", "wb+")
  63. merged_mem = gzip.GzipFile(fileobj=myfile, mode="wb")
  64. max_curtick = 0
  65. when = 0
  66. for (i, arg) in enumerate(args):
  67. print arg
  68. config = myCP()
  69. config.readfp(open(cpts[i] + "/m5.cpt"))
  70. for sec in config.sections():
  71. if re.compile("cpu").search(sec):
  72. newsec = re.sub("cpu", "cpu" + str(i), sec)
  73. merged.add_section(newsec)
  74. if re.compile("workload$").search(sec):
  75. merged.set(newsec, "M5_pid", i)
  76. items = config.items(sec)
  77. if options.alpha:
  78. for item in items:
  79. if item[0] == "ppn":
  80. if config.getint(sec, "tag") != 0:
  81. merged.set(newsec, item[0], int(item[1]) + page_ptr)
  82. continue
  83. elif item[0] == "asn":
  84. tmp = re.compile("(.*).Entry(\d+)").search(sec).groups()
  85. if config.has_option(tmp[0], "nlu"):
  86. size = config.getint(tmp[0], "nlu")
  87. if int(tmp[1]) < size:
  88. merged.set(newsec, item[0], i)
  89. continue
  90. else:
  91. merged.set(newsec, item[0], i)
  92. continue
  93. merged.set(newsec, item[0], item[1])
  94. else:a #x86
  95. for item in items:
  96. if item[0] == "paddr":
  97. merged.set(newsec, item[0], int(item[1]) + (page_ptr << 12))
  98. continue
  99. merged.set(newsec, item[0], item[1])
  100. elif sec == "system":
  101. pass
  102. elif sec == "Globals":
  103. tick = config.getint(sec, "curTick")
  104. if tick > max_curtick:
  105. max_curtick = tick
  106. when = config.getint("system.cpu.tickEvent", "_when")
  107. else:
  108. if i == 0:
  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. page_ptr = page_ptr + int(config.get("system", "pagePtr"))
  117. ### memory stuff
  118. f = open(cpts[i] + "/system.physmem.physmem", "rb")
  119. gf = gzip.GzipFile(fileobj=f, mode="rb")
  120. pages = int(config.get("system", "pagePtr"))
  121. print "pages to be read: ", pages
  122. x = 0
  123. while x < pages:
  124. if options.alpha:
  125. bytesRead = gf.read(1 << 13)
  126. else: #x86
  127. bytesRead = gf.read(1 << 12)
  128. merged_mem.write(bytesRead)
  129. x += 1
  130. gf.close()
  131. f.close()
  132. merged.add_section("system")
  133. merged.set("system", "pagePtr", page_ptr)
  134. merged.set("system", "nextPID", len(args))
  135. print "WARNING: "
  136. print "Make sure the simulation using this checkpoint has at least ",
  137. if options.alpha:
  138. print page_ptr, "x 8K of memory"
  139. else: # assume x86
  140. print page_ptr, "x 4K of memory"
  141. merged.add_section("Globals")
  142. merged.set("Globals", "curTick", max_curtick)
  143. for i in xrange(len(args)):
  144. merged.set("system.cpu" + str(i) + ".tickEvent", "_when", when)
  145. merged.write(file(fullpath + "/m5.cpt", "wb"))
  146. merged_mem.close()
  147. myfile.close()
  148. if __name__ == "__main__":
  149. parser = optparse.OptionParser()
  150. parser.add_option("--prefix", type="string", default="agg")
  151. # If not alpha, then assume x86. Any other ISAs would need
  152. # extra stuff in this script to appropriately parse their page tables
  153. # and understand page sizes.
  154. parser.add_option("--alpha", action="store_true")
  155. (options, args) = parser.parse_args()
  156. aggregate(options, args)