Gabe Black has submitted this change and it was merged. ( https://gem5-review.googlesource.com/c/public/gem5/+/12461 )

Change subject: systemc: Implement sc_(g|s)et_time_resolution.
......................................................................

systemc: Implement sc_(g|s)et_time_resolution.

Change-Id: If546bea633e777cdb2b14f47c0d9d50b044b99cf
Reviewed-on: https://gem5-review.googlesource.com/c/12461
Reviewed-by: Gabe Black <[email protected]>
Maintainer: Gabe Black <[email protected]>
---
M src/systemc/core/sc_time.cc
1 file changed, 50 insertions(+), 4 deletions(-)

Approvals:
  Gabe Black: Looks good to me, approved; Looks good to me, approved



diff --git a/src/systemc/core/sc_time.cc b/src/systemc/core/sc_time.cc
index 96877e8..e0e8cf1 100644
--- a/src/systemc/core/sc_time.cc
+++ b/src/systemc/core/sc_time.cc
@@ -33,7 +33,9 @@
 #include "base/types.hh"
 #include "python/pybind11/pybind.hh"
 #include "systemc/core/python.hh"
+#include "systemc/ext/core/sc_main.hh"
 #include "systemc/ext/core/sc_time.hh"
+#include "systemc/ext/utils/sc_report_handler.hh"

 namespace sc_core
 {
@@ -98,6 +100,15 @@
 }

 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)
 {
     // Only fix time once.
@@ -358,16 +369,51 @@
 const sc_time SC_ZERO_TIME;

 void
-sc_set_time_resolution(double, sc_time_unit)
+sc_set_time_resolution(double d, sc_time_unit tu)
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
+    if (d < 0.0) {
+        SC_REPORT_ERROR("(E514) set time resolution failed",
+                "value not positive");
+    }
+    double dummy;
+    if (modf(log10(d), &dummy) != 0.0) {
+        SC_REPORT_ERROR("(E514) set time resolution failed",
+                "value not a power of ten");
+    }
+    if (sc_is_running()) {
+        SC_REPORT_ERROR("(E514) set time resolution failed",
+                "simulation running");
+    }
+    static bool specified = false;
+    if (specified) {
+        SC_REPORT_ERROR("(E514) set time resolution failed",
+                "already specified");
+    }
+    // This won't detect the timescale being fixed outside of systemc, but
+    // it's at least some protection.
+    if (timeFixed) {
+        SC_REPORT_ERROR("(E514) set time resolution failed",
+                "sc_time object(s) constructed");
+    }
+
+    // Normalize d to seconds.
+    d *= TimeUnitScale[tu];
+    if (d < TimeUnitScale[SC_FS]) {
+        SC_REPORT_ERROR("(E514) set time resolution failed",
+                "value smaller than 1 fs");
+    }
+    // Change d from a period to a frequency.
+    d = 1 / d;
+    // Convert to integer ticks.
+    Tick ticks_per_second = static_cast<Tick>(d);
+    setGlobalFrequency(ticks_per_second);
+    specified = true;
 }

 sc_time
 sc_get_time_resolution()
 {
-    warn("%s not implemented.\n", __PRETTY_FUNCTION__);
-    return sc_time();
+    return sc_time::from_value(1);
 }

 const sc_time &

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/12461
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: If546bea633e777cdb2b14f47c0d9d50b044b99cf
Gerrit-Change-Number: 12461
Gerrit-PatchSet: 8
Gerrit-Owner: Gabe Black <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Gabe Black <[email protected]>
Gerrit-Reviewer: Giacomo Travaglini <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Matthias Jung <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to