]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: hide all to lscpu_read_topology()
authorKarel Zak <kzak@redhat.com>
Fri, 14 Aug 2020 10:07:18 +0000 (12:07 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 13 Nov 2020 08:19:02 +0000 (09:19 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
sys-utils/lscpu-api.h
sys-utils/lscpu-cputype.c
sys-utils/lscpu-topology.c

index b3067dadd2dd0d3f6ed14188812b74db282355bd..61932cb0080b79a70949a8cb36dc2a8ae1aea5a9 100644 (file)
@@ -199,8 +199,6 @@ int lscpu_read_vulnerabilities(struct lscpu_cxt *cxt);
 int lscpu_read_numas(struct lscpu_cxt *cxt);
 
 int lscpu_read_topology(struct lscpu_cxt *cxt);
-int lscpu_read_topology_ids(struct lscpu_cxt *cxt);
-int lscpu_read_topology_polarization(struct lscpu_cxt *cxt);
 void lscpu_cputype_free_topology(struct lscpu_cputype *ct);
 
 struct lscpu_arch *lscpu_read_architecture(struct lscpu_cxt *cxt);
index cd2aa775f33d35b6e1a44d9377f9f82729048d5a..ac96d7f1d0938f8a35e9d86b60a764515afe0e4b 100644 (file)
@@ -872,8 +872,6 @@ int main(int argc, char **argv)
        lscpu_read_vulnerabilities(cxt);
        lscpu_read_numas(cxt);
        lscpu_read_topology(cxt);
-       lscpu_read_topology_ids(cxt);
-       lscpu_read_topology_polarization(cxt);
 
        lscpu_decode_arm(cxt);
 
index 3d12a7e7833d33e81c9132797d9019d16790803d..036e1440c79221cd46b6af09db692779e2cfc46e 100644 (file)
@@ -184,79 +184,75 @@ static int cputype_read_topology(struct lscpu_cxt *cxt, struct lscpu_cputype *ct
        return 0;
 }
 
-int lscpu_read_topology(struct lscpu_cxt *cxt)
+static int read_ids(struct lscpu_cxt *cxt, struct lscpu_cpu *cpu)
 {
-       size_t i;
-       int rc = 0;
+       struct path_cxt *sys = cxt->syscpu;
+       int num = cpu->logical_id;
 
-       for (i = 0; i < cxt->ncputypes; i++)
-               rc += cputype_read_topology(cxt, cxt->cputypes[i]);
+       if (ul_path_accessf(sys, F_OK, "cpu%d/topology", num) != 0)
+               return 0;
 
-       return rc;
+       DBG(CPU, ul_debugobj(cpu, "#%d reading IDs", num));
+
+       if (ul_path_readf_s32(sys, &cpu->coreid, "cpu%d/topology/core_id", num) != 0)
+               cpu->coreid = -1;
+       if (ul_path_readf_s32(sys, &cpu->socketid, "cpu%d/topology/physical_package_id", num) != 0)
+               cpu->socketid = -1;
+       if (ul_path_readf_s32(sys, &cpu->bookid, "cpu%d/topology/book_id", num) != 0)
+               cpu->bookid = -1;
+       if (ul_path_readf_s32(sys, &cpu->drawerid, "cpu%d/topology/drawer_id", num) != 0)
+               cpu->drawerid = -1;
+
+       return 0;
 }
 
-int lscpu_read_topology_ids(struct lscpu_cxt *cxt)
+static int read_polarization(struct lscpu_cxt *cxt, struct lscpu_cpu *cpu)
 {
        struct path_cxt *sys = cxt->syscpu;
-       size_t i;
-
-       for (i = 0; i < cxt->npossibles; i++) {
-               struct lscpu_cpu *cpu = cxt->cpus[i];
-               int num;
+       int num = cpu->logical_id;
+       char mode[64];
 
-               if (!cpu)
-                       continue;
+       if (ul_path_accessf(sys, F_OK, "cpu%d/polarization", num) != 0)
+               return 0;
 
-               num = cpu->logical_id;
-               if (ul_path_accessf(sys, F_OK, "cpu%d/topology", num) != 0)
-                       continue;
+       ul_path_readf_buffer(sys, mode, sizeof(mode), "cpu%d/polarization", num);
 
-               DBG(CPU, ul_debugobj(cpu, "#%d reading IDs", num));
+       DBG(CPU, ul_debugobj(cpu, "#%d polar=%s", num, mode));
 
-               if (ul_path_readf_s32(sys, &cpu->coreid, "cpu%d/topology/core_id", num) != 0)
-                       cpu->coreid = -1;
-               if (ul_path_readf_s32(sys, &cpu->socketid, "cpu%d/topology/physical_package_id", num) != 0)
-                       cpu->socketid = -1;
-               if (ul_path_readf_s32(sys, &cpu->bookid, "cpu%d/topology/book_id", num) != 0)
-                       cpu->bookid = -1;
-               if (ul_path_readf_s32(sys, &cpu->drawerid, "cpu%d/topology/drawer_id", num) != 0)
-                       cpu->drawerid = -1;
-       }
+       if (strncmp(mode, "vertical:low", sizeof(mode)) == 0)
+               cpu->polarization = POLAR_VLOW;
+       else if (strncmp(mode, "vertical:medium", sizeof(mode)) == 0)
+               cpu->polarization = POLAR_VMEDIUM;
+       else if (strncmp(mode, "vertical:high", sizeof(mode)) == 0)
+               cpu->polarization = POLAR_VHIGH;
+       else if (strncmp(mode, "horizontal", sizeof(mode)) == 0)
+               cpu->polarization = POLAR_HORIZONTAL;
+       else
+               cpu->polarization = POLAR_UNKNOWN;
 
        return 0;
 }
 
-int lscpu_read_topology_polarization(struct lscpu_cxt *cxt)
+int lscpu_read_topology(struct lscpu_cxt *cxt)
 {
-       struct path_cxt *sys = cxt->syscpu;
        size_t i;
+       int rc = 0;
+
+       for (i = 0; i < cxt->ncputypes; i++)
+               rc += cputype_read_topology(cxt, cxt->cputypes[i]);
 
-       for (i = 0; i < cxt->npossibles; i++) {
+       for (i = 0; rc == 0 && i < cxt->npossibles; i++) {
                struct lscpu_cpu *cpu = cxt->cpus[i];
-               int num;
-               char mode[64];
 
-               if (!cpu || !cpu->type || cpu->type->dispatching < 0)
+               if (!cpu || !cpu->type)
                        continue;
 
-               num = cpu->logical_id;
-               if (ul_path_accessf(sys, F_OK, "cpu%d/polarization", num) != 0)
-                       continue;
+               rc = read_ids(cxt, cpu);
+               if (rc == 0)
+                       read_polarization(cxt, cpu);
+       }
 
-               ul_path_readf_buffer(sys, mode, sizeof(mode), "cpu%d/polarization", num);
+       return rc;
+}
 
-               DBG(CPU, ul_debugobj(cpu, "#%d polar=%s", num, mode));
 
-               if (strncmp(mode, "vertical:low", sizeof(mode)) == 0)
-                       cpu->polarization = POLAR_VLOW;
-               else if (strncmp(mode, "vertical:medium", sizeof(mode)) == 0)
-                       cpu->polarization = POLAR_VMEDIUM;
-               else if (strncmp(mode, "vertical:high", sizeof(mode)) == 0)
-                       cpu->polarization = POLAR_VHIGH;
-               else if (strncmp(mode, "horizontal", sizeof(mode)) == 0)
-                       cpu->polarization = POLAR_HORIZONTAL;
-               else
-                       cpu->polarization = POLAR_UNKNOWN;
-       }
-       return 0;
-}