main.cc revision 2729
12SN/A/* 21762SN/A * Copyright (c) 2000-2005 The Regents of The University of Michigan 32SN/A * All rights reserved. 42SN/A * 52SN/A * Redistribution and use in source and binary forms, with or without 62SN/A * modification, are permitted provided that the following conditions are 72SN/A * met: redistributions of source code must retain the above copyright 82SN/A * notice, this list of conditions and the following disclaimer; 92SN/A * redistributions in binary form must reproduce the above copyright 102SN/A * notice, this list of conditions and the following disclaimer in the 112SN/A * documentation and/or other materials provided with the distribution; 122SN/A * neither the name of the copyright holders nor the names of its 132SN/A * contributors may be used to endorse or promote products derived from 142SN/A * this software without specific prior written permission. 152SN/A * 162SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272665Ssaidi@eecs.umich.edu * 282665Ssaidi@eecs.umich.edu * Authors: Steve Raasch 292665Ssaidi@eecs.umich.edu * Nathan Binkert 302665Ssaidi@eecs.umich.edu * Steve Reinhardt 312SN/A */ 322SN/A 332SN/A/// 342SN/A/// @file sim/main.cc 352SN/A/// 362655Sstever@eecs.umich.edu#include <Python.h> // must be before system headers... see Python docs 372655Sstever@eecs.umich.edu 382SN/A#include <sys/types.h> 392SN/A#include <sys/stat.h> 401399SN/A#include <errno.h> 411396SN/A#include <libgen.h> 422SN/A#include <stdlib.h> 432SN/A#include <signal.h> 442729Ssaidi@eecs.umich.edu#include <getopt.h> 452SN/A 461310SN/A#include <list> 472SN/A#include <string> 482SN/A#include <vector> 492SN/A 502667Sstever@eecs.umich.edu#include "base/callback.hh" 5156SN/A#include "base/inifile.hh" 52146SN/A#include "base/misc.hh" 531388SN/A#include "base/output.hh" 5456SN/A#include "base/pollevent.hh" 5556SN/A#include "base/statistics.hh" 561311SN/A#include "base/str.hh" 57400SN/A#include "base/time.hh" 581717SN/A#include "cpu/base.hh" 591717SN/A#include "cpu/smt.hh" 60146SN/A#include "sim/async.hh" 61146SN/A#include "sim/builder.hh" 62146SN/A#include "sim/configfile.hh" 63146SN/A#include "sim/host.hh" 6456SN/A#include "sim/sim_events.hh" 6556SN/A#include "sim/sim_exit.hh" 6656SN/A#include "sim/sim_object.hh" 67695SN/A#include "sim/stat_control.hh" 68695SN/A#include "sim/stats.hh" 691696SN/A#include "sim/root.hh" 702SN/A 712SN/Ausing namespace std; 722SN/A 732SN/A// See async.h. 742SN/Avolatile bool async_event = false; 752SN/Avolatile bool async_dump = false; 76329SN/Avolatile bool async_dumpreset = false; 772SN/Avolatile bool async_exit = false; 782SN/Avolatile bool async_io = false; 792SN/Avolatile bool async_alarm = false; 802SN/A 812SN/A/// Stats signal handler. 822SN/Avoid 832SN/AdumpStatsHandler(int sigtype) 842SN/A{ 852SN/A async_event = true; 862SN/A async_dump = true; 872SN/A} 882SN/A 89329SN/Avoid 90329SN/AdumprstStatsHandler(int sigtype) 91329SN/A{ 92329SN/A async_event = true; 93329SN/A async_dumpreset = true; 94329SN/A} 95329SN/A 962SN/A/// Exit signal handler. 972SN/Avoid 982SN/AexitNowHandler(int sigtype) 992SN/A{ 1002SN/A async_event = true; 1012SN/A async_exit = true; 1022SN/A} 1032SN/A 104764SN/A/// Abort signal handler. 105764SN/Avoid 106764SN/AabortHandler(int sigtype) 107764SN/A{ 108764SN/A cerr << "Program aborted at cycle " << curTick << endl; 109764SN/A 110764SN/A#if TRACING_ON 111764SN/A // dump trace buffer, if there is one 112764SN/A Trace::theLog.dump(cerr); 113764SN/A#endif 114764SN/A} 115764SN/A 1162729Ssaidi@eecs.umich.edu/// Simulator executable name 1172729Ssaidi@eecs.umich.educhar *myProgName = ""; 1182729Ssaidi@eecs.umich.edu 1192729Ssaidi@eecs.umich.edu/// Show brief help message. 1202729Ssaidi@eecs.umich.eduvoid 1212729Ssaidi@eecs.umich.edushowBriefHelp(ostream &out) 1222729Ssaidi@eecs.umich.edu{ 1232729Ssaidi@eecs.umich.edu char *prog = basename(myProgName); 1242729Ssaidi@eecs.umich.edu 1252729Ssaidi@eecs.umich.edu ccprintf(out, "Usage:\n"); 1262729Ssaidi@eecs.umich.edu ccprintf(out, 1272729Ssaidi@eecs.umich.edu"%s [-p <path>] [-i ] [-h] <config file>\n" 1282729Ssaidi@eecs.umich.edu"\n" 1292729Ssaidi@eecs.umich.edu" -p, --path <path> prepends <path> to PYTHONPATH instead of using\n" 1302729Ssaidi@eecs.umich.edu" built-in zip archive. Useful when developing/debugging\n" 1312729Ssaidi@eecs.umich.edu" changes to built-in Python libraries, as the new Python\n" 1322729Ssaidi@eecs.umich.edu" can be tested without building a new m5 binary.\n\n" 1332729Ssaidi@eecs.umich.edu" -i, --interactive forces entry into interactive mode after the supplied\n" 1342729Ssaidi@eecs.umich.edu" script is executed (just like the -i option to the\n" 1352729Ssaidi@eecs.umich.edu" Python interpreter).\n\n" 1362729Ssaidi@eecs.umich.edu" -h Prints this help\n\n" 1372729Ssaidi@eecs.umich.edu" <configfile> config file name (ends in .py)\n\n", 1382729Ssaidi@eecs.umich.edu prog); 1392729Ssaidi@eecs.umich.edu 1402729Ssaidi@eecs.umich.edu} 1412SN/A 1422667Sstever@eecs.umich.educonst char *briefCopyright = 1432667Sstever@eecs.umich.edu"Copyright (c) 2001-2006\n" 1442667Sstever@eecs.umich.edu"The Regents of The University of Michigan\n" 1452667Sstever@eecs.umich.edu"All Rights Reserved\n"; 1462667Sstever@eecs.umich.edu 1472667Sstever@eecs.umich.edu/// Print welcome message. 1481388SN/Avoid 1492667Sstever@eecs.umich.edusayHello(ostream &out) 1502SN/A{ 1512667Sstever@eecs.umich.edu extern const char *compileDate; // from date.cc 1522SN/A 1532667Sstever@eecs.umich.edu ccprintf(out, "M5 Simulator System\n"); 1542667Sstever@eecs.umich.edu // display copyright 1552667Sstever@eecs.umich.edu ccprintf(out, "%s\n", briefCopyright); 1562667Sstever@eecs.umich.edu ccprintf(out, "M5 compiled %d\n", compileDate); 1572667Sstever@eecs.umich.edu ccprintf(out, "M5 started %s\n", Time::start); 1582SN/A 1592667Sstever@eecs.umich.edu char *host = getenv("HOSTNAME"); 1602667Sstever@eecs.umich.edu if (!host) 1612667Sstever@eecs.umich.edu host = getenv("HOST"); 1622SN/A 1632667Sstever@eecs.umich.edu if (host) 1642667Sstever@eecs.umich.edu ccprintf(out, "M5 executing on %s\n", host); 1652667Sstever@eecs.umich.edu} 1662SN/A 1672SN/A 1682667Sstever@eecs.umich.eduextern "C" { void init_main(); } 1692SN/A 1702SN/Aint 1712SN/Amain(int argc, char **argv) 1722SN/A{ 1732729Ssaidi@eecs.umich.edu // Saze off program name 1742729Ssaidi@eecs.umich.edu myProgName = argv[0]; 1752729Ssaidi@eecs.umich.edu 1762667Sstever@eecs.umich.edu sayHello(cerr); 1772SN/A 1782SN/A signal(SIGFPE, SIG_IGN); // may occur on misspeculated paths 1792SN/A signal(SIGTRAP, SIG_IGN); 180329SN/A signal(SIGUSR1, dumpStatsHandler); // dump intermediate stats 181329SN/A signal(SIGUSR2, dumprstStatsHandler); // dump and reset stats 182329SN/A signal(SIGINT, exitNowHandler); // dump final stats and exit 183764SN/A signal(SIGABRT, abortHandler); 1842SN/A 1852655Sstever@eecs.umich.edu Py_SetProgramName(argv[0]); 1862667Sstever@eecs.umich.edu 1872667Sstever@eecs.umich.edu // default path to m5 python code is the currently executing 1882667Sstever@eecs.umich.edu // file... Python ZipImporter will find embedded zip archive 1892667Sstever@eecs.umich.edu char *pythonpath = argv[0]; 1902667Sstever@eecs.umich.edu 1912667Sstever@eecs.umich.edu bool interactive = false; 1922729Ssaidi@eecs.umich.edu bool show_help = false; 1932667Sstever@eecs.umich.edu bool getopt_done = false; 1942729Ssaidi@eecs.umich.edu int opt_index = 0; 1952729Ssaidi@eecs.umich.edu 1962729Ssaidi@eecs.umich.edu static struct option long_options[] = { 1972729Ssaidi@eecs.umich.edu {"python", 1, 0, 'p'}, 1982729Ssaidi@eecs.umich.edu {"interactive", 0, 0, 'i'}, 1992729Ssaidi@eecs.umich.edu {"help", 0, 0, 'h'}, 2002729Ssaidi@eecs.umich.edu {0,0,0,0} 2012729Ssaidi@eecs.umich.edu }; 2022729Ssaidi@eecs.umich.edu 2032667Sstever@eecs.umich.edu do { 2042729Ssaidi@eecs.umich.edu switch (getopt_long(argc, argv, "+p:ih", long_options, &opt_index)) { 2052667Sstever@eecs.umich.edu // -p <path> prepends <path> to PYTHONPATH instead of 2062667Sstever@eecs.umich.edu // using built-in zip archive. Useful when 2072667Sstever@eecs.umich.edu // developing/debugging changes to built-in Python 2082667Sstever@eecs.umich.edu // libraries, as the new Python can be tested without 2092667Sstever@eecs.umich.edu // building a new m5 binary. 2102667Sstever@eecs.umich.edu case 'p': 2112667Sstever@eecs.umich.edu pythonpath = optarg; 2122667Sstever@eecs.umich.edu break; 2132667Sstever@eecs.umich.edu 2142667Sstever@eecs.umich.edu // -i forces entry into interactive mode after the 2152667Sstever@eecs.umich.edu // supplied script is executed (just like the -i option to 2162667Sstever@eecs.umich.edu // the Python interpreter). 2172667Sstever@eecs.umich.edu case 'i': 2182667Sstever@eecs.umich.edu interactive = true; 2192667Sstever@eecs.umich.edu break; 2202667Sstever@eecs.umich.edu 2212729Ssaidi@eecs.umich.edu case 'h': 2222729Ssaidi@eecs.umich.edu show_help = true; 2232729Ssaidi@eecs.umich.edu break; 2242667Sstever@eecs.umich.edu case -1: 2252667Sstever@eecs.umich.edu getopt_done = true; 2262667Sstever@eecs.umich.edu break; 2272667Sstever@eecs.umich.edu 2282667Sstever@eecs.umich.edu default: 2292667Sstever@eecs.umich.edu fatal("Unrecognized option %c\n", optopt); 2302667Sstever@eecs.umich.edu } 2312667Sstever@eecs.umich.edu } while (!getopt_done); 2322667Sstever@eecs.umich.edu 2332729Ssaidi@eecs.umich.edu if (show_help) { 2342729Ssaidi@eecs.umich.edu showBriefHelp(cerr); 2352729Ssaidi@eecs.umich.edu exit(1); 2362729Ssaidi@eecs.umich.edu } 2372729Ssaidi@eecs.umich.edu 2382667Sstever@eecs.umich.edu // Fix up argc & argv to hide arguments we just processed. 2392667Sstever@eecs.umich.edu // getopt() sets optind to the index of the first non-processed 2402667Sstever@eecs.umich.edu // argv element. 2412667Sstever@eecs.umich.edu argc -= optind; 2422667Sstever@eecs.umich.edu argv += optind; 2432667Sstever@eecs.umich.edu 2442667Sstever@eecs.umich.edu // Set up PYTHONPATH to make sure the m5 module is found 2452667Sstever@eecs.umich.edu string newpath(pythonpath); 2462667Sstever@eecs.umich.edu 2472667Sstever@eecs.umich.edu char *oldpath = getenv("PYTHONPATH"); 2482667Sstever@eecs.umich.edu if (oldpath != NULL) { 2492667Sstever@eecs.umich.edu newpath += ":"; 2502667Sstever@eecs.umich.edu newpath += oldpath; 2512667Sstever@eecs.umich.edu } 2522667Sstever@eecs.umich.edu 2532667Sstever@eecs.umich.edu if (setenv("PYTHONPATH", newpath.c_str(), true) == -1) 2542667Sstever@eecs.umich.edu fatal("setenv: %s\n", strerror(errno)); 2552667Sstever@eecs.umich.edu 2562667Sstever@eecs.umich.edu // initialize embedded Python interpreter 2572655Sstever@eecs.umich.edu Py_Initialize(); 2582655Sstever@eecs.umich.edu PySys_SetArgv(argc, argv); 2591311SN/A 2602667Sstever@eecs.umich.edu // initialize SWIG 'main' module 2612667Sstever@eecs.umich.edu init_main(); 2621703SN/A 2632667Sstever@eecs.umich.edu if (argc > 0) { 2642667Sstever@eecs.umich.edu // extra arg(s): first is script file, remaining ones are args 2652667Sstever@eecs.umich.edu // to script file 2662667Sstever@eecs.umich.edu char *filename = argv[0]; 2672667Sstever@eecs.umich.edu FILE *fp = fopen(filename, "r"); 2682667Sstever@eecs.umich.edu if (!fp) { 2692667Sstever@eecs.umich.edu fatal("cannot open file '%s'\n", filename); 2702667Sstever@eecs.umich.edu } 2711703SN/A 2722667Sstever@eecs.umich.edu PyRun_AnyFile(fp, filename); 2732667Sstever@eecs.umich.edu } else { 2742667Sstever@eecs.umich.edu // no script file argument... force interactive prompt 2752667Sstever@eecs.umich.edu interactive = true; 2762667Sstever@eecs.umich.edu } 2772SN/A 2782667Sstever@eecs.umich.edu if (interactive) { 2792667Sstever@eecs.umich.edu // The following code to import readline was copied from Python 2802667Sstever@eecs.umich.edu // 2.4.3's Modules/main.c. 2812667Sstever@eecs.umich.edu // Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006 2822667Sstever@eecs.umich.edu // Python Software Foundation; All Rights Reserved 2832667Sstever@eecs.umich.edu // We should only enable this if we're actually using an 2842667Sstever@eecs.umich.edu // interactive prompt. 2852667Sstever@eecs.umich.edu PyObject *v; 2862667Sstever@eecs.umich.edu v = PyImport_ImportModule("readline"); 2872667Sstever@eecs.umich.edu if (v == NULL) 2882667Sstever@eecs.umich.edu PyErr_Clear(); 2892667Sstever@eecs.umich.edu else 2902667Sstever@eecs.umich.edu Py_DECREF(v); 2912667Sstever@eecs.umich.edu 2922667Sstever@eecs.umich.edu PyRun_InteractiveLoop(stdin, "stdin"); 2932667Sstever@eecs.umich.edu } 2942667Sstever@eecs.umich.edu 2952667Sstever@eecs.umich.edu // clean up Python intepreter. 2962655Sstever@eecs.umich.edu Py_Finalize(); 2972667Sstever@eecs.umich.edu} 2981388SN/A 2992667Sstever@eecs.umich.edu 3002667Sstever@eecs.umich.edu/// Initialize C++ configuration. Exported to Python via SWIG; invoked 3012667Sstever@eecs.umich.edu/// from m5.instantiate(). 3022667Sstever@eecs.umich.eduvoid 3032667Sstever@eecs.umich.eduinitialize() 3042667Sstever@eecs.umich.edu{ 3052655Sstever@eecs.umich.edu configStream = simout.find("config.out"); 3061388SN/A 3072SN/A // The configuration database is now complete; start processing it. 3081388SN/A IniFile inifile; 3092655Sstever@eecs.umich.edu inifile.load("config.ini"); 3102SN/A 3111388SN/A // Initialize statistics database 3121388SN/A Stats::InitSimStats(); 3132SN/A 3141310SN/A // Now process the configuration hierarchy and create the SimObjects. 3151388SN/A ConfigHierarchy configHierarchy(inifile); 3161310SN/A configHierarchy.build(); 3171310SN/A configHierarchy.createSimObjects(); 3181310SN/A 3191388SN/A // Parse and check all non-config-hierarchy parameters. 3201388SN/A ParamContext::parseAllContexts(inifile); 3211388SN/A ParamContext::checkAllContexts(); 3221388SN/A 3232667Sstever@eecs.umich.edu // Echo all parameter settings to stats file as well. 3241104SN/A ParamContext::showAllContexts(*configStream); 3252SN/A 3262499SN/A // Any objects that can't connect themselves until after construction should 3272499SN/A // do so now 3282499SN/A SimObject::connectAll(); 3292499SN/A 3301127SN/A // Do a second pass to finish initializing the sim objects 3311127SN/A SimObject::initAll(); 3321127SN/A 3332SN/A // Restore checkpointed state, if any. 3342SN/A configHierarchy.unserializeSimObjects(); 3352SN/A 3362SN/A // Done processing the configuration database. 3372SN/A // Check for unreferenced entries. 3381388SN/A if (inifile.printUnreferenced()) 3391388SN/A panic("unreferenced sections/entries in the intermediate ini file"); 3402SN/A 3412SN/A SimObject::regAllStats(); 3422SN/A 3432SN/A // uncomment the following to get PC-based execution-time profile 3442SN/A#ifdef DO_PROFILE 3452SN/A init_profile((char *)&_init, (char *)&_fini); 3462SN/A#endif 3472SN/A 3482SN/A // Check to make sure that the stats package is properly initialized 349729SN/A Stats::check(); 3502SN/A 351395SN/A // Reset to put the stats in a consistent state. 352729SN/A Stats::reset(); 353395SN/A 3541127SN/A SimStartup(); 3552667Sstever@eecs.umich.edu} 3562667Sstever@eecs.umich.edu 3572667Sstever@eecs.umich.edu 3582667Sstever@eecs.umich.edu/** Simulate for num_cycles additional cycles. If num_cycles is -1 3592667Sstever@eecs.umich.edu * (the default), do not limit simulation; some other event must 3602667Sstever@eecs.umich.edu * terminate the loop. Exported to Python via SWIG. 3612667Sstever@eecs.umich.edu * @return The SimLoopExitEvent that caused the loop to exit. 3622667Sstever@eecs.umich.edu */ 3632667Sstever@eecs.umich.eduSimLoopExitEvent * 3642667Sstever@eecs.umich.edusimulate(Tick num_cycles = -1) 3652667Sstever@eecs.umich.edu{ 3662667Sstever@eecs.umich.edu warn("Entering event queue @ %d. Starting simulation...\n", curTick); 3672667Sstever@eecs.umich.edu 3682667Sstever@eecs.umich.edu // Fix up num_cycles. Special default value -1 means simulate 3692667Sstever@eecs.umich.edu // "forever"... schedule event at MaxTick just to be safe. 3702667Sstever@eecs.umich.edu // Otherwise it's a delta for additional cycles to simulate past 3712667Sstever@eecs.umich.edu // curTick, and thus must be non-negative. 3722667Sstever@eecs.umich.edu if (num_cycles == -1) 3732667Sstever@eecs.umich.edu num_cycles = MaxTick; 3742667Sstever@eecs.umich.edu else if (num_cycles < 0) 3752667Sstever@eecs.umich.edu fatal("simulate: num_cycles must be >= 0 (was %d)\n", num_cycles); 3762667Sstever@eecs.umich.edu else 3772667Sstever@eecs.umich.edu num_cycles = curTick + num_cycles; 3782667Sstever@eecs.umich.edu 3792667Sstever@eecs.umich.edu Event *limit_event = new SimLoopExitEvent(num_cycles, 3802667Sstever@eecs.umich.edu "simulate() limit reached"); 3812667Sstever@eecs.umich.edu 3822667Sstever@eecs.umich.edu while (1) { 3832667Sstever@eecs.umich.edu // there should always be at least one event (the SimLoopExitEvent 3842667Sstever@eecs.umich.edu // we just scheduled) in the queue 3852667Sstever@eecs.umich.edu assert(!mainEventQueue.empty()); 3862SN/A assert(curTick <= mainEventQueue.nextTick() && 3872SN/A "event scheduled in the past"); 3882SN/A 3892SN/A // forward current cycle to the time of the first event on the 3902SN/A // queue 3912SN/A curTick = mainEventQueue.nextTick(); 3922667Sstever@eecs.umich.edu Event *exit_event = mainEventQueue.serviceOne(); 3932667Sstever@eecs.umich.edu if (exit_event != NULL) { 3942667Sstever@eecs.umich.edu // hit some kind of exit event; return to Python 3952667Sstever@eecs.umich.edu // event must be subclass of SimLoopExitEvent... 3962667Sstever@eecs.umich.edu SimLoopExitEvent *se_event = dynamic_cast<SimLoopExitEvent *>(exit_event); 3972667Sstever@eecs.umich.edu if (se_event == NULL) 3982667Sstever@eecs.umich.edu panic("Bogus exit event class!"); 3992667Sstever@eecs.umich.edu 4002667Sstever@eecs.umich.edu // if we didn't hit limit_event, delete it 4012667Sstever@eecs.umich.edu if (se_event != limit_event) { 4022667Sstever@eecs.umich.edu assert(limit_event->scheduled()); 4032667Sstever@eecs.umich.edu limit_event->deschedule(); 4042667Sstever@eecs.umich.edu delete limit_event; 4052667Sstever@eecs.umich.edu } 4062667Sstever@eecs.umich.edu 4072667Sstever@eecs.umich.edu return se_event; 4082667Sstever@eecs.umich.edu } 4092SN/A 4102SN/A if (async_event) { 4112SN/A async_event = false; 4122SN/A if (async_dump) { 4132SN/A async_dump = false; 414294SN/A 415729SN/A using namespace Stats; 416294SN/A SetupEvent(Dump, curTick); 4172SN/A } 4182SN/A 419329SN/A if (async_dumpreset) { 420329SN/A async_dumpreset = false; 421329SN/A 422729SN/A using namespace Stats; 423329SN/A SetupEvent(Dump | Reset, curTick); 424329SN/A } 425329SN/A 4262SN/A if (async_exit) { 4272SN/A async_exit = false; 4282667Sstever@eecs.umich.edu exitSimLoop("user interrupt received"); 4292SN/A } 4302SN/A 4312SN/A if (async_io || async_alarm) { 4322SN/A async_io = false; 4332SN/A async_alarm = false; 4342SN/A pollQueue.service(); 4352SN/A } 4362SN/A } 4372SN/A } 4382SN/A 4392667Sstever@eecs.umich.edu // not reached... only exit is return on SimLoopExitEvent 4402667Sstever@eecs.umich.edu} 4412SN/A 4422667Sstever@eecs.umich.edu/** 4432667Sstever@eecs.umich.edu * Queue of C++ callbacks to invoke on simulator exit. 4442667Sstever@eecs.umich.edu */ 4452667Sstever@eecs.umich.eduCallbackQueue exitCallbacks; 4462667Sstever@eecs.umich.edu 4472667Sstever@eecs.umich.edu/** 4482667Sstever@eecs.umich.edu * Register an exit callback. 4492667Sstever@eecs.umich.edu */ 4502667Sstever@eecs.umich.eduvoid 4512667Sstever@eecs.umich.eduregisterExitCallback(Callback *callback) 4522667Sstever@eecs.umich.edu{ 4532667Sstever@eecs.umich.edu exitCallbacks.add(callback); 4542SN/A} 4552667Sstever@eecs.umich.edu 4562667Sstever@eecs.umich.edu/** 4572667Sstever@eecs.umich.edu * Do C++ simulator exit processing. Exported to SWIG to be invoked 4582667Sstever@eecs.umich.edu * when simulator terminates via Python's atexit mechanism. 4592667Sstever@eecs.umich.edu */ 4602667Sstever@eecs.umich.eduvoid 4612667Sstever@eecs.umich.edudoExitCleanup() 4622667Sstever@eecs.umich.edu{ 4632667Sstever@eecs.umich.edu exitCallbacks.process(); 4642667Sstever@eecs.umich.edu exitCallbacks.clear(); 4652667Sstever@eecs.umich.edu 4662667Sstever@eecs.umich.edu cout.flush(); 4672667Sstever@eecs.umich.edu 4682667Sstever@eecs.umich.edu ParamContext::cleanupAllContexts(); 4692667Sstever@eecs.umich.edu 4702667Sstever@eecs.umich.edu // print simulation stats 4712667Sstever@eecs.umich.edu Stats::DumpNow(); 4722667Sstever@eecs.umich.edu} 473