]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: make code more readable
authorKarel Zak <kzak@redhat.com>
Mon, 29 Jul 2024 08:21:28 +0000 (10:21 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 6 Jan 2025 17:27:22 +0000 (18:27 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
(cherry picked from commit 5d1129e6879a05aa9ac5804ffc8ace22cda735c1)

sys-utils/lscpu-arm.c
sys-utils/lscpu-cputype.c
sys-utils/lscpu-virt.c
sys-utils/lscpu.h

index 96f6b33c9245951d027c61bbe82dd4c8c3b7daff..2decc18f9494a96bae5aaa0f0056ed5a12f5f646 100644 (file)
@@ -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;
index bcdf06e8db06dbcb14dfae5ef75d0a5015868fb3..1c0edd3a6f624c51730731c117ffbd94517c0684 100644 (file)
@@ -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;
index dc786a88028e392549e46c2381d0620b37b0c50f..7c955a9390a5e04b15968978c6374b423e48e03b 100644 (file)
@@ -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();
index 09ebe14da32d2b723ad231eb83b54e6f895b90d0..9da1b362a537668970453c034f8779b48a806882 100644 (file)
@@ -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))