fs_bigLITTLE.py revision 11630
12023SN/A# Copyright (c) 2016 ARM Limited
22023SN/A# All rights reserved.
32023SN/A#
42023SN/A# The license below extends only to copyright in the software and shall
52023SN/A# not be construed as granting a license to any other intellectual
62023SN/A# property including but not limited to intellectual property relating
72023SN/A# to a hardware implementation of the functionality of the software
82023SN/A# licensed hereunder.  You may use the software subject to the license
92023SN/A# terms below provided that you ensure that this notice is replicated
102023SN/A# unmodified and in its entirety in all distributions of the software,
112023SN/A# modified or unmodified, in source code or in binary form.
122023SN/A#
132023SN/A# Redistribution and use in source and binary forms, with or without
142023SN/A# modification, are permitted provided that the following conditions are
152023SN/A# met: redistributions of source code must retain the above copyright
162023SN/A# notice, this list of conditions and the following disclaimer;
172023SN/A# redistributions in binary form must reproduce the above copyright
182023SN/A# notice, this list of conditions and the following disclaimer in the
192023SN/A# documentation and/or other materials provided with the distribution;
202023SN/A# neither the name of the copyright holders nor the names of its
212023SN/A# contributors may be used to endorse or promote products derived from
222023SN/A# this software without specific prior written permission.
232023SN/A#
242023SN/A# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
252023SN/A# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
262023SN/A# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
272665Ssaidi@eecs.umich.edu# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
282665Ssaidi@eecs.umich.edu# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
292665Ssaidi@eecs.umich.edu# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
302023SN/A# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
312023SN/A# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
322028SN/A# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
332028SN/A# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
342023SN/A# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
352597SN/A#
362023SN/A# Authors: Gabor Dozsa
372023SN/A#          Andreas Sandberg
382239SN/A
392239SN/A# This is an example configuration script for full system simulation of
402028SN/A# a generic ARM bigLITTLE system.
412023SN/A
422131SN/A
432023SN/Aimport argparse
442131SN/Aimport os
452023SN/Aimport sys
462525SN/Aimport m5
472525SN/Afrom m5.objects import *
482447SN/A
492023SN/Am5.util.addToPath("../../common")
502972Sgblack@eecs.umich.eduimport SysPaths
512972Sgblack@eecs.umich.eduimport CpuConfig
522972Sgblack@eecs.umich.edu
532972Sgblack@eecs.umich.eduimport devices
542239SN/A
552972Sgblack@eecs.umich.edu
562972Sgblack@eecs.umich.edudefault_dtb = 'armv8_gem5_v1_big_little_2_2.dtb'
572131SN/Adefault_kernel = 'vmlinux4.3.aarch64'
582972Sgblack@eecs.umich.edudefault_disk = 'aarch64-ubuntu-trusty-headless.img'
592972Sgblack@eecs.umich.edudefault_rcs = 'bootscript.rcS'
602972Sgblack@eecs.umich.edu
612972Sgblack@eecs.umich.edudefault_mem_size= "2GB"
622972Sgblack@eecs.umich.edu
632972Sgblack@eecs.umich.edu
642972Sgblack@eecs.umich.educlass BigCluster(devices.CpuCluster):
652131SN/A    def __init__(self, system, num_cpus, cpu_clock,
662972Sgblack@eecs.umich.edu                 cpu_voltage="1.0V"):
672972Sgblack@eecs.umich.edu        cpu_config = [ CpuConfig.get("arm_detailed"), devices.L1I, devices.L1D,
682972Sgblack@eecs.umich.edu                    devices.WalkCache, devices.L2 ]
692131SN/A        super(BigCluster, self).__init__(system, num_cpus, cpu_clock,
702972Sgblack@eecs.umich.edu                                         cpu_voltage, *cpu_config)
712972Sgblack@eecs.umich.edu
722597SN/Aclass LittleCluster(devices.CpuCluster):
732972Sgblack@eecs.umich.edu    def __init__(self, system, num_cpus, cpu_clock,
742597SN/A                 cpu_voltage="1.0V"):
752972Sgblack@eecs.umich.edu        cpu_config = [ CpuConfig.get("minor"), devices.L1I, devices.L1D,
762972Sgblack@eecs.umich.edu                       devices.WalkCache, devices.L2 ]
772972Sgblack@eecs.umich.edu        super(LittleCluster, self).__init__(system, num_cpus, cpu_clock,
782597SN/A                                         cpu_voltage, *cpu_config)
792972Sgblack@eecs.umich.edu
802972Sgblack@eecs.umich.edu
812972Sgblack@eecs.umich.edudef createSystem(kernel, bootscript, disks=[]):
822972Sgblack@eecs.umich.edu    sys = devices.SimpleSystem(kernel=SysPaths.binary(kernel),
832972Sgblack@eecs.umich.edu                               readfile=bootscript,
842972Sgblack@eecs.umich.edu                               machine_type="DTOnly")
852972Sgblack@eecs.umich.edu
862972Sgblack@eecs.umich.edu    mem_region = sys.realview._mem_regions[0]
872972Sgblack@eecs.umich.edu    sys.mem_ctrls = SimpleMemory(
882972Sgblack@eecs.umich.edu        range=AddrRange(start=mem_region[0], size=default_mem_size))
892972Sgblack@eecs.umich.edu    sys.mem_ctrls.port = sys.membus.master
902972Sgblack@eecs.umich.edu
912972Sgblack@eecs.umich.edu    sys.connect()
922972Sgblack@eecs.umich.edu
932972Sgblack@eecs.umich.edu    # Attach disk images
942972Sgblack@eecs.umich.edu    if disks:
952597SN/A        def cow_disk(image_file):
962972Sgblack@eecs.umich.edu            image = CowDiskImage()
972972Sgblack@eecs.umich.edu            image.child.image_file = SysPaths.disk(image_file)
982972Sgblack@eecs.umich.edu            return image
992131SN/A
1002972Sgblack@eecs.umich.edu        sys.disk_images = [ cow_disk(f) for f in disks ]
1012972Sgblack@eecs.umich.edu        sys.pci_vio_block = [ PciVirtIO(vio=VirtIOBlock(image=img))
1022131SN/A                              for img in sys.disk_images ]
1032972Sgblack@eecs.umich.edu        for dev in sys.pci_vio_block:
1042131SN/A            sys.attach_pci(dev)
1052972Sgblack@eecs.umich.edu
1062972Sgblack@eecs.umich.edu    sys.realview.setupBootLoader(sys.membus, sys, SysPaths.binary)
1072972Sgblack@eecs.umich.edu
1082972Sgblack@eecs.umich.edu    return sys
1092131SN/A
1102972Sgblack@eecs.umich.edu
1112972Sgblack@eecs.umich.edudef main():
1122972Sgblack@eecs.umich.edu    parser = argparse.ArgumentParser(
1132131SN/A        description="Generic ARM big.LITTLE configuration")
1142972Sgblack@eecs.umich.edu
1152972Sgblack@eecs.umich.edu    parser.add_argument("--restore-from", type=str, default=None,
1162131SN/A                        help="Restore from checkpoint")
1172023SN/A    parser.add_argument("--dtb", type=str, default=default_dtb,
1182023SN/A                        help="DTB file to load")
1192447SN/A    parser.add_argument("--kernel", type=str, default=default_kernel,
1202447SN/A                        help="Linux kernel")
1212028SN/A    parser.add_argument("--disk", action="append", type=str, default=[],
122                        help="Disks to instantiate")
123    parser.add_argument("--bootscript", type=str, default=default_rcs,
124                        help="Linux bootscript")
125    parser.add_argument("--atomic", action="store_true", default=False,
126                        help="Use atomic CPUs")
127    parser.add_argument("--kernel-init", type=str, default="/sbin/init",
128                        help="Override init")
129    parser.add_argument("--big-cpus", type=int, default=1,
130                        help="Number of big CPUs to instantiate")
131    parser.add_argument("--little-cpus", type=int, default=1,
132                        help="Number of little CPUs to instantiate")
133    parser.add_argument("--caches", action="store_true", default=False,
134                        help="Instantiate caches")
135    parser.add_argument("--last-cache-level", type=int, default=2,
136                        help="Last level of caches (e.g. 3 for L3)")
137    parser.add_argument("--big-cpu-clock", type=str, default="2GHz",
138                        help="Big CPU clock frequency")
139    parser.add_argument("--little-cpu-clock", type=str, default="1GHz",
140                        help="Little CPU clock frequency")
141
142    m5.ticks.fixGlobalFrequency()
143
144    options = parser.parse_args()
145
146    kernel_cmd = [
147        "earlyprintk=pl011,0x1c090000",
148        "console=ttyAMA0",
149        "lpj=19988480",
150        "norandmaps",
151        "loglevel=8",
152        "mem=%s" % default_mem_size,
153        "root=/dev/vda1",
154        "rw",
155        "init=%s" % options.kernel_init,
156        "vmalloc=768MB",
157    ]
158
159    root = Root(full_system=True)
160
161    disks = default_disk if len(options.disk) == 0 else options.disk
162    system = createSystem(options.kernel, options.bootscript, disks=disks)
163
164    root.system = system
165    system.boot_osflags = " ".join(kernel_cmd)
166
167    AtomicCluster = devices.AtomicCluster
168
169    if options.big_cpus + options.little_cpus == 0:
170        m5.util.panic("Empty CPU clusters")
171
172    # big cluster
173    if options.big_cpus > 0:
174        if options.atomic:
175            system.bigCluster = AtomicCluster(system, options.big_cpus,
176                                              options.big_cpu_clock)
177        else:
178            system.bigCluster = BigCluster(system, options.big_cpus,
179                                           options.big_cpu_clock)
180        mem_mode = system.bigCluster.memoryMode()
181    # little cluster
182    if options.little_cpus > 0:
183        if options.atomic:
184            system.littleCluster = AtomicCluster(system, options.little_cpus,
185                                                 options.little_cpu_clock)
186
187        else:
188            system.littleCluster = LittleCluster(system, options.little_cpus,
189                                                 options.little_cpu_clock)
190        mem_mode = system.littleCluster.memoryMode()
191
192    if options.big_cpus > 0 and options.little_cpus > 0:
193        if system.bigCluster.memoryMode() != system.littleCluster.memoryMode():
194            m5.util.panic("Memory mode missmatch among CPU clusters")
195    system.mem_mode = mem_mode
196
197    # create caches
198    system.addCaches(options.caches, options.last_cache_level)
199    if not options.caches:
200        if options.big_cpus > 0 and system.bigCluster.requireCaches():
201            m5.util.panic("Big CPU model requires caches")
202        if options.little_cpus > 0 and system.littleCluster.requireCaches():
203            m5.util.panic("Little CPU model requires caches")
204
205    # Linux device tree
206    system.dtb_filename = SysPaths.binary(options.dtb)
207
208    # Get and load from the chkpt or simpoint checkpoint
209    if options.restore_from is not None:
210        m5.instantiate(options.restore_from)
211    else:
212        m5.instantiate()
213
214    # start simulation (and drop checkpoints when requested)
215    while True:
216        event = m5.simulate()
217        exit_msg = event.getCause()
218        if exit_msg == "checkpoint":
219            print "Dropping checkpoint at tick %d" % m5.curTick()
220            cpt_dir = os.path.join(m5.options.outdir, "cpt.%d" % m5.curTick())
221            m5.checkpoint(os.path.join(cpt_dir))
222            print "Checkpoint done."
223        else:
224            print exit_msg, " @ ", m5.curTick()
225            break
226
227    sys.exit(event.getCode())
228
229
230if __name__ == "__m5_main__":
231    main()
232