]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lscpu: add lscpu_read_topolgy_ids()
authorKarel Zak <kzak@redhat.com>
Wed, 15 Jul 2020 14:25:15 +0000 (16:25 +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-cpu.c
sys-utils/lscpu-cputype.c

index a7883e03f6eee9c4d356c5a482ab384c0398c80e..e09ba65fd88940722bf60d865ef6b0760bbb58cb 100644 (file)
@@ -191,6 +191,7 @@ int lscpu_read_archext(struct lscpu_cxt *cxt);
 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_topolgy_ids(struct lscpu_cxt *cxt);
 
 struct lscpu_arch *lscpu_read_architecture(struct lscpu_cxt *cxt);
 void lscpu_free_architecture(struct lscpu_arch *ar);
index f31dcba4d5e12843291c1f86c78eb0cca8c385b7..78d9404f130860c54248a98ce9db845397417cb0 100644 (file)
@@ -55,6 +55,7 @@ int lscpu_add_cpu(struct lscpu_cxt *cxt,
        if (type) {
                cpu->type = type;
                lscpu_ref_cputype(type);
+               type->ncpus++;
        }
 
        return 0;
@@ -70,21 +71,33 @@ int lscpu_cpus_apply_type(struct lscpu_cxt *cxt, struct lscpu_cputype *type)
                if (!cpu->type) {
                        cpu->type = type;
                        lscpu_ref_cputype(type);
+                       type->ncpus++;
                }
        }
        return 0;
 }
 
-/* returns first CPU which represents the type */
-struct lscpu_cpu *lscpu_cpus_loopup_by_type(struct lscpu_cxt *cxt, struct lscpu_cputype *ct)
+
+int lscpu_read_topolgy_ids(struct lscpu_cxt *cxt)
 {
+       struct path_cxt *sys = cxt->syscpu;
        size_t i;
 
        for (i = 0; i < cxt->ncpus; i++) {
                struct lscpu_cpu *cpu = cxt->cpus[i];
-
-               if (cpu->type == ct)
-                       return cpu;
+               int num = cpu->logical_id;
+
+               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 NULL;
+
+       return 0;
 }
+
+
index cca7fb89819a5c541a488385cbe545bee0841600..88d391a8fa570da043fb4a7a67775c1d3c2c1461 100644 (file)
@@ -213,15 +213,16 @@ static int cputype_read_topology(struct lscpu_cxt *cxt, struct lscpu_cputype *ct
 
        for (i = 0; i < cxt->ncpus; i++) {
                struct lscpu_cpu *cpu = cxt->cpus[i++];
-               cpu_set_t *thread_siblings, *core_siblings;
-               cpu_set_t *book_siblings, *drawer_siblings;
+               cpu_set_t *thread_siblings = NULL, *core_siblings = NULL;
+               cpu_set_t *book_siblings = NULL, *drawer_siblings = NULL;
                int num;
 
                if (cpu->type != ct)
                        continue;
 
                num = cpu->logical_id;
-               if (ul_path_accessf(sys, F_OK, "cpu%d/topology/thread_siblings", num) != 0)
+               if (ul_path_accessf(sys, F_OK,
+                                       "cpu%d/topology/thread_siblings", num) != 0)
                        continue;
 
                /* read topology maps */
@@ -234,7 +235,6 @@ static int cputype_read_topology(struct lscpu_cxt *cxt, struct lscpu_cputype *ct
                ul_path_readf_cpuset(sys, &drawer_siblings, cxt->maxcpus,
                                        "cpu%d/topology/drawer_siblings", num);
 
-
                /* Allocate arrays for topology maps.
                 *
                 * For each map we make sure that it can have up to ncpuspos
@@ -253,8 +253,8 @@ static int cputype_read_topology(struct lscpu_cxt *cxt, struct lscpu_cputype *ct
                        ct->drawermaps = xcalloc(npos, sizeof(cpu_set_t *));
 
                /* add to topology maps */
-               add_cpuset_to_array(ct->socketmaps, &ct->nsockets, core_siblings, setsize);
                add_cpuset_to_array(ct->coremaps, &ct->ncores, thread_siblings, setsize);
+               add_cpuset_to_array(ct->socketmaps, &ct->nsockets, core_siblings, setsize);
 
                if (book_siblings)
                        add_cpuset_to_array(ct->bookmaps, &ct->nbooks, book_siblings, setsize);
@@ -949,6 +949,7 @@ int main(int argc, char **argv)
        lscpu_read_vulnerabilities(cxt);
        lscpu_read_numas(cxt);
        lscpu_read_topology(cxt);
+       lscpu_read_topolgy_ids(cxt);
 
        lscpu_decode_arm(cxt);