Meatboy 106 has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/53423 )
Change subject: base: Move conversion to int outside from
m5.ticks.fromSeconds
......................................................................
base: Move conversion to int outside from m5.ticks.fromSeconds
m5.ticks.fromSeconds now converts a /s value to a /tick value while keeping
the
original value type (typically float or int). Conversion to int with warning
upon excessive rounding error has been moved to m5.util.convert.toint.
Related Jira: https://gem5.atlassian.net/browse/GEM5-1118
Change-Id: Ia3b866991108a57de23e258ca685a24af9ee578e
---
M configs/common/Simulation.py
M src/python/gem5/components/processors/linear_generator_core.py
M src/python/m5/util/convert.py
M src/python/gem5/components/processors/complex_generator_core.py
M tests/gem5/configs/realview64-kvm-dual.py
M tests/gem5/configs/switcheroo.py
M src/python/gem5/components/processors/random_generator_core.py
M tests/gem5/configs/checkpoint.py
M src/python/m5/params.py
M configs/example/read_config.py
M src/python/m5/ticks.py
11 files changed, 53 insertions(+), 44 deletions(-)
diff --git a/configs/common/Simulation.py b/configs/common/Simulation.py
index 3b9efc0..477edc9 100644
--- a/configs/common/Simulation.py
+++ b/configs/common/Simulation.py
@@ -645,7 +645,7 @@
"absolute max tick")
explicit_maxticks += 1
if options.maxtime:
- maxtick_from_maxtime = m5.ticks.fromSeconds(options.maxtime)
+ maxtick_from_maxtime = toint(m5.ticks.fromSeconds(options.maxtime))
explicit_maxticks += 1
if explicit_maxticks > 1:
warn("Specified multiple of --abs-max-tick, --rel-max-tick,
--maxtime."\
diff --git a/configs/example/read_config.py b/configs/example/read_config.py
index 5e64a9a..fae49e2 100644
--- a/configs/example/read_config.py
+++ b/configs/example/read_config.py
@@ -99,7 +99,7 @@
# Convert to byte/tick
value = 1.0 / float(param)
# Convert to byte/s
- value = ticks.fromSeconds(value)
+ value = toint(ticks.fromSeconds(value))
return cls('%fB/s' % value)
# These parameters have trickier parsing from .ini files than might be
diff --git
a/src/python/gem5/components/processors/complex_generator_core.py
b/src/python/gem5/components/processors/complex_generator_core.py
index 583b318..cd52657 100644
--- a/src/python/gem5/components/processors/complex_generator_core.py
+++ b/src/python/gem5/components/processors/complex_generator_core.py
@@ -268,9 +268,9 @@
:param data_limit: The amount of data in bytes to read/write by the
generator before stopping generation.
"""
- duration = fromSeconds(toLatency(duration))
+ duration = toint(fromSeconds(toLatency(duration)))
rate = toMemoryBandwidth(rate)
- period = fromSeconds(block_size / rate)
+ period = toint(fromSeconds(block_size / rate))
min_period = period
max_period = period
yield self.generator.createLinear(
@@ -314,9 +314,9 @@
:param data_limit: The amount of data in bytes to read/write by the
generator before stopping generation.
"""
- duration = fromSeconds(toLatency(duration))
+ duration = toint(fromSeconds(toLatency(duration)))
rate = toMemoryBandwidth(rate)
- period = fromSeconds(block_size / rate)
+ period = toint(fromSeconds(block_size / rate))
min_period = period
max_period = period
yield self.generator.createRandom(
diff --git a/src/python/gem5/components/processors/linear_generator_core.py
b/src/python/gem5/components/processors/linear_generator_core.py
index e6bf441..dcbd14e 100644
--- a/src/python/gem5/components/processors/linear_generator_core.py
+++ b/src/python/gem5/components/processors/linear_generator_core.py
@@ -25,7 +25,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from m5.ticks import fromSeconds
-from m5.util.convert import toLatency, toMemoryBandwidth
+from m5.util.convert import toLatency, toMemoryBandwidth, toint
from m5.objects import PyTrafficGen, Port, BaseTrafficGen
from .abstract_core import AbstractCore
@@ -95,9 +95,9 @@
:rtype: Iterator[BaseTrafficGen]
"""
- duration = fromSeconds(toLatency(self._duration))
+ duration = toint(fromSeconds(toLatency(self._duration)))
rate = toMemoryBandwidth(self._rate)
- period = fromSeconds(self._block_size / rate)
+ period = toint(fromSeconds(self._block_size / rate))
min_period = period
max_period = period
yield self.generator.createLinear(
diff --git a/src/python/gem5/components/processors/random_generator_core.py
b/src/python/gem5/components/processors/random_generator_core.py
index 219040c..90ee315 100644
--- a/src/python/gem5/components/processors/random_generator_core.py
+++ b/src/python/gem5/components/processors/random_generator_core.py
@@ -25,7 +25,7 @@
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from m5.ticks import fromSeconds
-from m5.util.convert import toLatency, toMemoryBandwidth
+from m5.util.convert import toLatency, toMemoryBandwidth, toint
from m5.objects import PyTrafficGen, Port, BaseTrafficGen
from .abstract_core import AbstractCore
@@ -95,9 +95,9 @@
:rtype: Iterator[BaseTrafficGen]
"""
- duration = fromSeconds(toLatency(self._duration))
+ duration = toint(fromSeconds(toLatency(self._duration)))
rate = toMemoryBandwidth(self._rate)
- period = fromSeconds(self._block_size / rate)
+ period = toint(fromSeconds(self._block_size / rate))
min_period = period
max_period = period
yield self.generator.createRandom(
diff --git a/src/python/m5/params.py b/src/python/m5/params.py
index 39137c5..9a8e041 100644
--- a/src/python/m5/params.py
+++ b/src/python/m5/params.py
@@ -1536,9 +1536,6 @@
'little',
]
-# how big does a rounding error need to be before we warn about it?
-frequency_tolerance = 0.001 # 0.1%
-
class TickParamValue(NumericParamValue):
cxx_type = 'Tick'
ex_str = "1MHz"
@@ -1597,7 +1594,7 @@
if self.ticks or self.value == 0:
value = self.value
else:
- value = ticks.fromSeconds(self.value)
+ value = toint(ticks.fromSeconds(self.value))
return int(value)
def config_value(self):
@@ -1640,7 +1637,7 @@
if self.ticks or self.value == 0:
value = self.value
else:
- value = ticks.fromSeconds(1.0 / self.value)
+ value = toint(ticks.fromSeconds(1.0 / self.value))
return int(value)
def config_value(self):
@@ -1784,7 +1781,7 @@
# convert to seconds per byte
value = 8.0 / float(self)
# convert to ticks per byte
- value = ticks.fromSeconds(value)
+ value = toint(ticks.fromSeconds(value))
return float(value)
def ini_str(self):
@@ -1822,7 +1819,7 @@
if value:
value = 1.0 / float(self)
# convert to ticks per byte
- value = ticks.fromSeconds(value)
+ value = toint(ticks.fromSeconds(value))
return float(value)
def ini_str(self):
diff --git a/src/python/m5/ticks.py b/src/python/m5/ticks.py
index 1ec012b..e28f857 100644
--- a/src/python/m5/ticks.py
+++ b/src/python/m5/ticks.py
@@ -23,11 +23,8 @@
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-import decimal
-
import sys
-from m5.util import warn
+import numbers
# fix the global frequency
def fixGlobalFrequency():
@@ -49,13 +46,10 @@
"wrong type '%s' for ticksPerSecond" % type(ticksPerSecond))
_m5.core.setClockFrequency(int(tps))
-# how big does a rounding error need to be before we warn about it?
-frequency_tolerance = 0.001 # 0.1%
-
def fromSeconds(value):
import _m5.core
- if not isinstance(value, float):
+ if not isinstance(value, numbers.Number):
raise TypeError("can't convert '%s' to type tick" % type(value))
# once someone needs to convert to seconds, the global frequency
@@ -64,19 +58,8 @@
raise AttributeError(
"In order to do conversions, the global frequency must be
fixed")
- if value == 0:
- return 0
-
- # convert the value from time to ticks
+ # convert the value from seconds to ticks
value *= _m5.core.getClockFrequency()
+ return value
- int_value = int(
- decimal.Decimal(value).to_integral_value(
decimal.ROUND_HALF_UP))
- err = (value - int_value) / value
- if err > frequency_tolerance:
- warn("rounding error > tolerance\n %f rounded to %d", value,
- int_value)
- return int_value
-
-__all__ = [ 'setGlobalFrequency', 'fixGlobalFrequency', 'fromSeconds',
- 'frequency_tolerance' ]
+__all__ = [ 'setGlobalFrequency', 'fixGlobalFrequency', 'fromSeconds']
diff --git a/src/python/m5/util/convert.py b/src/python/m5/util/convert.py
index e66eb5c..9c9fe96 100644
--- a/src/python/m5/util/convert.py
+++ b/src/python/m5/util/convert.py
@@ -37,6 +37,8 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+import decimal
+
# metric prefixes
atto = 1.0e-18
femto = 1.0e-15
@@ -322,3 +324,15 @@
raise ValueError(f"{value} is an invalid temperature")
return kelvin
+
+def toint(value, warnMargin = 0.001):
+ if value == 0:
+ return 0
+ int_value = int(
+ decimal.Decimal(value).to_integral_value( decimal.ROUND_HALF_UP))
+ err = (value - int_value) / value
+ if err > warnMargin:
+ from . import warn
+ warn("rounding error > tolerance\n %f rounded to %d", value,
+ int_value)
+ return int_value
diff --git a/tests/gem5/configs/checkpoint.py
b/tests/gem5/configs/checkpoint.py
index 3545095..44967a8 100644
--- a/tests/gem5/configs/checkpoint.py
+++ b/tests/gem5/configs/checkpoint.py
@@ -70,7 +70,7 @@
else:
m5.instantiate()
- e = m5.simulate(m5.ticks.fromSeconds(interval))
+ e = toint(m5.simulate(m5.ticks.fromSeconds(interval)))
cause = e.getCause()
if cause in _exit_limit:
m5.checkpoint(name)
diff --git a/tests/gem5/configs/realview64-kvm-dual.py
b/tests/gem5/configs/realview64-kvm-dual.py
index c97240a..b3e911d 100644
--- a/tests/gem5/configs/realview64-kvm-dual.py
+++ b/tests/gem5/configs/realview64-kvm-dual.py
@@ -43,4 +43,4 @@
cpu_class=ArmV8KvmCPU,
num_cpus=2).create_root()
fixGlobalFrequency()
-root.sim_quantum = fromSeconds(m5.util.convert.anyToLatency("1ms"))
+root.sim_quantum = toint(fromSeconds(m5.util.convert.anyToLatency("1ms")))
diff --git a/tests/gem5/configs/switcheroo.py
b/tests/gem5/configs/switcheroo.py
index fb1db81..2dc2d00 100644
--- a/tests/gem5/configs/switcheroo.py
+++ b/tests/gem5/configs/switcheroo.py
@@ -111,7 +111,7 @@
# Determine the switching period, this has to be done after
# instantiating the system since the time base must be fixed.
- period = m5.ticks.fromSeconds(1.0 / freq)
+ period = toint(m5.ticks.fromSeconds(1.0 / freq))
while True:
exit_event = m5.simulate(period)
exit_cause = exit_event.getCause()
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/53423
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Ia3b866991108a57de23e258ca685a24af9ee578e
Gerrit-Change-Number: 53423
Gerrit-PatchSet: 1
Gerrit-Owner: Meatboy 106 <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s