MESI_Two_Level.py revision 11065
16915SN/A# Copyright (c) 2006-2007 The Regents of The University of Michigan 26915SN/A# Copyright (c) 2009 Advanced Micro Devices, Inc. 36915SN/A# All rights reserved. 46915SN/A# 56915SN/A# Redistribution and use in source and binary forms, with or without 66915SN/A# modification, are permitted provided that the following conditions are 76915SN/A# met: redistributions of source code must retain the above copyright 86915SN/A# notice, this list of conditions and the following disclaimer; 96915SN/A# redistributions in binary form must reproduce the above copyright 106915SN/A# notice, this list of conditions and the following disclaimer in the 116915SN/A# documentation and/or other materials provided with the distribution; 126915SN/A# neither the name of the copyright holders nor the names of its 136915SN/A# contributors may be used to endorse or promote products derived from 146915SN/A# this software without specific prior written permission. 156915SN/A# 166915SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 176915SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 186915SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 196915SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 206915SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 216915SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 226915SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 236915SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 246915SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 256915SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 266915SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 276915SN/A# 286915SN/A# Authors: Brad Beckmann 296915SN/A 306915SN/Aimport math 316915SN/Aimport m5 326915SN/Afrom m5.objects import * 336915SN/Afrom m5.defines import buildEnv 349100SN/Afrom Ruby import create_topology 3510529Smorr@cs.wisc.edufrom Ruby import send_evicts 366915SN/A 376915SN/A# 3811019Sjthestness@gmail.com# Declare caches used by the protocol 396915SN/A# 4011019Sjthestness@gmail.comclass L1Cache(RubyCache): pass 4111019Sjthestness@gmail.comclass L2Cache(RubyCache): pass 426915SN/A 437538SN/Adef define_options(parser): 447538SN/A return 457538SN/A 4610519Snilay@cs.wisc.edudef create_system(options, full_system, system, dma_ports, ruby_system): 4710007Snilay@cs.wisc.edu 4810007Snilay@cs.wisc.edu if buildEnv['PROTOCOL'] != 'MESI_Two_Level': 4910007Snilay@cs.wisc.edu fatal("This script requires the MESI_Two_Level protocol to be built.") 506915SN/A 516915SN/A cpu_sequencers = [] 5210007Snilay@cs.wisc.edu 536915SN/A # 546915SN/A # The ruby network creation expects the list of nodes in the system to be 556915SN/A # consistent with the NetDest list. Therefore the l1 controller nodes must be 566915SN/A # listed before the directory nodes and directory nodes before dma nodes, etc. 576915SN/A # 586915SN/A l1_cntrl_nodes = [] 596915SN/A l2_cntrl_nodes = [] 606915SN/A dir_cntrl_nodes = [] 616915SN/A dma_cntrl_nodes = [] 626915SN/A 636915SN/A # 646915SN/A # Must create the individual controllers before the network to ensure the 656915SN/A # controller constructors are called before the network constructor 666915SN/A # 678180SN/A l2_bits = int(math.log(options.num_l2caches, 2)) 688180SN/A block_size_bits = int(math.log(options.cacheline_size, 2)) 6910007Snilay@cs.wisc.edu 706915SN/A for i in xrange(options.num_cpus): 716915SN/A # 726915SN/A # First create the Ruby objects associated with this cpu 736915SN/A # 746915SN/A l1i_cache = L1Cache(size = options.l1i_size, 758180SN/A assoc = options.l1i_assoc, 769319SN/A start_index_bit = block_size_bits, 779319SN/A is_icache = True) 786915SN/A l1d_cache = L1Cache(size = options.l1d_size, 798180SN/A assoc = options.l1d_assoc, 809319SN/A start_index_bit = block_size_bits, 819319SN/A is_icache = False) 826915SN/A 839366SN/A prefetcher = RubyPrefetcher.Prefetcher() 849366SN/A 858322SN/A l1_cntrl = L1Cache_Controller(version = i, 869696SN/A L1Icache = l1i_cache, 879696SN/A L1Dcache = l1d_cache, 888436SN/A l2_select_num_bits = l2_bits, 8910529Smorr@cs.wisc.edu send_evictions = send_evicts(options), 909366SN/A prefetcher = prefetcher, 919366SN/A ruby_system = ruby_system, 9210300Scastilloe@unican.es clk_domain=system.cpu[i].clk_domain, 939841SN/A transitions_per_cycle=options.ports, 949366SN/A enable_prefetch = False) 958322SN/A 967015SN/A cpu_seq = RubySequencer(version = i, 977015SN/A icache = l1i_cache, 986915SN/A dcache = l1d_cache, 9910300Scastilloe@unican.es clk_domain=system.cpu[i].clk_domain, 1008436SN/A ruby_system = ruby_system) 1016915SN/A 1028322SN/A l1_cntrl.sequencer = cpu_seq 1039468SN/A exec("ruby_system.l1_cntrl%d = l1_cntrl" % i) 10410007Snilay@cs.wisc.edu 1056915SN/A # Add controllers and sequencers to the appropriate lists 1066915SN/A cpu_sequencers.append(cpu_seq) 1076915SN/A l1_cntrl_nodes.append(l1_cntrl) 10810007Snilay@cs.wisc.edu 10910311Snilay@cs.wisc.edu # Connect the L1 controllers and the network 11011022Sjthestness@gmail.com l1_cntrl.mandatoryQueue = MessageBuffer() 11111022Sjthestness@gmail.com l1_cntrl.requestFromL1Cache = MessageBuffer() 11211022Sjthestness@gmail.com l1_cntrl.requestFromL1Cache.master = ruby_system.network.slave 11311022Sjthestness@gmail.com l1_cntrl.responseFromL1Cache = MessageBuffer() 11411022Sjthestness@gmail.com l1_cntrl.responseFromL1Cache.master = ruby_system.network.slave 11511022Sjthestness@gmail.com l1_cntrl.unblockFromL1Cache = MessageBuffer() 11611022Sjthestness@gmail.com l1_cntrl.unblockFromL1Cache.master = ruby_system.network.slave 11710311Snilay@cs.wisc.edu 11811022Sjthestness@gmail.com l1_cntrl.optionalQueue = MessageBuffer() 11911022Sjthestness@gmail.com 12011022Sjthestness@gmail.com l1_cntrl.requestToL1Cache = MessageBuffer() 12111022Sjthestness@gmail.com l1_cntrl.requestToL1Cache.slave = ruby_system.network.master 12211022Sjthestness@gmail.com l1_cntrl.responseToL1Cache = MessageBuffer() 12311022Sjthestness@gmail.com l1_cntrl.responseToL1Cache.slave = ruby_system.network.master 12410311Snilay@cs.wisc.edu 12510311Snilay@cs.wisc.edu 1268180SN/A l2_index_start = block_size_bits + l2_bits 1278180SN/A 1286915SN/A for i in xrange(options.num_l2caches): 1296915SN/A # 1306915SN/A # First create the Ruby objects associated with this cpu 1316915SN/A # 1326915SN/A l2_cache = L2Cache(size = options.l2_size, 1338180SN/A assoc = options.l2_assoc, 1348180SN/A start_index_bit = l2_index_start) 1356915SN/A 1366915SN/A l2_cntrl = L2Cache_Controller(version = i, 1379696SN/A L2cache = l2_cache, 1389841SN/A transitions_per_cycle=options.ports, 1398436SN/A ruby_system = ruby_system) 14010007Snilay@cs.wisc.edu 1419468SN/A exec("ruby_system.l2_cntrl%d = l2_cntrl" % i) 1426915SN/A l2_cntrl_nodes.append(l2_cntrl) 14310007Snilay@cs.wisc.edu 14410311Snilay@cs.wisc.edu # Connect the L2 controllers and the network 14511022Sjthestness@gmail.com l2_cntrl.DirRequestFromL2Cache = MessageBuffer() 14611022Sjthestness@gmail.com l2_cntrl.DirRequestFromL2Cache.master = ruby_system.network.slave 14711022Sjthestness@gmail.com l2_cntrl.L1RequestFromL2Cache = MessageBuffer() 14811022Sjthestness@gmail.com l2_cntrl.L1RequestFromL2Cache.master = ruby_system.network.slave 14911022Sjthestness@gmail.com l2_cntrl.responseFromL2Cache = MessageBuffer() 15011022Sjthestness@gmail.com l2_cntrl.responseFromL2Cache.master = ruby_system.network.slave 15110311Snilay@cs.wisc.edu 15211022Sjthestness@gmail.com l2_cntrl.unblockToL2Cache = MessageBuffer() 15311022Sjthestness@gmail.com l2_cntrl.unblockToL2Cache.slave = ruby_system.network.master 15411022Sjthestness@gmail.com l2_cntrl.L1RequestToL2Cache = MessageBuffer() 15511022Sjthestness@gmail.com l2_cntrl.L1RequestToL2Cache.slave = ruby_system.network.master 15611022Sjthestness@gmail.com l2_cntrl.responseToL2Cache = MessageBuffer() 15711022Sjthestness@gmail.com l2_cntrl.responseToL2Cache.slave = ruby_system.network.master 15810311Snilay@cs.wisc.edu 15910311Snilay@cs.wisc.edu 1609826SN/A phys_mem_size = sum(map(lambda r: r.size(), system.mem_ranges)) 1619798SN/A assert(phys_mem_size % options.num_dirs == 0) 1626915SN/A mem_module_size = phys_mem_size / options.num_dirs 1636915SN/A 16410311Snilay@cs.wisc.edu 1659793SN/A # Run each of the ruby memory controllers at a ratio of the frequency of 1669793SN/A # the ruby system 1679793SN/A # clk_divider value is a fix to pass regression. 1689793SN/A ruby_system.memctrl_clk_domain = DerivedClockDomain( 1699793SN/A clk_domain=ruby_system.clk_domain, 1709793SN/A clk_divider=3) 1719793SN/A 1726915SN/A for i in xrange(options.num_dirs): 1736915SN/A dir_size = MemorySize('0B') 1746915SN/A dir_size.value = mem_module_size 1756915SN/A 1766915SN/A dir_cntrl = Directory_Controller(version = i, 17710524Snilay@cs.wisc.edu directory = RubyDirectoryMemory( 17810524Snilay@cs.wisc.edu version = i, size = dir_size), 1799841SN/A transitions_per_cycle = options.ports, 1808436SN/A ruby_system = ruby_system) 1816915SN/A 1829468SN/A exec("ruby_system.dir_cntrl%d = dir_cntrl" % i) 1836915SN/A dir_cntrl_nodes.append(dir_cntrl) 1846915SN/A 18510311Snilay@cs.wisc.edu # Connect the directory controllers and the network 18611022Sjthestness@gmail.com dir_cntrl.requestToDir = MessageBuffer() 18711022Sjthestness@gmail.com dir_cntrl.requestToDir.slave = ruby_system.network.master 18811022Sjthestness@gmail.com dir_cntrl.responseToDir = MessageBuffer() 18911022Sjthestness@gmail.com dir_cntrl.responseToDir.slave = ruby_system.network.master 19011022Sjthestness@gmail.com dir_cntrl.responseFromDir = MessageBuffer() 19111022Sjthestness@gmail.com dir_cntrl.responseFromDir.master = ruby_system.network.slave 19211022Sjthestness@gmail.com dir_cntrl.responseFromMemory = MessageBuffer() 19310311Snilay@cs.wisc.edu 19410311Snilay@cs.wisc.edu 1958929SN/A for i, dma_port in enumerate(dma_ports): 1966915SN/A # Create the Ruby objects associated with the dma controller 1976915SN/A dma_seq = DMASequencer(version = i, 19810519Snilay@cs.wisc.edu ruby_system = ruby_system, 19910519Snilay@cs.wisc.edu slave = dma_port) 20010007Snilay@cs.wisc.edu 2016915SN/A dma_cntrl = DMA_Controller(version = i, 2028477SN/A dma_sequencer = dma_seq, 2039841SN/A transitions_per_cycle = options.ports, 2048477SN/A ruby_system = ruby_system) 2056915SN/A 2069468SN/A exec("ruby_system.dma_cntrl%d = dma_cntrl" % i) 2076915SN/A dma_cntrl_nodes.append(dma_cntrl) 2088257SN/A 20910311Snilay@cs.wisc.edu # Connect the dma controller to the network 21011022Sjthestness@gmail.com dma_cntrl.mandatoryQueue = MessageBuffer() 21111022Sjthestness@gmail.com dma_cntrl.responseFromDir = MessageBuffer(ordered = True) 21211022Sjthestness@gmail.com dma_cntrl.responseFromDir.slave = ruby_system.network.master 21311022Sjthestness@gmail.com dma_cntrl.requestToDir = MessageBuffer() 21411022Sjthestness@gmail.com dma_cntrl.requestToDir.master = ruby_system.network.slave 21510311Snilay@cs.wisc.edu 2166915SN/A all_cntrls = l1_cntrl_nodes + \ 2176915SN/A l2_cntrl_nodes + \ 2186915SN/A dir_cntrl_nodes + \ 2196915SN/A dma_cntrl_nodes 2206915SN/A 22110519Snilay@cs.wisc.edu # Create the io controller and the sequencer 22210519Snilay@cs.wisc.edu if full_system: 22310519Snilay@cs.wisc.edu io_seq = DMASequencer(version=len(dma_ports), ruby_system=ruby_system) 22410519Snilay@cs.wisc.edu ruby_system._io_port = io_seq 22510519Snilay@cs.wisc.edu io_controller = DMA_Controller(version = len(dma_ports), 22610519Snilay@cs.wisc.edu dma_sequencer = io_seq, 22710519Snilay@cs.wisc.edu ruby_system = ruby_system) 22810519Snilay@cs.wisc.edu ruby_system.io_controller = io_controller 22910519Snilay@cs.wisc.edu 23010519Snilay@cs.wisc.edu # Connect the dma controller to the network 23111022Sjthestness@gmail.com io_controller.mandatoryQueue = MessageBuffer() 23211022Sjthestness@gmail.com io_controller.responseFromDir = MessageBuffer(ordered = True) 23311022Sjthestness@gmail.com io_controller.responseFromDir.slave = ruby_system.network.master 23411022Sjthestness@gmail.com io_controller.requestToDir = MessageBuffer() 23511022Sjthestness@gmail.com io_controller.requestToDir.master = ruby_system.network.slave 23610519Snilay@cs.wisc.edu 23710519Snilay@cs.wisc.edu all_cntrls = all_cntrls + [io_controller] 23810519Snilay@cs.wisc.edu 23911065Snilay@cs.wisc.edu ruby_system.network.number_of_virtual_networks = 3 2409100SN/A topology = create_topology(all_cntrls, options) 2419100SN/A return (cpu_sequencers, dir_cntrl_nodes, topology) 242