CacheConfig.py revision 12097
1955SN/A# Copyright (c) 2012-2013, 2015-2016 ARM Limited 2955SN/A# All rights reserved 31762SN/A# 4955SN/A# The license below extends only to copyright in the software and shall 5955SN/A# not be construed as granting a license to any other intellectual 6955SN/A# property including but not limited to intellectual property relating 7955SN/A# to a hardware implementation of the functionality of the software 8955SN/A# licensed hereunder. You may use the software subject to the license 9955SN/A# terms below provided that you ensure that this notice is replicated 10955SN/A# unmodified and in its entirety in all distributions of the software, 11955SN/A# modified or unmodified, in source code or in binary form. 12955SN/A# 13955SN/A# Copyright (c) 2010 Advanced Micro Devices, Inc. 14955SN/A# All rights reserved. 15955SN/A# 16955SN/A# Redistribution and use in source and binary forms, with or without 17955SN/A# modification, are permitted provided that the following conditions are 18955SN/A# met: redistributions of source code must retain the above copyright 19955SN/A# notice, this list of conditions and the following disclaimer; 20955SN/A# redistributions in binary form must reproduce the above copyright 21955SN/A# notice, this list of conditions and the following disclaimer in the 22955SN/A# documentation and/or other materials provided with the distribution; 23955SN/A# neither the name of the copyright holders nor the names of its 24955SN/A# contributors may be used to endorse or promote products derived from 25955SN/A# this software without specific prior written permission. 26955SN/A# 27955SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 282665Ssaidi@eecs.umich.edu# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 294762Snate@binkert.org# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 30955SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 314762Snate@binkert.org# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 32955SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 33955SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 344202Sbinkertn@umich.edu# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 354382Sbinkertn@umich.edu# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 364202Sbinkertn@umich.edu# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 374762Snate@binkert.org# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 384762Snate@binkert.org# 394762Snate@binkert.org# Authors: Lisa Hsu 40955SN/A 414381Sbinkertn@umich.edu# Configure the M5 cache hierarchy config in one place 424381Sbinkertn@umich.edu# 43955SN/A 44955SN/Aimport m5 45955SN/Afrom m5.objects import * 464202Sbinkertn@umich.edufrom Caches import * 47955SN/A 484382Sbinkertn@umich.edudef config_cache(options, system): 494382Sbinkertn@umich.edu if options.external_memory_system and (options.caches or options.l2cache): 504382Sbinkertn@umich.edu print "External caches and internal caches are exclusive options.\n" 514762Snate@binkert.org sys.exit(1) 524762Snate@binkert.org 534762Snate@binkert.org if options.external_memory_system: 544762Snate@binkert.org ExternalCache = ExternalCacheFactory(options.external_memory_system) 554762Snate@binkert.org 564762Snate@binkert.org if options.cpu_type == "O3_ARM_v7a_3": 574762Snate@binkert.org try: 584762Snate@binkert.org from cores.arm.O3_ARM_v7a import * 594762Snate@binkert.org except: 604762Snate@binkert.org print "O3_ARM_v7a_3 is unavailable. Did you compile the O3 model?" 614762Snate@binkert.org sys.exit(1) 624762Snate@binkert.org 634762Snate@binkert.org dcache_class, icache_class, l2_cache_class, walk_cache_class = \ 644762Snate@binkert.org O3_ARM_v7a_DCache, O3_ARM_v7a_ICache, O3_ARM_v7aL2, \ 654762Snate@binkert.org O3_ARM_v7aWalkCache 664762Snate@binkert.org else: 674762Snate@binkert.org dcache_class, icache_class, l2_cache_class, walk_cache_class = \ 684762Snate@binkert.org L1_DCache, L1_ICache, L2Cache, None 694762Snate@binkert.org 704762Snate@binkert.org if buildEnv['TARGET_ISA'] == 'x86': 714762Snate@binkert.org walk_cache_class = PageTableWalkerCache 724762Snate@binkert.org 734762Snate@binkert.org # Set the cache line size of the system 744762Snate@binkert.org system.cache_line_size = options.cacheline_size 754762Snate@binkert.org 764762Snate@binkert.org # If elastic trace generation is enabled, make sure the memory system is 774762Snate@binkert.org # minimal so that compute delays do not include memory access latencies. 784762Snate@binkert.org # Configure the compulsory L1 caches for the O3CPU, do not configure 794762Snate@binkert.org # any more caches. 804762Snate@binkert.org if options.l2cache and options.elastic_trace_en: 814762Snate@binkert.org fatal("When elastic trace is enabled, do not configure L2 caches.") 824762Snate@binkert.org 834762Snate@binkert.org if options.l2cache: 844382Sbinkertn@umich.edu # Provide a clock for the L2 and the L1-to-L2 bus here as they 854762Snate@binkert.org # are not connected using addTwoLevelCacheHierarchy. Use the 864382Sbinkertn@umich.edu # same clock as the CPUs. 874762Snate@binkert.org system.l2 = l2_cache_class(clk_domain=system.cpu_clk_domain, 884381Sbinkertn@umich.edu size=options.l2_size, 894762Snate@binkert.org assoc=options.l2_assoc) 904762Snate@binkert.org 914762Snate@binkert.org system.tol2bus = L2XBar(clk_domain = system.cpu_clk_domain) 924762Snate@binkert.org system.l2.cpu_side = system.tol2bus.master 934762Snate@binkert.org system.l2.mem_side = system.membus.slave 944762Snate@binkert.org 954762Snate@binkert.org if options.memchecker: 964762Snate@binkert.org system.memchecker = MemChecker() 974762Snate@binkert.org 984762Snate@binkert.org for i in xrange(options.num_cpus): 994762Snate@binkert.org if options.caches: 1004762Snate@binkert.org icache = icache_class(size=options.l1i_size, 1014762Snate@binkert.org assoc=options.l1i_assoc) 1024762Snate@binkert.org dcache = dcache_class(size=options.l1d_size, 1034762Snate@binkert.org assoc=options.l1d_assoc) 1044762Snate@binkert.org 1054762Snate@binkert.org # If we have a walker cache specified, instantiate two 1064762Snate@binkert.org # instances here 1074762Snate@binkert.org if walk_cache_class: 1084762Snate@binkert.org iwalkcache = walk_cache_class() 1094762Snate@binkert.org dwalkcache = walk_cache_class() 1104762Snate@binkert.org else: 1114762Snate@binkert.org iwalkcache = None 1124762Snate@binkert.org dwalkcache = None 1134762Snate@binkert.org 1144762Snate@binkert.org if options.memchecker: 1154762Snate@binkert.org dcache_mon = MemCheckerMonitor(warn_only=True) 1164762Snate@binkert.org dcache_real = dcache 1174762Snate@binkert.org 1184762Snate@binkert.org # Do not pass the memchecker into the constructor of 1194762Snate@binkert.org # MemCheckerMonitor, as it would create a copy; we require 1204762Snate@binkert.org # exactly one MemChecker instance. 1214762Snate@binkert.org dcache_mon.memchecker = system.memchecker 1224762Snate@binkert.org 1234762Snate@binkert.org # Connect monitor 1244762Snate@binkert.org dcache_mon.mem_side = dcache.cpu_side 1254762Snate@binkert.org 1264762Snate@binkert.org # Let CPU connect to monitors 1274762Snate@binkert.org dcache = dcache_mon 1284762Snate@binkert.org 129955SN/A # When connecting the caches, the clock is also inherited 1304382Sbinkertn@umich.edu # from the CPU in question 1314202Sbinkertn@umich.edu system.cpu[i].addPrivateSplitL1Caches(icache, dcache, 1324382Sbinkertn@umich.edu iwalkcache, dwalkcache) 1334382Sbinkertn@umich.edu 1344382Sbinkertn@umich.edu if options.memchecker: 1354382Sbinkertn@umich.edu # The mem_side ports of the caches haven't been connected yet. 1364382Sbinkertn@umich.edu # Make sure connectAllPorts connects the right objects. 1374382Sbinkertn@umich.edu system.cpu[i].dcache = dcache_real 1385192Ssaidi@eecs.umich.edu system.cpu[i].dcache_mon = dcache_mon 1395192Ssaidi@eecs.umich.edu 1405192Ssaidi@eecs.umich.edu elif options.external_memory_system: 1415192Ssaidi@eecs.umich.edu # These port names are presented to whatever 'external' system 1425192Ssaidi@eecs.umich.edu # gem5 is connecting to. Its configuration will likely depend 1435192Ssaidi@eecs.umich.edu # on these names. For simplicity, we would advise configuring 1445192Ssaidi@eecs.umich.edu # it to use this naming scheme; if this isn't possible, change 1455192Ssaidi@eecs.umich.edu # the names below. 1465192Ssaidi@eecs.umich.edu if buildEnv['TARGET_ISA'] in ['x86', 'arm']: 1475192Ssaidi@eecs.umich.edu system.cpu[i].addPrivateSplitL1Caches( 1485192Ssaidi@eecs.umich.edu ExternalCache("cpu%d.icache" % i), 1495192Ssaidi@eecs.umich.edu ExternalCache("cpu%d.dcache" % i), 1505192Ssaidi@eecs.umich.edu ExternalCache("cpu%d.itb_walker_cache" % i), 1515192Ssaidi@eecs.umich.edu ExternalCache("cpu%d.dtb_walker_cache" % i)) 1525192Ssaidi@eecs.umich.edu else: 1535192Ssaidi@eecs.umich.edu system.cpu[i].addPrivateSplitL1Caches( 1545192Ssaidi@eecs.umich.edu ExternalCache("cpu%d.icache" % i), 1555192Ssaidi@eecs.umich.edu ExternalCache("cpu%d.dcache" % i)) 1565192Ssaidi@eecs.umich.edu 1575192Ssaidi@eecs.umich.edu system.cpu[i].createInterruptController() 1585192Ssaidi@eecs.umich.edu if options.l2cache: 1595192Ssaidi@eecs.umich.edu system.cpu[i].connectAllPorts(system.tol2bus, system.membus) 1605192Ssaidi@eecs.umich.edu elif options.external_memory_system: 1615192Ssaidi@eecs.umich.edu system.cpu[i].connectUncachedPorts(system.membus) 1625192Ssaidi@eecs.umich.edu else: 1635192Ssaidi@eecs.umich.edu system.cpu[i].connectAllPorts(system.membus) 1645192Ssaidi@eecs.umich.edu 1655192Ssaidi@eecs.umich.edu return system 1665192Ssaidi@eecs.umich.edu 1675192Ssaidi@eecs.umich.edu# ExternalSlave provides a "port", but when that port connects to a cache, 1685192Ssaidi@eecs.umich.edu# the connecting CPU SimObject wants to refer to its "cpu_side". 1695192Ssaidi@eecs.umich.edu# The 'ExternalCache' class provides this adaptation by rewriting the name, 1704382Sbinkertn@umich.edu# eliminating distracting changes elsewhere in the config code. 1714382Sbinkertn@umich.educlass ExternalCache(ExternalSlave): 1724382Sbinkertn@umich.edu def __getattr__(cls, attr): 1732667Sstever@eecs.umich.edu if (attr == "cpu_side"): 1742667Sstever@eecs.umich.edu attr = "port" 1752667Sstever@eecs.umich.edu return super(ExternalSlave, cls).__getattr__(attr) 1762667Sstever@eecs.umich.edu 1772667Sstever@eecs.umich.edu def __setattr__(cls, attr, value): 1782667Sstever@eecs.umich.edu if (attr == "cpu_side"): 1792037SN/A attr = "port" 1802037SN/A return super(ExternalSlave, cls).__setattr__(attr, value) 1812037SN/A 1824382Sbinkertn@umich.edudef ExternalCacheFactory(port_type): 1834762Snate@binkert.org def make(name): 1844202Sbinkertn@umich.edu return ExternalCache(port_data=name, port_type=port_type, 1854382Sbinkertn@umich.edu addr_ranges=[AllMemory]) 1864202Sbinkertn@umich.edu return make 1874202Sbinkertn@umich.edu