From 7799827d1ce32d001f229bc62a50e053bd27d387 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 | 15 +++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/pycheribuild/projects/cross/cheribsd.py b/pycheribuild/projects/cross/cheribsd.py index a842f0fd2..58c7397ba 100644 --- a/pycheribuild/projects/cross/cheribsd.py +++ b/pycheribuild/projects/cross/cheribsd.py @@ -90,6 +90,7 @@ class KernelABI(Enum): NOCHERI = "no-cheri" HYBRID = "hybrid" PURECAP = "purecap" + PURECAP_BENCHMARK = "purecap-benchmark" class ConfigPlatform(Enum): @@ -161,6 +162,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]", @@ -240,7 +244,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)) @@ -248,7 +252,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) @@ -260,7 +264,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) @@ -295,11 +299,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) @@ -308,7 +318,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) ) @@ -1876,6 +1886,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" ) @@ -1942,6 +1963,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 f104c7df4..ea269292d 100644 --- a/tests/test_argument_parsing.py +++ b/tests/test_argument_parsing.py @@ -912,9 +912,23 @@ def test_disk_image_path(target, expected_name): pytest.param( "cheribsd-morello-purecap", [], + ["GENERIC-MORELLO-PURECAP", "GENERIC-MORELLO"], + ), + pytest.param( + "cheribsd-morello-purecap", + ["--cheribsd/build-benchmark-abi-kernels"], + ["GENERIC-MORELLO-PURECAP", "GENERIC-MORELLO", "GENERIC-MORELLO-PURECAP-BENCHMARK"], + ), + pytest.param( + "cheribsd-morello-purecap", + ["--cheribsd/build-benchmark-abi-kernels", "--cheribsd/build-bench-kernels"], [ "GENERIC-MORELLO-PURECAP", + "GENERIC-MORELLO-PURECAP-NODEBUG", "GENERIC-MORELLO", + "GENERIC-MORELLO-NODEBUG", + "GENERIC-MORELLO-PURECAP-BENCHMARK", + "GENERIC-MORELLO-PURECAP-BENCHMARK-NODEBUG", ], ), pytest.param( @@ -1252,6 +1266,7 @@ def test_mfs_root_kernel_config_options(): "auto_var_init", "build_alternate_abi_kernels", "build_bench_kernels", + "build_benchmark_abi_kernels", "build_fett_kernels", "build_fpga_kernels", "build_nocaprevoke_kernels",