Gabe Black has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/33900 )

Change subject: sim: Add a mechanism for finding an compatible SE workload.
......................................................................

sim: Add a mechanism for finding an compatible SE workload.

This makes it possible to pick an SEWorkload generically at the config
level and not in C++ after the structure of the simulation has already
been set.

Change-Id: I7e52beb5a4d45aa43192e1ba4de6c5aab8b43d84
---
M src/sim/Workload.py
1 file changed, 43 insertions(+), 1 deletion(-)



diff --git a/src/sim/Workload.py b/src/sim/Workload.py
index f1974bb..0b141d8 100644
--- a/src/sim/Workload.py
+++ b/src/sim/Workload.py
@@ -28,6 +28,8 @@

 from m5.objects.SimpleMemory import *

+from six import with_metaclass
+
 class Workload(SimObject):
     type = 'Workload'
     cxx_header = "sim/workload.hh"
@@ -51,6 +53,46 @@

     command_line = Param.String("a", "boot flags to pass to the kernel")

-class SEWorkload(Workload):
+class SEWorkloadMeta(type(Workload)):
+    all_se_workload_classes = []
+    def __new__(mcls, name, bases, dct):
+        cls = super(SEWorkloadMeta, mcls).__new__(mcls, name, bases, dct)
+        SEWorkloadMeta.all_se_workload_classes.append(cls)
+        return cls
+
+class SEWorkload(Workload, metaclass=SEWorkloadMeta):
     type = 'SEWorkload'
     cxx_header = "sim/se_workload.hh"
+    cxx_class = 'SEWorkload'
+
+    @classmethod
+    def _is_compatible_with(cls, obj):
+        return False
+
+    @classmethod
+    def find_compatible(cls, path):
+        '''List the SE workloads compatible with the binary at path'''
+
+        from _m5 import object_file
+        obj = object_file.create(path)
+        options = list(filter(lambda wld: wld._is_compatible_with(obj),
+                              SEWorkloadMeta.all_se_workload_classes))
+
+        return options
+
+    @classmethod
+    def init_compatible(cls, path, *args, **kwargs):
+ '''Construct the only SE workload compatible with the binary at path'''
+
+        options = SEWorkload.find_compatible(path)
+
+        if len(options) > 1:
+ raise ValueError("More than one SE workload is compatible with %s")
+        elif len(options) < 1:
+            # For now, fall back to the base class if there are no matches.
+ # After we've had a chance to implement everything, this default + # can be removed since this should always find exactly one match.
+            return SEWorkload(*args, **kwargs)
+            raise ValueError("No SE workload is compatible with %s", path)
+
+        return options[0](*args, **kwargs)

--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/33900
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: I7e52beb5a4d45aa43192e1ba4de6c5aab8b43d84
Gerrit-Change-Number: 33900
Gerrit-PatchSet: 1
Gerrit-Owner: Gabe Black <gabebl...@google.com>
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