two_level.py revision 13774:a1be2a0c55f2
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. 313170Sstever@eecs.umich.eduThis script takes a single parameter which specifies a binary to execute. 323806Ssaidi@eecs.umich.eduIf none is provided it executes 'hello' by default (mostly used for testing) 332623SN/A 344040Ssaidi@eecs.umich.eduSee 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. 373348Sbinkertn@umich.edu 383348Sbinkertn@umich.eduIMPORTANT: If you modify this file, it's likely that the Learning gem5 book 394762Snate@binkert.org also needs to be updated. For now, email Jason <power.jg@gmail.com> 402901Ssaidi@eecs.umich.edu 412623SN/A""" 422623SN/A 432623SN/Afrom __future__ import print_function 442623SN/Afrom __future__ import absolute_import 452623SN/A 465606Snate@binkert.org# import the m5 (gem5) library created when gem5 is built 472623SN/Aimport m5 482623SN/A# import all of the SimObjects 492623SN/Afrom 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 * 562623SN/A 572623SN/A# import the SimpleOpts module 585336Shines@cs.fsu.edufrom common import SimpleOpts 592623SN/A 604873Sstever@eecs.umich.edu# Set the usage message to display 612623SN/ASimpleOpts.set_usage("usage: %prog [options] <binary to execute>") 622623SN/A 632856Srdreslin@umich.edu# Finalize the arguments and grab the opts so we can pass it on to our objects 642856Srdreslin@umich.edu(opts, args) = SimpleOpts.parse_args() 652856Srdreslin@umich.edu 662856Srdreslin@umich.edu# get ISA for the default binary to run. This is mostly for simple testing 672856Srdreslin@umich.eduisa = str(m5.defines.buildEnv['TARGET_ISA']).lower() 682856Srdreslin@umich.edu 692856Srdreslin@umich.edu# Default to running 'hello', use the compiled ISA to find the binary 704968Sacolyte@umich.edubinary = 'tests/test-progs/hello/bin/' + isa + '/linux/hello' 714968Sacolyte@umich.edu 724968Sacolyte@umich.edu# Check if there was a binary passed in via the command line and error if 734968Sacolyte@umich.edu# there are too many arguments 742856Srdreslin@umich.eduif len(args) == 1: 752856Srdreslin@umich.edu binary = args[0] 762856Srdreslin@umich.eduelif 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 812623SN/Asystem = System() 822623SN/A 832680Sktlim@umich.edu# Set the clock fequency of the system (and all of its children) 842680Sktlim@umich.edusystem.clk_domain = SrcClockDomain() 852623SN/Asystem.clk_domain.clock = '1GHz' 862623SN/Asystem.clk_domain.voltage_domain = VoltageDomain() 875714Shsul@eecs.umich.edu 882623SN/A# Set up the system 892623SN/Asystem.mem_mode = 'timing' # Use timing accesses 904968Sacolyte@umich.edusystem.mem_ranges = [AddrRange('512MB')] # Create an address range 914968Sacolyte@umich.edu 924968Sacolyte@umich.edu# Create a simple CPU 934968Sacolyte@umich.edusystem.cpu = TimingSimpleCPU() 944968Sacolyte@umich.edu 954968Sacolyte@umich.edu# Create an L1 instruction and data cache 965714Shsul@eecs.umich.edusystem.cpu.icache = L1ICache(opts) 975712Shsul@eecs.umich.edusystem.cpu.dcache = L1DCache(opts) 985712Shsul@eecs.umich.edu 995712Shsul@eecs.umich.edu# 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 1033349Sbinkertn@umich.edu# Create a memory bus, a coherent crossbar, in this case 1042623SN/Asystem.l2bus = L2XBar() 1053184Srdreslin@umich.edu 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 1103349Sbinkertn@umich.edu# Create an L2 cache and connect it to the l2bus 1112623SN/Asystem.l2cache = L2Cache(opts) 1123310Srdreslin@umich.edusystem.l2cache.connectCPUSideBus(system.l2bus) 1133649Srdreslin@umich.edu 1142623SN/A# Create a memory bus 1152623SN/Asystem.membus = SystemXBar() 1162623SN/A 1173349Sbinkertn@umich.edu# Connect the L2 cache to the membus 1182623SN/Asystem.l2cache.connectMemSideBus(system.membus) 1193184Srdreslin@umich.edu 1203184Srdreslin@umich.edu# create the interrupt controller for the CPU 1212623SN/Asystem.cpu.createInterruptController() 1222623SN/A 1232623SN/A# For x86 only, make sure the interrupts are connected to the memory 1242623SN/A# Note: these are directly connected to the memory bus and are not cached 1252623SN/Aif m5.defines.buildEnv['TARGET_ISA'] == "x86": 1263647Srdreslin@umich.edu system.cpu.interrupts[0].pio = system.membus.master 1273647Srdreslin@umich.edu system.cpu.interrupts[0].int_master = system.membus.slave 1283647Srdreslin@umich.edu system.cpu.interrupts[0].int_slave = system.membus.master 1293647Srdreslin@umich.edu 1303647Srdreslin@umich.edu# Connect the system up to the membus 1312626SN/Asystem.system_port = system.membus.slave 1323647Srdreslin@umich.edu 1332626SN/A# Create a DDR3 memory controller 1342623SN/Asystem.mem_ctrl = DDR3_1600_8x8() 1352623SN/Asystem.mem_ctrl.range = system.mem_ranges[0] 1362623SN/Asystem.mem_ctrl.port = system.membus.master 1372657Ssaidi@eecs.umich.edu 1382623SN/A# Create a process for a simple "Hello World" application 1392623SN/Aprocess = Process() 1402623SN/A# Set the command 1412623SN/A# cmd is a list which begins with the executable (like argv) 1422623SN/Aprocess.cmd = [binary] 1434192Sktlim@umich.edu# Set the cpu to use the process as its workload and create thread contexts 1444192Sktlim@umich.edusystem.cpu.workload = process 1454192Sktlim@umich.edusystem.cpu.createThreads() 1464192Sktlim@umich.edu 1474192Sktlim@umich.edu# set up the root SimObject and start the simulation 1484192Sktlim@umich.eduroot = Root(full_system = False, system = system) 1494192Sktlim@umich.edu# instantiate all of the objects we've created above 1504192Sktlim@umich.edum5.instantiate() 1515497Ssaidi@eecs.umich.edu 1524192Sktlim@umich.eduprint("Beginning simulation!") 1534192Sktlim@umich.eduexit_event = m5.simulate() 1542623SN/Aprint('Exiting @ tick %i because %s' % (m5.curTick(), exit_event.getCause())) 1555529Snate@binkert.org