sim_events.hh revision 7820:4ee66d8c1dd8
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#ifndef __SIM_SIM_EVENTS_HH__
322SN/A#define __SIM_SIM_EVENTS_HH__
332SN/A
342SN/A#include "sim/eventq.hh"
352SN/A
3656SN/A//
372SN/A// Event to terminate simulation at a particular cycle/instruction
382SN/A//
392SN/Aclass SimLoopExitEvent : public Event
402SN/A{
412SN/A  protected:
42492SN/A    // string explaining why we're terminating
43492SN/A    std::string cause;
44492SN/A    int code;
45492SN/A    Tick repeat;
46492SN/A
47492SN/A  public:
48492SN/A    SimLoopExitEvent(const std::string &_cause, int c, Tick repeat = 0);
49492SN/A
502SN/A    std::string getCause() { return cause; }
512SN/A    int getCode() { return code; }
522SN/A
53492SN/A    void process();     // process event
54492SN/A
55492SN/A    virtual const char *description() const;
562SN/A};
572SN/A
582SN/Aclass CountedDrainEvent : public SimLoopExitEvent
592SN/A{
602SN/A  private:
612SN/A    // Count of how many objects have not yet drained
622SN/A    int count;
632SN/A
642SN/A  public:
652SN/A    CountedDrainEvent();
662SN/A
672SN/A    void process();
682SN/A
692SN/A    void setCount(int _count) { count = _count; }
70448SN/A
712SN/A    int getCount() { return count; }
722SN/A};
732SN/A
742SN/A//
752SN/A// Event class to terminate simulation after 'n' related events have
762SN/A// occurred using a shared counter: used to terminate when *all*
772SN/A// threads have reached a particular instruction count
782SN/A//
792SN/Aclass CountedExitEvent : public Event
802SN/A{
812SN/A  private:
822SN/A    std::string cause;  // string explaining why we're terminating
832SN/A    int &downCounter;   // decrement & terminate if zero
842SN/A
852SN/A  public:
862SN/A    CountedExitEvent(const std::string &_cause, int &_downCounter);
872SN/A
882SN/A    void process();     // process event
892SN/A
902SN/A    virtual const char *description() const;
912SN/A};
922SN/A
932SN/A
942SN/A#endif  // __SIM_SIM_EVENTS_HH__
952SN/A