Options.py revision 13774
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 MemConfig
52from . import PlatformConfig
53
54def _listCpuTypes(option, opt, value, parser):
55    CpuConfig.print_cpu_list()
56    sys.exit(0)
57
58def _listBPTypes(option, opt, value, parser):
59    BPConfig.print_bp_list()
60    sys.exit(0)
61
62def _listMemTypes(option, opt, value, parser):
63    MemConfig.print_mem_list()
64    sys.exit(0)
65
66def _listPlatformTypes(option, opt, value, parser):
67    PlatformConfig.print_platform_list()
68    sys.exit(0)
69
70# Add the very basic options that work also in the case of the no ISA
71# being used, and consequently no CPUs, but rather various types of
72# testers and traffic generators.
73def addNoISAOptions(parser):
74    parser.add_option("-n", "--num-cpus", type="int", default=1)
75    parser.add_option("--sys-voltage", action="store", type="string",
76                      default='1.0V',
77                      help = """Top-level voltage for blocks running at system
78                      power supply""")
79    parser.add_option("--sys-clock", action="store", type="string",
80                      default='1GHz',
81                      help = """Top-level clock for blocks running at system
82                      speed""")
83
84    # Memory Options
85    parser.add_option("--list-mem-types",
86                      action="callback", callback=_listMemTypes,
87                      help="List available memory types")
88    parser.add_option("--mem-type", type="choice", default="DDR3_1600_8x8",
89                      choices=MemConfig.mem_names(),
90                      help = "type of memory to use")
91    parser.add_option("--mem-channels", type="int", default=1,
92                      help = "number of memory channels")
93    parser.add_option("--mem-ranks", type="int", default=None,
94                      help = "number of memory ranks per channel")
95    parser.add_option("--mem-size", action="store", type="string",
96                      default="512MB",
97                      help="Specify the physical memory size (single memory)")
98
99
100    parser.add_option("--memchecker", action="store_true")
101
102    # Cache Options
103    parser.add_option("--external-memory-system", type="string",
104                      help="use external ports of this port_type for caches")
105    parser.add_option("--tlm-memory", type="string",
106                      help="use external port for SystemC TLM cosimulation")
107    parser.add_option("--caches", action="store_true")
108    parser.add_option("--l2cache", action="store_true")
109    parser.add_option("--num-dirs", type="int", default=1)
110    parser.add_option("--num-l2caches", type="int", default=1)
111    parser.add_option("--num-l3caches", type="int", default=1)
112    parser.add_option("--l1d_size", type="string", default="64kB")
113    parser.add_option("--l1i_size", type="string", default="32kB")
114    parser.add_option("--l2_size", type="string", default="2MB")
115    parser.add_option("--l3_size", type="string", default="16MB")
116    parser.add_option("--l1d_assoc", type="int", default=2)
117    parser.add_option("--l1i_assoc", type="int", default=2)
118    parser.add_option("--l2_assoc", type="int", default=8)
119    parser.add_option("--l3_assoc", type="int", default=16)
120    parser.add_option("--cacheline_size", type="int", default=64)
121
122    # Enable Ruby
123    parser.add_option("--ruby", action="store_true")
124
125    # Run duration options
126    parser.add_option("-m", "--abs-max-tick", type="int", default=m5.MaxTick,
127                      metavar="TICKS", help="Run to absolute simulated tick "
128                      "specified including ticks from a restored checkpoint")
129    parser.add_option("--rel-max-tick", type="int", default=None,
130                      metavar="TICKS", help="Simulate for specified number of"
131                      " ticks relative to the simulation start tick (e.g. if "
132                      "restoring a checkpoint)")
133    parser.add_option("--maxtime", type="float", default=None,
134                      help="Run to the specified absolute simulated time in "
135                      "seconds")
136    parser.add_option("-P", "--param", action="append", default=[],
137        help="Set a SimObject parameter relative to the root node. "
138             "An extended Python multi range slicing syntax can be used "
139             "for arrays. For example: "
140             "'system.cpu[0,1,3:8:2].max_insts_all_threads = 42' "
141             "sets max_insts_all_threads for cpus 0, 1, 3, 5 and 7 "
142             "Direct parameters of the root object are not accessible, "
143             "only parameters of its children.")
144
145# Add common options that assume a non-NULL ISA.
146def addCommonOptions(parser):
147    # start by adding the base options that do not assume an ISA
148    addNoISAOptions(parser)
149
150    # system options
151    parser.add_option("--list-cpu-types",
152                      action="callback", callback=_listCpuTypes,
153                      help="List available CPU types")
154    parser.add_option("--cpu-type", type="choice", default="AtomicSimpleCPU",
155                      choices=CpuConfig.cpu_names(),
156                      help = "type of cpu to run with")
157    parser.add_option("--list-bp-types",
158                      action="callback", callback=_listBPTypes,
159                      help="List available branch predictor types")
160    parser.add_option("--bp-type", type="choice", default=None,
161                      choices=BPConfig.bp_names(),
162                      help = """
163                      type of branch predictor to run with
164                      (if not set, use the default branch predictor of
165                      the selected CPU)""")
166    parser.add_option("--checker", action="store_true");
167    parser.add_option("--cpu-clock", action="store", type="string",
168                      default='2GHz',
169                      help="Clock for blocks running at CPU speed")
170    parser.add_option("--smt", action="store_true", default=False,
171                      help = """
172                      Only used if multiple programs are specified. If true,
173                      then the number of threads per cpu is same as the
174                      number of programs.""")
175    parser.add_option("--elastic-trace-en", action="store_true",
176                      help="""Enable capture of data dependency and instruction
177                      fetch traces using elastic trace probe.""")
178    # Trace file paths input to trace probe in a capture simulation and input
179    # to Trace CPU in a replay simulation
180    parser.add_option("--inst-trace-file", action="store", type="string",
181                      help="""Instruction fetch trace file input to
182                      Elastic Trace probe in a capture simulation and
183                      Trace CPU in a replay simulation""", default="")
184    parser.add_option("--data-trace-file", action="store", type="string",
185                      help="""Data dependency trace file input to
186                      Elastic Trace probe in a capture simulation and
187                      Trace CPU in a replay simulation""", default="")
188
189    parser.add_option("-l", "--lpae", action="store_true")
190    parser.add_option("-V", "--virtualisation", action="store_true")
191
192    # dist-gem5 options
193    parser.add_option("--dist", action="store_true",
194                      help="Parallel distributed gem5 simulation.")
195    parser.add_option("--dist-sync-on-pseudo-op", action="store_true",
196                      help="Use a pseudo-op to start dist-gem5 synchronization.")
197    parser.add_option("--is-switch", action="store_true",
198                      help="Select the network switch simulator process for a"\
199                      "distributed gem5 run")
200    parser.add_option("--dist-rank", default=0, action="store", type="int",
201                      help="Rank of this system within the dist gem5 run.")
202    parser.add_option("--dist-size", default=0, action="store", type="int",
203                      help="Number of gem5 processes within the dist gem5 run.")
204    parser.add_option("--dist-server-name",
205                      default="127.0.0.1",
206                      action="store", type="string",
207                      help="Name of the message server host\nDEFAULT: localhost")
208    parser.add_option("--dist-server-port",
209                      default=2200,
210                      action="store", type="int",
211                      help="Message server listen port\nDEFAULT: 2200")
212    parser.add_option("--dist-sync-repeat",
213                      default="0us",
214                      action="store", type="string",
215                      help="Repeat interval for synchronisation barriers among dist-gem5 processes\nDEFAULT: --ethernet-linkdelay")
216    parser.add_option("--dist-sync-start",
217                      default="5200000000000t",
218                      action="store", type="string",
219                      help="Time to schedule the first dist synchronisation barrier\nDEFAULT:5200000000000t")
220    parser.add_option("--ethernet-linkspeed", default="10Gbps",
221                        action="store", type="string",
222                        help="Link speed in bps\nDEFAULT: 10Gbps")
223    parser.add_option("--ethernet-linkdelay", default="10us",
224                      action="store", type="string",
225                      help="Link delay in seconds\nDEFAULT: 10us")
226
227    # Run duration options
228    parser.add_option("-I", "--maxinsts", action="store", type="int",
229                      default=None, help="""Total number of instructions to
230                                            simulate (default: run forever)""")
231    parser.add_option("--work-item-id", action="store", type="int",
232                      help="the specific work id for exit & checkpointing")
233    parser.add_option("--num-work-ids", action="store", type="int",
234                      help="Number of distinct work item types")
235    parser.add_option("--work-begin-cpu-id-exit", action="store", type="int",
236                      help="exit when work starts on the specified cpu")
237    parser.add_option("--work-end-exit-count", action="store", type="int",
238                      help="exit at specified work end count")
239    parser.add_option("--work-begin-exit-count", action="store", type="int",
240                      help="exit at specified work begin count")
241    parser.add_option("--init-param", action="store", type="int", default=0,
242                      help="""Parameter available in simulation with m5
243                              initparam""")
244    parser.add_option("--initialize-only", action="store_true", default=False,
245                      help="""Exit after initialization. Do not simulate time.
246                              Useful when gem5 is run as a library.""")
247
248    # Simpoint options
249    parser.add_option("--simpoint-profile", action="store_true",
250                      help="Enable basic block profiling for SimPoints")
251    parser.add_option("--simpoint-interval", type="int", default=10000000,
252                      help="SimPoint interval in num of instructions")
253    parser.add_option("--take-simpoint-checkpoints", action="store", type="string",
254        help="<simpoint file,weight file,interval-length,warmup-length>")
255    parser.add_option("--restore-simpoint-checkpoint", action="store_true",
256        help="restore from a simpoint checkpoint taken with " +
257             "--take-simpoint-checkpoints")
258
259    # Checkpointing options
260    ###Note that performing checkpointing via python script files will override
261    ###checkpoint instructions built into binaries.
262    parser.add_option("--take-checkpoints", action="store", type="string",
263        help="<M,N> take checkpoints at tick M and every N ticks thereafter")
264    parser.add_option("--max-checkpoints", action="store", type="int",
265        help="the maximum number of checkpoints to drop", default=5)
266    parser.add_option("--checkpoint-dir", action="store", type="string",
267        help="Place all checkpoints in this absolute directory")
268    parser.add_option("-r", "--checkpoint-restore", action="store", type="int",
269        help="restore from checkpoint <N>")
270    parser.add_option("--checkpoint-at-end", action="store_true",
271                      help="take a checkpoint at end of run")
272    parser.add_option("--work-begin-checkpoint-count", action="store", type="int",
273                      help="checkpoint at specified work begin count")
274    parser.add_option("--work-end-checkpoint-count", action="store", type="int",
275                      help="checkpoint at specified work end count")
276    parser.add_option("--work-cpus-checkpoint-count", action="store", type="int",
277                      help="checkpoint and exit when active cpu count is reached")
278    parser.add_option("--restore-with-cpu", action="store", type="choice",
279                      default="AtomicSimpleCPU", choices=CpuConfig.cpu_names(),
280                      help = "cpu type for restoring from a checkpoint")
281
282
283    # CPU Switching - default switch model goes from a checkpoint
284    # to a timing simple CPU with caches to warm up, then to detailed CPU for
285    # data measurement
286    parser.add_option("--repeat-switch", action="store", type="int",
287        default=None,
288        help="switch back and forth between CPUs with period <N>")
289    parser.add_option("-s", "--standard-switch", action="store", type="int",
290        default=None,
291        help="switch from timing to Detailed CPU after warmup period of <N>")
292    parser.add_option("-p", "--prog-interval", type="str",
293        help="CPU Progress Interval")
294
295    # Fastforwarding and simpoint related materials
296    parser.add_option("-W", "--warmup-insts", action="store", type="int",
297        default=None,
298        help="Warmup period in total instructions (requires --standard-switch)")
299    parser.add_option("--bench", action="store", type="string", default=None,
300        help="base names for --take-checkpoint and --checkpoint-restore")
301    parser.add_option("-F", "--fast-forward", action="store", type="string",
302        default=None,
303        help="Number of instructions to fast forward before switching")
304    parser.add_option("-S", "--simpoint", action="store_true", default=False,
305        help="""Use workload simpoints as an instruction offset for
306                --checkpoint-restore or --take-checkpoint.""")
307    parser.add_option("--at-instruction", action="store_true", default=False,
308        help="""Treat value of --checkpoint-restore or --take-checkpoint as a
309                number of instructions.""")
310    parser.add_option("--spec-input", default="ref", type="choice",
311                      choices=["ref", "test", "train", "smred", "mdred",
312                               "lgred"],
313                      help="Input set size for SPEC CPU2000 benchmarks.")
314    parser.add_option("--arm-iset", default="arm", type="choice",
315                      choices=["arm", "thumb", "aarch64"],
316                      help="ARM instruction set.")
317
318
319def addSEOptions(parser):
320    # Benchmark options
321    parser.add_option("-c", "--cmd", default="",
322                      help="The binary to run in syscall emulation mode.")
323    parser.add_option("-o", "--options", default="",
324                      help="""The options to pass to the binary, use " "
325                              around the entire string""")
326    parser.add_option("-e", "--env", default="",
327                      help="Initialize workload environment from text file.")
328    parser.add_option("-i", "--input", default="",
329                      help="Read stdin from a file.")
330    parser.add_option("--output", default="",
331                      help="Redirect stdout to a file.")
332    parser.add_option("--errout", default="",
333                      help="Redirect stderr to a file.")
334
335def addFSOptions(parser):
336    from .FSConfig import os_types
337
338    # Simulation options
339    parser.add_option("--timesync", action="store_true",
340            help="Prevent simulated time from getting ahead of real time")
341
342    # System options
343    parser.add_option("--kernel", action="store", type="string")
344    parser.add_option("--os-type", action="store", type="choice",
345                      choices=os_types[str(buildEnv['TARGET_ISA'])],
346                      default="linux",
347                      help="Specifies type of OS to boot")
348    parser.add_option("--script", action="store", type="string")
349    parser.add_option("--frame-capture", action="store_true",
350            help="Stores changed frame buffers from the VNC server to compressed "\
351            "files in the gem5 output directory")
352
353    if buildEnv['TARGET_ISA'] == "arm":
354        parser.add_option("--bare-metal", action="store_true",
355                   help="Provide the raw system without the linux specific bits")
356        parser.add_option("--list-machine-types",
357                          action="callback", callback=_listPlatformTypes,
358                      help="List available platform types")
359        parser.add_option("--machine-type", action="store", type="choice",
360                choices=PlatformConfig.platform_names(),
361                default="VExpress_EMM")
362        parser.add_option("--dtb-filename", action="store", type="string",
363              help="Specifies device tree blob file to use with device-tree-"\
364              "enabled kernels")
365        parser.add_option("--enable-security-extensions", action="store_true",
366              help="Turn on the ARM Security Extensions")
367        parser.add_option("--enable-context-switch-stats-dump", \
368                action="store_true", help="Enable stats dump at context "\
369                "switches and dump tasks file (required for Streamline)")
370
371    # Benchmark options
372    parser.add_option("--dual", action="store_true",
373                      help="Simulate two systems attached with an ethernet link")
374    parser.add_option("-b", "--benchmark", action="store", type="string",
375                      dest="benchmark",
376                      help="Specify the benchmark to run. Available benchmarks: %s"\
377                      % DefinedBenchmarks)
378
379    # Metafile options
380    parser.add_option("--etherdump", action="store", type="string", dest="etherdump",
381                      help="Specify the filename to dump a pcap capture of the" \
382                      "ethernet traffic")
383
384    # Disk Image Options
385    parser.add_option("--disk-image", action="store", type="string", default=None,
386                      help="Path to the disk image to use.")
387    parser.add_option("--root-device", action="store", type="string", default=None,
388                      help="OS device name for root partition")
389
390    # Command line options
391    parser.add_option("--command-line", action="store", type="string",
392                      default=None,
393                      help="Template for the kernel command line.")
394    parser.add_option("--command-line-file", action="store",
395                      default=None, type="string",
396                      help="File with a template for the kernel command line")
397