event.py revision 11802
14167Sbinkertn@umich.edu# Copyright (c) 2006 The Regents of The University of Michigan
29983Sstever@gmail.com# Copyright (c) 2013 Advanced Micro Devices, Inc.
39983Sstever@gmail.com# Copyright (c) 2013 Mark D. Hill and David A. Wood
44167Sbinkertn@umich.edu# All rights reserved.
54167Sbinkertn@umich.edu#
64167Sbinkertn@umich.edu# Redistribution and use in source and binary forms, with or without
74167Sbinkertn@umich.edu# modification, are permitted provided that the following conditions are
84167Sbinkertn@umich.edu# met: redistributions of source code must retain the above copyright
94167Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer;
104167Sbinkertn@umich.edu# redistributions in binary form must reproduce the above copyright
114167Sbinkertn@umich.edu# notice, this list of conditions and the following disclaimer in the
124167Sbinkertn@umich.edu# documentation and/or other materials provided with the distribution;
134167Sbinkertn@umich.edu# neither the name of the copyright holders nor the names of its
144167Sbinkertn@umich.edu# contributors may be used to endorse or promote products derived from
154167Sbinkertn@umich.edu# this software without specific prior written permission.
164167Sbinkertn@umich.edu#
174167Sbinkertn@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
184167Sbinkertn@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
194167Sbinkertn@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
204167Sbinkertn@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
214167Sbinkertn@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
224167Sbinkertn@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
234167Sbinkertn@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
244167Sbinkertn@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
254167Sbinkertn@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
264167Sbinkertn@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
274167Sbinkertn@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
284167Sbinkertn@umich.edu#
294167Sbinkertn@umich.edu# Authors: Nathan Binkert
304167Sbinkertn@umich.edu
315696Snate@binkert.orgimport m5
3211802Sandreas.sandberg@arm.comimport _m5.event
334167Sbinkertn@umich.edu
3411802Sandreas.sandberg@arm.comfrom _m5.event import PythonEvent, GlobalSimLoopExitEvent as SimExit
355605Snate@binkert.org
369983Sstever@gmail.commainq = None
375605Snate@binkert.org
385605Snate@binkert.orgdef create(obj, priority=None):
395605Snate@binkert.org    if priority is None:
405879Snate@binkert.org        priority = Event.Default_Pri
415738Snate@binkert.org    return PythonEvent(obj, priority)
425605Snate@binkert.org
435879Snate@binkert.org
445879Snate@binkert.org# As a reminder, priorities found in sim/eventq.hh are stuck into the
455879Snate@binkert.org# Event class by swig
465605Snate@binkert.orgclass Event(PythonEvent):
475605Snate@binkert.org    def __init__(self, priority=None):
485605Snate@binkert.org        if priority is None:
495879Snate@binkert.org            priority = Event.Default_Pri
505696Snate@binkert.org        super(Event, self).__init__(self, priority)
515605Snate@binkert.org
525605Snate@binkert.orgclass ProgressEvent(Event):
535605Snate@binkert.org    def __init__(self, eventq, period):
545605Snate@binkert.org        super(ProgressEvent, self).__init__()
554167Sbinkertn@umich.edu        self.period = int(period)
565605Snate@binkert.org        self.eventq = eventq
575605Snate@binkert.org        self.eventq.schedule(self, m5.curTick() + self.period)
584167Sbinkertn@umich.edu
594167Sbinkertn@umich.edu    def __call__(self):
604167Sbinkertn@umich.edu        print "Progress! Time now %fs" % (m5.curTick()/1e12)
615605Snate@binkert.org        self.eventq.schedule(self, m5.curTick() + self.period)
625605Snate@binkert.org
639983Sstever@gmail.comdef getEventQueue(index):
6411802Sandreas.sandberg@arm.com    return _m5.event.getEventQueue(index)
659983Sstever@gmail.com
669983Sstever@gmail.comdef setEventQueue(eventq):
6711802Sandreas.sandberg@arm.com    _m5.event.curEventQueue(eventq)
689983Sstever@gmail.com
695605Snate@binkert.org__all__ = [ 'create', 'Event', 'ProgressEvent', 'SimExit', 'mainq' ]
70