From 84f0a1bd91b8af5517711fba00533daddb2359e1 Mon Sep 17 00:00:00 2001 From: Steve Reinhardt Date: Thu, 22 Sep 2011 18:59:55 -0700 Subject: [PATCH] event: minor cleanup Initialize flags via the Event constructor instead of calling setFlags() in the body of the derived class's constructor. I forget exactly why, but this made life easier when implementing multi-queue support. Also rename Event::getFlags() to isFlagSet() to better match common usage, and get rid of some unused Event methods. --- src/cpu/o3/commit_impl.hh | 3 +-- src/cpu/o3/inst_queue_impl.hh | 5 ++-- src/cpu/o3/lsq_unit_impl.hh | 4 +-- src/dev/etherlink.cc | 8 ++---- src/mem/ruby/eventqueue/RubyEventQueueNode.hh | 4 +-- src/sim/debug.cc | 3 +-- src/sim/eventq.hh | 26 ++++++------------- src/sim/sim_events.cc | 7 +++-- src/sim/stat_control.cc | 4 +-- 9 files changed, 23 insertions(+), 41 deletions(-) diff --git a/src/cpu/o3/commit_impl.hh b/src/cpu/o3/commit_impl.hh index f218cc76a..75ae87c75 100644 --- a/src/cpu/o3/commit_impl.hh +++ b/src/cpu/o3/commit_impl.hh @@ -71,9 +71,8 @@ using namespace std; template DefaultCommit::TrapEvent::TrapEvent(DefaultCommit *_commit, ThreadID _tid) - : Event(CPU_Tick_Pri), commit(_commit), tid(_tid) + : Event(CPU_Tick_Pri, AutoDelete), commit(_commit), tid(_tid) { - this->setFlags(AutoDelete); } template diff --git a/src/cpu/o3/inst_queue_impl.hh b/src/cpu/o3/inst_queue_impl.hh index 9f1dc77b2..b2016cc9c 100644 --- a/src/cpu/o3/inst_queue_impl.hh +++ b/src/cpu/o3/inst_queue_impl.hh @@ -56,10 +56,9 @@ using namespace std; template InstructionQueue::FUCompletion::FUCompletion(DynInstPtr &_inst, int fu_idx, InstructionQueue *iq_ptr) - : Event(Stat_Event_Pri), inst(_inst), fuIdx(fu_idx), iqPtr(iq_ptr), - freeFU(false) + : Event(Stat_Event_Pri, AutoDelete), + inst(_inst), fuIdx(fu_idx), iqPtr(iq_ptr), freeFU(false) { - this->setFlags(Event::AutoDelete); } template diff --git a/src/cpu/o3/lsq_unit_impl.hh b/src/cpu/o3/lsq_unit_impl.hh index f934e2032..2a37d8b5c 100644 --- a/src/cpu/o3/lsq_unit_impl.hh +++ b/src/cpu/o3/lsq_unit_impl.hh @@ -60,9 +60,9 @@ template LSQUnit::WritebackEvent::WritebackEvent(DynInstPtr &_inst, PacketPtr _pkt, LSQUnit *lsq_ptr) - : inst(_inst), pkt(_pkt), lsqPtr(lsq_ptr) + : Event(Default_Pri, AutoDelete), + inst(_inst), pkt(_pkt), lsqPtr(lsq_ptr) { - this->setFlags(Event::AutoDelete); } template diff --git a/src/dev/etherlink.cc b/src/dev/etherlink.cc index 289b74543..5ebc4fba5 100644 --- a/src/dev/etherlink.cc +++ b/src/dev/etherlink.cc @@ -228,17 +228,13 @@ EtherLink::Link::unserialize(const string &base, Checkpoint *cp, } LinkDelayEvent::LinkDelayEvent() - : link(NULL) + : Event(Default_Pri, AutoSerialize | AutoDelete), link(NULL) { - setFlags(AutoSerialize); - setFlags(AutoDelete); } LinkDelayEvent::LinkDelayEvent(EtherLink::Link *l, EthPacketPtr p) - : link(l), packet(p) + : Event(Default_Pri, AutoSerialize | AutoDelete), link(l), packet(p) { - setFlags(AutoSerialize); - setFlags(AutoDelete); } void diff --git a/src/mem/ruby/eventqueue/RubyEventQueueNode.hh b/src/mem/ruby/eventqueue/RubyEventQueueNode.hh index 0bdc48e61..de1550654 100644 --- a/src/mem/ruby/eventqueue/RubyEventQueueNode.hh +++ b/src/mem/ruby/eventqueue/RubyEventQueueNode.hh @@ -39,9 +39,9 @@ class RubyEventQueueNode : public Event { public: RubyEventQueueNode(Consumer* _consumer, RubyEventQueue* _eventq) - : m_consumer_ptr(_consumer), m_eventq_ptr(_eventq) + : Event(Default_Pri, AutoDelete), + m_consumer_ptr(_consumer), m_eventq_ptr(_eventq) { - setFlags(AutoDelete); } void print(std::ostream& out) const; diff --git a/src/sim/debug.cc b/src/sim/debug.cc index bd7924117..fadd89ae1 100644 --- a/src/sim/debug.cc +++ b/src/sim/debug.cc @@ -57,9 +57,8 @@ struct DebugBreakEvent : public Event // constructor: schedule at specified time // DebugBreakEvent::DebugBreakEvent() - : Event(Debug_Break_Pri) + : Event(Debug_Break_Pri, AutoDelete) { - setFlags(AutoDelete); } // diff --git a/src/sim/eventq.hh b/src/sim/eventq.hh index fcfa119c4..1509d05a5 100644 --- a/src/sim/eventq.hh +++ b/src/sim/eventq.hh @@ -149,20 +149,13 @@ class Event : public Serializable, public FastAlloc return flags & PublicRead; } - Flags - getFlags(Flags _flags) const + bool + isFlagSet(Flags _flags) const { assert(_flags.noneSet(~PublicRead)); return flags.isSet(_flags); } - Flags - allFlags(Flags _flags) const - { - assert(_flags.noneSet(~PublicRead)); - return flags.allSet(_flags); - } - /// Accessor for flags. void setFlags(Flags _flags) @@ -247,9 +240,11 @@ class Event : public Serializable, public FastAlloc * Event constructor * @param queue that the event gets scheduled on */ - Event(Priority p = Default_Pri) - : nextBin(NULL), nextInBin(NULL), _priority(p), flags(Initialized) + Event(Priority p = Default_Pri, Flags f = 0) + : nextBin(NULL), nextInBin(NULL), _priority(p), + flags(Initialized | f) { + assert(f.noneSet(~PublicWrite)); #ifndef NDEBUG instance = ++instanceCounter; queue = NULL; @@ -406,16 +401,11 @@ class EventQueue : public Serializable } } - // default: process all events up to 'now' (curTick()) - void serviceEvents() { serviceEvents(curTick()); } - // return true if no events are queued bool empty() const { return head == NULL; } void dump() const; - Tick nextEventTime() { return empty() ? curTick() : head->when(); } - bool debugVerify() const; #ifndef SWIG @@ -559,8 +549,8 @@ DelayFunction(EventQueue *eventq, Tick when, T *object) public: DelayEvent(T *o) - : object(o) - { this->setFlags(AutoDelete); } + : Event(Default_Pri, AutoDelete), object(o) + { } void process() { (object->*F)(); } const char *description() const { return "delay"; } }; diff --git a/src/sim/sim_events.cc b/src/sim/sim_events.cc index aac844429..725e7da9d 100644 --- a/src/sim/sim_events.cc +++ b/src/sim/sim_events.cc @@ -40,9 +40,8 @@ using namespace std; SimLoopExitEvent::SimLoopExitEvent(const std::string &_cause, int c, Tick r) - : Event(Sim_Exit_Pri), cause(_cause), code(c), repeat(r) + : Event(Sim_Exit_Pri, IsExitEvent), cause(_cause), code(c), repeat(r) { - setFlags(IsExitEvent); } @@ -55,7 +54,7 @@ SimLoopExitEvent::process() // if this got scheduled on a different queue (e.g. the committed // instruction queue) then make a corresponding event on the main // queue. - if (!getFlags(IsMainQueue)) { + if (!isFlagSet(IsMainQueue)) { exitSimLoop(cause, code); delete this; } @@ -65,7 +64,7 @@ SimLoopExitEvent::process() // but if you are doing this on intervals, don't forget to make another if (repeat) { - assert(getFlags(IsMainQueue)); + assert(isFlagSet(IsMainQueue)); mainEventQueue.schedule(this, curTick() + repeat); } } diff --git a/src/sim/stat_control.cc b/src/sim/stat_control.cc index 80aec224e..7cf77174f 100644 --- a/src/sim/stat_control.cc +++ b/src/sim/stat_control.cc @@ -175,9 +175,9 @@ class StatEvent : public Event public: StatEvent(bool _dump, bool _reset, Tick _repeat) - : Event(Stat_Event_Pri), dump(_dump), reset(_reset), repeat(_repeat) + : Event(Stat_Event_Pri, AutoDelete), + dump(_dump), reset(_reset), repeat(_repeat) { - setFlags(AutoDelete); } virtual void -- 2.30.2