sim_events.cc revision 5336
12SN/A/* 21762SN/A * Copyright (c) 2002-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: Nathan Binkert 292SN/A */ 302SN/A 312SN/A#include <string> 322SN/A 33601SN/A#include "base/callback.hh" 34601SN/A#include "base/hostinfo.hh" 35601SN/A#include "sim/eventq.hh" 3656SN/A#include "sim/sim_events.hh" 3756SN/A#include "sim/sim_exit.hh" 381127SN/A#include "sim/startup.hh" 39695SN/A#include "sim/stats.hh" 402SN/A 412SN/Ausing namespace std; 422SN/A 432SN/A// 442SN/A// handle termination event 452SN/A// 462SN/Avoid 472667Sstever@eecs.umich.eduSimLoopExitEvent::process() 482SN/A{ 492667Sstever@eecs.umich.edu // if this got scheduled on a different queue (e.g. the committed 502667Sstever@eecs.umich.edu // instruction queue) then make a corresponding event on the main 512667Sstever@eecs.umich.edu // queue. 522667Sstever@eecs.umich.edu if (theQueue() != &mainEventQueue) { 532667Sstever@eecs.umich.edu exitSimLoop(cause, code); 542SN/A delete this; 552SN/A } 562667Sstever@eecs.umich.edu 572667Sstever@eecs.umich.edu // otherwise do nothing... the IsExitEvent flag takes care of 582667Sstever@eecs.umich.edu // exiting the simulation loop and returning this object to Python 593144Shsul@eecs.umich.edu 603144Shsul@eecs.umich.edu // but if you are doing this on intervals, don't forget to make another 613144Shsul@eecs.umich.edu if (repeat) { 623144Shsul@eecs.umich.edu schedule(curTick + repeat); 633144Shsul@eecs.umich.edu } 642SN/A} 652SN/A 662SN/A 672SN/Aconst char * 685336Shines@cs.fsu.eduSimLoopExitEvent::description() const 692SN/A{ 702667Sstever@eecs.umich.edu return "simulation loop exit"; 712667Sstever@eecs.umich.edu} 722667Sstever@eecs.umich.edu 733144Shsul@eecs.umich.eduSimLoopExitEvent * 743144Shsul@eecs.umich.eduschedExitSimLoop(const std::string &message, Tick when, Tick repeat, 753144Shsul@eecs.umich.edu EventQueue *q, int exit_code) 762667Sstever@eecs.umich.edu{ 773144Shsul@eecs.umich.edu if (q == NULL) 783144Shsul@eecs.umich.edu q = &mainEventQueue; 793144Shsul@eecs.umich.edu 803144Shsul@eecs.umich.edu return new SimLoopExitEvent(q, when, repeat, message, exit_code); 812667Sstever@eecs.umich.edu} 822667Sstever@eecs.umich.edu 832667Sstever@eecs.umich.eduvoid 842667Sstever@eecs.umich.eduexitSimLoop(const std::string &message, int exit_code) 852667Sstever@eecs.umich.edu{ 863144Shsul@eecs.umich.edu schedExitSimLoop(message, curTick, 0, NULL, exit_code); 872SN/A} 882SN/A 892797Sktlim@umich.eduvoid 902839Sktlim@umich.eduCountedDrainEvent::process() 912797Sktlim@umich.edu{ 922797Sktlim@umich.edu if (--count == 0) { 932839Sktlim@umich.edu exitSimLoop("Finished drain"); 942797Sktlim@umich.edu } 952797Sktlim@umich.edu} 962797Sktlim@umich.edu 972SN/A// 982SN/A// constructor: automatically schedules at specified time 992SN/A// 1002SN/ACountedExitEvent::CountedExitEvent(EventQueue *q, const std::string &_cause, 1012SN/A Tick _when, int &_downCounter) 102396SN/A : Event(q, Sim_Exit_Pri), 1032SN/A cause(_cause), 1042SN/A downCounter(_downCounter) 1052SN/A{ 1062SN/A // catch stupid mistakes 1072SN/A assert(downCounter > 0); 1082SN/A 109396SN/A schedule(_when); 1102SN/A} 1112SN/A 1122SN/A 1132SN/A// 1142SN/A// handle termination event 1152SN/A// 1162SN/Avoid 1172SN/ACountedExitEvent::process() 1182SN/A{ 1192SN/A if (--downCounter == 0) { 1202667Sstever@eecs.umich.edu exitSimLoop(cause, 0); 1212SN/A } 1222SN/A} 1232SN/A 1242SN/A 1252SN/Aconst char * 1265336Shines@cs.fsu.eduCountedExitEvent::description() const 1272SN/A{ 1282SN/A return "counted exit"; 1292SN/A} 1302SN/A 1312SN/A#ifdef CHECK_SWAP_CYCLES 1322SN/Anew CheckSwapEvent(&mainEventQueue, CHECK_SWAP_CYCLES); 1332SN/A#endif 1342SN/A 1352SN/Avoid 1362SN/ACheckSwapEvent::process() 1372SN/A{ 1382SN/A /* Check the amount of free swap space */ 1392SN/A long swap; 1402SN/A 1412SN/A /* returns free swap in KBytes */ 14252SN/A swap = procInfo("/proc/meminfo", "SwapFree:"); 1432SN/A 1442SN/A if (swap < 1000) 1452SN/A ccprintf(cerr, "\a\a\aWarning! Swap space is low (%d)\n", swap); 1462SN/A 1472SN/A if (swap < 100) { 1482SN/A cerr << "\a\aAborting Simulation! Inadequate swap space!\n\n"; 1492667Sstever@eecs.umich.edu exitSimLoop("Lack of swap space"); 1502SN/A } 1512SN/A 1522SN/A schedule(curTick + interval); 1532SN/A} 1542SN/A 1552SN/Aconst char * 1565336Shines@cs.fsu.eduCheckSwapEvent::description() const 1572SN/A{ 1582SN/A return "check swap"; 1592SN/A} 160