python: Apply Black formatter to Python files

The command executed was `black src configs tests util`.

Change-Id: I8dfaa6ab04658fea37618127d6ac19270028d771
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/47024
Maintainer: Bobby Bruce <bbruce@ucdavis.edu>
Reviewed-by: Jason Lowe-Power <power.jg@gmail.com>
Reviewed-by: Giacomo Travaglini <giacomo.travaglini@arm.com>
Tested-by: kokoro <noreply+kokoro@google.com>
This commit is contained in:
Bobby R. Bruce
2022-07-05 11:02:25 -07:00
committed by Giacomo Travaglini
parent 1cfaa8da83
commit 787204c92d
980 changed files with 35668 additions and 22233 deletions

View File

@@ -58,11 +58,11 @@ from .util import fatal
from .util import attrdict
# define a MaxTick parameter, unsigned 64 bit
MaxTick = 2**64 - 1
MaxTick = 2 ** 64 - 1
_drain_manager = _m5.drain.DrainManager.instance()
_instantiated = False # Has m5.instantiate() been called?
_instantiated = False # Has m5.instantiate() been called?
# The final call to instantiate the SimObject graph and initialize the
# system.
@@ -85,13 +85,15 @@ def instantiate(ckpt_dir=None):
# Make sure SimObject-valued params are in the configuration
# hierarchy so we catch them with future descendants() walks
for obj in root.descendants(): obj.adoptOrphanParams()
for obj in root.descendants():
obj.adoptOrphanParams()
# Unproxy in sorted order for determinism
for obj in root.descendants(): obj.unproxyParams()
for obj in root.descendants():
obj.unproxyParams()
if options.dump_config:
ini_file = open(os.path.join(options.outdir, options.dump_config), 'w')
ini_file = open(os.path.join(options.outdir, options.dump_config), "w")
# Print ini sections in sorted order for easier diffing
for obj in sorted(root.descendants(), key=lambda o: o.path()):
obj.print_ini(ini_file)
@@ -100,8 +102,10 @@ def instantiate(ckpt_dir=None):
if options.json_config:
try:
import json
json_file = open(
os.path.join(options.outdir, options.json_config), 'w')
os.path.join(options.outdir, options.json_config), "w"
)
d = root.get_config_as_dict()
json.dump(d, json_file, indent=4)
json_file.close()
@@ -116,21 +120,26 @@ def instantiate(ckpt_dir=None):
stats.initSimStats()
# Create the C++ sim objects and connect ports
for obj in root.descendants(): obj.createCCObject()
for obj in root.descendants(): obj.connectPorts()
for obj in root.descendants():
obj.createCCObject()
for obj in root.descendants():
obj.connectPorts()
# Do a second pass to finish initializing the sim objects
for obj in root.descendants(): obj.init()
for obj in root.descendants():
obj.init()
# Do a third pass to initialize statistics
stats._bindStatHierarchy(root)
root.regStats()
# Do a fourth pass to initialize probe points
for obj in root.descendants(): obj.regProbePoints()
for obj in root.descendants():
obj.regProbePoints()
# Do a fifth pass to connect probe listeners
for obj in root.descendants(): obj.regProbeListeners()
for obj in root.descendants():
obj.regProbeListeners()
# We want to generate the DVFS diagram for the system. This can only be
# done once all of the CPP objects have been created and initialised so
@@ -145,15 +154,20 @@ def instantiate(ckpt_dir=None):
if ckpt_dir:
_drain_manager.preCheckpointRestore()
ckpt = _m5.core.getCheckpoint(ckpt_dir)
for obj in root.descendants(): obj.loadState(ckpt)
for obj in root.descendants():
obj.loadState(ckpt)
else:
for obj in root.descendants(): obj.initState()
for obj in root.descendants():
obj.initState()
# Check to see if any of the stat events are in the past after resuming from
# a checkpoint, If so, this call will shift them to be at a valid time.
updateStatEvents()
need_startup = True
def simulate(*args, **kwargs):
global need_startup
global _instantiated
@@ -163,7 +177,8 @@ def simulate(*args, **kwargs):
if need_startup:
root = objects.Root.getInstance()
for obj in root.descendants(): obj.startup()
for obj in root.descendants():
obj.startup()
need_startup = False
# Python exit handlers happen in reverse order.
@@ -189,6 +204,7 @@ def simulate(*args, **kwargs):
return sim_out
def drain():
"""Drain the simulator in preparation of a checkpoint or memory mode
switch.
@@ -212,7 +228,7 @@ def drain():
# WARNING: if a valid exit event occurs while draining, it
# will not get returned to the user script
exit_event = _m5.event.simulate()
while exit_event.getCause() != 'Finished drain':
while exit_event.getCause() != "Finished drain":
exit_event = simulate()
return False
@@ -224,14 +240,17 @@ def drain():
assert _drain_manager.isDrained(), "Drain state inconsistent"
def memWriteback(root):
for obj in root.descendants():
obj.memWriteback()
def memInvalidate(root):
for obj in root.descendants():
obj.memInvalidate()
def checkpoint(dir):
root = objects.Root.getInstance()
if not isinstance(root, objects.Root):
@@ -242,15 +261,19 @@ def checkpoint(dir):
print("Writing checkpoint")
_m5.core.serializeAll(dir)
def _changeMemoryMode(system, mode):
if not isinstance(system, (objects.Root, objects.System)):
raise TypeError("Parameter of type '%s'. Must be type %s or %s." % \
(type(system), objects.Root, objects.System))
raise TypeError(
"Parameter of type '%s'. Must be type %s or %s."
% (type(system), objects.Root, objects.System)
)
if system.getMemoryMode() != mode:
system.setMemoryMode(mode)
else:
print("System already in target mode. Memory mode unchanged.")
def switchCpus(system, cpuList, verbose=True):
"""Switch CPUs in a system.
@@ -283,21 +306,25 @@ def switchCpus(system, cpuList, verbose=True):
raise TypeError("%s is not of type BaseCPU" % new_cpu)
if new_cpu in old_cpu_set:
raise RuntimeError(
"New CPU (%s) is in the list of old CPUs." % (old_cpu,))
"New CPU (%s) is in the list of old CPUs." % (old_cpu,)
)
if not new_cpu.switchedOut():
raise RuntimeError("New CPU (%s) is already active." % (new_cpu,))
if not new_cpu.support_take_over():
raise RuntimeError(
"New CPU (%s) does not support CPU handover." % (old_cpu,))
"New CPU (%s) does not support CPU handover." % (old_cpu,)
)
if new_cpu.memory_mode() != memory_mode_name:
raise RuntimeError(
"%s and %s require different memory modes." % (new_cpu,
new_cpus[0]))
"%s and %s require different memory modes."
% (new_cpu, new_cpus[0])
)
if old_cpu.switchedOut():
raise RuntimeError("Old CPU (%s) is inactive." % (new_cpu,))
if not old_cpu.support_take_over():
raise RuntimeError(
"Old CPU (%s) does not support CPU handover." % (old_cpu,))
"Old CPU (%s) does not support CPU handover." % (old_cpu,)
)
MemoryMode = params.allEnums["MemoryMode"]
try:
@@ -326,11 +353,15 @@ def switchCpus(system, cpuList, verbose=True):
for old_cpu, new_cpu in cpuList:
new_cpu.takeOverFrom(old_cpu)
def notifyFork(root):
for obj in root.descendants():
obj.notifyFork()
fork_count = 0
def fork(simout="%(parent)s.f%(fork_seq)i"):
"""Fork the simulator.
@@ -353,6 +384,7 @@ def fork(simout="%(parent)s.f%(fork_seq)i"):
pid of the child process or 0 if running in the child.
"""
from m5 import options
global fork_count
if not _m5.core.listenersDisabled():
@@ -375,16 +407,17 @@ def fork(simout="%(parent)s.f%(fork_seq)i"):
# Setup a new output directory
parent = options.outdir
options.outdir = simout % {
"parent" : parent,
"fork_seq" : fork_count,
"pid" : os.getpid(),
}
"parent": parent,
"fork_seq": fork_count,
"pid": os.getpid(),
}
_m5.core.setOutputDir(options.outdir)
else:
fork_count += 1
return pid
from _m5.core import disableAllListeners, listenersDisabled
from _m5.core import listenersLoopbackOnly
from _m5.core import curTick