MOESI_AMD_Base.py revision 12697:cd71b966be1e
111184Serfan.azarkhish@unibo.it# Copyright (c) 2010-2015 Advanced Micro Devices, Inc.
211184Serfan.azarkhish@unibo.it# All rights reserved.
311184Serfan.azarkhish@unibo.it#
411184Serfan.azarkhish@unibo.it# For use for simulation and test purposes only
511184Serfan.azarkhish@unibo.it#
611184Serfan.azarkhish@unibo.it# Redistribution and use in source and binary forms, with or without
711184Serfan.azarkhish@unibo.it# modification, are permitted provided that the following conditions are met:
811184Serfan.azarkhish@unibo.it#
911184Serfan.azarkhish@unibo.it# 1. Redistributions of source code must retain the above copyright notice,
1011184Serfan.azarkhish@unibo.it# this list of conditions and the following disclaimer.
1111184Serfan.azarkhish@unibo.it#
1211184Serfan.azarkhish@unibo.it# 2. Redistributions in binary form must reproduce the above copyright notice,
1311184Serfan.azarkhish@unibo.it# this list of conditions and the following disclaimer in the documentation
1411184Serfan.azarkhish@unibo.it# and/or other materials provided with the distribution.
1511184Serfan.azarkhish@unibo.it#
1611184Serfan.azarkhish@unibo.it# 3. Neither the name of the copyright holder nor the names of its
1711184Serfan.azarkhish@unibo.it# contributors may be used to endorse or promote products derived from this
1811184Serfan.azarkhish@unibo.it# software without specific prior written permission.
1911184Serfan.azarkhish@unibo.it#
2011184Serfan.azarkhish@unibo.it# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2111184Serfan.azarkhish@unibo.it# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2211184Serfan.azarkhish@unibo.it# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2311184Serfan.azarkhish@unibo.it# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
2411184Serfan.azarkhish@unibo.it# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2511184Serfan.azarkhish@unibo.it# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2611184Serfan.azarkhish@unibo.it# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2711184Serfan.azarkhish@unibo.it# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2811184Serfan.azarkhish@unibo.it# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2911184Serfan.azarkhish@unibo.it# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3011184Serfan.azarkhish@unibo.it# POSSIBILITY OF SUCH DAMAGE.
3111184Serfan.azarkhish@unibo.it#
3211184Serfan.azarkhish@unibo.it# Authors: Lisa Hsu
3311184Serfan.azarkhish@unibo.it
3411184Serfan.azarkhish@unibo.itimport math
3511184Serfan.azarkhish@unibo.itimport m5
3611184Serfan.azarkhish@unibo.itfrom m5.objects import *
3711184Serfan.azarkhish@unibo.itfrom m5.defines import buildEnv
3811184Serfan.azarkhish@unibo.itfrom Ruby import create_topology
3911184Serfan.azarkhish@unibo.itfrom Ruby import send_evicts
4011184Serfan.azarkhish@unibo.it
4111184Serfan.azarkhish@unibo.itfrom topologies.Cluster import Cluster
4211184Serfan.azarkhish@unibo.itfrom topologies.Crossbar import Crossbar
4311184Serfan.azarkhish@unibo.it
4411184Serfan.azarkhish@unibo.itclass CntrlBase:
4511184Serfan.azarkhish@unibo.it    _seqs = 0
4611184Serfan.azarkhish@unibo.it    @classmethod
4711184Serfan.azarkhish@unibo.it    def seqCount(cls):
4811184Serfan.azarkhish@unibo.it        # Use SeqCount not class since we need global count
4911184Serfan.azarkhish@unibo.it        CntrlBase._seqs += 1
5011184Serfan.azarkhish@unibo.it        return CntrlBase._seqs - 1
5111184Serfan.azarkhish@unibo.it
5211184Serfan.azarkhish@unibo.it    _cntrls = 0
5311184Serfan.azarkhish@unibo.it    @classmethod
5411184Serfan.azarkhish@unibo.it    def cntrlCount(cls):
5511184Serfan.azarkhish@unibo.it        # Use CntlCount not class since we need global count
5611184Serfan.azarkhish@unibo.it        CntrlBase._cntrls += 1
5711184Serfan.azarkhish@unibo.it        return CntrlBase._cntrls - 1
5811184Serfan.azarkhish@unibo.it
5911184Serfan.azarkhish@unibo.it    _version = 0
6011184Serfan.azarkhish@unibo.it    @classmethod
6111184Serfan.azarkhish@unibo.it    def versionCount(cls):
6211184Serfan.azarkhish@unibo.it        cls._version += 1 # Use count for this particular type
6311184Serfan.azarkhish@unibo.it        return cls._version - 1
6411184Serfan.azarkhish@unibo.it
6511184Serfan.azarkhish@unibo.itclass L1DCache(RubyCache):
6611184Serfan.azarkhish@unibo.it    resourceStalls = False
6711184Serfan.azarkhish@unibo.it    def create(self, options):
6811184Serfan.azarkhish@unibo.it        self.size = MemorySize(options.l1d_size)
6911184Serfan.azarkhish@unibo.it        self.assoc = options.l1d_assoc
7011184Serfan.azarkhish@unibo.it        self.replacement_policy = PseudoLRUReplacementPolicy()
7111184Serfan.azarkhish@unibo.it
7211184Serfan.azarkhish@unibo.itclass L1ICache(RubyCache):
7311184Serfan.azarkhish@unibo.it    resourceStalls = False
7411184Serfan.azarkhish@unibo.it    def create(self, options):
7511184Serfan.azarkhish@unibo.it        self.size = MemorySize(options.l1i_size)
7611184Serfan.azarkhish@unibo.it        self.assoc = options.l1i_assoc
7711184Serfan.azarkhish@unibo.it        self.replacement_policy = PseudoLRUReplacementPolicy()
7811184Serfan.azarkhish@unibo.it
7911184Serfan.azarkhish@unibo.itclass L2Cache(RubyCache):
8011184Serfan.azarkhish@unibo.it    resourceStalls = False
8111184Serfan.azarkhish@unibo.it    def create(self, options):
8211184Serfan.azarkhish@unibo.it        self.size = MemorySize(options.l2_size)
8311184Serfan.azarkhish@unibo.it        self.assoc = options.l2_assoc
8411184Serfan.azarkhish@unibo.it        self.replacement_policy = PseudoLRUReplacementPolicy()
8511184Serfan.azarkhish@unibo.it
8611184Serfan.azarkhish@unibo.itclass CPCntrl(CorePair_Controller, CntrlBase):
8711184Serfan.azarkhish@unibo.it
8811184Serfan.azarkhish@unibo.it    def create(self, options, ruby_system, system):
8911184Serfan.azarkhish@unibo.it        self.version = self.versionCount()
9011184Serfan.azarkhish@unibo.it
9111184Serfan.azarkhish@unibo.it        self.L1Icache = L1ICache()
9211184Serfan.azarkhish@unibo.it        self.L1Icache.create(options)
9311184Serfan.azarkhish@unibo.it        self.L1D0cache = L1DCache()
9411184Serfan.azarkhish@unibo.it        self.L1D0cache.create(options)
9511184Serfan.azarkhish@unibo.it        self.L1D1cache = L1DCache()
9611184Serfan.azarkhish@unibo.it        self.L1D1cache.create(options)
9711184Serfan.azarkhish@unibo.it        self.L2cache = L2Cache()
9811184Serfan.azarkhish@unibo.it        self.L2cache.create(options)
9911184Serfan.azarkhish@unibo.it
10011184Serfan.azarkhish@unibo.it        self.sequencer = RubySequencer()
10111184Serfan.azarkhish@unibo.it        self.sequencer.icache_hit_latency = 2
10211184Serfan.azarkhish@unibo.it        self.sequencer.dcache_hit_latency = 2
10311184Serfan.azarkhish@unibo.it        self.sequencer.version = self.seqCount()
10411184Serfan.azarkhish@unibo.it        self.sequencer.icache = self.L1Icache
10511184Serfan.azarkhish@unibo.it        self.sequencer.dcache = self.L1D0cache
10611184Serfan.azarkhish@unibo.it        self.sequencer.ruby_system = ruby_system
10711184Serfan.azarkhish@unibo.it        self.sequencer.coreid = 0
10811184Serfan.azarkhish@unibo.it        self.sequencer.is_cpu_sequencer = True
10911184Serfan.azarkhish@unibo.it
11011184Serfan.azarkhish@unibo.it        self.sequencer1 = RubySequencer()
11111184Serfan.azarkhish@unibo.it        self.sequencer1.version = self.seqCount()
11211184Serfan.azarkhish@unibo.it        self.sequencer1.icache = self.L1Icache
11311184Serfan.azarkhish@unibo.it        self.sequencer1.dcache = self.L1D1cache
11411184Serfan.azarkhish@unibo.it        self.sequencer1.icache_hit_latency = 2
11511184Serfan.azarkhish@unibo.it        self.sequencer1.dcache_hit_latency = 2
11611184Serfan.azarkhish@unibo.it        self.sequencer1.ruby_system = ruby_system
11711184Serfan.azarkhish@unibo.it        self.sequencer1.coreid = 1
11811184Serfan.azarkhish@unibo.it        self.sequencer1.is_cpu_sequencer = True
11911184Serfan.azarkhish@unibo.it
12011184Serfan.azarkhish@unibo.it        self.issue_latency = options.cpu_to_dir_latency
121        self.send_evictions = send_evicts(options)
122
123        self.ruby_system = ruby_system
124
125        if options.recycle_latency:
126            self.recycle_latency = options.recycle_latency
127
128class L3Cache(RubyCache):
129    assoc = 8
130    dataArrayBanks = 256
131    tagArrayBanks = 256
132
133    def create(self, options, ruby_system, system):
134        self.size = MemorySize(options.l3_size)
135        self.size.value /= options.num_dirs
136        self.dataArrayBanks /= options.num_dirs
137        self.tagArrayBanks /= options.num_dirs
138        self.dataArrayBanks /= options.num_dirs
139        self.tagArrayBanks /= options.num_dirs
140        self.dataAccessLatency = options.l3_data_latency
141        self.tagAccessLatency = options.l3_tag_latency
142        self.resourceStalls = options.no_resource_stalls
143        self.replacement_policy = PseudoLRUReplacementPolicy()
144
145class L3Cntrl(L3Cache_Controller, CntrlBase):
146    def create(self, options, ruby_system, system):
147        self.version = self.versionCount()
148        self.L3cache = L3Cache()
149        self.L3cache.create(options, ruby_system, system)
150
151        self.l3_response_latency = max(self.L3cache.dataAccessLatency,
152                                       self.L3cache.tagAccessLatency)
153        self.ruby_system = ruby_system
154
155        if options.recycle_latency:
156            self.recycle_latency = options.recycle_latency
157
158    def connectWireBuffers(self, req_to_dir, resp_to_dir, l3_unblock_to_dir,
159                           req_to_l3, probe_to_l3, resp_to_l3):
160        self.reqToDir = req_to_dir
161        self.respToDir = resp_to_dir
162        self.l3UnblockToDir = l3_unblock_to_dir
163        self.reqToL3 = req_to_l3
164        self.probeToL3 = probe_to_l3
165        self.respToL3 = resp_to_l3
166
167class DirCntrl(Directory_Controller, CntrlBase):
168    def create(self, options, dir_ranges, ruby_system, system):
169        self.version = self.versionCount()
170
171        self.response_latency = 30
172
173        self.addr_ranges = dir_ranges
174        self.directory = RubyDirectoryMemory()
175
176        self.L3CacheMemory = L3Cache()
177        self.L3CacheMemory.create(options, ruby_system, system)
178
179        self.l3_hit_latency = max(self.L3CacheMemory.dataAccessLatency,
180                                  self.L3CacheMemory.tagAccessLatency)
181
182        self.number_of_TBEs = options.num_tbes
183
184        self.ruby_system = ruby_system
185
186        if options.recycle_latency:
187            self.recycle_latency = options.recycle_latency
188
189        self.CPUonly = True
190
191    def connectWireBuffers(self, req_to_dir, resp_to_dir, l3_unblock_to_dir,
192                           req_to_l3, probe_to_l3, resp_to_l3):
193        self.reqToDir = req_to_dir
194        self.respToDir = resp_to_dir
195        self.l3UnblockToDir = l3_unblock_to_dir
196        self.reqToL3 = req_to_l3
197        self.probeToL3 = probe_to_l3
198        self.respToL3 = resp_to_l3
199
200def define_options(parser):
201    parser.add_option("--num-subcaches", type="int", default=4)
202    parser.add_option("--l3-data-latency", type="int", default=20)
203    parser.add_option("--l3-tag-latency", type="int", default=15)
204    parser.add_option("--cpu-to-dir-latency", type="int", default=15)
205    parser.add_option("--no-resource-stalls", action="store_false",
206                      default=True)
207    parser.add_option("--num-tbes", type="int", default=256)
208    parser.add_option("--l2-latency", type="int", default=50) # load to use
209
210def create_system(options, full_system, system, dma_devices, bootmem,
211                  ruby_system):
212    if buildEnv['PROTOCOL'] != 'MOESI_AMD_Base':
213        panic("This script requires the MOESI_AMD_Base protocol.")
214
215    cpu_sequencers = []
216
217    #
218    # The ruby network creation expects the list of nodes in the system to
219    # be consistent with the NetDest list.  Therefore the l1 controller
220    # nodes must be listed before the directory nodes and directory nodes
221    # before dma nodes, etc.
222    #
223    l1_cntrl_nodes = []
224    l3_cntrl_nodes = []
225    dir_cntrl_nodes = []
226
227    control_count = 0
228
229    #
230    # Must create the individual controllers before the network to ensure
231    # the controller constructors are called before the network constructor
232    #
233
234    # This is the base crossbar that connects the L3s, Dirs, and cpu
235    # Cluster
236    mainCluster = Cluster(extBW = 512, intBW = 512) # 1 TB/s
237
238    if options.numa_high_bit:
239        numa_bit = options.numa_high_bit
240    else:
241        # if the numa_bit is not specified, set the directory bits as the
242        # lowest bits above the block offset bits, and the numa_bit as the
243        # highest of those directory bits
244        dir_bits = int(math.log(options.num_dirs, 2))
245        block_size_bits = int(math.log(options.cacheline_size, 2))
246        numa_bit = block_size_bits + dir_bits - 1
247
248    for i in xrange(options.num_dirs):
249        dir_ranges = []
250        for r in system.mem_ranges:
251            addr_range = m5.objects.AddrRange(r.start, size = r.size(),
252                                              intlvHighBit = numa_bit,
253                                              intlvBits = dir_bits,
254                                              intlvMatch = i)
255            dir_ranges.append(addr_range)
256
257
258        dir_cntrl = DirCntrl(TCC_select_num_bits = 0)
259        dir_cntrl.create(options, dir_ranges, ruby_system, system)
260
261        # Connect the Directory controller to the ruby network
262        dir_cntrl.requestFromCores = MessageBuffer(ordered = True)
263        dir_cntrl.requestFromCores.slave = ruby_system.network.master
264
265        dir_cntrl.responseFromCores = MessageBuffer()
266        dir_cntrl.responseFromCores.slave = ruby_system.network.master
267
268        dir_cntrl.unblockFromCores = MessageBuffer()
269        dir_cntrl.unblockFromCores.slave = ruby_system.network.master
270
271        dir_cntrl.probeToCore = MessageBuffer()
272        dir_cntrl.probeToCore.master = ruby_system.network.slave
273
274        dir_cntrl.responseToCore = MessageBuffer()
275        dir_cntrl.responseToCore.master = ruby_system.network.slave
276
277        dir_cntrl.triggerQueue = MessageBuffer(ordered = True)
278        dir_cntrl.L3triggerQueue = MessageBuffer(ordered = True)
279        dir_cntrl.responseFromMemory = MessageBuffer()
280
281        exec("system.dir_cntrl%d = dir_cntrl" % i)
282        dir_cntrl_nodes.append(dir_cntrl)
283
284        mainCluster.add(dir_cntrl)
285
286    # Technically this config can support an odd number of cpus, but the top
287    # level config files, such as the ruby_random_tester, will get confused if
288    # the number of cpus does not equal the number of sequencers.  Thus make
289    # sure that an even number of cpus is specified.
290    assert((options.num_cpus % 2) == 0)
291
292    # For an odd number of CPUs, still create the right number of controllers
293    cpuCluster = Cluster(extBW = 512, intBW = 512)  # 1 TB/s
294    for i in xrange((options.num_cpus + 1) / 2):
295
296        cp_cntrl = CPCntrl()
297        cp_cntrl.create(options, ruby_system, system)
298
299        exec("system.cp_cntrl%d = cp_cntrl" % i)
300        #
301        # Add controllers and sequencers to the appropriate lists
302        #
303        cpu_sequencers.extend([cp_cntrl.sequencer, cp_cntrl.sequencer1])
304
305        # Connect the CP controllers and the network
306        cp_cntrl.requestFromCore = MessageBuffer()
307        cp_cntrl.requestFromCore.master = ruby_system.network.slave
308
309        cp_cntrl.responseFromCore = MessageBuffer()
310        cp_cntrl.responseFromCore.master = ruby_system.network.slave
311
312        cp_cntrl.unblockFromCore = MessageBuffer()
313        cp_cntrl.unblockFromCore.master = ruby_system.network.slave
314
315        cp_cntrl.probeToCore = MessageBuffer()
316        cp_cntrl.probeToCore.slave = ruby_system.network.master
317
318        cp_cntrl.responseToCore = MessageBuffer()
319        cp_cntrl.responseToCore.slave = ruby_system.network.master
320
321        cp_cntrl.mandatoryQueue = MessageBuffer()
322        cp_cntrl.triggerQueue = MessageBuffer(ordered = True)
323
324        cpuCluster.add(cp_cntrl)
325
326    # Assuming no DMA devices
327    assert(len(dma_devices) == 0)
328
329    # Add cpu/gpu clusters to main cluster
330    mainCluster.add(cpuCluster)
331
332    ruby_system.network.number_of_virtual_networks = 10
333
334    return (cpu_sequencers, dir_cntrl_nodes, mainCluster)
335