caches.py revision 12072
111104Spower.jg@gmail.com# -*- coding: utf-8 -*-
211104Spower.jg@gmail.com# Copyright (c) 2015 Jason Power
311104Spower.jg@gmail.com# All rights reserved.
411104Spower.jg@gmail.com#
511104Spower.jg@gmail.com# Redistribution and use in source and binary forms, with or without
611104Spower.jg@gmail.com# modification, are permitted provided that the following conditions are
711104Spower.jg@gmail.com# met: redistributions of source code must retain the above copyright
811104Spower.jg@gmail.com# notice, this list of conditions and the following disclaimer;
911104Spower.jg@gmail.com# redistributions in binary form must reproduce the above copyright
1011104Spower.jg@gmail.com# notice, this list of conditions and the following disclaimer in the
1111104Spower.jg@gmail.com# documentation and/or other materials provided with the distribution;
1211104Spower.jg@gmail.com# neither the name of the copyright holders nor the names of its
1311104Spower.jg@gmail.com# contributors may be used to endorse or promote products derived from
1411104Spower.jg@gmail.com# this software without specific prior written permission.
1511104Spower.jg@gmail.com#
1611104Spower.jg@gmail.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1711104Spower.jg@gmail.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1811104Spower.jg@gmail.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1911104Spower.jg@gmail.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2011104Spower.jg@gmail.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2111104Spower.jg@gmail.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2211104Spower.jg@gmail.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2311104Spower.jg@gmail.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2411104Spower.jg@gmail.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2511104Spower.jg@gmail.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2611104Spower.jg@gmail.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2711104Spower.jg@gmail.com#
2811104Spower.jg@gmail.com# Authors: Jason Power
2911104Spower.jg@gmail.com
3011104Spower.jg@gmail.com""" Caches with options for a simple gem5 configuration script
3111104Spower.jg@gmail.com
3211104Spower.jg@gmail.comThis file contains L1 I/D and L2 caches to be used in the simple
3311104Spower.jg@gmail.comgem5 configuration script. It uses the SimpleOpts wrapper to set up command
3411104Spower.jg@gmail.comline options from each individual class.
3511104Spower.jg@gmail.com"""
3612072Sperise@gmail.comimport m5
3712072Sperise@gmail.comfrom m5.objects import Cache
3811104Spower.jg@gmail.com
3912072Sperise@gmail.com# Add the common scripts to our path
4012072Sperise@gmail.comm5.util.addToPath('../../')
4111104Spower.jg@gmail.com
4211682Sandreas.hansson@arm.comfrom common import SimpleOpts
4311104Spower.jg@gmail.com
4411104Spower.jg@gmail.com# Some specific options for caches
4511104Spower.jg@gmail.com# For all options see src/mem/cache/BaseCache.py
4611104Spower.jg@gmail.com
4711104Spower.jg@gmail.comclass L1Cache(Cache):
4811104Spower.jg@gmail.com    """Simple L1 Cache with default values"""
4911104Spower.jg@gmail.com
5011104Spower.jg@gmail.com    assoc = 2
5111722Ssophiane.senni@gmail.com    tag_latency = 2
5211722Ssophiane.senni@gmail.com    data_latency = 2
5311104Spower.jg@gmail.com    response_latency = 2
5411104Spower.jg@gmail.com    mshrs = 4
5511104Spower.jg@gmail.com    tgts_per_mshr = 20
5611104Spower.jg@gmail.com
5711104Spower.jg@gmail.com    def __init__(self, options=None):
5811104Spower.jg@gmail.com        super(L1Cache, self).__init__()
5911104Spower.jg@gmail.com        pass
6011104Spower.jg@gmail.com
6111104Spower.jg@gmail.com    def connectBus(self, bus):
6211104Spower.jg@gmail.com        """Connect this cache to a memory-side bus"""
6311104Spower.jg@gmail.com        self.mem_side = bus.slave
6411104Spower.jg@gmail.com
6511104Spower.jg@gmail.com    def connectCPU(self, cpu):
6611104Spower.jg@gmail.com        """Connect this cache's port to a CPU-side port
6711104Spower.jg@gmail.com           This must be defined in a subclass"""
6811104Spower.jg@gmail.com        raise NotImplementedError
6911104Spower.jg@gmail.com
7011104Spower.jg@gmail.comclass L1ICache(L1Cache):
7111104Spower.jg@gmail.com    """Simple L1 instruction cache with default values"""
7211104Spower.jg@gmail.com
7311104Spower.jg@gmail.com    # Set the default size
7411104Spower.jg@gmail.com    size = '16kB'
7511104Spower.jg@gmail.com
7611104Spower.jg@gmail.com    SimpleOpts.add_option('--l1i_size',
7711104Spower.jg@gmail.com                          help="L1 instruction cache size. Default: %s" % size)
7811104Spower.jg@gmail.com
7911104Spower.jg@gmail.com    def __init__(self, opts=None):
8011104Spower.jg@gmail.com        super(L1ICache, self).__init__(opts)
8111104Spower.jg@gmail.com        if not opts or not opts.l1i_size:
8211104Spower.jg@gmail.com            return
8311104Spower.jg@gmail.com        self.size = opts.l1i_size
8411104Spower.jg@gmail.com
8511104Spower.jg@gmail.com    def connectCPU(self, cpu):
8611104Spower.jg@gmail.com        """Connect this cache's port to a CPU icache port"""
8711104Spower.jg@gmail.com        self.cpu_side = cpu.icache_port
8811104Spower.jg@gmail.com
8911104Spower.jg@gmail.comclass L1DCache(L1Cache):
9011104Spower.jg@gmail.com    """Simple L1 data cache with default values"""
9111104Spower.jg@gmail.com
9211104Spower.jg@gmail.com    # Set the default size
9311104Spower.jg@gmail.com    size = '64kB'
9411104Spower.jg@gmail.com
9511104Spower.jg@gmail.com    SimpleOpts.add_option('--l1d_size',
9611104Spower.jg@gmail.com                          help="L1 data cache size. Default: %s" % size)
9711104Spower.jg@gmail.com
9811104Spower.jg@gmail.com    def __init__(self, opts=None):
9911104Spower.jg@gmail.com        super(L1DCache, self).__init__(opts)
10011104Spower.jg@gmail.com        if not opts or not opts.l1d_size:
10111104Spower.jg@gmail.com            return
10211104Spower.jg@gmail.com        self.size = opts.l1d_size
10311104Spower.jg@gmail.com
10411104Spower.jg@gmail.com    def connectCPU(self, cpu):
10511104Spower.jg@gmail.com        """Connect this cache's port to a CPU dcache port"""
10611104Spower.jg@gmail.com        self.cpu_side = cpu.dcache_port
10711104Spower.jg@gmail.com
10811104Spower.jg@gmail.comclass L2Cache(Cache):
10911104Spower.jg@gmail.com    """Simple L2 Cache with default values"""
11011104Spower.jg@gmail.com
11111104Spower.jg@gmail.com    # Default parameters
11211104Spower.jg@gmail.com    size = '256kB'
11311104Spower.jg@gmail.com    assoc = 8
11411722Ssophiane.senni@gmail.com    tag_latency = 20
11511722Ssophiane.senni@gmail.com    data_latency = 20
11611104Spower.jg@gmail.com    response_latency = 20
11711104Spower.jg@gmail.com    mshrs = 20
11811104Spower.jg@gmail.com    tgts_per_mshr = 12
11911104Spower.jg@gmail.com
12011104Spower.jg@gmail.com    SimpleOpts.add_option('--l2_size', help="L2 cache size. Default: %s" % size)
12111104Spower.jg@gmail.com
12211104Spower.jg@gmail.com    def __init__(self, opts=None):
12311104Spower.jg@gmail.com        super(L2Cache, self).__init__()
12411104Spower.jg@gmail.com        if not opts or not opts.l2_size:
12511104Spower.jg@gmail.com            return
12611104Spower.jg@gmail.com        self.size = opts.l2_size
12711104Spower.jg@gmail.com
12811104Spower.jg@gmail.com    def connectCPUSideBus(self, bus):
12911104Spower.jg@gmail.com        self.cpu_side = bus.master
13011104Spower.jg@gmail.com
13111104Spower.jg@gmail.com    def connectMemSideBus(self, bus):
13211104Spower.jg@gmail.com        self.mem_side = bus.slave
133