Deleted Added
sdiff udiff text old ( 4123:9c80390ea1bb ) new ( 4167:ce5d0f62f13b )
full compact
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
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
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
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):
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"']
674 def __init__(self, value):
675 self.value = getLatency(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):
686 return str(tick_check(self.value * ticks_per_sec))
687
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"']
693 def __init__(self, value):
694 self.value = 1 / getLatency(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
703 # convert frequency to ticks per period
704 def ini_str(self):
705 return self.period.ini_str()
706
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):
737 self.value = getLatency(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):
752 val = convert.toNetworkBandwidth(value) / 8.0
753 return super(cls, NetworkBandwidth).__new__(cls, val)
754
755 def __str__(self):
756 return str(self.val)
757
758 def ini_str(self):
759 return '%f' % (ticks_per_sec / float(self))
760
761class MemoryBandwidth(float,ParamValue):
762 cxx_type = 'float'
763 def __new__(self, value):
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):
771 return '%f' % (ticks_per_sec / float(self))
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',
1026 'Latency', 'Frequency', 'RootClock', '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