sim_events.hh revision 2
114184Sgabeblack@google.com/*
214184Sgabeblack@google.com * Copyright (c) 2003 The Regents of The University of Michigan
314184Sgabeblack@google.com * All rights reserved.
414184Sgabeblack@google.com *
514184Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
614184Sgabeblack@google.com * modification, are permitted provided that the following conditions are
714184Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
814184Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
914184Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
1014184Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1114184Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1214184Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1314184Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1414184Sgabeblack@google.com * this software without specific prior written permission.
1514184Sgabeblack@google.com *
1614184Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1714184Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1814184Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1914184Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2014184Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2114184Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2214184Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2314184Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2414184Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2514184Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2614184Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2714184Sgabeblack@google.com */
2814184Sgabeblack@google.com
2914184Sgabeblack@google.com#ifndef __SIM_EVENTS_HH__
3014184Sgabeblack@google.com#define __SIM_EVENTS_HH__
3114184Sgabeblack@google.com
3214184Sgabeblack@google.com#include "eventq.hh"
3314184Sgabeblack@google.com
3414184Sgabeblack@google.com//
3514184Sgabeblack@google.com// Event to terminate simulation at a particular cycle/instruction
3614184Sgabeblack@google.com//
3714184Sgabeblack@google.comclass SimExitEvent : public Event
3814184Sgabeblack@google.com{
3914184Sgabeblack@google.com  private:
4014184Sgabeblack@google.com    // string explaining why we're terminating
4114184Sgabeblack@google.com    std::string cause;
4214184Sgabeblack@google.com    int code;
4314184Sgabeblack@google.com
4414184Sgabeblack@google.com  public:
4514184Sgabeblack@google.com    SimExitEvent(const std::string &_cause, int c = 0)
4614184Sgabeblack@google.com        : Event(&mainEventQueue), cause(_cause),
4714184Sgabeblack@google.com          code(c)
4814184Sgabeblack@google.com        { schedule(curTick, 1000); }
4914184Sgabeblack@google.com
5014184Sgabeblack@google.com    SimExitEvent(Tick _when, const std::string &_cause, int c = 0)
5114184Sgabeblack@google.com        : Event(&mainEventQueue), cause(_cause),
5214184Sgabeblack@google.com          code(c)
5314184Sgabeblack@google.com        { schedule(_when, 1000); }
5414184Sgabeblack@google.com
5514184Sgabeblack@google.com    SimExitEvent(EventQueue *q, const std::string &_cause, int c = 0)
5614184Sgabeblack@google.com        : Event(q), cause(_cause), code(c)
5714184Sgabeblack@google.com        { schedule(curTick, 1000); }
5814184Sgabeblack@google.com
5914184Sgabeblack@google.com    SimExitEvent(EventQueue *q, Tick _when, const std::string &_cause,
6014184Sgabeblack@google.com                 int c = 0)
6114184Sgabeblack@google.com        : Event(q), cause(_cause), code(c)
6214184Sgabeblack@google.com        { schedule(_when, 1000); }
6314184Sgabeblack@google.com
6414184Sgabeblack@google.com    void process();	// process event
6514184Sgabeblack@google.com
6614184Sgabeblack@google.com    virtual const char *description();
6714184Sgabeblack@google.com};
6814184Sgabeblack@google.com
6914184Sgabeblack@google.com//
7014184Sgabeblack@google.com// Event class to terminate simulation after 'n' related events have
7114184Sgabeblack@google.com// occurred using a shared counter: used to terminate when *all*
7214184Sgabeblack@google.com// threads have reached a particular instruction count
7314184Sgabeblack@google.com//
7414184Sgabeblack@google.comclass CountedExitEvent : public Event
7514184Sgabeblack@google.com{
7614184Sgabeblack@google.com  private:
7714184Sgabeblack@google.com    std::string cause;	// string explaining why we're terminating
7814184Sgabeblack@google.com    int &downCounter;	// decrement & terminate if zero
7914184Sgabeblack@google.com
8014184Sgabeblack@google.com  public:
8114184Sgabeblack@google.com    CountedExitEvent(EventQueue *q, const std::string &_cause,
8214184Sgabeblack@google.com                     Tick _when, int &_downCounter);
8314184Sgabeblack@google.com
8414184Sgabeblack@google.com    void process();	// process event
8514184Sgabeblack@google.com
8614184Sgabeblack@google.com    virtual const char *description();
8714184Sgabeblack@google.com};
8814184Sgabeblack@google.com
8914184Sgabeblack@google.com//
9014184Sgabeblack@google.com// Event to cause a statistics dump
9114184Sgabeblack@google.com//
9214184Sgabeblack@google.comclass DumpStatsEvent : public Event
9314184Sgabeblack@google.com{
9414184Sgabeblack@google.com  public:
9514184Sgabeblack@google.com    DumpStatsEvent()
9614184Sgabeblack@google.com        : Event(&mainEventQueue)
9714184Sgabeblack@google.com        { setFlags(AutoDelete); schedule(curTick, 999); }
9814184Sgabeblack@google.com
9914184Sgabeblack@google.com    DumpStatsEvent(EventQueue *q)
10014184Sgabeblack@google.com        : Event(q)
10114184Sgabeblack@google.com        { setFlags(AutoDelete); schedule(curTick, 999); }
10214184Sgabeblack@google.com
10314184Sgabeblack@google.com    DumpStatsEvent(Tick when)
10414184Sgabeblack@google.com        : Event(&mainEventQueue)
10514184Sgabeblack@google.com        { setFlags(AutoDelete); schedule(when, 999); }
10614184Sgabeblack@google.com
10714184Sgabeblack@google.com    DumpStatsEvent(EventQueue *q, Tick when)
10814184Sgabeblack@google.com        : Event(q)
10914184Sgabeblack@google.com        { setFlags(AutoDelete); schedule(when, 999); }
11014184Sgabeblack@google.com
11114184Sgabeblack@google.com    void process();
11214184Sgabeblack@google.com
11314184Sgabeblack@google.com    virtual const char *description();
11414184Sgabeblack@google.com};
11514184Sgabeblack@google.com
11614184Sgabeblack@google.comclass CheckSwapEvent : public Event
11714184Sgabeblack@google.com{
11814184Sgabeblack@google.com  private:
11914184Sgabeblack@google.com    int interval;
12014184Sgabeblack@google.com
12114184Sgabeblack@google.com  public:
12214184Sgabeblack@google.com    CheckSwapEvent(EventQueue *q, int ival)
12314184Sgabeblack@google.com        : Event(q), interval(ival)
12414184Sgabeblack@google.com        { schedule(interval); }
12514184Sgabeblack@google.com
12614184Sgabeblack@google.com    void process();	// process event
12714184Sgabeblack@google.com
12814184Sgabeblack@google.com    virtual const char *description();
12914184Sgabeblack@google.com};
13014184Sgabeblack@google.com
13114184Sgabeblack@google.com#endif  // __SIM_EVENTS_HH__
13214184Sgabeblack@google.com