main.py revision 4046
12889Sbinkertn@umich.edu# Copyright (c) 2005 The Regents of The University of Michigan 22889Sbinkertn@umich.edu# All rights reserved. 32889Sbinkertn@umich.edu# 42889Sbinkertn@umich.edu# Redistribution and use in source and binary forms, with or without 52889Sbinkertn@umich.edu# modification, are permitted provided that the following conditions are 62889Sbinkertn@umich.edu# met: redistributions of source code must retain the above copyright 72889Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer; 82889Sbinkertn@umich.edu# redistributions in binary form must reproduce the above copyright 92889Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer in the 102889Sbinkertn@umich.edu# documentation and/or other materials provided with the distribution; 112889Sbinkertn@umich.edu# neither the name of the copyright holders nor the names of its 122889Sbinkertn@umich.edu# contributors may be used to endorse or promote products derived from 132889Sbinkertn@umich.edu# this software without specific prior written permission. 142889Sbinkertn@umich.edu# 152889Sbinkertn@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 162889Sbinkertn@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 172889Sbinkertn@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 182889Sbinkertn@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 192889Sbinkertn@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 202889Sbinkertn@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 212889Sbinkertn@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 222889Sbinkertn@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 232889Sbinkertn@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 242889Sbinkertn@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 252889Sbinkertn@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 262889Sbinkertn@umich.edu# 272889Sbinkertn@umich.edu# Authors: Nathan Binkert 282889Sbinkertn@umich.edu 292889Sbinkertn@umich.eduimport code, optparse, os, socket, sys 302889Sbinkertn@umich.edufrom datetime import datetime 312889Sbinkertn@umich.edufrom attrdict import attrdict 322889Sbinkertn@umich.edu 332889Sbinkertn@umich.edu__all__ = [ 'options', 'arguments', 'main' ] 342889Sbinkertn@umich.edu 352889Sbinkertn@umich.eduusage="%prog [m5 options] script.py [script options]" 362889Sbinkertn@umich.eduversion="%prog 2.0" 372889Sbinkertn@umich.edubrief_copyright=''' 382889Sbinkertn@umich.eduCopyright (c) 2001-2006 392889Sbinkertn@umich.eduThe Regents of The University of Michigan 402889Sbinkertn@umich.eduAll Rights Reserved 412889Sbinkertn@umich.edu''' 422889Sbinkertn@umich.edu 432889Sbinkertn@umich.edu# there's only one option parsing done, so make it global and add some 442889Sbinkertn@umich.edu# helper functions to make it work well. 452889Sbinkertn@umich.eduparser = optparse.OptionParser(usage=usage, version=version, 462889Sbinkertn@umich.edu description=brief_copyright, 472889Sbinkertn@umich.edu formatter=optparse.TitledHelpFormatter()) 482890Sbinkertn@umich.eduparser.disable_interspersed_args() 492889Sbinkertn@umich.edu 502889Sbinkertn@umich.edu# current option group 512889Sbinkertn@umich.edugroup = None 522889Sbinkertn@umich.edu 532889Sbinkertn@umich.edudef set_group(*args, **kwargs): 542889Sbinkertn@umich.edu '''set the current option group''' 552889Sbinkertn@umich.edu global group 562889Sbinkertn@umich.edu if not args and not kwargs: 572889Sbinkertn@umich.edu group = None 582889Sbinkertn@umich.edu else: 592889Sbinkertn@umich.edu group = parser.add_option_group(*args, **kwargs) 602889Sbinkertn@umich.edu 612889Sbinkertn@umich.educlass splitter(object): 622889Sbinkertn@umich.edu def __init__(self, split): 632889Sbinkertn@umich.edu self.split = split 642889Sbinkertn@umich.edu def __call__(self, option, opt_str, value, parser): 652889Sbinkertn@umich.edu getattr(parser.values, option.dest).extend(value.split(self.split)) 662889Sbinkertn@umich.edu 672889Sbinkertn@umich.edudef add_option(*args, **kwargs): 682889Sbinkertn@umich.edu '''add an option to the current option group, or global none set''' 692889Sbinkertn@umich.edu 702889Sbinkertn@umich.edu # if action=split, but allows the option arguments 712889Sbinkertn@umich.edu # themselves to be lists separated by the split variable''' 722889Sbinkertn@umich.edu 732889Sbinkertn@umich.edu if kwargs.get('action', None) == 'append' and 'split' in kwargs: 742889Sbinkertn@umich.edu split = kwargs.pop('split') 752889Sbinkertn@umich.edu kwargs['default'] = [] 762889Sbinkertn@umich.edu kwargs['type'] = 'string' 772889Sbinkertn@umich.edu kwargs['action'] = 'callback' 782889Sbinkertn@umich.edu kwargs['callback'] = splitter(split) 792889Sbinkertn@umich.edu 802889Sbinkertn@umich.edu if group: 812889Sbinkertn@umich.edu return group.add_option(*args, **kwargs) 822889Sbinkertn@umich.edu 832889Sbinkertn@umich.edu return parser.add_option(*args, **kwargs) 842889Sbinkertn@umich.edu 852889Sbinkertn@umich.edudef bool_option(name, default, help): 862889Sbinkertn@umich.edu '''add a boolean option called --name and --no-name. 872889Sbinkertn@umich.edu Display help depending on which is the default''' 882889Sbinkertn@umich.edu 892889Sbinkertn@umich.edu tname = '--%s' % name 902889Sbinkertn@umich.edu fname = '--no-%s' % name 912889Sbinkertn@umich.edu dest = name.replace('-', '_') 922889Sbinkertn@umich.edu if default: 932889Sbinkertn@umich.edu thelp = optparse.SUPPRESS_HELP 942889Sbinkertn@umich.edu fhelp = help 952889Sbinkertn@umich.edu else: 962889Sbinkertn@umich.edu thelp = help 972889Sbinkertn@umich.edu fhelp = optparse.SUPPRESS_HELP 982889Sbinkertn@umich.edu 992889Sbinkertn@umich.edu add_option(tname, action="store_true", default=default, help=thelp) 1002889Sbinkertn@umich.edu add_option(fname, action="store_false", dest=dest, help=fhelp) 1012889Sbinkertn@umich.edu 1022889Sbinkertn@umich.edu# Help options 1032889Sbinkertn@umich.eduadd_option('-A', "--authors", action="store_true", default=False, 1042889Sbinkertn@umich.edu help="Show author information") 1052889Sbinkertn@umich.eduadd_option('-C', "--copyright", action="store_true", default=False, 1062889Sbinkertn@umich.edu help="Show full copyright information") 1072889Sbinkertn@umich.eduadd_option('-R', "--readme", action="store_true", default=False, 1082889Sbinkertn@umich.edu help="Show the readme") 1092889Sbinkertn@umich.eduadd_option('-N', "--release-notes", action="store_true", default=False, 1102889Sbinkertn@umich.edu help="Show the release notes") 1112889Sbinkertn@umich.edu 1122889Sbinkertn@umich.edu# Options for configuring the base simulator 1132889Sbinkertn@umich.eduadd_option('-d', "--outdir", metavar="DIR", default=".", 1142889Sbinkertn@umich.edu help="Set the output directory to DIR [Default: %default]") 1152889Sbinkertn@umich.eduadd_option('-i', "--interactive", action="store_true", default=False, 1162889Sbinkertn@umich.edu help="Invoke the interactive interpreter after running the script") 1172899Sbinkertn@umich.eduadd_option("--pdb", action="store_true", default=False, 1182899Sbinkertn@umich.edu help="Invoke the python debugger before running the script") 1192889Sbinkertn@umich.eduadd_option('-p', "--path", metavar="PATH[:PATH]", action='append', split=':', 1202889Sbinkertn@umich.edu help="Prepend PATH to the system path when invoking the script") 1212889Sbinkertn@umich.eduadd_option('-q', "--quiet", action="count", default=0, 1222889Sbinkertn@umich.edu help="Reduce verbosity") 1232889Sbinkertn@umich.eduadd_option('-v', "--verbose", action="count", default=0, 1242889Sbinkertn@umich.edu help="Increase verbosity") 1252889Sbinkertn@umich.edu 1262889Sbinkertn@umich.edu# Statistics options 1272889Sbinkertn@umich.eduset_group("Statistics Options") 1282889Sbinkertn@umich.eduadd_option("--stats-file", metavar="FILE", default="m5stats.txt", 1292889Sbinkertn@umich.edu help="Sets the output file for statistics [Default: %default]") 1302889Sbinkertn@umich.edu 1312889Sbinkertn@umich.edu# Debugging options 1322889Sbinkertn@umich.eduset_group("Debugging Options") 1332889Sbinkertn@umich.eduadd_option("--debug-break", metavar="TIME[,TIME]", action='append', split=',', 1342889Sbinkertn@umich.edu help="Cycle to create a breakpoint") 1352889Sbinkertn@umich.edu 1362889Sbinkertn@umich.edu# Tracing options 1372889Sbinkertn@umich.eduset_group("Trace Options") 1382889Sbinkertn@umich.eduadd_option("--trace-flags", metavar="FLAG[,FLAG]", action='append', split=',', 1392889Sbinkertn@umich.edu help="Sets the flags for tracing") 1404044Sbinkertn@umich.eduadd_option("--trace-start", metavar="TIME", type='int', 1414044Sbinkertn@umich.edu help="Start tracing at TIME (must be in ticks)") 1422889Sbinkertn@umich.eduadd_option("--trace-file", metavar="FILE", default="cout", 1432889Sbinkertn@umich.edu help="Sets the output file for tracing [Default: %default]") 1442889Sbinkertn@umich.eduadd_option("--trace-ignore", metavar="EXPR", action='append', split=':', 1452889Sbinkertn@umich.edu help="Ignore EXPR sim objects") 1462889Sbinkertn@umich.edu 1472889Sbinkertn@umich.edu# Execution Trace options 1482889Sbinkertn@umich.eduset_group("Execution Trace Options") 1492889Sbinkertn@umich.edubool_option("speculative", default=True, 1502889Sbinkertn@umich.edu help="Don't capture speculative instructions") 1512889Sbinkertn@umich.edubool_option("print-cycle", default=True, 1522889Sbinkertn@umich.edu help="Don't print cycle numbers in trace output") 1532889Sbinkertn@umich.edubool_option("print-symbol", default=True, 1542889Sbinkertn@umich.edu help="Disable PC symbols in trace output") 1552889Sbinkertn@umich.edubool_option("print-opclass", default=True, 1562889Sbinkertn@umich.edu help="Don't print op class type in trace output") 1572889Sbinkertn@umich.edubool_option("print-thread", default=True, 1582889Sbinkertn@umich.edu help="Don't print thread number in trace output") 1592889Sbinkertn@umich.edubool_option("print-effaddr", default=True, 1602889Sbinkertn@umich.edu help="Don't print effective address in trace output") 1612889Sbinkertn@umich.edubool_option("print-data", default=True, 1622889Sbinkertn@umich.edu help="Don't print result data in trace output") 1632889Sbinkertn@umich.edubool_option("print-iregs", default=False, 1642889Sbinkertn@umich.edu help="Print fetch sequence numbers in trace output") 1652889Sbinkertn@umich.edubool_option("print-fetch-seq", default=False, 1662889Sbinkertn@umich.edu help="Print fetch sequence numbers in trace output") 1672889Sbinkertn@umich.edubool_option("print-cpseq", default=False, 1682889Sbinkertn@umich.edu help="Print correct path sequence numbers in trace output") 1692973Sgblack@eecs.umich.edu#bool_option("print-reg-delta", default=False, 1702973Sgblack@eecs.umich.edu# help="Print which registers changed to what in trace output") 1713506Ssaidi@eecs.umich.edubool_option("legion-lock", default=False, 1723506Ssaidi@eecs.umich.edu help="Compare simulator state with Legion simulator every cycle") 1732889Sbinkertn@umich.edu 1742889Sbinkertn@umich.eduoptions = attrdict() 1752889Sbinkertn@umich.eduarguments = [] 1762889Sbinkertn@umich.edu 1772889Sbinkertn@umich.edudef usage(exitcode=None): 1782903Ssaidi@eecs.umich.edu parser.print_help() 1792889Sbinkertn@umich.edu if exitcode is not None: 1802889Sbinkertn@umich.edu sys.exit(exitcode) 1812889Sbinkertn@umich.edu 1822889Sbinkertn@umich.edudef parse_args(): 1832889Sbinkertn@umich.edu _opts,args = parser.parse_args() 1842889Sbinkertn@umich.edu opts = attrdict(_opts.__dict__) 1852889Sbinkertn@umich.edu 1862889Sbinkertn@umich.edu # setting verbose and quiet at the same time doesn't make sense 1872889Sbinkertn@umich.edu if opts.verbose > 0 and opts.quiet > 0: 1882889Sbinkertn@umich.edu usage(2) 1892889Sbinkertn@umich.edu 1902889Sbinkertn@umich.edu # store the verbosity in a single variable. 0 is default, 1912889Sbinkertn@umich.edu # negative numbers represent quiet and positive values indicate verbose 1922889Sbinkertn@umich.edu opts.verbose -= opts.quiet 1932889Sbinkertn@umich.edu 1942889Sbinkertn@umich.edu del opts.quiet 1952889Sbinkertn@umich.edu 1962889Sbinkertn@umich.edu options.update(opts) 1972889Sbinkertn@umich.edu arguments.extend(args) 1982889Sbinkertn@umich.edu return opts,args 1992889Sbinkertn@umich.edu 2002889Sbinkertn@umich.edudef main(): 2014042Sbinkertn@umich.edu import defines 2024042Sbinkertn@umich.edu import info 2033624Sbinkertn@umich.edu import internal 2042889Sbinkertn@umich.edu 2052889Sbinkertn@umich.edu parse_args() 2062889Sbinkertn@umich.edu 2072889Sbinkertn@umich.edu done = False 2082889Sbinkertn@umich.edu if options.copyright: 2092889Sbinkertn@umich.edu done = True 2102889Sbinkertn@umich.edu print info.LICENSE 2112889Sbinkertn@umich.edu print 2122889Sbinkertn@umich.edu 2132889Sbinkertn@umich.edu if options.authors: 2142889Sbinkertn@umich.edu done = True 2152889Sbinkertn@umich.edu print 'Author information:' 2162889Sbinkertn@umich.edu print 2172889Sbinkertn@umich.edu print info.AUTHORS 2182889Sbinkertn@umich.edu print 2192889Sbinkertn@umich.edu 2202889Sbinkertn@umich.edu if options.readme: 2212889Sbinkertn@umich.edu done = True 2222889Sbinkertn@umich.edu print 'Readme:' 2232889Sbinkertn@umich.edu print 2242889Sbinkertn@umich.edu print info.README 2252889Sbinkertn@umich.edu print 2262889Sbinkertn@umich.edu 2272889Sbinkertn@umich.edu if options.release_notes: 2282889Sbinkertn@umich.edu done = True 2292889Sbinkertn@umich.edu print 'Release Notes:' 2302889Sbinkertn@umich.edu print 2312889Sbinkertn@umich.edu print info.RELEASE_NOTES 2322889Sbinkertn@umich.edu print 2332889Sbinkertn@umich.edu 2342889Sbinkertn@umich.edu if done: 2352889Sbinkertn@umich.edu sys.exit(0) 2362889Sbinkertn@umich.edu 2372889Sbinkertn@umich.edu if options.verbose >= 0: 2382889Sbinkertn@umich.edu print "M5 Simulator System" 2392889Sbinkertn@umich.edu print brief_copyright 2402889Sbinkertn@umich.edu print 2413624Sbinkertn@umich.edu print "M5 compiled %s" % internal.main.cvar.compileDate; 2422889Sbinkertn@umich.edu print "M5 started %s" % datetime.now().ctime() 2432889Sbinkertn@umich.edu print "M5 executing on %s" % socket.gethostname() 2442967Sktlim@umich.edu print "command line:", 2452967Sktlim@umich.edu for argv in sys.argv: 2462967Sktlim@umich.edu print argv, 2472967Sktlim@umich.edu print 2482889Sbinkertn@umich.edu 2492889Sbinkertn@umich.edu # check to make sure we can find the listed script 2502889Sbinkertn@umich.edu if not arguments or not os.path.isfile(arguments[0]): 2512922Sktlim@umich.edu if arguments and not os.path.isfile(arguments[0]): 2522922Sktlim@umich.edu print "Script %s not found" % arguments[0] 2532889Sbinkertn@umich.edu usage(2) 2542889Sbinkertn@umich.edu 2552889Sbinkertn@umich.edu # tell C++ about output directory 2563624Sbinkertn@umich.edu internal.main.setOutputDir(options.outdir) 2572889Sbinkertn@umich.edu 2582889Sbinkertn@umich.edu # update the system path with elements from the -p option 2592889Sbinkertn@umich.edu sys.path[0:0] = options.path 2602889Sbinkertn@umich.edu 2612889Sbinkertn@umich.edu import objects 2622889Sbinkertn@umich.edu 2632889Sbinkertn@umich.edu # set stats options 2642889Sbinkertn@umich.edu objects.Statistics.text_file = options.stats_file 2652889Sbinkertn@umich.edu 2662889Sbinkertn@umich.edu # set debugging options 2673645Sbinkertn@umich.edu for when in options.debug_break: 2683645Sbinkertn@umich.edu internal.debug.schedBreakCycle(int(when)) 2692889Sbinkertn@umich.edu 2704042Sbinkertn@umich.edu for flag in options.trace_flags: 2714046Sbinkertn@umich.edu internal.trace.set(flag) 2724042Sbinkertn@umich.edu 2734042Sbinkertn@umich.edu if options.trace_start is not None: 2744042Sbinkertn@umich.edu internal.trace.enabled = False 2754042Sbinkertn@umich.edu def enable_trace(): 2764042Sbinkertn@umich.edu internal.event.enabled = True 2774042Sbinkertn@umich.edu internal.event.create(enable_trace, options.trace_start) 2784042Sbinkertn@umich.edu 2794046Sbinkertn@umich.edu internal.trace.output(options.trace_file) 2804042Sbinkertn@umich.edu 2814042Sbinkertn@umich.edu for ignore in options.trace_ignore: 2824042Sbinkertn@umich.edu internal.trace.ignore(ignore) 2832889Sbinkertn@umich.edu 2842889Sbinkertn@umich.edu # set execution trace options 2852889Sbinkertn@umich.edu objects.ExecutionTrace.speculative = options.speculative 2862889Sbinkertn@umich.edu objects.ExecutionTrace.print_cycle = options.print_cycle 2872889Sbinkertn@umich.edu objects.ExecutionTrace.pc_symbol = options.print_symbol 2882889Sbinkertn@umich.edu objects.ExecutionTrace.print_opclass = options.print_opclass 2892889Sbinkertn@umich.edu objects.ExecutionTrace.print_thread = options.print_thread 2902889Sbinkertn@umich.edu objects.ExecutionTrace.print_effaddr = options.print_effaddr 2912889Sbinkertn@umich.edu objects.ExecutionTrace.print_data = options.print_data 2922889Sbinkertn@umich.edu objects.ExecutionTrace.print_iregs = options.print_iregs 2932889Sbinkertn@umich.edu objects.ExecutionTrace.print_fetchseq = options.print_fetch_seq 2942889Sbinkertn@umich.edu objects.ExecutionTrace.print_cpseq = options.print_cpseq 2952973Sgblack@eecs.umich.edu #objects.ExecutionTrace.print_reg_delta = options.print_reg_delta 2963506Ssaidi@eecs.umich.edu objects.ExecutionTrace.legion_lockstep = options.legion_lock 2972889Sbinkertn@umich.edu 2982889Sbinkertn@umich.edu sys.argv = arguments 2992889Sbinkertn@umich.edu sys.path = [ os.path.dirname(sys.argv[0]) ] + sys.path 3002891Sbinkertn@umich.edu 3013887Sbinkertn@umich.edu scope = { '__file__' : sys.argv[0], 3023887Sbinkertn@umich.edu '__name__' : '__m5_main__' } 3032899Sbinkertn@umich.edu 3042899Sbinkertn@umich.edu # we want readline if we're doing anything interactive 3052899Sbinkertn@umich.edu if options.interactive or options.pdb: 3064042Sbinkertn@umich.edu exec "import readline" in scope 3072899Sbinkertn@umich.edu 3082899Sbinkertn@umich.edu # if pdb was requested, execfile the thing under pdb, otherwise, 3092899Sbinkertn@umich.edu # just do the execfile normally 3102899Sbinkertn@umich.edu if options.pdb: 3112899Sbinkertn@umich.edu from pdb import Pdb 3122899Sbinkertn@umich.edu debugger = Pdb() 3132899Sbinkertn@umich.edu debugger.run('execfile("%s")' % sys.argv[0], scope) 3142899Sbinkertn@umich.edu else: 3152899Sbinkertn@umich.edu execfile(sys.argv[0], scope) 3162889Sbinkertn@umich.edu 3172889Sbinkertn@umich.edu # once the script is done 3182889Sbinkertn@umich.edu if options.interactive: 3192889Sbinkertn@umich.edu interact = code.InteractiveConsole(scope) 3202889Sbinkertn@umich.edu interact.interact("M5 Interactive Console") 3212889Sbinkertn@umich.edu 3222889Sbinkertn@umich.eduif __name__ == '__main__': 3232889Sbinkertn@umich.edu from pprint import pprint 3242889Sbinkertn@umich.edu 3252889Sbinkertn@umich.edu parse_args() 3262889Sbinkertn@umich.edu 3272889Sbinkertn@umich.edu print 'opts:' 3282889Sbinkertn@umich.edu pprint(options, indent=4) 3292889Sbinkertn@umich.edu print 3302889Sbinkertn@umich.edu 3312889Sbinkertn@umich.edu print 'args:' 3322889Sbinkertn@umich.edu pprint(arguments, indent=4) 333