sim_events.cc revision 2667
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"
3685SN/A#include "sim/param.hh"
3756SN/A#include "sim/sim_events.hh"
3856SN/A#include "sim/sim_exit.hh"
391127SN/A#include "sim/startup.hh"
40695SN/A#include "sim/stats.hh"
412SN/A
422SN/Ausing namespace std;
432SN/A
442SN/A//
452SN/A// handle termination event
462SN/A//
472SN/Avoid
482667Sstever@eecs.umich.eduSimLoopExitEvent::process()
492SN/A{
502667Sstever@eecs.umich.edu    // if this got scheduled on a different queue (e.g. the committed
512667Sstever@eecs.umich.edu    // instruction queue) then make a corresponding event on the main
522667Sstever@eecs.umich.edu    // queue.
532667Sstever@eecs.umich.edu    if (theQueue() != &mainEventQueue) {
542667Sstever@eecs.umich.edu        exitSimLoop(cause, code);
552SN/A        delete this;
562SN/A    }
572667Sstever@eecs.umich.edu
582667Sstever@eecs.umich.edu    // otherwise do nothing... the IsExitEvent flag takes care of
592667Sstever@eecs.umich.edu    // exiting the simulation loop and returning this object to Python
602SN/A}
612SN/A
622SN/A
632SN/Aconst char *
642667Sstever@eecs.umich.eduSimLoopExitEvent::description()
652SN/A{
662667Sstever@eecs.umich.edu    return "simulation loop exit";
672667Sstever@eecs.umich.edu}
682667Sstever@eecs.umich.edu
692667Sstever@eecs.umich.eduvoid
702667Sstever@eecs.umich.eduexitSimLoop(Tick when, const std::string &message, int exit_code)
712667Sstever@eecs.umich.edu{
722667Sstever@eecs.umich.edu    new SimLoopExitEvent(when, message, exit_code);
732667Sstever@eecs.umich.edu}
742667Sstever@eecs.umich.edu
752667Sstever@eecs.umich.eduvoid
762667Sstever@eecs.umich.eduexitSimLoop(const std::string &message, int exit_code)
772667Sstever@eecs.umich.edu{
782667Sstever@eecs.umich.edu    exitSimLoop(curTick, message, exit_code);
792SN/A}
802SN/A
812SN/A//
822SN/A// constructor: automatically schedules at specified time
832SN/A//
842SN/ACountedExitEvent::CountedExitEvent(EventQueue *q, const std::string &_cause,
852SN/A                                   Tick _when, int &_downCounter)
86396SN/A    : Event(q, Sim_Exit_Pri),
872SN/A      cause(_cause),
882SN/A      downCounter(_downCounter)
892SN/A{
902SN/A    // catch stupid mistakes
912SN/A    assert(downCounter > 0);
922SN/A
93396SN/A    schedule(_when);
942SN/A}
952SN/A
962SN/A
972SN/A//
982SN/A// handle termination event
992SN/A//
1002SN/Avoid
1012SN/ACountedExitEvent::process()
1022SN/A{
1032SN/A    if (--downCounter == 0) {
1042667Sstever@eecs.umich.edu        exitSimLoop(cause, 0);
1052SN/A    }
1062SN/A}
1072SN/A
1082SN/A
1092SN/Aconst char *
1102SN/ACountedExitEvent::description()
1112SN/A{
1122SN/A    return "counted exit";
1132SN/A}
1142SN/A
1152SN/A#ifdef CHECK_SWAP_CYCLES
1162SN/Anew CheckSwapEvent(&mainEventQueue, CHECK_SWAP_CYCLES);
1172SN/A#endif
1182SN/A
1192SN/Avoid
1202SN/ACheckSwapEvent::process()
1212SN/A{
1222SN/A    /*  Check the amount of free swap space  */
1232SN/A    long swap;
1242SN/A
1252SN/A    /*  returns free swap in KBytes  */
12652SN/A    swap = procInfo("/proc/meminfo", "SwapFree:");
1272SN/A
1282SN/A    if (swap < 1000)
1292SN/A        ccprintf(cerr, "\a\a\aWarning! Swap space is low (%d)\n", swap);
1302SN/A
1312SN/A    if (swap < 100) {
1322SN/A        cerr << "\a\aAborting Simulation! Inadequate swap space!\n\n";
1332667Sstever@eecs.umich.edu        exitSimLoop("Lack of swap space");
1342SN/A    }
1352SN/A
1362SN/A    schedule(curTick + interval);
1372SN/A}
1382SN/A
1392SN/Aconst char *
1402SN/ACheckSwapEvent::description()
1412SN/A{
1422SN/A    return "check swap";
1432SN/A}
1442SN/A
1452SN/A//
1462SN/A// handle progress event: print message and reschedule
1472SN/A//
1482SN/Avoid
1492SN/AProgressEvent::process()
1502SN/A{
1512SN/A    DPRINTFN("ProgressEvent\n");
1522SN/A    // reschedule for next interval
1532SN/A    schedule(curTick + interval);
1542SN/A}
1552SN/A
1562SN/A
1572SN/Aconst char *
1582SN/AProgressEvent::description()
1592SN/A{
1602SN/A    return "progress message";
1612SN/A}
162