Jairo Balart has uploaded this change for review. ( https://gem5-review.googlesource.com/c/public/gem5/+/15320

Change subject: config: add command line flags to list and select available indirect branch predictors
......................................................................

config: add command line flags to list and select available indirect branch
predictors

Change-Id: I9a855d36de7d95b7785ff8a897899037cea6a3d8
---
M configs/common/BPConfig.py
M configs/common/Options.py
M configs/common/Simulation.py
M configs/example/fs.py
M configs/example/se.py
5 files changed, 77 insertions(+), 2 deletions(-)



diff --git a/configs/common/BPConfig.py b/configs/common/BPConfig.py
index 5e5b92f..12222f9 100644
--- a/configs/common/BPConfig.py
+++ b/configs/common/BPConfig.py
@@ -85,3 +85,54 @@
 for name, cls in inspect.getmembers(m5.objects, is_bp_class):
     _bp_classes[name] = cls

+
+# The same for indirect branch predictors...
+# Dictionary of mapping names of real branch predictor models to classes.
+_indirect_bp_classes = {}
+
+
+def is_indirect_bp_class(cls):
+    """Determine if a class is an indirect branch predictor that can be
+    instantiated"""
+
+    # We can't use the normal inspect.isclass because the ParamFactory
+    # and ProxyFactory classes have a tendency to confuse it.
+    try:
+        return issubclass(cls, m5.objects.IndirectPredictorBase) and \
+            not cls.abstract
+    except (TypeError, AttributeError):
+        return False
+
+def get_indirect(name):
+ """Get an Indirect BP class from a user provided class name or alias."""
+
+    try:
+        indirect_bp_class = _indirect_bp_classes[name]
+        return indirect_bp_class
+    except KeyError:
+        print("%s is not a valid indirect BP model." % (name,))
+        sys.exit(1)
+
+def print_indirect_bp_list():
+    """Print a list of available indirect BP classes."""
+
+    print("Available Indirect BranchPredictor classes:")
+ doc_wrapper = TextWrapper(initial_indent="\t\t", subsequent_indent="\t\t")
+    for name, cls in _indirect_bp_classes.items():
+        print("\t%s" % name)
+
+        # Try to extract the class documentation from the class help
+        # string.
+        doc = inspect.getdoc(cls)
+        if doc:
+            for line in doc_wrapper.wrap(doc):
+                print(line)
+
+def indirect_bp_names():
+    """Return a list of valid Indirect Branch Predictor names."""
+    return _indirect_bp_classes.keys()
+
+# Add all indirect BPs in the object hierarchy.
+for name, cls in inspect.getmembers(m5.objects, is_indirect_bp_class):
+    _indirect_bp_classes[name] = cls
+
diff --git a/configs/common/Options.py b/configs/common/Options.py
index 536da44..d27b549 100644
--- a/configs/common/Options.py
+++ b/configs/common/Options.py
@@ -56,6 +56,10 @@
     BPConfig.print_bp_list()
     sys.exit(0)

+def _listIndirectBPTypes(option, opt, value, parser):
+    BPConfig.print_indirect_bp_list()
+    sys.exit(0)
+
 def _listMemTypes(option, opt, value, parser):
     MemConfig.print_mem_list()
     sys.exit(0)
@@ -154,12 +158,18 @@
     parser.add_option("--list-bp-types",
                       action="callback", callback=_listBPTypes,
                       help="List available branch predictor types")
+    parser.add_option("--list-indirect-bp-types",
+                      action="callback", callback=_listIndirectBPTypes,
+ help="List available indirect branch predictor types")
     parser.add_option("--bp-type", type="choice", default=None,
                       choices=BPConfig.bp_names(),
-                      help = """
-                      type of branch predictor to run with
+                      help = """type of branch predictor to run with
                       (if not set, use the default branch predictor of
                       the selected CPU)""")
+    parser.add_option("--indirect-bp-type", type="choice",
+                      default="IndirectPredictor",
+                      choices=BPConfig.indirect_bp_names(),
+ help = "type of indirect branch predictor to run with")
     parser.add_option("--checker", action="store_true");
     parser.add_option("--cpu-clock", action="store", type="string",
                       default='2GHz',
diff --git a/configs/common/Simulation.py b/configs/common/Simulation.py
index 19bd962..f1093ec 100644
--- a/configs/common/Simulation.py
+++ b/configs/common/Simulation.py
@@ -482,6 +482,11 @@
             if options.bp_type:
                 bpClass = BPConfig.get(options.bp_type)
                 switch_cpus[i].branchPred = bpClass()
+            if options.indirect_bp_type:
+                IndirectBPClass = \
+                    BPConfig.get_indirect(options.indirect_bp_type)
+                switch_cpus[i].branchPred.branchPred.indirectBranchPred = \
+                    IndirectBPClass()

         # If elastic tracing is enabled attach the elastic trace probe
         # to the switch CPUs
diff --git a/configs/example/fs.py b/configs/example/fs.py
index 3fdf151..83bd7e9 100644
--- a/configs/example/fs.py
+++ b/configs/example/fs.py
@@ -203,6 +203,11 @@
             if options.bp_type:
                 bpClass = BPConfig.get(options.bp_type)
                 test_sys.cpu[i].branchPred = bpClass()
+            if options.indirect_bp_type:
+                IndirectBPClass = \
+                    BPConfig.get_indirect(options.indirect_bp_type)
+                test_sys.cpu[i].branchPred.indirectBranchPred = \
+                    IndirectBPClass()
             test_sys.cpu[i].createThreads()

# If elastic tracing is enabled when not restoring from checkpoint and
diff --git a/configs/example/se.py b/configs/example/se.py
index 8403066..925a9be 100644
--- a/configs/example/se.py
+++ b/configs/example/se.py
@@ -238,6 +238,10 @@
         bpClass = BPConfig.get(options.bp_type)
         system.cpu[i].branchPred = bpClass()

+    if options.indirect_bp_type:
+        indirectBPClass = BPConfig.get_indirect(options.indirect_bp_type)
+        system.cpu[i].branchPred.indirectBranchPred = indirectBPClass()
+
     system.cpu[i].createThreads()

 if options.ruby:

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

Gerrit-Project: public/gem5
Gerrit-Branch: master
Gerrit-Change-Id: I9a855d36de7d95b7785ff8a897899037cea6a3d8
Gerrit-Change-Number: 15320
Gerrit-PatchSet: 1
Gerrit-Owner: Jairo Balart <jairo.bal...@metempsy.com>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to