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.
This commit is contained in:
parent
2680c827be
commit
2d6470936c
23 changed files with 137 additions and 84 deletions
|
@ -46,6 +46,7 @@
|
|||
|
||||
#include "base/vnc/vncinput.hh"
|
||||
#include "base/output.hh" //simout
|
||||
#include "base/trace.hh"
|
||||
#include "debug/VNC.hh"
|
||||
|
||||
using namespace std;
|
||||
|
|
|
@ -38,8 +38,9 @@
|
|||
|
||||
#include "base/bitunion.hh"
|
||||
#include "base/types.hh"
|
||||
#include "base/trace.hh"
|
||||
#include "debug/Intel8254Timer.hh"
|
||||
#include "sim/eventq.hh"
|
||||
#include "sim/eventq_impl.hh"
|
||||
#include "sim/serialize.hh"
|
||||
|
||||
/** Programmable Interval Timer (Intel 8254) */
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#ifndef __DEV_MC146818_HH__
|
||||
#define __DEV_MC146818_HH__
|
||||
|
||||
#include "sim/eventq.hh"
|
||||
#include "sim/eventq_impl.hh"
|
||||
|
||||
/** Real-Time Clock (MC146818) */
|
||||
class MC146818 : public EventManager
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
* Andreas Hansson
|
||||
*/
|
||||
|
||||
#include "base/trace.hh"
|
||||
#include "debug/CommMonitor.hh"
|
||||
#include "mem/comm_monitor.hh"
|
||||
#include "sim/stats.hh"
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
* Andreas Hansson
|
||||
*/
|
||||
|
||||
#include "base/trace.hh"
|
||||
#include "debug/Drain.hh"
|
||||
#include "debug/PacketQueue.hh"
|
||||
#include "mem/packet_queue.hh"
|
||||
|
|
|
@ -56,8 +56,8 @@
|
|||
#include <list>
|
||||
|
||||
#include "mem/port.hh"
|
||||
#include "sim/eventq.hh"
|
||||
#include "sim/drain.hh"
|
||||
#include "sim/eventq_impl.hh"
|
||||
|
||||
/**
|
||||
* A packet queue is a class that holds deferred packets and later
|
||||
|
|
|
@ -50,6 +50,7 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
|
||||
#include "base/trace.hh"
|
||||
#include "debug/BusAddrRanges.hh"
|
||||
#include "debug/Checkpoint.hh"
|
||||
#include "mem/abstract_mem.hh"
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include <cassert>
|
||||
|
||||
#include "base/trace.hh"
|
||||
#include "debug/RubyNetwork.hh"
|
||||
#include "mem/protocol/MachineType.hh"
|
||||
#include "mem/ruby/common/NetDest.hh"
|
||||
|
|
|
@ -226,7 +226,7 @@ RubySystem::serialize(std::ostream &os)
|
|||
// Restore eventq head
|
||||
eventq_head = eventq->replaceHead(eventq_head);
|
||||
// Restore curTick
|
||||
curTick(curtick_original);
|
||||
setCurTick(curtick_original);
|
||||
|
||||
uint8_t *raw_data = NULL;
|
||||
|
||||
|
@ -357,7 +357,7 @@ RubySystem::startup()
|
|||
// save the event queue head
|
||||
Event* eventq_head = eventq->replaceHead(NULL);
|
||||
// set curTick to 0 and reset Ruby System's clock
|
||||
curTick(0);
|
||||
setCurTick(0);
|
||||
resetClock();
|
||||
|
||||
// Schedule an event to start cache warmup
|
||||
|
@ -377,7 +377,7 @@ RubySystem::startup()
|
|||
// Restore eventq head
|
||||
eventq_head = eventq->replaceHead(eventq_head);
|
||||
// Restore curTick and Ruby System's clock
|
||||
curTick(curtick_original);
|
||||
setCurTick(curtick_original);
|
||||
resetClock();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@
|
|||
* Ani Udipi
|
||||
*/
|
||||
|
||||
#include "base/trace.hh"
|
||||
#include "debug/Drain.hh"
|
||||
#include "debug/DRAM.hh"
|
||||
#include "debug/DRAMWR.hh"
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
%{
|
||||
#include "base/types.hh"
|
||||
#include "python/swig/pyevent.hh"
|
||||
#include "sim/eventq.hh"
|
||||
#include "sim/eventq_impl.hh"
|
||||
#include "sim/sim_events.hh"
|
||||
#include "sim/sim_exit.hh"
|
||||
#include "sim/simulate.hh"
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
|
||||
#include "base/intmath.hh"
|
||||
#include "params/ClockedObject.hh"
|
||||
#include "sim/core.hh"
|
||||
#include "sim/sim_object.hh"
|
||||
|
||||
/**
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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"
|
||||
|
||||
|
|
|
@ -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)
|
||||
{}
|
||||
|
|
|
@ -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,68 +481,10 @@ class EventManager
|
|||
{
|
||||
eventq->reschedule(event, when, always);
|
||||
}
|
||||
|
||||
void setCurTick(Tick newVal) { eventq->setCurTick(newVal); }
|
||||
};
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
template <class T, void (T::* F)()>
|
||||
void
|
||||
DelayFunction(EventQueue *eventq, Tick when, T *object)
|
||||
|
|
100
src/sim/eventq_impl.hh
Normal file
100
src/sim/eventq_impl.hh
Normal file
|
@ -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__
|
|
@ -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"
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue