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 |
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 |
636# how big does a rounding error need to be before we warn about it? 637frequency_tolerance = 0.001 # 0.1% 638 |
639class TickParamValue(NumericParamValue): |
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): |
646 def __init__(self, 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) |
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): |
669 if self.ticks or self.value == 0: 670 return '%d' % self.value 671 else: 672 return '%d' % (ticks.fromSeconds(self.value)) |
673 |
674class Frequency(TickParamValue): |
675 def __init__(self, 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) |
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 |
696 # convert latency to ticks |
697 def ini_str(self): |
698 if self.ticks or self.value == 0: 699 return '%d' % self.value 700 else: 701 return '%d' % (ticks.fromSeconds(1.0 / self.value)) |
702 |
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): |
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) |
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): |
738 # convert to bits per second 739 val = convert.toNetworkBandwidth(value) |
740 return super(cls, NetworkBandwidth).__new__(cls, val) 741 742 def __str__(self): 743 return str(self.val) 744 745 def ini_str(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)) |
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 |
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): |
762 # convert to seconds per byte 763 value = 1.0 / float(self) 764 # convert to ticks per byte 765 return '%f' % (ticks.fromSeconds(value)) |
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', |
1020 'Latency', 'Frequency', 'Clock', |
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 |