HWPConfig.py revision 13876:1643f200987c
15347Ssaidi@eecs.umich.edu# Copyright (c) 2018 Metempsy Technology Consulting 23395Shsul@eecs.umich.edu# All rights reserved. 33395Shsul@eecs.umich.edu# 43395Shsul@eecs.umich.edu# Redistribution and use in source and binary forms, with or without 53395Shsul@eecs.umich.edu# modification, are permitted provided that the following conditions are 63395Shsul@eecs.umich.edu# met: redistributions of source code must retain the above copyright 73395Shsul@eecs.umich.edu# notice, this list of conditions and the following disclaimer; 83395Shsul@eecs.umich.edu# redistributions in binary form must reproduce the above copyright 93395Shsul@eecs.umich.edu# notice, this list of conditions and the following disclaimer in the 103395Shsul@eecs.umich.edu# documentation and/or other materials provided with the distribution; 113395Shsul@eecs.umich.edu# neither the name of the copyright holders nor the names of its 123395Shsul@eecs.umich.edu# contributors may be used to endorse or promote products derived from 133395Shsul@eecs.umich.edu# this software without specific prior written permission. 143395Shsul@eecs.umich.edu# 153395Shsul@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 163395Shsul@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 173395Shsul@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 183395Shsul@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 193395Shsul@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 203395Shsul@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 213395Shsul@eecs.umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 223395Shsul@eecs.umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 233395Shsul@eecs.umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 243395Shsul@eecs.umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 253395Shsul@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 263395Shsul@eecs.umich.edu# 273395Shsul@eecs.umich.edu# Authors: Pau Cabre 283395Shsul@eecs.umich.edu 293395Shsul@eecs.umich.edu# This file is a copy of MemConfig.py / CpuConfig.py, but modified to 303509Shsul@eecs.umich.edu# hanle branch predictors instead of memory controllers / CPUs 313395Shsul@eecs.umich.edu 323395Shsul@eecs.umich.edufrom __future__ import print_function 333395Shsul@eecs.umich.edufrom __future__ import absolute_import 343448Shsul@eecs.umich.edu 353395Shsul@eecs.umich.edufrom m5 import fatal 363481Shsul@eecs.umich.eduimport m5.objects 373481Shsul@eecs.umich.eduimport inspect 383481Shsul@eecs.umich.eduimport sys 393481Shsul@eecs.umich.edufrom textwrap import TextWrapper 405347Ssaidi@eecs.umich.edu 413481Shsul@eecs.umich.edu# Dictionary of mapping names of real branch predictor models to classes. 423681Sktlim@umich.edu_hwp_classes = {} 433681Sktlim@umich.edu 443681Sktlim@umich.edu 455347Ssaidi@eecs.umich.edudef is_hwp_class(cls): 463481Shsul@eecs.umich.edu """Determine if a class is a prefetcher that can be instantiated""" 475347Ssaidi@eecs.umich.edu 483481Shsul@eecs.umich.edu # We can't use the normal inspect.isclass because the ParamFactory 493481Shsul@eecs.umich.edu # and ProxyFactory classes have a tendency to confuse it. 503481Shsul@eecs.umich.edu try: 513481Shsul@eecs.umich.edu return issubclass(cls, m5.objects.BasePrefetcher) and \ 523481Shsul@eecs.umich.edu not cls.abstract 533481Shsul@eecs.umich.edu except (TypeError, AttributeError): 543481Shsul@eecs.umich.edu return False 553481Shsul@eecs.umich.edu 565347Ssaidi@eecs.umich.edudef get(name): 573481Shsul@eecs.umich.edu """Get a HWP class from a user provided class name or alias.""" 583481Shsul@eecs.umich.edu 593481Shsul@eecs.umich.edu try: 603481Shsul@eecs.umich.edu hwp_class = _hwp_classes[name] 613481Shsul@eecs.umich.edu return hwp_class 623481Shsul@eecs.umich.edu except KeyError: 633481Shsul@eecs.umich.edu print("%s is not a valid HWP model." % (name,)) 643395Shsul@eecs.umich.edu sys.exit(1) 653395Shsul@eecs.umich.edu 663395Shsul@eecs.umich.edudef print_hwp_list(): 674167Sbinkertn@umich.edu """Print a list of available HWP classes.""" 683395Shsul@eecs.umich.edu 693395Shsul@eecs.umich.edu print("Available Hardware Prefetcher classes:") 703395Shsul@eecs.umich.edu doc_wrapper = TextWrapper(initial_indent="\t\t", subsequent_indent="\t\t") 713511Shsul@eecs.umich.edu for name, cls in _hwp_classes.items(): 723395Shsul@eecs.umich.edu print("\t%s" % name) 733395Shsul@eecs.umich.edu 743395Shsul@eecs.umich.edu # Try to extract the class documentation from the class help 755211Ssaidi@eecs.umich.edu # string. 765211Ssaidi@eecs.umich.edu doc = inspect.getdoc(cls) 773395Shsul@eecs.umich.edu if doc: 783395Shsul@eecs.umich.edu for line in doc_wrapper.wrap(doc): 793395Shsul@eecs.umich.edu print(line) 803395Shsul@eecs.umich.edu 813395Shsul@eecs.umich.edudef hwp_names(): 823481Shsul@eecs.umich.edu """Return a list of valid Hardware Prefetcher names.""" 833481Shsul@eecs.umich.edu return list(_hwp_classes.keys()) 843481Shsul@eecs.umich.edu 853481Shsul@eecs.umich.edu# Add all HWPs in the object hierarchy. 863481Shsul@eecs.umich.edufor name, cls in inspect.getmembers(m5.objects, is_hwp_class): 873481Shsul@eecs.umich.edu _hwp_classes[name] = cls 883481Shsul@eecs.umich.edu 893481Shsul@eecs.umich.edu