All developers should be aware of this change.  It is a significant
difference from what we're used to and could cause some issues with
uncommitted code.  It is necessary to make a workable solution for
parallelized M5.

  Nate

On Thu, Oct 9, 2008 at 9:11 AM, Nathan Binkert <[EMAIL PROTECTED]> wrote:
> changeset b194a80157e2 in /z/repo/m5
> details: http://repo.m5sim.org/m5?cmd=changeset;node=b194a80157e2
> description:
>        eventq: Major API change for the Event and EventQueue structures.
>
>        Since the early days of M5, an event needed to know which event queue
>        it was on, and that data was required at the time of construction of
>        the event object.  In the future parallelized M5, this sort of
>        requirement does not work well since the proper event queue will not
>        always be known at the time of construction of an event.  Now, events
>        are created, and the EventQueue itself has the schedule function,
>        e.g. eventq->schedule(event, when).  To simplify the syntax, I created
>        a class called EventManager which holds a pointer to an EventQueue and
>        provides the schedule interface that is a proxy for the EventQueue.
>        The intent is that objects that frequently schedule events can be
>        derived from EventManager and then they have the schedule interface.
>        SimObject and Port are examples of objects that will become
>        EventManagers.  The end result is that any SimObject can just call
>        schedule(event, when) and it will just call that SimObject's
>        eventq->schedule function.  Of course, some objects may have more than
>        one EventQueue, so this interface might not be perfect for those, but
>        they should be relatively few.
>
> diffstat:
>
> 6 files changed, 21 insertions(+), 20 deletions(-)
> src/python/m5/event.py       |   14 ++++++++++----
> src/python/swig/event.i      |   10 +++++++++-
> src/python/swig/pyevent.cc   |    1 -
> src/python/swig/pyevent.hh   |   10 +---------
> src/sim/eventq.hh            |    5 -----
> src/sim/sim_object_params.hh |    1 +
>
> diffs (truncated from 816 to 300 lines):
>
> diff -r 7c58fc1ec5dc -r b194a80157e2 src/mem/port.cc
> --- a/src/mem/port.cc   Thu Oct 09 04:58:23 2008 -0700
> +++ b/src/mem/port.cc   Thu Oct 09 04:58:23 2008 -0700
> @@ -49,7 +49,7 @@
>
>   public:
>     DefaultPeerPort()
> -        : Port("default_port")
> +        : Port("default_port", NULL)
>     { }
>
>     bool recvTiming(PacketPtr)
> @@ -90,13 +90,9 @@
>
>  DefaultPeerPort defaultPeerPort;
>
> -Port::Port()
> -    : peer(&defaultPeerPort), owner(NULL)
> -{
> -}
> -
>  Port::Port(const std::string &_name, MemObject *_owner)
> -    : portName(_name), peer(&defaultPeerPort), owner(_owner)
> +    : EventManager(_owner), portName(_name), peer(&defaultPeerPort),
> +      owner(_owner)
>  {
>  }
>
> @@ -110,6 +106,13 @@
>     DPRINTF(Config, "setting peer to %s\n", port->name());
>
>     peer = port;
> +}
> +
> +void
> +Port::setOwner(MemObject *_owner)
> +{
> +    eventq = _owner->queue();
> +    owner = _owner;
>  }
>
>  void
> diff -r 7c58fc1ec5dc -r b194a80157e2 src/mem/port.hh
> --- a/src/mem/port.hh   Thu Oct 09 04:58:23 2008 -0700
> +++ b/src/mem/port.hh   Thu Oct 09 04:58:23 2008 -0700
> @@ -47,6 +47,7 @@
>  #include "base/range.hh"
>  #include "mem/packet.hh"
>  #include "mem/request.hh"
> +#include "sim/eventq.hh"
>
>  /** This typedef is used to clean up the parameter list of
>  * getDeviceAddressRanges() and getPeerAddressRanges().  It's declared
> @@ -58,6 +59,7 @@
>  typedef std::list<Range<Addr> > AddrRangeList;
>  typedef std::list<Range<Addr> >::iterator AddrRangeIter;
>
> +class EventQueue;
>  class MemObject;
>
>  /**
> @@ -71,7 +73,7 @@
>  * Send accessor functions are being called from the device the port is
>  * associated with, and it will call the peer recv. accessor function.
>  */
> -class Port
> +class Port : public EventManager
>  {
>   protected:
>     /** Descriptive name (for DPRINTF output) */
> @@ -86,9 +88,6 @@
>     MemObject *owner;
>
>   public:
> -
> -    Port();
> -
>     /**
>      * Constructor.
>      *
> @@ -97,7 +96,7 @@
>      * @param _owner Pointer to the MemObject that owns this port.
>      * Will not necessarily be set.
>      */
> -    Port(const std::string &_name, MemObject *_owner = NULL);
> +    Port(const std::string &_name, MemObject *_owner);
>
>     /** Return port name (for DPRINTF). */
>     const std::string &name() const { return portName; }
> @@ -121,7 +120,7 @@
>     Port *getPeer() { return peer; }
>
>     /** Function to set the owner of this port. */
> -    void setOwner(MemObject *_owner) { owner = _owner; }
> +    void setOwner(MemObject *_owner);
>
>     /** Function to return the owner of this port. */
>     MemObject *getOwner() { return owner; }
> diff -r 7c58fc1ec5dc -r b194a80157e2 src/python/m5/event.py
> --- a/src/python/m5/event.py    Thu Oct 09 04:58:23 2008 -0700
> +++ b/src/python/m5/event.py    Thu Oct 09 04:58:23 2008 -0700
> @@ -26,17 +26,32 @@
>  #
>  # Authors: Nathan Binkert
>
> -from internal.event import create
> -from internal.event import SimLoopExitEvent as SimExit
> +import internal.event
>
> -class ProgressEvent(object):
> -    def __init__(self, period):
> +from internal.event import PythonEvent, SimLoopExitEvent as SimExit
> +
> +mainq = internal.event.cvar.mainEventQueue
> +
> +def create(obj, priority=None):
> +    if priority is None:
> +        priority = internal.event.Event.Default_Pri
> +    return internal.event.PythonEvent(obj, priority)
> +
> +class Event(PythonEvent):
> +    def __init__(self, priority=None):
> +        if priority is None:
> +            priority = internal.event.Event.Default_Pri
> +        super(PythonEvent, self).__init__(self, priority)
> +
> +class ProgressEvent(Event):
> +    def __init__(self, eventq, period):
> +        super(ProgressEvent, self).__init__()
>         self.period = int(period)
> -        self.schedule()
> -
> -    def schedule(self):
> -        create(self, m5.curTick() + self.period)
> +        self.eventq = eventq
> +        self.eventq.schedule(self, m5.curTick() + self.period)
>
>     def __call__(self):
>         print "Progress! Time now %fs" % (m5.curTick()/1e12)
> -        self.schedule()
> +        self.eventq.schedule(self, m5.curTick() + self.period)
> +
> +__all__ = [ 'create', 'Event', 'ProgressEvent', 'SimExit', 'mainq' ]
> diff -r 7c58fc1ec5dc -r b194a80157e2 src/python/swig/event.i
> --- a/src/python/swig/event.i   Thu Oct 09 04:58:23 2008 -0700
> +++ b/src/python/swig/event.i   Thu Oct 09 04:58:23 2008 -0700
> @@ -32,34 +32,36 @@
>
>  %{
>  #include "python/swig/pyevent.hh"
> -
> +#include "sim/host.hh"
> +#include "sim/eventq.hh"
>  #include "sim/sim_events.hh"
>  #include "sim/sim_exit.hh"
>  #include "sim/simulate.hh"
>  %}
>
> +#pragma SWIG nowarn=350,351
> +
> +%import "base/fast_alloc.hh"
> +%import "sim/serialize.hh"
> +
>  %include "stdint.i"
>  %include "std_string.i"
>  %include "sim/host.hh"
> +%include "sim/eventq.hh"
> +%include "python/swig/pyevent.hh"
>
> -void create(PyObject *object, Tick when);
> -
> -class Event;
> -class CountedDrainEvent : public Event {
> -  public:
> +struct CountedDrainEvent : public Event
> +{
>     void setCount(int _count);
>  };
>
> -CountedDrainEvent *createCountedDrain();
> -void cleanupCountedDrain(Event *drain_event);
> -
>  // minimal definition of SimExitEvent interface to wrap
> -class SimLoopExitEvent {
> +class SimLoopExitEvent : public Event
> +{
>   public:
>     std::string getCause();
>     int getCode();
> -    SimLoopExitEvent(EventQueue *q, Tick _when, Tick _repeat,
> -                     const std::string &_cause, int c = 0);
> +    SimLoopExitEvent(const std::string &_cause, int c, Tick _repeat = 0);
>  };
>
>  %exception simulate {
> diff -r 7c58fc1ec5dc -r b194a80157e2 src/python/swig/pyevent.cc
> --- a/src/python/swig/pyevent.cc        Thu Oct 09 04:58:23 2008 -0700
> +++ b/src/python/swig/pyevent.cc        Thu Oct 09 04:58:23 2008 -0700
> @@ -33,8 +33,8 @@
>  #include "python/swig/pyevent.hh"
>  #include "sim/async.hh"
>
> -PythonEvent::PythonEvent(PyObject *obj, Tick when, Priority priority)
> -    : Event(&mainEventQueue, priority), object(obj)
> +PythonEvent::PythonEvent(PyObject *obj, Priority priority)
> +    : Event(priority), object(obj)
>  {
>     if (object == NULL)
>         panic("Passed in invalid object");
> @@ -42,7 +42,6 @@
>     Py_INCREF(object);
>
>     setFlags(AutoDelete);
> -    schedule(when);
>  }
>
>  PythonEvent::~PythonEvent()
> @@ -67,3 +66,36 @@
>         async_exception = true;
>     }
>  }
> +
> +Event *
> +createCountedDrain()
> +{
> +    return new CountedDrainEvent();
> +}
> +
> +void
> +cleanupCountedDrain(Event *counted_drain)
> +{
> +    CountedDrainEvent *event =
> +        dynamic_cast<CountedDrainEvent *>(counted_drain);
> +    if (event == NULL) {
> +        fatal("Called cleanupCountedDrain() on an event that was not "
> +              "a CountedDrainEvent.");
> +    }
> +    assert(event->getCount() == 0);
> +    delete event;
> +}
> +
> +#if 0
> +Event *
> +create(PyObject *object, Event::Priority priority)
> +{
> +    return new PythonEvent(object, priority);
> +}
> +
> +void
> +destroy(Event *event)
> +{
> +    delete event;
> +}
> +#endif
> diff -r 7c58fc1ec5dc -r b194a80157e2 src/python/swig/pyevent.hh
> --- a/src/python/swig/pyevent.hh        Thu Oct 09 04:58:23 2008 -0700
> +++ b/src/python/swig/pyevent.hh        Thu Oct 09 04:58:23 2008 -0700
> @@ -40,35 +40,13 @@
>     PyObject *object;
>
>   public:
> -    PythonEvent(PyObject *obj, Tick when, Priority priority = Default_Pri);
> +    PythonEvent(PyObject *obj, Event::Priority priority);
>     ~PythonEvent();
>
>     virtual void process();
>  };
>
> -inline void
> -create(PyObject *object, Tick when)
> -{
> -    new PythonEvent(object, when);
> -}
> -
> -inline Event *
> -createCountedDrain()
> -{
> -    return new CountedDrainEvent();
> -}
> -
> -inline void
> -cleanupCountedDrain(Event *counted_drain)
> -{
> -    CountedDrainEvent *event =
> -        dynamic_cast<CountedDrainEvent *>(counted_drain);
> -    if (event == NULL) {
> -        fatal("Called cleanupCountedDrain() on an event that was not "
> -              "a CountedDrainEvent.");
> -    }
> -    assert(event->getCount() == 0);
> -    delete event;
> -}
> +Event *createCountedDrain();
> +void cleanupCountedDrain(Event *counted_drain);
>
>  #endif // __PYTHON_SWIG_PYEVENT_HH__
> diff -r 7c58fc1ec5dc -r b194a80157e2 src/sim/eventq.cc
> --- a/src/sim/eventq.cc Thu Oct 09 04:58:23 2008 -0700
> +++ b/src/sim/eventq.cc Thu Oct 09 04:58:23 2008 -0700
> @@ -51,7 +51,7 @@
> _______________________________________________
> m5-dev mailing list
> [email protected]
> http://m5sim.org/mailman/listinfo/m5-dev
>
>
_______________________________________________
m5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/m5-dev

Reply via email to