42#include "pybind11/operators.h"
43#include "pybind11/pybind11.h"
44#include "pybind11/stl.h"
63namespace py = pybind11;
80 py::module_
m = py::module_::import(
"m5.SimObject");
81 auto f =
m.attr(
"resolveSimObject");
92 py::module_
m = m_native.def_submodule(
"drain");
94 py::enum_<DrainState>(
m,
"DrainState")
100 py::class_<Drainable, std::unique_ptr<Drainable, py::nodelete>>(
108 py::class_<DrainManager, std::unique_ptr<DrainManager, py::nodelete>>(
117 py::return_value_policy::reference)
124 py::module_
m = m_native.def_submodule(
"serialize");
126 py::class_<Serializable, std::unique_ptr<Serializable, py::nodelete>>(
130 py::class_<CheckpointIn>(
m,
"CheckpointIn")
137 py::module_
m = m_native.def_submodule(
"range");
139 py::class_<AddrRange>(
m,
"AddrRange")
141 .def(py::init<Addr &, Addr &>())
144 .def(py::init<Addr, Addr, uint8_t, uint8_t, uint8_t, uint8_t>())
170 py::module_
m = m_native.def_submodule(
"pc");
171 py::class_<PcCountPair>(
m,
"PcCountPair")
173 .def(py::init<Addr, int>())
174 .def(
"__eq__", [](
const PcCountPair& self, py::object other) {
175 py::int_ pyPC = other.attr(
"get_pc")();
176 py::int_ pyCount = other.attr(
"get_count")();
177 uint64_t cPC = pyPC.cast<uint64_t>();
178 int cCount = pyCount.cast<
int>();
182 py::int_ pyPC = py::cast(self.
getPC());
183 py::int_ pyCount = py::cast(self.
getCount());
184 return py::hash(py::make_tuple(pyPC, pyCount));
195 py::module_
m = m_native.def_submodule(
"net");
197 py::class_<networking::EthAddr>(
m,
"EthAddr")
199 .def(py::init<const std::string &>())
202 py::class_<networking::IpAddress>(
m,
"IpAddress")
204 .def(py::init<uint32_t>())
207 py::class_<networking::IpNetmask, networking::IpAddress>(
m,
"IpNetmask")
209 .def(py::init<uint32_t, uint8_t>())
212 py::class_<networking::IpWithPort, networking::IpAddress>(
m,
"IpWithPort")
214 .def(py::init<uint32_t, uint16_t>())
221 py::module_
m = m_native.def_submodule(
"loader");
229 py::module_ m_socket = m_native.def_submodule(
"socket");
234 .def(
"listenSocketUnixAbstractConfig",
237 py::class_<ListenSocketConfig>(m_socket,
"ListenSocketConfig");
243 py::module_ m_core = m_native.def_submodule(
"core");
245 py::class_<Cycles>(m_core,
"Cycles")
247 .def(py::init<uint64_t>())
248 .def(
"__int__", &Cycles::operator uint64_t)
249 .def(
"__add__", &Cycles::operator+)
250 .def(
"__sub__", &Cycles::operator-)
253 py::class_<Temperature>(m_core,
"Temperature")
255 .def(py::init<double>())
262 .def(py::self == py::self)
263 .def(py::self != py::self)
264 .def(py::self < py::self)
265 .def(py::self <= py::self)
266 .def(py::self > py::self)
267 .def(py::self >= py::self)
268 .def(py::self + py::self)
269 .def(py::self - py::self)
270 .def(py::self *
float())
271 .def(
float() * py::self)
272 .def(py::self /
float())
280 s <<
"Temperature(" <<
t.toKelvin() <<
")";
285 py::class_<tm>(m_core,
"tm")
286 .def_static(
"gmtime", [](std::time_t
t) {
return *std::gmtime(&
t); })
287 .def_readwrite(
"tm_sec", &tm::tm_sec)
288 .def_readwrite(
"tm_min", &tm::tm_min)
289 .def_readwrite(
"tm_hour", &tm::tm_hour)
290 .def_readwrite(
"tm_mday", &tm::tm_mday)
291 .def_readwrite(
"tm_mon", &tm::tm_mon)
292 .def_readwrite(
"tm_wday", &tm::tm_wday)
293 .def_readwrite(
"tm_yday", &tm::tm_yday)
294 .def_readwrite(
"tm_isdst", &tm::tm_isdst)
297 py::enum_<Logger::LogLevel>(m_core,
"LogLevel")
313 .def(
"seedRandom", [](uint64_t seed) {
random_mt.
init(seed); })
325 m_core.attr(
"compileDate") = py::cast(
compileDate);
326 m_core.attr(
"gem5Version") = py::cast(
gem5Version);
328 m_core.attr(
"TRACING_ON") = py::cast(TRACING_ON);
330 m_core.attr(
"MaxTick") = py::cast(
MaxTick);
337 .def(
"getCheckpoint", [](
const std::string &cpt_dir) {
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,...
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
static DrainManager & instance()
Get the singleton DrainManager instance.
static void loopbackOnly()
static bool allDisabled()
static void setLevel(LogLevel ll)
constexpr Addr getPC() const
Returns the Program Counter address.
std::string to_string() const
String format.
constexpr int getCount() const
Returns the count of the Program.
Resolve a SimObject name using the Pybind configuration.
SimObject * resolveSimObject(const std::string &name)
Find a SimObject given a full path name.
Base class to wrap object resolving functionality.
Abstract superclass for simulation objects.
static void serializeAll(const std::string &cpt_dir)
Create a checkpoint by serializing all SimObjects in the system.
static void setSimObjectResolver(SimObjectResolver *resolver)
There is a single object name resolver, and it is only set when simulation is restoring from checkpoi...
The class stores temperatures in Kelvin and provides helper methods to convert to/from Celsius.
double toFahrenheit() const
static Temperature fromCelsius(double _value)
constexpr double toKelvin() const
constexpr double toCelsius() const
static Temperature fromFahrenheit(double _value)
static Temperature fromKelvin(double _value)
bool interleaved() const
Determine if the range is interleaved or not.
bool isSubset(const AddrRange &r) const
Determine if this range is a subset of another range, i.e.
AddrRange RangeEx(Addr start, Addr end)
AddrRange RangeSize(Addr start, Addr size)
uint64_t granularity() const
Determing the interleaving granularity of the range.
AddrRange RangeIn(Addr start, Addr end)
AddrRangeList exclude(const AddrRangeList &exclude_ranges) const
Subtract a list of intervals from the range and return the resulting collection of ranges,...
uint32_t stripes() const
Determine the number of interleaved address stripes this range is part of.
bool valid() const
Determine if the range is valid.
bool intersects(const AddrRange &r) const
Determine if another range intersects this one, i.e.
Addr end() const
Get the end address of the range.
bool mergesWith(const AddrRange &r) const
Determine if another range merges with the current one, i.e.
Addr start() const
Get the start address of the range.
Addr size() const
Get the size of the address range.
std::string to_string() const
Get a string representation of the range.
void preCheckpointRestore()
Run state fixups before a checkpoint restore operation.
DrainState state() const
Get the simulators global drain state.
void signalDrainDone()
Notify the DrainManager that a Drainable object has finished draining.
virtual void notifyFork()
Notify a child process of a fork.
void resume()
Resume normal simulation in a Drained system.
DrainState drainState() const
Return the current drain state of an object.
bool isDrained() const
Check if the system is drained.
bool tryDrain()
Try to drain the system.
@ Draining
Draining buffers pending serialization/handover.
@ Running
Running normally.
@ Drained
Buffers drained, ready for serialization/handover.
void setInterpDir(const std::string &dirname)
This is the interface for setting up a base path for the elf interpreter.
Copyright (c) 2024 - Pranith Kumar Copyright (c) 2020 Inria All rights reserved.
static void init_pc(py::module_ &m_native)
static void init_drain(py::module_ &m_native)
ListenSocketConfig listenSocketUnixAbstractConfig(std::string path)
Tick curTick()
The universal simulation clock.
void pybind_init_core(py::module_ &m_native)
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
ListenSocketConfig listenSocketInetConfig(int port)
bool clockFrequencyFixed()
static void init_loader(py::module_ &m_native)
void setOutputDir(const std::string &dir)
PybindSimObjectResolver pybindSimObjectResolver
void setClockFrequency(Tick tps)
void doExitCleanup()
Do C++ simulator exit processing.
static void init_net(py::module_ &m_native)
ListenSocketConfig listenSocketUnixFileConfig(std::string dir, std::string fname)
static void init_serialize(py::module_ &m_native)
static ListenSocketConfig listenSocketEmptyConfig()
static void init_socket(py::module_ &m_native)
static void init_range(py::module_ &m_native)
const std::string & name()