29a30,31
> #include <cmath>
> #include <cstring>
34d35
< #include "python/pybind11/pybind.hh"
36d36
< #include "systemc/core/python.hh"
49,63d48
< bool timeFixed = false;
< bool pythonReady = false;
<
< struct SetInfo
< {
< SetInfo(::sc_core::sc_time *time, double d, ::sc_core::sc_time_unit tu) :
< time(time), d(d), tu(tu)
< {}
<
< ::sc_core::sc_time *time;
< double d;
< ::sc_core::sc_time_unit tu;
< };
< std::vector<SetInfo> toSet;
<
65c50
< setWork(sc_time *time, double d, ::sc_core::sc_time_unit tu)
---
> set(::sc_core::sc_time *time, double d, ::sc_core::sc_time_unit tu)
66a52,54
> if (d != 0)
> fixClockFrequency();
>
74,138d61
< void
< fixTime()
< {
< auto ticks = pybind11::module::import("m5.ticks");
< auto fix_global_frequency = ticks.attr("fixGlobalFrequency");
< fix_global_frequency();
<
< for (auto &t: toSet)
< setWork(t.time, t.d, t.tu);
< toSet.clear();
< }
<
< void
< attemptToFixTime()
< {
< // Only fix time once.
< if (!timeFixed) {
< timeFixed = true;
<
< // If we've run, python is working and we haven't fixed time yet.
< if (pythonReady)
< fixTime();
< }
< }
<
< void
< setGlobalFrequency(Tick ticks_per_second)
< {
< auto ticks = pybind11::module::import("m5.ticks");
< auto set_global_frequency = ticks.attr("setGlobalFrequency");
< set_global_frequency(ticks_per_second);
< fixTime();
< }
<
< void
< set(::sc_core::sc_time *time, double d, ::sc_core::sc_time_unit tu)
< {
< if (d != 0)
< attemptToFixTime();
< if (pythonReady) {
< // Time should be working. Set up this sc_time.
< setWork(time, d, tu);
< } else {
< // Time isn't set up yet. Defer setting up this sc_time.
< toSet.emplace_back(time, d, tu);
< }
< }
<
< class TimeSetter : public ::sc_gem5::PythonReadyFunc
< {
< public:
< TimeSetter() : ::sc_gem5::PythonReadyFunc() {}
<
< void
< run() override
< {
< // Record that we've run and python/pybind should be usable.
< pythonReady = true;
<
< // If time is already fixed, let python know.
< if (timeFixed)
< fixTime();
< }
< } timeSetter;
<
292c215
< attemptToFixTime();
---
> fixClockFrequency();
391c314
< if (timeFixed) {
---
> if (clockFrequencyFixed()) {
413c336
< setGlobalFrequency(ticks_per_second);
---
> setClockFrequency(ticks_per_second);
450c373
< if (timeFixed) {
---
> if (clockFrequencyFixed()) {