eventq.hh revision 9979
12SN/A/* 21762SN/A * Copyright (c) 2000-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: Steve Reinhardt 292665Ssaidi@eecs.umich.edu * Nathan Binkert 302SN/A */ 312SN/A 322SN/A/* @file 332SN/A * EventQueue interfaces 342SN/A */ 352SN/A 361354SN/A#ifndef __SIM_EVENTQ_HH__ 371354SN/A#define __SIM_EVENTQ_HH__ 382SN/A 392SN/A#include <algorithm> 405501Snate@binkert.org#include <cassert> 415546Snate@binkert.org#include <climits> 427004Snate@binkert.org#include <iosfwd> 432SN/A#include <string> 442SN/A 455769Snate@binkert.org#include "base/flags.hh" 462361SN/A#include "base/misc.hh" 476216Snate@binkert.org#include "base/types.hh" 488232Snate@binkert.org#include "debug/Event.hh" 4956SN/A#include "sim/serialize.hh" 502SN/A 515543Ssaidi@eecs.umich.educlass EventQueue; // forward declaration 522SN/A 531354SN/Aextern EventQueue mainEventQueue; 541354SN/A 552SN/A/* 562SN/A * An item on an event queue. The action caused by a given 572SN/A * event is specified by deriving a subclass and overriding the 582SN/A * process() member function. 595501Snate@binkert.org * 605501Snate@binkert.org * Caution, the order of members is chosen to maximize data packing. 612SN/A */ 629044SAli.Saidi@ARM.comclass Event : public Serializable 632SN/A{ 642SN/A friend class EventQueue; 652SN/A 665769Snate@binkert.org protected: 678902Sandreas.hansson@arm.com typedef unsigned short FlagsType; 685769Snate@binkert.org typedef ::Flags<FlagsType> Flags; 695769Snate@binkert.org 707059Snate@binkert.org static const FlagsType PublicRead = 0x003f; // public readable flags 717059Snate@binkert.org static const FlagsType PublicWrite = 0x001d; // public writable flags 727059Snate@binkert.org static const FlagsType Squashed = 0x0001; // has been squashed 737059Snate@binkert.org static const FlagsType Scheduled = 0x0002; // has been scheduled 747059Snate@binkert.org static const FlagsType AutoDelete = 0x0004; // delete after dispatch 757059Snate@binkert.org static const FlagsType AutoSerialize = 0x0008; // must be serialized 767059Snate@binkert.org static const FlagsType IsExitEvent = 0x0010; // special exit event 777059Snate@binkert.org static const FlagsType IsMainQueue = 0x0020; // on main event queue 787059Snate@binkert.org static const FlagsType Initialized = 0x7a40; // somewhat random bits 797059Snate@binkert.org static const FlagsType InitMask = 0xffc0; // mask for init bits 807059Snate@binkert.org 817059Snate@binkert.org bool 827059Snate@binkert.org initialized() const 837059Snate@binkert.org { 847059Snate@binkert.org return this && (flags & InitMask) == Initialized; 857059Snate@binkert.org } 865769Snate@binkert.org 877058Snate@binkert.org public: 887058Snate@binkert.org typedef int8_t Priority; 897058Snate@binkert.org 902SN/A private: 915502Snate@binkert.org // The event queue is now a linked list of linked lists. The 925502Snate@binkert.org // 'nextBin' pointer is to find the bin, where a bin is defined as 935502Snate@binkert.org // when+priority. All events in the same bin will be stored in a 945503Snate@binkert.org // second linked list (a stack) maintained by the 'nextInBin' 955503Snate@binkert.org // pointer. The list will be accessed in LIFO order. The end 965502Snate@binkert.org // result is that the insert/removal in 'nextBin' is 975502Snate@binkert.org // linear/constant, and the lookup/removal in 'nextInBin' is 985502Snate@binkert.org // constant/constant. Hopefully this is a significant improvement 995502Snate@binkert.org // over the current fully linear insertion. 1005502Snate@binkert.org Event *nextBin; 1015502Snate@binkert.org Event *nextInBin; 1025502Snate@binkert.org 1035602Snate@binkert.org static Event *insertBefore(Event *event, Event *curr); 1045602Snate@binkert.org static Event *removeItem(Event *event, Event *last); 1055501Snate@binkert.org 1065543Ssaidi@eecs.umich.edu Tick _when; //!< timestamp when event should be processed 1077058Snate@binkert.org Priority _priority; //!< event priority 1085769Snate@binkert.org Flags flags; 1094016Sstever@eecs.umich.edu 1104016Sstever@eecs.umich.edu#ifndef NDEBUG 1114016Sstever@eecs.umich.edu /// Global counter to generate unique IDs for Event instances 1124016Sstever@eecs.umich.edu static Counter instanceCounter; 1134016Sstever@eecs.umich.edu 1144016Sstever@eecs.umich.edu /// This event's unique ID. We can also use pointer values for 1154016Sstever@eecs.umich.edu /// this but they're not consistent across runs making debugging 1164016Sstever@eecs.umich.edu /// more difficult. Thus we use a global counter value when 1174016Sstever@eecs.umich.edu /// debugging. 1185501Snate@binkert.org Counter instance; 1195605Snate@binkert.org 1205605Snate@binkert.org /// queue to which this event belongs (though it may or may not be 1215605Snate@binkert.org /// scheduled on this queue yet) 1225605Snate@binkert.org EventQueue *queue; 1235501Snate@binkert.org#endif 1244016Sstever@eecs.umich.edu 1255577SSteve.Reinhardt@amd.com#ifdef EVENTQ_DEBUG 1265501Snate@binkert.org Tick whenCreated; //!< time created 1275501Snate@binkert.org Tick whenScheduled; //!< time scheduled 1285501Snate@binkert.org#endif 1295502Snate@binkert.org 1305502Snate@binkert.org void 1315605Snate@binkert.org setWhen(Tick when, EventQueue *q) 1325502Snate@binkert.org { 1335502Snate@binkert.org _when = when; 1345605Snate@binkert.org#ifndef NDEBUG 1355605Snate@binkert.org queue = q; 1365605Snate@binkert.org#endif 1375577SSteve.Reinhardt@amd.com#ifdef EVENTQ_DEBUG 1387823Ssteve.reinhardt@amd.com whenScheduled = curTick(); 1395502Snate@binkert.org#endif 1405502Snate@binkert.org } 1415502Snate@binkert.org 1422SN/A protected: 1435769Snate@binkert.org /// Accessor for flags. 1445769Snate@binkert.org Flags 1455769Snate@binkert.org getFlags() const 1465769Snate@binkert.org { 1475769Snate@binkert.org return flags & PublicRead; 1485769Snate@binkert.org } 1492SN/A 1508581Ssteve.reinhardt@amd.com bool 1518581Ssteve.reinhardt@amd.com isFlagSet(Flags _flags) const 1525769Snate@binkert.org { 1537059Snate@binkert.org assert(_flags.noneSet(~PublicRead)); 1545769Snate@binkert.org return flags.isSet(_flags); 1555769Snate@binkert.org } 1562SN/A 1575769Snate@binkert.org /// Accessor for flags. 1585769Snate@binkert.org void 1595769Snate@binkert.org setFlags(Flags _flags) 1605769Snate@binkert.org { 1615769Snate@binkert.org assert(_flags.noneSet(~PublicWrite)); 1625769Snate@binkert.org flags.set(_flags); 1635769Snate@binkert.org } 1645769Snate@binkert.org 1655769Snate@binkert.org void 1665769Snate@binkert.org clearFlags(Flags _flags) 1675769Snate@binkert.org { 1685769Snate@binkert.org assert(_flags.noneSet(~PublicWrite)); 1695769Snate@binkert.org flags.clear(_flags); 1705769Snate@binkert.org } 1715769Snate@binkert.org 1725769Snate@binkert.org void 1735769Snate@binkert.org clearFlags() 1745769Snate@binkert.org { 1755769Snate@binkert.org flags.clear(PublicWrite); 1765769Snate@binkert.org } 1775769Snate@binkert.org 1785501Snate@binkert.org // This function isn't really useful if TRACING_ON is not defined 1795543Ssaidi@eecs.umich.edu virtual void trace(const char *action); //!< trace event activity 1802SN/A 1812SN/A public: 182396SN/A /// Event priorities, to provide tie-breakers for events scheduled 183396SN/A /// at the same cycle. Most events are scheduled at the default 184396SN/A /// priority; these values are used to control events that need to 185396SN/A /// be ordered within a cycle. 1865501Snate@binkert.org 1877058Snate@binkert.org /// Minimum priority 1887058Snate@binkert.org static const Priority Minimum_Pri = SCHAR_MIN; 1893329Sstever@eecs.umich.edu 1907058Snate@binkert.org /// If we enable tracing on a particular cycle, do that as the 1917058Snate@binkert.org /// very first thing so we don't miss any of the events on 1927058Snate@binkert.org /// that cycle (even if we enter the debugger). 1939979Satgutier@umich.edu static const Priority Debug_Enable_Pri = -101; 194396SN/A 1957058Snate@binkert.org /// Breakpoints should happen before anything else (except 1967058Snate@binkert.org /// enabling trace output), so we don't miss any action when 1977058Snate@binkert.org /// debugging. 1987058Snate@binkert.org static const Priority Debug_Break_Pri = -100; 1993329Sstever@eecs.umich.edu 2007058Snate@binkert.org /// CPU switches schedule the new CPU's tick event for the 2017058Snate@binkert.org /// same cycle (after unscheduling the old CPU's tick event). 2027058Snate@binkert.org /// The switch needs to come before any tick events to make 2037058Snate@binkert.org /// sure we don't tick both CPUs in the same cycle. 2047058Snate@binkert.org static const Priority CPU_Switch_Pri = -31; 205396SN/A 2067058Snate@binkert.org /// For some reason "delayed" inter-cluster writebacks are 2077058Snate@binkert.org /// scheduled before regular writebacks (which have default 2087058Snate@binkert.org /// priority). Steve? 2097058Snate@binkert.org static const Priority Delayed_Writeback_Pri = -1; 210396SN/A 2117058Snate@binkert.org /// Default is zero for historical reasons. 2127058Snate@binkert.org static const Priority Default_Pri = 0; 213396SN/A 2147058Snate@binkert.org /// Serailization needs to occur before tick events also, so 2157058Snate@binkert.org /// that a serialize/unserialize is identical to an on-line 2167058Snate@binkert.org /// CPU switch. 2177058Snate@binkert.org static const Priority Serialize_Pri = 32; 218396SN/A 2197058Snate@binkert.org /// CPU ticks must come after other associated CPU events 2207058Snate@binkert.org /// (such as writebacks). 2217058Snate@binkert.org static const Priority CPU_Tick_Pri = 50; 222396SN/A 2237058Snate@binkert.org /// Statistics events (dump, reset, etc.) come after 2247058Snate@binkert.org /// everything else, but before exit. 2257058Snate@binkert.org static const Priority Stat_Event_Pri = 90; 2264075Sbinkertn@umich.edu 2277058Snate@binkert.org /// Progress events come at the end. 2287058Snate@binkert.org static const Priority Progress_Event_Pri = 95; 2295501Snate@binkert.org 2307058Snate@binkert.org /// If we want to exit on this cycle, it's the very last thing 2317058Snate@binkert.org /// we do. 2327058Snate@binkert.org static const Priority Sim_Exit_Pri = 100; 2337058Snate@binkert.org 2347058Snate@binkert.org /// Maximum priority 2357058Snate@binkert.org static const Priority Maximum_Pri = SCHAR_MAX; 236396SN/A 2372SN/A /* 2382SN/A * Event constructor 2392SN/A * @param queue that the event gets scheduled on 2402SN/A */ 2418581Ssteve.reinhardt@amd.com Event(Priority p = Default_Pri, Flags f = 0) 2428581Ssteve.reinhardt@amd.com : nextBin(NULL), nextInBin(NULL), _priority(p), 2438581Ssteve.reinhardt@amd.com flags(Initialized | f) 244224SN/A { 2458581Ssteve.reinhardt@amd.com assert(f.noneSet(~PublicWrite)); 2464016Sstever@eecs.umich.edu#ifndef NDEBUG 2475501Snate@binkert.org instance = ++instanceCounter; 2485605Snate@binkert.org queue = NULL; 2495501Snate@binkert.org#endif 2505501Snate@binkert.org#ifdef EVENTQ_DEBUG 2517823Ssteve.reinhardt@amd.com whenCreated = curTick(); 2525501Snate@binkert.org whenScheduled = 0; 2534016Sstever@eecs.umich.edu#endif 254224SN/A } 255224SN/A 2565768Snate@binkert.org virtual ~Event(); 2575768Snate@binkert.org virtual const std::string name() const; 258265SN/A 2595501Snate@binkert.org /// Return a C string describing the event. This string should 2605501Snate@binkert.org /// *not* be dynamically allocated; just a const char array 2615501Snate@binkert.org /// describing the event class. 2625501Snate@binkert.org virtual const char *description() const; 2635501Snate@binkert.org 2645501Snate@binkert.org /// Dump the current event data 2655501Snate@binkert.org void dump() const; 2665501Snate@binkert.org 2675501Snate@binkert.org public: 2685501Snate@binkert.org /* 2695501Snate@binkert.org * This member function is invoked when the event is processed 2705501Snate@binkert.org * (occurs). There is no default implementation; each subclass 2715501Snate@binkert.org * must provide its own implementation. The event is not 2725501Snate@binkert.org * automatically deleted after it is processed (to allow for 2735501Snate@binkert.org * statically allocated event objects). 2745501Snate@binkert.org * 2755501Snate@binkert.org * If the AutoDestroy flag is set, the object is deleted once it 2765501Snate@binkert.org * is processed. 2775501Snate@binkert.org */ 2785501Snate@binkert.org virtual void process() = 0; 2795501Snate@binkert.org 2802SN/A /// Determine if the current event is scheduled 2815769Snate@binkert.org bool scheduled() const { return flags.isSet(Scheduled); } 2822SN/A 2832SN/A /// Squash the current event 2845769Snate@binkert.org void squash() { flags.set(Squashed); } 2852SN/A 2862SN/A /// Check whether the event is squashed 2875769Snate@binkert.org bool squashed() const { return flags.isSet(Squashed); } 2882SN/A 2892667Sstever@eecs.umich.edu /// See if this is a SimExitEvent (without resorting to RTTI) 2905769Snate@binkert.org bool isExitEvent() const { return flags.isSet(IsExitEvent); } 2912667Sstever@eecs.umich.edu 2922SN/A /// Get the time that the event is scheduled 2932SN/A Tick when() const { return _when; } 2942SN/A 2952SN/A /// Get the event priority 2967058Snate@binkert.org Priority priority() const { return _priority; } 2972SN/A 2985605Snate@binkert.org#ifndef SWIG 299224SN/A virtual void serialize(std::ostream &os); 300237SN/A virtual void unserialize(Checkpoint *cp, const std::string §ion); 3015605Snate@binkert.org#endif 302571SN/A}; 303571SN/A 3047005Snate@binkert.org#ifndef SWIG 3057005Snate@binkert.orginline bool 3067005Snate@binkert.orgoperator<(const Event &l, const Event &r) 3077005Snate@binkert.org{ 3087005Snate@binkert.org return l.when() < r.when() || 3097005Snate@binkert.org (l.when() == r.when() && l.priority() < r.priority()); 3107005Snate@binkert.org} 3117005Snate@binkert.org 3127005Snate@binkert.orginline bool 3137005Snate@binkert.orgoperator>(const Event &l, const Event &r) 3147005Snate@binkert.org{ 3157005Snate@binkert.org return l.when() > r.when() || 3167005Snate@binkert.org (l.when() == r.when() && l.priority() > r.priority()); 3177005Snate@binkert.org} 3187005Snate@binkert.org 3197005Snate@binkert.orginline bool 3207005Snate@binkert.orgoperator<=(const Event &l, const Event &r) 3217005Snate@binkert.org{ 3227005Snate@binkert.org return l.when() < r.when() || 3237005Snate@binkert.org (l.when() == r.when() && l.priority() <= r.priority()); 3247005Snate@binkert.org} 3257005Snate@binkert.orginline bool 3267005Snate@binkert.orgoperator>=(const Event &l, const Event &r) 3277005Snate@binkert.org{ 3287005Snate@binkert.org return l.when() > r.when() || 3297005Snate@binkert.org (l.when() == r.when() && l.priority() >= r.priority()); 3307005Snate@binkert.org} 3317005Snate@binkert.org 3327005Snate@binkert.orginline bool 3337005Snate@binkert.orgoperator==(const Event &l, const Event &r) 3347005Snate@binkert.org{ 3357005Snate@binkert.org return l.when() == r.when() && l.priority() == r.priority(); 3367005Snate@binkert.org} 3377005Snate@binkert.org 3387005Snate@binkert.orginline bool 3397005Snate@binkert.orgoperator!=(const Event &l, const Event &r) 3407005Snate@binkert.org{ 3417005Snate@binkert.org return l.when() != r.when() || l.priority() != r.priority(); 3427005Snate@binkert.org} 3437005Snate@binkert.org#endif 3447005Snate@binkert.org 3452SN/A/* 3462SN/A * Queue of events sorted in time order 3472SN/A */ 348395SN/Aclass EventQueue : public Serializable 3492SN/A{ 3505605Snate@binkert.org private: 351265SN/A std::string objName; 3522SN/A Event *head; 3539356Snilay@cs.wisc.edu Tick _curTick; 3542SN/A 3552SN/A void insert(Event *event); 3562SN/A void remove(Event *event); 3572SN/A 3587063Snate@binkert.org EventQueue(const EventQueue &); 3597063Snate@binkert.org const EventQueue &operator=(const EventQueue &); 3607063Snate@binkert.org 3612SN/A public: 3627063Snate@binkert.org EventQueue(const std::string &n); 3632SN/A 364512SN/A virtual const std::string name() const { return objName; } 365265SN/A 3662SN/A // schedule the given event on this queue 3675738Snate@binkert.org void schedule(Event *event, Tick when); 3685738Snate@binkert.org void deschedule(Event *event); 3695738Snate@binkert.org void reschedule(Event *event, Tick when, bool always = false); 3702SN/A 3715501Snate@binkert.org Tick nextTick() const { return head->when(); } 3729356Snilay@cs.wisc.edu void setCurTick(Tick newVal) { _curTick = newVal; } 3739356Snilay@cs.wisc.edu Tick getCurTick() { return _curTick; } 3749356Snilay@cs.wisc.edu 3752667Sstever@eecs.umich.edu Event *serviceOne(); 3762SN/A 3772SN/A // process all events up to the given timestamp. we inline a 3782SN/A // quick test to see if there are any events to process; if so, 3792SN/A // call the internal out-of-line version to process them all. 3805501Snate@binkert.org void 3815501Snate@binkert.org serviceEvents(Tick when) 3825501Snate@binkert.org { 3832SN/A while (!empty()) { 3842SN/A if (nextTick() > when) 3852SN/A break; 3862SN/A 3871634SN/A /** 3881634SN/A * @todo this assert is a good bug catcher. I need to 3891634SN/A * make it true again. 3901634SN/A */ 3911634SN/A //assert(head->when() >= when && "event scheduled in the past"); 3922SN/A serviceOne(); 3932SN/A } 3949356Snilay@cs.wisc.edu 3959356Snilay@cs.wisc.edu setCurTick(when); 3962SN/A } 3972SN/A 3982SN/A // return true if no events are queued 3995501Snate@binkert.org bool empty() const { return head == NULL; } 4002SN/A 4015501Snate@binkert.org void dump() const; 4022SN/A 4035502Snate@binkert.org bool debugVerify() const; 4045502Snate@binkert.org 4058648Snilay@cs.wisc.edu /** 4068648Snilay@cs.wisc.edu * function for replacing the head of the event queue, so that a 4078648Snilay@cs.wisc.edu * different set of events can run without disturbing events that have 4088648Snilay@cs.wisc.edu * already been scheduled. Already scheduled events can be processed 4098648Snilay@cs.wisc.edu * by replacing the original head back. 4108648Snilay@cs.wisc.edu * USING THIS FUNCTION CAN BE DANGEROUS TO THE HEALTH OF THE SIMULATOR. 4118648Snilay@cs.wisc.edu * NOT RECOMMENDED FOR USE. 4128648Snilay@cs.wisc.edu */ 4138648Snilay@cs.wisc.edu Event* replaceHead(Event* s); 4148648Snilay@cs.wisc.edu 4155605Snate@binkert.org#ifndef SWIG 416217SN/A virtual void serialize(std::ostream &os); 417237SN/A virtual void unserialize(Checkpoint *cp, const std::string §ion); 4185605Snate@binkert.org#endif 4192SN/A}; 4202SN/A 4219554Sandreas.hansson@arm.comvoid dumpMainQueue(); 4229554Sandreas.hansson@arm.com 4235605Snate@binkert.org#ifndef SWIG 4245605Snate@binkert.orgclass EventManager 4255605Snate@binkert.org{ 4265605Snate@binkert.org protected: 4275605Snate@binkert.org /** A pointer to this object's event queue */ 4285605Snate@binkert.org EventQueue *eventq; 4292SN/A 4305605Snate@binkert.org public: 4319099Sandreas.hansson@arm.com EventManager(EventManager &em) : eventq(em.eventq) {} 4329159Sandreas.hansson@arm.com EventManager(EventManager *em) : eventq(em->eventq) {} 4335605Snate@binkert.org EventManager(EventQueue *eq) : eventq(eq) {} 4342SN/A 4355605Snate@binkert.org EventQueue * 4369099Sandreas.hansson@arm.com eventQueue() const 4377060Snate@binkert.org { 4387060Snate@binkert.org return eventq; 4397060Snate@binkert.org } 4407060Snate@binkert.org 4415605Snate@binkert.org void 4425605Snate@binkert.org schedule(Event &event, Tick when) 4435605Snate@binkert.org { 4445605Snate@binkert.org eventq->schedule(&event, when); 4455605Snate@binkert.org } 4465605Snate@binkert.org 4475605Snate@binkert.org void 4485605Snate@binkert.org deschedule(Event &event) 4495605Snate@binkert.org { 4505605Snate@binkert.org eventq->deschedule(&event); 4515605Snate@binkert.org } 4525605Snate@binkert.org 4535605Snate@binkert.org void 4545605Snate@binkert.org reschedule(Event &event, Tick when, bool always = false) 4555605Snate@binkert.org { 4565605Snate@binkert.org eventq->reschedule(&event, when, always); 4575605Snate@binkert.org } 4585605Snate@binkert.org 4595605Snate@binkert.org void 4605605Snate@binkert.org schedule(Event *event, Tick when) 4615605Snate@binkert.org { 4625605Snate@binkert.org eventq->schedule(event, when); 4635605Snate@binkert.org } 4645605Snate@binkert.org 4655605Snate@binkert.org void 4665605Snate@binkert.org deschedule(Event *event) 4675605Snate@binkert.org { 4685605Snate@binkert.org eventq->deschedule(event); 4695605Snate@binkert.org } 4705605Snate@binkert.org 4715605Snate@binkert.org void 4725605Snate@binkert.org reschedule(Event *event, Tick when, bool always = false) 4735605Snate@binkert.org { 4745605Snate@binkert.org eventq->reschedule(event, when, always); 4755605Snate@binkert.org } 4769356Snilay@cs.wisc.edu 4779356Snilay@cs.wisc.edu void setCurTick(Tick newVal) { eventq->setCurTick(newVal); } 4785605Snate@binkert.org}; 4795605Snate@binkert.org 4807005Snate@binkert.orgtemplate <class T, void (T::* F)()> 4817005Snate@binkert.orgvoid 4827005Snate@binkert.orgDelayFunction(EventQueue *eventq, Tick when, T *object) 4835502Snate@binkert.org{ 4847005Snate@binkert.org class DelayEvent : public Event 4857005Snate@binkert.org { 4867005Snate@binkert.org private: 4877005Snate@binkert.org T *object; 4887005Snate@binkert.org 4897005Snate@binkert.org public: 4907005Snate@binkert.org DelayEvent(T *o) 4918581Ssteve.reinhardt@amd.com : Event(Default_Pri, AutoDelete), object(o) 4928581Ssteve.reinhardt@amd.com { } 4937005Snate@binkert.org void process() { (object->*F)(); } 4947005Snate@binkert.org const char *description() const { return "delay"; } 4957005Snate@binkert.org }; 4967005Snate@binkert.org 4977005Snate@binkert.org eventq->schedule(new DelayEvent(object), when); 4985502Snate@binkert.org} 4995502Snate@binkert.org 5007005Snate@binkert.orgtemplate <class T, void (T::* F)()> 5017005Snate@binkert.orgclass EventWrapper : public Event 5025502Snate@binkert.org{ 5037005Snate@binkert.org private: 5047005Snate@binkert.org T *object; 5055502Snate@binkert.org 5067005Snate@binkert.org public: 5077005Snate@binkert.org EventWrapper(T *obj, bool del = false, Priority p = Default_Pri) 5087005Snate@binkert.org : Event(p), object(obj) 5097005Snate@binkert.org { 5107005Snate@binkert.org if (del) 5117005Snate@binkert.org setFlags(AutoDelete); 5127005Snate@binkert.org } 5135502Snate@binkert.org 5147066Snate@binkert.org EventWrapper(T &obj, bool del = false, Priority p = Default_Pri) 5157066Snate@binkert.org : Event(p), object(&obj) 5167066Snate@binkert.org { 5177066Snate@binkert.org if (del) 5187066Snate@binkert.org setFlags(AutoDelete); 5197066Snate@binkert.org } 5207066Snate@binkert.org 5217005Snate@binkert.org void process() { (object->*F)(); } 5225502Snate@binkert.org 5237005Snate@binkert.org const std::string 5247005Snate@binkert.org name() const 5257005Snate@binkert.org { 5267005Snate@binkert.org return object->name() + ".wrapped_event"; 5277005Snate@binkert.org } 5287005Snate@binkert.org 5297005Snate@binkert.org const char *description() const { return "EventWrapped"; } 5307005Snate@binkert.org}; 5315605Snate@binkert.org#endif 5322SN/A 5331354SN/A#endif // __SIM_EVENTQ_HH__ 534