diff options
author | Gabe Black <gabeblack@google.com> | 2018-11-07 17:34:11 -0800 |
---|---|---|
committer | Gabe Black <gabeblack@google.com> | 2018-11-12 22:05:00 +0000 |
commit | 3fb91393a67515a008dae0346689ffffe5180ab8 (patch) | |
tree | cc5ff91879a416fbb80eea3e4a43da8ca0c63276 /src/python/m5 | |
parent | 8c8a2f12f2f8b419723e7af8e3851033c41b7b51 (diff) | |
download | gem5-3fb91393a67515a008dae0346689ffffe5180ab8.tar.xz |
sim: Push the global frequency management code into C++.
That makes it available when python is left out, and makes it available
to c++ code without having to call back into python.
Change-Id: If82e7e8eff526f2b957f84afe046e1d56fed4aa2
Reviewed-on: https://gem5-review.googlesource.com/c/14055
Reviewed-by: Srikant Bharadwaj <srikant.bharadwaj@amd.com>
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Jason Lowe-Power <jason@lowepower.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>
Diffstat (limited to 'src/python/m5')
-rw-r--r-- | src/python/m5/ticks.py | 25 |
1 files changed, 8 insertions, 17 deletions
diff --git a/src/python/m5/ticks.py b/src/python/m5/ticks.py index 582c65cac..fe258421e 100644 --- a/src/python/m5/ticks.py +++ b/src/python/m5/ticks.py @@ -31,26 +31,14 @@ from __future__ import print_function import sys from m5.util import warn -tps = 1.0e12 # default to 1 THz (1 Tick == 1 ps) -tps_fixed = False # once set to true, can't be changed - -# fix the global frequency and tell C++ about it +# fix the global frequency def fixGlobalFrequency(): import _m5.core - global tps, tps_fixed - if not tps_fixed: - tps_fixed = True - _m5.core.setClockFrequency(int(tps)) - print("Global frequency set at %d ticks per second" % int(tps)) + _m5.core.fixClockFrequency() def setGlobalFrequency(ticksPerSecond): from m5.util import convert - - global tps, tps_fixed - - if tps_fixed: - raise AttributeError, \ - "Global frequency already fixed at %f ticks/s." % tps + import _m5.core if isinstance(ticksPerSecond, (int, long)): tps = ticksPerSecond @@ -61,17 +49,20 @@ def setGlobalFrequency(ticksPerSecond): else: raise TypeError, \ "wrong type '%s' for ticksPerSecond" % type(ticksPerSecond) + _m5.core.setClockFrequency(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): raise TypeError, "can't convert '%s' to type tick" % type(value) # once someone needs to convert to seconds, the global frequency # had better be fixed - if not tps_fixed: + if not _m5.core.clockFrequencyFixed(): raise AttributeError, \ "In order to do conversions, the global frequency must be fixed" @@ -79,7 +70,7 @@ def fromSeconds(value): return 0 # convert the value from time to ticks - value *= tps + value *= _m5.core.getClockFrequency() int_value = int(round(value)) err = (value - int_value) / value |