Prefetcher.py revision 13551
12623SN/A# Copyright (c) 2012, 2014 ARM Limited 22623SN/A# All rights reserved. 32623SN/A# 42623SN/A# The license below extends only to copyright in the software and shall 52623SN/A# not be construed as granting a license to any other intellectual 62623SN/A# property including but not limited to intellectual property relating 72623SN/A# to a hardware implementation of the functionality of the software 82623SN/A# licensed hereunder. You may use the software subject to the license 92623SN/A# terms below provided that you ensure that this notice is replicated 102623SN/A# unmodified and in its entirety in all distributions of the software, 112623SN/A# modified or unmodified, in source code or in binary form. 122623SN/A# 132623SN/A# Copyright (c) 2005 The Regents of The University of Michigan 142623SN/A# All rights reserved. 152623SN/A# 162623SN/A# Redistribution and use in source and binary forms, with or without 172623SN/A# modification, are permitted provided that the following conditions are 182623SN/A# met: redistributions of source code must retain the above copyright 192623SN/A# notice, this list of conditions and the following disclaimer; 202623SN/A# redistributions in binary form must reproduce the above copyright 212623SN/A# notice, this list of conditions and the following disclaimer in the 222623SN/A# documentation and/or other materials provided with the distribution; 232623SN/A# neither the name of the copyright holders nor the names of its 242623SN/A# contributors may be used to endorse or promote products derived from 252623SN/A# this software without specific prior written permission. 262623SN/A# 272665Ssaidi@eecs.umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 282665Ssaidi@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 292623SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 302623SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 313170Sstever@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 322623SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 332623SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 342623SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 352623SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 362623SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 372901Ssaidi@eecs.umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 382623SN/A# 392623SN/A# Authors: Ron Dreslinski 402623SN/A# Mitch Hayenga 412623SN/A 422623SN/Afrom ClockedObject import ClockedObject 432623SN/Afrom m5.SimObject import * 442623SN/Afrom m5.params import * 452623SN/Afrom m5.proxy import * 462623SN/Afrom ReplacementPolicies import * 472623SN/A 482623SN/Aclass HWPProbeEvent(object): 492623SN/A def __init__(self, prefetcher, obj, *listOfNames): 502623SN/A self.obj = obj 512623SN/A self.prefetcher = prefetcher 522623SN/A self.names = listOfNames 532623SN/A 542623SN/A def register(self): 552623SN/A if self.obj: 562623SN/A for name in self.names: 572623SN/A self.prefetcher.getCCObject().addEventProbe( 582623SN/A self.obj.getCCObject(), name) 592623SN/A 602856Srdreslin@umich.educlass BasePrefetcher(ClockedObject): 612856Srdreslin@umich.edu type = 'BasePrefetcher' 622856Srdreslin@umich.edu abstract = True 632856Srdreslin@umich.edu cxx_header = "mem/cache/prefetch/base.hh" 642856Srdreslin@umich.edu cxx_exports = [ 652856Srdreslin@umich.edu PyBindMethod("addEventProbe"), 662856Srdreslin@umich.edu ] 672856Srdreslin@umich.edu sys = Param.System(Parent.any, "System this prefetcher belongs to") 682856Srdreslin@umich.edu 692856Srdreslin@umich.edu # Get the block size from the parent (system) 702623SN/A block_size = Param.Int(Parent.cache_line_size, "Block size in bytes") 712623SN/A 722623SN/A on_miss = Param.Bool(False, "Only notify prefetcher on misses") 732623SN/A on_read = Param.Bool(True, "Notify prefetcher on reads") 742623SN/A on_write = Param.Bool(True, "Notify prefetcher on writes") 752856Srdreslin@umich.edu on_data = Param.Bool(True, "Notify prefetcher on data accesses") 762856Srdreslin@umich.edu on_inst = Param.Bool(True, "Notify prefetcher on instruction accesses") 772856Srdreslin@umich.edu prefetch_on_access = Param.Bool(Parent.prefetch_on_access, 782623SN/A "Notify the hardware prefetcher on every access (not just misses)") 792856Srdreslin@umich.edu use_virtual_addresses = Param.Bool(False, 802856Srdreslin@umich.edu "Use virtual addresses for prefetching") 812856Srdreslin@umich.edu 822623SN/A _events = [] 832623SN/A def addEvent(self, newObject): 842623SN/A self._events.append(newObject) 852680Sktlim@umich.edu 862680Sktlim@umich.edu # Override the normal SimObject::regProbeListeners method and 872623SN/A # register deferred event handlers. 882623SN/A def regProbeListeners(self): 892680Sktlim@umich.edu for event in self._events: 902623SN/A event.register() 912623SN/A self.getCCObject().regProbeListeners() 922623SN/A 932623SN/A def listenFromProbe(self, simObj, *probeNames): 942623SN/A if not isinstance(simObj, SimObject): 952630SN/A raise TypeError("argument must be of SimObject type") 962623SN/A if len(probeNames) <= 0: 973184Srdreslin@umich.edu raise TypeError("probeNames must have at least one element") 982623SN/A self.addEvent(HWPProbeEvent(self, simObj, *probeNames)) 992623SN/A 1002623SN/Aclass QueuedPrefetcher(BasePrefetcher): 1012623SN/A type = "QueuedPrefetcher" 1022630SN/A abstract = True 1032623SN/A cxx_class = "QueuedPrefetcher" 1042623SN/A cxx_header = "mem/cache/prefetch/queued.hh" 1052623SN/A latency = Param.Int(1, "Latency for generated prefetches") 1062623SN/A queue_size = Param.Int(32, "Maximum number of queued prefetches") 1072623SN/A queue_squash = Param.Bool(True, "Squash queued prefetch on demand access") 1082623SN/A queue_filter = Param.Bool(True, "Don't queue redundant prefetches") 1092630SN/A cache_snoop = Param.Bool(False, "Snoop cache to eliminate redundant request") 1102623SN/A 1113184Srdreslin@umich.edu tag_prefetch = Param.Bool(True, "Tag prefetch with PC of generating access") 1123184Srdreslin@umich.edu 1132623SN/Aclass StridePrefetcher(QueuedPrefetcher): 1142623SN/A type = 'StridePrefetcher' 1152623SN/A cxx_class = 'StridePrefetcher' 1162623SN/A cxx_header = "mem/cache/prefetch/stride.hh" 1172623SN/A 1182626SN/A # Do not consult stride prefetcher on instruction accesses 1192626SN/A on_inst = False 1202626SN/A 1212623SN/A max_conf = Param.Int(7, "Maximum confidence level") 1222623SN/A thresh_conf = Param.Int(4, "Threshold confidence level") 1232623SN/A min_conf = Param.Int(0, "Minimum confidence level") 1242657Ssaidi@eecs.umich.edu start_conf = Param.Int(4, "Starting confidence for new entries") 1252623SN/A 1262623SN/A table_sets = Param.Int(16, "Number of sets in PC lookup table") 1272623SN/A table_assoc = Param.Int(4, "Associativity of PC lookup table") 1282623SN/A use_master_id = Param.Bool(True, "Use master id based history") 1292623SN/A 1302623SN/A degree = Param.Int(4, "Number of prefetches to generate") 1312623SN/A 1322623SN/A # Get replacement policy 1332623SN/A replacement_policy = Param.BaseReplacementPolicy(RandomRP(), 1342640Sstever@eecs.umich.edu "Replacement policy") 1352623SN/A 1362623SN/Aclass TaggedPrefetcher(QueuedPrefetcher): 1372623SN/A type = 'TaggedPrefetcher' 1382663Sstever@eecs.umich.edu cxx_class = 'TaggedPrefetcher' 1393170Sstever@eecs.umich.edu cxx_header = "mem/cache/prefetch/tagged.hh" 1402641Sstever@eecs.umich.edu 1412623SN/A degree = Param.Int(2, "Number of prefetches to generate") 1422623SN/A