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""" 3613774Sandreas.sandberg@arm.com 3713774Sandreas.sandberg@arm.comfrom __future__ import print_function 3813774Sandreas.sandberg@arm.comfrom __future__ import absolute_import 3913774Sandreas.sandberg@arm.com 4012072Sperise@gmail.comimport m5 4112072Sperise@gmail.comfrom m5.objects import Cache 4211104Spower.jg@gmail.com 4312072Sperise@gmail.com# Add the common scripts to our path 4412072Sperise@gmail.comm5.util.addToPath('../../') 4511104Spower.jg@gmail.com 4611682Sandreas.hansson@arm.comfrom common import SimpleOpts 4711104Spower.jg@gmail.com 4811104Spower.jg@gmail.com# Some specific options for caches 4911104Spower.jg@gmail.com# For all options see src/mem/cache/BaseCache.py 5011104Spower.jg@gmail.com 5111104Spower.jg@gmail.comclass L1Cache(Cache): 5211104Spower.jg@gmail.com """Simple L1 Cache with default values""" 5311104Spower.jg@gmail.com 5411104Spower.jg@gmail.com assoc = 2 5511722Ssophiane.senni@gmail.com tag_latency = 2 5611722Ssophiane.senni@gmail.com data_latency = 2 5711104Spower.jg@gmail.com response_latency = 2 5811104Spower.jg@gmail.com mshrs = 4 5911104Spower.jg@gmail.com tgts_per_mshr = 20 6011104Spower.jg@gmail.com 6111104Spower.jg@gmail.com def __init__(self, options=None): 6211104Spower.jg@gmail.com super(L1Cache, self).__init__() 6311104Spower.jg@gmail.com pass 6411104Spower.jg@gmail.com 6511104Spower.jg@gmail.com def connectBus(self, bus): 6611104Spower.jg@gmail.com """Connect this cache to a memory-side bus""" 6711104Spower.jg@gmail.com self.mem_side = bus.slave 6811104Spower.jg@gmail.com 6911104Spower.jg@gmail.com def connectCPU(self, cpu): 7011104Spower.jg@gmail.com """Connect this cache's port to a CPU-side port 7111104Spower.jg@gmail.com This must be defined in a subclass""" 7211104Spower.jg@gmail.com raise NotImplementedError 7311104Spower.jg@gmail.com 7411104Spower.jg@gmail.comclass L1ICache(L1Cache): 7511104Spower.jg@gmail.com """Simple L1 instruction cache with default values""" 7611104Spower.jg@gmail.com 7711104Spower.jg@gmail.com # Set the default size 7811104Spower.jg@gmail.com size = '16kB' 7911104Spower.jg@gmail.com 8011104Spower.jg@gmail.com SimpleOpts.add_option('--l1i_size', 8111104Spower.jg@gmail.com help="L1 instruction cache size. Default: %s" % size) 8211104Spower.jg@gmail.com 8311104Spower.jg@gmail.com def __init__(self, opts=None): 8411104Spower.jg@gmail.com super(L1ICache, self).__init__(opts) 8511104Spower.jg@gmail.com if not opts or not opts.l1i_size: 8611104Spower.jg@gmail.com return 8711104Spower.jg@gmail.com self.size = opts.l1i_size 8811104Spower.jg@gmail.com 8911104Spower.jg@gmail.com def connectCPU(self, cpu): 9011104Spower.jg@gmail.com """Connect this cache's port to a CPU icache port""" 9111104Spower.jg@gmail.com self.cpu_side = cpu.icache_port 9211104Spower.jg@gmail.com 9311104Spower.jg@gmail.comclass L1DCache(L1Cache): 9411104Spower.jg@gmail.com """Simple L1 data cache with default values""" 9511104Spower.jg@gmail.com 9611104Spower.jg@gmail.com # Set the default size 9711104Spower.jg@gmail.com size = '64kB' 9811104Spower.jg@gmail.com 9911104Spower.jg@gmail.com SimpleOpts.add_option('--l1d_size', 10011104Spower.jg@gmail.com help="L1 data cache size. Default: %s" % size) 10111104Spower.jg@gmail.com 10211104Spower.jg@gmail.com def __init__(self, opts=None): 10311104Spower.jg@gmail.com super(L1DCache, self).__init__(opts) 10411104Spower.jg@gmail.com if not opts or not opts.l1d_size: 10511104Spower.jg@gmail.com return 10611104Spower.jg@gmail.com self.size = opts.l1d_size 10711104Spower.jg@gmail.com 10811104Spower.jg@gmail.com def connectCPU(self, cpu): 10911104Spower.jg@gmail.com """Connect this cache's port to a CPU dcache port""" 11011104Spower.jg@gmail.com self.cpu_side = cpu.dcache_port 11111104Spower.jg@gmail.com 11211104Spower.jg@gmail.comclass L2Cache(Cache): 11311104Spower.jg@gmail.com """Simple L2 Cache with default values""" 11411104Spower.jg@gmail.com 11511104Spower.jg@gmail.com # Default parameters 11611104Spower.jg@gmail.com size = '256kB' 11711104Spower.jg@gmail.com assoc = 8 11811722Ssophiane.senni@gmail.com tag_latency = 20 11911722Ssophiane.senni@gmail.com data_latency = 20 12011104Spower.jg@gmail.com response_latency = 20 12111104Spower.jg@gmail.com mshrs = 20 12211104Spower.jg@gmail.com tgts_per_mshr = 12 12311104Spower.jg@gmail.com 12411104Spower.jg@gmail.com SimpleOpts.add_option('--l2_size', help="L2 cache size. Default: %s" % size) 12511104Spower.jg@gmail.com 12611104Spower.jg@gmail.com def __init__(self, opts=None): 12711104Spower.jg@gmail.com super(L2Cache, self).__init__() 12811104Spower.jg@gmail.com if not opts or not opts.l2_size: 12911104Spower.jg@gmail.com return 13011104Spower.jg@gmail.com self.size = opts.l2_size 13111104Spower.jg@gmail.com 13211104Spower.jg@gmail.com def connectCPUSideBus(self, bus): 13311104Spower.jg@gmail.com self.cpu_side = bus.master 13411104Spower.jg@gmail.com 13511104Spower.jg@gmail.com def connectMemSideBus(self, bus): 13611104Spower.jg@gmail.com self.mem_side = bus.slave 137