gem5  [DEVELOP-FOR-23.0]
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
63 namespace py = pybind11;
64 
65 namespace gem5
66 {
67 
70 {
71  SimObject *resolveSimObject(const std::string &name);
72 };
73 
75 
76 SimObject *
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 
86 extern const char *compileDate;
87 extern const char *gem5Version;
88 
89 static void
90 init_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 
121 static void
122 init_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 
134 static void
135 init_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 
167 static void
168 init_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 
192 static void
193 init_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 
218 static void
219 init_loader(py::module_ &m_native)
220 {
221  py::module_ m = m_native.def_submodule("loader");
222 
223  m.def("setInterpDir", &loader::setInterpDir);
224 }
225 
226 static void
227 init_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 
240 void
241 pybind_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
gem5::Temperature::toCelsius
constexpr double toCelsius() const
Definition: temperature.hh:69
gem5::DrainManager::instance
static DrainManager & instance()
Get the singleton DrainManager instance.
Definition: drain.hh:91
gem5::curTick
Tick curTick()
The universal simulation clock.
Definition: cur_tick.hh:46
gem5::ListenSocket::disableAll
static void disableAll()
Definition: socket.cc:82
gem5::init_pc
static void init_pc(py::module_ &m_native)
Definition: core.cc:168
gem5::VegaISA::f
Bitfield< 56 > f
Definition: pagetable.hh:53
gem5::AddrRange::to_string
std::string to_string() const
Get a string representation of the range.
Definition: addr_range.hh:360
socket.hh
gem5::PcCountPair::to_string
std::string to_string() const
String format.
Definition: pc_count_pair.hh:77
gem5::AddrRange::granularity
uint64_t granularity() const
Determing the interleaving granularity of the range.
Definition: addr_range.hh:294
gem5::AddrRange::start
Addr start() const
Get the start address of the range.
Definition: addr_range.hh:343
gem5::VegaISA::m
m
Definition: pagetable.hh:52
gem5::Logger::PANIC
@ PANIC
Definition: logging.hh:69
serialize.hh
gem5::init_loader
static void init_loader(py::module_ &m_native)
Definition: core.cc:219
gem5::Drainable::drainState
DrainState drainState() const
Return the current drain state of an object.
Definition: drain.hh:324
gem5::RangeSize
AddrRange RangeSize(Addr start, Addr size)
Definition: addr_range.hh:831
gem5::SimObject::serializeAll
static void serializeAll(const std::string &cpt_dir)
Create a checkpoint by serializing all SimObjects in the system.
Definition: sim_object.cc:132
gem5::CheckpointIn
Definition: serialize.hh:68
cur_tick.hh
random.hh
gem5::init_net
static void init_net(py::module_ &m_native)
Definition: core.cc:193
gem5::MaxTick
const Tick MaxTick
Definition: types.hh:60
gem5::init_serialize
static void init_serialize(py::module_ &m_native)
Definition: core.cc:122
gem5::loader::setInterpDir
void setInterpDir(const std::string &dirname)
This is the interface for setting up a base path for the elf interpreter.
Definition: elf_object.cc:102
gem5::AddrRange::intersects
bool intersects(const AddrRange &r) const
Determine if another range intersects this one, i.e.
Definition: addr_range.hh:408
std::vector< Addr >
gem5::listenSocketUnixFileConfig
ListenSocketConfig listenSocketUnixFileConfig(std::string dir, std::string fname)
Definition: socket.cc:370
gem5::sim_clock::as_int::s
Tick s
second
Definition: core.cc:65
gem5::Drainable::notifyFork
virtual void notifyFork()
Notify a child process of a fork.
Definition: drain.hh:344
gem5::Temperature
The class stores temperatures in Kelvin and provides helper methods to convert to/from Celsius.
Definition: temperature.hh:50
gem5::AddrRange::isSubset
bool isSubset(const AddrRange &r) const
Determine if this range is a subset of another range, i.e.
Definition: addr_range.hh:445
gem5::pybind_init_core
void pybind_init_core(py::module_ &m_native)
Definition: core.cc:241
gem5::init_range
static void init_range(py::module_ &m_native)
Definition: core.cc:135
gem5::RangeIn
AddrRange RangeIn(Addr start, Addr end)
Definition: addr_range.hh:822
gem5::compileDate
const char * compileDate
Definition: date.cc:35
gem5::doExitCleanup
void doExitCleanup()
Do C++ simulator exit processing.
Definition: core.cc:153
gem5::RangeEx
AddrRange RangeEx(Addr start, Addr end)
Definition: addr_range.hh:813
gem5::Logger::INFO
@ INFO
Definition: logging.hh:69
gem5::DrainManager::preCheckpointRestore
void preCheckpointRestore()
Run state fixups before a checkpoint restore operation.
Definition: drain.cc:135
elf_object.hh
gem5::listenSocketInetConfig
ListenSocketConfig listenSocketInetConfig(int port)
Definition: socket.cc:260
gem5::Temperature::fromKelvin
static Temperature fromKelvin(double _value)
Definition: temperature.cc:44
gem5::Temperature::fromFahrenheit
static Temperature fromFahrenheit(double _value)
Definition: temperature.cc:56
gem5::getClockFrequency
Tick getClockFrequency()
Definition: core.cc:121
gem5::VegaISA::t
Bitfield< 51 > t
Definition: pagetable.hh:56
gem5::AddrRange::interleaved
bool interleaved() const
Determine if the range is interleaved or not.
Definition: addr_range.hh:284
sim_object.hh
pc_count_pair.hh
gem5::gem5Version
const char * gem5Version
Definition: version.cc:35
gem5::AddrRange::size
Addr size() const
Get the size of the address range.
Definition: addr_range.hh:326
gem5::AddrRange::end
Addr end() const
Get the end address of the range.
Definition: addr_range.hh:350
gem5::AddrRange::valid
bool valid() const
Determine if the range is valid.
Definition: addr_range.hh:336
gem5::clockFrequencyFixed
bool clockFrequencyFixed()
Definition: core.cc:112
gem5::init_socket
static void init_socket(py::module_ &m_native)
Definition: core.cc:227
gem5::PybindSimObjectResolver::resolveSimObject
SimObject * resolveSimObject(const std::string &name)
Find a SimObject given a full path name.
Definition: core.cc:77
gem5::Logger::HACK
@ HACK
Definition: logging.hh:69
gem5::SimObject
Abstract superclass for simulation objects.
Definition: sim_object.hh:146
gem5::DrainState::Drained
@ Drained
Buffers drained, ready for serialization/handover.
gem5::fixClockFrequency
void fixClockFrequency()
Definition: core.cc:84
gem5::Temperature::toKelvin
constexpr double toKelvin() const
Definition: temperature.hh:68
gem5::ListenSocket::allDisabled
static bool allDisabled()
Definition: socket.cc:90
gem5::Addr
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
Definition: types.hh:147
gem5::listenSocketUnixAbstractConfig
ListenSocketConfig listenSocketUnixAbstractConfig(std::string path)
Definition: socket.cc:400
name
const std::string & name()
Definition: trace.cc:48
gem5::init_drain
static void init_drain(py::module_ &m_native)
Definition: core.cc:90
addr_range.hh
temperature.hh
gem5::AddrRange::mergesWith
bool mergesWith(const AddrRange &r) const
Determine if another range merges with the current one, i.e.
Definition: addr_range.hh:391
gem5::DrainManager::tryDrain
bool tryDrain()
Try to drain the system.
Definition: drain.cc:64
gem5::pybindSimObjectResolver
PybindSimObjectResolver pybindSimObjectResolver
Definition: core.cc:74
gem5::DrainManager::resume
void resume()
Resume normal simulation in a Drained system.
Definition: drain.cc:96
gem5::setOutputDir
void setOutputDir(const std::string &dir)
Definition: core.cc:124
gem5::PybindSimObjectResolver
Resolve a SimObject name using the Pybind configuration.
Definition: core.cc:69
gem5::Logger::FATAL
@ FATAL
Definition: logging.hh:69
types.hh
gem5::DrainManager::isDrained
bool isDrained() const
Check if the system is drained.
Definition: drain.hh:145
core.hh
gem5::SimObjectResolver
Base class to wrap object resolving functionality.
Definition: sim_object.hh:379
gem5::PcCountPair::getPC
constexpr Addr getPC() const
Returns the Program Counter address.
Definition: pc_count_pair.hh:57
gem5::setClockFrequency
void setClockFrequency(Tick tps)
Definition: core.cc:115
logging.hh
gem5::Logger::setLevel
static void setLevel(LogLevel ll)
Definition: logging.hh:74
gem5::AddrRange::exclude
AddrRangeList exclude(const AddrRangeList &exclude_ranges) const
Subtract a list of intervals from the range and return the resulting collection of ranges,...
Definition: addr_range.hh:639
gem5::ListenSocket::loopbackOnly
static void loopbackOnly()
Definition: socket.cc:96
gem5::PcCountPair::getCount
constexpr int getCount() const
Returns the count of the Program.
Definition: pc_count_pair.hh:59
gem5::DrainManager::state
DrainState state() const
Get the simulators global drain state.
Definition: drain.hh:152
gem5::statistics::init
const FlagsType init
This Stat is Initialized.
Definition: info.hh:55
drain.hh
gem5::DrainManager::signalDrainDone
void signalDrainDone()
Notify the DrainManager that a Drainable object has finished draining.
Definition: drain.cc:149
gem5::DrainState::Running
@ Running
Running normally.
gem5::Logger::WARN
@ WARN
Definition: logging.hh:69
gem5::Temperature::fromCelsius
static Temperature fromCelsius(double _value)
Definition: temperature.cc:50
gem5::AddrRange
The AddrRange class encapsulates an address range, and supports a number of tests to check if two ran...
Definition: addr_range.hh:81
std::list< AddrRange >
inet.hh
gem5
Reference material can be found at the JEDEC website: UFS standard http://www.jedec....
Definition: gpu_translation_state.hh:37
gem5::listenSocketEmptyConfig
static ListenSocketConfig listenSocketEmptyConfig()
Definition: socket.hh:137
gem5::Random::init
void init(uint32_t s)
Definition: random.cc:67
gem5::random_mt
Random random_mt
Definition: random.cc:99
gem5::Temperature::toFahrenheit
double toFahrenheit() const
Definition: temperature.cc:62
gem5::SimObject::setSimObjectResolver
static void setSimObjectResolver(SimObjectResolver *resolver)
There is a single object name resolver, and it is only set when simulation is restoring from checkpoi...
Definition: sim_object.cc:164
gem5::PcCountPair
Definition: pc_count_pair.hh:37
gem5::DrainState::Draining
@ Draining
Draining buffers pending serialization/handover.
gem5::AddrRange::stripes
uint32_t stripes() const
Determine the number of interleaved address stripes this range is part of.
Definition: addr_range.hh:316

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