From: Karel Zak Date: Wed, 15 Jul 2020 16:05:15 +0000 (+0200) Subject: lscpu: deallocate maps X-Git-Tag: v2.37-rc1~359 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b8a319460dba9c62c7f92044915498da8d7827e3;p=thirdparty%2Futil-linux.git lscpu: deallocate maps Signed-off-by: Karel Zak --- diff --git a/sys-utils/lscpu-cpu.c b/sys-utils/lscpu-cpu.c index 78d9404f13..01efaafdeb 100644 --- a/sys-utils/lscpu-cpu.c +++ b/sys-utils/lscpu-cpu.c @@ -83,10 +83,13 @@ 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]; int num = cpu->logical_id; + DBG(TYPE, 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) diff --git a/sys-utils/lscpu-cputype.c b/sys-utils/lscpu-cputype.c index 88d391a8fa..86c93b5fda 100644 --- a/sys-utils/lscpu-cputype.c +++ b/sys-utils/lscpu-cputype.c @@ -77,7 +77,7 @@ static int add_cpuset_to_array(cpu_set_t **ary, int *items, cpu_set_t *set, size int i; if (!ary) - return -1; + return -EINVAL; for (i = 0; i < *items; i++) { if (CPU_EQUAL_S(setsize, set, ary[i])) @@ -92,6 +92,17 @@ static int add_cpuset_to_array(cpu_set_t **ary, int *items, cpu_set_t *set, size return 1; } +static void free_cpuset_array(cpu_set_t **ary, int items) +{ + int i; + + if (!ary) + return; + for (i = 0; i < items; i++) + free(ary[i]); + free(ary); +} + struct lscpu_cputype *lscpu_new_cputype(void) { struct lscpu_cputype *ct; @@ -127,10 +138,10 @@ void lscpu_unref_cputype(struct lscpu_cputype *ct) free(ct->flags); free(ct->mtid); /* maximum thread id (s390) */ free(ct->addrsz); /* address sizes */ - free(ct->coremaps); - free(ct->socketmaps); - free(ct->bookmaps); - free(ct->drawermaps); + free_cpuset_array(ct->coremaps, ct->ncores); + free_cpuset_array(ct->socketmaps, ct->nsockets); + free_cpuset_array(ct->bookmaps, ct->nbooks); + free_cpuset_array(ct->drawermaps, ct->ndrawers); free(ct); } } @@ -212,7 +223,7 @@ static int cputype_read_topology(struct lscpu_cxt *cxt, struct lscpu_cputype *ct npos = cxt->ncpuspos; /* possible CPUs */ for (i = 0; i < cxt->ncpus; i++) { - struct lscpu_cpu *cpu = cxt->cpus[i++]; + struct lscpu_cpu *cpu = cxt->cpus[i]; cpu_set_t *thread_siblings = NULL, *core_siblings = NULL; cpu_set_t *book_siblings = NULL, *drawer_siblings = NULL; int num; @@ -225,6 +236,8 @@ static int cputype_read_topology(struct lscpu_cxt *cxt, struct lscpu_cputype *ct "cpu%d/topology/thread_siblings", num) != 0) continue; + DBG(TYPE, ul_debugobj(ct, "#%d reading topology", num)); + /* read topology maps */ ul_path_readf_cpuset(sys, &thread_siblings, cxt->maxcpus, "cpu%d/topology/thread_siblings", num); @@ -279,7 +292,7 @@ static int cputype_read_topology(struct lscpu_cxt *cxt, struct lscpu_cputype *ct * non-present cpu maps and to keep calculation easy we make * sure that nsockets and nbooks is at least 1. */ - nsockets = ct->ncpus / nthreads / ncores; + nsockets = cxt->npresents / nthreads / ncores; if (!nsockets) nsockets = 1; @@ -297,6 +310,13 @@ static int cputype_read_topology(struct lscpu_cxt *cxt, struct lscpu_cputype *ct } } + + DBG(TYPE, ul_debugobj(ct, " nthreads: %d", ct->nthreads)); + DBG(TYPE, ul_debugobj(ct, " ncores: %d", ct->ncores)); + DBG(TYPE, ul_debugobj(ct, " nsockets: %d", ct->nsockets)); + DBG(TYPE, ul_debugobj(ct, " nbooks: %d", ct->nbooks)); + DBG(TYPE, ul_debugobj(ct, " ndrawers: %d", ct->ndrawers)); + return 0; }