Tom Rollet has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/50728 )
Change subject: tests: add tests for the perfect BP
......................................................................
tests: add tests for the perfect BP
Change-Id: Ic81192fab6318e0744031b1b1e97d538538c3821
---
M src/cpu/o3/commit.cc
M tests/gem5/configs/simple_binary_run.py
A tests/gem5/options/perfect_bp/ARM_hello_trace_BP.gz
A tests/gem5/options/perfect_bp/GCN3_X86_hello_trace_BP.gz
A tests/gem5/options/perfect_bp/test_perfect_bp.py
M tests/gem5/verifier.py
6 files changed, 255 insertions(+), 3 deletions(-)
diff --git a/src/cpu/o3/commit.cc b/src/cpu/o3/commit.cc
index 2325118..c02eee6 100644
--- a/src/cpu/o3/commit.cc
+++ b/src/cpu/o3/commit.cc
@@ -191,7 +191,6 @@
commitSquashedInsts.prereq(commitSquashedInsts);
commitNonSpecStalls.prereq(commitNonSpecStalls);
- branchMispredicts.prereq(branchMispredicts);
numCommittedDist
.init(0,commit->commitWidth,1)
diff --git a/tests/gem5/configs/simple_binary_run.py
b/tests/gem5/configs/simple_binary_run.py
index 2c27ef7..e5d4ad5 100644
--- a/tests/gem5/configs/simple_binary_run.py
+++ b/tests/gem5/configs/simple_binary_run.py
@@ -75,6 +75,20 @@
help="Override a local resource if the hashes do not match.",
)
+parser.add_argument(
+ "--trace-BP",
+ type=str,
+ required=False,
+ help="Used to test the generation of the branch trace"
+)
+
+parser.add_argument(
+ "--perfect-BP",
+ type=str,
+ required=False,
+ help="Used to test the perfect branch predictor"
+)
+
args = parser.parse_args()
def input_to_cputype(input: str) -> CPUTypes:
@@ -111,6 +125,18 @@
root = Root(full_system=False, system=motherboard)
+
+# Used in the tests from 'options/perfect_bp/test_perfect_bp.py'
+if args.trace_BP:
+ core = root.system.get_processor().get_cores()[0].get_simobject()
+ core.trace_BP = True
+ core.trace_file_BP = args.trace_BP
+if args.perfect_BP:
+ core = root.system.get_processor().get_cores()[0].get_simobject()
+ core.branchPred.perfect = True
+ core.branchPred.perfectBranchPredictorTrace = args.perfect_BP
+
+
if args.cpu == "kvm":
# TODO: This of annoying. Is there a way to fix this to happen
# automatically when running KVM?
diff --git a/tests/gem5/options/perfect_bp/ARM_hello_trace_BP.gz
b/tests/gem5/options/perfect_bp/ARM_hello_trace_BP.gz
new file mode 100644
index 0000000..d113012
--- /dev/null
+++ b/tests/gem5/options/perfect_bp/ARM_hello_trace_BP.gz
Binary files differ
diff --git a/tests/gem5/options/perfect_bp/GCN3_X86_hello_trace_BP.gz
b/tests/gem5/options/perfect_bp/GCN3_X86_hello_trace_BP.gz
new file mode 100644
index 0000000..6e61fc6
--- /dev/null
+++ b/tests/gem5/options/perfect_bp/GCN3_X86_hello_trace_BP.gz
Binary files differ
diff --git a/tests/gem5/options/perfect_bp/test_perfect_bp.py
b/tests/gem5/options/perfect_bp/test_perfect_bp.py
new file mode 100644
index 0000000..4d32f6a
--- /dev/null
+++ b/tests/gem5/options/perfect_bp/test_perfect_bp.py
@@ -0,0 +1,186 @@
+# Copyright (c) 2021 Huawei International
+# Copyright (c) 2020 The Regents of the University of California
+# All rights reserved.
+#
+# Copyright (c) 2020 ARM Limited
+# All rights reserved
+#
+# The license below extends only to copyright in the software and shall
+# not be construed as granting a license to any other intellectual
+# property including but not limited to intellectual property relating
+# to a hardware implementation of the functionality of the software
+# licensed hereunder. You may use the software subject to the license
+# terms below provided that you ensure that this notice is replicated
+# unmodified and in its entirety in all distributions of the software,
+# modified or unmodified, in source code or in binary form.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met: redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer;
+# redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution;
+# neither the name of the copyright holders nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+
+"""
+Test file for the perfect branch predictor and its trace generation.
+The first test generates a trace for the hello binary and compares it
+with a pre-generated one.
+The second test uses the pre-generated trace to feed the perfect branch
+predictor.
+The stats are checked to be sure that no mispredictions were spotted at
commit.
+"""
+
+from testlib import *
+
+import re
+
+
+_static_progs = {
+ constants.gcn3_x86_tag: ( "x86-hello64-static",),
+ constants.arm_tag: ( "arm-hello64-static",),
+ constants.riscv_tag: ("riscv-hello",),
+ constants.mips_tag: ("mips-hello",),
+ constants.sparc_tag: ("sparc-hello",),
+}
+
+_cpu_types = {
+ constants.gcn3_x86_tag: ("atomic", "o3"),
+ constants.arm_tag: ("atomic", "o3"),
+ constants.riscv_tag: ("atomic", "o3"),
+ constants.mips_tag: ("atomic", "o3"),
+ constants.sparc_tag: ("atomic"),
+}
+
+_os_length = {
+ constants.gcn3_x86_tag: constants.quick_tag,
+ constants.arm_tag: constants.quick_tag,
+ constants.riscv_tag: constants.quick_tag,
+ constants.mips_tag: constants.long_tag,
+ constants.sparc_tag: constants.long_tag,
+}
+
+
+if config.bin_path:
+ resource_path = config.bin_path
+else:
+ resource_path = joinpath(absdirpath(__file__), "..", "resources")
+
+
+def verify_config(isa, binary, cpu, hosts):
+
+ # Filter arch that have a branch trace file for the hello binary
+ ref_trace_file_name = isa + "_hello_trace_BP.gz"
+ ref_branch_trace_file = joinpath(absdirpath(__file__),
ref_trace_file_name)
+ if not os.path.isfile(ref_branch_trace_file):
+ return
+
+ """
+ Branch trace generation test
+ """
+
+
+ generated_trace_file_name = isa + "_hello_trace_BP.gz"
+
+ # Makes sure that the generated trace is EXACTLY the same as the ref
+ # May break if changes are made in gem5 on where the binary is mapped
in
+ # memory (trace contains pc and target of all branches)
+ trace_verifier = verifier.MatchFile(
+ ref = ref_branch_trace_file,
+ filename = generated_trace_file_name,
+ )
+
+ gem5_verify_config(
+ name="test-trace-bp-" + binary + "-" + cpu,
+ fixtures=(),
+ verifiers=(trace_verifier,),
+ config=joinpath(
+ config.base_dir,
+ "tests",
+ "gem5",
+ "configs",
+ "simple_binary_run.py",
+ ),
+ config_args=[
+ binary,
+ cpu,
+ "--override-download",
+ "--resource-directory",
+ resource_path,
+ "--trace-BP",
+ generated_trace_file_name,
+ ],
+ valid_isas=(isa,),
+ valid_hosts=hosts,
+ length=_os_length[isa],
+ )
+
+ """
+ Perfect Branch Predictor Test on o3 cpu
+ """
+ if not cpu == "o3":
+ return
+
+
+ """
+ Make sure the o3 cpu does not commit mispredicted branches
+ Match a string(no spaces) finishing by 'branchMispredicts'
+ The string is followed by spaces and a 0
+ Ex: it will match:
+ 'system.processor.cores.core.commit.branchMispredicts 0'
+ """
+ match_mispred = re.compile(r"^[^\s]*commit\.branchMispredicts\s*0")
+
+ perfect_BP_verifier = verifier.MatchRegex(
+ regex = match_mispred,
+ match_stderr = False,
+ match_stdout = False,
+ files_to_match = [constants.gem5_simulation_stats])
+
+ gem5_verify_config(
+ name="test-perfect-bp-" + binary + "-" + cpu,
+ verifiers=(perfect_BP_verifier,),
+ fixtures=(),
+ config=joinpath(
+ config.base_dir,
+ "tests",
+ "gem5",
+ "configs",
+ "simple_binary_run.py",
+ ),
+ config_args=[
+ binary,
+ cpu,
+ "--override-download",
+ "--resource-directory",
+ resource_path,
+ "--perfect-BP",
+ ref_branch_trace_file,
+ ],
+ valid_isas=(isa,),
+ valid_hosts=hosts,
+ length=_os_length[isa],
+ )
+
+
+# Run statically linked hello worlds
+for isa in _static_progs:
+ for binary in _static_progs[isa]:
+ for cpu in _cpu_types[isa]:
+ verify_config(isa, binary, cpu, constants.supported_hosts)
diff --git a/tests/gem5/verifier.py b/tests/gem5/verifier.py
index f6687f5..3e8f3e0 100644
--- a/tests/gem5/verifier.py
+++ b/tests/gem5/verifier.py
@@ -42,6 +42,7 @@
'''
import re
import os
+import filecmp
from testlib import test_util
from testlib.configuration import constants
@@ -188,6 +189,41 @@
re.compile(r'''^\s*"(cwd|input|codefile)":'''),
)
+class MatchFile(Verifier):
+ """
+ Look if 2 files are identical, at the binary level
+ The MatchGoldStandard could theoretically also provide this feature,
+ but the helper functions in ext/testlib/helper.py need refactoring
+ to also handle files opened in binary mode.
+ """
+
+ def __init__(self, ref, filename):
+ super(MatchFile, self).__init__()
+
+ if not os.path.isfile(ref):
+ raise Exception()
+
+ self.ref = ref
+ self.filename = filename
+
+
+ def test(self, params):
+ fixtures = params.fixtures
+ # Get the file from the tempdir of the test.
+ tempdir = fixtures[constants.tempdir_fixture_name].path
+
+ # Generated file to match
+ new_file = joinpath(tempdir, self.filename)
+
+ if new_file:
+ if filecmp.cmp(self.ref, new_file):
+ return #Success
+ test_util.fail('Tese files does not match: ' + self.filename
+ " "
+ + self.ref)
+ else:
+ test_util.fail('Could not find the file: ' + self.filename)
+
+
class MatchFileRegex(Verifier):
"""
Looking for a match between a regex pattern and the content of a list
@@ -219,14 +255,19 @@
class MatchRegex(MatchFileRegex):
"""
- Looking for a match between a regex pattern and stdout/stderr.
+ Looking for a match between a regex pattern and stdout/stderr/given
file
+ list
"""
- def __init__(self, regex, match_stderr=True, match_stdout=True):
+ def __init__(self, regex, match_stderr=True, match_stdout=True,
+ files_to_match=None):
filenames = list()
if match_stdout:
filenames.append(constants.gem5_simulation_stdout)
if match_stderr:
filenames.append(constants.gem5_simulation_stderr)
+ if files_to_match:
+ filenames += files_to_match
+
super(MatchRegex, self).__init__(regex, filenames)
_re_type = type(re.compile(''))
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/50728
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: Ic81192fab6318e0744031b1b1e97d538538c3821
Gerrit-Change-Number: 50728
Gerrit-PatchSet: 1
Gerrit-Owner: Tom Rollet <tom.rol...@huawei.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