29a30,31
> #include <vector>
>
32a35
> #include "systemc/core/python.hh"
58a62,76
> 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;
>
60c78
< fixTimeResolution()
---
> setWork(sc_time *time, double d, ::sc_core::sc_time_unit tu)
62,64c80,86
< static bool fixed = false;
< if (fixed)
< return;
---
> //XXX Assuming the time resolution is 1ps.
> double scale = TimeUnitScale[tu] / TimeUnitScale[SC_PS];
> // Accellera claims there is a linux bug, and that these next two
> // lines work around them.
> volatile double tmp = d * scale + 0.5;
> *time = sc_time::from_value(static_cast<uint64_t>(tmp));
> }
65a88,90
> void
> fixTime()
> {
69c94,97
< fixed = true;
---
>
> for (auto &t: toSet)
> setWork(t.time, t.d, t.tu);
> toSet.clear();
71a100,136
> void
> set(::sc_core::sc_time *time, double d, ::sc_core::sc_time_unit tu)
> {
> // 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();
> }
> 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;
>
79,87c144,145
< if (d != 0) {
< fixTimeResolution();
< //XXX Assuming the time resolution is 1ps.
< double scale = TimeUnitScale[tu] / TimeUnitScale[SC_PS];
< // Accellera claims there is a linux bug, and that these next two
< // lines work around them.
< volatile double tmp = d * scale + 0.5;
< val = static_cast<uint64_t>(tmp);
< }
---
> if (d != 0)
> set(this, d, tu);