two_level.py revision 13774
12623SN/A# -*- coding: utf-8 -*-
22623SN/A# Copyright (c) 2015 Jason Power
32623SN/A# All rights reserved.
42623SN/A#
52623SN/A# Redistribution and use in source and binary forms, with or without
62623SN/A# modification, are permitted provided that the following conditions are
72623SN/A# met: redistributions of source code must retain the above copyright
82623SN/A# notice, this list of conditions and the following disclaimer;
92623SN/A# redistributions in binary form must reproduce the above copyright
102623SN/A# notice, this list of conditions and the following disclaimer in the
112623SN/A# documentation and/or other materials provided with the distribution;
122623SN/A# neither the name of the copyright holders nor the names of its
132623SN/A# contributors may be used to endorse or promote products derived from
142623SN/A# this software without specific prior written permission.
152623SN/A#
162623SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
172623SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
182623SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
192623SN/A# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
202623SN/A# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
212623SN/A# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
222623SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
232623SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
242623SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
252623SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
262623SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
272665Ssaidi@eecs.umich.edu#
282665Ssaidi@eecs.umich.edu# Authors: Jason Power
292623SN/A
302623SN/A""" This file creates a single CPU and a two-level cache system.
312623SN/AThis script takes a single parameter which specifies a binary to execute.
322623SN/AIf none is provided it executes 'hello' by default (mostly used for testing)
332623SN/A
342623SN/ASee Part 1, Chapter 3: Adding cache to the configuration script in the
352623SN/Alearning_gem5 book for more information about this script.
362623SN/AThis file exports options for the L1 I/D and L2 cache sizes.
372623SN/A
382623SN/AIMPORTANT: If you modify this file, it's likely that the Learning gem5 book
392623SN/A           also needs to be updated. For now, email Jason <power.jg@gmail.com>
402856Srdreslin@umich.edu
412856Srdreslin@umich.edu"""
422856Srdreslin@umich.edu
432856Srdreslin@umich.edufrom __future__ import print_function
442856Srdreslin@umich.edufrom __future__ import absolute_import
452856Srdreslin@umich.edu
462856Srdreslin@umich.edu# import the m5 (gem5) library created when gem5 is built
472856Srdreslin@umich.eduimport m5
482856Srdreslin@umich.edu# import all of the SimObjects
492856Srdreslin@umich.edufrom m5.objects import *
502623SN/A
512623SN/A# Add the common scripts to our path
522623SN/Am5.util.addToPath('../../')
532623SN/A
542623SN/A# import the caches which we made
552623SN/Afrom caches import *
562680Sktlim@umich.edu
572680Sktlim@umich.edu# import the SimpleOpts module
582623SN/Afrom common import SimpleOpts
592623SN/A
602680Sktlim@umich.edu# Set the usage message to display
612623SN/ASimpleOpts.set_usage("usage: %prog [options] <binary to execute>")
622623SN/A
632623SN/A# Finalize the arguments and grab the opts so we can pass it on to our objects
642623SN/A(opts, args) = SimpleOpts.parse_args()
652623SN/A
662630SN/A# get ISA for the default binary to run. This is mostly for simple testing
672623SN/Aisa = str(m5.defines.buildEnv['TARGET_ISA']).lower()
682623SN/A
692623SN/A# Default to running 'hello', use the compiled ISA to find the binary
702623SN/Abinary = 'tests/test-progs/hello/bin/' + isa + '/linux/hello'
712623SN/A
722623SN/A# Check if there was a binary passed in via the command line and error if
732630SN/A# there are too many arguments
742623SN/Aif len(args) == 1:
752623SN/A    binary = args[0]
762623SN/Aelif len(args) > 1:
772623SN/A    SimpleOpts.print_help()
782623SN/A    m5.fatal("Expected a binary to execute as positional argument")
792623SN/A
802623SN/A# create the system we are going to simulate
812631SN/Asystem = System()
822631SN/A
832631SN/A# Set the clock fequency of the system (and all of its children)
842623SN/Asystem.clk_domain = SrcClockDomain()
852623SN/Asystem.clk_domain.clock = '1GHz'
862623SN/Asystem.clk_domain.voltage_domain = VoltageDomain()
872623SN/A
882623SN/A# Set up the system
892623SN/Asystem.mem_mode = 'timing'               # Use timing accesses
902623SN/Asystem.mem_ranges = [AddrRange('512MB')] # Create an address range
912623SN/A
922839Sktlim@umich.edu# Create a simple CPU
932798Sktlim@umich.edusystem.cpu = TimingSimpleCPU()
942623SN/A
952623SN/A# Create an L1 instruction and data cache
962623SN/Asystem.cpu.icache = L1ICache(opts)
972623SN/Asystem.cpu.dcache = L1DCache(opts)
982623SN/A
992623SN/A# Connect the instruction and data caches to the CPU
1002623SN/Asystem.cpu.icache.connectCPU(system.cpu)
1012623SN/Asystem.cpu.dcache.connectCPU(system.cpu)
1022623SN/A
1032623SN/A# Create a memory bus, a coherent crossbar, in this case
1042798Sktlim@umich.edusystem.l2bus = L2XBar()
1052623SN/A
1062623SN/A# Hook the CPU ports up to the l2bus
1072623SN/Asystem.cpu.icache.connectBus(system.l2bus)
1082623SN/Asystem.cpu.dcache.connectBus(system.l2bus)
1092623SN/A
1102623SN/A# Create an L2 cache and connect it to the l2bus
1112798Sktlim@umich.edusystem.l2cache = L2Cache(opts)
1122623SN/Asystem.l2cache.connectCPUSideBus(system.l2bus)
1132798Sktlim@umich.edu
1142798Sktlim@umich.edu# Create a memory bus
1152798Sktlim@umich.edusystem.membus = SystemXBar()
1162839Sktlim@umich.edu
1172798Sktlim@umich.edu# Connect the L2 cache to the membus
1182839Sktlim@umich.edusystem.l2cache.connectMemSideBus(system.membus)
1192798Sktlim@umich.edu
1202798Sktlim@umich.edu# create the interrupt controller for the CPU
1212839Sktlim@umich.edusystem.cpu.createInterruptController()
1222798Sktlim@umich.edu
1232798Sktlim@umich.edu# For x86 only, make sure the interrupts are connected to the memory
1242839Sktlim@umich.edu# Note: these are directly connected to the memory bus and are not cached
1252839Sktlim@umich.eduif m5.defines.buildEnv['TARGET_ISA'] == "x86":
1262798Sktlim@umich.edu    system.cpu.interrupts[0].pio = system.membus.master
1272798Sktlim@umich.edu    system.cpu.interrupts[0].int_master = system.membus.slave
1282623SN/A    system.cpu.interrupts[0].int_slave = system.membus.master
1292623SN/A
1302623SN/A# Connect the system up to the membus
1312798Sktlim@umich.edusystem.system_port = system.membus.slave
1322623SN/A
1332798Sktlim@umich.edu# Create a DDR3 memory controller
1342798Sktlim@umich.edusystem.mem_ctrl = DDR3_1600_8x8()
1352798Sktlim@umich.edusystem.mem_ctrl.range = system.mem_ranges[0]
1362798Sktlim@umich.edusystem.mem_ctrl.port = system.membus.master
1372623SN/A
1382798Sktlim@umich.edu# Create a process for a simple "Hello World" application
1392798Sktlim@umich.eduprocess = Process()
1402798Sktlim@umich.edu# Set the command
1412798Sktlim@umich.edu# cmd is a list which begins with the executable (like argv)
1422798Sktlim@umich.eduprocess.cmd = [binary]
1432798Sktlim@umich.edu# Set the cpu to use the process as its workload and create thread contexts
1442798Sktlim@umich.edusystem.cpu.workload = process
1452798Sktlim@umich.edusystem.cpu.createThreads()
1462798Sktlim@umich.edu
1472798Sktlim@umich.edu# set up the root SimObject and start the simulation
1482798Sktlim@umich.eduroot = Root(full_system = False, system = system)
1492798Sktlim@umich.edu# instantiate all of the objects we've created above
1502798Sktlim@umich.edum5.instantiate()
1512623SN/A
1522623SN/Aprint("Beginning simulation!")
1532623SN/Aexit_event = m5.simulate()
1542623SN/Aprint('Exiting @ tick %i because %s' % (m5.curTick(), exit_event.getCause()))
1552623SN/A