sim_events.hh revision 2797
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
311798SN/A#ifndef __SIM_SIM_EVENTS_HH__
321798SN/A#define __SIM_SIM_EVENTS_HH__
332SN/A
3456SN/A#include "sim/eventq.hh"
352SN/A
362SN/A//
372SN/A// Event to terminate simulation at a particular cycle/instruction
382SN/A//
392667Sstever@eecs.umich.educlass SimLoopExitEvent : public Event
402SN/A{
412SN/A  private:
422SN/A    // string explaining why we're terminating
432SN/A    std::string cause;
442SN/A    int code;
452SN/A
462SN/A  public:
472797Sktlim@umich.edu    // Default constructor.  Only really used for derived classes.
482797Sktlim@umich.edu    SimLoopExitEvent()
492797Sktlim@umich.edu        : Event(&mainEventQueue, Sim_Exit_Pri)
502797Sktlim@umich.edu    { }
512797Sktlim@umich.edu
522667Sstever@eecs.umich.edu    SimLoopExitEvent(Tick _when, const std::string &_cause, int c = 0)
53396SN/A        : Event(&mainEventQueue, Sim_Exit_Pri), cause(_cause),
542SN/A          code(c)
552667Sstever@eecs.umich.edu    { setFlags(IsExitEvent); schedule(_when); }
562SN/A
572667Sstever@eecs.umich.edu    SimLoopExitEvent(EventQueue *q,
582667Sstever@eecs.umich.edu                     Tick _when, const std::string &_cause, int c = 0)
592667Sstever@eecs.umich.edu        : Event(q, Sim_Exit_Pri), cause(_cause), code(c)
602667Sstever@eecs.umich.edu    { setFlags(IsExitEvent); schedule(_when); }
612SN/A
622667Sstever@eecs.umich.edu    std::string getCause() { return cause; }
632667Sstever@eecs.umich.edu    int getCode() { return code; }
642SN/A
652SN/A    void process();	// process event
662SN/A
672SN/A    virtual const char *description();
682SN/A};
692SN/A
702797Sktlim@umich.educlass CountedQuiesceEvent : public SimLoopExitEvent
712797Sktlim@umich.edu{
722797Sktlim@umich.edu  private:
732797Sktlim@umich.edu    // Count down to quiescing
742797Sktlim@umich.edu    int count;
752797Sktlim@umich.edu  public:
762797Sktlim@umich.edu    CountedQuiesceEvent()
772797Sktlim@umich.edu        : count(0)
782797Sktlim@umich.edu    { }
792797Sktlim@umich.edu    void process();
802797Sktlim@umich.edu
812797Sktlim@umich.edu    void setCount(int _count) { count = _count; }
822797Sktlim@umich.edu
832797Sktlim@umich.edu    int getCount() { return count; }
842797Sktlim@umich.edu};
852797Sktlim@umich.edu
862SN/A//
872SN/A// Event class to terminate simulation after 'n' related events have
882SN/A// occurred using a shared counter: used to terminate when *all*
892SN/A// threads have reached a particular instruction count
902SN/A//
912SN/Aclass CountedExitEvent : public Event
922SN/A{
932SN/A  private:
942SN/A    std::string cause;	// string explaining why we're terminating
952SN/A    int &downCounter;	// decrement & terminate if zero
962SN/A
972SN/A  public:
982SN/A    CountedExitEvent(EventQueue *q, const std::string &_cause,
992SN/A                     Tick _when, int &_downCounter);
1002SN/A
1012SN/A    void process();	// process event
1022SN/A
1032SN/A    virtual const char *description();
1042SN/A};
1052SN/A
1062SN/A//
1071798SN/A// Event to check swap usage
1082SN/A//
1092SN/Aclass CheckSwapEvent : public Event
1102SN/A{
1112SN/A  private:
1122SN/A    int interval;
1132SN/A
1142SN/A  public:
1152SN/A    CheckSwapEvent(EventQueue *q, int ival)
1162SN/A        : Event(q), interval(ival)
1171798SN/A    { schedule(curTick + interval); }
1182SN/A
1192SN/A    void process();	// process event
1202SN/A
1212SN/A    virtual const char *description();
1222SN/A};
1232SN/A
1241798SN/A//
1251798SN/A// Progress event: print out cycle every so often so we know we're
1261798SN/A// making forward progress.
1271798SN/A//
1281798SN/Aclass ProgressEvent : public Event
1291798SN/A{
1301798SN/A  protected:
1311798SN/A    Tick interval;
1321798SN/A
1331798SN/A  public:
1341798SN/A    ProgressEvent(EventQueue *q, Tick ival)
1351798SN/A        : Event(q), interval(ival)
1361798SN/A    { schedule(curTick + interval); }
1371798SN/A
1381798SN/A    void process();	// process event
1391798SN/A
1401798SN/A    virtual const char *description();
1411798SN/A};
1421798SN/A
1431798SN/A#endif  // __SIM_SIM_EVENTS_HH__
144