gem5  v22.0.0.2
event.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017, 2021 Arm Limited
3  * All rights reserved
4  *
5  * The license below extends only to copyright in the software and shall
6  * not be construed as granting a license to any other intellectual
7  * property including but not limited to intellectual property relating
8  * to a hardware implementation of the functionality of the software
9  * licensed hereunder. You may use the software subject to the license
10  * terms below provided that you ensure that this notice is replicated
11  * unmodified and in its entirety in all distributions of the software,
12  * modified or unmodified, in source code or in binary form.
13  *
14  * Copyright (c) 2006 The Regents of The University of Michigan
15  * Copyright (c) 2013 Advanced Micro Devices, Inc.
16  * Copyright (c) 2013 Mark D. Hill and David A. Wood
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms, with or without
20  * modification, are permitted provided that the following conditions are
21  * met: redistributions of source code must retain the above copyright
22  * notice, this list of conditions and the following disclaimer;
23  * redistributions in binary form must reproduce the above copyright
24  * notice, this list of conditions and the following disclaimer in the
25  * documentation and/or other materials provided with the distribution;
26  * neither the name of the copyright holders nor the names of its
27  * contributors may be used to endorse or promote products derived from
28  * this software without specific prior written permission.
29  *
30  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41  */
42 
43 #include "pybind11/pybind11.h"
44 #include "pybind11/stl.h"
45 
46 #include "base/logging.hh"
47 #include "sim/eventq.hh"
48 #include "sim/sim_events.hh"
49 #include "sim/sim_exit.hh"
50 #include "sim/simulate.hh"
51 
52 namespace py = pybind11;
53 
54 namespace gem5
55 {
56 
67 class PyEvent : public Event
68 {
69  public:
72  {
73  }
74 
75  void process() override {
76  // Call the Python implementation as __call__. This provides a
77  // slightly more Python-friendly interface.
78  PYBIND11_OVERLOAD_PURE_NAME(void, PyEvent, "__call__", process);
79  }
80 
81  protected:
82  void acquireImpl() override {
83  py::object obj = py::cast(this);
84 
85  if (obj) {
86  obj.inc_ref();
87  } else {
88  panic("Failed to get PyBind object to increase ref count\n");
89  }
90  }
91 
92  void releaseImpl() override {
93  py::object obj = py::cast(this);
94 
95  if (obj) {
96  obj.dec_ref();
97  } else {
98  panic("Failed to get PyBind object to decrease ref count\n");
99  }
100  }
101 };
102 
103 void
104 pybind_init_event(py::module_ &m_native)
105 {
106  py::module_ m = m_native.def_submodule("event");
107 
108  m.def("simulate", &simulate,
109  py::arg("ticks") = MaxTick);
110  m.def("terminateEventQueueThreads", &terminateEventQueueThreads);
111  m.def("exitSimLoop", &exitSimLoop);
112  m.def("getEventQueue", []() { return curEventQueue(); },
113  py::return_value_policy::reference);
114  m.def("setEventQueue", [](EventQueue *q) { return curEventQueue(q); });
115  m.def("getEventQueue", &getEventQueue,
116  py::return_value_policy::reference);
117 
118  py::class_<EventQueue>(m, "EventQueue")
119  .def("name", [](EventQueue *eq) { return eq->name(); })
120  .def("dump", &EventQueue::dump)
121  .def("schedule", [](EventQueue *eq, PyEvent *e, Tick t) {
122  eq->schedule(e, t);
123  }, py::arg("event"), py::arg("when"))
124  .def("deschedule", &EventQueue::deschedule,
125  py::arg("event"))
126  .def("reschedule", &EventQueue::reschedule,
127  py::arg("event"), py::arg("tick"), py::arg("always") = false)
128  ;
129 
130  // TODO: Ownership of global exit events has always been a bit
131  // questionable. We currently assume they are owned by the C++
132  // world. This is what the old SWIG code did, but that will result
133  // in memory leaks.
134  py::class_<GlobalSimLoopExitEvent,
135  std::unique_ptr<GlobalSimLoopExitEvent, py::nodelete>>(
136  m, "GlobalSimLoopExitEvent")
137  .def("getCause", &GlobalSimLoopExitEvent::getCause)
138  .def("getCode", &GlobalSimLoopExitEvent::getCode)
139  ;
140 
141  // Event base class. These should never be returned directly to
142  // Python since they don't have a well-defined life cycle. Python
143  // events should be derived from PyEvent instead.
144  py::class_<Event> c_event(
145  m, "Event");
146  c_event
147  .def("name", &Event::name)
148  .def("dump", &Event::dump)
149  .def("scheduled", &Event::scheduled)
150  .def("squash", &Event::squash)
151  .def("squashed", &Event::squashed)
152  .def("isExitEvent", &Event::isExitEvent)
153  .def("when", &Event::when)
154  .def("priority", &Event::priority)
155  ;
156 
157  py::class_<PyEvent, Event>(m, "PyEvent")
158  .def(py::init<Event::Priority>(),
159  py::arg("priority") = (int)Event::Default_Pri)
160  ;
161 
162 #define PRIO(n) c_event.attr(# n) = py::cast((int)Event::n)
163  PRIO(Minimum_Pri);
164  PRIO(Minimum_Pri);
165  PRIO(Debug_Enable_Pri);
166  PRIO(Debug_Break_Pri);
167  PRIO(CPU_Switch_Pri);
168  PRIO(Delayed_Writeback_Pri);
169  PRIO(Default_Pri);
170  PRIO(DVFS_Update_Pri);
171  PRIO(Serialize_Pri);
172  PRIO(CPU_Tick_Pri);
173  PRIO(Stat_Event_Pri);
174  PRIO(Progress_Event_Pri);
175  PRIO(Sim_Exit_Pri);
176  PRIO(Maximum_Pri);
177 }
178 
179 } // namespace gem5
gem5::Event::isExitEvent
bool isExitEvent() const
See if this is a SimExitEvent (without resorting to RTTI)
Definition: eventq.hh:486
gem5::Event::when
Tick when() const
Get the time that the event is scheduled.
Definition: eventq.hh:508
gem5::terminateEventQueueThreads
void terminateEventQueueThreads()
Terminate helper threads when running in parallel mode.
Definition: simulate.cc:235
gem5::Event::name
virtual const std::string name() const
Definition: eventq.cc:84
gem5::VegaISA::m
m
Definition: pagetable.hh:52
gem5::pybind_init_event
void pybind_init_event(py::module_ &m_native)
Definition: event.cc:104
sim_events.hh
gem5::PyEvent::PyEvent
PyEvent(Event::Priority priority)
Definition: event.cc:70
simulate.hh
gem5::getEventQueue
EventQueue * getEventQueue(uint32_t index)
Function for returning eventq queue for the provided index.
Definition: eventq.cc:62
gem5::GlobalSimLoopExitEvent::getCode
int getCode() const
Definition: sim_events.hh:69
gem5::EventQueue::reschedule
void reschedule(Event *event, Tick when, bool always=false)
Reschedule the specified event.
Definition: eventq.hh:821
gem5::ArmISA::e
Bitfield< 9 > e
Definition: misc_types.hh:65
gem5::MaxTick
const Tick MaxTick
Definition: types.hh:60
gem5::PyEvent::acquireImpl
void acquireImpl() override
Definition: event.cc:82
gem5::GlobalSimLoopExitEvent
Definition: sim_events.hh:55
sim_exit.hh
gem5::exitSimLoop
void exitSimLoop(const std::string &message, int exit_code, Tick when, Tick repeat, bool serialize)
Schedule an event to exit the simulation loop (returning to Python) at the end of the current cycle (...
Definition: sim_events.cc:88
gem5::Event::priority
Priority priority() const
Get the event priority.
Definition: eventq.hh:515
gem5::VegaISA::t
Bitfield< 51 > t
Definition: pagetable.hh:56
gem5::Event
Definition: eventq.hh:251
gem5::GlobalSimLoopExitEvent::getCause
const std::string getCause() const
Definition: sim_events.hh:68
gem5::EventQueue::deschedule
void deschedule(Event *event)
Deschedule the specified event.
Definition: eventq.hh:797
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::EventQueue
Queue of events sorted in time order.
Definition: eventq.hh:622
gem5::EventBase::Managed
static const FlagsType Managed
Definition: eventq.hh:106
gem5::PyEvent
PyBind wrapper for Events.
Definition: event.cc:67
gem5::simulate
GlobalSimLoopExitEvent * simulate(Tick num_cycles)
Simulate for num_cycles additional cycles.
Definition: simulate.cc:188
gem5::ArmISA::q
Bitfield< 27 > q
Definition: misc_types.hh:55
gem5::curEventQueue
EventQueue * curEventQueue()
Definition: eventq.hh:88
gem5::PowerISA::eq
Bitfield< 29 > eq
Definition: misc.hh:53
gem5::EventBase::Priority
int8_t Priority
Definition: eventq.hh:123
gem5::Event::squashed
bool squashed() const
Check whether the event is squashed.
Definition: eventq.hh:479
gem5::PyEvent::process
void process() override
Definition: event.cc:75
logging.hh
gem5::Event::squash
void squash()
Squash the current event.
Definition: eventq.hh:472
gem5::EventBase::Default_Pri
static const Priority Default_Pri
Default is zero for historical reasons.
Definition: eventq.hh:179
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::PyEvent::releaseImpl
void releaseImpl() override
Definition: event.cc:92
gem5::Event::scheduled
bool scheduled() const
Determine if the current event is scheduled.
Definition: eventq.hh:465
gem5::Event::dump
void dump() const
Dump the current event data.
Definition: eventq.cc:401
gem5::EventQueue::dump
void dump() const
This is a debugging function which will print everything on the event queue.
Definition: eventq.cc:289
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:178
PRIO
#define PRIO(n)
eventq.hh

Generated on Thu Jul 28 2022 13:32:36 for gem5 by doxygen 1.8.17