Bobby R. Bruce has submitted this change. (
https://gem5-review.googlesource.com/c/public/gem5/+/51948 )
Change subject: stdlib: Automatically set disk root partition in
set_workload
......................................................................
stdlib: Automatically set disk root partition in set_workload
The linux kernel `root` parameter must be specified in the board's
`set_workload` function. However, the root partition on a disk image
passed to this function can change. Therefore, for gem5 resources disk
images, we inspect the metadata to obtain the root partition and
automatically set this.
This patch is dependent on the following gem5 resources change to
function correctly:
https://gem5-review.googlesource.com/c/public/gem5-resources/+/51887
Note: This patch will only automatically set the root partition
information for disk images in gem5 resources.
Issue-on: https://gem5.atlassian.net/browse/GEM5-1102
Change-Id: I9a19706f3ba78bf026b6bfdff4bff84a3c8ccdb2
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/51948
Reviewed-by: Bobby R. Bruce <[email protected]>
Maintainer: Bobby R. Bruce <[email protected]>
Tested-by: kokoro <[email protected]>
---
M src/python/gem5/components/boards/riscv_board.py
M src/python/gem5/resources/resource.py
M src/python/gem5/components/boards/x86_board.py
3 files changed, 75 insertions(+), 9 deletions(-)
Approvals:
Bobby R. Bruce: Looks good to me, approved; Looks good to me, approved
kokoro: Regressions pass
diff --git a/src/python/gem5/components/boards/riscv_board.py
b/src/python/gem5/components/boards/riscv_board.py
index 43a5112..3fc15cb 100644
--- a/src/python/gem5/components/boards/riscv_board.py
+++ b/src/python/gem5/components/boards/riscv_board.py
@@ -240,7 +240,19 @@
image.child.image_file = disk_image.get_local_path()
self.disk.vio.image = image
- self.workload.command_line = "console=ttyS0 root=/dev/vda ro"
+ # Determine where the root exists in the disk image. This is done
by
+ # inspecting the resource metadata.
+ root_val = "/dev/vda"
+ try:
+ partition_val =
disk_image.get_metadata()["additional_metadata"]\
+ ["root_partition"]
+ except KeyError:
+ partition_val = None
+
+ if partition_val is not None:
+ root_val += partition_val
+
+ self.workload.command_line = f"console=ttyS0 root={root_val} ro"
# Note: This must be called after set_workload because it looks
for an
# attribute named "disk" and connects
diff --git a/src/python/gem5/components/boards/x86_board.py
b/src/python/gem5/components/boards/x86_board.py
index c6ce459..a32ee7d 100644
--- a/src/python/gem5/components/boards/x86_board.py
+++ b/src/python/gem5/components/boards/x86_board.py
@@ -288,20 +288,34 @@
first partition should be the root partition.
:param command: The command(s) to run with bash once the OS is
booted
:param kernel_args: Additional arguments to be passed to the
kernel.
- `earlyprintk=ttyS0 console=ttyS0 lpj=7999923 root=/dev/hda1` are
- already passed. This parameter is used to pass additional
arguments.
+ `earlyprintk=ttyS0 console=ttyS0 lpj=7999923
+ root=/dev/hda<partition_val>` are already passed
(`<partition_val>` is
+ automatically inferred from resource metadata). This parameter is
used
+ to pass additional arguments.
"""
# Set the Linux kernel to use.
self.workload.object_file = kernel.get_local_path()
+ # Determine where the root exists in the disk image. This is done
by
+ # inspecting the resource metadata.
+ root_val = "/dev/hda"
+ try:
+ partition_val =
disk_image.get_metadata()["additional_metadata"]\
+ ["root_partition"]
+ except KeyError:
+ partition_val = None
+
+ if partition_val is not None:
+ root_val += partition_val
+
# Options specified on the kernel command line.
self.workload.command_line = " ".join(
[
"earlyprintk=ttyS0",
"console=ttyS0",
"lpj=7999923",
- "root=/dev/hda1",
+ f"root={root_val}",
] + kernel_args
)
diff --git a/src/python/gem5/resources/resource.py
b/src/python/gem5/resources/resource.py
index 07c6a80..b054b09 100644
--- a/src/python/gem5/resources/resource.py
+++ b/src/python/gem5/resources/resource.py
@@ -28,9 +28,9 @@
import os
from pathlib import Path
-from .downloader import get_resource
+from .downloader import get_resource, get_resources_json_obj
-from typing import Optional
+from typing import Optional, Dict
"""
A Resource object encapsulates a gem5 resource. Resources are items needed
to
@@ -50,12 +50,21 @@
__metaclass__ = ABCMeta
- def __init__(self, local_path: str):
+ def __init__(self, local_path: str, metadata: Dict = {}):
self._local_path = local_path
+ self._metadata = metadata
def get_local_path(self) -> str:
return self._local_path
+ def get_metadata(self) -> Dict:
+ """
+ Returns the raw data from this resource, as seen in the
+ `resources.json` file. A user may specify the metadata of a local
+ resource.
+ """
+ return self._metadata
+
class CustomResource(AbstractResource):
"""
@@ -64,9 +73,10 @@
repository.
"""
- def __init__(self, local_path: str):
+ def __init__(self, local_path: str, metadata: Optional[Dict] = None):
"""
:param local_path: The path of the resource on the host system.
+ :param metadata: Add metadata for the custom resource.
"""
super().__init__(local_path=local_path)
@@ -117,11 +127,14 @@
to_path = os.path.join(resource_directory, resource_name)
- super(Resource, self).__init__(local_path=to_path)
+ super(Resource, self).__init__(
+ local_path=to_path,
+ metadata=get_resources_json_obj(resource_name))
get_resource(
resource_name=resource_name, to_path=to_path, override=override
)
+
def _get_default_resource_dir(cls) -> str:
"""
Obtain the default gem5 resources directory on the host system.
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/51948
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: I9a19706f3ba78bf026b6bfdff4bff84a3c8ccdb2
Gerrit-Change-Number: 51948
Gerrit-PatchSet: 10
Gerrit-Owner: Bobby R. Bruce <[email protected]>
Gerrit-Reviewer: Andreas Sandberg <[email protected]>
Gerrit-Reviewer: Bobby R. Bruce <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: Jason Lowe-Power <[email protected]>
Gerrit-Reviewer: kokoro <[email protected]>
Gerrit-MessageType: merged
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s