From: Gabe Black Date: Wed, 26 Aug 2020 06:24:47 +0000 (-0700) Subject: sim: Add a mechanism for finding an compatible SE workload. X-Git-Tag: develop-gem5-snapshot~677 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8041ab0ad70a44406e330801b96b6b7ee010d456;p=gem5.git 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 Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/33900 Reviewed-by: Andreas Sandberg Maintainer: Andreas Sandberg Tested-by: kokoro --- diff --git a/src/sim/Workload.py b/src/sim/Workload.py index f1974bbe9..4f1b1b56e 100644 --- a/src/sim/Workload.py +++ b/src/sim/Workload.py @@ -51,6 +51,46 @@ class KernelWorkload(Workload): 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)