Cache.py revision 12600
15222Sksewell@umich.edu# Copyright (c) 2012-2013, 2015 ARM Limited
25254Sksewell@umich.edu# All rights reserved.
35254Sksewell@umich.edu#
45222Sksewell@umich.edu# The license below extends only to copyright in the software and shall
55254Sksewell@umich.edu# not be construed as granting a license to any other intellectual
65254Sksewell@umich.edu# property including but not limited to intellectual property relating
75254Sksewell@umich.edu# to a hardware implementation of the functionality of the software
85254Sksewell@umich.edu# licensed hereunder.  You may use the software subject to the license
95254Sksewell@umich.edu# terms below provided that you ensure that this notice is replicated
105254Sksewell@umich.edu# unmodified and in its entirety in all distributions of the software,
115254Sksewell@umich.edu# modified or unmodified, in source code or in binary form.
125254Sksewell@umich.edu#
135254Sksewell@umich.edu# Copyright (c) 2005-2007 The Regents of The University of Michigan
145254Sksewell@umich.edu# All rights reserved.
155222Sksewell@umich.edu#
165254Sksewell@umich.edu# Redistribution and use in source and binary forms, with or without
175254Sksewell@umich.edu# modification, are permitted provided that the following conditions are
185254Sksewell@umich.edu# met: redistributions of source code must retain the above copyright
195254Sksewell@umich.edu# notice, this list of conditions and the following disclaimer;
205254Sksewell@umich.edu# redistributions in binary form must reproduce the above copyright
215254Sksewell@umich.edu# notice, this list of conditions and the following disclaimer in the
225254Sksewell@umich.edu# documentation and/or other materials provided with the distribution;
235254Sksewell@umich.edu# neither the name of the copyright holders nor the names of its
245254Sksewell@umich.edu# contributors may be used to endorse or promote products derived from
255254Sksewell@umich.edu# this software without specific prior written permission.
265254Sksewell@umich.edu#
275222Sksewell@umich.edu# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
285254Sksewell@umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
295222Sksewell@umich.edu# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
305222Sksewell@umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
315222Sksewell@umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
325222Sksewell@umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
335222Sksewell@umich.edu# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
345222Sksewell@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
355222Sksewell@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
365222Sksewell@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
375222Sksewell@umich.edu# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
385222Sksewell@umich.edu#
396378Sgblack@eecs.umich.edu# Authors: Nathan Binkert
405222Sksewell@umich.edu#          Andreas Hansson
415222Sksewell@umich.edu
425222Sksewell@umich.edufrom m5.params import *
435222Sksewell@umich.edufrom m5.proxy import *
445222Sksewell@umich.edufrom MemObject import MemObject
455222Sksewell@umich.edufrom Prefetcher import BasePrefetcher
466378Sgblack@eecs.umich.edufrom ReplacementPolicies import *
475222Sksewell@umich.edufrom Tags import *
485222Sksewell@umich.edu
495222Sksewell@umich.educlass BaseCache(MemObject):
505222Sksewell@umich.edu    type = 'BaseCache'
515222Sksewell@umich.edu    abstract = True
525704Snate@binkert.org    cxx_header = "mem/cache/base.hh"
535222Sksewell@umich.edu
546378Sgblack@eecs.umich.edu    size = Param.MemorySize("Capacity")
555222Sksewell@umich.edu    assoc = Param.Unsigned("Associativity")
565222Sksewell@umich.edu
575222Sksewell@umich.edu    tag_latency = Param.Cycles("Tag lookup latency")
585222Sksewell@umich.edu    data_latency = Param.Cycles("Data access latency")
595222Sksewell@umich.edu    response_latency = Param.Cycles("Latency for the return path on a miss");
605222Sksewell@umich.edu
615704Snate@binkert.org    warmup_percentage = Param.Percent(0,
625222Sksewell@umich.edu        "Percentage of tags to be touched to warm up the cache")
635222Sksewell@umich.edu
645222Sksewell@umich.edu    max_miss_count = Param.Counter(0,
655222Sksewell@umich.edu        "Number of misses to handle before calling exit")
665704Snate@binkert.org
675222Sksewell@umich.edu    mshrs = Param.Unsigned("Number of MSHRs (max outstanding requests)")
685222Sksewell@umich.edu    demand_mshr_reserve = Param.Unsigned(1, "MSHRs reserved for demand access")
695222Sksewell@umich.edu    tgts_per_mshr = Param.Unsigned("Max number of accesses per MSHR")
705704Snate@binkert.org    write_buffers = Param.Unsigned(8, "Number of write buffers")
715222Sksewell@umich.edu
726378Sgblack@eecs.umich.edu    is_read_only = Param.Bool(False, "Is this cache read only (e.g. inst)")
735704Snate@binkert.org
745222Sksewell@umich.edu    prefetcher = Param.BasePrefetcher(NULL,"Prefetcher attached to cache")
755222Sksewell@umich.edu    prefetch_on_access = Param.Bool(False,
765222Sksewell@umich.edu         "Notify the hardware prefetcher on every access (not just misses)")
775222Sksewell@umich.edu
785222Sksewell@umich.edu    tags = Param.BaseTags(BaseSetAssoc(), "Tag store")
795222Sksewell@umich.edu    replacement_policy = Param.BaseReplacementPolicy(LRURP(),
805222Sksewell@umich.edu        "Replacement policy")
816378Sgblack@eecs.umich.edu
825222Sksewell@umich.edu    sequential_access = Param.Bool(False,
835222Sksewell@umich.edu        "Whether to access tags and data sequentially")
845222Sksewell@umich.edu
855222Sksewell@umich.edu    cpu_side = SlavePort("Upstream port closer to the CPU and/or device")
865222Sksewell@umich.edu    mem_side = MasterPort("Downstream port closer to memory")
875222Sksewell@umich.edu
885222Sksewell@umich.edu    addr_ranges = VectorParam.AddrRange([AllMemory],
895222Sksewell@umich.edu         "Address range for the CPU-side port (to allow striping)")
905222Sksewell@umich.edu
915704Snate@binkert.org    system = Param.System(Parent.any, "System we belong to")
925704Snate@binkert.org
935704Snate@binkert.org# Enum for cache clusivity, currently mostly inclusive or mostly
945222Sksewell@umich.edu# exclusive.
955222Sksewell@umich.educlass Clusivity(Enum): vals = ['mostly_incl', 'mostly_excl']
965222Sksewell@umich.edu
975222Sksewell@umich.educlass Cache(BaseCache):
986378Sgblack@eecs.umich.edu    type = 'Cache'
996378Sgblack@eecs.umich.edu    cxx_header = 'mem/cache/cache.hh'
1005222Sksewell@umich.edu
1015222Sksewell@umich.edu    # Control whether this cache should be mostly inclusive or mostly
1025222Sksewell@umich.edu    # exclusive with respect to upstream caches. The behaviour on a
1035222Sksewell@umich.edu    # fill is determined accordingly. For a mostly inclusive cache,
1046378Sgblack@eecs.umich.edu    # blocks are allocated on all fill operations. Thus, L1 caches
1056378Sgblack@eecs.umich.edu    # should be set as mostly inclusive even if they have no upstream
1065222Sksewell@umich.edu    # caches. In the case of a mostly exclusive cache, fills are not
1075222Sksewell@umich.edu    # allocating unless they came directly from a non-caching source,
1085222Sksewell@umich.edu    # e.g. a table walker. Additionally, on a hit from an upstream
1095222Sksewell@umich.edu    # cache a line is dropped for a mostly exclusive cache.
1105222Sksewell@umich.edu    clusivity = Param.Clusivity('mostly_incl',
1115222Sksewell@umich.edu                                "Clusivity with upstream cache")
1125222Sksewell@umich.edu
1135222Sksewell@umich.edu    # Determine if this cache sends out writebacks for clean lines, or
1145222Sksewell@umich.edu    # simply clean evicts. In cases where a downstream cache is mostly
1155222Sksewell@umich.edu    # exclusive with respect to this cache (acting as a victim cache),
1165222Sksewell@umich.edu    # the clean writebacks are essential for performance. In general
1175222Sksewell@umich.edu    # this should be set to True for anything but the last-level
1185222Sksewell@umich.edu    # cache.
1195222Sksewell@umich.edu    writeback_clean = Param.Bool(False, "Writeback clean lines")
120