Prefetcher.py revision 13624:3d8220c2d41d
112853Sgabeblack@google.com# Copyright (c) 2012, 2014 ARM Limited
212853Sgabeblack@google.com# All rights reserved.
312853Sgabeblack@google.com#
412853Sgabeblack@google.com# The license below extends only to copyright in the software and shall
512853Sgabeblack@google.com# not be construed as granting a license to any other intellectual
612853Sgabeblack@google.com# property including but not limited to intellectual property relating
712853Sgabeblack@google.com# to a hardware implementation of the functionality of the software
812853Sgabeblack@google.com# licensed hereunder.  You may use the software subject to the license
912853Sgabeblack@google.com# terms below provided that you ensure that this notice is replicated
1012853Sgabeblack@google.com# unmodified and in its entirety in all distributions of the software,
1112853Sgabeblack@google.com# modified or unmodified, in source code or in binary form.
1212853Sgabeblack@google.com#
1312853Sgabeblack@google.com# Copyright (c) 2005 The Regents of The University of Michigan
1412853Sgabeblack@google.com# All rights reserved.
1512853Sgabeblack@google.com#
1612853Sgabeblack@google.com# Redistribution and use in source and binary forms, with or without
1712853Sgabeblack@google.com# modification, are permitted provided that the following conditions are
1812853Sgabeblack@google.com# met: redistributions of source code must retain the above copyright
1912853Sgabeblack@google.com# notice, this list of conditions and the following disclaimer;
2012853Sgabeblack@google.com# redistributions in binary form must reproduce the above copyright
2112853Sgabeblack@google.com# notice, this list of conditions and the following disclaimer in the
2212853Sgabeblack@google.com# documentation and/or other materials provided with the distribution;
2312853Sgabeblack@google.com# neither the name of the copyright holders nor the names of its
2412853Sgabeblack@google.com# contributors may be used to endorse or promote products derived from
2512853Sgabeblack@google.com# this software without specific prior written permission.
2612853Sgabeblack@google.com#
2712853Sgabeblack@google.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2812853Sgabeblack@google.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2912853Sgabeblack@google.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3012853Sgabeblack@google.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3112853Sgabeblack@google.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3212853Sgabeblack@google.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3312853Sgabeblack@google.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3412853Sgabeblack@google.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3512853Sgabeblack@google.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3612853Sgabeblack@google.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3712853Sgabeblack@google.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3812853Sgabeblack@google.com#
3912853Sgabeblack@google.com# Authors: Ron Dreslinski
4012853Sgabeblack@google.com#          Mitch Hayenga
4112853Sgabeblack@google.com
4212853Sgabeblack@google.comfrom ClockedObject import ClockedObject
4312853Sgabeblack@google.comfrom IndexingPolicies import *
4412853Sgabeblack@google.comfrom m5.SimObject import *
4512853Sgabeblack@google.comfrom m5.params import *
4612853Sgabeblack@google.comfrom m5.proxy import *
4712853Sgabeblack@google.comfrom ReplacementPolicies import *
4812853Sgabeblack@google.com
4912853Sgabeblack@google.comclass HWPProbeEvent(object):
5012853Sgabeblack@google.com    def __init__(self, prefetcher, obj, *listOfNames):
5112853Sgabeblack@google.com        self.obj = obj
5212853Sgabeblack@google.com        self.prefetcher = prefetcher
5312853Sgabeblack@google.com        self.names = listOfNames
5412853Sgabeblack@google.com
5512853Sgabeblack@google.com    def register(self):
5612853Sgabeblack@google.com        if self.obj:
5712853Sgabeblack@google.com            for name in self.names:
5812853Sgabeblack@google.com                self.prefetcher.getCCObject().addEventProbe(
5912853Sgabeblack@google.com                    self.obj.getCCObject(), name)
6012853Sgabeblack@google.com
6112853Sgabeblack@google.comclass BasePrefetcher(ClockedObject):
6212853Sgabeblack@google.com    type = 'BasePrefetcher'
6312853Sgabeblack@google.com    abstract = True
6412853Sgabeblack@google.com    cxx_header = "mem/cache/prefetch/base.hh"
6512853Sgabeblack@google.com    cxx_exports = [
6612853Sgabeblack@google.com        PyBindMethod("addEventProbe"),
6712853Sgabeblack@google.com    ]
6812853Sgabeblack@google.com    sys = Param.System(Parent.any, "System this prefetcher belongs to")
6912853Sgabeblack@google.com
7012853Sgabeblack@google.com    # Get the block size from the parent (system)
7112853Sgabeblack@google.com    block_size = Param.Int(Parent.cache_line_size, "Block size in bytes")
7212853Sgabeblack@google.com
7312853Sgabeblack@google.com    on_miss = Param.Bool(False, "Only notify prefetcher on misses")
7412853Sgabeblack@google.com    on_read = Param.Bool(True, "Notify prefetcher on reads")
7512853Sgabeblack@google.com    on_write = Param.Bool(True, "Notify prefetcher on writes")
7612853Sgabeblack@google.com    on_data  = Param.Bool(True, "Notify prefetcher on data accesses")
7712853Sgabeblack@google.com    on_inst  = Param.Bool(True, "Notify prefetcher on instruction accesses")
7812853Sgabeblack@google.com    prefetch_on_access = Param.Bool(Parent.prefetch_on_access,
7912853Sgabeblack@google.com        "Notify the hardware prefetcher on every access (not just misses)")
8012853Sgabeblack@google.com    use_virtual_addresses = Param.Bool(False,
8112853Sgabeblack@google.com        "Use virtual addresses for prefetching")
8212853Sgabeblack@google.com
8312853Sgabeblack@google.com    _events = []
8412853Sgabeblack@google.com    def addEvent(self, newObject):
8512853Sgabeblack@google.com        self._events.append(newObject)
8612853Sgabeblack@google.com
8712853Sgabeblack@google.com    # Override the normal SimObject::regProbeListeners method and
8812853Sgabeblack@google.com    # register deferred event handlers.
8912853Sgabeblack@google.com    def regProbeListeners(self):
9012853Sgabeblack@google.com        for event in self._events:
9112853Sgabeblack@google.com           event.register()
9212853Sgabeblack@google.com        self.getCCObject().regProbeListeners()
9312853Sgabeblack@google.com
9412853Sgabeblack@google.com    def listenFromProbe(self, simObj, *probeNames):
9512853Sgabeblack@google.com        if not isinstance(simObj, SimObject):
9612853Sgabeblack@google.com            raise TypeError("argument must be of SimObject type")
9712853Sgabeblack@google.com        if len(probeNames) <= 0:
9812853Sgabeblack@google.com            raise TypeError("probeNames must have at least one element")
9912853Sgabeblack@google.com        self.addEvent(HWPProbeEvent(self, simObj, *probeNames))
10012853Sgabeblack@google.com
10112853Sgabeblack@google.comclass QueuedPrefetcher(BasePrefetcher):
10212853Sgabeblack@google.com    type = "QueuedPrefetcher"
10312853Sgabeblack@google.com    abstract = True
10412853Sgabeblack@google.com    cxx_class = "QueuedPrefetcher"
10512853Sgabeblack@google.com    cxx_header = "mem/cache/prefetch/queued.hh"
10612853Sgabeblack@google.com    latency = Param.Int(1, "Latency for generated prefetches")
10712853Sgabeblack@google.com    queue_size = Param.Int(32, "Maximum number of queued prefetches")
10812853Sgabeblack@google.com    queue_squash = Param.Bool(True, "Squash queued prefetch on demand access")
10912853Sgabeblack@google.com    queue_filter = Param.Bool(True, "Don't queue redundant prefetches")
11012853Sgabeblack@google.com    cache_snoop = Param.Bool(False, "Snoop cache to eliminate redundant request")
11112853Sgabeblack@google.com
11212853Sgabeblack@google.com    tag_prefetch = Param.Bool(True, "Tag prefetch with PC of generating access")
11312853Sgabeblack@google.com
11412853Sgabeblack@google.comclass StridePrefetcher(QueuedPrefetcher):
11512853Sgabeblack@google.com    type = 'StridePrefetcher'
11612853Sgabeblack@google.com    cxx_class = 'StridePrefetcher'
11712853Sgabeblack@google.com    cxx_header = "mem/cache/prefetch/stride.hh"
11812853Sgabeblack@google.com
11912853Sgabeblack@google.com    # Do not consult stride prefetcher on instruction accesses
12012853Sgabeblack@google.com    on_inst = False
12112853Sgabeblack@google.com
12212853Sgabeblack@google.com    max_conf = Param.Int(7, "Maximum confidence level")
12312853Sgabeblack@google.com    thresh_conf = Param.Int(4, "Threshold confidence level")
12412853Sgabeblack@google.com    min_conf = Param.Int(0, "Minimum confidence level")
12512853Sgabeblack@google.com    start_conf = Param.Int(4, "Starting confidence for new entries")
12612853Sgabeblack@google.com
12712853Sgabeblack@google.com    table_sets = Param.Int(16, "Number of sets in PC lookup table")
12812853Sgabeblack@google.com    table_assoc = Param.Int(4, "Associativity of PC lookup table")
12912853Sgabeblack@google.com    use_master_id = Param.Bool(True, "Use master id based history")
13012853Sgabeblack@google.com
13112853Sgabeblack@google.com    degree = Param.Int(4, "Number of prefetches to generate")
13212853Sgabeblack@google.com
13312853Sgabeblack@google.com    # Get replacement policy
13412853Sgabeblack@google.com    replacement_policy = Param.BaseReplacementPolicy(RandomRP(),
13512853Sgabeblack@google.com        "Replacement policy")
13612853Sgabeblack@google.com
13712853Sgabeblack@google.comclass TaggedPrefetcher(QueuedPrefetcher):
13812853Sgabeblack@google.com    type = 'TaggedPrefetcher'
13912853Sgabeblack@google.com    cxx_class = 'TaggedPrefetcher'
14012853Sgabeblack@google.com    cxx_header = "mem/cache/prefetch/tagged.hh"
14112853Sgabeblack@google.com
14212853Sgabeblack@google.com    degree = Param.Int(2, "Number of prefetches to generate")
14312853Sgabeblack@google.com
14412853Sgabeblack@google.comclass SignaturePathPrefetcher(QueuedPrefetcher):
14512853Sgabeblack@google.com    type = 'SignaturePathPrefetcher'
14612853Sgabeblack@google.com    cxx_class = 'SignaturePathPrefetcher'
14712853Sgabeblack@google.com    cxx_header = "mem/cache/prefetch/signature_path.hh"
14812853Sgabeblack@google.com
14912853Sgabeblack@google.com    signature_shift = Param.UInt8(3,
15012853Sgabeblack@google.com        "Number of bits to shift when calculating a new signature");
15112853Sgabeblack@google.com    signature_bits = Param.UInt16(12,
15212853Sgabeblack@google.com        "Size of the signature, in bits");
15312853Sgabeblack@google.com    signature_table_entries = Param.MemorySize("1024",
15412853Sgabeblack@google.com        "Number of entries of the signature table")
15512853Sgabeblack@google.com    signature_table_assoc = Param.Unsigned(2,
15612853Sgabeblack@google.com        "Associativity of the signature table")
15712853Sgabeblack@google.com    signature_table_indexing_policy = Param.BaseIndexingPolicy(
15812853Sgabeblack@google.com        SetAssociative(entry_size = 1, assoc = Parent.signature_table_assoc,
15912853Sgabeblack@google.com        size = Parent.signature_table_entries),
16012853Sgabeblack@google.com        "Indexing policy of the signature table")
16112853Sgabeblack@google.com    signature_table_replacement_policy = Param.BaseReplacementPolicy(LRURP(),
16212853Sgabeblack@google.com        "Replacement policy of the signature table")
16312853Sgabeblack@google.com
16412853Sgabeblack@google.com    max_counter_value = Param.UInt8(7, "Maximum pattern counter value")
16512853Sgabeblack@google.com    pattern_table_entries = Param.MemorySize("4096",
16612853Sgabeblack@google.com        "Number of entries of the pattern table")
16712853Sgabeblack@google.com    pattern_table_assoc = Param.Unsigned(1,
16812853Sgabeblack@google.com        "Associativity of the pattern table")
16912853Sgabeblack@google.com    strides_per_pattern_entry = Param.Unsigned(4,
17012853Sgabeblack@google.com        "Number of strides stored in each pattern entry")
17112853Sgabeblack@google.com    pattern_table_indexing_policy = Param.BaseIndexingPolicy(
17212853Sgabeblack@google.com        SetAssociative(entry_size = 1, assoc = Parent.pattern_table_assoc,
17312853Sgabeblack@google.com        size = Parent.pattern_table_entries),
17412853Sgabeblack@google.com        "Indexing policy of the pattern table")
17512853Sgabeblack@google.com    pattern_table_replacement_policy = Param.BaseReplacementPolicy(LRURP(),
17612853Sgabeblack@google.com        "Replacement policy of the pattern table")
17712853Sgabeblack@google.com
17812853Sgabeblack@google.com    prefetch_confidence_threshold = Param.Float(0.5,
17912853Sgabeblack@google.com        "Minimum confidence to issue prefetches")
18012853Sgabeblack@google.com    lookahead_confidence_threshold = Param.Float(0.75,
18112853Sgabeblack@google.com        "Minimum confidence to continue exploring lookahead entries")
18212853Sgabeblack@google.com
18312853Sgabeblack@google.comclass SignaturePathPrefetcherV2(SignaturePathPrefetcher):
18412853Sgabeblack@google.com    type = 'SignaturePathPrefetcherV2'
18512853Sgabeblack@google.com    cxx_class = 'SignaturePathPrefetcherV2'
18612853Sgabeblack@google.com    cxx_header = "mem/cache/prefetch/signature_path_v2.hh"
18712853Sgabeblack@google.com
18812853Sgabeblack@google.com    signature_table_entries = "256"
18912853Sgabeblack@google.com    signature_table_assoc = 1
19012853Sgabeblack@google.com    pattern_table_entries = "512"
19112853Sgabeblack@google.com    pattern_table_assoc = 1
19212853Sgabeblack@google.com    max_counter_value = 15
19312853Sgabeblack@google.com    prefetch_confidence_threshold = 0.25
19412853Sgabeblack@google.com    lookahead_confidence_threshold = 0.25
19512853Sgabeblack@google.com
19612853Sgabeblack@google.com    global_history_register_entries = Param.MemorySize("8",
19712853Sgabeblack@google.com        "Number of entries of global history register")
19812853Sgabeblack@google.com    global_history_register_indexing_policy = Param.BaseIndexingPolicy(
19912853Sgabeblack@google.com        SetAssociative(entry_size = 1,
200        assoc = Parent.global_history_register_entries,
201        size = Parent.global_history_register_entries),
202        "Indexing policy of the global history register")
203    global_history_register_replacement_policy = Param.BaseReplacementPolicy(
204        LRURP(), "Replacement policy of the global history register")
205
206class AccessMapPatternMatchingPrefetcher(QueuedPrefetcher):
207    type = 'AccessMapPatternMatchingPrefetcher'
208    cxx_class = 'AccessMapPatternMatchingPrefetcher'
209    cxx_header = "mem/cache/prefetch/access_map_pattern_matching.hh"
210
211    start_degree = Param.Unsigned(4,
212        "Initial degree (Maximum number of prefetches generated")
213    hot_zone_size = Param.MemorySize("2kB", "Memory covered by a hot zone")
214    access_map_table_entries = Param.MemorySize("256",
215        "Number of entries in the access map table")
216    access_map_table_assoc = Param.Unsigned(8,
217        "Associativity of the access map table")
218    access_map_table_indexing_policy = Param.BaseIndexingPolicy(
219        SetAssociative(entry_size = 1, assoc = Parent.access_map_table_assoc,
220        size = Parent.access_map_table_entries),
221        "Indexing policy of the access map table")
222    access_map_table_replacement_policy = Param.BaseReplacementPolicy(LRURP(),
223        "Replacement policy of the access map table")
224    high_coverage_threshold = Param.Float(0.25,
225        "A prefetch coverage factor bigger than this is considered high")
226    low_coverage_threshold = Param.Float(0.125,
227        "A prefetch coverage factor smaller than this is considered low")
228    high_accuracy_threshold = Param.Float(0.5,
229        "A prefetch accuracy factor bigger than this is considered high")
230    low_accuracy_threshold = Param.Float(0.25,
231        "A prefetch accuracy factor smaller than this is considered low")
232    high_cache_hit_threshold = Param.Float(0.875,
233        "A cache hit ratio bigger than this is considered high")
234    low_cache_hit_threshold = Param.Float(0.75,
235        "A cache hit ratio smaller than this is considered low")
236    epoch_cycles = Param.Cycles(256000, "Cycles in an epoch period")
237    offchip_memory_latency = Param.Latency("30ns",
238        "Memory latency used to compute the required memory bandwidth")
239