aboutsummaryrefslogtreecommitdiffstats
path: root/sys-utils
diff options
context:
space:
mode:
authorKarel Zak <kzak@redhat.com>2024-07-29 10:21:28 +0200
committerPratik R. Sampat <pratikrajesh.sampat@amd.com>2024-07-30 14:26:50 +0000
commit5d1129e6879a05aa9ac5804ffc8ace22cda735c1 (patch)
tree5d693ba84ccf67d974587f31c0158d9005a38bd4 /sys-utils
parent50a3efab6d126b28fcdcc28f1a0cd5cd596ae357 (diff)
downloadutil-linux-5d1129e6879a05aa9ac5804ffc8ace22cda735c1.tar.gz
lscpu: make code more readable
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils')
-rw-r--r--sys-utils/lscpu-arm.c6
-rw-r--r--sys-utils/lscpu-cputype.c8
-rw-r--r--sys-utils/lscpu-virt.c2
-rw-r--r--sys-utils/lscpu.h3
4 files changed, 11 insertions, 8 deletions
diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c
index ad714e77ae..5966df0a61 100644
--- a/sys-utils/lscpu-arm.c
+++ b/sys-utils/lscpu-arm.c
@@ -449,13 +449,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();
}
@@ -463,7 +463,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 64518fbd81..739dd99c59 100644
--- a/sys-utils/lscpu-cputype.c
+++ b/sys-utils/lscpu-cputype.c
@@ -727,7 +727,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 */
;
@@ -779,7 +779,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)
@@ -812,7 +812,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();
@@ -884,7 +884,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 6ba7c02dc6..051384622a 100644
--- a/sys-utils/lscpu-virt.c
+++ b/sys-utils/lscpu-virt.c
@@ -558,7 +558,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 b68d1fff5f..02f8577815 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))