Prefetcher.py revision 13551
112837Sgabeblack@google.com# Copyright (c) 2012, 2014 ARM Limited
212837Sgabeblack@google.com# All rights reserved.
312837Sgabeblack@google.com#
412837Sgabeblack@google.com# The license below extends only to copyright in the software and shall
512837Sgabeblack@google.com# not be construed as granting a license to any other intellectual
612837Sgabeblack@google.com# property including but not limited to intellectual property relating
712837Sgabeblack@google.com# to a hardware implementation of the functionality of the software
812837Sgabeblack@google.com# licensed hereunder.  You may use the software subject to the license
912837Sgabeblack@google.com# terms below provided that you ensure that this notice is replicated
1012837Sgabeblack@google.com# unmodified and in its entirety in all distributions of the software,
1112837Sgabeblack@google.com# modified or unmodified, in source code or in binary form.
1212837Sgabeblack@google.com#
1312837Sgabeblack@google.com# Copyright (c) 2005 The Regents of The University of Michigan
1412837Sgabeblack@google.com# All rights reserved.
1512837Sgabeblack@google.com#
1612837Sgabeblack@google.com# Redistribution and use in source and binary forms, with or without
1712837Sgabeblack@google.com# modification, are permitted provided that the following conditions are
1812837Sgabeblack@google.com# met: redistributions of source code must retain the above copyright
1912837Sgabeblack@google.com# notice, this list of conditions and the following disclaimer;
2012837Sgabeblack@google.com# redistributions in binary form must reproduce the above copyright
2112837Sgabeblack@google.com# notice, this list of conditions and the following disclaimer in the
2212837Sgabeblack@google.com# documentation and/or other materials provided with the distribution;
2312837Sgabeblack@google.com# neither the name of the copyright holders nor the names of its
2412837Sgabeblack@google.com# contributors may be used to endorse or promote products derived from
2512837Sgabeblack@google.com# this software without specific prior written permission.
2612837Sgabeblack@google.com#
2712837Sgabeblack@google.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2812837Sgabeblack@google.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2912837Sgabeblack@google.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3012837Sgabeblack@google.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3112955Sgabeblack@google.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3212837Sgabeblack@google.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3313279Sgabeblack@google.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3412837Sgabeblack@google.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3512837Sgabeblack@google.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3612837Sgabeblack@google.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3712837Sgabeblack@google.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3812955Sgabeblack@google.com#
3912955Sgabeblack@google.com# Authors: Ron Dreslinski
4012955Sgabeblack@google.com#          Mitch Hayenga
4112955Sgabeblack@google.com
4212955Sgabeblack@google.comfrom ClockedObject import ClockedObject
4312955Sgabeblack@google.comfrom m5.SimObject import *
4412955Sgabeblack@google.comfrom m5.params import *
4512955Sgabeblack@google.comfrom m5.proxy import *
4612955Sgabeblack@google.comfrom ReplacementPolicies import *
4712955Sgabeblack@google.com
4812955Sgabeblack@google.comclass HWPProbeEvent(object):
4912955Sgabeblack@google.com    def __init__(self, prefetcher, obj, *listOfNames):
5012837Sgabeblack@google.com        self.obj = obj
5112955Sgabeblack@google.com        self.prefetcher = prefetcher
5212837Sgabeblack@google.com        self.names = listOfNames
5312837Sgabeblack@google.com
5412955Sgabeblack@google.com    def register(self):
5512955Sgabeblack@google.com        if self.obj:
5612955Sgabeblack@google.com            for name in self.names:
5712837Sgabeblack@google.com                self.prefetcher.getCCObject().addEventProbe(
5812955Sgabeblack@google.com                    self.obj.getCCObject(), name)
5912837Sgabeblack@google.com
6012837Sgabeblack@google.comclass BasePrefetcher(ClockedObject):
6112955Sgabeblack@google.com    type = 'BasePrefetcher'
6212837Sgabeblack@google.com    abstract = True
6312955Sgabeblack@google.com    cxx_header = "mem/cache/prefetch/base.hh"
6412837Sgabeblack@google.com    cxx_exports = [
6512837Sgabeblack@google.com        PyBindMethod("addEventProbe"),
6612837Sgabeblack@google.com    ]
6712837Sgabeblack@google.com    sys = Param.System(Parent.any, "System this prefetcher belongs to")
6812837Sgabeblack@google.com
6912837Sgabeblack@google.com    # Get the block size from the parent (system)
7012955Sgabeblack@google.com    block_size = Param.Int(Parent.cache_line_size, "Block size in bytes")
7112837Sgabeblack@google.com
7212837Sgabeblack@google.com    on_miss = Param.Bool(False, "Only notify prefetcher on misses")
7312837Sgabeblack@google.com    on_read = Param.Bool(True, "Notify prefetcher on reads")
7412955Sgabeblack@google.com    on_write = Param.Bool(True, "Notify prefetcher on writes")
7512837Sgabeblack@google.com    on_data  = Param.Bool(True, "Notify prefetcher on data accesses")
7612955Sgabeblack@google.com    on_inst  = Param.Bool(True, "Notify prefetcher on instruction accesses")
7712837Sgabeblack@google.com    prefetch_on_access = Param.Bool(Parent.prefetch_on_access,
7812837Sgabeblack@google.com        "Notify the hardware prefetcher on every access (not just misses)")
7912837Sgabeblack@google.com    use_virtual_addresses = Param.Bool(False,
8012955Sgabeblack@google.com        "Use virtual addresses for prefetching")
8112837Sgabeblack@google.com
8212955Sgabeblack@google.com    _events = []
8312837Sgabeblack@google.com    def addEvent(self, newObject):
8412837Sgabeblack@google.com        self._events.append(newObject)
8512837Sgabeblack@google.com
8612837Sgabeblack@google.com    # Override the normal SimObject::regProbeListeners method and
8712955Sgabeblack@google.com    # register deferred event handlers.
8812837Sgabeblack@google.com    def regProbeListeners(self):
8912955Sgabeblack@google.com        for event in self._events:
9012837Sgabeblack@google.com           event.register()
9112837Sgabeblack@google.com        self.getCCObject().regProbeListeners()
9212837Sgabeblack@google.com
9312837Sgabeblack@google.com    def listenFromProbe(self, simObj, *probeNames):
9412955Sgabeblack@google.com        if not isinstance(simObj, SimObject):
9512837Sgabeblack@google.com            raise TypeError("argument must be of SimObject type")
9612955Sgabeblack@google.com        if len(probeNames) <= 0:
9712955Sgabeblack@google.com            raise TypeError("probeNames must have at least one element")
9812955Sgabeblack@google.com        self.addEvent(HWPProbeEvent(self, simObj, *probeNames))
9912955Sgabeblack@google.com
10012837Sgabeblack@google.comclass QueuedPrefetcher(BasePrefetcher):
10112837Sgabeblack@google.com    type = "QueuedPrefetcher"
10212837Sgabeblack@google.com    abstract = True
10312955Sgabeblack@google.com    cxx_class = "QueuedPrefetcher"
10412837Sgabeblack@google.com    cxx_header = "mem/cache/prefetch/queued.hh"
10512955Sgabeblack@google.com    latency = Param.Int(1, "Latency for generated prefetches")
10612955Sgabeblack@google.com    queue_size = Param.Int(32, "Maximum number of queued prefetches")
10712955Sgabeblack@google.com    queue_squash = Param.Bool(True, "Squash queued prefetch on demand access")
10812955Sgabeblack@google.com    queue_filter = Param.Bool(True, "Don't queue redundant prefetches")
10912837Sgabeblack@google.com    cache_snoop = Param.Bool(False, "Snoop cache to eliminate redundant request")
11012837Sgabeblack@google.com
11112955Sgabeblack@google.com    tag_prefetch = Param.Bool(True, "Tag prefetch with PC of generating access")
11212955Sgabeblack@google.com
11312837Sgabeblack@google.comclass StridePrefetcher(QueuedPrefetcher):
11412955Sgabeblack@google.com    type = 'StridePrefetcher'
11512837Sgabeblack@google.com    cxx_class = 'StridePrefetcher'
11612837Sgabeblack@google.com    cxx_header = "mem/cache/prefetch/stride.hh"
11712955Sgabeblack@google.com
11812955Sgabeblack@google.com    # Do not consult stride prefetcher on instruction accesses
11912837Sgabeblack@google.com    on_inst = False
12012955Sgabeblack@google.com
12112837Sgabeblack@google.com    max_conf = Param.Int(7, "Maximum confidence level")
12212837Sgabeblack@google.com    thresh_conf = Param.Int(4, "Threshold confidence level")
12312955Sgabeblack@google.com    min_conf = Param.Int(0, "Minimum confidence level")
12412955Sgabeblack@google.com    start_conf = Param.Int(4, "Starting confidence for new entries")
12512955Sgabeblack@google.com
12612955Sgabeblack@google.com    table_sets = Param.Int(16, "Number of sets in PC lookup table")
12712955Sgabeblack@google.com    table_assoc = Param.Int(4, "Associativity of PC lookup table")
12812955Sgabeblack@google.com    use_master_id = Param.Bool(True, "Use master id based history")
12912955Sgabeblack@google.com
13012955Sgabeblack@google.com    degree = Param.Int(4, "Number of prefetches to generate")
13112955Sgabeblack@google.com
13212955Sgabeblack@google.com    # Get replacement policy
13312955Sgabeblack@google.com    replacement_policy = Param.BaseReplacementPolicy(RandomRP(),
13412955Sgabeblack@google.com        "Replacement policy")
13512837Sgabeblack@google.com
13612955Sgabeblack@google.comclass TaggedPrefetcher(QueuedPrefetcher):
13712837Sgabeblack@google.com    type = 'TaggedPrefetcher'
13812837Sgabeblack@google.com    cxx_class = 'TaggedPrefetcher'
13912955Sgabeblack@google.com    cxx_header = "mem/cache/prefetch/tagged.hh"
14012955Sgabeblack@google.com
14112955Sgabeblack@google.com    degree = Param.Int(2, "Number of prefetches to generate")
14212955Sgabeblack@google.com