gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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("setMaxTick", &set_max_tick, py::arg("tick"));
111  m.def("getMaxTick", &get_max_tick, py::return_value_policy::copy);
112  m.def("terminateEventQueueThreads", &terminateEventQueueThreads);
113  m.def("exitSimLoop", &exitSimLoop);
114  m.def("getEventQueue", []() { return curEventQueue(); },
115  py::return_value_policy::reference);
116  m.def("setEventQueue", [](EventQueue *q) { return curEventQueue(q); });
117  m.def("getEventQueue", &getEventQueue,
118  py::return_value_policy::reference);
119 
120  py::class_<EventQueue>(m, "EventQueue")
121  .def("name", [](EventQueue *eq) { return eq->name(); })
122  .def("dump", &EventQueue::dump)
123  .def("schedule", [](EventQueue *eq, PyEvent *e, Tick t) {
124  eq->schedule(e, t);
125  }, py::arg("event"), py::arg("when"))
126  .def("deschedule", &EventQueue::deschedule,
127  py::arg("event"))
128  .def("reschedule", &EventQueue::reschedule,
129  py::arg("event"), py::arg("tick"), py::arg("always") = false)
130  ;
131 
132  // TODO: Ownership of global exit events has always been a bit
133  // questionable. We currently assume they are owned by the C++
134  // world. This is what the old SWIG code did, but that will result
135  // in memory leaks.
136  py::class_<GlobalSimLoopExitEvent,
137  std::unique_ptr<GlobalSimLoopExitEvent, py::nodelete>>(
138  m, "GlobalSimLoopExitEvent")
139  .def("getCause", &GlobalSimLoopExitEvent::getCause)
140  .def("getCode", &GlobalSimLoopExitEvent::getCode)
141  ;
142 
143  // Event base class. These should never be returned directly to
144  // Python since they don't have a well-defined life cycle. Python
145  // events should be derived from PyEvent instead.
146  py::class_<Event> c_event(
147  m, "Event");
148  c_event
149  .def("name", &Event::name)
150  .def("dump", &Event::dump)
151  .def("scheduled", &Event::scheduled)
152  .def("squash", &Event::squash)
153  .def("squashed", &Event::squashed)
154  .def("isExitEvent", &Event::isExitEvent)
155  .def("when", &Event::when)
156  .def("priority", &Event::priority)
157  ;
158 
159  py::class_<PyEvent, Event>(m, "PyEvent")
160  .def(py::init<Event::Priority>(),
161  py::arg("priority") = (int)Event::Default_Pri)
162  ;
163 
164 #define PRIO(n) c_event.attr(# n) = py::cast((int)Event::n)
165  PRIO(Minimum_Pri);
166  PRIO(Minimum_Pri);
167  PRIO(Debug_Enable_Pri);
168  PRIO(Debug_Break_Pri);
169  PRIO(CPU_Switch_Pri);
170  PRIO(Delayed_Writeback_Pri);
171  PRIO(Default_Pri);
172  PRIO(DVFS_Update_Pri);
173  PRIO(Serialize_Pri);
174  PRIO(CPU_Tick_Pri);
175  PRIO(Stat_Event_Pri);
176  PRIO(Progress_Event_Pri);
177  PRIO(Sim_Exit_Pri);
178  PRIO(Maximum_Pri);
179 }
180 
181 } // namespace gem5
gem5::Event::isExitEvent
bool isExitEvent() const
See if this is a SimExitEvent (without resorting to RTTI)
Definition: eventq.hh:479
gem5::Event::when
Tick when() const
Get the time that the event is scheduled.
Definition: eventq.hh:501
gem5::terminateEventQueueThreads
void terminateEventQueueThreads()
Terminate helper threads when running in parallel mode.
Definition: simulate.cc:269
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:814
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
gem5::set_max_tick
void set_max_tick(Tick tick)
Set the maximum tick.
Definition: simulate.cc:245
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:508
gem5::get_max_tick
Tick get_max_tick()
Get the maximum simulation tick.
Definition: simulate.cc:256
gem5::VegaISA::t
Bitfield< 51 > t
Definition: pagetable.hh:56
gem5::Event
Definition: eventq.hh:254
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:790
gem5::Tick
uint64_t Tick
Tick count type.
Definition: types.hh:58
gem5::EventQueue
Queue of events sorted in time order.
Definition: eventq.hh:615
gem5::EventBase::Managed
static const FlagsType Managed
Definition: eventq.hh:109
gem5::PyEvent
PyBind wrapper for Events.
Definition: event.cc:67
gem5::simulate
GlobalSimLoopExitEvent * simulate(Tick num_cycles)
Definition: simulate.cc:188
gem5::ArmISA::q
Bitfield< 27 > q
Definition: misc_types.hh:55
gem5::curEventQueue
EventQueue * curEventQueue()
Definition: eventq.hh:91
gem5::PowerISA::eq
Bitfield< 29 > eq
Definition: misc.hh:58
gem5::EventBase::Priority
int8_t Priority
Definition: eventq.hh:126
gem5::Event::squashed
bool squashed() const
Check whether the event is squashed.
Definition: eventq.hh:472
gem5::PyEvent::process
void process() override
Definition: event.cc:75
logging.hh
gem5::Event::squash
void squash()
Squash the current event.
Definition: eventq.hh:465
gem5::EventBase::Default_Pri
static const Priority Default_Pri
Default is zero for historical reasons.
Definition: eventq.hh:182
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:458
gem5::Event::dump
void dump() const
Dump the current event data.
Definition: eventq.cc:427
gem5::EventQueue::dump
void dump() const
This is a debugging function which will print everything on the event queue.
Definition: eventq.cc:315
panic
#define panic(...)
This implements a cprintf based panic() function.
Definition: logging.hh:188
PRIO
#define PRIO(n)
eventq.hh

Generated on Sun Jul 30 2023 01:56:59 for gem5 by doxygen 1.8.17