summaryrefslogtreecommitdiff
path: root/src/systemc
diff options
context:
space:
mode:
authorGabe Black <gabeblack@google.com>2018-11-07 17:56:54 -0800
committerGabe Black <gabeblack@google.com>2018-11-12 22:07:09 +0000
commita7105c617fa921904213d7509746a8f6c51c002f (patch)
treef8943402bc506ca619b62f93ba5aea4e60b145b6 /src/systemc
parent3fb91393a67515a008dae0346689ffffe5180ab8 (diff)
downloadgem5-a7105c617fa921904213d7509746a8f6c51c002f.tar.xz
systemc: Stop using python to set/manage the global time resolution.
Now that that's managed in c++, we can do that directly without having to depend on the python code being available, the code which lets us call from c++ to python, or for the embedded python interpretter to have started running and have loaded the appropriate modules. Change-Id: Ied110d8f22181095f8c0c645636a9bd67964263e Reviewed-on: https://gem5-review.googlesource.com/c/14056 Maintainer: Gabe Black <gabeblack@google.com> Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com> Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Diffstat (limited to 'src/systemc')
-rw-r--r--src/systemc/core/sc_time.cc97
1 files changed, 10 insertions, 87 deletions
diff --git a/src/systemc/core/sc_time.cc b/src/systemc/core/sc_time.cc
index 5c72927da..95398ce50 100644
--- a/src/systemc/core/sc_time.cc
+++ b/src/systemc/core/sc_time.cc
@@ -27,13 +27,13 @@
* Authors: Gabe Black
*/
+#include <cmath>
+#include <cstring>
#include <sstream>
#include <vector>
#include "base/types.hh"
-#include "python/pybind11/pybind.hh"
#include "sim/core.hh"
-#include "systemc/core/python.hh"
#include "systemc/core/time.hh"
#include "systemc/ext/core/messages.hh"
#include "systemc/ext/core/sc_main.hh"
@@ -46,24 +46,12 @@ namespace sc_core
namespace
{
-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;
-
void
-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)
{
+ if (d != 0)
+ fixClockFrequency();
+
double scale = sc_gem5::TimeUnitScale[tu] * SimClock::Float::s;
// Accellera claims there is a linux bug, and that these next two
// lines work around them.
@@ -71,71 +59,6 @@ setWork(sc_time *time, double d, ::sc_core::sc_time_unit tu)
*time = sc_time::from_value(static_cast<uint64_t>(tmp));
}
-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;
-
double defaultUnit = 1.0e-9;
} // anonymous namespace
@@ -289,7 +212,7 @@ sc_time
sc_time::from_value(sc_dt::uint64 u)
{
if (u)
- attemptToFixTime();
+ fixClockFrequency();
sc_time t;
t.val = u;
return t;
@@ -388,7 +311,7 @@ sc_set_time_resolution(double d, sc_time_unit tu)
// This won't detect the timescale being fixed outside of systemc, but
// it's at least some protection.
- if (timeFixed) {
+ if (clockFrequencyFixed()) {
SC_REPORT_ERROR(SC_ID_SET_TIME_RESOLUTION_,
"sc_time object(s) constructed");
}
@@ -410,7 +333,7 @@ sc_set_time_resolution(double d, sc_time_unit tu)
Tick ticks_per_second =
sc_gem5::TimeUnitFrequency[tu] / static_cast<Tick>(d);
- setGlobalFrequency(ticks_per_second);
+ setClockFrequency(ticks_per_second);
specified = true;
}
@@ -447,7 +370,7 @@ sc_set_default_time_unit(double d, sc_time_unit tu)
}
// This won't detect the timescale being fixed outside of systemc, but
// it's at least some protection.
- if (timeFixed) {
+ if (clockFrequencyFixed()) {
SC_REPORT_ERROR(SC_ID_SET_DEFAULT_TIME_UNIT_,
"sc_time object(s) constructed");
}