diff options
Diffstat (limited to 'python')
-rw-r--r-- | python/m5/config.py | 103 | ||||
-rw-r--r-- | python/m5/convert.py | 22 | ||||
-rw-r--r-- | python/m5/objects/Ethernet.py | 3 |
3 files changed, 70 insertions, 58 deletions
diff --git a/python/m5/config.py b/python/m5/config.py index 3c49421d3..e1970e672 100644 --- a/python/m5/config.py +++ b/python/m5/config.py @@ -755,7 +755,7 @@ class ParamDesc(object): class VectorParamValue(list): def ini_str(self): - return ' '.join([str(v) for v in self]) + return ' '.join([v.ini_str() for v in self]) def unproxy(self, base): return [v.unproxy(base) for v in self] @@ -825,6 +825,40 @@ VectorParam = ParamFactory(VectorParamDesc) # ##################################################################### +# superclass for "numeric" parameter values, to emulate math +# operations in a type-safe way. e.g., a Latency times an int returns +# a new Latency object. +class NumericParamValue(ParamValue): + def __str__(self): + return str(self.value) + + def __float__(self): + return float(self.value) + + # hook for bounds checking + def _check(self): + return + + def __mul__(self, other): + newobj = self.__class__(self) + newobj.value *= other + newobj._check() + return newobj + + __rmul__ = __mul__ + + def __div__(self, other): + newobj = self.__class__(self) + newobj.value /= other + newobj._check() + return newobj + + def __sub__(self, other): + newobj = self.__class__(self) + newobj.value -= other + newobj._check() + return newobj + class Range(ParamValue): type = int # default; can be overridden in subclasses def __init__(self, *args, **kwargs): @@ -891,19 +925,20 @@ class CheckedIntType(type): # class is subclassed to generate parameter classes with specific # bounds. Initialization of the min and max bounds is done in the # metaclass CheckedIntType.__init__. -class CheckedInt(long,ParamValue): +class CheckedInt(NumericParamValue): __metaclass__ = CheckedIntType - def __new__(cls, value): - if isinstance(value, str): - value = toInteger(value) - - self = long.__new__(cls, value) - - if not cls.min <= self <= cls.max: + def _check(self): + if not self.min <= self.value <= self.max: raise TypeError, 'Integer param out of bounds %d < %d < %d' % \ - (cls.min, self, cls.max) - return self + (self.min, self.value, self.max) + + def __init__(self, value): + if isinstance(value, str): + self.value = toInteger(value) + elif isinstance(value, (int, long)): + self.value = long(value) + self._check() class Int(CheckedInt): size = 32; unsigned = False class Unsigned(CheckedInt): size = 32; unsigned = True @@ -930,19 +965,26 @@ class Float(ParamValue, float): class MemorySize(CheckedInt): size = 64 unsigned = True - def __new__(cls, value): - return super(MemorySize, cls).__new__(cls, toMemorySize(value)) + def __init__(self, value): + if isinstance(value, MemorySize): + self.value = value.value + else: + self.value = toMemorySize(value) + self._check() class Addr(CheckedInt): size = 64 unsigned = True - def __new__(cls, value): - try: - value = long(toMemorySize(value)) - except TypeError: - value = long(value) - return super(Addr, cls).__new__(cls, value) + def __init__(self, value): + if isinstance(value, Addr): + self.value = value.value + else: + try: + self.value = toMemorySize(value) + except TypeError: + self.value = long(value) + self._check() class AddrRange(Range): type = Addr @@ -1123,29 +1165,6 @@ def tick_check(float_ticks): #raise ValueError return int_ticks -# superclass for "numeric" parameter values, to emulate math -# operations in a type-safe way. e.g., a Latency times an int returns -# a new Latency object. -class NumericParamValue(ParamValue): - def __str__(self): - return str(self.value) - - def __float__(self): - return float(self.value) - - def __mul__(self, other): - newobj = self.__class__(self) - newobj.value *= other - return newobj - - __rmul__ = __mul__ - - def __div__(self, other): - newobj = self.__class__(self) - newobj.value /= other - return newobj - - def getLatency(value): if isinstance(value, Latency) or isinstance(value, Clock): return value.value diff --git a/python/m5/convert.py b/python/m5/convert.py index 9d9f4efa7..73181e985 100644 --- a/python/m5/convert.py +++ b/python/m5/convert.py @@ -89,17 +89,9 @@ def toFloat(value): else: return float(value) -def toLong(value): - value = toFloat(value) - result = int(value) - if value != result: - raise ValueError, "cannot convert '%s' to long" % value - - return result - def toInteger(value): value = toFloat(value) - result = int(value) + result = long(value) if value != result: raise ValueError, "cannot convert '%s' to integer" % value @@ -220,16 +212,16 @@ def toMemorySize(value): raise TypeError, "wrong type '%s' should be str" % type(value) if value.endswith('PB'): - return float(value[:-2]) * pebi + return long(value[:-2]) * pebi elif value.endswith('TB'): - return float(value[:-2]) * tebi + return long(value[:-2]) * tebi elif value.endswith('GB'): - return float(value[:-2]) * gibi + return long(value[:-2]) * gibi elif value.endswith('MB'): - return float(value[:-2]) * mebi + return long(value[:-2]) * mebi elif value.endswith('kB'): - return float(value[:-2]) * kibi + return long(value[:-2]) * kibi elif value.endswith('B'): - return float(value[:-1]) + return long(value[:-1]) raise ValueError, "cannot convert '%s' to memory size" % value diff --git a/python/m5/objects/Ethernet.py b/python/m5/objects/Ethernet.py index 3ad6b57f9..a2a8b217f 100644 --- a/python/m5/objects/Ethernet.py +++ b/python/m5/objects/Ethernet.py @@ -84,6 +84,7 @@ class EtherDevBase(PciDevice): rx_filter = Param.Bool(True, "Enable Receive Filter") intr_delay = Param.Latency('10us', "Interrupt Propagation Delay") + dedicated = Param.Bool(False, "dedicate a kernel thread to the driver") class NSGigE(EtherDevBase): type = 'NSGigE' @@ -91,7 +92,6 @@ class NSGigE(EtherDevBase): dma_data_free = Param.Bool(False, "DMA of Data is free") dma_desc_free = Param.Bool(False, "DMA of Descriptors is free") - dedicated = Param.Bool(False, "dedicate a kernel thread to the driver") class NSGigEInt(EtherInt): type = 'NSGigEInt' @@ -102,6 +102,7 @@ class Sinic(EtherDevBase): rx_max_copy = Param.MemorySize('1514B', "rx max copy") tx_max_copy = Param.MemorySize('16kB', "tx max copy") + rx_max_intr = Param.UInt32(10, "max rx packets per interrupt") rx_fifo_threshold = Param.MemorySize('48kB', "rx fifo high threshold") tx_fifo_threshold = Param.MemorySize('16kB', "tx fifo low threshold") |