Prefetcher.py revision 13554:f16adb9b35cc
12SN/A# Copyright (c) 2012, 2014 ARM Limited 24039Sbinkertn@umich.edu# All rights reserved. 32SN/A# 42SN/A# The license below extends only to copyright in the software and shall 52SN/A# not be construed as granting a license to any other intellectual 62SN/A# property including but not limited to intellectual property relating 72SN/A# to a hardware implementation of the functionality of the software 82SN/A# licensed hereunder. You may use the software subject to the license 92SN/A# terms below provided that you ensure that this notice is replicated 102SN/A# unmodified and in its entirety in all distributions of the software, 112SN/A# modified or unmodified, in source code or in binary form. 122SN/A# 132SN/A# Copyright (c) 2005 The Regents of The University of Michigan 142SN/A# All rights reserved. 152SN/A# 162SN/A# Redistribution and use in source and binary forms, with or without 172SN/A# modification, are permitted provided that the following conditions are 182SN/A# met: redistributions of source code must retain the above copyright 192SN/A# notice, this list of conditions and the following disclaimer; 202SN/A# redistributions in binary form must reproduce the above copyright 212SN/A# notice, this list of conditions and the following disclaimer in the 222SN/A# documentation and/or other materials provided with the distribution; 232SN/A# neither the name of the copyright holders nor the names of its 242SN/A# contributors may be used to endorse or promote products derived from 252SN/A# this software without specific prior written permission. 262SN/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 292665Ssaidi@eecs.umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 302SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 312SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 328229Snate@binkert.org# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 332SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 342SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 352SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 362SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 3756SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 384046Sbinkertn@umich.edu# 394046Sbinkertn@umich.edu# Authors: Ron Dreslinski 4056SN/A# Mitch Hayenga 414039Sbinkertn@umich.edu 422SN/Afrom ClockedObject import ClockedObject 432SN/Afrom IndexingPolicies import * 442SN/Afrom m5.SimObject import * 452SN/Afrom m5.params import * 468232Snate@binkert.orgfrom m5.proxy import * 472SN/Afrom ReplacementPolicies import * 484074Sbinkertn@umich.edu 492SN/Aclass HWPProbeEvent(object): 502SN/A def __init__(self, prefetcher, obj, *listOfNames): 512SN/A self.obj = obj 522SN/A self.prefetcher = prefetcher 532SN/A self.names = listOfNames 542SN/A 552SN/A def register(self): 56488SN/A if self.obj: 574046Sbinkertn@umich.edu for name in self.names: 584046Sbinkertn@umich.edu self.prefetcher.getCCObject().addEventProbe( 594046Sbinkertn@umich.edu self.obj.getCCObject(), name) 604046Sbinkertn@umich.edu 614046Sbinkertn@umich.educlass BasePrefetcher(ClockedObject): 624046Sbinkertn@umich.edu type = 'BasePrefetcher' 634046Sbinkertn@umich.edu abstract = True 644046Sbinkertn@umich.edu cxx_header = "mem/cache/prefetch/base.hh" 654046Sbinkertn@umich.edu cxx_exports = [ 664046Sbinkertn@umich.edu PyBindMethod("addEventProbe"), 674046Sbinkertn@umich.edu ] 682SN/A sys = Param.System(Parent.any, "System this prefetcher belongs to") 691031SN/A 702SN/A # Get the block size from the parent (system) 714046Sbinkertn@umich.edu block_size = Param.Int(Parent.cache_line_size, "Block size in bytes") 724046Sbinkertn@umich.edu 734046Sbinkertn@umich.edu on_miss = Param.Bool(False, "Only notify prefetcher on misses") 744046Sbinkertn@umich.edu on_read = Param.Bool(True, "Notify prefetcher on reads") 754046Sbinkertn@umich.edu on_write = Param.Bool(True, "Notify prefetcher on writes") 764046Sbinkertn@umich.edu on_data = Param.Bool(True, "Notify prefetcher on data accesses") 772SN/A on_inst = Param.Bool(True, "Notify prefetcher on instruction accesses") 784046Sbinkertn@umich.edu prefetch_on_access = Param.Bool(Parent.prefetch_on_access, 792SN/A "Notify the hardware prefetcher on every access (not just misses)") 802SN/A use_virtual_addresses = Param.Bool(False, 814046Sbinkertn@umich.edu "Use virtual addresses for prefetching") 822SN/A 832SN/A _events = [] 842SN/A def addEvent(self, newObject): 854039Sbinkertn@umich.edu self._events.append(newObject) 862SN/A 872SN/A # Override the normal SimObject::regProbeListeners method and 884046Sbinkertn@umich.edu # register deferred event handlers. 892SN/A def regProbeListeners(self): 904046Sbinkertn@umich.edu for event in self._events: 912SN/A event.register() 922SN/A self.getCCObject().regProbeListeners() 932SN/A 942SN/A def listenFromProbe(self, simObj, *probeNames): 954039Sbinkertn@umich.edu if not isinstance(simObj, SimObject): 962SN/A raise TypeError("argument must be of SimObject type") 972SN/A if len(probeNames) <= 0: 982SN/A raise TypeError("probeNames must have at least one element") 994046Sbinkertn@umich.edu self.addEvent(HWPProbeEvent(self, simObj, *probeNames)) 1004046Sbinkertn@umich.edu 1012SN/Aclass QueuedPrefetcher(BasePrefetcher): 1024046Sbinkertn@umich.edu type = "QueuedPrefetcher" 1034046Sbinkertn@umich.edu abstract = True 1042SN/A cxx_class = "QueuedPrefetcher" 1054046Sbinkertn@umich.edu cxx_header = "mem/cache/prefetch/queued.hh" 1062SN/A latency = Param.Int(1, "Latency for generated prefetches") 1074046Sbinkertn@umich.edu queue_size = Param.Int(32, "Maximum number of queued prefetches") 1084046Sbinkertn@umich.edu queue_squash = Param.Bool(True, "Squash queued prefetch on demand access") 1094046Sbinkertn@umich.edu queue_filter = Param.Bool(True, "Don't queue redundant prefetches") 1104046Sbinkertn@umich.edu cache_snoop = Param.Bool(False, "Snoop cache to eliminate redundant request") 1114046Sbinkertn@umich.edu 1124046Sbinkertn@umich.edu tag_prefetch = Param.Bool(True, "Tag prefetch with PC of generating access") 1134046Sbinkertn@umich.edu 1144046Sbinkertn@umich.educlass StridePrefetcher(QueuedPrefetcher): 1154046Sbinkertn@umich.edu type = 'StridePrefetcher' 1164046Sbinkertn@umich.edu cxx_class = 'StridePrefetcher' 1174046Sbinkertn@umich.edu cxx_header = "mem/cache/prefetch/stride.hh" 1184046Sbinkertn@umich.edu 1194046Sbinkertn@umich.edu # Do not consult stride prefetcher on instruction accesses 1204046Sbinkertn@umich.edu on_inst = False 1212SN/A 1222SN/A max_conf = Param.Int(7, "Maximum confidence level") 1234046Sbinkertn@umich.edu thresh_conf = Param.Int(4, "Threshold confidence level") 1244046Sbinkertn@umich.edu min_conf = Param.Int(0, "Minimum confidence level") 1252SN/A start_conf = Param.Int(4, "Starting confidence for new entries") 1262SN/A 1272SN/A table_sets = Param.Int(16, "Number of sets in PC lookup table") 1282SN/A table_assoc = Param.Int(4, "Associativity of PC lookup table") 1292SN/A use_master_id = Param.Bool(True, "Use master id based history") 1302SN/A 1312SN/A degree = Param.Int(4, "Number of prefetches to generate") 1322SN/A 1332SN/A # Get replacement policy 1342SN/A replacement_policy = Param.BaseReplacementPolicy(RandomRP(), 1352SN/A "Replacement policy") 1362SN/A 1372SN/Aclass TaggedPrefetcher(QueuedPrefetcher): 1382SN/A type = 'TaggedPrefetcher' 1392SN/A cxx_class = 'TaggedPrefetcher' 1404046Sbinkertn@umich.edu cxx_header = "mem/cache/prefetch/tagged.hh" 1412SN/A 1422SN/A degree = Param.Int(2, "Number of prefetches to generate") 1432SN/A 1442SN/Aclass SignaturePathPrefetcher(QueuedPrefetcher): 1452SN/A type = 'SignaturePathPrefetcher' 1462SN/A cxx_class = 'SignaturePathPrefetcher' 1472SN/A cxx_header = "mem/cache/prefetch/signature_path.hh" 1482SN/A 1494046Sbinkertn@umich.edu signature_shift = Param.UInt8(3, 1507811Ssteve.reinhardt@amd.com "Number of bits to shift when calculating a new signature"); 151 signature_bits = Param.UInt16(12, 152 "Size of the signature, in bits"); 153 signature_table_entries = Param.MemorySize("1024", 154 "Number of entries of the signature table") 155 signature_table_assoc = Param.Unsigned(2, 156 "Associativity of the signature table") 157 signature_table_indexing_policy = Param.BaseIndexingPolicy( 158 SetAssociative(entry_size = 1, assoc = Parent.signature_table_assoc, 159 size = Parent.signature_table_entries), 160 "Indexing policy of the signature table") 161 signature_table_replacement_policy = Param.BaseReplacementPolicy(LRURP(), 162 "Replacement policy of the signature table") 163 164 max_counter_value = Param.UInt8(7, "Maximum pattern counter value") 165 pattern_table_entries = Param.MemorySize("4096", 166 "Number of entries of the pattern table") 167 pattern_table_assoc = Param.Unsigned(1, 168 "Associativity of the pattern table") 169 strides_per_pattern_entry = Param.Unsigned(4, 170 "Number of strides stored in each pattern entry") 171 pattern_table_indexing_policy = Param.BaseIndexingPolicy( 172 SetAssociative(entry_size = 1, assoc = Parent.pattern_table_assoc, 173 size = Parent.pattern_table_entries), 174 "Indexing policy of the pattern table") 175 pattern_table_replacement_policy = Param.BaseReplacementPolicy(LRURP(), 176 "Replacement policy of the pattern table") 177 178 prefetch_confidence_threshold = Param.Float(0.5, 179 "Minimum confidence to issue prefetches") 180 lookahead_confidence_threshold = Param.Float(0.75, 181 "Minimum confidence to continue exploring lookahead entries") 182 183class AccessMapPatternMatchingPrefetcher(QueuedPrefetcher): 184 type = 'AccessMapPatternMatchingPrefetcher' 185 cxx_class = 'AccessMapPatternMatchingPrefetcher' 186 cxx_header = "mem/cache/prefetch/access_map_pattern_matching.hh" 187 188 start_degree = Param.Unsigned(4, 189 "Initial degree (Maximum number of prefetches generated") 190 hot_zone_size = Param.MemorySize("2kB", "Memory covered by a hot zone") 191 access_map_table_entries = Param.MemorySize("256", 192 "Number of entries in the access map table") 193 access_map_table_assoc = Param.Unsigned(8, 194 "Associativity of the access map table") 195 access_map_table_indexing_policy = Param.BaseIndexingPolicy( 196 SetAssociative(entry_size = 1, assoc = Parent.access_map_table_assoc, 197 size = Parent.access_map_table_entries), 198 "Indexing policy of the access map table") 199 access_map_table_replacement_policy = Param.BaseReplacementPolicy(LRURP(), 200 "Replacement policy of the access map table") 201 high_coverage_threshold = Param.Float(0.25, 202 "A prefetch coverage factor bigger than this is considered high") 203 low_coverage_threshold = Param.Float(0.125, 204 "A prefetch coverage factor smaller than this is considered low") 205 high_accuracy_threshold = Param.Float(0.5, 206 "A prefetch accuracy factor bigger than this is considered high") 207 low_accuracy_threshold = Param.Float(0.25, 208 "A prefetch accuracy factor smaller than this is considered low") 209 high_cache_hit_threshold = Param.Float(0.875, 210 "A cache hit ratio bigger than this is considered high") 211 low_cache_hit_threshold = Param.Float(0.75, 212 "A cache hit ratio smaller than this is considered low") 213 epoch_cycles = Param.Cycles(256000, "Cycles in an epoch period") 214 offchip_memory_latency = Param.Latency("30ns", 215 "Memory latency used to compute the required memory bandwidth") 216