From 8041ab0ad70a44406e330801b96b6b7ee010d456 Mon Sep 17 00:00:00 2001 From: Gabe Black Date: Tue, 25 Aug 2020 23:24:47 -0700 Subject: [PATCH] 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 --- src/sim/Workload.py | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) 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) -- 2.30.2