sim_events.cc revision 2839
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
812797Sktlim@umich.eduvoid
822839Sktlim@umich.eduCountedDrainEvent::process()
832797Sktlim@umich.edu{
842797Sktlim@umich.edu    if (--count == 0) {
852839Sktlim@umich.edu        exitSimLoop("Finished drain");
862797Sktlim@umich.edu    }
872797Sktlim@umich.edu}
882797Sktlim@umich.edu
892SN/A//
902SN/A// constructor: automatically schedules at specified time
912SN/A//
922SN/ACountedExitEvent::CountedExitEvent(EventQueue *q, const std::string &_cause,
932SN/A                                   Tick _when, int &_downCounter)
94396SN/A    : Event(q, Sim_Exit_Pri),
952SN/A      cause(_cause),
962SN/A      downCounter(_downCounter)
972SN/A{
982SN/A    // catch stupid mistakes
992SN/A    assert(downCounter > 0);
1002SN/A
101396SN/A    schedule(_when);
1022SN/A}
1032SN/A
1042SN/A
1052SN/A//
1062SN/A// handle termination event
1072SN/A//
1082SN/Avoid
1092SN/ACountedExitEvent::process()
1102SN/A{
1112SN/A    if (--downCounter == 0) {
1122667Sstever@eecs.umich.edu        exitSimLoop(cause, 0);
1132SN/A    }
1142SN/A}
1152SN/A
1162SN/A
1172SN/Aconst char *
1182SN/ACountedExitEvent::description()
1192SN/A{
1202SN/A    return "counted exit";
1212SN/A}
1222SN/A
1232SN/A#ifdef CHECK_SWAP_CYCLES
1242SN/Anew CheckSwapEvent(&mainEventQueue, CHECK_SWAP_CYCLES);
1252SN/A#endif
1262SN/A
1272SN/Avoid
1282SN/ACheckSwapEvent::process()
1292SN/A{
1302SN/A    /*  Check the amount of free swap space  */
1312SN/A    long swap;
1322SN/A
1332SN/A    /*  returns free swap in KBytes  */
13452SN/A    swap = procInfo("/proc/meminfo", "SwapFree:");
1352SN/A
1362SN/A    if (swap < 1000)
1372SN/A        ccprintf(cerr, "\a\a\aWarning! Swap space is low (%d)\n", swap);
1382SN/A
1392SN/A    if (swap < 100) {
1402SN/A        cerr << "\a\aAborting Simulation! Inadequate swap space!\n\n";
1412667Sstever@eecs.umich.edu        exitSimLoop("Lack of swap space");
1422SN/A    }
1432SN/A
1442SN/A    schedule(curTick + interval);
1452SN/A}
1462SN/A
1472SN/Aconst char *
1482SN/ACheckSwapEvent::description()
1492SN/A{
1502SN/A    return "check swap";
1512SN/A}
1522SN/A
1532SN/A//
1542SN/A// handle progress event: print message and reschedule
1552SN/A//
1562SN/Avoid
1572SN/AProgressEvent::process()
1582SN/A{
1592SN/A    DPRINTFN("ProgressEvent\n");
1602SN/A    // reschedule for next interval
1612SN/A    schedule(curTick + interval);
1622SN/A}
1632SN/A
1642SN/A
1652SN/Aconst char *
1662SN/AProgressEvent::description()
1672SN/A{
1682SN/A    return "progress message";
1692SN/A}
170