From: Karel Zak Date: Wed, 15 Jul 2020 14:25:15 +0000 (+0200) Subject: lscpu: add lscpu_read_topolgy_ids() X-Git-Tag: v2.37-rc1~360 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=314aa95fd51ffb2bc72ad64fe41f85d4b8f82386;p=thirdparty%2Futil-linux.git lscpu: add lscpu_read_topolgy_ids() Signed-off-by: Karel Zak --- diff --git a/sys-utils/lscpu-api.h b/sys-utils/lscpu-api.h index a7883e03f6..e09ba65fd8 100644 --- a/sys-utils/lscpu-api.h +++ b/sys-utils/lscpu-api.h @@ -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); diff --git a/sys-utils/lscpu-cpu.c b/sys-utils/lscpu-cpu.c index f31dcba4d5..78d9404f13 100644 --- a/sys-utils/lscpu-cpu.c +++ b/sys-utils/lscpu-cpu.c @@ -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; } + + diff --git a/sys-utils/lscpu-cputype.c b/sys-utils/lscpu-cputype.c index cca7fb8981..88d391a8fa 100644 --- a/sys-utils/lscpu-cputype.c +++ b/sys-utils/lscpu-cputype.c @@ -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);