sim_events.hh revision 5543
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;
453144Shsul@eecs.umich.edu    Tick repeat;
462SN/A
472SN/A  public:
482797Sktlim@umich.edu    // Default constructor.  Only really used for derived classes.
492797Sktlim@umich.edu    SimLoopExitEvent()
502797Sktlim@umich.edu        : Event(&mainEventQueue, Sim_Exit_Pri)
512797Sktlim@umich.edu    { }
522797Sktlim@umich.edu
533144Shsul@eecs.umich.edu    SimLoopExitEvent(EventQueue *q,
543144Shsul@eecs.umich.edu                     Tick _when, Tick _repeat, const std::string &_cause,
553144Shsul@eecs.umich.edu                     int c = 0)
563144Shsul@eecs.umich.edu        : Event(q, Sim_Exit_Pri), cause(_cause),
573144Shsul@eecs.umich.edu          code(c), repeat(_repeat)
582667Sstever@eecs.umich.edu    { setFlags(IsExitEvent); schedule(_when); }
592SN/A
603144Shsul@eecs.umich.edu//     SimLoopExitEvent(EventQueue *q,
615543Ssaidi@eecs.umich.edu//                   Tick _when, const std::string &_cause,
625543Ssaidi@eecs.umich.edu//                   Tick _repeat = 0, int c = 0)
635543Ssaidi@eecs.umich.edu//      : Event(q, Sim_Exit_Pri), cause(_cause), code(c), repeat(_repeat)
643144Shsul@eecs.umich.edu//     { setFlags(IsExitEvent); schedule(_when); }
652SN/A
662667Sstever@eecs.umich.edu    std::string getCause() { return cause; }
672667Sstever@eecs.umich.edu    int getCode() { return code; }
682SN/A
695543Ssaidi@eecs.umich.edu    void process();     // process event
702SN/A
715336Shines@cs.fsu.edu    virtual const char *description() const;
722SN/A};
732SN/A
742839Sktlim@umich.educlass CountedDrainEvent : public SimLoopExitEvent
752797Sktlim@umich.edu{
762797Sktlim@umich.edu  private:
772839Sktlim@umich.edu    // Count of how many objects have not yet drained
782797Sktlim@umich.edu    int count;
792797Sktlim@umich.edu  public:
802839Sktlim@umich.edu    CountedDrainEvent()
812797Sktlim@umich.edu        : count(0)
822797Sktlim@umich.edu    { }
832797Sktlim@umich.edu    void process();
842797Sktlim@umich.edu
852797Sktlim@umich.edu    void setCount(int _count) { count = _count; }
862797Sktlim@umich.edu
872797Sktlim@umich.edu    int getCount() { return count; }
882797Sktlim@umich.edu};
892797Sktlim@umich.edu
902SN/A//
912SN/A// Event class to terminate simulation after 'n' related events have
922SN/A// occurred using a shared counter: used to terminate when *all*
932SN/A// threads have reached a particular instruction count
942SN/A//
952SN/Aclass CountedExitEvent : public Event
962SN/A{
972SN/A  private:
985543Ssaidi@eecs.umich.edu    std::string cause;  // string explaining why we're terminating
995543Ssaidi@eecs.umich.edu    int &downCounter;   // decrement & terminate if zero
1002SN/A
1012SN/A  public:
1022SN/A    CountedExitEvent(EventQueue *q, const std::string &_cause,
1032SN/A                     Tick _when, int &_downCounter);
1042SN/A
1055543Ssaidi@eecs.umich.edu    void process();     // process event
1062SN/A
1075336Shines@cs.fsu.edu    virtual const char *description() const;
1082SN/A};
1092SN/A
1102SN/A//
1111798SN/A// Event to check swap usage
1122SN/A//
1132SN/Aclass CheckSwapEvent : public Event
1142SN/A{
1152SN/A  private:
1162SN/A    int interval;
1172SN/A
1182SN/A  public:
1192SN/A    CheckSwapEvent(EventQueue *q, int ival)
1202SN/A        : Event(q), interval(ival)
1211798SN/A    { schedule(curTick + interval); }
1222SN/A
1235543Ssaidi@eecs.umich.edu    void process();     // process event
1242SN/A
1255336Shines@cs.fsu.edu    virtual const char *description() const;
1262SN/A};
1272SN/A
1281798SN/A#endif  // __SIM_SIM_EVENTS_HH__
129