diff options
author | Nilay Vaish <nilay@cs.wisc.edu> | 2012-11-16 10:27:47 -0600 |
---|---|---|
committer | Nilay Vaish <nilay@cs.wisc.edu> | 2012-11-16 10:27:47 -0600 |
commit | 2d6470936ca06310b213117159fa0010259708cd (patch) | |
tree | 24fc62d3c1b27711fecadffacc722bbae45c3df9 /src/sim | |
parent | 2680c827bee835175d780b82b93590e2b3467591 (diff) | |
download | gem5-2d6470936ca06310b213117159fa0010259708cd.tar.xz |
sim: have a curTick per eventq
This patch adds a _curTick variable to an eventq. This variable is updated
whenever an event is serviced in function serviceOne(), or all events upto
a particular time are processed in function serviceEvents(). This change
helps when there are eventqs that do not make use of curTick for scheduling
events.
Diffstat (limited to 'src/sim')
-rw-r--r-- | src/sim/clocked_object.hh | 1 | ||||
-rw-r--r-- | src/sim/core.cc | 3 | ||||
-rw-r--r-- | src/sim/core.hh | 6 | ||||
-rw-r--r-- | src/sim/debug.cc | 2 | ||||
-rw-r--r-- | src/sim/eventq.cc | 7 | ||||
-rw-r--r-- | src/sim/eventq.hh | 69 | ||||
-rw-r--r-- | src/sim/eventq_impl.hh | 100 | ||||
-rw-r--r-- | src/sim/root.cc | 1 | ||||
-rw-r--r-- | src/sim/serialize.cc | 2 | ||||
-rw-r--r-- | src/sim/sim_events.cc | 2 | ||||
-rw-r--r-- | src/sim/sim_object.hh | 2 | ||||
-rw-r--r-- | src/sim/simulate.cc | 5 |
12 files changed, 123 insertions, 77 deletions
diff --git a/src/sim/clocked_object.hh b/src/sim/clocked_object.hh index 9a4c1034a..d9630139a 100644 --- a/src/sim/clocked_object.hh +++ b/src/sim/clocked_object.hh @@ -47,6 +47,7 @@ #include "base/intmath.hh" #include "params/ClockedObject.hh" +#include "sim/core.hh" #include "sim/sim_object.hh" /** diff --git a/src/sim/core.cc b/src/sim/core.cc index ab75e1d9a..aa618bdb3 100644 --- a/src/sim/core.cc +++ b/src/sim/core.cc @@ -35,11 +35,10 @@ #include "base/callback.hh" #include "base/output.hh" #include "sim/core.hh" +#include "sim/eventq.hh" using namespace std; -Tick _curTick = 0; - namespace SimClock { /// The simulated frequency of curTick(). (In ticks per second) Tick Frequency; diff --git a/src/sim/core.hh b/src/sim/core.hh index 4f842ab48..b5a082bcb 100644 --- a/src/sim/core.hh +++ b/src/sim/core.hh @@ -39,12 +39,10 @@ #include <string> #include "base/types.hh" +#include "sim/eventq.hh" /// The universal simulation clock. -extern Tick _curTick; - -inline Tick curTick() { return _curTick; } -inline void curTick(Tick newVal) { _curTick = newVal; } +inline Tick curTick() { return mainEventQueue.getCurTick(); } const Tick retryTime = 1000; diff --git a/src/sim/debug.cc b/src/sim/debug.cc index fadd89ae1..51b92740e 100644 --- a/src/sim/debug.cc +++ b/src/sim/debug.cc @@ -36,7 +36,7 @@ #include "base/debug.hh" #include "sim/debug.hh" -#include "sim/eventq.hh" +#include "sim/eventq_impl.hh" #include "sim/sim_events.hh" #include "sim/sim_exit.hh" diff --git a/src/sim/eventq.cc b/src/sim/eventq.cc index b32b330e7..d81937a86 100644 --- a/src/sim/eventq.cc +++ b/src/sim/eventq.cc @@ -42,7 +42,7 @@ #include "cpu/smt.hh" #include "debug/Config.hh" #include "sim/core.hh" -#include "sim/eventq.hh" +#include "sim/eventq_impl.hh" using namespace std; @@ -201,6 +201,9 @@ EventQueue::serviceOne() // handle action if (!event->squashed()) { + // forward current cycle to the time when this event occurs. + setCurTick(event->when()); + event->process(); if (event->isExitEvent()) { assert(!event->flags.isSet(Event::AutoDelete) || @@ -429,5 +432,5 @@ Event::dump() const } EventQueue::EventQueue(const string &n) - : objName(n), head(NULL) + : objName(n), head(NULL), _curTick(0) {} diff --git a/src/sim/eventq.hh b/src/sim/eventq.hh index 5362dcf34..5d5764a6a 100644 --- a/src/sim/eventq.hh +++ b/src/sim/eventq.hh @@ -44,7 +44,6 @@ #include "base/flags.hh" #include "base/misc.hh" -#include "base/trace.hh" #include "base/types.hh" #include "debug/Event.hh" #include "sim/serialize.hh" @@ -361,6 +360,7 @@ class EventQueue : public Serializable private: std::string objName; Event *head; + Tick _curTick; void insert(Event *event); void remove(Event *event); @@ -379,6 +379,9 @@ class EventQueue : public Serializable void reschedule(Event *event, Tick when, bool always = false); Tick nextTick() const { return head->when(); } + void setCurTick(Tick newVal) { _curTick = newVal; } + Tick getCurTick() { return _curTick; } + Event *serviceOne(); // process all events up to the given timestamp. we inline a @@ -398,6 +401,8 @@ class EventQueue : public Serializable //assert(head->when() >= when && "event scheduled in the past"); serviceOne(); } + + setCurTick(when); } // return true if no events are queued @@ -476,67 +481,9 @@ class EventManager { eventq->reschedule(event, when, always); } -}; - -inline void -EventQueue::schedule(Event *event, Tick when) -{ - assert(when >= curTick()); - assert(!event->scheduled()); - assert(event->initialized()); - - event->setWhen(when, this); - insert(event); - event->flags.set(Event::Scheduled); - if (this == &mainEventQueue) - event->flags.set(Event::IsMainQueue); - else - event->flags.clear(Event::IsMainQueue); - - if (DTRACE(Event)) - event->trace("scheduled"); -} - -inline void -EventQueue::deschedule(Event *event) -{ - assert(event->scheduled()); - assert(event->initialized()); - remove(event); - - event->flags.clear(Event::Squashed); - event->flags.clear(Event::Scheduled); - - if (DTRACE(Event)) - event->trace("descheduled"); - - if (event->flags.isSet(Event::AutoDelete)) - delete event; -} - -inline void -EventQueue::reschedule(Event *event, Tick when, bool always) -{ - assert(when >= curTick()); - assert(always || event->scheduled()); - assert(event->initialized()); - - if (event->scheduled()) - remove(event); - - event->setWhen(when, this); - insert(event); - event->flags.clear(Event::Squashed); - event->flags.set(Event::Scheduled); - if (this == &mainEventQueue) - event->flags.set(Event::IsMainQueue); - else - event->flags.clear(Event::IsMainQueue); - - if (DTRACE(Event)) - event->trace("rescheduled"); -} + void setCurTick(Tick newVal) { eventq->setCurTick(newVal); } +}; template <class T, void (T::* F)()> void diff --git a/src/sim/eventq_impl.hh b/src/sim/eventq_impl.hh new file mode 100644 index 000000000..c53a4da77 --- /dev/null +++ b/src/sim/eventq_impl.hh @@ -0,0 +1,100 @@ +/* + * Copyright (c) 2012 The Regents of The University of Michigan + * Copyright (c) 2012 Mark D. Hill and David A. Wood + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer; + * redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution; + * neither the name of the copyright holders nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * Authors: Steve Reinhardt + * Nathan Binkert + * Nilay Vaish + */ + +#ifndef __SIM_EVENTQ_IMPL_HH__ +#define __SIM_EVENTQ_IMPL_HH__ + +#include "base/trace.hh" +#include "sim/eventq.hh" + +inline void +EventQueue::schedule(Event *event, Tick when) +{ + assert(when >= getCurTick()); + assert(!event->scheduled()); + assert(event->initialized()); + + event->setWhen(when, this); + insert(event); + event->flags.set(Event::Scheduled); + if (this == &mainEventQueue) + event->flags.set(Event::IsMainQueue); + else + event->flags.clear(Event::IsMainQueue); + + if (DTRACE(Event)) + event->trace("scheduled"); +} + +inline void +EventQueue::deschedule(Event *event) +{ + assert(event->scheduled()); + assert(event->initialized()); + + remove(event); + + event->flags.clear(Event::Squashed); + event->flags.clear(Event::Scheduled); + + if (DTRACE(Event)) + event->trace("descheduled"); + + if (event->flags.isSet(Event::AutoDelete)) + delete event; +} + +inline void +EventQueue::reschedule(Event *event, Tick when, bool always) +{ + assert(when >= getCurTick()); + assert(always || event->scheduled()); + assert(event->initialized()); + + if (event->scheduled()) + remove(event); + + event->setWhen(when, this); + insert(event); + event->flags.clear(Event::Squashed); + event->flags.set(Event::Scheduled); + if (this == &mainEventQueue) + event->flags.set(Event::IsMainQueue); + else + event->flags.clear(Event::IsMainQueue); + + if (DTRACE(Event)) + event->trace("rescheduled"); +} + +#endif // __SIM_EVENTQ_IMPL_HH__ diff --git a/src/sim/root.cc b/src/sim/root.cc index b8fadf190..f77159486 100644 --- a/src/sim/root.cc +++ b/src/sim/root.cc @@ -32,6 +32,7 @@ */ #include "base/misc.hh" +#include "base/trace.hh" #include "config/the_isa.hh" #include "debug/TimeSync.hh" #include "sim/full_system.hh" diff --git a/src/sim/serialize.cc b/src/sim/serialize.cc index 54b7926d6..9ef92d449 100644 --- a/src/sim/serialize.cc +++ b/src/sim/serialize.cc @@ -465,7 +465,7 @@ Globals::unserialize(Checkpoint *cp, const std::string §ion) { Tick tick; paramIn(cp, section, "curTick", tick); - curTick(tick); + mainEventQueue.setCurTick(tick); mainEventQueue.unserialize(cp, "MainEventQueue"); } diff --git a/src/sim/sim_events.cc b/src/sim/sim_events.cc index 2354e89f7..0ae7e573e 100644 --- a/src/sim/sim_events.cc +++ b/src/sim/sim_events.cc @@ -32,7 +32,7 @@ #include "base/callback.hh" #include "base/hostinfo.hh" -#include "sim/eventq.hh" +#include "sim/eventq_impl.hh" #include "sim/sim_events.hh" #include "sim/sim_exit.hh" #include "sim/stats.hh" diff --git a/src/sim/sim_object.hh b/src/sim/sim_object.hh index f04289e2f..6424f631b 100644 --- a/src/sim/sim_object.hh +++ b/src/sim/sim_object.hh @@ -46,7 +46,7 @@ #include "enums/MemoryMode.hh" #include "params/SimObject.hh" #include "sim/drain.hh" -#include "sim/eventq.hh" +#include "sim/eventq_impl.hh" #include "sim/serialize.hh" class BaseCPU; diff --git a/src/sim/simulate.cc b/src/sim/simulate.cc index 238e68787..6962fab9f 100644 --- a/src/sim/simulate.cc +++ b/src/sim/simulate.cc @@ -33,7 +33,7 @@ #include "base/pollevent.hh" #include "base/types.hh" #include "sim/async.hh" -#include "sim/eventq.hh" +#include "sim/eventq_impl.hh" #include "sim/sim_events.hh" #include "sim/sim_exit.hh" #include "sim/simulate.hh" @@ -65,9 +65,6 @@ simulate(Tick num_cycles) assert(curTick() <= mainEventQueue.nextTick() && "event scheduled in the past"); - // forward current cycle to the time of the first event on the - // queue - curTick(mainEventQueue.nextTick()); Event *exit_event = mainEventQueue.serviceOne(); if (exit_event != NULL) { // hit some kind of exit event; return to Python |