MOESI_hammer.py revision 10116:d61a59beb670
112853Sgabeblack@google.com# Copyright (c) 2006-2007 The Regents of The University of Michigan
212853Sgabeblack@google.com# Copyright (c) 2009 Advanced Micro Devices, Inc.
312853Sgabeblack@google.com# All rights reserved.
412853Sgabeblack@google.com#
512853Sgabeblack@google.com# Redistribution and use in source and binary forms, with or without
612853Sgabeblack@google.com# modification, are permitted provided that the following conditions are
712853Sgabeblack@google.com# met: redistributions of source code must retain the above copyright
812853Sgabeblack@google.com# notice, this list of conditions and the following disclaimer;
912853Sgabeblack@google.com# redistributions in binary form must reproduce the above copyright
1012853Sgabeblack@google.com# notice, this list of conditions and the following disclaimer in the
1112853Sgabeblack@google.com# documentation and/or other materials provided with the distribution;
1212853Sgabeblack@google.com# neither the name of the copyright holders nor the names of its
1312853Sgabeblack@google.com# contributors may be used to endorse or promote products derived from
1412853Sgabeblack@google.com# this software without specific prior written permission.
1512853Sgabeblack@google.com#
1612853Sgabeblack@google.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1712853Sgabeblack@google.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1812853Sgabeblack@google.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1912853Sgabeblack@google.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2012853Sgabeblack@google.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2112853Sgabeblack@google.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2212853Sgabeblack@google.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2312853Sgabeblack@google.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2412853Sgabeblack@google.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2512853Sgabeblack@google.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2612853Sgabeblack@google.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2712853Sgabeblack@google.com#
2812853Sgabeblack@google.com# Authors: Brad Beckmann
2912853Sgabeblack@google.com
3012853Sgabeblack@google.comimport math
3112853Sgabeblack@google.comimport m5
3212853Sgabeblack@google.comfrom m5.objects import *
3312853Sgabeblack@google.comfrom m5.defines import buildEnv
3412853Sgabeblack@google.comfrom Ruby import create_topology
3512853Sgabeblack@google.com
3612853Sgabeblack@google.com#
3712853Sgabeblack@google.com# Note: the L1 Cache latency is only used by the sequencer on fast path hits
3812853Sgabeblack@google.com#
3912853Sgabeblack@google.comclass L1Cache(RubyCache):
4012853Sgabeblack@google.com    latency = 2
4112853Sgabeblack@google.com
4212853Sgabeblack@google.com#
4312853Sgabeblack@google.com# Note: the L2 Cache latency is not currently used
4412853Sgabeblack@google.com#
4512853Sgabeblack@google.comclass L2Cache(RubyCache):
4612853Sgabeblack@google.com    latency = 10
4712853Sgabeblack@google.com
4812853Sgabeblack@google.com#
4912853Sgabeblack@google.com# Probe filter is a cache, latency is not used
5012853Sgabeblack@google.com#
5112853Sgabeblack@google.comclass ProbeFilter(RubyCache):
5212853Sgabeblack@google.com    latency = 1
5312853Sgabeblack@google.com
5412853Sgabeblack@google.comdef define_options(parser):
5512853Sgabeblack@google.com    parser.add_option("--allow-atomic-migration", action="store_true",
5612853Sgabeblack@google.com          help="allow migratory sharing for atomic only accessed blocks")
5712853Sgabeblack@google.com    parser.add_option("--pf-on", action="store_true",
5812853Sgabeblack@google.com          help="Hammer: enable Probe Filter")
5912853Sgabeblack@google.com    parser.add_option("--dir-on", action="store_true",
6012853Sgabeblack@google.com          help="Hammer: enable Full-bit Directory")
6112853Sgabeblack@google.com
6212853Sgabeblack@google.comdef create_system(options, system, dma_ports, ruby_system):
6312853Sgabeblack@google.com
6412853Sgabeblack@google.com    if buildEnv['PROTOCOL'] != 'MOESI_hammer':
6512853Sgabeblack@google.com        panic("This script requires the MOESI_hammer protocol to be built.")
6612853Sgabeblack@google.com
6712853Sgabeblack@google.com    cpu_sequencers = []
6812853Sgabeblack@google.com
6912853Sgabeblack@google.com    #
7012853Sgabeblack@google.com    # The ruby network creation expects the list of nodes in the system to be
7112853Sgabeblack@google.com    # consistent with the NetDest list.  Therefore the l1 controller nodes must be
7212853Sgabeblack@google.com    # listed before the directory nodes and directory nodes before dma nodes, etc.
7312853Sgabeblack@google.com    #
7412853Sgabeblack@google.com    l1_cntrl_nodes = []
7512853Sgabeblack@google.com    dir_cntrl_nodes = []
7612853Sgabeblack@google.com    dma_cntrl_nodes = []
7712853Sgabeblack@google.com
7812853Sgabeblack@google.com    #
7912853Sgabeblack@google.com    # Must create the individual controllers before the network to ensure the
8012853Sgabeblack@google.com    # controller constructors are called before the network constructor
8112853Sgabeblack@google.com    #
8212853Sgabeblack@google.com    block_size_bits = int(math.log(options.cacheline_size, 2))
8312853Sgabeblack@google.com
8412853Sgabeblack@google.com    for i in xrange(options.num_cpus):
8512853Sgabeblack@google.com        #
8612853Sgabeblack@google.com        # First create the Ruby objects associated with this cpu
8712853Sgabeblack@google.com        #
8812853Sgabeblack@google.com        l1i_cache = L1Cache(size = options.l1i_size,
8912853Sgabeblack@google.com                            assoc = options.l1i_assoc,
9012853Sgabeblack@google.com                            start_index_bit = block_size_bits,
9112853Sgabeblack@google.com                            is_icache = True)
9212853Sgabeblack@google.com        l1d_cache = L1Cache(size = options.l1d_size,
9312853Sgabeblack@google.com                            assoc = options.l1d_assoc,
9412853Sgabeblack@google.com                            start_index_bit = block_size_bits)
9512853Sgabeblack@google.com        l2_cache = L2Cache(size = options.l2_size,
9612853Sgabeblack@google.com                           assoc = options.l2_assoc,
9712853Sgabeblack@google.com                           start_index_bit = block_size_bits)
9812853Sgabeblack@google.com
9912853Sgabeblack@google.com        l1_cntrl = L1Cache_Controller(version = i,
10012853Sgabeblack@google.com                                      L1Icache = l1i_cache,
10112853Sgabeblack@google.com                                      L1Dcache = l1d_cache,
10212853Sgabeblack@google.com                                      L2cache = l2_cache,
10312853Sgabeblack@google.com                                      no_mig_atomic = not \
10412853Sgabeblack@google.com                                        options.allow_atomic_migration,
10512853Sgabeblack@google.com                                      send_evictions = (
10612853Sgabeblack@google.com                                          options.cpu_type == "detailed"),
10712853Sgabeblack@google.com                                      transitions_per_cycle = options.ports,
10812853Sgabeblack@google.com                                      ruby_system = ruby_system)
10912853Sgabeblack@google.com
11012853Sgabeblack@google.com        cpu_seq = RubySequencer(version = i,
11112853Sgabeblack@google.com                                icache = l1i_cache,
11212853Sgabeblack@google.com                                dcache = l1d_cache,
11312853Sgabeblack@google.com                                ruby_system = ruby_system)
11412853Sgabeblack@google.com
11512853Sgabeblack@google.com        l1_cntrl.sequencer = cpu_seq
11612853Sgabeblack@google.com        if options.recycle_latency:
11712853Sgabeblack@google.com            l1_cntrl.recycle_latency = options.recycle_latency
11812853Sgabeblack@google.com
11912853Sgabeblack@google.com        exec("ruby_system.l1_cntrl%d = l1_cntrl" % i)
12012853Sgabeblack@google.com        #
12112853Sgabeblack@google.com        # Add controllers and sequencers to the appropriate lists
12212853Sgabeblack@google.com        #
12312853Sgabeblack@google.com        cpu_sequencers.append(cpu_seq)
12412853Sgabeblack@google.com        l1_cntrl_nodes.append(l1_cntrl)
12512853Sgabeblack@google.com
12612853Sgabeblack@google.com    phys_mem_size = sum(map(lambda r: r.size(), system.mem_ranges))
12712853Sgabeblack@google.com    assert(phys_mem_size % options.num_dirs == 0)
12812853Sgabeblack@google.com    mem_module_size = phys_mem_size / options.num_dirs
12912853Sgabeblack@google.com
13012853Sgabeblack@google.com    #
13112853Sgabeblack@google.com    # determine size and index bits for probe filter
13212853Sgabeblack@google.com    # By default, the probe filter size is configured to be twice the
13312853Sgabeblack@google.com    # size of the L2 cache.
13412853Sgabeblack@google.com    #
13512853Sgabeblack@google.com    pf_size = MemorySize(options.l2_size)
13612853Sgabeblack@google.com    pf_size.value = pf_size.value * 2
13712853Sgabeblack@google.com    dir_bits = int(math.log(options.num_dirs, 2))
13812853Sgabeblack@google.com    pf_bits = int(math.log(pf_size.value, 2))
13912853Sgabeblack@google.com    if options.numa_high_bit:
14012853Sgabeblack@google.com        if options.pf_on or options.dir_on:
14112853Sgabeblack@google.com            # if numa high bit explicitly set, make sure it does not overlap
14212853Sgabeblack@google.com            # with the probe filter index
14312853Sgabeblack@google.com            assert(options.numa_high_bit - dir_bits > pf_bits)
14412853Sgabeblack@google.com
14512853Sgabeblack@google.com        # set the probe filter start bit to just above the block offset
14612853Sgabeblack@google.com        pf_start_bit = block_size_bits
14712853Sgabeblack@google.com    else:
14812853Sgabeblack@google.com        if dir_bits > 0:
14912853Sgabeblack@google.com            pf_start_bit = dir_bits + block_size_bits - 1
15012853Sgabeblack@google.com        else:
15112853Sgabeblack@google.com            pf_start_bit = block_size_bits
15212853Sgabeblack@google.com
15312853Sgabeblack@google.com    # Run each of the ruby memory controllers at a ratio of the frequency of
15412853Sgabeblack@google.com    # the ruby system
15512853Sgabeblack@google.com    # clk_divider value is a fix to pass regression.
15612853Sgabeblack@google.com    ruby_system.memctrl_clk_domain = DerivedClockDomain(
15712853Sgabeblack@google.com                                          clk_domain=ruby_system.clk_domain,
15812853Sgabeblack@google.com                                          clk_divider=3)
15912853Sgabeblack@google.com
16012853Sgabeblack@google.com    for i in xrange(options.num_dirs):
16112853Sgabeblack@google.com        #
16212853Sgabeblack@google.com        # Create the Ruby objects associated with the directory controller
16312853Sgabeblack@google.com        #
16412853Sgabeblack@google.com
16512853Sgabeblack@google.com        mem_cntrl = RubyMemoryControl(
16612853Sgabeblack@google.com                              clk_domain = ruby_system.memctrl_clk_domain,
16712853Sgabeblack@google.com                              version = i,
16812853Sgabeblack@google.com                              ruby_system = ruby_system)
16912853Sgabeblack@google.com
17012853Sgabeblack@google.com        dir_size = MemorySize('0B')
17112853Sgabeblack@google.com        dir_size.value = mem_module_size
17212853Sgabeblack@google.com
17312853Sgabeblack@google.com        pf = ProbeFilter(size = pf_size, assoc = 4,
17412853Sgabeblack@google.com                         start_index_bit = pf_start_bit)
17512853Sgabeblack@google.com
17612853Sgabeblack@google.com        dir_cntrl = Directory_Controller(version = i,
17712853Sgabeblack@google.com                                         directory = \
17812853Sgabeblack@google.com                                         RubyDirectoryMemory( \
17912853Sgabeblack@google.com                                                    version = i,
18012853Sgabeblack@google.com                                                    size = dir_size,
18112853Sgabeblack@google.com                                                    use_map = options.use_map,
18212853Sgabeblack@google.com                                                    map_levels = \
18312853Sgabeblack@google.com                                                    options.map_levels,
18412853Sgabeblack@google.com                                                    numa_high_bit = \
18512853Sgabeblack@google.com                                                      options.numa_high_bit),
18612853Sgabeblack@google.com                                         probeFilter = pf,
18712853Sgabeblack@google.com                                         memBuffer = mem_cntrl,
18812853Sgabeblack@google.com                                         probe_filter_enabled = options.pf_on,
18912853Sgabeblack@google.com                                         full_bit_dir_enabled = options.dir_on,
19012853Sgabeblack@google.com                                         transitions_per_cycle = options.ports,
19112853Sgabeblack@google.com                                         ruby_system = ruby_system)
19212853Sgabeblack@google.com
19312853Sgabeblack@google.com        if options.recycle_latency:
19412853Sgabeblack@google.com            dir_cntrl.recycle_latency = options.recycle_latency
19512853Sgabeblack@google.com
19612853Sgabeblack@google.com        exec("ruby_system.dir_cntrl%d = dir_cntrl" % i)
19712853Sgabeblack@google.com        dir_cntrl_nodes.append(dir_cntrl)
19812853Sgabeblack@google.com
19912853Sgabeblack@google.com    for i, dma_port in enumerate(dma_ports):
20012853Sgabeblack@google.com        #
20112853Sgabeblack@google.com        # Create the Ruby objects associated with the dma controller
20212853Sgabeblack@google.com        #
20312853Sgabeblack@google.com        dma_seq = DMASequencer(version = i,
20412853Sgabeblack@google.com                               ruby_system = ruby_system)
20512853Sgabeblack@google.com
20612853Sgabeblack@google.com        dma_cntrl = DMA_Controller(version = i,
20712853Sgabeblack@google.com                                   dma_sequencer = dma_seq,
20812853Sgabeblack@google.com                                   transitions_per_cycle = options.ports,
20912853Sgabeblack@google.com                                   ruby_system = ruby_system)
21012853Sgabeblack@google.com
21112853Sgabeblack@google.com        exec("ruby_system.dma_cntrl%d = dma_cntrl" % i)
21212853Sgabeblack@google.com        exec("ruby_system.dma_cntrl%d.dma_sequencer.slave = dma_port" % i)
21312853Sgabeblack@google.com        dma_cntrl_nodes.append(dma_cntrl)
21412853Sgabeblack@google.com
21512853Sgabeblack@google.com        if options.recycle_latency:
21612853Sgabeblack@google.com            dma_cntrl.recycle_latency = options.recycle_latency
21712853Sgabeblack@google.com
21812853Sgabeblack@google.com    all_cntrls = l1_cntrl_nodes + dir_cntrl_nodes + dma_cntrl_nodes
21912853Sgabeblack@google.com    topology = create_topology(all_cntrls, options)
22012853Sgabeblack@google.com
22112853Sgabeblack@google.com    return (cpu_sequencers, dir_cntrl_nodes, topology)
22212853Sgabeblack@google.com