changeset 26fee6c20087 in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=26fee6c20087
description:
        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.

diffstat:

 src/python/m5/params.py       |  25 +++++++++++++++++++++++++
 src/python/m5/util/convert.py |   8 ++++++++
 2 files changed, 33 insertions(+), 0 deletions(-)

diffs (50 lines):

diff -r cba563d00376 -r 26fee6c20087 src/python/m5/params.py
--- a/src/python/m5/params.py   Thu Oct 09 17:51:58 2014 -0400
+++ b/src/python/m5/params.py   Thu Oct 09 17:52:00 2014 -0400
@@ -1485,6 +1485,31 @@
     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 -r cba563d00376 -r 26fee6c20087 src/python/m5/util/convert.py
--- a/src/python/m5/util/convert.py     Thu Oct 09 17:51:58 2014 -0400
+++ b/src/python/m5/util/convert.py     Thu Oct 09 17:52:00 2014 -0400
@@ -311,3 +311,11 @@
 
     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
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to