sim_events.hh 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
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:
472667Sstever@eecs.umich.edu    SimLoopExitEvent(Tick _when, const std::string &_cause, int c = 0)
48396SN/A        : Event(&mainEventQueue, Sim_Exit_Pri), cause(_cause),
492SN/A          code(c)
502667Sstever@eecs.umich.edu    { setFlags(IsExitEvent); schedule(_when); }
512SN/A
522667Sstever@eecs.umich.edu    SimLoopExitEvent(EventQueue *q,
532667Sstever@eecs.umich.edu                     Tick _when, const std::string &_cause, int c = 0)
542667Sstever@eecs.umich.edu        : Event(q, Sim_Exit_Pri), cause(_cause), code(c)
552667Sstever@eecs.umich.edu    { setFlags(IsExitEvent); schedule(_when); }
562SN/A
572667Sstever@eecs.umich.edu    std::string getCause() { return cause; }
582667Sstever@eecs.umich.edu    int getCode() { return code; }
592SN/A
602SN/A    void process();	// process event
612SN/A
622SN/A    virtual const char *description();
632SN/A};
642SN/A
652SN/A//
662SN/A// Event class to terminate simulation after 'n' related events have
672SN/A// occurred using a shared counter: used to terminate when *all*
682SN/A// threads have reached a particular instruction count
692SN/A//
702SN/Aclass CountedExitEvent : public Event
712SN/A{
722SN/A  private:
732SN/A    std::string cause;	// string explaining why we're terminating
742SN/A    int &downCounter;	// decrement & terminate if zero
752SN/A
762SN/A  public:
772SN/A    CountedExitEvent(EventQueue *q, const std::string &_cause,
782SN/A                     Tick _when, int &_downCounter);
792SN/A
802SN/A    void process();	// process event
812SN/A
822SN/A    virtual const char *description();
832SN/A};
842SN/A
852SN/A//
861798SN/A// Event to check swap usage
872SN/A//
882SN/Aclass CheckSwapEvent : public Event
892SN/A{
902SN/A  private:
912SN/A    int interval;
922SN/A
932SN/A  public:
942SN/A    CheckSwapEvent(EventQueue *q, int ival)
952SN/A        : Event(q), interval(ival)
961798SN/A    { schedule(curTick + interval); }
972SN/A
982SN/A    void process();	// process event
992SN/A
1002SN/A    virtual const char *description();
1012SN/A};
1022SN/A
1031798SN/A//
1041798SN/A// Progress event: print out cycle every so often so we know we're
1051798SN/A// making forward progress.
1061798SN/A//
1071798SN/Aclass ProgressEvent : public Event
1081798SN/A{
1091798SN/A  protected:
1101798SN/A    Tick interval;
1111798SN/A
1121798SN/A  public:
1131798SN/A    ProgressEvent(EventQueue *q, Tick ival)
1141798SN/A        : Event(q), interval(ival)
1151798SN/A    { schedule(curTick + interval); }
1161798SN/A
1171798SN/A    void process();	// process event
1181798SN/A
1191798SN/A    virtual const char *description();
1201798SN/A};
1211798SN/A
1221798SN/A#endif  // __SIM_SIM_EVENTS_HH__
123