From 576a2303410fb632c1b74b9746f85f4a123302da Mon Sep 17 00:00:00 2001 From: Alexander Egorenkov Date: Wed, 30 Oct 2024 12:49:24 +0100 Subject: [PATCH] util_arch: Use dump area size provided by kernel through sysfs attribute MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Newer s390 kernels provide the new sysfs /sys/firmware/dump/dump_area_size attribute which specifies the exact size of machine's dump area size. Use this value if it is present but fall back to the previous and slightly improved way of computation of dump area size to support also older s390 kernels w/o the new sysfs attribute. This has the advantage that util_arch_hsa_maxsize() has no longer to be adapted with every introduction of yet another machine type in the future. Suggested-by: Heiko Carstens Reviewed-by: Jan Höppner Reviewed-by: Thomas Richter Signed-off-by: Alexander Egorenkov Signed-off-by: Steffen Eiden --- libutil/util_arch.c | 49 +++++++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/libutil/util_arch.c b/libutil/util_arch.c index 9b2ef45b..dbebff2c 100644 --- a/libutil/util_arch.c +++ b/libutil/util_arch.c @@ -13,6 +13,8 @@ #include #include +#include "lib/util_path.h" +#include "lib/util_file.h" #include "lib/util_arch.h" #define PROC_SYSINFO "/proc/sysinfo" @@ -107,13 +109,44 @@ const char *util_arch_machine_type_to_str(int type) */ unsigned long util_arch_hsa_maxsize(void) { - switch (util_arch_machine_type()) { - case UTIL_ARCH_MACHINE_TYPE_Z15: - case UTIL_ARCH_MACHINE_TYPE_Z15_T02: - case UTIL_ARCH_MACHINE_TYPE_Z16: - case UTIL_ARCH_MACHINE_TYPE_Z16_A02: - return HSA_SIZE_512M; - default: - return HSA_SIZE_32M; + unsigned long hsa_size = 0; + char *path; + int rc; + + path = util_path_sysfs("firmware/dump/dump_area_size"); + if (util_path_exists(path)) { + rc = util_file_read_ul(&hsa_size, 10, path); + if (rc) + hsa_size = 0; } + free(path); + + /* + * Fall back in case of failed attempt to obtain dump area size + * from sysfs for some reason (e.g. no kernel support of + * the sysfs attribute /sys/firmware/dump/dump_area_size). + * For all machine types starting with z15 we can safely assume + * at least 512M of dump area size, otherwise, only 32M can be + * safely assumed. + */ + if (!hsa_size) { + switch (util_arch_machine_type()) { + case UTIL_ARCH_MACHINE_TYPE_Z10_EC: + case UTIL_ARCH_MACHINE_TYPE_Z10_BC: + case UTIL_ARCH_MACHINE_TYPE_ZE_196: + case UTIL_ARCH_MACHINE_TYPE_ZE_114: + case UTIL_ARCH_MACHINE_TYPE_ZE_EC12: + case UTIL_ARCH_MACHINE_TYPE_ZE_BC12: + case UTIL_ARCH_MACHINE_TYPE_Z13: + case UTIL_ARCH_MACHINE_TYPE_Z13_S: + case UTIL_ARCH_MACHINE_TYPE_Z14: + case UTIL_ARCH_MACHINE_TYPE_Z14_ZR1: + hsa_size = HSA_SIZE_32M; + break; + default: + hsa_size = HSA_SIZE_512M; + } + } + + return hsa_size; }