gem5 v24.0.0.0
Loading...
Searching...
No Matches
core.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017, 2019, 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) 2010 Advanced Micro Devices, Inc.
15 * Copyright (c) 2006 The Regents of The University of Michigan
16 * All rights reserved.
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met: redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer;
22 * redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution;
25 * neither the name of the copyright holders nor the names of its
26 * contributors may be used to endorse or promote products derived from
27 * this software without specific prior written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 */
41
42#include "pybind11/operators.h"
43#include "pybind11/pybind11.h"
44#include "pybind11/stl.h"
45
46#include <ctime>
47
48#include "base/addr_range.hh"
49#include "base/inet.hh"
51#include "base/logging.hh"
52#include "base/random.hh"
53#include "base/socket.hh"
54#include "base/temperature.hh"
55#include "base/types.hh"
56#include "sim/core.hh"
57#include "sim/cur_tick.hh"
58#include "sim/drain.hh"
59#include "sim/serialize.hh"
60#include "sim/sim_object.hh"
62
63namespace py = pybind11;
64
65namespace gem5
66{
67
70{
71 SimObject *resolveSimObject(const std::string &name);
72};
73
75
78{
79 // TODO
80 py::module_ m = py::module_::import("m5.SimObject");
81 auto f = m.attr("resolveSimObject");
82
83 return f(name).cast<SimObject *>();
84}
85
86extern const char *compileDate;
87extern const char *gem5Version;
88
89static void
90init_drain(py::module_ &m_native)
91{
92 py::module_ m = m_native.def_submodule("drain");
93
94 py::enum_<DrainState>(m, "DrainState")
95 .value("Running", DrainState::Running)
96 .value("Draining", DrainState::Draining)
97 .value("Drained", DrainState::Drained)
98 ;
99
100 py::class_<Drainable, std::unique_ptr<Drainable, py::nodelete>>(
101 m, "Drainable")
102 .def("drainState", &Drainable::drainState)
103 .def("notifyFork", &Drainable::notifyFork)
104 ;
105
106 // The drain manager is a singleton with a private
107 // destructor. Disable deallocation from the Python binding.
108 py::class_<DrainManager, std::unique_ptr<DrainManager, py::nodelete>>(
109 m, "DrainManager")
110 .def("tryDrain", &DrainManager::tryDrain)
111 .def("resume", &DrainManager::resume)
112 .def("preCheckpointRestore", &DrainManager::preCheckpointRestore)
113 .def("isDrained", &DrainManager::isDrained)
114 .def("state", &DrainManager::state)
115 .def("signalDrainDone", &DrainManager::signalDrainDone)
116 .def_static("instance", &DrainManager::instance,
117 py::return_value_policy::reference)
118 ;
119}
120
121static void
122init_serialize(py::module_ &m_native)
123{
124 py::module_ m = m_native.def_submodule("serialize");
125
126 py::class_<Serializable, std::unique_ptr<Serializable, py::nodelete>>(
127 m, "Serializable")
128 ;
129
130 py::class_<CheckpointIn>(m, "CheckpointIn")
131 ;
132}
133
134static void
135init_range(py::module_ &m_native)
136{
137 py::module_ m = m_native.def_submodule("range");
138
139 py::class_<AddrRange>(m, "AddrRange")
140 .def(py::init<>())
141 .def(py::init<Addr &, Addr &>())
142 .def(py::init<Addr, Addr, const std::vector<Addr> &, uint8_t>())
143 .def(py::init<const std::vector<AddrRange> &>())
144 .def(py::init<Addr, Addr, uint8_t, uint8_t, uint8_t, uint8_t>())
145
146 .def("__str__", &AddrRange::to_string)
147
148 .def("interleaved", &AddrRange::interleaved)
149 .def("granularity", &AddrRange::granularity)
150 .def("stripes", &AddrRange::stripes)
151 .def("size", &AddrRange::size)
152 .def("valid", &AddrRange::valid)
153 .def("start", &AddrRange::start)
154 .def("end", &AddrRange::end)
155 .def("mergesWith", &AddrRange::mergesWith)
156 .def("intersects", &AddrRange::intersects)
157 .def("isSubset", &AddrRange::isSubset)
158 .def("exclude", static_cast<AddrRangeList (AddrRange::*)(
159 const AddrRangeList &) const>(&AddrRange::exclude))
160 ;
161
162 m.def("RangeEx", &RangeEx);
163 m.def("RangeIn", &RangeIn);
164 m.def("RangeSize", &RangeSize);
165}
166
167static void
168init_pc(py::module_ &m_native)
169{
170 py::module_ m = m_native.def_submodule("pc");
171 py::class_<PcCountPair>(m, "PcCountPair")
172 .def(py::init<>())
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>();
179 return (self.getPC() == cPC && self.getCount() == cCount);
180 })
181 .def("__hash__", [](const PcCountPair& self){
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));
185 })
186 .def("__str__", &PcCountPair::to_string)
187 .def("get_pc", &PcCountPair::getPC)
188 .def("get_count", &PcCountPair::getCount)
189 ;
190}
191
192static void
193init_net(py::module_ &m_native)
194{
195 py::module_ m = m_native.def_submodule("net");
196
197 py::class_<networking::EthAddr>(m, "EthAddr")
198 .def(py::init<>())
199 .def(py::init<const std::string &>())
200 ;
201
202 py::class_<networking::IpAddress>(m, "IpAddress")
203 .def(py::init<>())
204 .def(py::init<uint32_t>())
205 ;
206
207 py::class_<networking::IpNetmask, networking::IpAddress>(m, "IpNetmask")
208 .def(py::init<>())
209 .def(py::init<uint32_t, uint8_t>())
210 ;
211
212 py::class_<networking::IpWithPort, networking::IpAddress>(m, "IpWithPort")
213 .def(py::init<>())
214 .def(py::init<uint32_t, uint16_t>())
215 ;
216}
217
218static void
219init_loader(py::module_ &m_native)
220{
221 py::module_ m = m_native.def_submodule("loader");
222
223 m.def("setInterpDir", &loader::setInterpDir);
224}
225
226static void
227init_socket(py::module_ &m_native)
228{
229 py::module_ m_socket = m_native.def_submodule("socket");
230 m_socket
231 .def("listenSocketEmptyConfig", &listenSocketEmptyConfig)
232 .def("listenSocketInetConfig", &listenSocketInetConfig)
233 .def("listenSocketUnixFileConfig", &listenSocketUnixFileConfig)
234 .def("listenSocketUnixAbstractConfig",
236
237 py::class_<ListenSocketConfig>(m_socket, "ListenSocketConfig");
238}
239
240void
241pybind_init_core(py::module_ &m_native)
242{
243 py::module_ m_core = m_native.def_submodule("core");
244
245 py::class_<Cycles>(m_core, "Cycles")
246 .def(py::init<>())
247 .def(py::init<uint64_t>())
248 .def("__int__", &Cycles::operator uint64_t)
249 .def("__add__", &Cycles::operator+)
250 .def("__sub__", &Cycles::operator-)
251 ;
252
253 py::class_<Temperature>(m_core, "Temperature")
254 .def(py::init<>())
255 .def(py::init<double>())
256 .def_static("from_celsius", &Temperature::fromCelsius)
257 .def_static("from_kelvin", &Temperature::fromKelvin)
258 .def_static("from_fahrenheit", &Temperature::fromFahrenheit)
259 .def("celsius", &Temperature::toCelsius)
260 .def("kelvin", &Temperature::toKelvin)
261 .def("fahrenheit", &Temperature::toFahrenheit)
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())
273 .def("__str__", [](const Temperature &t) {
274 std::stringstream s;
275 s << t;
276 return s.str();
277 })
278 .def("__repr__", [](const Temperature &t) {
279 std::stringstream s;
280 s << "Temperature(" << t.toKelvin() << ")";
281 return s.str();
282 })
283 ;
284
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)
295 ;
296
297 py::enum_<Logger::LogLevel>(m_core, "LogLevel")
298 .value("PANIC", Logger::PANIC)
299 .value("FATAL", Logger::FATAL)
300 .value("WARN", Logger::WARN)
301 .value("INFO", Logger::INFO)
302 .value("HACK", Logger::HACK)
303 ;
304
305 m_core
306 .def("setLogLevel", &Logger::setLevel)
307 .def("setOutputDir", &setOutputDir)
308 .def("doExitCleanup", &doExitCleanup)
309
310 .def("disableAllListeners", &ListenSocket::disableAll)
311 .def("listenersDisabled", &ListenSocket::allDisabled)
312 .def("listenersLoopbackOnly", &ListenSocket::loopbackOnly)
313 .def("seedRandom", [](uint64_t seed) { random_mt.init(seed); })
314
315
316 .def("fixClockFrequency", &fixClockFrequency)
317 .def("clockFrequencyFixed", &clockFrequencyFixed)
318
319 .def("setClockFrequency", &setClockFrequency)
320 .def("getClockFrequency", &getClockFrequency)
321 .def("curTick", curTick)
322 ;
323
324 /* TODO: These should be read-only */
325 m_core.attr("compileDate") = py::cast(compileDate);
326 m_core.attr("gem5Version") = py::cast(gem5Version);
327
328 m_core.attr("TRACING_ON") = py::cast(TRACING_ON);
329
330 m_core.attr("MaxTick") = py::cast(MaxTick);
331
332 /*
333 * Serialization helpers
334 */
335 m_core
336 .def("serializeAll", &SimObject::serializeAll)
337 .def("getCheckpoint", [](const std::string &cpt_dir) {
339 return new CheckpointIn(cpt_dir);
340 })
341
342 ;
343
344
345 init_drain(m_native);
346 init_serialize(m_native);
347 init_range(m_native);
348 init_net(m_native);
349 init_loader(m_native);
350 init_pc(m_native);
351 init_socket(m_native);
352}
353
354} // namespace gem5
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...
Definition addr_range.hh:82
static DrainManager & instance()
Get the singleton DrainManager instance.
Definition drain.hh:91
static void loopbackOnly()
Definition socket.cc:96
static bool allDisabled()
Definition socket.cc:90
static void disableAll()
Definition socket.cc:82
static void setLevel(LogLevel ll)
Definition logging.hh:74
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.
Definition core.cc:70
SimObject * resolveSimObject(const std::string &name)
Find a SimObject given a full path name.
Definition core.cc:77
void init(uint32_t s)
Definition random.cc:67
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)
STL vector class.
Definition stl.hh:37
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.
const char * gem5Version
Definition version.cc:35
Random random_mt
Definition random.cc:99
const char * compileDate
Definition date.cc:35
void preCheckpointRestore()
Run state fixups before a checkpoint restore operation.
Definition drain.cc:135
DrainState state() const
Get the simulators global drain state.
Definition drain.hh:152
void signalDrainDone()
Notify the DrainManager that a Drainable object has finished draining.
Definition drain.cc:149
virtual void notifyFork()
Notify a child process of a fork.
Definition drain.hh:344
void resume()
Resume normal simulation in a Drained system.
Definition drain.cc:96
DrainState drainState() const
Return the current drain state of an object.
Definition drain.hh:324
bool isDrained() const
Check if the system is drained.
Definition drain.hh:145
bool tryDrain()
Try to drain the system.
Definition drain.cc:64
@ Draining
Draining buffers pending serialization/handover.
@ Running
Running normally.
@ Drained
Buffers drained, ready for serialization/handover.
Bitfield< 5 > t
Definition misc_types.hh:71
Bitfield< 4 > s
Bitfield< 6 > f
Definition misc_types.hh:68
Bitfield< 0 > m
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.
Definition binary32.hh:36
Tick getClockFrequency()
Definition core.cc:121
static void init_pc(py::module_ &m_native)
Definition core.cc:168
static void init_drain(py::module_ &m_native)
Definition core.cc:90
ListenSocketConfig listenSocketUnixAbstractConfig(std::string path)
Definition socket.cc:400
Tick curTick()
The universal simulation clock.
Definition cur_tick.hh:46
void pybind_init_core(py::module_ &m_native)
Definition core.cc:241
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition types.hh:147
ListenSocketConfig listenSocketInetConfig(int port)
Definition socket.cc:260
bool clockFrequencyFixed()
Definition core.cc:112
void fixClockFrequency()
Definition core.cc:84
static void init_loader(py::module_ &m_native)
Definition core.cc:219
const Tick MaxTick
Definition types.hh:60
void setOutputDir(const std::string &dir)
Definition core.cc:124
PybindSimObjectResolver pybindSimObjectResolver
Definition core.cc:74
void setClockFrequency(Tick tps)
Definition core.cc:115
void doExitCleanup()
Do C++ simulator exit processing.
Definition core.cc:153
static void init_net(py::module_ &m_native)
Definition core.cc:193
ListenSocketConfig listenSocketUnixFileConfig(std::string dir, std::string fname)
Definition socket.cc:370
static void init_serialize(py::module_ &m_native)
Definition core.cc:122
static ListenSocketConfig listenSocketEmptyConfig()
Definition socket.hh:137
static void init_socket(py::module_ &m_native)
Definition core.cc:227
static void init_range(py::module_ &m_native)
Definition core.cc:135
const std::string & name()
Definition trace.cc:48

Generated on Tue Jun 18 2024 16:24:05 for gem5 by doxygen 1.11.0