checkpoint_aggregator.py revision 9991
16313Sgblack@eecs.umich.edu# Copyright (c) 2009 The Regents of The University of Michigan 212529Sgiacomo.travaglini@arm.com# Copyright (c) 2011 Advanced Micro Devices, Inc. 37093Sgblack@eecs.umich.edu# Copyright (c) 2013 Mark D. Hill and David A. Wood 47093Sgblack@eecs.umich.edu# All rights reserved. 57093Sgblack@eecs.umich.edu# 67093Sgblack@eecs.umich.edu# Redistribution and use in source and binary forms, with or without 77093Sgblack@eecs.umich.edu# modification, are permitted provided that the following conditions are 87093Sgblack@eecs.umich.edu# met: redistributions of source code must retain the above copyright 97093Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer; 107093Sgblack@eecs.umich.edu# redistributions in binary form must reproduce the above copyright 117093Sgblack@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the 127093Sgblack@eecs.umich.edu# documentation and/or other materials provided with the distribution; 137093Sgblack@eecs.umich.edu# neither the name of the copyright holders nor the names of its 146313Sgblack@eecs.umich.edu# contributors may be used to endorse or promote products derived from 156313Sgblack@eecs.umich.edu# this software without specific prior written permission. 166313Sgblack@eecs.umich.edu# 176313Sgblack@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 186313Sgblack@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 196313Sgblack@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 206313Sgblack@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 216313Sgblack@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 226313Sgblack@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 236313Sgblack@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 246313Sgblack@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 256313Sgblack@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 266313Sgblack@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 276313Sgblack@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 286313Sgblack@eecs.umich.edu# 296313Sgblack@eecs.umich.edu# Authors: Lisa Hsu 306313Sgblack@eecs.umich.edu# Nilay Vaish 316313Sgblack@eecs.umich.edu 326313Sgblack@eecs.umich.edufrom ConfigParser import ConfigParser 336313Sgblack@eecs.umich.eduimport gzip 346313Sgblack@eecs.umich.edu 356313Sgblack@eecs.umich.eduimport sys, re, os 366313Sgblack@eecs.umich.edu 376313Sgblack@eecs.umich.educlass myCP(ConfigParser): 386313Sgblack@eecs.umich.edu def __init__(self): 396313Sgblack@eecs.umich.edu ConfigParser.__init__(self) 406313Sgblack@eecs.umich.edu 416313Sgblack@eecs.umich.edu def optionxform(self, optionstr): 426313Sgblack@eecs.umich.edu return optionstr 436313Sgblack@eecs.umich.edu 447404SAli.Saidi@ARM.comdef aggregate(output_dir, cpts, no_compress, memory_size): 456313Sgblack@eecs.umich.edu merged_config = None 4610461SAndreas.Sandberg@ARM.com page_ptr = 0 4712479SCurtis.Dunham@arm.com 486333Sgblack@eecs.umich.edu output_path = output_dir 4910037SARM gem5 Developers if not os.path.isdir(output_path): 507404SAli.Saidi@ARM.com os.system("mkdir -p " + output_path) 516313Sgblack@eecs.umich.edu 5212109SRekai.GonzalezAlberquilla@arm.com agg_mem_file = open(output_path + "/system.physmem.store0.pmem", "wb+") 538232Snate@binkert.org agg_config_file = open(output_path + "/m5.cpt", "wb+") 5412109SRekai.GonzalezAlberquilla@arm.com 559384SAndreas.Sandberg@arm.com if not no_compress: 5611165SRekai.GonzalezAlberquilla@arm.com merged_mem = gzip.GzipFile(fileobj= agg_mem_file, mode="wb") 576313Sgblack@eecs.umich.edu 589384SAndreas.Sandberg@arm.com max_curtick = 0 5910461SAndreas.Sandberg@ARM.com num_digits = len(str(len(cpts)-1)) 606333Sgblack@eecs.umich.edu 616313Sgblack@eecs.umich.edu for (i, arg) in enumerate(cpts): 626313Sgblack@eecs.umich.edu print arg 636313Sgblack@eecs.umich.edu merged_config = myCP() 646313Sgblack@eecs.umich.edu config = myCP() 656313Sgblack@eecs.umich.edu config.readfp(open(cpts[i] + "/m5.cpt")) 669384SAndreas.Sandberg@arm.com 676313Sgblack@eecs.umich.edu for sec in config.sections(): 686313Sgblack@eecs.umich.edu if re.compile("cpu").search(sec): 6910037SARM gem5 Developers newsec = re.sub("cpu", "cpu" + str(i).zfill(num_digits), sec) 7010037SARM gem5 Developers merged_config.add_section(newsec) 7110037SARM gem5 Developers 7211165SRekai.GonzalezAlberquilla@arm.com items = config.items(sec) 7311165SRekai.GonzalezAlberquilla@arm.com for item in items: 7412109SRekai.GonzalezAlberquilla@arm.com if item[0] == "paddr": 7511165SRekai.GonzalezAlberquilla@arm.com merged_config.set(newsec, item[0], int(item[1]) + (page_ptr << 12)) 7610461SAndreas.Sandberg@ARM.com continue 7710461SAndreas.Sandberg@ARM.com merged_config.set(newsec, item[0], item[1]) 7810461SAndreas.Sandberg@ARM.com 7910461SAndreas.Sandberg@ARM.com if re.compile("workload.FdMap256$").search(sec): 8010461SAndreas.Sandberg@ARM.com merged_config.set(newsec, "M5_pid", i) 8110461SAndreas.Sandberg@ARM.com 8210844Sandreas.sandberg@arm.com elif sec == "system": 8310844Sandreas.sandberg@arm.com pass 8410844Sandreas.sandberg@arm.com elif sec == "Globals": 8510037SARM gem5 Developers tick = config.getint(sec, "curTick") 8611771SCurtis.Dunham@arm.com if tick > max_curtick: 8710037SARM gem5 Developers max_curtick = tick 8810037SARM gem5 Developers else: 8910037SARM gem5 Developers if i == len(cpts)-1: 9010037SARM gem5 Developers merged_config.add_section(sec) 9110037SARM gem5 Developers for item in config.items(sec): 9210037SARM gem5 Developers merged_config.set(sec, item[0], item[1]) 9312478SCurtis.Dunham@arm.com 9410037SARM gem5 Developers if i != len(cpts)-1: 9512477SCurtis.Dunham@arm.com merged_config.write(agg_config_file) 9612477SCurtis.Dunham@arm.com 9712478SCurtis.Dunham@arm.com ### memory stuff 9812478SCurtis.Dunham@arm.com pages = int(config.get("system", "pagePtr")) 9912478SCurtis.Dunham@arm.com page_ptr = page_ptr + pages 10012478SCurtis.Dunham@arm.com print "pages to be read: ", pages 10112478SCurtis.Dunham@arm.com 10212478SCurtis.Dunham@arm.com f = open(cpts[i] + "/system.physmem.store0.pmem", "rb") 10312478SCurtis.Dunham@arm.com gf = gzip.GzipFile(fileobj=f, mode="rb") 10412478SCurtis.Dunham@arm.com 10512478SCurtis.Dunham@arm.com x = 0 10612478SCurtis.Dunham@arm.com while x < pages: 10712478SCurtis.Dunham@arm.com bytesRead = gf.read(1 << 12) 10812478SCurtis.Dunham@arm.com if not no_compress: 10912478SCurtis.Dunham@arm.com merged_mem.write(bytesRead) 11012478SCurtis.Dunham@arm.com else: 11112478SCurtis.Dunham@arm.com agg_mem_file.write(bytesRead) 11212478SCurtis.Dunham@arm.com x += 1 11310037SARM gem5 Developers 11410037SARM gem5 Developers gf.close() 11512477SCurtis.Dunham@arm.com f.close() 11612479SCurtis.Dunham@arm.com 11712477SCurtis.Dunham@arm.com merged_config.add_section("system") 11812477SCurtis.Dunham@arm.com merged_config.set("system", "pagePtr", page_ptr) 11912477SCurtis.Dunham@arm.com merged_config.set("system", "nextPID", len(cpts)) 12012479SCurtis.Dunham@arm.com 12112477SCurtis.Dunham@arm.com file_size = page_ptr * 4 * 1024 12212477SCurtis.Dunham@arm.com dummy_data = "".zfill(4096) 12312477SCurtis.Dunham@arm.com while file_size < memory_size: 12412477SCurtis.Dunham@arm.com if not no_compress: 12512477SCurtis.Dunham@arm.com merged_mem.write(dummy_data) 12612477SCurtis.Dunham@arm.com else: 12712477SCurtis.Dunham@arm.com agg_mem_file.write(dummy_data) 12812478SCurtis.Dunham@arm.com file_size += 4 * 1024 12912478SCurtis.Dunham@arm.com page_ptr += 1 13012478SCurtis.Dunham@arm.com 13112478SCurtis.Dunham@arm.com print "WARNING: " 13212478SCurtis.Dunham@arm.com print "Make sure the simulation using this checkpoint has at least ", 13312478SCurtis.Dunham@arm.com print page_ptr, "x 4K of memory" 13412478SCurtis.Dunham@arm.com merged_config.set("system.physmem.store0", "range_size", page_ptr * 4 * 1024) 13512478SCurtis.Dunham@arm.com 13612478SCurtis.Dunham@arm.com merged_config.add_section("Globals") 13712478SCurtis.Dunham@arm.com merged_config.set("Globals", "curTick", max_curtick) 13812478SCurtis.Dunham@arm.com 13912478SCurtis.Dunham@arm.com merged_config.write(agg_config_file) 14012478SCurtis.Dunham@arm.com 14112478SCurtis.Dunham@arm.com if not no_compress: 14212478SCurtis.Dunham@arm.com merged_mem.close() 14312478SCurtis.Dunham@arm.com agg_mem_file.close() 14412479SCurtis.Dunham@arm.com else: 14512479SCurtis.Dunham@arm.com agg_mem_file.close() 14612479SCurtis.Dunham@arm.com 14712479SCurtis.Dunham@arm.comif __name__ == "__main__": 14812479SCurtis.Dunham@arm.com from argparse import ArgumentParser 14912479SCurtis.Dunham@arm.com parser = ArgumentParser("usage: %prog [options] <directory names which "\ 15012479SCurtis.Dunham@arm.com "hold the checkpoints to be combined>") 15112479SCurtis.Dunham@arm.com parser.add_argument("-o", "--output-dir", action="store", 15212479SCurtis.Dunham@arm.com help="Output directory") 15312479SCurtis.Dunham@arm.com parser.add_argument("-c", "--no-compress", action="store_true") 15412479SCurtis.Dunham@arm.com parser.add_argument("--cpts", nargs='+') 15512479SCurtis.Dunham@arm.com parser.add_argument("--memory-size", action="store", type=int) 15612479SCurtis.Dunham@arm.com 15712479SCurtis.Dunham@arm.com # Assume x86 ISA. Any other ISAs would need extra stuff in this script 15812479SCurtis.Dunham@arm.com # to appropriately parse their page tables and understand page sizes. 15912479SCurtis.Dunham@arm.com options = parser.parse_args() 16012479SCurtis.Dunham@arm.com print options.cpts, len(options.cpts) 16112479SCurtis.Dunham@arm.com if len(options.cpts) <= 1: 16212479SCurtis.Dunham@arm.com parser.error("You must specify atleast two checkpoint files that "\ 16312479SCurtis.Dunham@arm.com "need to be combined.") 16412479SCurtis.Dunham@arm.com 16512479SCurtis.Dunham@arm.com aggregate(options.output_dir, options.cpts, options.no_compress, 16612479SCurtis.Dunham@arm.com options.memory_size) 16712479SCurtis.Dunham@arm.com