BPConfig.py revision 13731:67cd980cb20f
12SN/A# Copyright (c) 2018 Metempsy Technology Consulting 213575Sciro.santilli@arm.com# All rights reserved. 313575Sciro.santilli@arm.com# 413575Sciro.santilli@arm.com# Redistribution and use in source and binary forms, with or without 513575Sciro.santilli@arm.com# modification, are permitted provided that the following conditions are 613575Sciro.santilli@arm.com# met: redistributions of source code must retain the above copyright 713575Sciro.santilli@arm.com# notice, this list of conditions and the following disclaimer; 813575Sciro.santilli@arm.com# redistributions in binary form must reproduce the above copyright 913575Sciro.santilli@arm.com# notice, this list of conditions and the following disclaimer in the 1013575Sciro.santilli@arm.com# documentation and/or other materials provided with the distribution; 1113575Sciro.santilli@arm.com# neither the name of the copyright holders nor the names of its 1213575Sciro.santilli@arm.com# contributors may be used to endorse or promote products derived from 1311274Sshingarov@labware.com# this software without specific prior written permission. 1410595Sgabeblack@google.com# 151762SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 162SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 172SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 182SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 192SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 202SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 212SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 222SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 232SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 242SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 252SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 262SN/A# 272SN/A# Authors: Pau Cabre 282SN/A 292SN/A# This file is a copy of MemConfig.py / CpuConfig.py, but modified to 302SN/A# hanle branch predictors instead of memory controllers / CPUs 312SN/A 322SN/Afrom __future__ import print_function 332SN/A 342SN/Afrom m5 import fatal 352SN/Aimport m5.objects 362SN/Aimport inspect 372SN/Aimport sys 382SN/Afrom textwrap import TextWrapper 392SN/A 402665Ssaidi@eecs.umich.edu# Dictionary of mapping names of real branch predictor models to classes. 412665Ssaidi@eecs.umich.edu_bp_classes = {} 4211274Sshingarov@labware.com 432SN/A 442SN/Adef is_bp_class(cls): 452SN/A """Determine if a class is a branch predictor that can be instantiated""" 462SN/A 472SN/A # We can't use the normal inspect.isclass because the ParamFactory 483960Sgblack@eecs.umich.edu # and ProxyFactory classes have a tendency to confuse it. 4977SN/A try: 5012031Sgabeblack@google.com return issubclass(cls, m5.objects.BranchPredictor) and \ 518229Snate@binkert.org not cls.abstract 5212031Sgabeblack@google.com except (TypeError, AttributeError): 538229Snate@binkert.org return False 542986Sgblack@eecs.umich.edu 5510595Sgabeblack@google.comdef get(name): 5656SN/A """Get a BP class from a user provided class name or alias.""" 5756SN/A 588229Snate@binkert.org try: 592SN/A bp_class = _bp_classes[name] 602SN/A return bp_class 612680Sktlim@umich.edu except KeyError: 622SN/A print("%s is not a valid BP model." % (name,)) 6312449Sgabeblack@google.com sys.exit(1) 6412449Sgabeblack@google.com 653536Sgblack@eecs.umich.edudef print_bp_list(): 6612449Sgabeblack@google.com """Print a list of available BP classes.""" 6712449Sgabeblack@google.com 6812449Sgabeblack@google.com print("Available BranchPredictor classes:") 6912449Sgabeblack@google.com doc_wrapper = TextWrapper(initial_indent="\t\t", subsequent_indent="\t\t") 7012449Sgabeblack@google.com for name, cls in _bp_classes.items(): 7112449Sgabeblack@google.com print("\t%s" % name) 7212449Sgabeblack@google.com 7312449Sgabeblack@google.com # Try to extract the class documentation from the class help 742SN/A # string. 7512031Sgabeblack@google.com doc = inspect.getdoc(cls) 7612031Sgabeblack@google.com if doc: 7712449Sgabeblack@google.com for line in doc_wrapper.wrap(doc): 7812449Sgabeblack@google.com print(line) 7912449Sgabeblack@google.com 8012449Sgabeblack@google.comdef bp_names(): 8112449Sgabeblack@google.com """Return a list of valid Branch Predictor names.""" 8212449Sgabeblack@google.com return list(_bp_classes.keys()) 8312031Sgabeblack@google.com 8412449Sgabeblack@google.com# Add all BPs in the object hierarchy. 8512449Sgabeblack@google.comfor name, cls in inspect.getmembers(m5.objects, is_bp_class): 8612449Sgabeblack@google.com _bp_classes[name] = cls 8712449Sgabeblack@google.com 8812449Sgabeblack@google.com