From 73deffba903e43e2c1580c83aebc290eb23f7e0c Mon Sep 17 00:00:00 2001 From: Alfredo Mazzinghi Date: Wed, 15 May 2024 11:46:01 +0100 Subject: [PATCH] Build Morello benchmark ABI kernels. This is enabled by the build-benchmark-abi-kernels. --- pycheribuild/projects/cross/cheribsd.py | 35 +++++++++++++++++++++---- tests/test_argument_parsing.py | 14 ++++++++++ 2 files changed, 44 insertions(+), 5 deletions(-) diff --git a/pycheribuild/projects/cross/cheribsd.py b/pycheribuild/projects/cross/cheribsd.py index 9ae563af8..1280d9860 100644 --- a/pycheribuild/projects/cross/cheribsd.py +++ b/pycheribuild/projects/cross/cheribsd.py @@ -94,6 +94,7 @@ class KernelABI(Enum): NOCHERI = "no-cheri" HYBRID = "hybrid" PURECAP = "purecap" + PURECAP_BENCHMARK = "purecap-benchmark" class ConfigPlatform(Enum): @@ -165,6 +166,9 @@ def get_platform_name(self, platforms: "set[ConfigPlatform]") -> Optional[str]: return self.platform_name_map[platform] assert False, "Should not be reached..." + def get_available_kabis(self) -> "list[KernelABI]": + return [KernelABI.NOCHERI, KernelABI.HYBRID, KernelABI.PURECAP] + def get_flag_names( self, platforms: "set[ConfigPlatform]", @@ -244,7 +248,7 @@ def get_flag_names( def make_all(self) -> "list[CheriBSDConfig]": configs = [] # Generate QEMU kernels - for kernel_abi in KernelABI: + for kernel_abi in self.get_available_kabis(): configs.append(self.make_config({ConfigPlatform.QEMU}, kernel_abi, default=True)) configs.append(self.make_config({ConfigPlatform.QEMU}, kernel_abi, benchmark=True, default=True)) configs.append(self.make_config({ConfigPlatform.QEMU}, kernel_abi, mfsroot=True, default=True)) @@ -252,7 +256,7 @@ def make_all(self) -> "list[CheriBSDConfig]": self.make_config({ConfigPlatform.QEMU}, kernel_abi, mfsroot=True, benchmark=True, default=True) ) # Generate FPGA kernels - for kernel_abi in KernelABI: + for kernel_abi in self.get_available_kabis(): configs.append(self.make_config({ConfigPlatform.GFE}, kernel_abi, mfsroot=True, default=True)) configs.append( self.make_config({ConfigPlatform.GFE}, kernel_abi, mfsroot=True, benchmark=True, default=True) @@ -264,7 +268,7 @@ def make_all(self) -> "list[CheriBSDConfig]": configs.append(self.make_config({ConfigPlatform.QEMU}, KernelABI.HYBRID, fett=True, default=True)) # Caprevoke kernels - for kernel_abi in KernelABI: + for kernel_abi in self.get_available_kabis(): configs.append(self.make_config({ConfigPlatform.QEMU}, kernel_abi, nocaprevoke=True, default=True)) configs.append( self.make_config({ConfigPlatform.QEMU}, kernel_abi, nocaprevoke=True, benchmark=True, default=True) @@ -299,11 +303,17 @@ def get_kabi_name(self, kernel_abi) -> Optional[str]: return "MORELLO" elif kernel_abi == KernelABI.PURECAP: return f"MORELLO{self.separator}PURECAP" + elif kernel_abi == KernelABI.PURECAP_BENCHMARK: + return f"MORELLO{self.separator}PURECAP{self.separator}BENCHMARK" + + def get_available_kabis(self) -> "list[KernelABI]": + abis = super().get_available_kabis() + return [*abis, KernelABI.PURECAP_BENCHMARK] def make_all(self) -> "list[CheriBSDConfig]": configs = [] # Generate QEMU/FVP kernels - for kernel_abi in KernelABI: + for kernel_abi in self.get_available_kabis(): configs.append(self.make_config({ConfigPlatform.QEMU, ConfigPlatform.FVP}, kernel_abi, default=True)) configs.append( self.make_config({ConfigPlatform.QEMU, ConfigPlatform.FVP}, kernel_abi, default=True, benchmark=True) @@ -312,7 +322,7 @@ def make_all(self) -> "list[CheriBSDConfig]": self.make_config({ConfigPlatform.QEMU, ConfigPlatform.FVP}, kernel_abi, default=True, mfsroot=True) ) # Caprevoke kernels - for kernel_abi in KernelABI: + for kernel_abi in self.get_available_kabis(): configs.append( self.make_config({ConfigPlatform.QEMU, ConfigPlatform.FVP}, kernel_abi, default=True, nocaprevoke=True) ) @@ -1880,6 +1890,17 @@ def setup_config_options(cls, kernel_only_target=False, install_directory_help=N help="Also build kernels with non-default ABI (purecap or hybrid)", ) + cls.build_benchmark_abi_kernels = cls.add_bool_option( + "build-benchmark-abi-kernels", + show_help=True, + only_add_for_targets=[ + CompilationTargets.CHERIBSD_MORELLO_HYBRID, + CompilationTargets.CHERIBSD_MORELLO_PURECAP, + ], + default=False, + help="Also build Morello Benchmark ABI kernels", + ) + cls.build_bench_kernels = cls.add_bool_option( "build-bench-kernels", show_help=True, _allow_unknown_targets=True, help="Also build benchmark kernels" ) @@ -1946,6 +1967,10 @@ def _get_kernel_abis_to_build(self) -> "list[KernelABI]": if self.crosscompile_target in self.purecap_kernel_targets and self.build_alternate_abi_kernels: other_abi = KernelABI.PURECAP if default_kernel_abi != KernelABI.PURECAP else KernelABI.HYBRID kernel_abis.append(other_abi) + if self.build_benchmark_abi_kernels and default_kernel_abi != KernelABI.PURECAP_BENCHMARK: + # Enable benchmark ABI kernels + kernel_abis.append(KernelABI.PURECAP_BENCHMARK) + return kernel_abis def _get_all_kernel_configs(self) -> "list[CheriBSDConfig]": diff --git a/tests/test_argument_parsing.py b/tests/test_argument_parsing.py index a3dcab3b5..fcf751646 100644 --- a/tests/test_argument_parsing.py +++ b/tests/test_argument_parsing.py @@ -913,9 +913,23 @@ def test_disk_image_path(target, expected_name): pytest.param( "cheribsd-morello-purecap", [], + ["GENERIC-MORELLO", "GENERIC-MORELLO-PURECAP"], + ), + pytest.param( + "cheribsd-morello-purecap", + ["--cheribsd/build-benchmark-abi-kernels"], + ["GENERIC-MORELLO", "GENERIC-MORELLO-PURECAP", "GENERIC-MORELLO-PURECAP-BENCHMARK"], + ), + pytest.param( + "cheribsd-morello-purecap", + ["--cheribsd/build-benchmark-abi-kernels", "--cheribsd/build-bench-kernels"], [ "GENERIC-MORELLO", + "GENERIC-MORELLO-NODEBUG", "GENERIC-MORELLO-PURECAP", + "GENERIC-MORELLO-PURECAP-NODEBUG", + "GENERIC-MORELLO-PURECAP-BENCHMARK", + "GENERIC-MORELLO-PURECAP-BENCHMARK-NODEBUG", ], ), pytest.param(