CpuConfig.py revision 9891:19fa1dfd583f
17513SN/A# Copyright (c) 2012 ARM Limited 27513SN/A# All rights reserved. 37513SN/A# 410036SAli.Saidi@ARM.com# The license below extends only to copyright in the software and shall 58835SAli.Saidi@ARM.com# not be construed as granting a license to any other intellectual 610036SAli.Saidi@ARM.com# property including but not limited to intellectual property relating 77935SN/A# to a hardware implementation of the functionality of the software 87935SN/A# licensed hereunder. You may use the software subject to the license 97935SN/A# terms below provided that you ensure that this notice is replicated 107513SN/A# unmodified and in its entirety in all distributions of the software, 117513SN/A# modified or unmodified, in source code or in binary form. 127513SN/A# 1310315Snilay@cs.wisc.edu# Redistribution and use in source and binary forms, with or without 148835SAli.Saidi@ARM.com# modification, are permitted provided that the following conditions are 159885Sstever@gmail.com# met: redistributions of source code must retain the above copyright 169885Sstever@gmail.com# notice, this list of conditions and the following disclaimer; 1711570SCurtis.Dunham@arm.com# redistributions in binary form must reproduce the above copyright 1810036SAli.Saidi@ARM.com# notice, this list of conditions and the following disclaimer in the 1911388Ssteve.reinhardt@amd.com# documentation and/or other materials provided with the distribution; 208835SAli.Saidi@ARM.com# neither the name of the copyright holders nor the names of its 218835SAli.Saidi@ARM.com# contributors may be used to endorse or promote products derived from 2210315Snilay@cs.wisc.edu# this software without specific prior written permission. 238835SAli.Saidi@ARM.com# 2410038SAli.Saidi@ARM.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 259481Snilay@cs.wisc.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 269481Snilay@cs.wisc.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 278721SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 2810900Snilay@cs.wisc.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2911388Ssteve.reinhardt@amd.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 308721SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3111570SCurtis.Dunham@arm.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 3211570SCurtis.Dunham@arm.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 3311570SCurtis.Dunham@arm.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3411570SCurtis.Dunham@arm.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 358835SAli.Saidi@ARM.com# 368835SAli.Saidi@ARM.com# Authors: Andreas Sandberg 3711515Sandreas.sandberg@arm.com 3811515Sandreas.sandberg@arm.comimport m5.objects 397935SN/Aimport inspect 407935SN/Aimport sys 417935SN/Afrom textwrap import TextWrapper 427935SN/A 437935SN/A# Dictionary of mapping names of real CPU models to classes. 447935SN/A_cpu_classes = {} 457935SN/A 468893Ssaidi@eecs.umich.edu# CPU aliases. The CPUs listed here might not be compiled, we make 477513SN/A# sure they exist before we add them to the CPU list. A target may be 489885Sstever@gmail.com# specified as a tuple, in which case the first available CPU model in 499885Sstever@gmail.com# the tuple will be used as the target. 509885Sstever@gmail.com_cpu_aliases_all = [ 5110315Snilay@cs.wisc.edu ("timing", "TimingSimpleCPU"), 5210036SAli.Saidi@ARM.com ("atomic", "AtomicSimpleCPU"), 5310315Snilay@cs.wisc.edu ("inorder", "InOrderCPU"), 549885Sstever@gmail.com ("detailed", "DerivO3CPU"), 559885Sstever@gmail.com ("kvm", ("ArmKvmCPU", "X86KvmCPU")), 567513SN/A ] 577513SN/A 5810038SAli.Saidi@ARM.com# Filtered list of aliases. Only aliases for existing CPUs exist in 5910315Snilay@cs.wisc.edu# this list. 607513SN/A_cpu_aliases = {} 619885Sstever@gmail.com 627513SN/A 6311570SCurtis.Dunham@arm.comdef is_cpu_class(cls): 647513SN/A """Determine if a class is a CPU that can be instantiated""" 658835SAli.Saidi@ARM.com 667513SN/A # We can't use the normal inspect.isclass because the ParamFactory 6710038SAli.Saidi@ARM.com # and ProxyFactory classes have a tendency to confuse it. 687513SN/A try: 6910036SAli.Saidi@ARM.com return issubclass(cls, m5.objects.BaseCPU) and \ 707513SN/A not cls.abstract and \ 717513SN/A not issubclass(cls, m5.objects.CheckerCPU) 728835SAli.Saidi@ARM.com except TypeError: 739481Snilay@cs.wisc.edu return False 7410038SAli.Saidi@ARM.com 757513SN/Adef get(name): 767513SN/A """Get a CPU class from a user provided class name or alias.""" 777513SN/A 787513SN/A real_name = _cpu_aliases.get(name, name) 797513SN/A 807513SN/A try: 8111570SCurtis.Dunham@arm.com cpu_class = _cpu_classes[real_name] 8211570SCurtis.Dunham@arm.com return cpu_class 8311570SCurtis.Dunham@arm.com except KeyError: 8411570SCurtis.Dunham@arm.com print "%s is not a valid CPU model." % (name,) 858835SAli.Saidi@ARM.com sys.exit(1) 867513SN/A 879885Sstever@gmail.comdef print_cpu_list(): 8810315Snilay@cs.wisc.edu """Print a list of available CPU classes including their aliases.""" 899481Snilay@cs.wisc.edu 9011960Sgabeblack@google.com print "Available CPU classes:" 917513SN/A doc_wrapper = TextWrapper(initial_indent="\t\t", subsequent_indent="\t\t") 927513SN/A for name, cls in _cpu_classes.items(): 937513SN/A print "\t%s" % name 947513SN/A 957513SN/A # Try to extract the class documentation from the class help 967513SN/A # string. 977513SN/A doc = inspect.getdoc(cls) 9811103Snilay@cs.wisc.edu if doc: 999885Sstever@gmail.com for line in doc_wrapper.wrap(doc): 10011960Sgabeblack@google.com print line 1017513SN/A 1029885Sstever@gmail.com if _cpu_aliases: 10311388Ssteve.reinhardt@amd.com print "\nCPU aliases:" 10411960Sgabeblack@google.com for alias, target in _cpu_aliases.items(): 10511570SCurtis.Dunham@arm.com print "\t%s => %s" % (alias, target) 10610900Snilay@cs.wisc.edu 10710036SAli.Saidi@ARM.comdef cpu_names(): 10810900Snilay@cs.wisc.edu """Return a list of valid CPU names.""" 1097513SN/A return _cpu_classes.keys() + _cpu_aliases.keys() 1109481Snilay@cs.wisc.edu 11111570SCurtis.Dunham@arm.com# The ARM detailed CPU is special in the sense that it doesn't exist 11211570SCurtis.Dunham@arm.com# in the normal object hierarchy, so we have to add it manually. 11311570SCurtis.Dunham@arm.comtry: 11411570SCurtis.Dunham@arm.com from O3_ARM_v7a import O3_ARM_v7a_3 1157513SN/A _cpu_classes["arm_detailed"] = O3_ARM_v7a_3 1168835SAli.Saidi@ARM.comexcept: 1179481Snilay@cs.wisc.edu pass 11810036SAli.Saidi@ARM.com 1197513SN/A# Add all CPUs in the object hierarchy. 1208835SAli.Saidi@ARM.comfor name, cls in inspect.getmembers(m5.objects, is_cpu_class): 12111960Sgabeblack@google.com _cpu_classes[name] = cls 1229885Sstever@gmail.com 1239481Snilay@cs.wisc.edufor alias, target in _cpu_aliases_all: 1247513SN/A if isinstance(target, tuple): 12511388Ssteve.reinhardt@amd.com # Some aliases contain a list of CPU model sorted in priority 1267513SN/A # order. Use the first target that's available. 1278893Ssaidi@eecs.umich.edu for t in target: 1287513SN/A if t in _cpu_classes: 1299885Sstever@gmail.com _cpu_aliases[alias] = t 1309885Sstever@gmail.com break 1319885Sstever@gmail.com elif target in _cpu_classes: 1329885Sstever@gmail.com # Normal alias 1339885Sstever@gmail.com _cpu_aliases[alias] = target 13411960Sgabeblack@google.com