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

index 78d9404f130860c54248a98ce9db845397417cb0..01efaafdeb435396c59d002b41bc7956274a9f03 100644 (file)
@@ -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)
index 88d391a8fa570da043fb4a7a67775c1d3c2c1461..86c93b5fda4a1b6267e1ce8593a370565b306acc 100644 (file)
@@ -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;
 }