params.py (4123:9c80390ea1bb) | params.py (4167:ce5d0f62f13b) |
---|---|
1# Copyright (c) 2004-2006 The Regents of The University of Michigan 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright --- 37 unchanged lines hidden (view full) --- 46 47import copy 48import datetime 49import inspect 50import sys 51import time 52 53import convert | 1# Copyright (c) 2004-2006 The Regents of The University of Michigan 2# All rights reserved. 3# 4# Redistribution and use in source and binary forms, with or without 5# modification, are permitted provided that the following conditions are 6# met: redistributions of source code must retain the above copyright 7# notice, this list of conditions and the following disclaimer; 8# redistributions in binary form must reproduce the above copyright --- 37 unchanged lines hidden (view full) --- 46 47import copy 48import datetime 49import inspect 50import sys 51import time 52 53import convert |
54import ticks |
|
54from util import * 55 56# Dummy base class to identify types that are legitimate for SimObject 57# parameters. 58class ParamValue(object): 59 60 cxx_predecls = [] 61 swig_predecls = [] --- 565 unchanged lines hidden (view full) --- 627 if value not in self.map: 628 raise TypeError, "Enum param got bad value '%s' (not in %s)" \ 629 % (value, self.vals) 630 self.value = value 631 632 def __str__(self): 633 return self.value 634 | 55from util import * 56 57# Dummy base class to identify types that are legitimate for SimObject 58# parameters. 59class ParamValue(object): 60 61 cxx_predecls = [] 62 swig_predecls = [] --- 565 unchanged lines hidden (view full) --- 628 if value not in self.map: 629 raise TypeError, "Enum param got bad value '%s' (not in %s)" \ 630 % (value, self.vals) 631 self.value = value 632 633 def __str__(self): 634 return self.value 635 |
635ticks_per_sec = None 636 | |
637# how big does a rounding error need to be before we warn about it? 638frequency_tolerance = 0.001 # 0.1% 639 | 636# how big does a rounding error need to be before we warn about it? 637frequency_tolerance = 0.001 # 0.1% 638 |
640# convert a floting-point # of ticks to integer, and warn if rounding 641# discards too much precision 642def tick_check(float_ticks): 643 if float_ticks == 0: 644 return 0 645 int_ticks = int(round(float_ticks)) 646 err = (float_ticks - int_ticks) / float_ticks 647 if err > frequency_tolerance: 648 print >> sys.stderr, "Warning: rounding error > tolerance" 649 print >> sys.stderr, " %f rounded to %d" % (float_ticks, int_ticks) 650 #raise ValueError 651 return int_ticks 652 653def getLatency(value): 654 if isinstance(value, Latency) or isinstance(value, Clock): 655 return value.value 656 elif isinstance(value, Frequency) or isinstance(value, RootClock): 657 return 1 / value.value 658 elif isinstance(value, str): 659 try: 660 return convert.toLatency(value) 661 except ValueError: 662 try: 663 return 1 / convert.toFrequency(value) 664 except ValueError: 665 pass # fall through 666 raise ValueError, "Invalid Frequency/Latency value '%s'" % value 667 668 669class Latency(NumericParamValue): | 639class TickParamValue(NumericParamValue): |
670 cxx_type = 'Tick' 671 cxx_predecls = ['#include "sim/host.hh"'] 672 swig_predecls = ['%import "python/m5/swig/stdint.i"\n' + 673 '%import "sim/host.hh"'] | 640 cxx_type = 'Tick' 641 cxx_predecls = ['#include "sim/host.hh"'] 642 swig_predecls = ['%import "python/m5/swig/stdint.i"\n' + 643 '%import "sim/host.hh"'] |
644 645class Latency(TickParamValue): |
|
674 def __init__(self, value): | 646 def __init__(self, value): |
675 self.value = getLatency(value) | 647 if isinstance(value, (Latency, Clock)): 648 self.ticks = value.ticks 649 self.value = value.value 650 elif isinstance(value, Frequency): 651 self.ticks = value.ticks 652 self.value = 1.0 / value.value 653 elif value.endswith('t'): 654 self.ticks = True 655 self.value = int(value[:-1]) 656 else: 657 self.ticks = False 658 self.value = convert.toLatency(value) |
676 677 def __getattr__(self, attr): 678 if attr in ('latency', 'period'): 679 return self 680 if attr == 'frequency': 681 return Frequency(self) 682 raise AttributeError, "Latency object has no attribute '%s'" % attr 683 684 # convert latency to ticks 685 def ini_str(self): | 659 660 def __getattr__(self, attr): 661 if attr in ('latency', 'period'): 662 return self 663 if attr == 'frequency': 664 return Frequency(self) 665 raise AttributeError, "Latency object has no attribute '%s'" % attr 666 667 # convert latency to ticks 668 def ini_str(self): |
686 return str(tick_check(self.value * ticks_per_sec)) | 669 if self.ticks or self.value == 0: 670 return '%d' % self.value 671 else: 672 return '%d' % (ticks.fromSeconds(self.value)) |
687 | 673 |
688class Frequency(NumericParamValue): 689 cxx_type = 'Tick' 690 cxx_predecls = ['#include "sim/host.hh"'] 691 swig_predecls = ['%import "python/m5/swig/stdint.i"\n' + 692 '%import "sim/host.hh"'] | 674class Frequency(TickParamValue): |
693 def __init__(self, value): | 675 def __init__(self, value): |
694 self.value = 1 / getLatency(value) | 676 if isinstance(value, (Latency, Clock)): 677 if value.value == 0: 678 self.value = 0 679 else: 680 self.value = 1.0 / value.value 681 self.ticks = value.ticks 682 elif isinstance(value, Frequency): 683 self.value = value.value 684 self.ticks = value.ticks 685 else: 686 self.ticks = False 687 self.value = convert.toFrequency(value) |
695 696 def __getattr__(self, attr): 697 if attr == 'frequency': 698 return self 699 if attr in ('latency', 'period'): 700 return Latency(self) 701 raise AttributeError, "Frequency object has no attribute '%s'" % attr 702 | 688 689 def __getattr__(self, attr): 690 if attr == 'frequency': 691 return self 692 if attr in ('latency', 'period'): 693 return Latency(self) 694 raise AttributeError, "Frequency object has no attribute '%s'" % attr 695 |
703 # convert frequency to ticks per period | 696 # convert latency to ticks |
704 def ini_str(self): | 697 def ini_str(self): |
705 return self.period.ini_str() | 698 if self.ticks or self.value == 0: 699 return '%d' % self.value 700 else: 701 return '%d' % (ticks.fromSeconds(1.0 / self.value)) |
706 | 702 |
707# Just like Frequency, except ini_str() is absolute # of ticks per sec (Hz). 708# We can't inherit from Frequency because we don't want it to be directly 709# assignable to a regular Frequency parameter. 710class RootClock(ParamValue): 711 cxx_type = 'Tick' 712 cxx_predecls = ['#include "sim/host.hh"'] 713 swig_predecls = ['%import "python/m5/swig/stdint.i"\n' + 714 '%import "sim/host.hh"'] 715 def __init__(self, value): 716 self.value = 1 / getLatency(value) 717 718 def __getattr__(self, attr): 719 if attr == 'frequency': 720 return Frequency(self) 721 if attr in ('latency', 'period'): 722 return Latency(self) 723 raise AttributeError, "Frequency object has no attribute '%s'" % attr 724 725 def ini_str(self): 726 return str(tick_check(self.value)) 727 | |
728# A generic frequency and/or Latency value. Value is stored as a latency, 729# but to avoid ambiguity this object does not support numeric ops (* or /). 730# An explicit conversion to a Latency or Frequency must be made first. 731class Clock(ParamValue): 732 cxx_type = 'Tick' 733 cxx_predecls = ['#include "sim/host.hh"'] 734 swig_predecls = ['%import "python/m5/swig/stdint.i"\n' + 735 '%import "sim/host.hh"'] 736 def __init__(self, value): | 703# A generic frequency and/or Latency value. Value is stored as a latency, 704# but to avoid ambiguity this object does not support numeric ops (* or /). 705# An explicit conversion to a Latency or Frequency must be made first. 706class Clock(ParamValue): 707 cxx_type = 'Tick' 708 cxx_predecls = ['#include "sim/host.hh"'] 709 swig_predecls = ['%import "python/m5/swig/stdint.i"\n' + 710 '%import "sim/host.hh"'] 711 def __init__(self, value): |
737 self.value = getLatency(value) | 712 if isinstance(value, (Latency, Clock)): 713 self.ticks = value.ticks 714 self.value = value.value 715 elif isinstance(value, Frequency): 716 self.ticks = value.ticks 717 self.value = 1.0 / value.value 718 elif value.endswith('t'): 719 self.ticks = True 720 self.value = int(value[:-1]) 721 else: 722 self.ticks = False 723 self.value = convert.anyToLatency(value) |
738 739 def __getattr__(self, attr): 740 if attr == 'frequency': 741 return Frequency(self) 742 if attr in ('latency', 'period'): 743 return Latency(self) 744 raise AttributeError, "Frequency object has no attribute '%s'" % attr 745 746 def ini_str(self): 747 return self.period.ini_str() 748 749class NetworkBandwidth(float,ParamValue): 750 cxx_type = 'float' 751 def __new__(cls, value): | 724 725 def __getattr__(self, attr): 726 if attr == 'frequency': 727 return Frequency(self) 728 if attr in ('latency', 'period'): 729 return Latency(self) 730 raise AttributeError, "Frequency object has no attribute '%s'" % attr 731 732 def ini_str(self): 733 return self.period.ini_str() 734 735class NetworkBandwidth(float,ParamValue): 736 cxx_type = 'float' 737 def __new__(cls, value): |
752 val = convert.toNetworkBandwidth(value) / 8.0 | 738 # convert to bits per second 739 val = convert.toNetworkBandwidth(value) |
753 return super(cls, NetworkBandwidth).__new__(cls, val) 754 755 def __str__(self): 756 return str(self.val) 757 758 def ini_str(self): | 740 return super(cls, NetworkBandwidth).__new__(cls, val) 741 742 def __str__(self): 743 return str(self.val) 744 745 def ini_str(self): |
759 return '%f' % (ticks_per_sec / float(self)) | 746 # convert to seconds per byte 747 value = 8.0 / float(self) 748 # convert to ticks per byte 749 return '%f' % (ticks.fromSeconds(value)) |
760 761class MemoryBandwidth(float,ParamValue): 762 cxx_type = 'float' 763 def __new__(self, value): | 750 751class MemoryBandwidth(float,ParamValue): 752 cxx_type = 'float' 753 def __new__(self, value): |
754 # we want the number of ticks per byte of data |
|
764 val = convert.toMemoryBandwidth(value) 765 return super(cls, MemoryBandwidth).__new__(cls, val) 766 767 def __str__(self): 768 return str(self.val) 769 770 def ini_str(self): | 755 val = convert.toMemoryBandwidth(value) 756 return super(cls, MemoryBandwidth).__new__(cls, val) 757 758 def __str__(self): 759 return str(self.val) 760 761 def ini_str(self): |
771 return '%f' % (ticks_per_sec / float(self)) | 762 # convert to seconds per byte 763 value = 1.0 / float(self) 764 # convert to ticks per byte 765 return '%f' % (ticks.fromSeconds(value)) |
772 773# 774# "Constants"... handy aliases for various values. 775# 776 777# Special class for NULL pointers. Note the special check in 778# make_param_value() above that lets these be assigned where a 779# SimObject is required. --- 238 unchanged lines hidden (view full) --- 1018 1019__all__ = ['Param', 'VectorParam', 1020 'Enum', 'Bool', 'String', 'Float', 1021 'Int', 'Unsigned', 'Int8', 'UInt8', 'Int16', 'UInt16', 1022 'Int32', 'UInt32', 'Int64', 'UInt64', 1023 'Counter', 'Addr', 'Tick', 'Percent', 1024 'TcpPort', 'UdpPort', 'EthernetAddr', 1025 'MemorySize', 'MemorySize32', | 766 767# 768# "Constants"... handy aliases for various values. 769# 770 771# Special class for NULL pointers. Note the special check in 772# make_param_value() above that lets these be assigned where a 773# SimObject is required. --- 238 unchanged lines hidden (view full) --- 1012 1013__all__ = ['Param', 'VectorParam', 1014 'Enum', 'Bool', 'String', 'Float', 1015 'Int', 'Unsigned', 'Int8', 'UInt8', 'Int16', 'UInt16', 1016 'Int32', 'UInt32', 'Int64', 'UInt64', 1017 'Counter', 'Addr', 'Tick', 'Percent', 1018 'TcpPort', 'UdpPort', 'EthernetAddr', 1019 'MemorySize', 'MemorySize32', |
1026 'Latency', 'Frequency', 'RootClock', 'Clock', | 1020 'Latency', 'Frequency', 'Clock', |
1027 'NetworkBandwidth', 'MemoryBandwidth', 1028 'Range', 'AddrRange', 'TickRange', 1029 'MaxAddr', 'MaxTick', 'AllMemory', 1030 'Time', 1031 'NextEthernetAddr', 'NULL', 1032 'Port', 'VectorPort'] 1033 1034# see comment on imports at end of __init__.py. 1035from SimObject import isSimObject, isSimObjectSequence, isSimObjectClass 1036import proxy 1037import objects 1038import internal | 1021 'NetworkBandwidth', 'MemoryBandwidth', 1022 'Range', 'AddrRange', 'TickRange', 1023 'MaxAddr', 'MaxTick', 'AllMemory', 1024 'Time', 1025 'NextEthernetAddr', 'NULL', 1026 'Port', 'VectorPort'] 1027 1028# see comment on imports at end of __init__.py. 1029from SimObject import isSimObject, isSimObjectSequence, isSimObjectClass 1030import proxy 1031import objects 1032import internal |