sim_events.hh revision 2
17860SN/A/*
27860SN/A * Copyright (c) 2003 The Regents of The University of Michigan
37860SN/A * All rights reserved.
48825Snilay@cs.wisc.edu *
57935SN/A * Redistribution and use in source and binary forms, with or without
67935SN/A * modification, are permitted provided that the following conditions are
77935SN/A * met: redistributions of source code must retain the above copyright
87860SN/A * notice, this list of conditions and the following disclaimer;
97860SN/A * redistributions in binary form must reproduce the above copyright
107860SN/A * notice, this list of conditions and the following disclaimer in the
117860SN/A * documentation and/or other materials provided with the distribution;
128825Snilay@cs.wisc.edu * neither the name of the copyright holders nor the names of its
138825Snilay@cs.wisc.edu * contributors may be used to endorse or promote products derived from
148825Snilay@cs.wisc.edu * this software without specific prior written permission.
158825Snilay@cs.wisc.edu *
167860SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
178464SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
188721SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
198825Snilay@cs.wisc.edu * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
208825Snilay@cs.wisc.edu * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
217935SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
227935SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
237935SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
247935SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
257935SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
267935SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
277935SN/A */
288893Ssaidi@eecs.umich.edu
297860SN/A#ifndef __SIM_EVENTS_HH__
307860SN/A#define __SIM_EVENTS_HH__
317860SN/A
328825Snilay@cs.wisc.edu#include "eventq.hh"
337860SN/A
347860SN/A//
357860SN/A// Event to terminate simulation at a particular cycle/instruction
367860SN/A//
378210SN/Aclass SimExitEvent : public Event
388210SN/A{
397860SN/A  private:
407860SN/A    // string explaining why we're terminating
417860SN/A    std::string cause;
427860SN/A    int code;
437860SN/A
447860SN/A  public:
457860SN/A    SimExitEvent(const std::string &_cause, int c = 0)
467860SN/A        : Event(&mainEventQueue), cause(_cause),
477860SN/A          code(c)
487860SN/A        { schedule(curTick, 1000); }
497860SN/A
507860SN/A    SimExitEvent(Tick _when, const std::string &_cause, int c = 0)
517860SN/A        : Event(&mainEventQueue), cause(_cause),
527860SN/A          code(c)
537860SN/A        { schedule(_when, 1000); }
547860SN/A
557860SN/A    SimExitEvent(EventQueue *q, const std::string &_cause, int c = 0)
567860SN/A        : Event(q), cause(_cause), code(c)
577860SN/A        { schedule(curTick, 1000); }
587860SN/A
597860SN/A    SimExitEvent(EventQueue *q, Tick _when, const std::string &_cause,
607860SN/A                 int c = 0)
618825Snilay@cs.wisc.edu        : Event(q), cause(_cause), code(c)
627860SN/A        { schedule(_when, 1000); }
637860SN/A
647860SN/A    void process();	// process event
657860SN/A
667860SN/A    virtual const char *description();
677860SN/A};
687860SN/A
697860SN/A//
707860SN/A// Event class to terminate simulation after 'n' related events have
717860SN/A// occurred using a shared counter: used to terminate when *all*
727860SN/A// threads have reached a particular instruction count
737860SN/A//
747860SN/Aclass CountedExitEvent : public Event
757860SN/A{
767860SN/A  private:
777860SN/A    std::string cause;	// string explaining why we're terminating
787860SN/A    int &downCounter;	// decrement & terminate if zero
798825Snilay@cs.wisc.edu
807860SN/A  public:
817860SN/A    CountedExitEvent(EventQueue *q, const std::string &_cause,
827860SN/A                     Tick _when, int &_downCounter);
837860SN/A
847860SN/A    void process();	// process event
857860SN/A
867860SN/A    virtual const char *description();
877860SN/A};
887860SN/A
897860SN/A//
907860SN/A// Event to cause a statistics dump
918825Snilay@cs.wisc.edu//
927860SN/Aclass DumpStatsEvent : public Event
937860SN/A{
947860SN/A  public:
957860SN/A    DumpStatsEvent()
967860SN/A        : Event(&mainEventQueue)
977860SN/A        { setFlags(AutoDelete); schedule(curTick, 999); }
987860SN/A
997860SN/A    DumpStatsEvent(EventQueue *q)
1008825Snilay@cs.wisc.edu        : Event(q)
1017860SN/A        { setFlags(AutoDelete); schedule(curTick, 999); }
1027860SN/A
1037860SN/A    DumpStatsEvent(Tick when)
1047860SN/A        : Event(&mainEventQueue)
1057860SN/A        { setFlags(AutoDelete); schedule(when, 999); }
1067860SN/A
1077860SN/A    DumpStatsEvent(EventQueue *q, Tick when)
1087860SN/A        : Event(q)
1097860SN/A        { setFlags(AutoDelete); schedule(when, 999); }
1107860SN/A
1117860SN/A    void process();
1127860SN/A
1137860SN/A    virtual const char *description();
1147860SN/A};
1157860SN/A
1167860SN/Aclass CheckSwapEvent : public Event
1178521SN/A{
1187860SN/A  private:
1197860SN/A    int interval;
1207860SN/A
1217860SN/A  public:
1227860SN/A    CheckSwapEvent(EventQueue *q, int ival)
1237860SN/A        : Event(q), interval(ival)
1247860SN/A        { schedule(interval); }
1257860SN/A
1267860SN/A    void process();	// process event
1277860SN/A
1287860SN/A    virtual const char *description();
1298893Ssaidi@eecs.umich.edu};
1307860SN/A
1317860SN/A#endif  // __SIM_EVENTS_HH__
1327860SN/A