Bobby R. Bruce has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/50753 )

Change subject: python: Add simulate.py to the gem5 library
......................................................................

python: Add simulate.py to the gem5 library

This replaces the `m5.simulate` and `m5.instantiate` functions, thereby
removing some gem5 boilerplate code.

Change-Id: I4706119478464efcf4d92e3a1da05bddd0953b6a
---
A src/python/gem5/simulate.py
M tests/gem5/configs/x86_boot_exit_run.py
2 files changed, 62 insertions(+), 12 deletions(-)



diff --git a/src/python/gem5/simulate.py b/src/python/gem5/simulate.py
new file mode 100644
index 0000000..6aaddd8
--- /dev/null
+++ b/src/python/gem5/simulate.py
@@ -0,0 +1,58 @@
+# Copyright (c) 2021 The Regents of the University of California
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+import m5
+from m5.objects import Root
+
+from typing import Optional
+
+from components.boards.abstract_board import AbstractBoard
+from components.processors.cpu_types import CPUTypes
+
+instantiated: bool = False
+
+def instantiate(board: AbstractBoard, full_system: bool = True) -> None:
+
+
+    if instantiated:
+        raise Exception("This board has already been instantiated.")
+
+    root = Root(full_system=full_system, system=board)
+
+    if CPUTypes.KVM in [
+            core.get_type() for core in board.get_processor().get_cores()
+        ]:
+        root.sim_quantum = int(1e9)
+
+    m5.instantiate()
+
+def simulate(to_tick: Optional[int] = None):
+    if not instantiated:
+        raise Exception("This board has not been instantiated.")
+
+    if to_tick:
+        return m5.simulate(to_tick)
+    return m5.simulate()
\ No newline at end of file
diff --git a/tests/gem5/configs/x86_boot_exit_run.py b/tests/gem5/configs/x86_boot_exit_run.py
index 6c5488d..be25e66 100644
--- a/tests/gem5/configs/x86_boot_exit_run.py
+++ b/tests/gem5/configs/x86_boot_exit_run.py
@@ -29,7 +29,6 @@
 """

 import m5
-from m5.objects import Root

 from gem5.runtime import (
     get_runtime_coherence_protocol,
@@ -43,6 +42,7 @@
 from gem5.isas import ISA
 from gem5.coherence_protocol import CoherenceProtocol
 from gem5.resources.resource import Resource
+from gem5.simulate import instantiate, simulate

 import argparse

@@ -214,27 +214,19 @@
     kernel_args=additional_kernal_args,
 )

-
# Begin running of the simulation. This will exit once the Linux system boot
 # is complete.
 print("Running with ISA: " + get_runtime_isa().name)
 print("Running with protocol: " + get_runtime_coherence_protocol().name)
 print()

-root = Root(full_system=True, system=motherboard)
-
-if args.cpu == "kvm":
-    # TODO: This of annoying. Is there a way to fix this to happen
-    # automatically when running KVM?
-    root.sim_quantum = int(1e9)
-
-m5.instantiate()
+instantiate(board=motherboard)

 print("Beginning simulation!")
 if args.tick_exit != None:
-    exit_event = m5.simulate(args.tick_exit)
+    exit_event = simulate(args.tick_exit)
 else:
-    exit_event = m5.simulate()
+    exit_event = simulate()
 print(
"Exiting @ tick {} because {}.".format(m5.curTick(), exit_event.getCause())
 )

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/50753
To unsubscribe, or for help writing mail filters, visit https://gem5-review.googlesource.com/settings

Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: I4706119478464efcf4d92e3a1da05bddd0953b6a
Gerrit-Change-Number: 50753
Gerrit-PatchSet: 1
Gerrit-Owner: Bobby R. Bruce <bbr...@ucdavis.edu>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- gem5-dev@gem5.org
To unsubscribe send an email to gem5-dev-le...@gem5.org
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s

Reply via email to