MESI_Two_Level.py revision 10007
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
356915SN/A
366915SN/A#
376915SN/A# Note: the L1 Cache latency is only used by the sequencer on fast path hits
386915SN/A#
396915SN/Aclass L1Cache(RubyCache):
406915SN/A    latency = 3
416915SN/A
426915SN/A#
436915SN/A# Note: the L2 Cache latency is not currently used
446915SN/A#
456915SN/Aclass L2Cache(RubyCache):
466915SN/A    latency = 15
476915SN/A
487538SN/Adef define_options(parser):
497538SN/A    return
507538SN/A
518929SN/Adef create_system(options, system, piobus, dma_ports, ruby_system):
5210007Snilay@cs.wisc.edu
5310007Snilay@cs.wisc.edu    if buildEnv['PROTOCOL'] != 'MESI_Two_Level':
5410007Snilay@cs.wisc.edu        fatal("This script requires the MESI_Two_Level protocol to be built.")
556915SN/A
566915SN/A    cpu_sequencers = []
5710007Snilay@cs.wisc.edu
586915SN/A    #
596915SN/A    # The ruby network creation expects the list of nodes in the system to be
606915SN/A    # consistent with the NetDest list.  Therefore the l1 controller nodes must be
616915SN/A    # listed before the directory nodes and directory nodes before dma nodes, etc.
626915SN/A    #
636915SN/A    l1_cntrl_nodes = []
646915SN/A    l2_cntrl_nodes = []
656915SN/A    dir_cntrl_nodes = []
666915SN/A    dma_cntrl_nodes = []
676915SN/A
686915SN/A    #
696915SN/A    # Must create the individual controllers before the network to ensure the
706915SN/A    # controller constructors are called before the network constructor
716915SN/A    #
728180SN/A    l2_bits = int(math.log(options.num_l2caches, 2))
738180SN/A    block_size_bits = int(math.log(options.cacheline_size, 2))
7410007Snilay@cs.wisc.edu
756915SN/A    for i in xrange(options.num_cpus):
766915SN/A        #
776915SN/A        # First create the Ruby objects associated with this cpu
786915SN/A        #
796915SN/A        l1i_cache = L1Cache(size = options.l1i_size,
808180SN/A                            assoc = options.l1i_assoc,
819319SN/A                            start_index_bit = block_size_bits,
829319SN/A                            is_icache = True)
836915SN/A        l1d_cache = L1Cache(size = options.l1d_size,
848180SN/A                            assoc = options.l1d_assoc,
859319SN/A                            start_index_bit = block_size_bits,
869319SN/A                            is_icache = False)
876915SN/A
889366SN/A        prefetcher = RubyPrefetcher.Prefetcher()
899366SN/A
908322SN/A        l1_cntrl = L1Cache_Controller(version = i,
919696SN/A                                      L1Icache = l1i_cache,
929696SN/A                                      L1Dcache = l1d_cache,
938436SN/A                                      l2_select_num_bits = l2_bits,
948717SN/A                                      send_evictions = (
958717SN/A                                          options.cpu_type == "detailed"),
969366SN/A                                      prefetcher = prefetcher,
979366SN/A                                      ruby_system = ruby_system,
989841SN/A                                      transitions_per_cycle=options.ports,
999366SN/A                                      enable_prefetch = False)
1008322SN/A
1017015SN/A        cpu_seq = RubySequencer(version = i,
1027015SN/A                                icache = l1i_cache,
1036915SN/A                                dcache = l1d_cache,
1048436SN/A                                ruby_system = ruby_system)
1056915SN/A
1068322SN/A        l1_cntrl.sequencer = cpu_seq
1078322SN/A
1086915SN/A        if piobus != None:
1098845SN/A            cpu_seq.pio_port = piobus.slave
1106915SN/A
1119468SN/A        exec("ruby_system.l1_cntrl%d = l1_cntrl" % i)
11210007Snilay@cs.wisc.edu
1136915SN/A        #
1146915SN/A        # Add controllers and sequencers to the appropriate lists
1156915SN/A        #
1166915SN/A        cpu_sequencers.append(cpu_seq)
1176915SN/A        l1_cntrl_nodes.append(l1_cntrl)
11810007Snilay@cs.wisc.edu
1198180SN/A    l2_index_start = block_size_bits + l2_bits
1208180SN/A
1216915SN/A    for i in xrange(options.num_l2caches):
1226915SN/A        #
1236915SN/A        # First create the Ruby objects associated with this cpu
1246915SN/A        #
1256915SN/A        l2_cache = L2Cache(size = options.l2_size,
1268180SN/A                           assoc = options.l2_assoc,
1278180SN/A                           start_index_bit = l2_index_start)
1286915SN/A
1296915SN/A        l2_cntrl = L2Cache_Controller(version = i,
1309696SN/A                                      L2cache = l2_cache,
1319841SN/A                                      transitions_per_cycle=options.ports,
1328436SN/A                                      ruby_system = ruby_system)
13310007Snilay@cs.wisc.edu
1349468SN/A        exec("ruby_system.l2_cntrl%d = l2_cntrl" % i)
1356915SN/A        l2_cntrl_nodes.append(l2_cntrl)
13610007Snilay@cs.wisc.edu
1379826SN/A    phys_mem_size = sum(map(lambda r: r.size(), system.mem_ranges))
1389798SN/A    assert(phys_mem_size % options.num_dirs == 0)
1396915SN/A    mem_module_size = phys_mem_size / options.num_dirs
1406915SN/A
1419793SN/A    # Run each of the ruby memory controllers at a ratio of the frequency of
1429793SN/A    # the ruby system
1439793SN/A    # clk_divider value is a fix to pass regression.
1449793SN/A    ruby_system.memctrl_clk_domain = DerivedClockDomain(
1459793SN/A                                          clk_domain=ruby_system.clk_domain,
1469793SN/A                                          clk_divider=3)
1479793SN/A
1486915SN/A    for i in xrange(options.num_dirs):
1496915SN/A        #
1506915SN/A        # Create the Ruby objects associated with the directory controller
1516915SN/A        #
1526915SN/A
1539793SN/A        mem_cntrl = RubyMemoryControl(
1549793SN/A                              clk_domain = ruby_system.memctrl_clk_domain,
1559793SN/A                              version = i,
1569793SN/A                              ruby_system = ruby_system)
1576915SN/A
1586915SN/A        dir_size = MemorySize('0B')
1596915SN/A        dir_size.value = mem_module_size
1606915SN/A
1616915SN/A        dir_cntrl = Directory_Controller(version = i,
1626915SN/A                                         directory = \
1636915SN/A                                         RubyDirectoryMemory(version = i,
1648718SN/A                                                             size = dir_size,
1658718SN/A                                                             use_map =
1668718SN/A                                                           options.use_map),
1678436SN/A                                         memBuffer = mem_cntrl,
1689841SN/A                                         transitions_per_cycle = options.ports,
1698436SN/A                                         ruby_system = ruby_system)
1706915SN/A
1719468SN/A        exec("ruby_system.dir_cntrl%d = dir_cntrl" % i)
1726915SN/A        dir_cntrl_nodes.append(dir_cntrl)
1736915SN/A
1748929SN/A    for i, dma_port in enumerate(dma_ports):
1756915SN/A        #
1766915SN/A        # Create the Ruby objects associated with the dma controller
1776915SN/A        #
1786915SN/A        dma_seq = DMASequencer(version = i,
1798477SN/A                               ruby_system = ruby_system)
18010007Snilay@cs.wisc.edu
1816915SN/A        dma_cntrl = DMA_Controller(version = i,
1828477SN/A                                   dma_sequencer = dma_seq,
1839841SN/A                                   transitions_per_cycle = options.ports,
1848477SN/A                                   ruby_system = ruby_system)
1856915SN/A
1869468SN/A        exec("ruby_system.dma_cntrl%d = dma_cntrl" % i)
1879468SN/A        exec("ruby_system.dma_cntrl%d.dma_sequencer.slave = dma_port" % i)
1886915SN/A        dma_cntrl_nodes.append(dma_cntrl)
1898257SN/A
1906915SN/A    all_cntrls = l1_cntrl_nodes + \
1916915SN/A                 l2_cntrl_nodes + \
1926915SN/A                 dir_cntrl_nodes + \
1936915SN/A                 dma_cntrl_nodes
1946915SN/A
1959100SN/A    topology = create_topology(all_cntrls, options)
1969100SN/A
1979100SN/A    return (cpu_sequencers, dir_cntrl_nodes, topology)
198