fs_bigLITTLE.py revision 11756
111569Sgabor.dozsa@arm.com# Copyright (c) 2016 ARM Limited
211569Sgabor.dozsa@arm.com# All rights reserved.
311569Sgabor.dozsa@arm.com#
411569Sgabor.dozsa@arm.com# The license below extends only to copyright in the software and shall
511569Sgabor.dozsa@arm.com# not be construed as granting a license to any other intellectual
611569Sgabor.dozsa@arm.com# property including but not limited to intellectual property relating
711569Sgabor.dozsa@arm.com# to a hardware implementation of the functionality of the software
811569Sgabor.dozsa@arm.com# licensed hereunder.  You may use the software subject to the license
911569Sgabor.dozsa@arm.com# terms below provided that you ensure that this notice is replicated
1011569Sgabor.dozsa@arm.com# unmodified and in its entirety in all distributions of the software,
1111569Sgabor.dozsa@arm.com# modified or unmodified, in source code or in binary form.
1211569Sgabor.dozsa@arm.com#
1311569Sgabor.dozsa@arm.com# Redistribution and use in source and binary forms, with or without
1411569Sgabor.dozsa@arm.com# modification, are permitted provided that the following conditions are
1511569Sgabor.dozsa@arm.com# met: redistributions of source code must retain the above copyright
1611569Sgabor.dozsa@arm.com# notice, this list of conditions and the following disclaimer;
1711569Sgabor.dozsa@arm.com# redistributions in binary form must reproduce the above copyright
1811569Sgabor.dozsa@arm.com# notice, this list of conditions and the following disclaimer in the
1911569Sgabor.dozsa@arm.com# documentation and/or other materials provided with the distribution;
2011569Sgabor.dozsa@arm.com# neither the name of the copyright holders nor the names of its
2111569Sgabor.dozsa@arm.com# contributors may be used to endorse or promote products derived from
2211569Sgabor.dozsa@arm.com# this software without specific prior written permission.
2311569Sgabor.dozsa@arm.com#
2411569Sgabor.dozsa@arm.com# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2511569Sgabor.dozsa@arm.com# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2611569Sgabor.dozsa@arm.com# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2711569Sgabor.dozsa@arm.com# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2811569Sgabor.dozsa@arm.com# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2911569Sgabor.dozsa@arm.com# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3011569Sgabor.dozsa@arm.com# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3111569Sgabor.dozsa@arm.com# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3211569Sgabor.dozsa@arm.com# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3311569Sgabor.dozsa@arm.com# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3411569Sgabor.dozsa@arm.com# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3511569Sgabor.dozsa@arm.com#
3611569Sgabor.dozsa@arm.com# Authors: Gabor Dozsa
3711569Sgabor.dozsa@arm.com#          Andreas Sandberg
3811569Sgabor.dozsa@arm.com
3911569Sgabor.dozsa@arm.com# This is an example configuration script for full system simulation of
4011569Sgabor.dozsa@arm.com# a generic ARM bigLITTLE system.
4111569Sgabor.dozsa@arm.com
4211569Sgabor.dozsa@arm.com
4311569Sgabor.dozsa@arm.comimport argparse
4411569Sgabor.dozsa@arm.comimport os
4511569Sgabor.dozsa@arm.comimport sys
4611569Sgabor.dozsa@arm.comimport m5
4711569Sgabor.dozsa@arm.comfrom m5.objects import *
4811569Sgabor.dozsa@arm.com
4911682Sandreas.hansson@arm.comm5.util.addToPath("../../")
5011682Sandreas.hansson@arm.com
5111682Sandreas.hansson@arm.comfrom common import SysPaths
5211682Sandreas.hansson@arm.comfrom common import CpuConfig
5311569Sgabor.dozsa@arm.com
5411569Sgabor.dozsa@arm.comimport devices
5511569Sgabor.dozsa@arm.com
5611569Sgabor.dozsa@arm.com
5711569Sgabor.dozsa@arm.comdefault_dtb = 'armv8_gem5_v1_big_little_2_2.dtb'
5811569Sgabor.dozsa@arm.comdefault_kernel = 'vmlinux4.3.aarch64'
5911569Sgabor.dozsa@arm.comdefault_disk = 'aarch64-ubuntu-trusty-headless.img'
6011569Sgabor.dozsa@arm.comdefault_rcs = 'bootscript.rcS'
6111569Sgabor.dozsa@arm.com
6211569Sgabor.dozsa@arm.comdefault_mem_size= "2GB"
6311569Sgabor.dozsa@arm.com
6411630Sgabor.dozsa@arm.com
6511630Sgabor.dozsa@arm.comclass BigCluster(devices.CpuCluster):
6611630Sgabor.dozsa@arm.com    def __init__(self, system, num_cpus, cpu_clock,
6711630Sgabor.dozsa@arm.com                 cpu_voltage="1.0V"):
6811630Sgabor.dozsa@arm.com        cpu_config = [ CpuConfig.get("arm_detailed"), devices.L1I, devices.L1D,
6911630Sgabor.dozsa@arm.com                    devices.WalkCache, devices.L2 ]
7011630Sgabor.dozsa@arm.com        super(BigCluster, self).__init__(system, num_cpus, cpu_clock,
7111630Sgabor.dozsa@arm.com                                         cpu_voltage, *cpu_config)
7211630Sgabor.dozsa@arm.com
7311630Sgabor.dozsa@arm.comclass LittleCluster(devices.CpuCluster):
7411630Sgabor.dozsa@arm.com    def __init__(self, system, num_cpus, cpu_clock,
7511630Sgabor.dozsa@arm.com                 cpu_voltage="1.0V"):
7611630Sgabor.dozsa@arm.com        cpu_config = [ CpuConfig.get("minor"), devices.L1I, devices.L1D,
7711630Sgabor.dozsa@arm.com                       devices.WalkCache, devices.L2 ]
7811630Sgabor.dozsa@arm.com        super(LittleCluster, self).__init__(system, num_cpus, cpu_clock,
7911630Sgabor.dozsa@arm.com                                         cpu_voltage, *cpu_config)
8011630Sgabor.dozsa@arm.com
8111630Sgabor.dozsa@arm.com
8211756Sgabor.dozsa@arm.comdef createSystem(caches, kernel, bootscript, disks=[]):
8311756Sgabor.dozsa@arm.com    sys = devices.SimpleSystem(caches, default_mem_size,
8411756Sgabor.dozsa@arm.com                               kernel=SysPaths.binary(kernel),
8511569Sgabor.dozsa@arm.com                               readfile=bootscript,
8611569Sgabor.dozsa@arm.com                               machine_type="DTOnly")
8711569Sgabor.dozsa@arm.com
8811756Sgabor.dozsa@arm.com    sys.mem_ctrls = SimpleMemory(range=sys._mem_range)
8911569Sgabor.dozsa@arm.com    sys.mem_ctrls.port = sys.membus.master
9011569Sgabor.dozsa@arm.com
9111569Sgabor.dozsa@arm.com    sys.connect()
9211569Sgabor.dozsa@arm.com
9311569Sgabor.dozsa@arm.com    # Attach disk images
9411569Sgabor.dozsa@arm.com    if disks:
9511569Sgabor.dozsa@arm.com        def cow_disk(image_file):
9611569Sgabor.dozsa@arm.com            image = CowDiskImage()
9711569Sgabor.dozsa@arm.com            image.child.image_file = SysPaths.disk(image_file)
9811569Sgabor.dozsa@arm.com            return image
9911569Sgabor.dozsa@arm.com
10011569Sgabor.dozsa@arm.com        sys.disk_images = [ cow_disk(f) for f in disks ]
10111569Sgabor.dozsa@arm.com        sys.pci_vio_block = [ PciVirtIO(vio=VirtIOBlock(image=img))
10211569Sgabor.dozsa@arm.com                              for img in sys.disk_images ]
10311569Sgabor.dozsa@arm.com        for dev in sys.pci_vio_block:
10411569Sgabor.dozsa@arm.com            sys.attach_pci(dev)
10511569Sgabor.dozsa@arm.com
10611569Sgabor.dozsa@arm.com    sys.realview.setupBootLoader(sys.membus, sys, SysPaths.binary)
10711569Sgabor.dozsa@arm.com
10811569Sgabor.dozsa@arm.com    return sys
10911569Sgabor.dozsa@arm.com
11011569Sgabor.dozsa@arm.com
11111569Sgabor.dozsa@arm.comdef main():
11211569Sgabor.dozsa@arm.com    parser = argparse.ArgumentParser(
11311569Sgabor.dozsa@arm.com        description="Generic ARM big.LITTLE configuration")
11411569Sgabor.dozsa@arm.com
11511569Sgabor.dozsa@arm.com    parser.add_argument("--restore-from", type=str, default=None,
11611569Sgabor.dozsa@arm.com                        help="Restore from checkpoint")
11711569Sgabor.dozsa@arm.com    parser.add_argument("--dtb", type=str, default=default_dtb,
11811569Sgabor.dozsa@arm.com                        help="DTB file to load")
11911569Sgabor.dozsa@arm.com    parser.add_argument("--kernel", type=str, default=default_kernel,
12011569Sgabor.dozsa@arm.com                        help="Linux kernel")
12111569Sgabor.dozsa@arm.com    parser.add_argument("--disk", action="append", type=str, default=[],
12211569Sgabor.dozsa@arm.com                        help="Disks to instantiate")
12311569Sgabor.dozsa@arm.com    parser.add_argument("--bootscript", type=str, default=default_rcs,
12411569Sgabor.dozsa@arm.com                        help="Linux bootscript")
12511569Sgabor.dozsa@arm.com    parser.add_argument("--atomic", action="store_true", default=False,
12611569Sgabor.dozsa@arm.com                        help="Use atomic CPUs")
12711569Sgabor.dozsa@arm.com    parser.add_argument("--kernel-init", type=str, default="/sbin/init",
12811569Sgabor.dozsa@arm.com                        help="Override init")
12911569Sgabor.dozsa@arm.com    parser.add_argument("--big-cpus", type=int, default=1,
13011569Sgabor.dozsa@arm.com                        help="Number of big CPUs to instantiate")
13111569Sgabor.dozsa@arm.com    parser.add_argument("--little-cpus", type=int, default=1,
13211569Sgabor.dozsa@arm.com                        help="Number of little CPUs to instantiate")
13311569Sgabor.dozsa@arm.com    parser.add_argument("--caches", action="store_true", default=False,
13411569Sgabor.dozsa@arm.com                        help="Instantiate caches")
13511569Sgabor.dozsa@arm.com    parser.add_argument("--last-cache-level", type=int, default=2,
13611569Sgabor.dozsa@arm.com                        help="Last level of caches (e.g. 3 for L3)")
13711569Sgabor.dozsa@arm.com    parser.add_argument("--big-cpu-clock", type=str, default="2GHz",
13811569Sgabor.dozsa@arm.com                        help="Big CPU clock frequency")
13911569Sgabor.dozsa@arm.com    parser.add_argument("--little-cpu-clock", type=str, default="1GHz",
14011569Sgabor.dozsa@arm.com                        help="Little CPU clock frequency")
14111569Sgabor.dozsa@arm.com
14211569Sgabor.dozsa@arm.com    m5.ticks.fixGlobalFrequency()
14311569Sgabor.dozsa@arm.com
14411569Sgabor.dozsa@arm.com    options = parser.parse_args()
14511569Sgabor.dozsa@arm.com
14611569Sgabor.dozsa@arm.com    kernel_cmd = [
14711569Sgabor.dozsa@arm.com        "earlyprintk=pl011,0x1c090000",
14811569Sgabor.dozsa@arm.com        "console=ttyAMA0",
14911569Sgabor.dozsa@arm.com        "lpj=19988480",
15011569Sgabor.dozsa@arm.com        "norandmaps",
15111569Sgabor.dozsa@arm.com        "loglevel=8",
15211569Sgabor.dozsa@arm.com        "mem=%s" % default_mem_size,
15311569Sgabor.dozsa@arm.com        "root=/dev/vda1",
15411569Sgabor.dozsa@arm.com        "rw",
15511569Sgabor.dozsa@arm.com        "init=%s" % options.kernel_init,
15611569Sgabor.dozsa@arm.com        "vmalloc=768MB",
15711569Sgabor.dozsa@arm.com    ]
15811569Sgabor.dozsa@arm.com
15911569Sgabor.dozsa@arm.com    root = Root(full_system=True)
16011569Sgabor.dozsa@arm.com
16111756Sgabor.dozsa@arm.com    disks = [default_disk] if len(options.disk) == 0 else options.disk
16211756Sgabor.dozsa@arm.com    system = createSystem(options.caches,
16311756Sgabor.dozsa@arm.com                          options.kernel,
16411756Sgabor.dozsa@arm.com                          options.bootscript,
16511756Sgabor.dozsa@arm.com                          disks=disks)
16611569Sgabor.dozsa@arm.com
16711569Sgabor.dozsa@arm.com    root.system = system
16811569Sgabor.dozsa@arm.com    system.boot_osflags = " ".join(kernel_cmd)
16911569Sgabor.dozsa@arm.com
17011630Sgabor.dozsa@arm.com    AtomicCluster = devices.AtomicCluster
17111630Sgabor.dozsa@arm.com
17211630Sgabor.dozsa@arm.com    if options.big_cpus + options.little_cpus == 0:
17311630Sgabor.dozsa@arm.com        m5.util.panic("Empty CPU clusters")
17411630Sgabor.dozsa@arm.com
17511569Sgabor.dozsa@arm.com    # big cluster
17611569Sgabor.dozsa@arm.com    if options.big_cpus > 0:
17711630Sgabor.dozsa@arm.com        if options.atomic:
17811630Sgabor.dozsa@arm.com            system.bigCluster = AtomicCluster(system, options.big_cpus,
17911630Sgabor.dozsa@arm.com                                              options.big_cpu_clock)
18011630Sgabor.dozsa@arm.com        else:
18111630Sgabor.dozsa@arm.com            system.bigCluster = BigCluster(system, options.big_cpus,
18211630Sgabor.dozsa@arm.com                                           options.big_cpu_clock)
18311630Sgabor.dozsa@arm.com        mem_mode = system.bigCluster.memoryMode()
18411630Sgabor.dozsa@arm.com    # little cluster
18511630Sgabor.dozsa@arm.com    if options.little_cpus > 0:
18611630Sgabor.dozsa@arm.com        if options.atomic:
18711630Sgabor.dozsa@arm.com            system.littleCluster = AtomicCluster(system, options.little_cpus,
18811630Sgabor.dozsa@arm.com                                                 options.little_cpu_clock)
18911569Sgabor.dozsa@arm.com
19011630Sgabor.dozsa@arm.com        else:
19111630Sgabor.dozsa@arm.com            system.littleCluster = LittleCluster(system, options.little_cpus,
19211630Sgabor.dozsa@arm.com                                                 options.little_cpu_clock)
19311630Sgabor.dozsa@arm.com        mem_mode = system.littleCluster.memoryMode()
19411569Sgabor.dozsa@arm.com
19511630Sgabor.dozsa@arm.com    if options.big_cpus > 0 and options.little_cpus > 0:
19611630Sgabor.dozsa@arm.com        if system.bigCluster.memoryMode() != system.littleCluster.memoryMode():
19711630Sgabor.dozsa@arm.com            m5.util.panic("Memory mode missmatch among CPU clusters")
19811630Sgabor.dozsa@arm.com    system.mem_mode = mem_mode
19911569Sgabor.dozsa@arm.com
20011630Sgabor.dozsa@arm.com    # create caches
20111630Sgabor.dozsa@arm.com    system.addCaches(options.caches, options.last_cache_level)
20211630Sgabor.dozsa@arm.com    if not options.caches:
20311630Sgabor.dozsa@arm.com        if options.big_cpus > 0 and system.bigCluster.requireCaches():
20411630Sgabor.dozsa@arm.com            m5.util.panic("Big CPU model requires caches")
20511630Sgabor.dozsa@arm.com        if options.little_cpus > 0 and system.littleCluster.requireCaches():
20611630Sgabor.dozsa@arm.com            m5.util.panic("Little CPU model requires caches")
20711569Sgabor.dozsa@arm.com
20811569Sgabor.dozsa@arm.com    # Linux device tree
20911569Sgabor.dozsa@arm.com    system.dtb_filename = SysPaths.binary(options.dtb)
21011569Sgabor.dozsa@arm.com
21111569Sgabor.dozsa@arm.com    # Get and load from the chkpt or simpoint checkpoint
21211569Sgabor.dozsa@arm.com    if options.restore_from is not None:
21311569Sgabor.dozsa@arm.com        m5.instantiate(options.restore_from)
21411569Sgabor.dozsa@arm.com    else:
21511569Sgabor.dozsa@arm.com        m5.instantiate()
21611569Sgabor.dozsa@arm.com
21711569Sgabor.dozsa@arm.com    # start simulation (and drop checkpoints when requested)
21811569Sgabor.dozsa@arm.com    while True:
21911569Sgabor.dozsa@arm.com        event = m5.simulate()
22011569Sgabor.dozsa@arm.com        exit_msg = event.getCause()
22111569Sgabor.dozsa@arm.com        if exit_msg == "checkpoint":
22211569Sgabor.dozsa@arm.com            print "Dropping checkpoint at tick %d" % m5.curTick()
22311569Sgabor.dozsa@arm.com            cpt_dir = os.path.join(m5.options.outdir, "cpt.%d" % m5.curTick())
22411569Sgabor.dozsa@arm.com            m5.checkpoint(os.path.join(cpt_dir))
22511569Sgabor.dozsa@arm.com            print "Checkpoint done."
22611569Sgabor.dozsa@arm.com        else:
22711569Sgabor.dozsa@arm.com            print exit_msg, " @ ", m5.curTick()
22811569Sgabor.dozsa@arm.com            break
22911569Sgabor.dozsa@arm.com
23011569Sgabor.dozsa@arm.com    sys.exit(event.getCode())
23111569Sgabor.dozsa@arm.com
23211569Sgabor.dozsa@arm.com
23311569Sgabor.dozsa@arm.comif __name__ == "__m5_main__":
23411569Sgabor.dozsa@arm.com    main()
235