CpuConfig.py revision 11995
19520SAndreas.Sandberg@ARM.com# Copyright (c) 2012 ARM Limited
29520SAndreas.Sandberg@ARM.com# All rights reserved.
39520SAndreas.Sandberg@ARM.com#
49520SAndreas.Sandberg@ARM.com# The license below extends only to copyright in the software and shall
59520SAndreas.Sandberg@ARM.com# not be construed as granting a license to any other intellectual
69520SAndreas.Sandberg@ARM.com# property including but not limited to intellectual property relating
79520SAndreas.Sandberg@ARM.com# to a hardware implementation of the functionality of the software
89520SAndreas.Sandberg@ARM.com# licensed hereunder.  You may use the software subject to the license
99520SAndreas.Sandberg@ARM.com# terms below provided that you ensure that this notice is replicated
109520SAndreas.Sandberg@ARM.com# unmodified and in its entirety in all distributions of the software,
119520SAndreas.Sandberg@ARM.com# modified or unmodified, in source code or in binary form.
129520SAndreas.Sandberg@ARM.com#
139520SAndreas.Sandberg@ARM.com# Redistribution and use in source and binary forms, with or without
149520SAndreas.Sandberg@ARM.com# modification, are permitted provided that the following conditions are
159520SAndreas.Sandberg@ARM.com# met: redistributions of source code must retain the above copyright
169520SAndreas.Sandberg@ARM.com# notice, this list of conditions and the following disclaimer;
179520SAndreas.Sandberg@ARM.com# redistributions in binary form must reproduce the above copyright
189520SAndreas.Sandberg@ARM.com# notice, this list of conditions and the following disclaimer in the
199520SAndreas.Sandberg@ARM.com# documentation and/or other materials provided with the distribution;
209520SAndreas.Sandberg@ARM.com# neither the name of the copyright holders nor the names of its
219520SAndreas.Sandberg@ARM.com# contributors may be used to endorse or promote products derived from
229520SAndreas.Sandberg@ARM.com# this software without specific prior written permission.
239520SAndreas.Sandberg@ARM.com#
249520SAndreas.Sandberg@ARM.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
259520SAndreas.Sandberg@ARM.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
269520SAndreas.Sandberg@ARM.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
279520SAndreas.Sandberg@ARM.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
289520SAndreas.Sandberg@ARM.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
299520SAndreas.Sandberg@ARM.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
309520SAndreas.Sandberg@ARM.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
319520SAndreas.Sandberg@ARM.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
329520SAndreas.Sandberg@ARM.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
339520SAndreas.Sandberg@ARM.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
349520SAndreas.Sandberg@ARM.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
359520SAndreas.Sandberg@ARM.com#
369520SAndreas.Sandberg@ARM.com# Authors: Andreas Sandberg
379520SAndreas.Sandberg@ARM.com
389520SAndreas.Sandberg@ARM.comimport m5.objects
399520SAndreas.Sandberg@ARM.comimport inspect
409520SAndreas.Sandberg@ARM.comimport sys
4111995Sgabeblack@google.comfrom textwrap import TextWrapper
429520SAndreas.Sandberg@ARM.com
439520SAndreas.Sandberg@ARM.com# Dictionary of mapping names of real CPU models to classes.
449520SAndreas.Sandberg@ARM.com_cpu_classes = {}
459520SAndreas.Sandberg@ARM.com
469520SAndreas.Sandberg@ARM.com
479520SAndreas.Sandberg@ARM.comdef is_cpu_class(cls):
489520SAndreas.Sandberg@ARM.com    """Determine if a class is a CPU that can be instantiated"""
499520SAndreas.Sandberg@ARM.com
509520SAndreas.Sandberg@ARM.com    # We can't use the normal inspect.isclass because the ParamFactory
519520SAndreas.Sandberg@ARM.com    # and ProxyFactory classes have a tendency to confuse it.
529520SAndreas.Sandberg@ARM.com    try:
539520SAndreas.Sandberg@ARM.com        return issubclass(cls, m5.objects.BaseCPU) and \
549520SAndreas.Sandberg@ARM.com            not cls.abstract and \
559520SAndreas.Sandberg@ARM.com            not issubclass(cls, m5.objects.CheckerCPU)
5611688Sandreas.hansson@arm.com    except (TypeError, AttributeError):
579520SAndreas.Sandberg@ARM.com        return False
589520SAndreas.Sandberg@ARM.com
599520SAndreas.Sandberg@ARM.comdef get(name):
609520SAndreas.Sandberg@ARM.com    """Get a CPU class from a user provided class name or alias."""
619520SAndreas.Sandberg@ARM.com
629520SAndreas.Sandberg@ARM.com    try:
6311995Sgabeblack@google.com        cpu_class = _cpu_classes[name]
649520SAndreas.Sandberg@ARM.com        return cpu_class
659520SAndreas.Sandberg@ARM.com    except KeyError:
669520SAndreas.Sandberg@ARM.com        print "%s is not a valid CPU model." % (name,)
679520SAndreas.Sandberg@ARM.com        sys.exit(1)
689520SAndreas.Sandberg@ARM.com
699520SAndreas.Sandberg@ARM.comdef print_cpu_list():
709520SAndreas.Sandberg@ARM.com    """Print a list of available CPU classes including their aliases."""
719520SAndreas.Sandberg@ARM.com
729520SAndreas.Sandberg@ARM.com    print "Available CPU classes:"
739520SAndreas.Sandberg@ARM.com    doc_wrapper = TextWrapper(initial_indent="\t\t", subsequent_indent="\t\t")
749520SAndreas.Sandberg@ARM.com    for name, cls in _cpu_classes.items():
759520SAndreas.Sandberg@ARM.com        print "\t%s" % name
769520SAndreas.Sandberg@ARM.com
779520SAndreas.Sandberg@ARM.com        # Try to extract the class documentation from the class help
789520SAndreas.Sandberg@ARM.com        # string.
799520SAndreas.Sandberg@ARM.com        doc = inspect.getdoc(cls)
809520SAndreas.Sandberg@ARM.com        if doc:
819520SAndreas.Sandberg@ARM.com            for line in doc_wrapper.wrap(doc):
829520SAndreas.Sandberg@ARM.com                print line
839520SAndreas.Sandberg@ARM.com
849520SAndreas.Sandberg@ARM.comdef cpu_names():
859520SAndreas.Sandberg@ARM.com    """Return a list of valid CPU names."""
8611995Sgabeblack@google.com    return _cpu_classes.keys()
879520SAndreas.Sandberg@ARM.com
8811251Sradhika.jagtap@ARM.comdef config_etrace(cpu_cls, cpu_list, options):
8911251Sradhika.jagtap@ARM.com    if issubclass(cpu_cls, m5.objects.DerivO3CPU):
9011251Sradhika.jagtap@ARM.com        # Assign the same file name to all cpus for now. This must be
9111251Sradhika.jagtap@ARM.com        # revisited when creating elastic traces for multi processor systems.
9211251Sradhika.jagtap@ARM.com        for cpu in cpu_list:
9311251Sradhika.jagtap@ARM.com            # Attach the elastic trace probe listener. Set the protobuf trace
9411251Sradhika.jagtap@ARM.com            # file names. Set the dependency window size equal to the cpu it
9511251Sradhika.jagtap@ARM.com            # is attached to.
9611251Sradhika.jagtap@ARM.com            cpu.traceListener = m5.objects.ElasticTrace(
9711251Sradhika.jagtap@ARM.com                                instFetchTraceFile = options.inst_trace_file,
9811251Sradhika.jagtap@ARM.com                                dataDepTraceFile = options.data_trace_file,
9911251Sradhika.jagtap@ARM.com                                depWindowSize = 3 * cpu.numROBEntries)
10011251Sradhika.jagtap@ARM.com            # Make the number of entries in the ROB, LQ and SQ very
10111251Sradhika.jagtap@ARM.com            # large so that there are no stalls due to resource
10211251Sradhika.jagtap@ARM.com            # limitation as such stalls will get captured in the trace
10311251Sradhika.jagtap@ARM.com            # as compute delay. For replay, ROB, LQ and SQ sizes are
10411251Sradhika.jagtap@ARM.com            # modelled in the Trace CPU.
10511251Sradhika.jagtap@ARM.com            cpu.numROBEntries = 512;
10611251Sradhika.jagtap@ARM.com            cpu.LQEntries = 128;
10711251Sradhika.jagtap@ARM.com            cpu.SQEntries = 128;
10811251Sradhika.jagtap@ARM.com    else:
10911251Sradhika.jagtap@ARM.com        fatal("%s does not support data dependency tracing. Use a CPU model of"
11011251Sradhika.jagtap@ARM.com              " type or inherited from DerivO3CPU.", cpu_cls)
11111251Sradhika.jagtap@ARM.com
1129520SAndreas.Sandberg@ARM.com# The ARM detailed CPU is special in the sense that it doesn't exist
1139520SAndreas.Sandberg@ARM.com# in the normal object hierarchy, so we have to add it manually.
1149520SAndreas.Sandberg@ARM.comtry:
1159520SAndreas.Sandberg@ARM.com    from O3_ARM_v7a import O3_ARM_v7a_3
11611995Sgabeblack@google.com    _cpu_classes["O3_ARM_v7a_3"] = O3_ARM_v7a_3
1179520SAndreas.Sandberg@ARM.comexcept:
1189520SAndreas.Sandberg@ARM.com    pass
1199520SAndreas.Sandberg@ARM.com
1209520SAndreas.Sandberg@ARM.com# Add all CPUs in the object hierarchy.
1219520SAndreas.Sandberg@ARM.comfor name, cls in inspect.getmembers(m5.objects, is_cpu_class):
1229520SAndreas.Sandberg@ARM.com    _cpu_classes[name] = cls
123