sim_events.hh revision 2
12348SN/A/* 22348SN/A * Copyright (c) 2003 The Regents of The University of Michigan 32348SN/A * All rights reserved. 42348SN/A * 52348SN/A * Redistribution and use in source and binary forms, with or without 62348SN/A * modification, are permitted provided that the following conditions are 72348SN/A * met: redistributions of source code must retain the above copyright 82348SN/A * notice, this list of conditions and the following disclaimer; 92348SN/A * redistributions in binary form must reproduce the above copyright 102348SN/A * notice, this list of conditions and the following disclaimer in the 112348SN/A * documentation and/or other materials provided with the distribution; 122348SN/A * neither the name of the copyright holders nor the names of its 132348SN/A * contributors may be used to endorse or promote products derived from 142348SN/A * this software without specific prior written permission. 152348SN/A * 162348SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 172348SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 182348SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 192348SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 202348SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 212348SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 222348SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 232348SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 242348SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 252348SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 262348SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 272689Sktlim@umich.edu */ 282689Sktlim@umich.edu 292348SN/A#ifndef __SIM_EVENTS_HH__ 302325SN/A#define __SIM_EVENTS_HH__ 312325SN/A 322325SN/A#include "eventq.hh" 332325SN/A 342325SN/A// 352325SN/A// Event to terminate simulation at a particular cycle/instruction 362325SN/A// 372348SN/Aclass SimExitEvent : public Event 382348SN/A{ 392348SN/A private: 402348SN/A // string explaining why we're terminating 412348SN/A std::string cause; 422348SN/A int code; 432348SN/A 442348SN/A public: 452348SN/A SimExitEvent(const std::string &_cause, int c = 0) 462348SN/A : Event(&mainEventQueue), cause(_cause), 472348SN/A code(c) 482348SN/A { schedule(curTick, 1000); } 492348SN/A 502348SN/A SimExitEvent(Tick _when, const std::string &_cause, int c = 0) 512348SN/A : Event(&mainEventQueue), cause(_cause), 525804Snate@binkert.org code(c) 535804Snate@binkert.org { schedule(_when, 1000); } 542325SN/A 555804Snate@binkert.org SimExitEvent(EventQueue *q, const std::string &_cause, int c = 0) 565804Snate@binkert.org : Event(q), cause(_cause), code(c) 572325SN/A { schedule(curTick, 1000); } 582325SN/A 592325SN/A SimExitEvent(EventQueue *q, Tick _when, const std::string &_cause, 602348SN/A int c = 0) 612348SN/A : Event(q), cause(_cause), code(c) 622348SN/A { schedule(_when, 1000); } 632348SN/A 642325SN/A void process(); // process event 652325SN/A 662348SN/A virtual const char *description(); 672325SN/A}; 682325SN/A 692348SN/A// 702325SN/A// Event class to terminate simulation after 'n' related events have 712325SN/A// occurred using a shared counter: used to terminate when *all* 722325SN/A// threads have reached a particular instruction count 732348SN/A// 742325SN/Aclass CountedExitEvent : public Event 752325SN/A{ 762348SN/A private: 772348SN/A std::string cause; // string explaining why we're terminating 782348SN/A int &downCounter; // decrement & terminate if zero 792325SN/A 802325SN/A public: 812325SN/A CountedExitEvent(EventQueue *q, const std::string &_cause, 822348SN/A Tick _when, int &_downCounter); 832325SN/A 842325SN/A void process(); // process event 852348SN/A 862325SN/A virtual const char *description(); 872325SN/A}; 882348SN/A 892325SN/A// 902325SN/A// Event to cause a statistics dump 912348SN/A// 922348SN/Aclass DumpStatsEvent : public Event 932348SN/A{ 942325SN/A public: 952325SN/A DumpStatsEvent() 962325SN/A : Event(&mainEventQueue) 975804Snate@binkert.org { setFlags(AutoDelete); schedule(curTick, 999); } 985804Snate@binkert.org 995804Snate@binkert.org DumpStatsEvent(EventQueue *q) 1005804Snate@binkert.org : Event(q) 1012325SN/A { setFlags(AutoDelete); schedule(curTick, 999); } 1022325SN/A 1032325SN/A DumpStatsEvent(Tick when) 1042325SN/A : Event(&mainEventQueue) 1052325SN/A { setFlags(AutoDelete); schedule(when, 999); } 1062325SN/A 1072325SN/A DumpStatsEvent(EventQueue *q, Tick when) 1082325SN/A : Event(q) 1092325SN/A { setFlags(AutoDelete); schedule(when, 999); } 1102325SN/A 1112348SN/A void process(); 1122325SN/A 1132325SN/A virtual const char *description(); 1142325SN/A}; 1152325SN/A 1162325SN/Aclass CheckSwapEvent : public Event 1172325SN/A{ 1182325SN/A private: 1192325SN/A int interval; 1202325SN/A 1212325SN/A public: 1222325SN/A CheckSwapEvent(EventQueue *q, int ival) 1232325SN/A : Event(q), interval(ival) 1242325SN/A { schedule(interval); } 1252348SN/A 1262325SN/A void process(); // process event 1272325SN/A 1282325SN/A virtual const char *description(); 1292325SN/A}; 1302325SN/A 1312325SN/A#endif // __SIM_EVENTS_HH__ 1322325SN/A