1# Copyright (c) 2013 ARM Limited
2# All rights reserved.
3#
4# The license below extends only to copyright in the software and shall
5# not be construed as granting a license to any other intellectual
6# property including but not limited to intellectual property relating
7# to a hardware implementation of the functionality of the software
8# licensed hereunder.  You may use the software subject to the license
9# terms below provided that you ensure that this notice is replicated
10# unmodified and in its entirety in all distributions of the software,
11# modified or unmodified, in source code or in binary form.
12#
13# Copyright (c) 2006-2008 The Regents of The University of Michigan
14# All rights reserved.
15#
16# Redistribution and use in source and binary forms, with or without
17# modification, are permitted provided that the following conditions are
18# met: redistributions of source code must retain the above copyright
19# notice, this list of conditions and the following disclaimer;
20# redistributions in binary form must reproduce the above copyright
21# notice, this list of conditions and the following disclaimer in the
22# documentation and/or other materials provided with the distribution;
23# neither the name of the copyright holders nor the names of its
24# contributors may be used to endorse or promote products derived from
25# this software without specific prior written permission.
26#
27# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38#
39# Authors: Lisa Hsu
40
41from __future__ import print_function
42from __future__ import absolute_import
43
44import m5
45from m5.defines import buildEnv
46from m5.objects import *
47
48from .Benchmarks import *
49from . import CpuConfig
50from . import BPConfig
51from . import HWPConfig
52from . import MemConfig
53from . import PlatformConfig
54
55def _listCpuTypes(option, opt, value, parser):
56    CpuConfig.print_cpu_list()
57    sys.exit(0)
58
59def _listBPTypes(option, opt, value, parser):
60    BPConfig.print_bp_list()
61    sys.exit(0)
62
63def _listHWPTypes(option, opt, value, parser):
64    HWPConfig.print_hwp_list()
65    sys.exit(0)
66
67def _listIndirectBPTypes(option, opt, value, parser):
68    BPConfig.print_indirect_bp_list()
69    sys.exit(0)
70
71def _listMemTypes(option, opt, value, parser):
72    MemConfig.print_mem_list()
73    sys.exit(0)
74
75def _listPlatformTypes(option, opt, value, parser):
76    PlatformConfig.print_platform_list()
77    sys.exit(0)
78
79# Add the very basic options that work also in the case of the no ISA
80# being used, and consequently no CPUs, but rather various types of
81# testers and traffic generators.
82def addNoISAOptions(parser):
83    parser.add_option("-n", "--num-cpus", type="int", default=1)
84    parser.add_option("--sys-voltage", action="store", type="string",
85                      default='1.0V',
86                      help = """Top-level voltage for blocks running at system
87                      power supply""")
88    parser.add_option("--sys-clock", action="store", type="string",
89                      default='1GHz',
90                      help = """Top-level clock for blocks running at system
91                      speed""")
92
93    # Memory Options
94    parser.add_option("--list-mem-types",
95                      action="callback", callback=_listMemTypes,
96                      help="List available memory types")
97    parser.add_option("--mem-type", type="choice", default="DDR3_1600_8x8",
98                      choices=MemConfig.mem_names(),
99                      help = "type of memory to use")
100    parser.add_option("--mem-channels", type="int", default=1,
101                      help = "number of memory channels")
102    parser.add_option("--mem-ranks", type="int", default=None,
103                      help = "number of memory ranks per channel")
104    parser.add_option("--mem-size", action="store", type="string",
105                      default="512MB",
106                      help="Specify the physical memory size (single memory)")
107    parser.add_option("--enable-dram-powerdown", action="store_true",
108                       help="Enable low-power states in DRAMCtrl")
109
110
111    parser.add_option("--memchecker", action="store_true")
112
113    # Cache Options
114    parser.add_option("--external-memory-system", type="string",
115                      help="use external ports of this port_type for caches")
116    parser.add_option("--tlm-memory", type="string",
117                      help="use external port for SystemC TLM cosimulation")
118    parser.add_option("--caches", action="store_true")
119    parser.add_option("--l2cache", action="store_true")
120    parser.add_option("--num-dirs", type="int", default=1)
121    parser.add_option("--num-l2caches", type="int", default=1)
122    parser.add_option("--num-l3caches", type="int", default=1)
123    parser.add_option("--l1d_size", type="string", default="64kB")
124    parser.add_option("--l1i_size", type="string", default="32kB")
125    parser.add_option("--l2_size", type="string", default="2MB")
126    parser.add_option("--l3_size", type="string", default="16MB")
127    parser.add_option("--l1d_assoc", type="int", default=2)
128    parser.add_option("--l1i_assoc", type="int", default=2)
129    parser.add_option("--l2_assoc", type="int", default=8)
130    parser.add_option("--l3_assoc", type="int", default=16)
131    parser.add_option("--cacheline_size", type="int", default=64)
132
133    # Enable Ruby
134    parser.add_option("--ruby", action="store_true")
135
136    # Run duration options
137    parser.add_option("-m", "--abs-max-tick", type="int", default=m5.MaxTick,
138                      metavar="TICKS", help="Run to absolute simulated tick "
139                      "specified including ticks from a restored checkpoint")
140    parser.add_option("--rel-max-tick", type="int", default=None,
141                      metavar="TICKS", help="Simulate for specified number of"
142                      " ticks relative to the simulation start tick (e.g. if "
143                      "restoring a checkpoint)")
144    parser.add_option("--maxtime", type="float", default=None,
145                      help="Run to the specified absolute simulated time in "
146                      "seconds")
147    parser.add_option("-P", "--param", action="append", default=[],
148        help="Set a SimObject parameter relative to the root node. "
149             "An extended Python multi range slicing syntax can be used "
150             "for arrays. For example: "
151             "'system.cpu[0,1,3:8:2].max_insts_all_threads = 42' "
152             "sets max_insts_all_threads for cpus 0, 1, 3, 5 and 7 "
153             "Direct parameters of the root object are not accessible, "
154             "only parameters of its children.")
155
156# Add common options that assume a non-NULL ISA.
157def addCommonOptions(parser):
158    # start by adding the base options that do not assume an ISA
159    addNoISAOptions(parser)
160
161    # system options
162    parser.add_option("--list-cpu-types",
163                      action="callback", callback=_listCpuTypes,
164                      help="List available CPU types")
165    parser.add_option("--cpu-type", type="choice", default="AtomicSimpleCPU",
166                      choices=CpuConfig.cpu_names(),
167                      help = "type of cpu to run with")
168    parser.add_option("--list-bp-types",
169                      action="callback", callback=_listBPTypes,
170                      help="List available branch predictor types")
171    parser.add_option("--list-indirect-bp-types",
172                      action="callback", callback=_listIndirectBPTypes,
173                      help="List available indirect branch predictor types")
174    parser.add_option("--bp-type", type="choice", default=None,
175                      choices=BPConfig.bp_names(),
176                      help = """
177                      type of branch predictor to run with
178                      (if not set, use the default branch predictor of
179                      the selected CPU)""")
180    parser.add_option("--indirect-bp-type", type="choice",
181                      default="SimpleIndirectPredictor",
182                      choices=BPConfig.indirect_bp_names(),
183                      help = "type of indirect branch predictor to run with")
184    parser.add_option("--list-hwp-types",
185                      action="callback", callback=_listHWPTypes,
186                      help="List available hardware prefetcher types")
187    parser.add_option("--l1i-hwp-type", type="choice", default=None,
188                      choices=HWPConfig.hwp_names(),
189                      help = """
190                      type of hardware prefetcher to use with the L1
191                      instruction cache.
192                      (if not set, use the default prefetcher of
193                      the selected cache)""")
194    parser.add_option("--l1d-hwp-type", type="choice", default=None,
195                      choices=HWPConfig.hwp_names(),
196                      help = """
197                      type of hardware prefetcher to use with the L1
198                      data cache.
199                      (if not set, use the default prefetcher of
200                      the selected cache)""")
201    parser.add_option("--l2-hwp-type", type="choice", default=None,
202                      choices=HWPConfig.hwp_names(),
203                      help = """
204                      type of hardware prefetcher to use with the L2 cache.
205                      (if not set, use the default prefetcher of
206                      the selected cache)""")
207    parser.add_option("--checker", action="store_true");
208    parser.add_option("--cpu-clock", action="store", type="string",
209                      default='2GHz',
210                      help="Clock for blocks running at CPU speed")
211    parser.add_option("--smt", action="store_true", default=False,
212                      help = """
213                      Only used if multiple programs are specified. If true,
214                      then the number of threads per cpu is same as the
215                      number of programs.""")
216    parser.add_option("--elastic-trace-en", action="store_true",
217                      help="""Enable capture of data dependency and instruction
218                      fetch traces using elastic trace probe.""")
219    # Trace file paths input to trace probe in a capture simulation and input
220    # to Trace CPU in a replay simulation
221    parser.add_option("--inst-trace-file", action="store", type="string",
222                      help="""Instruction fetch trace file input to
223                      Elastic Trace probe in a capture simulation and
224                      Trace CPU in a replay simulation""", default="")
225    parser.add_option("--data-trace-file", action="store", type="string",
226                      help="""Data dependency trace file input to
227                      Elastic Trace probe in a capture simulation and
228                      Trace CPU in a replay simulation""", default="")
229
230    parser.add_option("-l", "--lpae", action="store_true")
231    parser.add_option("-V", "--virtualisation", action="store_true")
232
233    # dist-gem5 options
234    parser.add_option("--dist", action="store_true",
235                      help="Parallel distributed gem5 simulation.")
236    parser.add_option("--dist-sync-on-pseudo-op", action="store_true",
237                      help="Use a pseudo-op to start dist-gem5 synchronization.")
238    parser.add_option("--is-switch", action="store_true",
239                      help="Select the network switch simulator process for a"\
240                      "distributed gem5 run")
241    parser.add_option("--dist-rank", default=0, action="store", type="int",
242                      help="Rank of this system within the dist gem5 run.")
243    parser.add_option("--dist-size", default=0, action="store", type="int",
244                      help="Number of gem5 processes within the dist gem5 run.")
245    parser.add_option("--dist-server-name",
246                      default="127.0.0.1",
247                      action="store", type="string",
248                      help="Name of the message server host\nDEFAULT: localhost")
249    parser.add_option("--dist-server-port",
250                      default=2200,
251                      action="store", type="int",
252                      help="Message server listen port\nDEFAULT: 2200")
253    parser.add_option("--dist-sync-repeat",
254                      default="0us",
255                      action="store", type="string",
256                      help="Repeat interval for synchronisation barriers among dist-gem5 processes\nDEFAULT: --ethernet-linkdelay")
257    parser.add_option("--dist-sync-start",
258                      default="5200000000000t",
259                      action="store", type="string",
260                      help="Time to schedule the first dist synchronisation barrier\nDEFAULT:5200000000000t")
261    parser.add_option("--ethernet-linkspeed", default="10Gbps",
262                        action="store", type="string",
263                        help="Link speed in bps\nDEFAULT: 10Gbps")
264    parser.add_option("--ethernet-linkdelay", default="10us",
265                      action="store", type="string",
266                      help="Link delay in seconds\nDEFAULT: 10us")
267
268    # Run duration options
269    parser.add_option("-I", "--maxinsts", action="store", type="int",
270                      default=None, help="""Total number of instructions to
271                                            simulate (default: run forever)""")
272    parser.add_option("--work-item-id", action="store", type="int",
273                      help="the specific work id for exit & checkpointing")
274    parser.add_option("--num-work-ids", action="store", type="int",
275                      help="Number of distinct work item types")
276    parser.add_option("--work-begin-cpu-id-exit", action="store", type="int",
277                      help="exit when work starts on the specified cpu")
278    parser.add_option("--work-end-exit-count", action="store", type="int",
279                      help="exit at specified work end count")
280    parser.add_option("--work-begin-exit-count", action="store", type="int",
281                      help="exit at specified work begin count")
282    parser.add_option("--init-param", action="store", type="int", default=0,
283                      help="""Parameter available in simulation with m5
284                              initparam""")
285    parser.add_option("--initialize-only", action="store_true", default=False,
286                      help="""Exit after initialization. Do not simulate time.
287                              Useful when gem5 is run as a library.""")
288
289    # Simpoint options
290    parser.add_option("--simpoint-profile", action="store_true",
291                      help="Enable basic block profiling for SimPoints")
292    parser.add_option("--simpoint-interval", type="int", default=10000000,
293                      help="SimPoint interval in num of instructions")
294    parser.add_option("--take-simpoint-checkpoints", action="store", type="string",
295        help="<simpoint file,weight file,interval-length,warmup-length>")
296    parser.add_option("--restore-simpoint-checkpoint", action="store_true",
297        help="restore from a simpoint checkpoint taken with " +
298             "--take-simpoint-checkpoints")
299
300    # Checkpointing options
301    ###Note that performing checkpointing via python script files will override
302    ###checkpoint instructions built into binaries.
303    parser.add_option("--take-checkpoints", action="store", type="string",
304        help="<M,N> take checkpoints at tick M and every N ticks thereafter")
305    parser.add_option("--max-checkpoints", action="store", type="int",
306        help="the maximum number of checkpoints to drop", default=5)
307    parser.add_option("--checkpoint-dir", action="store", type="string",
308        help="Place all checkpoints in this absolute directory")
309    parser.add_option("-r", "--checkpoint-restore", action="store", type="int",
310        help="restore from checkpoint <N>")
311    parser.add_option("--checkpoint-at-end", action="store_true",
312                      help="take a checkpoint at end of run")
313    parser.add_option("--work-begin-checkpoint-count", action="store", type="int",
314                      help="checkpoint at specified work begin count")
315    parser.add_option("--work-end-checkpoint-count", action="store", type="int",
316                      help="checkpoint at specified work end count")
317    parser.add_option("--work-cpus-checkpoint-count", action="store", type="int",
318                      help="checkpoint and exit when active cpu count is reached")
319    parser.add_option("--restore-with-cpu", action="store", type="choice",
320                      default="AtomicSimpleCPU", choices=CpuConfig.cpu_names(),
321                      help = "cpu type for restoring from a checkpoint")
322
323
324    # CPU Switching - default switch model goes from a checkpoint
325    # to a timing simple CPU with caches to warm up, then to detailed CPU for
326    # data measurement
327    parser.add_option("--repeat-switch", action="store", type="int",
328        default=None,
329        help="switch back and forth between CPUs with period <N>")
330    parser.add_option("-s", "--standard-switch", action="store", type="int",
331        default=None,
332        help="switch from timing to Detailed CPU after warmup period of <N>")
333    parser.add_option("-p", "--prog-interval", type="str",
334        help="CPU Progress Interval")
335
336    # Fastforwarding and simpoint related materials
337    parser.add_option("-W", "--warmup-insts", action="store", type="int",
338        default=None,
339        help="Warmup period in total instructions (requires --standard-switch)")
340    parser.add_option("--bench", action="store", type="string", default=None,
341        help="base names for --take-checkpoint and --checkpoint-restore")
342    parser.add_option("-F", "--fast-forward", action="store", type="string",
343        default=None,
344        help="Number of instructions to fast forward before switching")
345    parser.add_option("-S", "--simpoint", action="store_true", default=False,
346        help="""Use workload simpoints as an instruction offset for
347                --checkpoint-restore or --take-checkpoint.""")
348    parser.add_option("--at-instruction", action="store_true", default=False,
349        help="""Treat value of --checkpoint-restore or --take-checkpoint as a
350                number of instructions.""")
351    parser.add_option("--spec-input", default="ref", type="choice",
352                      choices=["ref", "test", "train", "smred", "mdred",
353                               "lgred"],
354                      help="Input set size for SPEC CPU2000 benchmarks.")
355    parser.add_option("--arm-iset", default="arm", type="choice",
356                      choices=["arm", "thumb", "aarch64"],
357                      help="ARM instruction set.")
358
359
360def addSEOptions(parser):
361    # Benchmark options
362    parser.add_option("-c", "--cmd", default="",
363                      help="The binary to run in syscall emulation mode.")
364    parser.add_option("-o", "--options", default="",
365                      help="""The options to pass to the binary, use " "
366                              around the entire string""")
367    parser.add_option("-e", "--env", default="",
368                      help="Initialize workload environment from text file.")
369    parser.add_option("-i", "--input", default="",
370                      help="Read stdin from a file.")
371    parser.add_option("--output", default="",
372                      help="Redirect stdout to a file.")
373    parser.add_option("--errout", default="",
374                      help="Redirect stderr to a file.")
375    parser.add_option("--chroot", action="store", type="string", default="/",
376                      help="The chroot option allows a user to alter the "    \
377                           "search path for processes running in SE mode. "   \
378                           "Normally, the search path would begin at the "    \
379                           "root of the filesystem (i.e. /). With chroot, "   \
380                           "a user can force the process to begin looking at" \
381                           "some other location (i.e. /home/user/rand_dir)."  \
382                           "The intended use is to trick sophisticated "      \
383                           "software which queries the __HOST__ filesystem "  \
384                           "for information or functionality. Instead of "    \
385                           "finding files on the __HOST__ filesystem, the "   \
386                           "process will find the user's replacment files.")
387
388
389def addFSOptions(parser):
390    from .FSConfig import os_types
391
392    # Simulation options
393    parser.add_option("--timesync", action="store_true",
394            help="Prevent simulated time from getting ahead of real time")
395
396    # System options
397    parser.add_option("--kernel", action="store", type="string")
398    parser.add_option("--os-type", action="store", type="choice",
399                      choices=os_types[str(buildEnv['TARGET_ISA'])],
400                      default="linux",
401                      help="Specifies type of OS to boot")
402    parser.add_option("--script", action="store", type="string")
403    parser.add_option("--frame-capture", action="store_true",
404            help="Stores changed frame buffers from the VNC server to compressed "\
405            "files in the gem5 output directory")
406
407    if buildEnv['TARGET_ISA'] == "arm":
408        parser.add_option("--bare-metal", action="store_true",
409                   help="Provide the raw system without the linux specific bits")
410        parser.add_option("--list-machine-types",
411                          action="callback", callback=_listPlatformTypes,
412                      help="List available platform types")
413        parser.add_option("--machine-type", action="store", type="choice",
414                choices=PlatformConfig.platform_names(),
415                default="VExpress_EMM")
416        parser.add_option("--dtb-filename", action="store", type="string",
417              help="Specifies device tree blob file to use with device-tree-"\
418              "enabled kernels")
419        parser.add_option("--enable-security-extensions", action="store_true",
420              help="Turn on the ARM Security Extensions")
421        parser.add_option("--enable-context-switch-stats-dump", \
422                action="store_true", help="Enable stats dump at context "\
423                "switches and dump tasks file (required for Streamline)")
424
425    # Benchmark options
426    parser.add_option("--dual", action="store_true",
427                      help="Simulate two systems attached with an ethernet link")
428    parser.add_option("-b", "--benchmark", action="store", type="string",
429                      dest="benchmark",
430                      help="Specify the benchmark to run. Available benchmarks: %s"\
431                      % DefinedBenchmarks)
432
433    # Metafile options
434    parser.add_option("--etherdump", action="store", type="string", dest="etherdump",
435                      help="Specify the filename to dump a pcap capture of the" \
436                      "ethernet traffic")
437
438    # Disk Image Options
439    parser.add_option("--disk-image", action="store", type="string", default=None,
440                      help="Path to the disk image to use.")
441    parser.add_option("--root-device", action="store", type="string", default=None,
442                      help="OS device name for root partition")
443
444    # Command line options
445    parser.add_option("--command-line", action="store", type="string",
446                      default=None,
447                      help="Template for the kernel command line.")
448    parser.add_option("--command-line-file", action="store",
449                      default=None, type="string",
450                      help="File with a template for the kernel command line")
451