sim_events.cc revision 396
12SN/A/* 29430SAndreas.Sandberg@ARM.com * Copyright (c) 2003 The Regents of The University of Michigan 38707Sandreas.hansson@arm.com * All rights reserved. 48707Sandreas.hansson@arm.com * 58707Sandreas.hansson@arm.com * Redistribution and use in source and binary forms, with or without 68707Sandreas.hansson@arm.com * modification, are permitted provided that the following conditions are 78707Sandreas.hansson@arm.com * met: redistributions of source code must retain the above copyright 88707Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer; 98707Sandreas.hansson@arm.com * redistributions in binary form must reproduce the above copyright 108707Sandreas.hansson@arm.com * notice, this list of conditions and the following disclaimer in the 118707Sandreas.hansson@arm.com * documentation and/or other materials provided with the distribution; 128707Sandreas.hansson@arm.com * neither the name of the copyright holders nor the names of its 138707Sandreas.hansson@arm.com * contributors may be used to endorse or promote products derived from 141762SN/A * this software without specific prior written permission. 157897Shestness@cs.utexas.edu * 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. 272SN/A */ 282SN/A 292SN/A#include <string> 302SN/A 312SN/A#include "sim/param.hh" 322SN/A#include "sim/eventq.hh" 332SN/A#include "base/hostinfo.hh" 342SN/A#include "sim/sim_events.hh" 352SN/A#include "sim/sim_exit.hh" 362SN/A#include "sim/sim_stats.hh" 372SN/A 382SN/Ausing namespace std; 392SN/A 402665Ssaidi@eecs.umich.edu// 412665Ssaidi@eecs.umich.edu// handle termination event 422665Ssaidi@eecs.umich.edu// 437897Shestness@cs.utexas.eduvoid 442SN/ASimExitEvent::process() 452SN/A{ 461717SN/A // This event does not autodelete because exitNow may be called, 471717SN/A // and the function will never be allowed to finish. 482SN/A if (theQueue() == &mainEventQueue) { 492SN/A string _cause = cause; 502SN/A int _code = code; 518745Sgblack@eecs.umich.edu delete this; 524182Sgblack@eecs.umich.edu exitNow(_cause, _code); 535664Sgblack@eecs.umich.edu } else { 54707SN/A new SimExitEvent(cause, code); 556658Snate@binkert.org delete this; 568229Snate@binkert.org } 5756SN/A} 588779Sgblack@eecs.umich.edu 594776Sgblack@eecs.umich.edu 602SN/Aconst char * 618901Sandreas.hansson@arm.comSimExitEvent::description() 622190SN/A{ 632315SN/A return "simulation termination"; 642680Sktlim@umich.edu} 652SN/A 662SN/A// 672356SN/A// constructor: automatically schedules at specified time 682356SN/A// 692356SN/ACountedExitEvent::CountedExitEvent(EventQueue *q, const std::string &_cause, 706144Sksewell@umich.edu Tick _when, int &_downCounter) 712356SN/A : Event(q, Sim_Exit_Pri), 722356SN/A cause(_cause), 736144Sksewell@umich.edu downCounter(_downCounter) 742356SN/A{ 752356SN/A // catch stupid mistakes 766144Sksewell@umich.edu assert(downCounter > 0); 772356SN/A 782356SN/A schedule(_when); 792356SN/A} 806144Sksewell@umich.edu 816144Sksewell@umich.edu 826144Sksewell@umich.edu// 836144Sksewell@umich.edu// handle termination event 846144Sksewell@umich.edu// 855336Shines@cs.fsu.eduvoid 862356SN/ACountedExitEvent::process() 872356SN/A{ 882856Srdreslin@umich.edu if (--downCounter == 0) { 892SN/A new SimExitEvent(cause, 0); 901634SN/A } 919157Sandreas.hansson@arm.com} 923814Ssaidi@eecs.umich.edu 933814Ssaidi@eecs.umich.edu 945712Shsul@eecs.umich.educonst char * 955712Shsul@eecs.umich.eduCountedExitEvent::description() 965715Shsul@eecs.umich.edu{ 975712Shsul@eecs.umich.edu return "counted exit"; 985712Shsul@eecs.umich.edu} 991634SN/A 1008832SAli.Saidi@ARM.com#ifdef CHECK_SWAP_CYCLES 1018832SAli.Saidi@ARM.comnew CheckSwapEvent(&mainEventQueue, CHECK_SWAP_CYCLES); 1028832SAli.Saidi@ARM.com#endif 1038832SAli.Saidi@ARM.com 1048832SAli.Saidi@ARM.comvoid 1058832SAli.Saidi@ARM.comCheckSwapEvent::process() 1069332Sdam.sunwoo@arm.com{ 1079332Sdam.sunwoo@arm.com /* Check the amount of free swap space */ 1089332Sdam.sunwoo@arm.com long swap; 1099332Sdam.sunwoo@arm.com 1109332Sdam.sunwoo@arm.com /* returns free swap in KBytes */ 1119332Sdam.sunwoo@arm.com swap = procInfo("/proc/meminfo", "SwapFree:"); 1129332Sdam.sunwoo@arm.com 1139332Sdam.sunwoo@arm.com if (swap < 1000) 1149332Sdam.sunwoo@arm.com ccprintf(cerr, "\a\a\aWarning! Swap space is low (%d)\n", swap); 1159332Sdam.sunwoo@arm.com 1169332Sdam.sunwoo@arm.com if (swap < 100) { 1179430SAndreas.Sandberg@ARM.com cerr << "\a\aAborting Simulation! Inadequate swap space!\n\n"; 1189430SAndreas.Sandberg@ARM.com new SimExitEvent("Lack of swap space"); 1199430SAndreas.Sandberg@ARM.com } 1208707Sandreas.hansson@arm.com 1218707Sandreas.hansson@arm.com schedule(curTick + interval); 1228707Sandreas.hansson@arm.com} 1238707Sandreas.hansson@arm.com 1248707Sandreas.hansson@arm.comconst char * 1258707Sandreas.hansson@arm.comCheckSwapEvent::description() 1268707Sandreas.hansson@arm.com{ 1278707Sandreas.hansson@arm.com return "check swap"; 1288922Swilliam.wang@arm.com} 1298707Sandreas.hansson@arm.com 1308707Sandreas.hansson@arm.com 1318707Sandreas.hansson@arm.com/////////////////////////////////////////////////// 1328707Sandreas.hansson@arm.com// 1338707Sandreas.hansson@arm.com// Simulation termination parameters 1348707Sandreas.hansson@arm.com// 1358707Sandreas.hansson@arm.com/////////////////////////////////////////////////// 1368707Sandreas.hansson@arm.com 1378707Sandreas.hansson@arm.comclass TermParamContext : public ParamContext 1388707Sandreas.hansson@arm.com{ 1398922Swilliam.wang@arm.com public: 1408707Sandreas.hansson@arm.com TermParamContext(const string &_iniSection) 1418707Sandreas.hansson@arm.com : ParamContext(_iniSection) {} 1428707Sandreas.hansson@arm.com void checkParams(); 1438707Sandreas.hansson@arm.com}; 1448975Sandreas.hansson@arm.com 1458707Sandreas.hansson@arm.comTermParamContext simTerminationParams("max"); 1468707Sandreas.hansson@arm.com 1478707Sandreas.hansson@arm.comParam<Tick> max_cycle(&simTerminationParams, "cycle", 1488948Sandreas.hansson@arm.com "maximum number of cycles to execute"); 1498707Sandreas.hansson@arm.com 1508707Sandreas.hansson@arm.comvoid 1518707Sandreas.hansson@arm.comTermParamContext::checkParams() 1521634SN/A{ 1538850Sandreas.hansson@arm.com // if a max cycle count was specified, put a termination event on 1548850Sandreas.hansson@arm.com // the event queue at that point 1558850Sandreas.hansson@arm.com if (max_cycle.isValid()) 1568850Sandreas.hansson@arm.com new SimExitEvent(max_cycle, "reached maximum cycle count"); 1578850Sandreas.hansson@arm.com} 1588850Sandreas.hansson@arm.com 1598850Sandreas.hansson@arm.com// 1608850Sandreas.hansson@arm.com// Progress event: print out cycle every so often so we know we're 1618850Sandreas.hansson@arm.com// making forward progress. 1628850Sandreas.hansson@arm.com// 1638850Sandreas.hansson@arm.comclass ProgressEvent : public Event 1648850Sandreas.hansson@arm.com{ 1658850Sandreas.hansson@arm.com protected: 1668850Sandreas.hansson@arm.com Tick interval; 1678850Sandreas.hansson@arm.com 1688850Sandreas.hansson@arm.com public: 1698850Sandreas.hansson@arm.com ProgressEvent(EventQueue *q, Tick interval); 1705712Shsul@eecs.umich.edu 1715712Shsul@eecs.umich.edu void process(); // process event 1725712Shsul@eecs.umich.edu virtual const char *description(); 1738832SAli.Saidi@ARM.com}; 1748832SAli.Saidi@ARM.com 1758832SAli.Saidi@ARM.com// 1768832SAli.Saidi@ARM.com// constructor: schedule at specified time 1778832SAli.Saidi@ARM.com// 1788850Sandreas.hansson@arm.comProgressEvent::ProgressEvent(EventQueue *q, Tick _interval) 1798926Sandreas.hansson@arm.com : Event(q), interval(_interval) 1808926Sandreas.hansson@arm.com{ 1818926Sandreas.hansson@arm.com schedule(interval); 1828850Sandreas.hansson@arm.com} 1838850Sandreas.hansson@arm.com 1848850Sandreas.hansson@arm.com// 1858850Sandreas.hansson@arm.com// handle progress event: print message and reschedule 1868922Swilliam.wang@arm.com// 1878850Sandreas.hansson@arm.comvoid 1889294Sandreas.hansson@arm.comProgressEvent::process() 1899294Sandreas.hansson@arm.com{ 1908850Sandreas.hansson@arm.com DPRINTFN("ProgressEvent\n"); 1919332Sdam.sunwoo@arm.com // reschedule for next interval 1929332Sdam.sunwoo@arm.com schedule(curTick + interval); 1939332Sdam.sunwoo@arm.com} 1949332Sdam.sunwoo@arm.com 1959332Sdam.sunwoo@arm.com 1969332Sdam.sunwoo@arm.comconst char * 1979332Sdam.sunwoo@arm.comProgressEvent::description() 1989332Sdam.sunwoo@arm.com{ 1997914SBrad.Beckmann@amd.com return "progress message"; 2007914SBrad.Beckmann@amd.com} 2013814Ssaidi@eecs.umich.edu 2023814Ssaidi@eecs.umich.edu///////// 2031634SN/A// 2045664Sgblack@eecs.umich.edu// Periodic progress message support: print out a message every n 2055664Sgblack@eecs.umich.edu// cycles so we know we're making forward progress. 2062SN/A// 2075704Snate@binkert.org///////// 2082SN/A 2092SN/A// Parameter space for execution address tracing options. Derive 2105645Sgblack@eecs.umich.edu// from ParamContext so we can override checkParams() function. 2115645Sgblack@eecs.umich.educlass ProgressParamContext : public ParamContext 2125645Sgblack@eecs.umich.edu{ 2135647Sgblack@eecs.umich.edu public: 2145645Sgblack@eecs.umich.edu ProgressParamContext(const string &_iniSection) 2155645Sgblack@eecs.umich.edu : ParamContext(_iniSection) {} 2165807Snate@binkert.org void checkParams(); 2175807Snate@binkert.org}; 2185807Snate@binkert.org 2195807Snate@binkert.orgProgressParamContext progessMessageParams("progress"); 2205807Snate@binkert.org 2215807Snate@binkert.orgParam<Tick> progress_interval(&progessMessageParams, "cycle", 2228779Sgblack@eecs.umich.edu "cycle interval for progress messages"); 2238779Sgblack@eecs.umich.edu 2245807Snate@binkert.org/* check execute options */ 2255807Snate@binkert.orgvoid 2265807Snate@binkert.orgProgressParamContext::checkParams() 2275807Snate@binkert.org{ 2285807Snate@binkert.org if (progress_interval.isValid()) 2295807Snate@binkert.org new ProgressEvent(&mainEventQueue, progress_interval); 2305807Snate@binkert.org} 2315807Snate@binkert.org