diff options
author | Andreas Hansson <andreas.hansson@arm.com> | 2014-10-09 17:52:00 -0400 |
---|---|---|
committer | Andreas Hansson <andreas.hansson@arm.com> | 2014-10-09 17:52:00 -0400 |
commit | c81517c293cdd3f612efae94d1143fb0cf002287 (patch) | |
tree | 9ea19c7d392e4ba450aa8f4f95831c51e7399cbd | |
parent | 06f4b521aa3ab32fbde45c97568bd84d218921d6 (diff) | |
download | gem5-c81517c293cdd3f612efae94d1143fb0cf002287.tar.xz |
config: Add Current as a parameter type
This patch adds the Python parameter type Current, which is used for
the DRAM power modelling (to start with). With this addition we avoid
implicit unit assumptions.
-rw-r--r-- | src/python/m5/params.py | 25 | ||||
-rw-r--r-- | src/python/m5/util/convert.py | 8 |
2 files changed, 33 insertions, 0 deletions
diff --git a/src/python/m5/params.py b/src/python/m5/params.py index 6c4a61d6a..f16cabaff 100644 --- a/src/python/m5/params.py +++ b/src/python/m5/params.py @@ -1485,6 +1485,31 @@ class Voltage(float,ParamValue): def ini_str(self): return '%f' % self.getValue() +class Current(float, ParamValue): + cxx_type = 'double' + ex_str = "1mA" + cmd_line_settable = False + + def __new__(cls, value): + # convert to current + val = convert.toCurrent(value) + return super(cls, Current).__new__(cls, val) + + def __call__(self, value): + val = convert.toCurrent(value) + self.__init__(val) + return value + + def __str__(self): + return str(self.getValue()) + + def getValue(self): + value = float(self) + return value + + def ini_str(self): + return '%f' % self.getValue() + class NetworkBandwidth(float,ParamValue): cxx_type = 'float' ex_str = "1Gbps" diff --git a/src/python/m5/util/convert.py b/src/python/m5/util/convert.py index 26f351e99..351ee1ee0 100644 --- a/src/python/m5/util/convert.py +++ b/src/python/m5/util/convert.py @@ -311,3 +311,11 @@ def toVoltage(value): raise ValueError, "cannot convert '%s' to voltage" % value +def toCurrent(value): + if not isinstance(value, str): + raise TypeError, "wrong type '%s' should be str" % type(value) + + if value.endswith('A'): + return toFloat(value[:-1]) + + raise ValueError, "cannot convert '%s' to current" % value |