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.
This commit is contained in:
@@ -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' ]
|
||||
|
||||
Reference in New Issue
Block a user