From ae5a369286e0e2d10fe7420c5f4ce832a75d0bf5 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 29 Jul 2024 10:21:28 +0200 Subject: [PATCH] lscpu: make code more readable Signed-off-by: Karel Zak (cherry picked from commit 5d1129e6879a05aa9ac5804ffc8ace22cda735c1) --- sys-utils/lscpu-arm.c | 6 +++--- sys-utils/lscpu-cputype.c | 8 ++++---- sys-utils/lscpu-virt.c | 2 +- sys-utils/lscpu.h | 3 +++ 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c index 96f6b33c92..2decc18f94 100644 --- a/sys-utils/lscpu-arm.c +++ b/sys-utils/lscpu-arm.c @@ -448,13 +448,13 @@ static int arm_rXpY_decode(struct lscpu_cputype *ct) static void arm_decode(struct lscpu_cxt *cxt, struct lscpu_cputype *ct) { - if (!cxt->noalive && access(_PATH_SYS_DMI, R_OK) == 0) + if (is_live(cxt) && access(_PATH_SYS_DMI, R_OK) == 0) dmi_decode_cputype(ct); arm_ids_decode(ct); arm_rXpY_decode(ct); - if (!cxt->noalive && cxt->is_cluster) + if (is_live(cxt) && cxt->is_cluster) ct->nr_socket_on_cluster = get_number_of_physical_sockets_from_dmi(); } @@ -462,7 +462,7 @@ static int is_cluster_arm(struct lscpu_cxt *cxt) { struct stat st; - if (!cxt->noalive + if (is_live(cxt) && strcmp(cxt->arch->name, "aarch64") == 0 && stat(_PATH_ACPI_PPTT, &st) < 0 && cxt->ncputypes == 1) return 1; diff --git a/sys-utils/lscpu-cputype.c b/sys-utils/lscpu-cputype.c index bcdf06e8db..1c0edd3a6f 100644 --- a/sys-utils/lscpu-cputype.c +++ b/sys-utils/lscpu-cputype.c @@ -621,7 +621,7 @@ struct lscpu_arch *lscpu_read_architecture(struct lscpu_cxt *cxt) ar = xcalloc(1, sizeof(*cxt->arch)); ar->name = xstrdup(utsbuf.machine); - if (cxt->noalive) + if (is_dump(cxt)) /* reading info from any /{sys,proc} dump, don't mix it with * information about our real CPU */ ; @@ -673,7 +673,7 @@ struct lscpu_arch *lscpu_read_architecture(struct lscpu_cxt *cxt) ar->bit64 = 1; } - if (ar->name && !cxt->noalive) { + if (ar->name && is_live(cxt)) { if (strcmp(ar->name, "ppc64") == 0) ar->bit32 = 1, ar->bit64 = 1; else if (strcmp(ar->name, "ppc") == 0) @@ -706,7 +706,7 @@ int lscpu_read_cpulists(struct lscpu_cxt *cxt) /* note that kernel_max is maximum index [NR_CPUS-1] */ cxt->maxcpus += 1; - else if (!cxt->noalive) + else if (is_live(cxt)) /* the root is '/' so we are working with data from the current kernel */ cxt->maxcpus = get_max_number_of_cpus(); @@ -778,7 +778,7 @@ int lscpu_read_archext(struct lscpu_cxt *cxt) #if defined(HAVE_LIBRTAS) /* Get PowerPC specific info */ - if (!cxt->noalive) { + if (is_live(cxt)) { int rc, len, ntypes; ct->physsockets = ct->physchips = ct->physcoresperchip = 0; diff --git a/sys-utils/lscpu-virt.c b/sys-utils/lscpu-virt.c index dc786a8802..7c955a9390 100644 --- a/sys-utils/lscpu-virt.c +++ b/sys-utils/lscpu-virt.c @@ -557,7 +557,7 @@ struct lscpu_virt *lscpu_read_virtualization(struct lscpu_cxt *cxt) goto done; } - if (!cxt->noalive) { + if (is_live(cxt)) { virt->vendor = read_hypervisor_cpuid(); if (!virt->vendor) virt->vendor = read_hypervisor_dmi(); diff --git a/sys-utils/lscpu.h b/sys-utils/lscpu.h index 09ebe14da3..9da1b362a5 100644 --- a/sys-utils/lscpu.h +++ b/sys-utils/lscpu.h @@ -263,6 +263,9 @@ struct lscpu_cxt { int is_cluster; /* For aarch64 if the machine doesn't have ACPI PPTT */ }; +#define is_live(_cxt) (!(_cxt)->noalive) +#define is_dump(_cxt) ((_cxt)->noalive) + #define is_cpu_online(_cxt, _cpu) \ ((_cxt) && (_cpu) && (_cxt)->online && \ CPU_ISSET_S((_cpu)->logical_id, (_cxt)->setsize, (_cxt)->online)) -- 2.47.2